Exemplo n.º 1
0
func doServiceRedeploy(args Redeploy, app, service string) {
	path := fmt.Sprintf("/applications/%s/services/%s/redeploy", app, service)
	body, err := json.MarshalIndent(args, " ", " ")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Fatal: %s\n", err)
		return
	}

	// Attach console
	if !redeployBatch {
		internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
	}

	// Redeploy
	buffer, _, err := internal.Stream("POST", path, body)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err)
		os.Exit(1)
	}

	line, err := internal.DisplayStream(buffer)
	internal.Check(err)
	if len(line) > 0 {
		var data map[string]interface{}
		err = json.Unmarshal(line, &data)
		internal.Check(err)

		fmt.Printf("Hostname: %v\n", data["hostname"])
	}

	if !redeployBatch {
		internal.ExitAfterCtrlC()
	}
}
Exemplo n.º 2
0
// serviceScale start service (without attach)
func serviceScale(app string, service string, number int, destroy bool, batch bool) {
	if !batch {
		internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
	}

	// stream service events in a goroutine
	internal.EventStreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/events", app, service), nil, true)

	path := fmt.Sprintf("/applications/%s/services/%s/scale", app, service)

	args := Scale{
		Number:  number,
		Destroy: destroy,
	}

	data, err := json.Marshal(&args)
	internal.Check(err)

	buffer, _, err := internal.Stream("POST", path, data)
	internal.Check(err)

	line, err := internal.DisplayStream(buffer)
	internal.Check(err)
	if len(line) > 0 {
		var data map[string]interface{}
		err = json.Unmarshal(line, &data)
		internal.Check(err)

		fmt.Printf("Hostname: %v\n", data["hostname"])
	}

	if !batch {
		internal.ExitAfterCtrlC()
	}
}
Exemplo n.º 3
0
// serviceStart start service (without attach)
func serviceStart(app string, service string, batch bool) {
	if !batch {
		internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
	}

	// stream service events in a goroutine
	internal.EventStreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/events", app, service), nil, true)

	path := fmt.Sprintf("/applications/%s/services/%s/start", app, service)
	buffer, _, err := internal.Stream("POST", path, []byte("{}"))
	internal.Check(err)

	line, err := internal.DisplayStream(buffer)
	internal.Check(err)
	if len(line) > 0 {
		var data map[string]interface{}
		err = json.Unmarshal(line, &data)
		internal.Check(err)

		fmt.Printf("Hostname: %v\n", data["hostname"])
	}

	if !batch {
		internal.ExitAfterCtrlC()
	}
}
Exemplo n.º 4
0
Arquivo: scale.go Projeto: bewiwi/sail
// serviceScale start service (without attach)
func serviceScale(app string, service string, number int, destroy bool, batch bool) {
	if !batch {
		internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
	}

	path := fmt.Sprintf("/applications/%s/services/%s/scale?stream", app, service)

	args := Scale{
		Number:  number,
		Destroy: destroy,
	}

	data, err := json.Marshal(&args)
	internal.Check(err)

	buffer, _, err := internal.Stream("POST", path, data)
	internal.Check(err)

	line, err := internal.DisplayStream(buffer)
	internal.Check(err)
	if line != nil {
		var data map[string]interface{}
		err = json.Unmarshal(line, &data)
		internal.Check(err)

		fmt.Printf("Hostname: %v\n", data["hostname"])
		fmt.Printf("Running containers: %v/%v\n", data["container_number"], data["container_target"])
	}

	if !batch {
		internal.ExitAfterCtrlC()
	}
}
Exemplo n.º 5
0
func serviceAttach(serviceID string) {
	t := strings.Split(serviceID, "/")
	if len(t) != 2 {
		fmt.Fprintln(os.Stderr, "Invalid usage. sail service attach <applicationName>/<serviceId>. Please see sail service attach --help")
		os.Exit(1)
	}

	internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", t[0], t[1]), nil)
	internal.ExitAfterCtrlC()
}
Exemplo n.º 6
0
func serviceAttach(serviceID string) {
	// Split namespace and service
	host, app, service, _, err := internal.ParseResourceName(serviceID)
	internal.Check(err)

	if !internal.CheckHostConsistent(host) {
		fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
		os.Exit(1)
	}

	internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
	internal.ExitAfterCtrlC()
}
Exemplo n.º 7
0
Arquivo: stop.go Projeto: Alkorin/sail
// serviceStop stop service (without attach)
func serviceStop(app string, service string, batch bool) {
	if !batch {
		internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
	}

	path := fmt.Sprintf("/applications/%s/services/%s/stop?stream", app, service)
	buffer, _, err := internal.Stream("POST", path, []byte("{}"))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err)
		os.Exit(1)
	}

	_, err = internal.DisplayStream(buffer)
	internal.Check(err)
}
Exemplo n.º 8
0
func containerAttach(containerID string) {
	// Split namespace and container
	host, _, container, tag, err := internal.ParseResourceName(containerID)
	internal.Check(err)

	if !internal.CheckHostConsistent(host) {
		fmt.Fprintf(os.Stderr, "Error: Invalid Host %s for endpoint %s\n", host, internal.Host)
		os.Exit(1)
	} else if len(tag) > 0 {
		fmt.Fprintf(os.Stderr, "Error: Invalid container name. Please see sail container attach --help\n")
		os.Exit(1)
	}

	internal.StreamPrint("GET", fmt.Sprintf("/containers/%s/attach", container), nil)
	internal.ExitAfterCtrlC()
}
Exemplo n.º 9
0
// serviceStart start service (without attach)
func serviceStart(app string, service string, batch bool) {
	if !batch {
		internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
	}

	path := fmt.Sprintf("/applications/%s/services/%s/start?stream", app, service)
	buffer, _, err := internal.Stream("POST", path, []byte("{}"))
	internal.Check(err)

	line, err := internal.DisplayStream(buffer)
	internal.Check(err)
	if line != nil {
		var data map[string]interface{}
		err = json.Unmarshal(line, &data)
		internal.Check(err)

		fmt.Printf("Hostname: %v\n", data["hostname"])
		fmt.Printf("Running containers: %v/%v\n", data["container_number"], data["container_target"])
	}

	if !batch {
		internal.ExitAfterCtrlC()
	}
}
Exemplo n.º 10
0
func serviceRedeploy(args Redeploy) {

	// Parse volumes
	if len(redeployVolume) > 0 {
		args.Volumes = make(map[string]VolumeConfig)
	}

	// Parse command
	if redeployCommand != "" {
		command, err := shlex.Split(redeployCommand)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Fatal, cannot split command %s\n", err)
			return
		}
		args.ContainerCommand = command
	}

	// Parse Entrypoint
	if redeployEntrypoint != "" {
		entrypoint, err := shlex.Split(redeployEntrypoint)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Fatal, cannot split command %s\n", err)
			return
		}
		args.ContainerEntrypoint = entrypoint
	}

	for _, vol := range redeployVolume {
		t := strings.Split(vol, ":")
		if len(t) == 2 {
			args.Volumes[t[0]] = VolumeConfig{Size: t[1]}
		} else if len(t) == 1 {
			args.Volumes[t[0]] = VolumeConfig{Size: "10"}
		} else {
			fmt.Fprintf(os.Stderr, "Error: Volume parameter '%s' not formated correctly\n", vol)
			os.Exit(1)
		}
	}

	// Parse links
	if len(redeployLink) > 0 {
		args.Links = make(map[string]string)
	}

	for _, link := range redeployLink {
		t := strings.Split(link, ":")
		if len(t) == 1 {
			args.Links[t[0]] = t[0]
		} else {
			args.Links[t[0]] = t[1]
		}
	}

	// Parse ContainerNetworks arguments
	if len(redeployNetwork) > 0 {
		args.ContainerNetwork = make(map[string]map[string][]string)
	}
	for _, network := range redeployNetwork {
		args.ContainerNetwork[network] = make(map[string][]string)
	}

	for _, gat := range redeployGateway {
		t := strings.Split(gat, ":")
		if len(t) != 2 {
			fmt.Fprintf(os.Stderr, "Invalid gateway parameter, should be \"input:output\". Typically, output will be 'predictor' or 'public'")
			os.Exit(1)
		}
	}
	// Load Pool
	args.Pool = redeployPool

	// Parse ContainerPorts
	args.ContainerPorts = parsePublishedPort(redeployPublished)
	app := args.Application
	service := args.Service

	path := fmt.Sprintf("/applications/%s/services/%s/redeploy", app, service)
	body, err := json.MarshalIndent(args, " ", " ")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Fatal: %s\n", err)
		return
	}

	// Attach console
	if !redeployBatch {
		internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/services/%s/attach", app, service), nil)
	}

	// Redeploy
	buffer, _, err := internal.Stream("POST", path+"?stream", body)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err)
		os.Exit(1)
	}

	line, err := internal.DisplayStream(buffer)
	internal.Check(err)
	if line != nil {
		var data map[string]interface{}
		err = json.Unmarshal(line, &data)
		internal.Check(err)

		fmt.Printf("Hostname: %v\n", data["hostname"])
		fmt.Printf("Running containers: %v/%v\n", data["container_number"], data["container_target"])
	}

	if !redeployBatch {
		internal.ExitAfterCtrlC()
	}
}
Exemplo n.º 11
0
func operationAttach(app, operationID string) {
	// Split namespace and service
	internal.StreamPrint("GET", fmt.Sprintf("/applications/%s/operation/%s/attach", app, operationID), nil)
	internal.ExitAfterCtrlC()
}