github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/actor/pushaction/application.go (about) 1 package pushaction 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/actor/v2action" 8 log "github.com/sirupsen/logrus" 9 ) 10 11 type Application struct { 12 v2action.Application 13 Stack v2action.Stack 14 } 15 16 func (app Application) String() string { 17 return fmt.Sprintf("%s, Stack Name: '%s'", app.Application, app.Stack.Name) 18 } 19 20 func (app *Application) SetStack(stack v2action.Stack) { 21 app.Stack = stack 22 app.StackGUID = stack.GUID 23 } 24 25 func (actor Actor) CreateOrUpdateApp(config ApplicationConfig) (ApplicationConfig, Event, Warnings, error) { 26 log.Debugf("creating or updating application") 27 if config.UpdatingApplication() { 28 app := config.DesiredApplication.Application 29 30 // Apps updates with both docker image and stack guids fail. So do not send 31 // StackGUID unless it is necessary. 32 if config.CurrentApplication.StackGUID == config.DesiredApplication.StackGUID { 33 app.StackGUID = "" 34 } 35 log.Debugf("updating application: %#v", app) 36 app, warnings, err := actor.V2Actor.UpdateApplication(app) 37 if err != nil { 38 log.Errorln("updating application:", err) 39 return ApplicationConfig{}, "", Warnings(warnings), err 40 } 41 42 config.DesiredApplication.Application = app 43 config.CurrentApplication = config.DesiredApplication 44 return config, UpdatedApplication, Warnings(warnings), err 45 } else { 46 log.Debugf("creating application: %#v", config.DesiredApplication) 47 app, warnings, err := actor.V2Actor.CreateApplication(config.DesiredApplication.Application) 48 if err != nil { 49 log.Errorln("creating application:", err) 50 return ApplicationConfig{}, "", Warnings(warnings), err 51 } 52 53 config.DesiredApplication.Application = app 54 config.CurrentApplication = config.DesiredApplication 55 return config, CreatedApplication, Warnings(warnings), err 56 } 57 } 58 59 func (actor Actor) FindOrReturnPartialApp(appName string, spaceGUID string) (bool, Application, v2action.Warnings, error) { 60 foundApp, appWarnings, err := actor.V2Actor.GetApplicationByNameAndSpace(appName, spaceGUID) 61 if _, ok := err.(actionerror.ApplicationNotFoundError); ok { 62 log.Warnf("unable to find app %s in current space (GUID: %s)", appName, spaceGUID) 63 return false, Application{ 64 Application: v2action.Application{ 65 Name: appName, 66 SpaceGUID: spaceGUID, 67 }, 68 }, appWarnings, nil 69 } else if err != nil { 70 log.WithField("appName", appName).Error("error retrieving app") 71 return false, Application{}, appWarnings, err 72 } 73 74 stack, stackWarnings, err := actor.V2Actor.GetStack(foundApp.StackGUID) 75 warnings := append(appWarnings, stackWarnings...) 76 if err != nil { 77 log.Warnf("unable to find app's stack (GUID: %s)", foundApp.StackGUID) 78 return false, Application{}, warnings, err 79 } 80 81 app := Application{ 82 Application: foundApp, 83 Stack: stack, 84 } 85 return true, app, warnings, err 86 }