本文整理匯總了Golang中github.com/catalyzeio/cli/commands/services.IServices類的典型用法代碼示例。如果您正苦於以下問題:Golang IServices類的具體用法?Golang IServices怎麽用?Golang IServices使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了IServices類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CmdList
func CmdList(databaseName string, page, pageSize int, id IDb, is services.IServices) error {
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
jobs, err := id.List(page, pageSize, service)
if err != nil {
return err
}
sort.Sort(SortedJobs(*jobs))
for _, job := range *jobs {
logrus.Printf("%s %s (status = %s)", job.ID, job.CreatedAt, job.Status)
}
if len(*jobs) == pageSize && page == 1 {
logrus.Println("(for older backups, try with --page 2 or adjust --page-size)")
}
if len(*jobs) == 0 && page == 1 {
logrus.Println("No backups created yet for this service.")
} else if len(*jobs) == 0 {
logrus.Println("No backups found with the given parameters.")
}
return nil
}
示例2: CmdDeploy
func CmdDeploy(svcName, target string, iw IWorker, is services.IServices, ij jobs.IJobs) error {
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services list\" command.", svcName)
}
logrus.Printf("Initiating a worker for service %s (procfile target = \"%s\")", svcName, target)
workers, err := iw.Retrieve(service.ID)
if err != nil {
return err
}
if _, ok := workers.Workers[target]; ok {
logrus.Printf("Worker with target %s for service %s is already running, deploying another worker", target, svcName)
}
workers.Workers[target]++
err = iw.Update(service.ID, workers)
if err != nil {
return err
}
err = ij.DeployTarget(target, service.ID)
if err != nil {
return err
}
logrus.Printf("Successfully deployed a worker for service %s with target %s", svcName, target)
return nil
}
示例3: CmdShow
func CmdShow(name string, is ISites, iservices services.IServices) error {
serviceProxy, err := iservices.RetrieveByLabel("service_proxy")
if err != nil {
return err
}
sites, err := is.List(serviceProxy.ID)
if err != nil {
return err
}
var site *models.Site
for _, s := range *sites {
if s.Name == name {
site = &s
break
}
}
if site == nil {
return fmt.Errorf("Could not find a site with the label \"%s\". You can list sites with the \"catalyze sites list\" command.", name)
}
site, err = is.Retrieve(site.ID, serviceProxy.ID)
if err != nil {
return err
}
table, err := simpletable.New(simpletable.HeadersForType(models.Site{}), []models.Site{*site})
if err != nil {
return err
}
table.Write(logrus.StandardLogger().Out)
return nil
}
示例4: CmdAdd
func CmdAdd(name, keyPath, svcName string, id IDeployKeys, is services.IServices) error {
if strings.ContainsAny(name, config.InvalidChars) {
return fmt.Errorf("Invalid SSH key name. Names must not contain the following characters: %s", config.InvalidChars)
}
if _, err := os.Stat(keyPath); os.IsNotExist(err) {
return fmt.Errorf("A file does not exist at path '%s'", keyPath)
}
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", svcName)
}
if service.Type != "code" {
return fmt.Errorf("You can only add deploy keys to code services, not %s services", service.Type)
}
key, err := ioutil.ReadFile(keyPath)
if err != nil {
return err
}
k, err := id.ParsePublicKey(key)
if err != nil {
return err
}
key = ssh.MarshalAuthorizedKey(k)
return id.Add(name, "ssh", string(key), service.ID)
}
示例5: CmdBackup
func CmdBackup(databaseName string, skipPoll bool, id IDb, is services.IServices, ij jobs.IJobs) error {
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
job, err := id.Backup(service)
if err != nil {
return err
}
logrus.Printf("Backup started (job ID = %s)", job.ID)
if !skipPoll {
// all because logrus treats print, println, and printf the same
logrus.StandardLogger().Out.Write([]byte("Polling until backup finishes."))
status, err := ij.PollTillFinished(job.ID, service.ID)
if err != nil {
return err
}
job.Status = status
logrus.Printf("\nEnded in status '%s'", job.Status)
err = id.DumpLogs("backup", job, service)
if err != nil {
return err
}
if job.Status != "finished" {
return fmt.Errorf("Job finished with invalid status %s", job.Status)
}
}
logrus.Printf("You can download your backup with the \"catalyze db download %s %s ./output_file_path\" command", databaseName, job.ID)
return nil
}
示例6: CmdSet
func CmdSet(svcName, defaultSvcID string, variables []string, iv IVars, is services.IServices) error {
if svcName != "" {
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", svcName)
}
defaultSvcID = service.ID
}
envVarsMap := make(map[string]string, len(variables))
r := regexp.MustCompile("^[a-zA-Z_]+[a-zA-Z0-9_]*$")
for _, envVar := range variables {
pieces := strings.SplitN(envVar, "=", 2)
if len(pieces) != 2 {
return fmt.Errorf("Invalid variable format. Expected <key>=<value> but got %s", envVar)
}
name, value := pieces[0], pieces[1]
if !r.MatchString(name) {
return fmt.Errorf("Invalid environment variable name '%s'. Environment variable names must only contain letters, numbers, and underscores and must not start with a number.", name)
}
envVarsMap[name] = value
}
err := iv.Set(defaultSvcID, envVarsMap)
if err != nil {
return err
}
// TODO add in the service label in the redeploy example once we take in the service label in
// this command
logrus.Println("Set. For these environment variables to take effect, you will need to redeploy your service with \"catalyze redeploy\"")
return nil
}
示例7: CmdRollback
func CmdRollback(svcName, releaseName string, ij jobs.IJobs, irs releases.IReleases, is services.IServices) error {
if strings.ContainsAny(releaseName, config.InvalidChars) {
return fmt.Errorf("Invalid release name. Names must not contain the following characters: %s", config.InvalidChars)
}
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", svcName)
}
logrus.Printf("Rolling back %s to %s", svcName, releaseName)
release, err := irs.Retrieve(releaseName, service.ID)
if err != nil {
return err
}
if release == nil {
return fmt.Errorf("Could not find a release with the name \"%s\". You can list releases for this code service with the \"catalyze releases list %s\" command.", releaseName, svcName)
}
err = ij.DeployRelease(releaseName, service.ID)
if err != nil {
return err
}
logrus.Println("Rollback successful! Check the status with \"catalyze status\" and your logging dashboard for updates.")
return nil
}
示例8: CmdDomain
// CmdDomain prints out the namespace plus domain of the given environment
func CmdDomain(envID string, ie environments.IEnvironments, is services.IServices, isites sites.ISites) error {
env, err := ie.Retrieve(envID)
if err != nil {
return err
}
serviceProxy, err := is.RetrieveByLabel("service_proxy")
if err != nil {
return err
}
sites, err := isites.List(serviceProxy.ID)
if err != nil {
return err
}
domain := ""
for _, site := range *sites {
if strings.HasPrefix(site.Name, env.Namespace) {
domain = site.Name
}
}
if domain == "" {
return errors.New("Could not determine the temporary domain name of your environment")
}
logrus.Println(domain)
return nil
}
示例9: CmdRm
func CmdRm(svcName, target string, iw IWorker, is services.IServices, ip prompts.IPrompts, ij jobs.IJobs) error {
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services list\" command.", svcName)
}
err = ip.YesNo(fmt.Sprintf("Removing the worker target %s for service %s will automatically stop all existing worker jobs with that target, would you like to proceed? (y/n) ", target, svcName))
if err != nil {
return err
}
jobs, err := ij.RetrieveByTarget(service.ID, target, 1, 1000)
if err != nil {
return err
}
for _, j := range *jobs {
err = ij.Delete(j.ID, service.ID)
if err != nil {
return err
}
}
workers, err := iw.Retrieve(service.ID)
if err != nil {
return err
}
delete(workers.Workers, target)
err = iw.Update(service.ID, workers)
if err != nil {
return err
}
logrus.Printf("Successfully removed all workers with target %s for service %s", target, svcName)
return nil
}
示例10: CmdDownload
func CmdDownload(databaseName, backupID, filePath string, force bool, id IDb, ip prompts.IPrompts, is services.IServices) error {
err := ip.PHI()
if err != nil {
return err
}
if !force {
if _, err := os.Stat(filePath); err == nil {
return fmt.Errorf("File already exists at path '%s'. Specify `--force` to overwrite", filePath)
}
} else {
os.Remove(filePath)
}
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
err = id.Download(backupID, filePath, service)
if err != nil {
return err
}
logrus.Printf("%s backup downloaded successfully to %s", databaseName, filePath)
logrus.Printf("You can also view logs for this backup with the \"catalyze db logs %s %s\" command", databaseName, backupID)
return nil
}
示例11: CmdImport
func CmdImport(databaseName, filePath, mongoCollection, mongoDatabase string, id IDb, is services.IServices, ij jobs.IJobs) error {
if _, err := os.Stat(filePath); os.IsNotExist(err) {
return fmt.Errorf("A file does not exist at path '%s'", filePath)
}
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
logrus.Printf("Backing up \"%s\" before performing the import", databaseName)
job, err := id.Backup(service)
if err != nil {
return err
}
logrus.Printf("Backup started (job ID = %s)", job.ID)
// all because logrus treats print, println, and printf the same
logrus.StandardLogger().Out.Write([]byte("Polling until backup finishes."))
status, err := ij.PollTillFinished(job.ID, service.ID)
if err != nil {
return err
}
job.Status = status
logrus.Printf("\nEnded in status '%s'", job.Status)
err = id.DumpLogs("backup", job, service)
if err != nil {
return err
}
if job.Status != "finished" {
return fmt.Errorf("Job finished with invalid status %s", job.Status)
}
logrus.Printf("Importing '%s' into %s (ID = %s)", filePath, databaseName, service.ID)
job, err = id.Import(filePath, mongoCollection, mongoDatabase, service)
if err != nil {
return err
}
// all because logrus treats print, println, and printf the same
logrus.StandardLogger().Out.Write([]byte(fmt.Sprintf("Processing import (job ID = %s).", job.ID)))
status, err = ij.PollTillFinished(job.ID, service.ID)
if err != nil {
return err
}
job.Status = status
logrus.Printf("\nImport complete (end status = '%s')", job.Status)
err = id.DumpLogs("restore", job, service)
if err != nil {
return err
}
if job.Status != "finished" {
return fmt.Errorf("Finished with invalid status %s", job.Status)
}
return nil
}
示例12: CmdConsole
func CmdConsole(svcName, command string, ic IConsole, is services.IServices) error {
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.\n", svcName)
}
return ic.Open(command, service)
}
示例13: CmdStatus
func CmdStatus(envID string, is IStatus, ie environments.IEnvironments, iservices services.IServices) error {
env, err := ie.Retrieve(envID)
if err != nil {
return err
}
svcs, err := iservices.ListByEnvID(env.ID, env.Pod)
if err != nil {
return err
}
return is.Status(env, svcs)
}
示例14: CmdWorker
func CmdWorker(svcName, defaultSvcID, target string, iw IWorker, is services.IServices, ij jobs.IJobs) error {
if svcName != "" {
service, err := is.RetrieveByLabel(svcName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services list\" command.", svcName)
}
svcName = service.Label
}
return CmdDeploy(svcName, target, iw, is, ij)
}
示例15: CmdLogs
func CmdLogs(databaseName, backupID string, id IDb, is services.IServices, ij jobs.IJobs) error {
service, err := is.RetrieveByLabel(databaseName)
if err != nil {
return err
}
if service == nil {
return fmt.Errorf("Could not find a service with the label \"%s\". You can list services with the \"catalyze services\" command.", databaseName)
}
job, err := ij.Retrieve(backupID, service.ID, false)
if err != nil {
return err
}
return id.DumpLogs("backup", job, service)
}