-
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 beacon and relay_eth, yet to test
- Loading branch information
Showing
23 changed files
with
1,950 additions
and
39 deletions.
There are no files selected for viewing
71 changes: 34 additions & 37 deletions
71
cmd/gateway/iris/actions/configure.go → cmd/beacon/actions/common.go
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,88 @@ | ||
/* | ||
Copyright © 2020 NAME HERE <EMAIL ADDRESS> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package actions | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/marlinprotocol/ctl2/modules/registry" | ||
projectRunners "github.com/marlinprotocol/ctl2/modules/runner/beacon" | ||
"github.com/marlinprotocol/ctl2/types" | ||
) | ||
|
||
// AppCmd represents the registry command | ||
var CreateCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: `Create a beacon on local system`, | ||
PreRunE: ConfigTest, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var projectConfig types.Project | ||
err := viper.UnmarshalKey(projectId, &projectConfig) | ||
if err != nil { | ||
log.Error("Error while reading project config: ", err) | ||
return | ||
} | ||
versionToRun, err := registry.GlobalRegistry.GetVersionToRun(projectId, updatePolicy, version) | ||
if err != nil { | ||
log.Error("Error while getting version to run: ", err) | ||
return | ||
} | ||
|
||
runner, err := projectRunners.GetRunnerInstance(versionToRun.RunnerId, versionToRun.Version, projectConfig.Storage, versionToRun.RunnerData, false, skipChecksum, instanceId) | ||
if err != nil { | ||
log.Error("Cannot get runner: ", err.Error()) | ||
return | ||
} | ||
|
||
err = runner.PreRunSanity() | ||
if err != nil { | ||
log.Error("Failure during pre run sanity: ", err.Error()) | ||
return | ||
} | ||
|
||
err = runner.Prepare() | ||
if err != nil { | ||
log.Error("Failure during preparation: ", err.Error()) | ||
return | ||
} | ||
|
||
err = runner.Create(runtimeArgs) | ||
if err != nil { | ||
log.Error("Failure during start: ", err.Error()) | ||
return | ||
} | ||
|
||
projectConfig.CurrentVersion = versionToRun.Version | ||
|
||
viper.Set(projectId, projectConfig) | ||
err = viper.WriteConfig() | ||
if err != nil { | ||
log.Error("Failure while updating config for current version: ", err.Error()) | ||
return | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
runtimeArgs = make(map[string]string) | ||
CreateCmd.Flags().StringVarP(&version, "runtime-version", "x", "", "version override") | ||
CreateCmd.Flags().StringVarP(&updatePolicy, "update-policy", "u", "", "update policy override") | ||
CreateCmd.Flags().StringVarP(&instanceId, "instance-id", "i", "001", "instance-id of the resource") | ||
CreateCmd.Flags().BoolVarP(&skipChecksum, "skip-checksum", "s", false, "skips checking file integrity during run") | ||
CreateCmd.Flags().StringToStringVarP(&runtimeArgs, "runtime-arguments", "r", map[string]string{}, "runtime arguments for beacon") | ||
} |
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,103 @@ | ||
/* | ||
Copyright © 2020 NAME HERE <EMAIL ADDRESS> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package actions | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"io/ioutil" | ||
"os" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
|
||
projectRunners "github.com/marlinprotocol/ctl2/modules/runner/beacon" | ||
"github.com/marlinprotocol/ctl2/types" | ||
) | ||
|
||
// AppCmd represents the registry command | ||
var DestroyCmd = &cobra.Command{ | ||
Use: "destroy", | ||
Short: "Destroy any running beacon", | ||
Long: `Destroy any running beacon`, | ||
PreRunE: ConfigTest, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var projectConfig types.Project | ||
err := viper.UnmarshalKey(projectId, &projectConfig) | ||
if err != nil { | ||
log.Error("Error while reading project config: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
runnerId, version, err := getResourceMetaData(projectConfig, instanceId) | ||
if err != nil { | ||
log.Error("Error while fetching resource information: ", err) | ||
os.Exit(1) | ||
} | ||
|
||
runner, err := projectRunners.GetRunnerInstance(runnerId, version, projectConfig.Storage, struct{}{}, true, true, instanceId) | ||
if err != nil { | ||
log.Error("Cannot get runner: ", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
err = runner.PreRunSanity() | ||
if err != nil { | ||
log.Error("Failure during pre run sanity: ", err.Error()) | ||
return | ||
} | ||
|
||
err = runner.Destroy() | ||
if err != nil { | ||
log.Error("Failure during destroy: ", err.Error()) | ||
log.Warning("Destroy failure can occur when creation and destruction of processes is done manually and not all through marlinctl." + | ||
" Failure may not reflect current process state.") | ||
return | ||
} | ||
|
||
err = runner.PostRun() | ||
if err != nil { | ||
log.Error("Failure during post run: ", err.Error()) | ||
return | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
DestroyCmd.Flags().StringVarP(&instanceId, "instance-id", "i", "001", "instance-id of the resource") | ||
} | ||
|
||
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,54 @@ | ||
/* | ||
Copyright © 2020 NAME HERE <EMAIL ADDRESS> | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package actions | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/marlinprotocol/ctl2/modules/registry" | ||
"github.com/marlinprotocol/ctl2/types" | ||
log "github.com/sirupsen/logrus" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// AppCmd represents the registry command | ||
var ListVersionsCmd = &cobra.Command{ | ||
Use: "listversions", | ||
Short: "List versions for beacon", | ||
Long: `List versions for beacon`, | ||
PreRunE: ConfigTest, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
var projectConfig types.Project | ||
err := viper.UnmarshalKey(projectId, &projectConfig) | ||
if err != nil { | ||
log.Error("Error while reading project config: ", err) | ||
os.Exit(1) | ||
} | ||
versions, err := registry.GlobalRegistry.GetVersions(projectId, projectConfig.Subscription, "0.0.0", "major", projectConfig.Runtime) | ||
|
||
if err != nil { | ||
log.Error("Error encountered while listing versions: ", err) | ||
return | ||
} | ||
|
||
registry.GlobalRegistry.PrettyPrintProjectVersions(versions) | ||
}, | ||
} | ||
|
||
func init() { | ||
} |
Oops, something went wrong.