github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/actor/v3action/application_manifest.go (about) 1 package v3action 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 6 ) 7 8 //go:generate counterfeiter . ManifestParser 9 10 type ManifestParser interface { 11 AppNames() []string 12 RawManifest(name string) ([]byte, error) 13 } 14 15 // ApplyApplicationManifest reads in the manifest from the path and provides it 16 // to the cloud controller. 17 func (actor Actor) ApplyApplicationManifest(parser ManifestParser, spaceGUID string) (Warnings, error) { 18 var allWarnings Warnings 19 20 for _, appName := range parser.AppNames() { 21 rawManifest, err := parser.RawManifest(appName) 22 if err != nil { 23 return allWarnings, err 24 } 25 26 app, getAppWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID) 27 28 allWarnings = append(allWarnings, getAppWarnings...) 29 if err != nil { 30 return allWarnings, err 31 } 32 33 jobURL, applyManifestWarnings, err := actor.CloudControllerClient.CreateApplicationActionsApplyManifestByApplication(rawManifest, app.GUID) 34 allWarnings = append(allWarnings, applyManifestWarnings...) 35 if err != nil { 36 return allWarnings, err 37 } 38 39 pollWarnings, err := actor.CloudControllerClient.PollJob(jobURL) 40 allWarnings = append(allWarnings, pollWarnings...) 41 if err != nil { 42 if newErr, ok := err.(ccerror.JobFailedError); ok { 43 return allWarnings, actionerror.ApplicationManifestError{Message: newErr.Message} 44 } 45 return allWarnings, err 46 } 47 } 48 49 return allWarnings, nil 50 }