-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added reset, diff, modify config commands
- Loading branch information
Showing
20 changed files
with
453 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package actions | ||
|
||
var ( | ||
enableBeta bool | ||
runtime string | ||
version string | ||
instanceId string | ||
updatePolicy string | ||
skipChecksum bool | ||
forceRuntime bool | ||
runtimeArgs map[string]string | ||
) |
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
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
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
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
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
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,37 @@ | ||
package common | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"io/ioutil" | ||
"os" | ||
|
||
projectRunners "github.com/marlinprotocol/ctl2/modules/runner/relay_eth" | ||
"github.com/marlinprotocol/ctl2/types" | ||
"github.com/prometheus/common/log" | ||
) | ||
|
||
const ( | ||
ProjectID string = types.ProjectID_relay_eth | ||
) | ||
|
||
func GetResourceMetaData(projectConfig types.Project, instanceId string) (string, string, error) { | ||
resFileLocation := projectRunners.GetResourceFileLocation(projectConfig.Storage, instanceId) | ||
if _, err := os.Stat(resFileLocation); os.IsNotExist(err) { | ||
return "", "", errors.New("Cannot locate resource: " + resFileLocation) | ||
} | ||
file, err := ioutil.ReadFile(resFileLocation) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
var resourceMetaData = struct { | ||
Runner string `json:"Runner"` | ||
Version string `json:"Version"` | ||
}{} | ||
err = json.Unmarshal([]byte(file), &resourceMetaData) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
log.Debug("Resource metadata: ", resourceMetaData) | ||
return resourceMetaData.Runner, resourceMetaData.Version, nil | ||
} |
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,45 @@ | ||
package actions | ||
|
||
import ( | ||
"os" | ||
|
||
cmn "github.com/marlinprotocol/ctl2/cmd/relay/eth/common" | ||
"github.com/marlinprotocol/ctl2/types" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// AppCmd represents the registry command | ||
var ConfigApplyCmd = &cobra.Command{ | ||
Use: "apply", | ||
Short: "Apply project config modifications", | ||
Long: `Apply project config modifications`, | ||
PreRunE: ConfigTest, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var projectConfig types.Project | ||
err := viper.UnmarshalKey(cmn.ProjectID, &projectConfig) | ||
if err != nil { | ||
log.Error("Error while reading project configs: ", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
modifiedProjectID := cmn.ProjectID + "_modified" | ||
var projectConfigMod types.Project | ||
if viper.IsSet(modifiedProjectID) { | ||
err = viper.UnmarshalKey(modifiedProjectID, &projectConfigMod) | ||
if err != nil { | ||
log.Error("Error while unmarshalling modifications: ", err.Error()) | ||
os.Exit(1) | ||
} | ||
} else { | ||
log.Info("No existing modifications found.") | ||
os.Exit(1) | ||
} | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
ConfigApplyCmd.Flags().BoolVar(&skipRecreate, "skip-recreate", false, "Skip recreating project's running resources while updating configs") | ||
} |
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,11 @@ | ||
package actions | ||
|
||
var ( | ||
subscriptions []string | ||
updatePolicy string | ||
currentVersion string | ||
storage string | ||
runtime string | ||
forceRuntime bool | ||
skipRecreate bool | ||
) |
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,32 @@ | ||
package actions | ||
|
||
import ( | ||
cmn "github.com/marlinprotocol/ctl2/cmd/relay/eth/common" | ||
"github.com/marlinprotocol/ctl2/types" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var ConfigTest = func(cmd *cobra.Command, args []string) error { | ||
var marlinConfig types.Project | ||
err := viper.UnmarshalKey(types.ProjectID_marlinctl, &marlinConfig) | ||
if err != nil { | ||
return err | ||
} | ||
if !viper.IsSet(cmn.ProjectID) { | ||
log.Debug("Setting up default config for running relay_eth.") | ||
updPol, ok1 := marlinConfig.AdditionalInfo["defaultprojectupdatepolicy"] | ||
defRun, ok2 := marlinConfig.AdditionalInfo["defaultprojectruntime"] | ||
if ok1 && ok2 { | ||
SetupConfiguration(false, | ||
false, | ||
updPol.(string), | ||
defRun.(string), | ||
"latest") | ||
} | ||
} else { | ||
log.Debug("Project config found. Not creating defaults.") | ||
} | ||
return nil | ||
} |
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,45 @@ | ||
package actions | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
cmn "github.com/marlinprotocol/ctl2/cmd/relay/eth/common" | ||
"github.com/marlinprotocol/ctl2/modules/util" | ||
"github.com/marlinprotocol/ctl2/types" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// AppCmd represents the registry command | ||
var ConfigDiffCmd = &cobra.Command{ | ||
Use: "diff", | ||
Short: "Show difference between current project configs and modifications", | ||
Long: `Show difference between current project configs and modifications`, | ||
PreRunE: ConfigTest, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var projectConfig types.Project | ||
err := viper.UnmarshalKey(cmn.ProjectID, &projectConfig) | ||
if err != nil { | ||
log.Error("Error while reading project configs: ", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
modifiedProjectID := cmn.ProjectID + "_modified" | ||
var projectConfigMod types.Project | ||
if viper.IsSet(modifiedProjectID) { | ||
err = viper.UnmarshalKey(modifiedProjectID, &projectConfigMod) | ||
if err != nil { | ||
log.Error("Error while unmarshalling modifications: ", err.Error()) | ||
os.Exit(1) | ||
} | ||
} else { | ||
log.Info("No existing modifications found.") | ||
os.Exit(1) | ||
} | ||
|
||
log.Info("Difference:") | ||
util.PrintPrettyDiff(cmp.Diff(projectConfig, projectConfigMod)) | ||
}, | ||
} |
Oops, something went wrong.