func ConnectToAService(srv *definitions.ServiceDefinition, dep string) { // Automagically provide links to serviceDeps so they can easily // find each other using Docker's automagical modifications to // /etc/hosts newLink := util.ServiceContainersName(dep, srv.Operations.ContainerNumber) + ":" + dep srv.Service.Links = append(srv.Service.Links, newLink) // Automagically mount VolumesFrom for serviceDeps so they can // easily pass files back and forth newVol := util.ServiceContainersName(dep, srv.Operations.ContainerNumber) + ":rw" // for now mounting as "rw" srv.Service.VolumesFrom = append(srv.Service.VolumesFrom, newVol) }
func linkAppToChain(do *definitions.Do, app *definitions.Contracts) { var newLink string if do.Chain.ChainType == "service" { newLink = util.ServiceContainersName(app.ChainName, do.Operations.ContainerNumber) + ":" + "chain" } else { newLink = util.ChainContainersName(app.ChainName, do.Operations.ContainerNumber) + ":" + "chain" } newLink2 := util.ServiceContainersName("keys", do.Operations.ContainerNumber) + ":" + "keys" do.Service.Links = append(do.Service.Links, newLink) do.Service.Links = append(do.Service.Links, newLink2) }
func testExistAndRun(t *testing.T, servName string, containerNumber int, toExist, toRun bool) { var exist, run bool logger.Infof("\nTesting whether (%s) is running? (%t) and existing? (%t)\n", servName, toRun, toExist) servName = util.ServiceContainersName(servName, containerNumber) do := def.NowDo() do.Quiet = true do.Args = []string{"testing"} if err := ListExisting(do); err != nil { logger.Errorln(err) fatal(t, err) } res := strings.Split(do.Result, "\n") for _, r := range res { logger.Debugf("Existing =>\t\t\t%s\n", r) if r == util.ContainersShortName(servName) { exist = true } } do = def.NowDo() do.Quiet = true do.Args = []string{"testing"} if err := ListRunning(do); err != nil { logger.Errorln(err) fatal(t, err) } res = strings.Split(do.Result, "\n") for _, r := range res { logger.Debugf("Running =>\t\t\t%s\n", r) if r == util.ContainersShortName(servName) { run = true } } if toExist != exist { if toExist { logger.Printf("Could not find an existing =>\t%s\n", servName) } else { logger.Printf("Found an existing instance of %s when I shouldn't have\n", servName) } fatal(t, nil) } if toRun != run { if toRun { logger.Printf("Could not find a running =>\t%s\n", servName) } else { logger.Printf("Found a running instance of %s when I shouldn't have\n", servName) } fatal(t, nil) } logger.Infoln("All good.\n") }
// These are things we want to *always* control. Should be last // called before a return... func ServiceFinalizeLoad(srv *definitions.ServiceDefinition) { // If no name use image name if srv.Name == "" { logger.Debugf("Service definition has no name. ") if srv.Service.Name != "" { logger.Debugf("Defaulting to service name =>\t%s\n", srv.Service.Name) srv.Name = srv.Service.Name } else { if srv.Service.Image != "" { srv.Name = strings.Replace(srv.Service.Image, "/", "_", -1) srv.Service.Name = srv.Name logger.Debugf("Defaulting to image name =>\t%s\n", srv.Name) } else { panic("Service's Image should have been set before reaching ServiceFinalizeLoad") } } } container := util.FindServiceContainer(srv.Name, srv.Operations.ContainerNumber, true) if container != nil { logger.Debugf("Setting SrvCont Names =>\t%s:%s\n", container.FullName, container.ContainerID) srv.Operations.SrvContainerName = container.FullName srv.Operations.SrvContainerID = container.ContainerID } else { srv.Operations.SrvContainerName = util.ServiceContainersName(srv.Name, srv.Operations.ContainerNumber) srv.Operations.DataContainerName = util.ServiceToDataContainer(srv.Operations.SrvContainerName) } if srv.Service.AutoData { dataContainer := util.FindDataContainer(srv.Name, srv.Operations.ContainerNumber) if dataContainer != nil { logger.Debugf("Setting DataCont Names =>\t%s:%s\n", dataContainer.FullName, dataContainer.ContainerID) srv.Operations.DataContainerName = dataContainer.FullName srv.Operations.DataContainerID = dataContainer.ContainerID } else { srv.Operations.SrvContainerName = util.ServiceContainersName(srv.Name, srv.Operations.ContainerNumber) srv.Operations.DataContainerName = util.ServiceToDataContainer(srv.Operations.SrvContainerName) } } }
// These are things we want to *always* control. Should be last // called before a return... func ServiceFinalizeLoad(srv *definitions.ServiceDefinition) { if srv.Name == "" && srv.Service.Name == "" && srv.Service.Image == "" { // If no name or image, panic panic("Service's Image should have been set before reaching ServiceFinalizeLoad") } else if srv.Name == "" && srv.Service.Name == "" && srv.Service.Image != "" { // If no name use image srv.Name = strings.Replace(srv.Service.Image, "/", "_", -1) srv.Service.Name = srv.Name log.WithField("image", srv.Name).Debug("Defaulting to image") } else if srv.Service.Name != "" && srv.Name == "" { // harmonize names srv.Name = srv.Service.Name log.WithField("service", srv.Service.Name).Debug("Defaulting to service") } else if srv.Service.Name == "" && srv.Name != "" { srv.Service.Name = srv.Name log.WithField("service", srv.Name).Debug("Defaulting to service") } container := util.FindServiceContainer(srv.Name, srv.Operations.ContainerNumber, true) if container != nil { log.WithField("=>", container.FullName).Debug("Setting service container name") srv.Operations.SrvContainerName = container.FullName srv.Operations.SrvContainerID = container.ContainerID } else { srv.Operations.SrvContainerName = util.ServiceContainersName(srv.Name, srv.Operations.ContainerNumber) srv.Operations.DataContainerName = util.ServiceToDataContainer(srv.Operations.SrvContainerName) } if srv.Service.AutoData { dataContainer := util.FindDataContainer(srv.Name, srv.Operations.ContainerNumber) if dataContainer != nil { log.WithField("=>", dataContainer.FullName).Debug("Setting data container name") srv.Operations.DataContainerName = dataContainer.FullName srv.Operations.DataContainerID = dataContainer.ContainerID } else { srv.Operations.SrvContainerName = util.ServiceContainersName(srv.Name, srv.Operations.ContainerNumber) srv.Operations.DataContainerName = util.ServiceToDataContainer(srv.Operations.SrvContainerName) } } }
//return to handle failings in each pkg //typ = type of test for dealing with do.() details func TestExistAndRun(name, typ string, contNum int, toExist, toRun bool) bool { var exist, run bool if typ == "actions" { name = strings.Replace(name, " ", "_", -1) // dirty } //logger.Infof("\nTesting whether (%s) existing? (%t)\n", name, toExist) logger.Infof("\nTesting whether (%s) is running? (%t) and existing? (%t)\n", name, toRun, toExist) if typ == "chains" { name = util.ChainContainersName(name, 1) // not worried about containerNumbers, deal with multiple containers in services tests } else if typ == "services" { name = util.ServiceContainersName(name, contNum) } else { name = util.DataContainersName(name, 1) } do := def.NowDo() do.Quiet = true do.Operations.Args = []string{"testing"} if typ == "data" || typ == "chains" || typ == "services" { do.Existing = true } else if typ == "actions" { do.Known = true } if err := util.ListAll(do, typ); err != nil { logger.Errorln(err) return true } res := strings.Split(do.Result, "\n") for _, r := range res { logger.Debugf("Existing =>\t\t\t%s\n", r) if r == util.ContainersShortName(name) { exist = true } } if toExist != exist { if toExist { logger.Infof("Could not find an existing =>\t%s\n", name) } else { logger.Infof("Found an existing instance of %s when I shouldn't have\n", name) } return true } //func should always be testing for toExist, only sometimes tested for runining if typ == "chains" || typ == "services" { do.Running = true do.Existing = false //unset if err := util.ListAll(do, typ); err != nil { return true } logger.Debugln("RUNNING RESULT:", do.Result) res = strings.Split(do.Result, "\n") for _, r := range res { logger.Debugf("Running =>\t\t\t%s\n", r) if r == util.ContainersShortName(name) { run = true } } if toRun != run { if toRun { logger.Infof("Could not find a running =>\t%s\n", name) } else { logger.Infof("Found a running instance of %s when I shouldn't have\n", name) } return true } } return false }
// MakeChain runs the `eris-cm make` command in a docker container. // It returns an error. Note that if do.Known, do.AccountTypes // or do.ChainType are not set the command will run via interactive // shell. // // do.Name - name of the chain to be created (required) // do.Known - will use the mintgen tool to parse csv's and create a genesis.json (requires do.ChainMakeVals and do.ChainMakeActs) (optional) // do.ChainMakeVals - csv file to use for validators (optional) // do.ChainMakeActs - csv file to use for accounts (optional) // do.AccountTypes - use eris-cm make account-types paradigm (example: Root:1,Participants:25,...) (optional) // do.ChainType - use eris-cm make chain-types paradigm (example: simplechain) (optional) // do.Tarball - instead of outputing raw files in directories, output packages of tarbals (optional) // do.ZipFile - similar to do.Tarball except uses zipfiles (optional) // do.Verbose - verbose output (optional) // do.Debug - debug output (optional) // func MakeChain(do *definitions.Do) error { do.Service.Name = do.Name do.Service.Image = path.Join(version.ERIS_REG_DEF, version.ERIS_IMG_CM) do.Service.User = "******" do.Service.AutoData = true do.Service.Links = []string{fmt.Sprintf("%s:%s", util.ServiceContainersName("keys", do.Operations.ContainerNumber), "keys")} do.Service.Environment = []string{ fmt.Sprintf("ERIS_KEYS_PATH=http://keys:%d", 4767), // note, needs to be made aware of keys port... fmt.Sprintf("ERIS_CHAINMANAGER_ACCOUNTTYPES=%s", strings.Join(do.AccountTypes, ",")), fmt.Sprintf("ERIS_CHAINMANAGER_CHAINTYPE=%s", do.ChainType), fmt.Sprintf("ERIS_CHAINMANAGER_TARBALLS=%v", do.Tarball), fmt.Sprintf("ERIS_CHAINMANAGER_ZIPFILES=%v", do.ZipFile), fmt.Sprintf("ERIS_CHAINMANAGER_OUTPUT=%v", do.Output), fmt.Sprintf("ERIS_CHAINMANAGER_VERBOSE=%v", do.Verbose), fmt.Sprintf("ERIS_CHAINMANAGER_DEBUG=%v", do.Debug), } do.Operations.ContainerType = "service" do.Operations.SrvContainerName = util.ServiceContainersName(do.Name, do.Operations.ContainerNumber) do.Operations.DataContainerName = util.DataContainersName(do.Name, do.Operations.ContainerNumber) if do.RmD { do.Operations.Remove = true } if do.Known { log.Debug("Using MintGen rather than eris:cm") do.Service.EntryPoint = "mintgen" do.Service.Command = fmt.Sprintf("known %s --csv=%s,%s > %s", do.Name, do.ChainMakeVals, do.ChainMakeActs, path.Join(ErisContainerRoot, "chains", do.Name, "genesis.json")) } else { log.Debug("Using eris:cm rather than MintGen") do.Service.EntryPoint = fmt.Sprintf("eris-cm make %s", do.Name) } if !do.Known && len(do.AccountTypes) == 0 && do.ChainType == "" { do.Operations.Interactive = true do.Operations.Args = strings.Split(do.Service.EntryPoint, " ") } if do.Known { do.Operations.Args = append(do.Operations.Args, strings.Split(do.Service.Command, " ")...) do.Service.WorkDir = path.Join(ErisContainerRoot, "chains", do.Name) } doData := definitions.NowDo() doData.Name = do.Name doData.Operations.ContainerNumber = do.Operations.ContainerNumber doData.Operations.DataContainerName = util.DataContainersName(do.Name, do.Operations.ContainerNumber) doData.Operations.ContainerType = "service" if !do.RmD { defer data.RmData(doData) } doData.Source = AccountsTypePath doData.Destination = path.Join(ErisContainerRoot, "chains", "account-types") if err := data.ImportData(doData); err != nil { return err } doData.Source = ChainTypePath doData.Destination = path.Join(ErisContainerRoot, "chains", "chain-types") if err := data.ImportData(doData); err != nil { return err } chnPath := filepath.Join(ChainsPath, do.Name) if _, err := os.Stat(chnPath); !os.IsNotExist(err) { doData.Operations.Args = []string{"mkdir", "--parents", path.Join(ErisContainerRoot, "chains", do.Name)} if err := data.ExecData(doData); err != nil { return err } doData.Operations.Args = []string{} doData.Source = chnPath doData.Destination = path.Join(ErisContainerRoot, "chains", do.Name) if err := data.ImportData(doData); err != nil { return err } } if err := perform.DockerExecService(do.Service, do.Operations); err != nil { return err } doData.Source = path.Join(ErisContainerRoot, "chains") doData.Destination = ErisRoot return data.ExportData(doData) }