Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seperate experiment runs from experiments in chaos_center (#4053)
* feat: seperate exp_run and exp grapql schemas Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: seperate exp_run and exp graphql resolvers Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: add generated types Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: add types for exp_run Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: add exp_run services Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * feat: add exp_run handler Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * refractor: remove functions in experiments service related to runs Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * refractor: remove functions in experiments handler related to runs Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * fix: issues due to handler and resolver types Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * fix: breaking changes in generated and service files Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * fix: bugs in experiment handlers and roles Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * fix: add exp run operator and update handler Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * fix: update infra opr to return exp-run Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> * refractor: package name chaos_exp_run Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com> --------- Signed-off-by: SohamRatnaparkhi <soham.ratnaparkhi@gmail.com>
- Loading branch information
1 parent
edb61a1
commit 1b6263b
Showing
14 changed files
with
1,831 additions
and
1,524 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
35 changes: 35 additions & 0 deletions
35
chaoscenter/graphql/definitions/shared/chaos_experiment_run.graphqls
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,35 @@ | ||
extend type Query { | ||
""" | ||
Returns experiment run based on experiment run ID | ||
""" | ||
getExperimentRun(projectID: ID!, experimentRunID: String!): ExperimentRun! | ||
|
||
""" | ||
Returns the list of experiment run based on various filter parameters | ||
""" | ||
listExperimentRun( | ||
projectID: ID! | ||
request: ListExperimentRunRequest! | ||
): ListExperimentRunResponse! | ||
|
||
""" | ||
Query to get experiment run stats | ||
""" | ||
getExperimentRunStats(projectID: ID!): GetExperimentRunStatsResponse! | ||
} | ||
|
||
extend type Mutation { | ||
""" | ||
Creates a new experiment run and sends it to subscriber | ||
""" | ||
# authorized directive not required | ||
chaosExperimentRun(request: ExperimentRunRequest!): String! | ||
|
||
""" | ||
Run the chaos experiment (used by frontend) | ||
""" | ||
runChaosExperiment( | ||
experimentID: String! | ||
projectID: ID! | ||
): RunChaosExperimentResponse! | ||
} |
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
117 changes: 117 additions & 0 deletions
117
chaoscenter/graphql/server/graph/chaos_experiment_run.resolvers.go
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,117 @@ | ||
package graph | ||
|
||
// This file will be automatically regenerated based on the schema, any resolver implementations | ||
// will be copied through when generating and any unknown code will be moved to the end. | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model" | ||
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/authorization" | ||
data_store "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/data-store" | ||
"github.com/sirupsen/logrus" | ||
"go.mongodb.org/mongo-driver/bson" | ||
) | ||
|
||
func (r *mutationResolver) ChaosExperimentRun(ctx context.Context, request model.ExperimentRunRequest) (string, error) { | ||
return r.chaosExperimentRunHandler.ChaosExperimentRunEvent(request) | ||
} | ||
|
||
func (r *mutationResolver) RunChaosExperiment(ctx context.Context, experimentID string, projectID string) (*model.RunChaosExperimentResponse, error) { | ||
logFields := logrus.Fields{ | ||
"projectId": projectID, | ||
"chaosExperimentId": experimentID, | ||
} | ||
|
||
logrus.WithFields(logFields).Info("request received to run chaos experiment") | ||
err := authorization.ValidateRole(ctx, projectID, | ||
authorization.MutationRbacRules[authorization.CreateChaosWorkFlow], | ||
model.InvitationAccepted.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
query := bson.D{ | ||
{"experiment_id", experimentID}, | ||
{"is_removed", false}, | ||
} | ||
|
||
experiment, err := r.chaosExperimentHandler.GetDBExperiment(query) | ||
if err != nil { | ||
return nil, errors.New("could not get experiment run, error: " + err.Error()) | ||
} | ||
|
||
var uiResponse *model.RunChaosExperimentResponse | ||
|
||
uiResponse, err = r.chaosExperimentRunHandler.RunChaosWorkFlow(ctx, projectID, experiment, data_store.Store) | ||
if err != nil { | ||
logrus.WithFields(logFields).Error(err) | ||
return nil, err | ||
} | ||
|
||
return &model.RunChaosExperimentResponse{NotifyID: uiResponse.NotifyID}, err | ||
} | ||
|
||
func (r *queryResolver) GetExperimentRun(ctx context.Context, projectID string, experimentRunID string) (*model.ExperimentRun, error) { | ||
logFields := logrus.Fields{ | ||
"projectId": projectID, | ||
"chaosExperimentRunId": experimentRunID, | ||
} | ||
logrus.WithFields(logFields).Info("request received to fetch chaos experiment run") | ||
err := authorization.ValidateRole(ctx, projectID, | ||
authorization.MutationRbacRules[authorization.GetWorkflowRun], | ||
model.InvitationAccepted.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
expRunResponse, err := r.chaosExperimentRunHandler.GetExperimentRun(ctx, projectID, experimentRunID) | ||
if err != nil { | ||
logrus.WithFields(logFields).Error(err) | ||
return nil, err | ||
} | ||
return expRunResponse, err | ||
} | ||
|
||
func (r *queryResolver) ListExperimentRun(ctx context.Context, projectID string, request model.ListExperimentRunRequest) (*model.ListExperimentRunResponse, error) { | ||
logFields := logrus.Fields{ | ||
"projectId": projectID, | ||
"chaosExperimentIds": request.ExperimentIDs, | ||
"chaosExperimentRunIds": request.ExperimentRunIDs, | ||
} | ||
logrus.WithFields(logFields).Info("request received to list chaos experiment run") | ||
|
||
err := authorization.ValidateRole(ctx, projectID, | ||
authorization.MutationRbacRules[authorization.ListWorkflowRuns], | ||
model.InvitationAccepted.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
uiResponse, err := r.chaosExperimentRunHandler.ListExperimentRun(projectID, request) | ||
if err != nil { | ||
logrus.WithFields(logFields).Error(err) | ||
return nil, err | ||
} | ||
return uiResponse, err | ||
} | ||
|
||
func (r *queryResolver) GetExperimentRunStats(ctx context.Context, projectID string) (*model.GetExperimentRunStatsResponse, error) { | ||
logFields := logrus.Fields{ | ||
"projectId": projectID, | ||
} | ||
logrus.WithFields(logFields).Info("request received to get chaos experiment run stats") | ||
err := authorization.ValidateRole(ctx, projectID, | ||
authorization.MutationRbacRules[authorization.ListWorkflowRuns], | ||
model.InvitationAccepted.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
uiResponse, err := r.chaosExperimentRunHandler.GetExperimentRunStats(ctx, projectID) | ||
if err != nil { | ||
logrus.WithFields(logFields).Error(err) | ||
return nil, err | ||
} | ||
return uiResponse, err | ||
} |
Oops, something went wrong.