// 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 }
func RmService(do *definitions.Do) error { for _, servName := range do.Args { service, err := loaders.LoadServiceDefinition(servName, false, do.Operations.ContainerNumber) if err != nil { return err } if IsServiceExisting(service.Service, service.Operations) { err = perform.DockerRemove(service.Service, service.Operations, do.RmD) if err != nil { return err } } if do.File { oldFile := util.GetFileByNameAndType("services", servName) if err != nil { return err } oldFile = path.Join(ServicesPath, oldFile) + ".toml" logger.Printf("Removing file =>\t\t%s\n", oldFile) if err := os.Remove(oldFile); err != nil { return err } } } do.Result = "success" return nil }
func CleanUp(do *definitions.Do, dapp *definitions.Contracts) error { logger.Infof("Commensing CleanUp.\n") if do.Chain.ChainType == "throwaway" { logger.Debugf("Destroying Throwaway Chain =>\t%s\n", do.Chain.Name) doRm := definitions.NowDo() doRm.Operations = do.Operations doRm.Name = do.Chain.Name doRm.Rm = true doRm.RmD = true chains.KillChain(doRm) logger.Debugf("Removing latent files/dirs =>\t%s:%s\n", path.Join(common.DataContainersPath, do.Chain.Name), path.Join(common.BlockchainsPath, do.Chain.Name+".toml")) os.RemoveAll(path.Join(common.DataContainersPath, do.Chain.Name)) os.Remove(path.Join(common.BlockchainsPath, do.Chain.Name+".toml")) } else { logger.Debugf("No Throwaway Chain to destroy.\n") } logger.Debugf("Removing data dir on host =>\t%s\n", path.Join(common.DataContainersPath, do.Service.Name)) os.RemoveAll(path.Join(common.DataContainersPath, do.Service.Name)) logger.Debugf("Removing tmp srv contnr =>\t%s\n", do.Operations.SrvContainerName) perform.DockerRemove(do.Service, do.Operations, true) return nil }
func KillChain(do *definitions.Do) error { chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber) if err != nil { return err } if do.Force { do.Timeout = 0 //overrides 10 sec default } if IsChainRunning(chain) { if err := perform.DockerStop(chain.Service, chain.Operations, do.Timeout); err != nil { return err } } else { logger.Infoln("Chain not currently running. Skipping.") } if do.Rm { if err := perform.DockerRemove(chain.Service, chain.Operations, do.RmD, do.Volumes); err != nil { return err } } return nil }
func RmChain(do *definitions.Do) error { chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber) if err != nil { return err } if IsChainExisting(chain) { if err = perform.DockerRemove(chain.Service, chain.Operations, do.RmD, do.Volumes); err != nil { return err } } else { log.Info("Chain container does not exist") } if do.File { oldFile := util.GetFileByNameAndType("chains", do.Name) if err != nil { return err } log.WithField("file", oldFile).Warn("Removing file") if err := os.Remove(oldFile); err != nil { return err } } return nil }
func RmChain(do *definitions.Do) error { chain, err := loaders.LoadChainDefinition(do.Name, false, do.Operations.ContainerNumber) if err != nil { return err } if IsChainExisting(chain) { if err = perform.DockerRemove(chain.Service, chain.Operations, do.RmD); err != nil { return err } } else { logger.Infoln("That chain's container does not exist.") } if do.File { oldFile := util.GetFileByNameAndType("chains", do.Name) if err != nil { return err } oldFile = path.Join(BlockchainsPath, oldFile) + ".toml" logger.Printf("Removing file =>\t\t%s\n", oldFile) if err := os.Remove(oldFile); err != nil { return err } } return nil }
func RmData(do *definitions.Do) error { if util.IsDataContainer(do.Name, do.Operations.ContainerNumber) { logger.Infoln("Removing data container " + do.Name) srv := definitions.BlankServiceDefinition() srv.Operations.SrvContainerName = util.ContainersName("data", do.Name, do.Operations.ContainerNumber) err := perform.DockerRemove(srv.Service, srv.Operations, false) if err != nil { return err } } else { return fmt.Errorf("I cannot find that data container. Please check the data container name you sent me.") } if do.RmHF { logger.Println("Removing host folder " + do.Name) err := os.RemoveAll(path.Join(DataContainersPath, do.Name)) if err != nil { return err } } do.Result = "success" return nil }
func CleanUp(do *definitions.Do) error { log.Info("Cleaning up") do.Force = true if do.Chain.ChainType == "throwaway" { log.WithField("=>", do.Chain.Name).Debug("Destroying throwaway chain") doRm := definitions.NowDo() doRm.Operations = do.Operations doRm.Name = do.Chain.Name doRm.Rm = true doRm.RmD = true doRm.Volumes = true KillChain(doRm) latentDir := filepath.Join(DataContainersPath, do.Chain.Name) latentFile := filepath.Join(ChainsPath, do.Chain.Name+".toml") if doRm.Name == "default" { log.WithField("dir", latentDir).Debug("Removing latent dir") os.RemoveAll(latentDir) } else { log.WithFields(log.Fields{ "dir": latentDir, "file": latentFile, }).Debug("Removing latent dir and file") os.RemoveAll(latentDir) os.Remove(latentFile) } } else { log.Debug("No throwaway chain to destroy") } if do.RmD { log.WithField("dir", filepath.Join(DataContainersPath, do.Service.Name)).Debug("Removing data dir on host") os.RemoveAll(filepath.Join(DataContainersPath, do.Service.Name)) } if do.Rm { log.WithField("=>", do.Operations.SrvContainerName).Debug("Removing tmp service container") perform.DockerRemove(do.Service, do.Operations, true, true, false) } return nil }
func KillService(do *definitions.Do) error { var services []*definitions.ServiceDefinition for _, servName := range do.Args { s, e := BuildServicesGroup(servName, do.Operations.ContainerNumber) if e != nil { return e } services = append(services, s...) } var err error services, err = BuildChainGroup(do.ChainName, services) if err != nil { return err } // if force flag given, this will override any timeout flag if do.Force { do.Timeout = 0 } for _, service := range services { if IsServiceRunning(service.Service, service.Operations) { logger.Debugf("Stopping Service =>\t\t%s:%d\n", service.Service.Name, service.Operations.ContainerNumber) if err := perform.DockerStop(service.Service, service.Operations, do.Timeout); err != nil { return err } } else { logger.Infoln("Service not currently running. Skipping.") } if do.Rm { if err := perform.DockerRemove(service.Service, service.Operations, do.RmD); err != nil { return err } } } return nil }
func CleanUp(do *definitions.Do) error { logger.Infof("Commensing CleanUp.\n") do.Force = true if do.Chain.ChainType == "throwaway" { logger.Debugf("Destroying Throwaway Chain =>\t%s\n", do.Chain.Name) doRm := definitions.NowDo() doRm.Operations = do.Operations doRm.Name = do.Chain.Name doRm.Rm = true doRm.RmD = true doRm.Volumes = true KillChain(doRm) if doRm.Name == "default" { logger.Debugf("Removing latent files/dirs =>\t%s\n", path.Join(DataContainersPath, do.Chain.Name)) os.RemoveAll(path.Join(DataContainersPath, do.Chain.Name)) } else { logger.Debugf("Removing latent files/dirs =>\t%s:%s\n", path.Join(DataContainersPath, do.Chain.Name), path.Join(ChainsPath, do.Chain.Name+".toml")) os.RemoveAll(path.Join(DataContainersPath, do.Chain.Name)) os.Remove(path.Join(ChainsPath, do.Chain.Name+".toml")) } } else { logger.Debugf("No Throwaway Chain to destroy.\n") } if do.RmD { logger.Debugf("Removing data dir on host =>\t%s\n", path.Join(DataContainersPath, do.Service.Name)) os.RemoveAll(path.Join(DataContainersPath, do.Service.Name)) } if do.Rm { logger.Debugf("Removing tmp srv contnr =>\t%s\n", do.Operations.SrvContainerName) perform.DockerRemove(do.Service, do.Operations, true, true) } return nil }
func KillService(do *definitions.Do) (err error) { var services []*definitions.ServiceDefinition log.WithField("args", do.Operations.Args).Info("Building services group") for _, servName := range do.Operations.Args { s, e := BuildServicesGroup(servName, do.Operations.ContainerNumber) if e != nil { return e } services = append(services, s...) } // if force flag given, this will override any timeout flag if do.Force { do.Timeout = 0 } for _, service := range services { if IsServiceRunning(service.Service, service.Operations) { log.WithField("=>", fmt.Sprintf("%s:%d", service.Service.Name, service.Operations.ContainerNumber)).Debug("Stopping service") if err := perform.DockerStop(service.Service, service.Operations, do.Timeout); err != nil { return err } } else { log.WithField("=>", service.Service.Name).Info("Service not currently running. Skipping") } if do.Rm { if err := perform.DockerRemove(service.Service, service.Operations, do.RmD, do.Volumes, do.Force); err != nil { return err } } } return nil }
func CleanUp(do *definitions.Do, app *definitions.Contracts) error { log.Info("Cleaning up") if do.Chain.ChainType == "throwaway" { log.WithField("=>", do.Chain.Name).Debug("Destroying throwaway chain") doRm := definitions.NowDo() doRm.Operations = do.Operations doRm.Name = do.Chain.Name doRm.Rm = true doRm.RmD = true chains.KillChain(doRm) latentDir := filepath.Join(common.DataContainersPath, do.Chain.Name) latentFile := filepath.Join(common.ChainsPath, do.Chain.Name+".toml") log.WithFields(log.Fields{ "dir": latentDir, "file": latentFile, }).Debug("Removing latent dir and file") os.RemoveAll(latentDir) os.Remove(latentFile) } else { log.Debug("No throwaway chain to destroy") } doData := definitions.NowDo() doData.Name = do.Service.Name doData.Operations = do.Operations doData.Source = common.ErisContainerRoot if do.Path != pwd { doData.Destination = do.Path } else { doData.Destination = filepath.Join(common.DataContainersPath, doData.Name) } var loca string if do.Path != pwd { loca = filepath.Join(common.DataContainersPath, doData.Name, do.Path) } else { loca = filepath.Join(common.DataContainersPath, doData.Name, "apps", app.Name) } log.WithFields(log.Fields{ "path": doData.Source, "location": loca, }).Debug("Exporting results") data.ExportData(doData) if app.AppType.Name == "epm" { files, _ := filepath.Glob(filepath.Join(loca, "*")) for _, f := range files { dest := filepath.Join(do.Path, filepath.Base(f)) log.WithFields(log.Fields{ "from": f, "to": dest, }).Debug("Moving file") common.Copy(f, dest) } } if !do.RmD { log.WithField("dir", filepath.Join(common.DataContainersPath, do.Service.Name)).Debug("Removing data dir on host") os.RemoveAll(filepath.Join(common.DataContainersPath, do.Service.Name)) } if !do.Rm { doRemove := definitions.NowDo() doRemove.Operations.SrvContainerName = do.Operations.DataContainerName log.WithField("=>", doRemove.Operations.SrvContainerName).Debug("Removing data container") if err := perform.DockerRemove(nil, doRemove.Operations, false, true); err != nil { return err } } return nil }
func CleanUp(do *definitions.Do, app *definitions.Contracts) error { logger.Infof("Commensing CleanUp.\n") if do.Chain.ChainType == "throwaway" { logger.Debugf("Destroying Throwaway Chain =>\t%s\n", do.Chain.Name) doRm := definitions.NowDo() doRm.Operations = do.Operations doRm.Name = do.Chain.Name doRm.Rm = true doRm.RmD = true chains.KillChain(doRm) logger.Debugf("Removing latent files/dirs =>\t%s:%s\n", path.Join(common.DataContainersPath, do.Chain.Name), path.Join(common.ChainsPath, do.Chain.Name+".toml")) os.RemoveAll(path.Join(common.DataContainersPath, do.Chain.Name)) os.Remove(path.Join(common.ChainsPath, do.Chain.Name+".toml")) } else { logger.Debugf("No Throwaway Chain to destroy.\n") } doData := definitions.NowDo() doData.Name = do.Service.Name doData.Operations = do.Operations doData.Source = common.ErisContainerRoot if do.Path != pwd { doData.Destination = do.Path } else { doData.Destination = filepath.Join(common.DataContainersPath, doData.Name) } var loca string if do.Path != pwd { loca = path.Join(common.DataContainersPath, doData.Name, do.Path) } else { loca = path.Join(common.DataContainersPath, doData.Name, "apps", app.Name) } logger.Debugf("Exporting Results =>\t\t%s:%s\n", doData.Source, loca) data.ExportData(doData) if app.AppType.Name == "epm" { files, _ := filepath.Glob(filepath.Join(loca, "*")) for _, f := range files { dest := filepath.Join(do.Path, filepath.Base(f)) logger.Debugf("Moving file =>\t\t\t%s:%s\n", f, dest) common.Copy(f, dest) } } if !do.RmD { logger.Debugf("Removing data dir on host =>\t%s\n", path.Join(common.DataContainersPath, do.Service.Name)) os.RemoveAll(path.Join(common.DataContainersPath, do.Service.Name)) } if !do.Rm { doRemove := definitions.NowDo() doRemove.Operations.SrvContainerName = do.Operations.DataContainerName logger.Debugf("Removing data contnr =>\t\t%s\n", doRemove.Operations.SrvContainerName) if err := perform.DockerRemove(nil, doRemove.Operations, false, true); err != nil { return err } } return nil }