-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL Admin API: Support export, draining, shutdown and setting lru…
…_mb operations (#4739) This PR adds support for doing export, shutdown, setting `lru_mb` and draining using the GraphQL Admin API. The current `/admin` HTTP endpoints have been kept as before.
- Loading branch information
1 parent
2eca86c
commit c39bd3f
Showing
11 changed files
with
458 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright 2020 Dgraph Labs, Inc. and Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package admin | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
dgoapi "github.com/dgraph-io/dgo/v2/protos/api" | ||
"github.com/dgraph-io/dgraph/gql" | ||
"github.com/dgraph-io/dgraph/graphql/schema" | ||
"github.com/dgraph-io/dgraph/worker" | ||
"github.com/golang/glog" | ||
) | ||
|
||
type configResolver struct { | ||
mutation schema.Mutation | ||
} | ||
|
||
type configInput struct { | ||
LruMB float64 | ||
} | ||
|
||
func (cr *configResolver) Rewrite( | ||
m schema.Mutation) (*gql.GraphQuery, []*dgoapi.Mutation, error) { | ||
glog.Info("Got config request through GraphQL admin API") | ||
|
||
cr.mutation = m | ||
input, err := getConfigInput(m) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
err = worker.UpdateLruMb(input.LruMB) | ||
return nil, nil, err | ||
} | ||
|
||
func (cr *configResolver) FromMutationResult( | ||
mutation schema.Mutation, | ||
assigned map[string]string, | ||
result map[string]interface{}) (*gql.GraphQuery, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (cr *configResolver) Mutate( | ||
ctx context.Context, | ||
query *gql.GraphQuery, | ||
mutations []*dgoapi.Mutation) (map[string]string, map[string]interface{}, error) { | ||
|
||
return nil, nil, nil | ||
} | ||
|
||
func (cr *configResolver) Query(ctx context.Context, query *gql.GraphQuery) ([]byte, error) { | ||
buf := writeResponse(cr.mutation, "Success", "Config updated successfully") | ||
return buf, nil | ||
} | ||
|
||
func getConfigInput(m schema.Mutation) (*configInput, error) { | ||
inputArg := m.ArgValue(schema.InputArgName) | ||
inputByts, err := json.Marshal(inputArg) | ||
if err != nil { | ||
return nil, schema.GQLWrapf(err, "couldn't get input argument") | ||
} | ||
|
||
var input configInput | ||
err = json.Unmarshal(inputByts, &input) | ||
return &input, schema.GQLWrapf(err, "couldn't get input argument") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2020 Dgraph Labs, Inc. and Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package admin | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
dgoapi "github.com/dgraph-io/dgo/v2/protos/api" | ||
"github.com/dgraph-io/dgraph/gql" | ||
"github.com/dgraph-io/dgraph/graphql/schema" | ||
"github.com/dgraph-io/dgraph/x" | ||
"github.com/golang/glog" | ||
) | ||
|
||
type drainingResolver struct { | ||
mutation schema.Mutation | ||
enable bool | ||
} | ||
|
||
type drainingInput struct { | ||
Enable bool | ||
} | ||
|
||
func (dr *drainingResolver) Rewrite( | ||
m schema.Mutation) (*gql.GraphQuery, []*dgoapi.Mutation, error) { | ||
glog.Info("Got draining request through GraphQL admin API") | ||
|
||
dr.mutation = m | ||
input, err := getDrainingInput(m) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
dr.enable = input.Enable | ||
x.UpdateDrainingMode(input.Enable) | ||
return nil, nil, nil | ||
} | ||
|
||
func (dr *drainingResolver) FromMutationResult( | ||
mutation schema.Mutation, | ||
assigned map[string]string, | ||
result map[string]interface{}) (*gql.GraphQuery, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (dr *drainingResolver) Mutate( | ||
ctx context.Context, | ||
query *gql.GraphQuery, | ||
mutations []*dgoapi.Mutation) (map[string]string, map[string]interface{}, error) { | ||
|
||
return nil, nil, nil | ||
} | ||
|
||
func (dr *drainingResolver) Query(ctx context.Context, query *gql.GraphQuery) ([]byte, error) { | ||
buf := writeResponse(dr.mutation, "Success", | ||
fmt.Sprintf("draining mode has been set to %v", dr.enable)) | ||
return buf, nil | ||
} | ||
|
||
func getDrainingInput(m schema.Mutation) (*drainingInput, error) { | ||
inputArg := m.ArgValue(schema.InputArgName) | ||
inputByts, err := json.Marshal(inputArg) | ||
if err != nil { | ||
return nil, schema.GQLWrapf(err, "couldn't get input argument") | ||
} | ||
|
||
var input drainingInput | ||
err = json.Unmarshal(inputByts, &input) | ||
return &input, schema.GQLWrapf(err, "couldn't get input argument") | ||
} |
Oops, something went wrong.