コード例 #1
0
ファイル: redeploy.go プロジェクト: dsteinkopf/seqredeploy
func doRedeployContainer(containerUri string, parentService tutum.Service, haproxyContainerUuid string) error {
	container, err := tutum.GetContainer(getUuidFromUri(containerUri))
	if err != nil {
		return err
	}
	httpCheckDef, err := getEnvFromContainer("HTTP_CHECK", container)
	if err != nil {
		return err
	}
	parts := strings.Split(httpCheckDef, " ")
	if len(parts) < 2 || parts[0] != "GET" {
		return fmt.Errorf("container %s (%s) has bad HTTP_CHECK '%s' (not implemented)",
			container.Name, containerUri, httpCheckDef)
	}
	httpCheckUri := parts[1]

	log.Printf("redeploying container %s (%s)", container.Name, container.Uuid)

	err = container.Redeploy(tutum.ReuseVolumesOption{Reuse: true})
	if err != nil {
		return err
	}

	newContainer, err := waitForContainerToTerminateAndReappear(container, parentService)
	if err != nil {
		return err
	}

	err = waitForCheckOk(httpCheckUri, newContainer, 10*60)
	if err != nil {
		return err
	}
	log.Printf("container %s (%s) checked ok", newContainer.Name, newContainer.Uuid)
	return nil
}
コード例 #2
0
ファイル: redeploy.go プロジェクト: dsteinkopf/seqredeploy
func waitForContainerToTerminateAndReappear(container tutum.Container,
	parentService tutum.Service) (tutum.Container, error) {
	log.Printf("waitForContainerToTerminateAndReappear")
	eventChan := make(chan tutum.Event)
	errChan := make(chan error)

	go tutum.TutumEvents(eventChan, errChan)

	didTerminate := false
	var newContainer tutum.Container
	var err error

	for {
		select {
		case event := <-eventChan:
			// log.Println(event)
			if event.Type == "container" &&
				strings.Contains(event.Resource_uri, container.Uuid) &&
				event.State == "Terminated" {

				log.Printf("got container Terminated event on my container")
				didTerminate = true
			}
			if event.Type == "container" &&
				parentsContain(event.Parents, parentService.Uuid) &&
				event.State == "Running" &&
				didTerminate == true {

				newContainer, err = tutum.GetContainer(getUuidFromUri(event.Resource_uri))
				if err != nil {
					return newContainer, err
				}
				log.Printf("got container Running event on new container (%s)", newContainer.Uuid)
				return newContainer, nil
			}
		case err := <-errChan:
			return newContainer, err
		}
	}
}