Skip to content

Commit

Permalink
Revert "Test/exp run: Handler and service tests for experiment run pa…
Browse files Browse the repository at this point in the history
…ckage (#4126)" (#4129)

This reverts commit fcc8382.

Co-authored-by: Amit Kumar Das <[email protected]>
  • Loading branch information
Saranya-jena and amityt authored Aug 16, 2023
1 parent fcc8382 commit edb61a1
Show file tree
Hide file tree
Showing 22 changed files with 1,541 additions and 3,534 deletions.
29 changes: 29 additions & 0 deletions chaoscenter/graphql/definitions/shared/chaos_experiment.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,18 @@ type GetExperimentStatsResponse {
}

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!

"""
Returns the experiment based on experiment ID
Expand All @@ -717,6 +728,10 @@ extend type Query {
request: ListExperimentRequest!
): ListExperimentResponse!

"""
Query to get experiment run stats
"""
getExperimentRunStats(projectID: ID!): GetExperimentRunStatsResponse!
"""
Query to get experiment stats
"""
Expand All @@ -740,6 +755,14 @@ extend type Mutation {
projectID: ID!
): String!

"""
Run the chaos experiment (used by frontend)
"""
runChaosExperiment(
experimentID: String!
projectID: ID!
): RunChaosExperimentResponse!

"""
Updates the experiment
"""
Expand All @@ -756,4 +779,10 @@ extend type Mutation {
experimentRunID: String
projectID: ID!
): Boolean!

"""
Creates a new experiment run and sends it to subscriber
"""
# authorized directive not required
chaosExperimentRun(request: ExperimentRunRequest!): String!
}

This file was deleted.

106 changes: 104 additions & 2 deletions chaoscenter/graphql/server/graph/chaos_experiment.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func (r *mutationResolver) CreateChaosExperiment(ctx context.Context, request mo

if experiment.CronSyntax != "" {

if err = r.chaosExperimentRunHandler.RunCronExperiment(ctx, projectID, experiment, data_store.Store); err != nil {
if err = r.chaosExperimentHandler.RunCronExperiment(ctx, projectID, experiment, data_store.Store); err != nil {
logrus.WithFields(logFields).Error(err)
return nil, err
}
logrus.WithFields(logFields).WithField("workflowId", experiment.ExperimentID).Info("cron experiment created successfully")
return uiResponse, nil
}

_, err = r.chaosExperimentRunHandler.RunChaosWorkFlow(ctx, projectID, experiment, data_store.Store)
_, err = r.chaosExperimentHandler.RunChaosWorkFlow(ctx, projectID, experiment, data_store.Store)
if err != nil {
logrus.WithFields(logFields).Error(err)
return nil, err
Expand Down Expand Up @@ -89,6 +89,41 @@ func (r *mutationResolver) SaveChaosExperiment(ctx context.Context, request mode
return uiResponse, nil
}

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.chaosExperimentHandler.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 *mutationResolver) UpdateChaosExperiment(ctx context.Context, request *model.ChaosExperimentRequest, projectID string) (*model.ChaosExperimentResponse, error) {
logFields := logrus.Fields{
"projectId": projectID,
Expand Down Expand Up @@ -135,6 +170,53 @@ func (r *mutationResolver) DeleteChaosExperiment(ctx context.Context, experiment
return uiResponse, err
}

func (r *mutationResolver) ChaosExperimentRun(ctx context.Context, request model.ExperimentRunRequest) (string, error) {
return r.chaosExperimentHandler.ChaosExperimentRunEvent(request)
}

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.ListWorkflowRuns],
model.InvitationAccepted.String())
if err != nil {
return nil, err
}

expRunResponse, err := r.chaosExperimentHandler.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.chaosExperimentHandler.ListExperimentRun(projectID, request)
if err != nil {
logrus.WithFields(logFields).Error(err)
return nil, err
}
return uiResponse, err
}

func (r *queryResolver) GetExperiment(ctx context.Context, projectID string, experimentID string) (*model.GetExperimentResponse, error) {
logFields := logrus.Fields{
"projectId": projectID,
Expand Down Expand Up @@ -177,6 +259,26 @@ func (r *queryResolver) ListExperiment(ctx context.Context, projectID string, re
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.chaosExperimentHandler.GetExperimentRunStats(ctx, projectID)
if err != nil {
logrus.WithFields(logFields).Error(err)
return nil, err
}
return uiResponse, err
}

func (r *queryResolver) GetExperimentStats(ctx context.Context, projectID string) (*model.GetExperimentStatsResponse, error) {
logFields := logrus.Fields{
"projectId": projectID,
Expand Down
117 changes: 0 additions & 117 deletions chaoscenter/graphql/server/graph/chaos_experiment_run.resolvers.go

This file was deleted.

Loading

0 comments on commit edb61a1

Please sign in to comment.