当前位置: 首页>>代码示例>>Golang>>正文


Golang ControlClient.AddServiceDeployment方法代码示例

本文整理汇总了Golang中github.com/zenoss/serviced.ControlClient.AddServiceDeployment方法的典型用法代码示例。如果您正苦于以下问题:Golang ControlClient.AddServiceDeployment方法的具体用法?Golang ControlClient.AddServiceDeployment怎么用?Golang ControlClient.AddServiceDeployment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/zenoss/serviced.ControlClient的用法示例。


在下文中一共展示了ControlClient.AddServiceDeployment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: RestAddService

func RestAddService(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
	var payload dao.Service
	var serviceId string
	err := r.DecodeJsonPayload(&payload)
	if err != nil {
		glog.V(1).Info("Could not decode service payload: ", err)
		RestBadRequest(w)
		return
	}
	service, err := dao.NewService()
	if err != nil {
		glog.Errorf("Could not create service: %v", err)
		RestServerError(w)
		return
	}
	now := time.Now()
	service.Name = payload.Name
	service.Description = payload.Description
	service.Context = payload.Context
	service.Tags = payload.Tags
	service.PoolId = payload.PoolId
	service.ImageId = payload.ImageId
	service.Startup = payload.Startup
	service.Instances = payload.Instances
	service.ParentServiceId = payload.ParentServiceId
	service.DesiredState = payload.DesiredState
	service.Launch = payload.Launch
	service.Endpoints = payload.Endpoints
	service.ConfigFiles = payload.ConfigFiles
	service.Volumes = payload.Volumes
	service.CreatedAt = now
	service.UpdatedAt = now

	//for each endpoint, evaluate it's Application
	if err = service.EvaluateEndpointTemplates(client); err != nil {
		glog.Errorf("Unable to evaluate service endpoints: %v", err)
		RestServerError(w)
		return
	}

	//add the service to the data store
	err = client.AddService(*service, &serviceId)
	if err != nil {
		glog.Errorf("Unable to add service: %v", err)
		RestServerError(w)
		return
	}

	//deploy the service, in other words start it
	var unused int
	sduuid, _ := dao.NewUuid()
	deployment := dao.ServiceDeployment{sduuid, "", service.Id, now}
	err = client.AddServiceDeployment(deployment, &unused)
	if err != nil {
		glog.Errorf("Unable to add service deployment: %v", err)
		RestServerError(w)
		return
	}

	glog.V(0).Info("Added service ", serviceId)
	w.WriteJson(&SimpleResponse{"Added service", serviceLinks(serviceId)})
}
开发者ID:jhuie-zenoss,项目名称:serviced,代码行数:62,代码来源:resources.go


注:本文中的github.com/zenoss/serviced.ControlClient.AddServiceDeployment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。