Ejemplo n.º 1
0
Archivo: push.go Proyecto: nsnt/cli
func (cmd *Push) restart(app cf.Application, params cf.AppParams, c *cli.Context) {
	if app.State != "stopped" {
		cmd.ui.Say("")
		app, _ = cmd.stopper.ApplicationStop(app)
	}

	cmd.ui.Say("")

	if c.Bool("no-start") {
		return
	}

	if params.Has("health_check_timeout") {
		timeout := params.Get("health_check_timeout").(int)
		cmd.starter.SetStartTimeoutSeconds(timeout)
	}

	cmd.starter.ApplicationStart(app)
}
Ejemplo n.º 2
0
Archivo: push.go Proyecto: nsnt/cli
func (cmd *Push) createApp(appParams cf.AppParams) (app cf.Application, apiResponse net.ApiResponse) {
	appParams.Set("space_guid", cmd.config.SpaceFields.Guid)

	cmd.ui.Say("Creating app %s in org %s / space %s as %s...",
		terminal.EntityNameColor(appParams.Get("name").(string)),
		terminal.EntityNameColor(cmd.config.OrganizationFields.Name),
		terminal.EntityNameColor(cmd.config.SpaceFields.Name),
		terminal.EntityNameColor(cmd.config.Username()),
	)

	app, apiResponse = cmd.appRepo.Create(appParams)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")

	return
}
Ejemplo n.º 3
0
func (repo CloudControllerApplicationRepository) formatAppJSON(input cf.AppParams) (data string, apiResponse net.ApiResponse) {
	params := generic.NewMap()
	for _, allowedKey := range allowedAppKeys {
		if input.Has(allowedKey) {
			params.Set(allowedKey, input.Get(allowedKey))
		}
	}

	if params.Has("command") && params.Get("command").(string) == "null" {
		params.Set("command", "")
	} else if params.Has("command") {
		params.Set("command", stringOrNull(params.Get("command")))
	}

	if params.Has("buildpack") {
		params.Set("buildpack", stringOrNull(params.Get("buildpack")))
	}

	if params.Has("stack_guid") {
		params.Set("stack_guid", stringOrNull(params.Get("stack_guid")))
	}

	if params.Has("state") {
		params.Set("state", strings.ToUpper(params.Get("state").(string)))
	}

	if params.Has("name") {
		reg := regexp.MustCompile("^[0-9a-zA-Z\\-_]*$")
		if !reg.MatchString(params.Get("name").(string)) {
			apiResponse = net.NewApiResponseWithMessage("App name is invalid: name can only contain letters, numbers, underscores and hyphens")
			return
		}
	}

	vals := []string{}

	if !params.IsEmpty() {
		vals = append(vals, mapToJsonValues(params)...)
	}
	if input.Has("env") {
		envVars := input.Get("env").(generic.Map)
		if !envVars.IsEmpty() {
			envVal := fmt.Sprintf(`"environment_json":{%s}`, strings.Join(mapToJsonValues(envVars), ","))
			vals = append(vals, envVal)
		}

	}
	data = fmt.Sprintf("{%s}", strings.Join(vals, ","))
	return
}
Ejemplo n.º 4
0
Archivo: push.go Proyecto: nsnt/cli
func (cmd *Push) app(appParams cf.AppParams) (app cf.Application, didCreate bool) {
	if !appParams.Has("name") {
		cmd.ui.Failed("Error: No name found for app")
		return
	}

	appName := appParams.Get("name").(string)
	app, apiResponse := cmd.appRepo.Read(appName)
	if apiResponse.IsError() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	if apiResponse.IsNotFound() {
		app, apiResponse = cmd.createApp(appParams)
		if apiResponse.IsNotSuccessful() {
			cmd.ui.Failed(apiResponse.Message)
			return
		}
		didCreate = true
	}

	return
}
Ejemplo n.º 5
0
Archivo: push.go Proyecto: pmuellr/cli
func createAppSetFromContextAndManifest(contextParams cf.AppParams, rootAppPath string, m *manifest.Manifest) (appSet cf.AppSet, err error) {
	if contextParams.Has("name") && len(m.Applications) > 1 {
		err = errors.New("APP_NAME command line argument is not allowed when pushing multiple apps from a manifest file.")
		return
	}

	appSet = make([]cf.AppParams, 0, len(m.Applications))
	if len(m.Applications) == 0 {
		appSet = append(appSet, contextParams)
	} else {
		for _, manifestAppParams := range m.Applications {
			appFields := cf.NewAppParams(generic.Merge(manifestAppParams, contextParams))

			path := rootAppPath
			if manifestAppParams.Has("path") {
				pathFromManifest := manifestAppParams.Get("path").(string)
				if filepath.IsAbs(pathFromManifest) {
					path = filepath.Clean(pathFromManifest)
				} else {
					path = filepath.Join(rootAppPath, pathFromManifest)
				}
			}
			appFields.Set("path", path)

			appSet = append(appSet, appFields)
		}
	}

	for _, appParams := range appSet {
		if !appParams.Has("name") {
			err = errors.New("app name is a required field")
		}
	}

	return
}
Ejemplo n.º 6
0
Archivo: push.go Proyecto: nsnt/cli
func (cmd *Push) fetchStackGuid(appParams cf.AppParams) {
	if !appParams.Has("stack") {
		return
	}

	stackName := appParams.Get("stack").(string)
	cmd.ui.Say("Using stack %s...", terminal.EntityNameColor(stackName))

	stack, apiResponse := cmd.stackRepo.FindByName(stackName)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	appParams.Set("stack_guid", stack.Guid)
}
Ejemplo n.º 7
0
func (repo CloudControllerApplicationRepository) formatAppJSON(input cf.AppParams) (data string, apiResponse net.ApiResponse) {
	params := generic.NewMap()
	for _, allowedKey := range allowedAppKeys {
		if input.Has(allowedKey) {
			params.Set(allowedKey, input.Get(allowedKey))
		}
	}

	if params.Has("buildpack") {
		params.Set("buildpack", stringOrNull(params.Get("buildpack")))
	}

	if params.Has("stack_guid") {
		params.Set("stack_guid", stringOrNull(params.Get("stack_guid")))
	}

	if params.Has("state") {
		params.Set("state", strings.ToUpper(params.Get("state").(string)))
	}

	vals := []string{}

	if !params.IsEmpty() {
		vals = append(vals, mapToJsonValues(params)...)
	}
	if input.Has("env") {
		envVars := input.Get("env").(generic.Map)
		if !envVars.IsEmpty() {
			envVal := fmt.Sprintf(`"environment_json":{%s}`, strings.Join(mapToJsonValues(envVars), ","))
			vals = append(vals, envVal)
		}

	}
	data = fmt.Sprintf("{%s}", strings.Join(vals, ","))
	return
}
Ejemplo n.º 8
0
Archivo: push.go Proyecto: nsnt/cli
func (cmd *Push) bindAppToRoute(app cf.Application, params cf.AppParams, c *cli.Context) {
	if c.Bool("no-route") {
		return
	}

	if params.Has("no-route") && params.Get("no-route") == true {
		cmd.ui.Say("App %s is a worker, skipping route creation", terminal.EntityNameColor(app.Name))
		return
	}

	routeFlagsPresent := c.String("n") != "" || c.String("d") != "" || c.Bool("no-hostname")
	if len(app.Routes) > 0 && !routeFlagsPresent {
		return
	}

	var defaultHostname string
	if params.Has("host") {
		defaultHostname = params.Get("host").(string)
	} else {
		defaultHostname = hostNameForString(app.Name)
	}

	var domainName string
	if params.Has("domain") {
		domainName = params.Get("domain").(string)
	} else {
		domainName = c.String("d")
	}

	hostName := cmd.hostname(c, defaultHostname)
	domain := cmd.domain(c, domainName)
	route := cmd.route(hostName, domain.DomainFields)

	for _, boundRoute := range app.Routes {
		if boundRoute.Guid == route.Guid {
			return
		}
	}

	cmd.ui.Say("Binding %s to %s...", terminal.EntityNameColor(domain.UrlForHost(hostName)), terminal.EntityNameColor(app.Name))

	apiResponse := cmd.routeRepo.Bind(route.Guid, app.Guid)
	if apiResponse.IsNotSuccessful() {
		cmd.ui.Failed(apiResponse.Message)
		return
	}

	cmd.ui.Ok()
	cmd.ui.Say("")
}
Ejemplo n.º 9
0
func (repo *FakeApplicationRepository) Create(params cf.AppParams) (resultApp cf.Application, apiResponse net.ApiResponse) {
	if repo.CreateAppParams == nil {
		repo.CreateAppParams = []cf.AppParams{}
	}

	repo.CreateAppParams = append(repo.CreateAppParams, params)

	resultApp.Guid = params.Get("name").(string) + "-guid"
	resultApp.Name = params.Get("name").(string)
	resultApp.State = "stopped"
	resultApp.EnvironmentVars = map[string]string{}

	if params.NotNil("space_guid") {
		resultApp.SpaceGuid = params.Get("space_guid").(string)
	}
	if params.NotNil("buildpack") {
		resultApp.BuildpackUrl = params.Get("buildpack").(string)
	}
	if params.NotNil("command") {
		resultApp.Command = params.Get("command").(string)
	}
	if params.NotNil("disk_quota") {
		resultApp.DiskQuota = params.Get("disk_quota").(uint64)
	}
	if params.NotNil("instances") {
		resultApp.InstanceCount = params.Get("instances").(int)
	}
	if params.NotNil("memory") {
		resultApp.Memory = params.Get("memory").(uint64)
	}

	if params.NotNil("env") {
		envVars := params.Get("env").(generic.Map)
		generic.Each(envVars, func(key, val interface{}) {
			resultApp.EnvironmentVars[key.(string)] = val.(string)
		})
	}
	return
}