Skip to content

Commit

Permalink
Seperate experiment runs from experiments in chaos_center (#4053)
Browse files Browse the repository at this point in the history
* feat: seperate exp_run and exp grapql schemas

Signed-off-by: SohamRatnaparkhi <[email protected]>

* feat: seperate exp_run and exp graphql resolvers

Signed-off-by: SohamRatnaparkhi <[email protected]>

* feat: add generated types

Signed-off-by: SohamRatnaparkhi <[email protected]>

* feat: add types for exp_run

Signed-off-by: SohamRatnaparkhi <[email protected]>

* feat: add exp_run services

Signed-off-by: SohamRatnaparkhi <[email protected]>

* feat: add exp_run handler

Signed-off-by: SohamRatnaparkhi <[email protected]>

* refractor: remove functions in experiments service related to runs

Signed-off-by: SohamRatnaparkhi <[email protected]>

* refractor: remove functions in experiments handler related to runs

Signed-off-by: SohamRatnaparkhi <[email protected]>

* fix: issues due to handler and resolver types

Signed-off-by: SohamRatnaparkhi <[email protected]>

* fix: breaking changes in generated and service files

Signed-off-by: SohamRatnaparkhi <[email protected]>

* fix: bugs in experiment handlers and roles

Signed-off-by: SohamRatnaparkhi <[email protected]>

* fix: add exp run  operator and update handler

Signed-off-by: SohamRatnaparkhi <[email protected]>

* fix: update infra opr to return exp-run

Signed-off-by: SohamRatnaparkhi <[email protected]>

* refractor: package name chaos_exp_run

Signed-off-by: SohamRatnaparkhi <[email protected]>

---------

Signed-off-by: SohamRatnaparkhi <[email protected]>
  • Loading branch information
SohamRatnaparkhi authored Aug 16, 2023
1 parent edb61a1 commit 1b6263b
Show file tree
Hide file tree
Showing 14 changed files with 1,831 additions and 1,524 deletions.
29 changes: 0 additions & 29 deletions chaoscenter/graphql/definitions/shared/chaos_experiment.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -702,18 +702,7 @@ 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 @@ -728,10 +717,6 @@ extend type Query {
request: ListExperimentRequest!
): ListExperimentResponse!

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

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

"""
Updates the experiment
"""
Expand All @@ -779,10 +756,4 @@ 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!
}
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!
}
106 changes: 2 additions & 104 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.chaosExperimentHandler.RunCronExperiment(ctx, projectID, experiment, data_store.Store); err != nil {
if err = r.chaosExperimentRunHandler.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.chaosExperimentHandler.RunChaosWorkFlow(ctx, projectID, experiment, data_store.Store)
_, err = r.chaosExperimentRunHandler.RunChaosWorkFlow(ctx, projectID, experiment, data_store.Store)
if err != nil {
logrus.WithFields(logFields).Error(err)
return nil, err
Expand Down Expand Up @@ -89,41 +89,6 @@ 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 @@ -170,53 +135,6 @@ 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 @@ -259,26 +177,6 @@ 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: 117 additions & 0 deletions chaoscenter/graphql/server/graph/chaos_experiment_run.resolvers.go
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
}
Loading

0 comments on commit 1b6263b

Please sign in to comment.