示例#1
0
// boot chain dependencies
// TODO: this currently only supports simple services (with no further dependencies)
func bootDependencies(chain *definitions.Chain, do *definitions.Do) error {
	if chain.Dependencies != nil {
		name := do.Name
		logger.Infoln("Booting chain dependencies", chain.Dependencies.Services, chain.Dependencies.Chains)
		for _, srvName := range chain.Dependencies.Services {
			do.Name = srvName
			srv, err := loaders.LoadServiceDefinition(do.Name, false, do.Operations.ContainerNumber)
			if err != nil {
				return err
			}

			// Start corresponding service.
			if !services.IsServiceRunning(srv.Service, srv.Operations) {
				name := strings.ToUpper(do.Name)
				logger.Infof("%s is not running. Starting now. Waiting for %s to become available \n", name, name)
				if err = perform.DockerRunService(srv.Service, srv.Operations); err != nil {
					return err
				}
			}

		}
		do.Name = name // undo side effects

		for _, chainName := range chain.Dependencies.Chains {
			chn, err := loaders.LoadChainDefinition(chainName, false, do.Operations.ContainerNumber)
			if err != nil {
				return err
			}
			if !IsChainRunning(chn) {
				return fmt.Errorf("chain %s depends on chain %s but %s is not running", chain.Name, chainName, chainName)
			}
		}
	}
	return nil
}
示例#2
0
文件: manage.go 项目: mxjxn/eris-cli
func RenameAction(do *definitions.Do) error {
	if do.Name == do.NewName {
		return fmt.Errorf("Cannot rename to same name")
	}

	do.Name = strings.Replace(do.Name, " ", "_", -1)
	do.NewName = strings.Replace(do.NewName, " ", "_", -1)
	act, _, err := LoadActionDefinition(do.Name)
	if err != nil {
		log.WithFields(log.Fields{
			"from": do.Name,
			"to":   do.NewName,
		}).Debug("Failed renaming action")
		return err
	}

	do.Name = strings.Replace(do.Name, " ", "_", -1)
	log.WithField("file", do.Name).Debug("Finding action definition file")
	oldFile := util.GetFileByNameAndType("actions", do.Name)
	if oldFile == "" {
		return fmt.Errorf("Could not find that action definition file.")
	}
	log.WithField("file", oldFile).Debug("Found action definition file")

	// if !strings.Contains(oldFile, ActionsPath) {
	// 	oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
	// }

	var newFile string
	newNameBase := strings.Replace(strings.Replace(do.NewName, " ", "_", -1), filepath.Ext(do.NewName), "", 1)

	if newNameBase == do.Name {
		newFile = strings.Replace(oldFile, filepath.Ext(oldFile), filepath.Ext(do.NewName), 1)
	} else {
		newFile = strings.Replace(oldFile, do.Name, do.NewName, 1)
		newFile = strings.Replace(newFile, " ", "_", -1)
	}

	if newFile == oldFile {
		log.Info("Not renaming the same file")
		return nil
	}

	act.Name = strings.Replace(newNameBase, "_", " ", -1)

	log.WithFields(log.Fields{
		"old": act.Name,
		"new": newFile,
	}).Debug("Writing new action definition file")
	err = WriteActionDefinitionFile(act, newFile)
	if err != nil {
		return err
	}

	log.WithField("file", oldFile).Debug("Removing old file")
	os.Remove(oldFile)

	return nil
}
示例#3
0
func RenameAction(do *definitions.Do) error {
	if do.Name == do.NewName {
		return fmt.Errorf("Cannot rename to same name")
	}

	do.Name = strings.Replace(do.Name, " ", "_", -1)
	do.NewName = strings.Replace(do.NewName, " ", "_", -1)
	act, _, err := LoadActionDefinition(do.Name)
	if err != nil {
		logger.Debugf("About to fail. Name:NewName =>\t%s:%s", do.Name, do.NewName)
		return err
	}

	do.Name = strings.Replace(do.Name, " ", "_", -1)
	logger.Debugf("About to find defFile =>\t%s\n", do.Name)
	oldFile := util.GetFileByNameAndType("actions", do.Name)
	if oldFile == "" {
		return fmt.Errorf("Could not find that action definition file.")
	}
	logger.Debugf("Found defFile at =>\t\t%s\n", oldFile)

	if !strings.Contains(oldFile, ActionsPath) {
		oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
	}

	var newFile string
	newNameBase := strings.Replace(strings.Replace(do.NewName, " ", "_", -1), filepath.Ext(do.NewName), "", 1)

	if newNameBase == do.Name {
		newFile = strings.Replace(oldFile, filepath.Ext(oldFile), filepath.Ext(do.NewName), 1)
	} else {
		newFile = strings.Replace(oldFile, do.Name, do.NewName, 1)
		newFile = strings.Replace(newFile, " ", "_", -1)
	}

	if newFile == oldFile {
		logger.Infoln("Those are the same file. Not renaming")
		return nil
	}

	act.Name = strings.Replace(newNameBase, "_", " ", -1)

	logger.Debugf("About to write new def file =>\t%s:%s\n", act.Name, newFile)
	err = WriteActionDefinitionFile(act, newFile)
	if err != nil {
		return err
	}

	logger.Debugf("Removing old file =>\t\t%s\n", oldFile)
	os.Remove(oldFile)

	return nil
}
示例#4
0
文件: manage.go 项目: mxjxn/eris-cli
// TODO: skip errors flag
func RmData(do *definitions.Do) (err error) {
	if len(do.Operations.Args) == 0 {
		do.Operations.Args = []string{do.Name}
	}
	for _, name := range do.Operations.Args {
		do.Name = name
		if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
			log.WithField("=>", do.Name).Info("Removing data container")

			srv := definitions.BlankServiceDefinition()
			srv.Operations.SrvContainerName = util.ContainersName("data", do.Name, do.Operations.ContainerNumber)

			if err = perform.DockerRemove(srv.Service, srv.Operations, false, do.Volumes); err != nil {
				log.Errorf("Error removing %s: %v", do.Name, err)
				return err
			}

		} else {
			err = fmt.Errorf("I cannot find that data container for %s. Please check the data container name you sent me.", do.Name)
			log.Error(err)
			return err
		}

		if do.RmHF {
			log.WithField("=>", do.Name).Warn("Removing host directory")
			if err = os.RemoveAll(filepath.Join(DataContainersPath, do.Name)); err != nil {
				return err
			}
		}
	}

	do.Result = "success"
	return err
}
示例#5
0
文件: writers.go 项目: mxjxn/eris-cli
func ImportKey(do *definitions.Do) error {

	do.Name = "keys"
	do.Operations.ContainerNumber = 1
	if err := srv.EnsureRunning(do); err != nil {
		return err
	}

	do.Operations.Interactive = false
	dir := path.Join(ErisContainerRoot, "keys", "data", do.Address)
	do.Operations.Args = []string{"mkdir", dir} //need to mkdir for import
	if err := srv.ExecService(do); err != nil {
		return err
	}
	//src on host

	if do.Source == "" {
		do.Source = filepath.Join(KeysPath, "data", do.Address, do.Address)
	}
	//dest in container
	do.Destination = dir

	if err := data.ImportData(do); err != nil {
		return err
	}
	return nil
}
示例#6
0
func MakeGenesisFile(do *def.Do) error {

	//otherwise it'll start its own keys server that won't have the key needed...
	do.Name = "keys"
	IfExit(srv.EnsureRunning(do))

	doThr := def.NowDo()
	doThr.Chain.ChainType = "throwaway" //for teardown
	doThr.Name = "default"
	doThr.Operations.ContainerNumber = 1
	doThr.Operations.PublishAllPorts = true

	logger.Infof("Starting chain from MakeGenesisFile =>\t%s\n", doThr.Name)
	if er := StartChain(doThr); er != nil {
		return fmt.Errorf("error starting chain %v\n", er)
	}

	doThr.Operations.Args = []string{"mintgen", "known", do.Chain.Name, fmt.Sprintf("--pub=%s", do.Pubkey)}
	doThr.Chain.Name = "default" //for teardown

	// pipe this output to /chains/chainName/genesis.json
	err := ExecChain(doThr)
	if err != nil {
		logger.Printf("exec chain err: %v\nCleaning up...\n", err)
		doThr.Rm = true
		doThr.RmD = true
		if err := CleanUp(doThr); err != nil {
			return err
		}
	}

	doThr.Rm = true
	doThr.RmD = true
	return CleanUp(doThr) // doesn't clean up keys but that's ~ ok b/c it's about to be used...
}
示例#7
0
文件: operate.go 项目: mxjxn/eris-cli
func bootThrowAwayChain(name string, do *definitions.Do) error {
	do.Chain.ChainType = "throwaway"

	tmp := do.Name
	do.Name = name
	err := chains.ThrowAwayChain(do)
	if err != nil {
		do.Name = tmp
		return err
	}

	do.Chain.Name = do.Name // setting this for tear down purposes
	log.WithField("=>", do.Name).Debug("Throwaway chain booted")

	do.Name = tmp
	return nil
}
示例#8
0
func NewAction(do *definitions.Do) error {
	do.Name = strings.Join(do.Args, "_")
	path := filepath.Join(ActionsPath, do.Name)
	logger.Debugf("NewActionRaw to MockAction =>\t%v:%s\n", do.Name, path)
	act, _ := MockAction(do.Name)
	if err := WriteActionDefinitionFile(act, path); err != nil {
		return err
	}
	return nil
}
示例#9
0
// boot chain dependencies
// TODO: this currently only supports simple services (with no further dependencies)
func bootDependencies(chain *definitions.Chain, do *definitions.Do) error {
	if do.Logsrotate {
		chain.Dependencies.Services = append(chain.Dependencies.Services, "logsrotate")
	}
	if chain.Dependencies != nil {
		name := do.Name
		log.WithFields(log.Fields{
			"services": chain.Dependencies.Services,
			"chains":   chain.Dependencies.Chains,
		}).Info("Booting chain dependencies")
		for _, srvName := range chain.Dependencies.Services {
			do.Name = srvName
			srv, err := loaders.LoadServiceDefinition(do.Name, false, do.Operations.ContainerNumber)
			if err != nil {
				return err
			}

			// Start corresponding service.
			if !services.IsServiceRunning(srv.Service, srv.Operations) {
				name := strings.ToUpper(do.Name)
				log.WithField("=>", name).Info("Dependency not running. Starting now")
				if err = perform.DockerRunService(srv.Service, srv.Operations); err != nil {
					return err
				}
			}

		}
		do.Name = name // undo side effects

		for _, chainName := range chain.Dependencies.Chains {
			chn, err := loaders.LoadChainDefinition(chainName, false, do.Operations.ContainerNumber)
			if err != nil {
				return err
			}
			if !IsChainRunning(chn) {
				return fmt.Errorf("chain %s depends on chain %s but %s is not running", chain.Name, chainName, chainName)
			}
		}
	}
	return nil
}
示例#10
0
文件: writers.go 项目: mxjxn/eris-cli
func ConvertKey(do *definitions.Do) error {

	do.Name = "keys"
	if err := srv.EnsureRunning(do); err != nil {
		return err
	}

	do.Operations.Args = []string{"mintkey", "mint", do.Address}
	if err := srv.ExecService(do); err != nil {
		return err
	}
	return nil
}
示例#11
0
func ExecData(do *definitions.Do) error {
	if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) {
		do.Name = util.DataContainersName(do.Name, do.Operations.ContainerNumber)
		logger.Infoln("Running exec on container with volumes from data container " + do.Name)
		if err := perform.DockerRunVolumesFromContainer(do.Name, do.Interactive, do.Args); err != nil {
			return err
		}
	} else {
		return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.")
	}
	do.Result = "success"
	return nil
}
示例#12
0
文件: manage.go 项目: mxjxn/eris-cli
func NewAction(do *definitions.Do) error {
	do.Name = strings.Join(do.Operations.Args, "_")
	path := filepath.Join(ActionsPath, do.Name)
	log.WithFields(log.Fields{
		"action": do.Name,
		"file":   path,
	}).Debug("Creating new action (mocking)")
	act, _ := MockAction(do.Name)
	if err := WriteActionDefinitionFile(act, path); err != nil {
		return err
	}
	return nil
}
示例#13
0
func PlopChain(do *definitions.Do) error {
	do.Name = do.ChainID
	rootDir := path.Join("/home/eris/.eris/blockchains", do.ChainID)
	switch do.Type {
	case "genesis":
		do.Args = []string{"cat", path.Join(rootDir, "genesis.json")}
	case "config":
		do.Args = []string{"cat", path.Join(rootDir, "config.toml")}
	case "status":
		do.Args = []string{"mintinfo", "--node-addr", "http://0.0.0.0:46657", "status"}
	default:
		return fmt.Errorf("unknown plop option %s", do.Type)
	}
	return ExecChain(do)
}
示例#14
0
// Throw away chains are used for eris contracts
func ThrowAwayChain(do *definitions.Do) error {
	do.Name = do.Name + "_" + strings.Split(uuid.New(), "-")[0]
	do.Path = filepath.Join(ChainsPath, "default")
	logger.Debugf("Making a ThrowAwayChain =>\t%s:%s\n", do.Name, do.Path)

	if err := NewChain(do); err != nil {
		return err
	}

	logger.Debugf("ThrowAwayChain created =>\t%s\n", do.Name)
	do.Run = true  // turns on edb api
	StartChain(do) // XXX [csk]: may not need to do this now that New starts....
	logger.Debugf("ThrowAwayChain started =>\t%s\n", do.Name)
	return nil
}
示例#15
0
func GenerateKey(do *definitions.Do) error {
	do.Name = "keys"
	do.Operations.ContainerNumber = 1

	if err := srv.EnsureRunning(do); err != nil {
		return err
	}
	do.Operations.Interactive = false
	do.Operations.Args = []string{"eris-keys", "gen", "--no-pass"}

	if err := srv.ExecService(do); err != nil {
		return err
	}
	return nil
}
示例#16
0
文件: writers.go 项目: mxjxn/eris-cli
func GetPubKey(do *definitions.Do) error {

	do.Name = "keys"
	do.Operations.ContainerNumber = 1
	if err := srv.EnsureRunning(do); err != nil {
		return err
	}

	do.Operations.Interactive = false
	do.Operations.Args = []string{"eris-keys", "pub", "--addr", do.Address}

	if err := srv.ExecService(do); err != nil {
		return err
	}
	return nil
}
示例#17
0
func RmAction(do *definitions.Do) error {
	do.Name = strings.Join(do.Args, "_")
	if do.File {
		oldFile := util.GetFileByNameAndType("actions", do.Name)
		if oldFile == "" {
			return nil
		}

		if !strings.Contains(oldFile, ActionsPath) {
			oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
		}

		logger.Debugf("Removing file =>\t\t%s\n", oldFile)
		os.Remove(oldFile)
	}
	return nil
}
示例#18
0
文件: manage.go 项目: mxjxn/eris-cli
func RmAction(do *definitions.Do) error {
	do.Name = strings.Join(do.Operations.Args, "_")
	if do.File {
		oldFile := util.GetFileByNameAndType("actions", do.Name)
		if oldFile == "" {
			return nil
		}

		// if !strings.Contains(oldFile, ActionsPath) {
		// 	oldFile = filepath.Join(ActionsPath, oldFile) + ".toml"
		// }

		log.WithField("file", oldFile).Debug("Removing file")
		os.Remove(oldFile)
	}
	return nil
}
示例#19
0
文件: manage.go 项目: mxjxn/eris-cli
func ImportAction(do *definitions.Do) error {
	if do.Name == "" {
		do.Name = strings.Join(do.Operations.Args, "_")
	}
	fileName := filepath.Join(ActionsPath, strings.Join(do.Operations.Args, " "))
	if filepath.Ext(fileName) == "" {
		fileName = fileName + ".toml"
	}

	s := strings.Split(do.Path, ":")
	if s[0] == "ipfs" {

		var err error
		//unset 1 as default ContainerNumber, let it take flag?
		ipfsService, err := loaders.LoadServiceDefinition("ipfs", false, 1)
		if err != nil {
			return err
		}

		ipfsService.Operations.ContainerType = definitions.TypeService
		err = perform.DockerRunService(ipfsService.Service, ipfsService.Operations)
		if err != nil {
			return err
		}

		if log.GetLevel() > 0 {
			err = ipfs.GetFromIPFS(s[1], fileName, "", os.Stdout)
		} else {
			err = ipfs.GetFromIPFS(s[1], fileName, "", bytes.NewBuffer([]byte{}))
		}

		if err != nil {
			return err
		}
		return nil
	}

	if strings.Contains(s[0], "github") {
		log.Warn("https://twitter.com/ryaneshea/status/595957712040628224")
		return nil
	}

	log.Warn("Failed to get that file. Sorry")
	return nil
}
示例#20
0
func ListKeys(do *definitions.Do) error {
	if do.Host {
		keysPath := filepath.Join(KeysPath, "data")
		addrs, err := ioutil.ReadDir(keysPath)
		if err != nil {
			return err
		}
		hostAddrs := make([]string, len(addrs))
		for i, addr := range addrs {
			hostAddrs[i] = addr.Name()
		}
		do.Result = strings.Join(hostAddrs, ",")
		log.WithField("=>", hostAddrs[0]).Warn("The keys on your host kind marmot:")
		hostAddrs = append(hostAddrs[:0], hostAddrs[1:]...)
		for _, addr := range hostAddrs {
			log.WithField("=>", addr).Warn()
		}
	}

	if do.Container {
		keysOut := new(bytes.Buffer)
		config.GlobalConfig.Writer = keysOut
		do.Name = "keys"
		do.Operations.ContainerNumber = 1
		if err := srv.EnsureRunning(do); err != nil {
			return err
		}

		do.Operations.Interactive = false
		do.Operations.Args = []string{"ls", "/home/eris/.eris/keys/data"}

		if err := srv.ExecService(do); err != nil {
			return err
		}
		keysOutString := strings.Split(util.TrimString(string(keysOut.Bytes())), "\n")
		do.Result = strings.Join(keysOutString, ",")
		log.WithField("=>", keysOutString[0]).Warn("The keys in your container kind marmot:")
		keysOutString = append(keysOutString[:0], keysOutString[1:]...)
		for _, addr := range keysOutString {
			log.WithField("=>", addr).Warn()
		}

	}
	return nil
}
示例#21
0
// Throw away chains are used for eris contracts
func ThrowAwayChain(do *definitions.Do) error {
	do.Name = do.Name + "_" + strings.Split(uuid.New(), "-")[0]
	do.Path = filepath.Join(ChainsPath, "default")
	log.WithFields(log.Fields{
		"=>":   do.Name,
		"path": do.Path,
	}).Debug("Making a throaway chain")

	if err := NewChain(do); err != nil {
		return err
	}

	log.WithField("=>", do.Name).Debug("Throwaway chain created")
	do.Run = true  // turns on edb api
	StartChain(do) // XXX [csk]: may not need to do this now that New starts....
	log.WithField("=>", do.Name).Debug("Throwaway chain started")
	return nil
}
示例#22
0
文件: writers.go 项目: mxjxn/eris-cli
func ExportKey(do *definitions.Do) error {

	do.Name = "keys"
	do.Operations.ContainerNumber = 1
	if err := srv.EnsureRunning(do); err != nil {
		return err
	}
	//destination on host
	if do.Destination == "" {
		do.Destination = filepath.Join(KeysPath, "data")
	}
	//src in container
	do.Source = path.Join(ErisContainerRoot, "keys", "data", do.Address)
	if err := data.ExportData(do); err != nil {
		return err
	}
	return nil
}
示例#23
0
文件: manage.go 项目: mxjxn/eris-cli
func PlopChain(do *definitions.Do) error {
	do.Name = do.ChainID
	rootDir := path.Join(ErisContainerRoot, "chains", do.ChainID)
	switch do.Type {
	case "genesis":
		do.Operations.Args = []string{"cat", filepath.Join(rootDir, "genesis.json")}
	case "config":
		do.Operations.Args = []string{"cat", filepath.Join(rootDir, "config.toml")}
	case "status":
		do.Operations.Args = []string{"mintinfo", "--node-addr", "http://0.0.0.0:46657", "status"}
	case "validators":
		do.Operations.Args = []string{"mintinfo", "--node-addr", "http://0.0.0.0:46657", "validators"}
	default:
		return fmt.Errorf("unknown plop option %s", do.Type)
	}
	do.Operations.PublishAllPorts = true // avoid port conflict
	log.WithField("args", do.Operations.Args).Debug("Executing command")
	return ExecChain(do)
}
示例#24
0
func PlopChain(do *definitions.Do) error {
	do.Name = do.ChainID
	rootDir := path.Join("/home/eris/.eris/chains", do.ChainID)
	switch do.Type {
	case "genesis":
		do.Operations.Args = []string{"cat", path.Join(rootDir, "genesis.json")}
	case "config":
		do.Operations.Args = []string{"cat", path.Join(rootDir, "config.toml")}
	case "status":
		do.Operations.Args = []string{"mintinfo", "--node-addr", "http://0.0.0.0:46657", "status"}
	case "validators":
		do.Operations.Args = []string{"mintinfo", "--node-addr", "http://0.0.0.0:46657", "validators"}
	default:
		return fmt.Errorf("unknown plop option %s", do.Type)
	}
	do.Operations.PublishAllPorts = true // avoid port conflict
	logger.Debugf("Execing =>\t\t\t%v\n", do.Operations.Args)
	return ExecChain(do)
}
示例#25
0
// Throw away chains are used for eris contracts
func ThrowAwayChain(do *definitions.Do) error {
	do.Name = do.Name + "_" + strings.Split(uuid.New(), "-")[0]
	do.Path = filepath.Join(ChainsConfigPath, "default")
	logger.Debugf("Making a ThrowAwayChain =>\t%s:%s\n", do.Name, do.Path)

	if err := NewChain(do); err != nil {
		return err
	}

	logger.Debugf("ThrowAwayChain created =>\t%s\n", do.Name)

	// fakeId := strings.Split(uuid.New(), "-")[0]
	// srv, err := loaders.MockChainDefinition(do.Name, fakeId, true, 1)
	// if err != nil {
	// 	return err
	// }

	StartChain(do)

	logger.Debugf("ThrowAwayChain started =>\t%s\n", do.Name)
	return nil
}