Adding clusterid and clustername response in UserClusterReg Mutation (#2184)
* Adding clusterid and clustername response in UserClusterReg Mutation Signed-off-by: Raj Babu Das <raj.das@mayadata.io>
This commit is contained in:
parent
70690ded67
commit
131cb3e19e
|
@ -139,6 +139,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
|||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/litmuschaos/litmus v0.0.0-20200928061105-eddf69c06c4a h1:0VH+h6gGucw2b37mVvwdeC7QY6/50Ko4/EMKBa8b33U=
|
||||
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
|
||||
|
|
|
@ -221,6 +221,12 @@ type ComplexityRoot struct {
|
|||
WorkflowRunID func(childComplexity int) int
|
||||
}
|
||||
|
||||
ClusterRegResponse struct {
|
||||
ClusterID func(childComplexity int) int
|
||||
ClusterName func(childComplexity int) int
|
||||
Token func(childComplexity int) int
|
||||
}
|
||||
|
||||
Weightages struct {
|
||||
ExperimentName func(childComplexity int) int
|
||||
Weightage func(childComplexity int) int
|
||||
|
@ -228,7 +234,7 @@ type ComplexityRoot struct {
|
|||
}
|
||||
|
||||
type MutationResolver interface {
|
||||
UserClusterReg(ctx context.Context, clusterInput model.ClusterInput) (string, error)
|
||||
UserClusterReg(ctx context.Context, clusterInput model.ClusterInput) (*model.ClusterRegResponse, error)
|
||||
CreateChaosWorkFlow(ctx context.Context, input model.ChaosWorkFlowInput) (*model.ChaosWorkFlowResponse, error)
|
||||
CreateUser(ctx context.Context, user model.CreateUserInput) (*model.User, error)
|
||||
UpdateUser(ctx context.Context, user model.UpdateUserInput) (string, error)
|
||||
|
@ -1243,6 +1249,27 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||
|
||||
return e.complexity.WorkflowRuns.WorkflowRunID(childComplexity), true
|
||||
|
||||
case "clusterRegResponse.cluster_id":
|
||||
if e.complexity.ClusterRegResponse.ClusterID == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.ClusterRegResponse.ClusterID(childComplexity), true
|
||||
|
||||
case "clusterRegResponse.cluster_name":
|
||||
if e.complexity.ClusterRegResponse.ClusterName == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.ClusterRegResponse.ClusterName(childComplexity), true
|
||||
|
||||
case "clusterRegResponse.token":
|
||||
if e.complexity.ClusterRegResponse.Token == nil {
|
||||
break
|
||||
}
|
||||
|
||||
return e.complexity.ClusterRegResponse.Token(childComplexity), true
|
||||
|
||||
case "weightages.experiment_name":
|
||||
if e.complexity.Weightages.ExperimentName == nil {
|
||||
break
|
||||
|
@ -1556,6 +1583,12 @@ type WorkflowRuns {
|
|||
last_updated: String!
|
||||
}
|
||||
|
||||
type clusterRegResponse{
|
||||
token: String!,
|
||||
cluster_id: String!,
|
||||
cluster_name: String!,
|
||||
}
|
||||
|
||||
type Query{
|
||||
# [Deprecated soon]
|
||||
getWorkFlowRuns(project_id: String!): [WorkflowRun!]! @authorized
|
||||
|
@ -1577,7 +1610,7 @@ type Query{
|
|||
|
||||
type Mutation{
|
||||
#It is used to create external cluster.
|
||||
userClusterReg(clusterInput: ClusterInput!): String! @authorized
|
||||
userClusterReg(clusterInput: ClusterInput!): clusterRegResponse! @authorized
|
||||
|
||||
#It is used to create chaosworkflow
|
||||
createChaosWorkFlow(input: ChaosWorkFlowInput!): ChaosWorkFlowResponse! @authorized
|
||||
|
@ -3340,10 +3373,10 @@ func (ec *executionContext) _Mutation_userClusterReg(ctx context.Context, field
|
|||
if tmp == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if data, ok := tmp.(string); ok {
|
||||
if data, ok := tmp.(*model.ClusterRegResponse); ok {
|
||||
return data, nil
|
||||
}
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be string`, tmp)
|
||||
return nil, fmt.Errorf(`unexpected type %T from directive, should be *github.com/litmuschaos/litmus/litmus-portal/graphql-server/graph/model.ClusterRegResponse`, tmp)
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
|
@ -3355,9 +3388,9 @@ func (ec *executionContext) _Mutation_userClusterReg(ctx context.Context, field
|
|||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
res := resTmp.(*model.ClusterRegResponse)
|
||||
fc.Result = res
|
||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||
return ec.marshalNclusterRegResponse2ᚖgithubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐClusterRegResponse(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Mutation_createChaosWorkFlow(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
|
@ -7836,6 +7869,108 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co
|
|||
return ec.marshalO__Type2ᚖgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐType(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _clusterRegResponse_token(ctx context.Context, field graphql.CollectedField, obj *model.ClusterRegResponse) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "clusterRegResponse",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.Token, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _clusterRegResponse_cluster_id(ctx context.Context, field graphql.CollectedField, obj *model.ClusterRegResponse) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "clusterRegResponse",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.ClusterID, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _clusterRegResponse_cluster_name(ctx context.Context, field graphql.CollectedField, obj *model.ClusterRegResponse) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
ec.Error(ctx, ec.Recover(ctx, r))
|
||||
ret = graphql.Null
|
||||
}
|
||||
}()
|
||||
fc := &graphql.FieldContext{
|
||||
Object: "clusterRegResponse",
|
||||
Field: field,
|
||||
Args: nil,
|
||||
IsMethod: false,
|
||||
}
|
||||
|
||||
ctx = graphql.WithFieldContext(ctx, fc)
|
||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||
ctx = rctx // use context from middleware stack in children
|
||||
return obj.ClusterName, nil
|
||||
})
|
||||
if err != nil {
|
||||
ec.Error(ctx, err)
|
||||
return graphql.Null
|
||||
}
|
||||
if resTmp == nil {
|
||||
if !graphql.HasFieldError(ctx, fc) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalNString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _weightages_experiment_name(ctx context.Context, field graphql.CollectedField, obj *model.Weightages) (ret graphql.Marshaler) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -9625,6 +9760,43 @@ func (ec *executionContext) ___Type(ctx context.Context, sel ast.SelectionSet, o
|
|||
return out
|
||||
}
|
||||
|
||||
var clusterRegResponseImplementors = []string{"clusterRegResponse"}
|
||||
|
||||
func (ec *executionContext) _clusterRegResponse(ctx context.Context, sel ast.SelectionSet, obj *model.ClusterRegResponse) graphql.Marshaler {
|
||||
fields := graphql.CollectFields(ec.OperationContext, sel, clusterRegResponseImplementors)
|
||||
|
||||
out := graphql.NewFieldSet(fields)
|
||||
var invalids uint32
|
||||
for i, field := range fields {
|
||||
switch field.Name {
|
||||
case "__typename":
|
||||
out.Values[i] = graphql.MarshalString("clusterRegResponse")
|
||||
case "token":
|
||||
out.Values[i] = ec._clusterRegResponse_token(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "cluster_id":
|
||||
out.Values[i] = ec._clusterRegResponse_cluster_id(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
case "cluster_name":
|
||||
out.Values[i] = ec._clusterRegResponse_cluster_name(ctx, field, obj)
|
||||
if out.Values[i] == graphql.Null {
|
||||
invalids++
|
||||
}
|
||||
default:
|
||||
panic("unknown field " + strconv.Quote(field.Name))
|
||||
}
|
||||
}
|
||||
out.Dispatch()
|
||||
if invalids > 0 {
|
||||
return graphql.Null
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
var weightagesImplementors = []string{"weightages"}
|
||||
|
||||
func (ec *executionContext) _weightages(ctx context.Context, sel ast.SelectionSet, obj *model.Weightages) graphql.Marshaler {
|
||||
|
@ -10445,6 +10617,20 @@ func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel a
|
|||
return res
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNclusterRegResponse2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐClusterRegResponse(ctx context.Context, sel ast.SelectionSet, v model.ClusterRegResponse) graphql.Marshaler {
|
||||
return ec._clusterRegResponse(ctx, sel, &v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNclusterRegResponse2ᚖgithubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐClusterRegResponse(ctx context.Context, sel ast.SelectionSet, v *model.ClusterRegResponse) graphql.Marshaler {
|
||||
if v == nil {
|
||||
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
|
||||
ec.Errorf(ctx, "must not be null")
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
return ec._clusterRegResponse(ctx, sel, v)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalNweightages2githubᚗcomᚋlitmuschaosᚋlitmusᚋlitmusᚑportalᚋgraphqlᚑserverᚋgraphᚋmodelᚐWeightages(ctx context.Context, sel ast.SelectionSet, v model.Weightages) graphql.Marshaler {
|
||||
return ec._weightages(ctx, sel, &v)
|
||||
}
|
||||
|
|
|
@ -240,6 +240,12 @@ type WorkflowRuns struct {
|
|||
LastUpdated string `json:"last_updated"`
|
||||
}
|
||||
|
||||
type ClusterRegResponse struct {
|
||||
Token string `json:"token"`
|
||||
ClusterID string `json:"cluster_id"`
|
||||
ClusterName string `json:"cluster_name"`
|
||||
}
|
||||
|
||||
type Weightages struct {
|
||||
ExperimentName string `json:"experiment_name"`
|
||||
Weightage int `json:"weightage"`
|
||||
|
|
|
@ -185,6 +185,12 @@ type WorkflowRuns {
|
|||
last_updated: String!
|
||||
}
|
||||
|
||||
type clusterRegResponse{
|
||||
token: String!,
|
||||
cluster_id: String!,
|
||||
cluster_name: String!,
|
||||
}
|
||||
|
||||
type Query{
|
||||
# [Deprecated soon]
|
||||
getWorkFlowRuns(project_id: String!): [WorkflowRun!]! @authorized
|
||||
|
@ -206,7 +212,7 @@ type Query{
|
|||
|
||||
type Mutation{
|
||||
#It is used to create external cluster.
|
||||
userClusterReg(clusterInput: ClusterInput!): String! @authorized
|
||||
userClusterReg(clusterInput: ClusterInput!): clusterRegResponse! @authorized
|
||||
|
||||
#It is used to create chaosworkflow
|
||||
createChaosWorkFlow(input: ChaosWorkFlowInput!): ChaosWorkFlowResponse! @authorized
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
func (r *mutationResolver) UserClusterReg(ctx context.Context, clusterInput model.ClusterInput) (string, error) {
|
||||
func (r *mutationResolver) UserClusterReg(ctx context.Context, clusterInput model.ClusterInput) (*model.ClusterRegResponse, error) {
|
||||
return mutations.ClusterRegister(clusterInput)
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
)
|
||||
|
||||
//ClusterRegister creates an entry for a new cluster in DB and generates the url used to apply manifest
|
||||
func ClusterRegister(input model.ClusterInput) (string, error) {
|
||||
func ClusterRegister(input model.ClusterInput) (*model.ClusterRegResponse, error) {
|
||||
newCluster := database.Cluster{
|
||||
ClusterID: uuid.New().String(),
|
||||
ClusterName: input.ClusterName,
|
||||
|
@ -37,16 +37,20 @@ func ClusterRegister(input model.ClusterInput) (string, error) {
|
|||
|
||||
err := database.InsertCluster(newCluster)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return &model.ClusterRegResponse{}, err
|
||||
}
|
||||
|
||||
log.Print("NEW CLUSTER REGISTERED : ID-", newCluster.ClusterID, " PID-", newCluster.ProjectID)
|
||||
token, err := cluster.ClusterCreateJWT(newCluster.ClusterID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return &model.ClusterRegResponse{}, err
|
||||
}
|
||||
|
||||
return token, nil
|
||||
return &model.ClusterRegResponse{
|
||||
ClusterID: newCluster.ClusterID,
|
||||
Token: token,
|
||||
ClusterName: newCluster.ClusterName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
//ConfirmClusterRegistration takes the cluster_id and access_key from the subscriber and validates it, if validated generates and sends new access_key
|
||||
|
|
|
@ -21,11 +21,11 @@ func StartDeployer(projectId string) {
|
|||
ClusterType: "internal",
|
||||
PlatformName: "others",
|
||||
}
|
||||
key, err := mutations.ClusterRegister(clusterInput)
|
||||
resp, err := mutations.ClusterRegister(clusterInput)
|
||||
if err != nil {
|
||||
log.Print("SELF CLUSTER REG FAILED[DB-REG] : ", err)
|
||||
}
|
||||
response, err := k8s.CreateDeployment(DEPLOYER_NAMESPACE, key)
|
||||
response, err := k8s.CreateDeployment(DEPLOYER_NAMESPACE, resp.Token)
|
||||
if err != nil {
|
||||
log.Print("SELF CLUSTER REG FAILED[DEPLOY-CREATION] : ", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue