Ejemplo n.º 1
0
func (this *TemplatesController) DeleteCustomService() {
	id, err := this.GetInt64("id", 0)
	service := entity.Service{}
	if err == nil && id != 0 {
		service.Id = id
		err = service.Load()
		if err == nil {
			serviceDto := entity.ServiceDto{}
			serviceDto.Service = service
			serviceDto.Load()
			if serviceDto.Service.Where == utils.Deploy_On_PaaS {
				serviceDto.OnPaaS.Delete()
			}
			if serviceDto.Service.Where == utils.Deploy_On_Vms {
				serviceDto.OnCustom.Delete()
			}
		}

		err = service.Delete()
		if err != nil {
			this.Data["MessageErr"] = fmt.Sprintf("Errors: %s", err)
		}
	}
	if err != nil {
		this.Data["MessageErr"] = fmt.Sprintf("Errors: %s", err)
	}
}
func (serviceDeploy *ServiceDeployWebSocketController) Deploy2PaaS(ws *websocket.Conn, service entity.Service) {
	//加载serviceDto
	//	writeStringMessage(ws, "Load ServiceDto")
	serviceDto := entity.ServiceDto{}
	serviceDto.Service = service
	err := serviceDto.Load()

	if err != nil {
		writeStringMessage(ws, fmt.Sprintf("Error,%s", err))
		return
	}

	//模板输出文件
	result := serviceDeploy.ParseTemplate(ws, service)
	if !result {
		return
	}
	//模板输出文件
	onPaaS := serviceDto.OnPaaS

	var deployDir = customServiceDir + "/" + service.Name

	success := serviceDeploy.setApi(ws, onPaaS, deployDir)

	if !success {
		writeStringMessage(ws, "Set endpoint failed")
	}

	if success {
		success = serviceDeploy.loginPaaS(ws, onPaaS, deployDir)
		if !success {
			writeStringMessage(ws, "Login PaaS failed")
		}
	}

	if success {
		success = serviceDeploy.targetPaaS(ws, onPaaS, deployDir)
		if !success {
			writeStringMessage(ws, "Target PaaS failed")
		}
	}

	if success {
		success = serviceDeploy.pushApp(ws, onPaaS, deployDir)
		if !success {
			writeStringMessage(ws, "Deploy app failed")
		}
	}

	if success {
		writeStringMessage(ws, "Push app successful")
	}

}
Ejemplo n.º 3
0
func (this *TemplatesController) LoadCustomServiceDetail() {
	id, err := this.GetInt64("id", 0)
	service := entity.Service{}
	if err == nil {
		service.Id = id
		err = service.Load()
		serviceDto := entity.ServiceDto{}
		serviceDto.Service = service
		err = serviceDto.Load()
		if err == nil {
			this.Data["json"] = &serviceDto
			this.ServeJSON()
		}
	}
}
// operate service on vms
func (serviceDeploy *ServiceDeployWebSocketController) OperateOnVms(ws *websocket.Conn, service entity.Service, operate string) {
	//加载serviceDto
	//	writeStringMessage(ws, "Load ServiceDto")
	serviceDto := entity.ServiceDto{}
	serviceDto.Service = service
	err := serviceDto.Load()

	if err != nil {
		writeStringMessage(ws, fmt.Sprintf("Error,%s", err))
		return
	}
	writeStringMessage(ws, "Load custom vms info")
	onCustom := serviceDto.OnCustom
	sshRunner := utils.NewDeploySSHRunner(onCustom.Ip, onCustom.User, onCustom.Passwd)

	operation := entity.Operation{}
	operation.Sid = service.Id
	err = operation.LoadBySid()

	var out bytes.Buffer

	if err == nil {
		switch operate {
		case utils.Service_Restart:
			writeStringMessage(ws, fmt.Sprintf("Start run command: %s app, please wait for a monent", "Restart"))
			err = sshRunner.RunCommand(operation.Restart, &out)
			if err == nil {
				writeStringMessage(ws, fmt.Sprintf("%s app successful", "Restart"))
			}
		case utils.Service_Start:
			writeStringMessage(ws, fmt.Sprintf("Start run command: %s app, please wait for a monent", "Start"))
			err = sshRunner.RunCommand(operation.Start, &out)
			if err == nil {
				writeStringMessage(ws, fmt.Sprintf("%s app successful", "Start"))
			}
		case utils.Service_Stop:
			writeStringMessage(ws, fmt.Sprintf("Start run command: %s app, please wait for a monent", "Stop"))
			err = sshRunner.RunCommand(operation.Stop, &out)
			if err == nil {
				writeStringMessage(ws, fmt.Sprintf("%s app successful", "Stop"))
			}
		}
		if err != nil {
			writeStringMessage(ws, fmt.Sprintf("%s app failed ,errors: %v", operate, err))
		}
	}

}
// deploy 2 vms
func (serviceDeploy *ServiceDeployWebSocketController) Deploy2Vms(ws *websocket.Conn, service entity.Service) {
	//加载serviceDto
	//	writeStringMessage(ws, "Load ServiceDto")
	serviceDto := entity.ServiceDto{}
	serviceDto.Service = service
	err := serviceDto.Load()
	if err != nil {
		writeStringMessage(ws, fmt.Sprintf("Error,%s", err))
		return
	}

	//加载TemplateList
	writeStringMessage(ws, "Load TemplateList")
	template, templateLoadErr := entity.LoadTemplateList(service.Id)

	if templateLoadErr != nil {
		writeStringMessage(ws, fmt.Sprintf("Error,%s", templateLoadErr))
		return
	}

	//模板输出文件
	result := serviceDeploy.ParseTemplate(ws, service)
	if !result {
		return
	}
	//模板输出文件
	//传输文件
	writeStringMessage(ws, "传输文件...")

	vms := serviceDto.OnCustom

	sshRunner := utils.NewDeploySSHRunner(vms.Ip, vms.User, vms.Passwd)

	for index, temp1 := range template {
		if temp1.FileType != utils.FileTypes_War {
			continue
		}
		serviceDeploy.pushFiles(ws, index, temp1, sshRunner)

	}
	writeStringMessage(ws, "Finish deploying")

}
func (serviceDeploy *ServiceDeployWebSocketController) OperateOnPaaS(ws *websocket.Conn, service entity.Service, operate string) {
	//加载serviceDto
	//	writeStringMessage(ws, "Load ServiceDto")
	serviceDto := entity.ServiceDto{}
	serviceDto.Service = service
	err := serviceDto.Load()

	if err != nil {
		writeStringMessage(ws, fmt.Sprintf("Error,%s", err))
		return
	}

	onPaaS := serviceDto.OnPaaS

	var deployDir = customServiceDir + "/" + service.Name

	success := serviceDeploy.setApi(ws, onPaaS, deployDir)

	if !success {
		writeStringMessage(ws, "Set endpoint failed")
	}

	if success {
		success = serviceDeploy.loginPaaS(ws, onPaaS, deployDir)
		if !success {
			writeStringMessage(ws, "Login PaaS failed")
		}
	}

	if success {
		success = serviceDeploy.targetPaaS(ws, onPaaS, deployDir)
		if !success {
			writeStringMessage(ws, "Target PaaS failed")
		}
	}

	if success {
		switch operate {
		case utils.Service_Restart:
			success = serviceDeploy.operateAppOnPaaS(ws, onPaaS, deployDir, "rs")
		case utils.Service_Start:
			success = serviceDeploy.operateAppOnPaaS(ws, onPaaS, deployDir, "start")
		case utils.Service_Stop:
			success = serviceDeploy.operateAppOnPaaS(ws, onPaaS, deployDir, "stop")
		}
		if !success {
			writeStringMessage(ws, fmt.Sprintf("%s app failed", operate))
		}
	}

	if success {
		switch operate {
		case utils.Service_Restart:
			writeStringMessage(ws, fmt.Sprintf("%s app successful", "Restart"))
		case utils.Service_Start:
			writeStringMessage(ws, fmt.Sprintf("%s app successful", "Start"))
		case utils.Service_Stop:
			writeStringMessage(ws, fmt.Sprintf("%s app successful", "Stop"))
		}
	}

}