Skip to content

Commit

Permalink
Fixes getServerVersion gql (#4424)
Browse files Browse the repository at this point in the history
Signed-off-by: nagesh bansal <[email protected]>
Co-authored-by: Saranya Jena <[email protected]>
Co-authored-by: Sarthak Jain <[email protected]>
  • Loading branch information
3 people authored Feb 15, 2024
1 parent d65c8af commit 7e53059
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion chaoscenter/graphql/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/api/middleware"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/chaoshub"
handler2 "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/chaoshub/handler"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb"
dbSchemaChaosHub "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/chaos_hub"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/projects"

"context"
"fmt"
"net"
"net/http"
"runtime"
Expand All @@ -27,7 +30,7 @@ import (
"github.com/gorilla/websocket"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/generated"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/config"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/handlers"
pb "github.com/litmuschaos/litmus/chaoscenter/graphql/server/protos"
log "github.com/sirupsen/logrus"
Expand All @@ -47,6 +50,28 @@ func init() {

}

func validateVersion() error {
currentVersion := utils.Config.Version
dbVersion, err := config.GetConfig(context.Background(), "version")
if err != nil {
return fmt.Errorf("failed to get version from db, error = %w", err)
}
if dbVersion == nil {
err := config.CreateConfig(
context.Background(),
&config.ServerConfig{Key: "version", Value: currentVersion},
)
if err != nil {
return fmt.Errorf("failed to insert current version in db, error = %w", err)
}
return nil
}
if dbVersion.Value.(string) != currentVersion {
return fmt.Errorf("control plane needs to be upgraded from version %v to %v", dbVersion.Value.(string), currentVersion)
}
return nil
}

func setupGin() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
router := gin.New()
Expand Down Expand Up @@ -74,6 +99,9 @@ func main() {
var mongodbOperator mongodb.MongoOperator = mongodb.NewMongoOperations(mongoClient)
mongodb.Operator = mongodbOperator

if err := validateVersion(); err != nil {
log.Fatal(err)
}
go startGRPCServer(utils.Config.RpcPort, mongodbOperator) // start GRPC serve

srv := handler.New(generated.NewExecutableSchema(graph.NewConfig(mongodbOperator)))
Expand Down

0 comments on commit 7e53059

Please sign in to comment.