Пример #1
0
func (p *oneProvisioner) Destroy(box *provision.Box, w io.Writer) error {
	fmt.Fprintf(w, "\n--- destroying box (%s)\n", box.GetFullName())
	args := runMachineActionsArgs{
		box:           box,
		writer:        w,
		isDeploy:      false,
		machineStatus: provision.StatusDestroying,
		provisioner:   p,
	}

	actions := []*action.Action{
		&updateStatusInRiak,
		&destroyOldMachine,
		&destroyOldRoute,
	}

	pipeline := action.NewPipeline(actions...)

	err := pipeline.Execute(args)
	if err != nil {
		fmt.Fprintf(w, "--- destroying box (%s)\n --> %s", box.GetFullName(), err)
		return err
	}
	err = doneNotify(box, w, alerts.DESTROYED)
	return nil
}
Пример #2
0
func (p *dockerProvisioner) deployPipeline(box *provision.Box, imageId string, w io.Writer) (string, error) {
	fmt.Fprintf(w, "\n--- deploy box (%s, image:%s)\n", box.GetFullName(), imageId)

	actions := []*action.Action{
		&updateStatusInRiak,
		&createContainer,
		&startContainer,
		&updateStatusInRiak,
		&setNetworkInfo,
		&followLogsAndCommit,
	}

	pipeline := action.NewPipeline(actions...)

	args := runContainerActionsArgs{
		box:             box,
		imageId:         imageId,
		writer:          w,
		isDeploy:        true,
		buildingImage:   imageId,
		containerStatus: provision.StatusLaunching,
		provisioner:     p,
	}
	err := pipeline.Execute(args)
	if err != nil {
		fmt.Fprintf(w, "deploy pipeline for box (%s)\n --> %s", box.GetFullName(), err)
		return "", err
	}
	return imageId, nil
}
Пример #3
0
//start by validating the image.
//1. &updateStatus in Riak - Deploying..
//2. &create an inmemory machine type from a Box.
//3. &updateStatus in Riak - Creating..
//4. &followLogs by posting it in the queue.
func (p *oneProvisioner) deployPipeline(box *provision.Box, imageId string, w io.Writer) (string, error) {
	fmt.Fprintf(w, "--- deploy box (%s, image:%s)\n", box.GetFullName(), imageId)
	actions := []*action.Action{
		&updateStatusInRiak,
		&createMachine,
		&updateStatusInRiak,
		&followLogs,
	}
	pipeline := action.NewPipeline(actions...)

	args := runMachineActionsArgs{
		box:           box,
		imageId:       imageId,
		writer:        w,
		isDeploy:      true,
		machineStatus: provision.StatusLaunching,
		provisioner:   p,
	}

	err := pipeline.Execute(args)
	if err != nil {
		fmt.Fprintf(w, "--- deploy pipeline for box (%s, image:%s)\n --> %s", box.GetFullName(), imageId, err)
		return "", err
	}
	return imageId, nil
}
Пример #4
0
func (p *oneProvisioner) Stop(box *provision.Box, process string, w io.Writer) error {
	fmt.Fprintf(w, "\n--- stoping box (%s)\n", box.GetFullName())
	args := runMachineActionsArgs{
		box:           box,
		writer:        w,
		isDeploy:      false,
		machineStatus: provision.StatusStopping,
		provisioner:   p,
	}
	actions := []*action.Action{
		&updateStatusInRiak,
		&stopMachine,
		&updateStatusInRiak,
	}

	pipeline := action.NewPipeline(actions...)

	err := pipeline.Execute(args)
	if err != nil {
		fmt.Fprintf(w, "--- stoping box (%s)\n --> %s", box.GetFullName(), err)
		return err
	}

	return nil
}
Пример #5
0
func (p *chefsoloProvisioner) Bootstrap(box *provision.Box, w io.Writer) error {
	fmt.Fprintf(w, "--- bootstrap box (%s)\n", box.GetFullName())
	actions := []*action.Action{
		&createMachine,
		&updateStatusInRiak,
		&updateIpsInRiak,
		&appendAuthKeys,
		&updateStatusInRiak,
		&changeStateofMachine,
	}

	pipeline := action.NewPipeline(actions...)

	args := runMachineActionsArgs{
		box:           box,
		writer:        w,
		machineStatus: constants.StatusBootstrapping,
		provisioner:   p,
	}

	if err := pipeline.Execute(args); err != nil {
		return err
	}
	fmt.Fprintf(w, "--- bootstrap box (%s) OK\n", box.GetFullName())
	return nil
}
Пример #6
0
func StopComponent(app *global.Component) error {
	actions := []*action.Action{&stopComponent}

	pipeline := action.NewPipeline(actions...)
	err := pipeline.Execute(app)
	if err != nil {
		return &AppLifecycleError{app: app.Name, Err: err}
	}
	return nil
}
Пример #7
0
func StartApp(app *global.AssemblyWithComponents) error {
	actions := []*action.Action{&startApp}

	pipeline := action.NewPipeline(actions...)
	err := pipeline.Execute(app)
	if err != nil {
		return &AppLifecycleError{app: app.Name, Err: err}
	}
	return nil
}
Пример #8
0
func StreamLogs(logs *global.DockerLogsInfo) error {
	actions := []*action.Action{&streamLogs}

	pipeline := action.NewPipeline(actions...)
	err := pipeline.Execute(logs)
	if err != nil {
		return &AppLifecycleError{app: logs.ContainerName, Err: err}
	}
	return nil
}
Пример #9
0
//
// this executes all actions for megam install
//
func AnalyticsProcess(app *global.App) error {
	actions := []*action.Action{&analyticsAction}

	pipeline := action.NewPipeline(actions...)
	err := pipeline.Execute(app)
	if err != nil {
		return err
	}
	return nil
}
Пример #10
0
func Shipper(app *global.Assemblies) error {
	actions := []*action.Action{&shipper}

	pipeline := action.NewPipeline(actions...)
	err := pipeline.Execute(app)
	if err != nil {
		return &AppLifecycleError{app: app.Name, Err: err}
	}
	return nil
}
Пример #11
0
func ConfigureNetworks(networks *global.DockerNetworksInfo) error {

	actions := []*action.Action{&configureNetworks}

	pipeline := action.NewPipeline(actions...)
	err := pipeline.Execute(networks)
	if err != nil {
		return &AppLifecycleError{app: networks.ContainerId, Err: err}
	}
	return nil
}
Пример #12
0
func (u *Upgradeable) opsBind(writer io.Writer) error {
	u.w = writer
	fmt.Fprintf(u.w, "  ops bind (%s) is kicking\n", u.B.GetFullName())

	actions := []*action.Action{
		&setEnvsAction,
	}
	pipeline := action.NewPipeline(actions...)
	args := runOpsPipelineArgs{
		box:    u.B,
		writer: u.w,
	}
	if err := pipeline.Execute(&args); err != nil {
		return err
	}
	fmt.Fprintf(u.w, "  ops bind (%s) OK\n", u.B.GetFullName())
	return nil
}
Пример #13
0
func LauncherHelper(asm *global.AssemblyWithComponents, id string, instance bool, act_id string) error {
	pair_host, perrscm := global.ParseKeyValuePair(asm.Inputs, "provider")
	if perrscm != nil {
		log.Error("Failed to get the host value : %s", perrscm)
	}

	if pair_host.Value == "docker" {

		log.Debug("Docker provisioner entry")
		// Provisioner
		p, err := provisioner.GetProvisioner("docker")
		if err != nil {
			return err
		}
		log.Info("Provisioner: %v", p)
		_, perr := p.Create(asm, id, instance, act_id)
		if perr != nil {
			return perr
		}
	}

	if pair_host.Value == "chef" {

		p, err := provisioner.GetProvisioner("chef")
		if err != nil {
			return err
		}

		str, perr := p.Create(asm, id, instance, act_id)
		if perr != nil {
			return perr
		}
		asm.Command = str
		actions := []*action.Action{&launchedApp}

		pipeline := action.NewPipeline(actions...)
		aerr := pipeline.Execute(asm)
		if aerr != nil {
			return aerr
		}
	}
	return nil
}
Пример #14
0
func (u *Upgradeable) opsBuild(writer io.Writer) error {
	u.w = writer
	fmt.Fprintf(u.w, "  ops ci (%s) is kicking\n", u.B.GetFullName())

	actions := []*action.Action{
		&cloneBox,
		&buildBox, //buildpack does everthing
	}
	pipeline := action.NewPipeline(actions...)
	args := runOpsPipelineArgs{
		box:    u.B,
		writer: u.w,
	}
	if err := pipeline.Execute(&args); err != nil {
		return err
	}
	fmt.Fprintf(u.w, "  ops ci (%s) OK\n", u.B.GetFullName())
	return nil
}
Пример #15
0
func (p *DockerProvisioner) createLogPipeline(writer io.Writer, closeChan chan bool) error {
	actions := []*action.Action{
		&setLogs,
	}
	pipeline := action.NewPipeline(actions...)
	args := runLogsActionsArgs{
		Id:        p.ContainerId,
		Name:      p.ContainerName,
		HomeDir:   p.HomeDir,
		Writer:    writer,
		CloseChan: closeChan,
	}

	err := pipeline.Execute(args)
	if err != nil {
		log.Errorf("Error on executing Log setup")
		return err
	}
	return nil
}
Пример #16
0
func (p *DockerProvisioner) createNetworkPipeline() error {
	actions := []*action.Action{
		&setNetwork,
	}
	pipeline := action.NewPipeline(actions...)
	args := runNetworkActionsArgs{
		Id:      p.ContainerId,
		IpAddr:  p.IpAddr,
		Bridge:  p.Bridge,
		Gateway: p.Gateway,
		HomeDir: p.HomeDir,
	}

	err := pipeline.Execute(args)
	if err != nil {
		log.Errorf("Error on executing Network setup")
		return err
	}
	return nil
}
Пример #17
0
func (p *dockerProvisioner) SetBoxStatus(box *provision.Box, w io.Writer, status provision.Status) error {
	fmt.Fprintf(w, "\n---- status %s box %s ----\n", box.GetFullName(), status.String())
	actions := []*action.Action{
		&updateStatusInRiak,
	}
	pipeline := action.NewPipeline(actions...)

	args := runContainerActionsArgs{
		box:             box,
		writer:          w,
		containerStatus: status,
		provisioner:     p,
	}

	err := pipeline.Execute(args)
	if err != nil {
		log.Errorf("error on execute status pipeline for box %s - %s", box.GetFullName(), err)
		return err
	}
	return nil
}
Пример #18
0
func (p *chefsoloProvisioner) Stop(b *provision.Box, w io.Writer) error {
	fmt.Fprintf(w, "--- stop box (%s)\n", b.GetFullName())
	actions := []*action.Action{
		&updateStatusInRiak,
		&stopBox,
		&updateStatusInRiak,
	}
	pipeline := action.NewPipeline(actions...)
	args := runMachineActionsArgs{
		box:           b,
		writer:        w,
		machineStatus: constants.StatusStopping,
		provisioner:   p,
	}

	if err := pipeline.Execute(args); err != nil {
		log.Errorf("error on execute stop pipeline for box %s - %s", b.GetFullName(), err)
		return err
	}
	fmt.Fprintf(w, "--- stop box (%s) OK\n", b.GetFullName())
	return nil
}
Пример #19
0
func (p *oneProvisioner) SetState(box *provision.Box, w io.Writer, changeto provision.Status) error {
	fmt.Fprintf(w, "\n--- stateto %s\n", box.GetFullName())
	args := runMachineActionsArgs{
		box:           box,
		writer:        w,
		machineStatus: changeto,
		provisioner:   p,
	}

	actions := []*action.Action{
		&changeStateofMachine,
		&addNewRoute,
	}

	pipeline := action.NewPipeline(actions...)

	err := pipeline.Execute(args)
	if err != nil {
		return err
	}
	err = doneNotify(box, w, alerts.LAUNCHED)
	return err
}
Пример #20
0
func (p *dockerProvisioner) Destroy(box *provision.Box, w io.Writer) error {
	fmt.Fprintf(w, "\n--- destroying box (%s) ----\n", box.GetFullName())
	containers, err := p.listContainersByBox(box)
	if err != nil {
		fmt.Fprintf(w, "Failed to list box containers (%s)\n --> %s", box.GetFullName(), err)
		return err
	}
	args := changeUnitsPipelineArgs{
		box:         box,
		toRemove:    containers,
		writer:      ioutil.Discard,
		provisioner: p,
		boxDestroy:  true,
	}
	pipeline := action.NewPipeline(
		&destroyOldContainers,
		&removeOldRoutes,
	)
	err = pipeline.Execute(args)
	if err != nil {
		return err
	}
	return nil
}
Пример #21
0
//1. &prepareJSON in generate the json file for chefsolo
//2. &prepareConfig in generate the config file for chefsolo.
//3. &updateStatus in Riak - Creating..
func (p *chefsoloProvisioner) kickOffSolo(b *provision.Box, w io.Writer) error {
	fmt.Fprintf(w, "--- kickofff chefsolo box (%s)\n", b.GetFullName())
	soloAction := make([]*action.Action, 0, 4)
	soloAction = append(soloAction, &generateSoloJson, &generateSoloConfig, &cloneBox)
	if b.Level != provision.BoxNone {
		soloAction = append(soloAction, &chefSoloRun)
	}
	soloAction = append(soloAction, &updateStatusInRiak)
	actions := soloAction
	pipeline := action.NewPipeline(actions...)
	args := runMachineActionsArgs{
		box:           b,
		writer:        w,
		machineStatus: constants.StatusRunning,
		provisioner:   p,
	}

	if err := pipeline.Execute(args); err != nil {
		log.Errorf("error on execute chefsolo pipeline for box %s - %s", b.GetFullName(), err)
		return err
	}
	fmt.Fprintf(w, "--- kickofff chefsolo box (%s) OK\n", b.GetFullName())
	return nil
}