Skip to content

Commit

Permalink
feat: save state (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
genos1998 authored Oct 23, 2024
1 parent 7a4f342 commit b9bbbbe
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 10 deletions.
19 changes: 19 additions & 0 deletions august2024august2024v2/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,23 @@ mutation UpdateArtifactScanData($artifactScanDataId: String!) {
}
}
}
}

mutation DeleteArtifactScanData($id: String) {
deleteArtifactScanData(filter: { id: { eq: $id } }) {
msg
numUids
}
}

mutation DeleteArtifactScanDataForInprogress {
deleteArtifactScanData(filter: { vulnScanState: { eq: "inprogress" } }) {
numUids
}
}

mutation DeleteArtifactScanDataNotHaveArtifact {
deleteArtifactScanData(filter: { not: { has: artifactDetails } }) {
numUids
}
}
172 changes: 172 additions & 0 deletions august2024august2024v2/schema-generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion august2024august2024v2/scoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ func calculateScoring(prodDgraphClient graphql.Client) error {

ctx := context.Background()

_, err := DeleteArtifactScanDataForInprogress(ctx, prodDgraphClient)
if err != nil {
return fmt.Errorf("error in DeleteArtifactScanDataForInprogress: %s", err.Error())
}

_, err = DeleteArtifactScanDataNotHaveArtifact(ctx, prodDgraphClient)
if err != nil {
return fmt.Errorf("error in DeleteArtifactScanDataNotHaveArtifact: %s", err.Error())
}

prodArtifactScanDataIds, err := GetArtifactScanDataId(ctx, prodDgraphClient)
if err != nil {
return fmt.Errorf("error: could'nt query prod artifact scan data id: %s", err.Error())
Expand Down Expand Up @@ -53,7 +63,10 @@ func calculateScoring(prodDgraphClient graphql.Client) error {
}

if len(artifactRunHistories.QueryArtifactScanData) == 0 {
logger.Sl.Debugf("Skipping iteration of scandata id: %s as runhistory record not found", eachArtifactScanData.Id)
logger.Sl.Debugf("Deleting iteration of scandata id: %s as runhistory record not found", eachArtifactScanData.Id)
if _, err := DeleteArtifactScanData(context.Background(), prodDgraphClient, eachArtifactScanData.Id); err != nil {
return fmt.Errorf("error: DeleteArtifactScanData: artifact scan data id: %s err: %s", eachArtifactScanData.Id, err.Error())
}
continue
}

Expand Down
8 changes: 7 additions & 1 deletion august2024august2024v2/upgradeSteps.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/Khan/genqlient/graphql"
)

func UpgradeToAugust2024v2(prodGraphUrl, prodToken string, prodDgraphClient graphql.Client) error {
func UpgradeToAugust2024v2(prodGraphUrl, prodToken, restoreServiceUrl string, prodDgraphClient graphql.Client) error {

logger.Logger.Info("--------------Starting Artifact Score Calculation------------------")

Expand All @@ -21,6 +21,12 @@ func UpgradeToAugust2024v2(prodGraphUrl, prodToken string, prodDgraphClient grap
return fmt.Errorf("UpgradeToAugust2024v2: calculateScoring: %s", err.Error())
}

if restoreServiceUrl != "" {
if err := graphqlfunc.BackupAndRestoreDgraph(prodGraphUrl, restoreServiceUrl); err != nil {
return fmt.Errorf("UpgradeToAugust2024v2: BackupAndRestoreDgraph: %s", err.Error())
}
}

logger.Logger.Info("--------------Completed UpgradeToAugust2024v2------------------")

return nil
Expand Down
8 changes: 7 additions & 1 deletion august2024v2september2024/upgradeSteps.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/Khan/genqlient/graphql"
)

func UpgradeToSeptember2024(prodGraphUrl, prodToken string, prodDgraphClient graphql.Client) error {
func UpgradeToSeptember2024(prodGraphUrl, prodToken, restoreServiceUrl string, prodDgraphClient graphql.Client) error {

logger.Logger.Info("--------------Starting UpgradeToSeptember2024------------------")

Expand Down Expand Up @@ -45,6 +45,12 @@ func UpgradeToSeptember2024(prodGraphUrl, prodToken string, prodDgraphClient gra
return fmt.Errorf("UpgradeToSeptember2024: setSummaryNodeForSecurityIssue: %s", err.Error())
}

if restoreServiceUrl != "" {
if err := graphqlfunc.BackupAndRestoreDgraph(prodGraphUrl, restoreServiceUrl); err != nil {
return fmt.Errorf("UpgradeToSeptember2024: BackupAndRestoreDgraph: %s", err.Error())
}
}

logger.Logger.Info("--------------Completed UpgradeToSeptember2024------------------")

return nil
Expand Down
12 changes: 6 additions & 6 deletions common/upgradeSteps.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ func beginProcessOfUpgrade(upgradeTo SchemaOrder, isSecondDgraphRequired, isLast

expGraphqlClient := graphqlfunc.NewClient(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken)

return june2024june2024v2.UpgradeToJune2024V2(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken, expGraphqlClient)
return june2024june2024v2.UpgradeToJune2024V2(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken, Conf.RemoteDgraphRestoreUrl, expGraphqlClient)
}
return june2024june2024v2.UpgradeToJune2024V2(Conf.ProdGraphQLAddr, Conf.ProdDgraphToken, prodGraphqlClient)
return june2024june2024v2.UpgradeToJune2024V2(Conf.ProdGraphQLAddr, Conf.ProdDgraphToken, "", prodGraphqlClient)

case July2024Version:
if err := allChecksForExpDgraph(July2024Version); err != nil {
Expand Down Expand Up @@ -150,9 +150,9 @@ func beginProcessOfUpgrade(upgradeTo SchemaOrder, isSecondDgraphRequired, isLast

expGraphqlClient := graphqlfunc.NewClient(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken)

return august2024august2024v2.UpgradeToAugust2024v2(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken, expGraphqlClient)
return august2024august2024v2.UpgradeToAugust2024v2(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken, Conf.RemoteDgraphRestoreUrl, expGraphqlClient)
}
return august2024august2024v2.UpgradeToAugust2024v2(Conf.ProdGraphQLAddr, Conf.ProdDgraphToken, prodGraphqlClient)
return august2024august2024v2.UpgradeToAugust2024v2(Conf.ProdGraphQLAddr, Conf.ProdDgraphToken, "", prodGraphqlClient)

case September2024Version:
if isSecondDgraphRequired && !isLastStep {
Expand All @@ -163,10 +163,10 @@ func beginProcessOfUpgrade(upgradeTo SchemaOrder, isSecondDgraphRequired, isLast

expGraphqlClient := graphqlfunc.NewClient(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken)

return august2024v2september2024.UpgradeToSeptember2024(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken, expGraphqlClient)
return august2024v2september2024.UpgradeToSeptember2024(Conf.ExpGraphQLAddr, Conf.ExpDgraphToken, Conf.RemoteDgraphRestoreUrl, expGraphqlClient)

}
return august2024v2september2024.UpgradeToSeptember2024(Conf.ProdGraphQLAddr, Conf.ProdDgraphToken, prodGraphqlClient)
return august2024v2september2024.UpgradeToSeptember2024(Conf.ProdGraphQLAddr, Conf.ProdDgraphToken, "", prodGraphqlClient)

}

Expand Down
8 changes: 7 additions & 1 deletion june2024june2024v2/upgradeSteps.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ import (
"github.com/Khan/genqlient/graphql"
)

func UpgradeToJune2024V2(prodGraphUrl, prodToken string, prodDgraphClient graphql.Client) error {
func UpgradeToJune2024V2(prodGraphUrl, prodToken, restoreServiceUrl string, prodDgraphClient graphql.Client) error {

logger.Logger.Info("--------------Starting UpgradeToJune2024V2------------------")

if err := graphqlfunc.UpdateSchema(prodGraphUrl, prodToken, []byte(schemas.June2024Version2)); err != nil {
return fmt.Errorf("UpgradeToJune2024: UpdateSchema: %s", err.Error())
}

if restoreServiceUrl != "" {
if err := graphqlfunc.BackupAndRestoreDgraph(prodGraphUrl, restoreServiceUrl); err != nil {
return fmt.Errorf("UpgradeToJune2024V2: BackupAndRestoreDgraph: %s", err.Error())
}
}

logger.Logger.Info("--------------Completed UpgradeToJune2024V2------------------")

return nil
Expand Down

0 comments on commit b9bbbbe

Please sign in to comment.