Ejemplo n.º 1
0
func discovering(wg *sync.WaitGroup) {
	defer wg.Done()
	c := make(chan tutum.Event)
	e := make(chan error)

	nodes.DiscoverPeers()

	go tutum.TutumEvents(c, e)
Loop:
	for {
		select {
		case event := <-c:
			if event.Type == "node" && (event.State == "Deployed" || event.State == "Terminated") {
				err := nodes.DiscoverPeers()
				if err != nil {
					log.Println(err)
				}
			}
			break
		case err := <-e:
			log.Println("[NODE DISCOVERY ERROR]: " + err.Error())
			time.Sleep(5 * time.Second)
			wg.Add(1)
			go discovering(wg)
			break Loop
		}
	}
}
Ejemplo n.º 2
0
func discovering(wg *sync.WaitGroup) {
	defer wg.Done()
	c := make(chan tutum.Event)
	e := make(chan error)

	nodes.DiscoverPeers()

	go tutum.TutumEvents(c, e)
	tutumEventHandler(wg, c, e)
}
Ejemplo n.º 3
0
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
		}
	}
}