Ejemplo n.º 1
0
func getRouterForBox(box *provision.Box) (router.Router, error) {
	routerName, err := box.GetRouter()
	if err != nil {
		return nil, err
	}
	return router.Get(routerName)
}
Ejemplo n.º 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
}
Ejemplo n.º 3
0
func (p *oneProvisioner) UnsetCName(box *provision.Box, cname string) error {
	r, err := getRouterForBox(box)
	if err != nil {
		return err
	}
	return r.UnsetCName(cname, box.GetFullName())
}
Ejemplo n.º 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
}
Ejemplo n.º 5
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
}
Ejemplo n.º 6
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
}
Ejemplo n.º 7
0
func (p *dockerProvisioner) ImageDeploy(box *provision.Box, imageId string, w io.Writer) (string, error) {
	isValid, err := isValidBoxImage(box.GetFullName(), imageId)
	if err != nil {
		return "", err
	}
	if !isValid {
		return "", fmt.Errorf("invalid image for box %s: %s", box.GetFullName(), imageId)
	}
	return p.deployPipeline(box, imageId, w)
}
Ejemplo n.º 8
0
func (p *oneProvisioner) ImageDeploy(box *provision.Box, imageId string, w io.Writer) (string, error) {
	isValid, err := isValidBoxImage(box.GetFullName(), imageId)
	if err != nil {
		return "", err
	}
	if !isValid {
		imageId = p.getBuildImage(box.Repo, box.ImageVersion)
	}
	return p.deployPipeline(box, imageId, w)
}
Ejemplo n.º 9
0
//this is essentially converting box to a container.
func (p *dockerProvisioner) GetContainerByBox(box *provision.Box) (*container.Container, error) {
	return &container.Container{
		BoxId:    box.Id,
		CartonId: box.CartonId,
		Name:     box.Name,
		BoxName:  box.GetFullName(),
		Level:    box.Level,
		Status:   box.Status,
	}, nil

}
Ejemplo n.º 10
0
func (*dockerProvisioner) Addr(box *provision.Box) (string, error) {
	r, err := getRouterForBox(box)
	if err != nil {
		log.Errorf("Failed to get router: %s", err)
		return "", err
	}
	addr, err := r.Addr(box.GetFullName())
	if err != nil {
		log.Errorf("Failed to obtain box %s address: %s", box.GetFullName(), err)
		return "", err
	}
	return addr, nil
}
Ejemplo n.º 11
0
func (p *dockerProvisioner) Stop(box *provision.Box, process string, w io.Writer) error {
	containers, err := p.listContainersByBox(box)
	if err != nil {
		fmt.Fprintf(w, "Failed to list box containers (%s)\n --> %s", box.GetFullName(), err)
	}
	return runInContainers(containers, func(c *container.Container, _ chan *container.Container) error {
		err := c.Stop(p)
		if err != nil {
			log.Errorf("Failed to stop %q: %s", box.GetFullName(), err)
		}
		return err
	}, nil, true)
}
Ejemplo n.º 12
0
func doneNotify(box *provision.Box, w io.Writer, evtAction alerts.EventAction) error {
	fmt.Fprintf(w, "\n--- done %s box \n", box.GetFullName())
	mi := make(map[string]string)
	mi[alerts.VERTNAME] = box.GetFullName()
	mi[alerts.VERTTYPE] = box.Tosca
	newEvent := events.NewMulti(
		[]*events.Event{
			&events.Event{
				AccountsId:  box.AccountsId,
				EventAction: evtAction,
				EventType:   events.EventUser,
				EventData:   events.EventData{M: mi},
				Timestamp:   time.Now().Local(),
			},
		})
	return newEvent.Write()
}
Ejemplo n.º 13
0
func (p *dockerProvisioner) Start(box *provision.Box, process string, w io.Writer) error {
	containers, err := p.listContainersByBox(box)
	if err != nil {
		fmt.Fprintf(w, "Failed to list box containers (%s)\n --> %s", box.GetFullName(), err)
	}
	return runInContainers(containers, func(c *container.Container, _ chan *container.Container) error {
		err := c.Start(&container.StartArgs{
			Provisioner: p,
			Box:         box,
		})
		if err != nil {
			return err
		}
		c.SetStatus(provision.StatusStarting)
		if info, err := c.NetworkInfo(p); err == nil {
			p.fixContainer(c, info)
		}
		return nil
	}, nil, true)
}
Ejemplo n.º 14
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
}
Ejemplo n.º 15
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
}
Ejemplo n.º 16
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
}