Example #1
0
func dockerStateHandler(chann []byte) {

	Msg := &Message{}
	parse_err := json.Unmarshal(chann, &Msg)
	log.Info(parse_err)
	if parse_err != nil {
		log.Error("Error: Message parsing error:\n%s.", parse_err)
		return
	}

	apprequest := global.AppRequest{Id: Msg.Id}
	req, err := apprequest.Get(Msg.Id)
	log.Info(req)
	if err != nil {
		log.Error("Error: Riak didn't cooperate:\n%s.", err)
		return
	}

	assembly := global.Assembly{Id: req.AppId}
	asm, err := assembly.GetAssemblyWithComponents(req.AppId)
	if err != nil {
		log.Error("Error: Riak didn't cooperate:\n%s.", err)
		return
	}

	cont_id, perrscm := global.ParseKeyValuePair(asm.Components[0].Outputs, "id")
	if perrscm != nil {
		log.Error("Failed to get the container id : %s", perrscm)
	}
	endpoint, perrscm := global.ParseKeyValuePair(asm.Components[0].Outputs, "endpoint")
	if perrscm != nil {
		log.Error("Failed to get the container id : %s", perrscm)
	}

	pair_cpu, perrscm := global.ParseKeyValuePair(asm.Inputs, "cpu")
	if perrscm != nil {
		log.Error("Failed to get the cpu value : %s", perrscm)
	}

	pair_memory, iderr := global.ParseKeyValuePair(asm.Inputs, "ram")
	if iderr != nil {
		log.Error("Failed to get the memory value : %s", iderr)
	}

	switch req.Action {
	case "start":
		log.Info("Starting Container")
		go docker.StartContainer(&global.Container{ContainerID: cont_id.Value, Cpu: pair_cpu.Value, Ram: pair_memory.Value}, endpoint.Value)
		break
	case "stop":
		log.Info("Stopping Container")
		go docker.StopContainer(&global.Container{ContainerID: cont_id.Value}, endpoint.Value)
		break
	case "restart":
		log.Info("Restarting container")
		go docker.RestartContainer(&global.Container{ContainerID: cont_id.Value}, endpoint.Value)
		break
	}
}
Example #2
0
func requestHandler(chann []byte) {
	log.Info("Cloud standup handler entered!-------->")
	m := &global.Message{}
	parse_err := json.Unmarshal(chann, &m)
	if parse_err != nil {
		log.Error("Error: Message parsing error:\n%s.", parse_err)
		return
	}
	request := global.Request{Id: m.Id}
	req, err := request.Get(m.Id)
	log.Debug(req)
	log.Debug("---------")
	if err != nil {
		log.Error("Error: Riak didn't cooperate:\n%s.", err)
		return
	}
	switch req.ReqType {
	case "create":
		log.Debug("============Create entry============")
		assemblies := global.Assemblies{Id: req.AssembliesId}
		asm, err := assemblies.Get(req.AssembliesId)
		if err != nil {
			log.Error("Error: Riak didn't cooperate:\n%s.", err)
			return
		}
		for i := range asm.Assemblies {
			log.Debug("Assemblies: [%s]", asm.Assemblies[i])
			if len(asm.Assemblies[i]) > 1 {

				assemblyID := asm.Assemblies[i]
				log.Debug("Assemblies id: [%s]", assemblyID)
				assembly := global.Assembly{Id: assemblyID}
				res, err := assembly.GetAssemblyWithComponents(assemblyID)
				if err != nil {
					log.Error("Error: Riak didn't cooperate:\n%s.", err)
					return
				}
				go app.LaunchApp(res, m.Id, asm.AccountsId)
				go pluginAdministrator(res, asm.AccountsId)
			}
		}

		//build delete command
	case "delete":
		log.Debug("============Delete entry==========")
		assembly := global.Assembly{Id: req.AssembliesId}
		asm, err := assembly.GetAssemblyWithComponents(req.AssembliesId)
		if err != nil {
			log.Error("Error: Riak didn't cooperate:\n%s.", err)
			return
		}
		res := asm
		go app.DeleteApp(res, m.Id)

	}
}