本文整理汇总了Golang中github.com/zenoss/serviced.ControlClient类的典型用法代码示例。如果您正苦于以下问题:Golang ControlClient类的具体用法?Golang ControlClient怎么用?Golang ControlClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ControlClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RestGetService
func RestGetService(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
var allServices []*dao.Service
if err := client.GetServices(&empty, &allServices); err != nil {
glog.Errorf("Could not get services: %v", err)
RestServerError(w)
return
}
sid, err := url.QueryUnescape(r.PathParam("serviceId"))
if err != nil {
RestBadRequest(w)
return
}
for _, service := range allServices {
if service.Id == sid {
w.WriteJson(&service)
return
}
}
glog.Errorf("No such service [%v]", sid)
RestServerError(w)
}
示例2: getNamedServices
func getNamedServices(client *serviced.ControlClient, nmregex string) ([]*dao.Service, error) {
services := []*dao.Service{}
if err := client.GetServices(&empty, &services); err != nil {
glog.Errorf("Could not get named services: %v", err)
return nil, err
}
return filterByNameRegex(nmregex, services)
}
示例3: RestGetPools
func RestGetPools(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
var poolsMap map[string]*dao.ResourcePool
err := client.GetResourcePools(&empty, &poolsMap)
if err != nil {
glog.Error("Could not get resource pools: ", err)
RestServerError(w)
return
}
w.WriteJson(&poolsMap)
}
示例4: getServices
func getServices(client *serviced.ControlClient) ([]*dao.Service, error) {
services := []*dao.Service{}
if err := client.GetServices(&empty, &services); err != nil {
glog.Errorf("Could not get services: %v", err)
return nil, err
}
glog.V(2).Infof("Returning %d services", len(services))
return services, nil
}
示例5: RestGetHosts
func RestGetHosts(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
var hosts map[string]*dao.Host
err := client.GetHosts(&empty, &hosts)
if err != nil {
glog.Errorf("Could not get hosts: %v", err)
RestServerError(w)
return
}
glog.V(2).Infof("Returning %d hosts", len(hosts))
w.WriteJson(&hosts)
}
示例6: RestGetServiceLogs
func RestGetServiceLogs(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
serviceId, err := url.QueryUnescape(r.PathParam("serviceId"))
if err != nil {
RestBadRequest(w)
return
}
var logs string
err = client.GetServiceLogs(serviceId, &logs)
if err != nil {
glog.Errorf("Unexpected error getting logs: %v", err)
RestServerError(w)
}
w.WriteJson(&SimpleResponse{logs, serviceLinks(serviceId)})
}
示例7: getTaggedServices
func getTaggedServices(client *serviced.ControlClient, tags, nmregex string) ([]*dao.Service, error) {
services := []*dao.Service{}
var ts interface{}
ts = strings.Split(tags, ",")
if err := client.GetTaggedServices(&ts, &services); err != nil {
glog.Errorf("Could not get tagged services: %v", err)
return nil, err
}
if nmregex != "" {
return filterByNameRegex(nmregex, services)
}
glog.V(2).Infof("Returning %d tagged services", len(services))
return services, nil
}
示例8: RestGetAllRunning
func RestGetAllRunning(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
var services []*dao.RunningService
err := client.GetRunningServices(&empty, &services)
if err != nil {
glog.Errorf("Could not get services: %v", err)
RestServerError(w)
return
}
if services == nil {
glog.V(3).Info("Services was nil, returning empty list instead")
services = []*dao.RunningService{}
}
glog.V(2).Infof("Return %d running services", len(services))
w.WriteJson(&services)
}
示例9: RestRemovePool
func RestRemovePool(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
poolId, err := url.QueryUnescape(r.PathParam("poolId"))
if err != nil {
RestBadRequest(w)
return
}
var unused int
err = client.RemoveResourcePool(poolId, &unused)
if err != nil {
glog.Error("Could not remove resource pool: ", err)
RestServerError(w)
return
}
glog.V(0).Info("Removed pool ", poolId)
w.WriteJson(&SimpleResponse{"Removed resource pool", poolsLinks()})
}
示例10: RestRemoveHost
func RestRemoveHost(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
var unused int
hostId, err := url.QueryUnescape(r.PathParam("hostId"))
if err != nil {
RestBadRequest(w)
return
}
err = client.RemoveHost(hostId, &unused)
if err != nil {
glog.Errorf("Could not remove host: %v", err)
RestServerError(w)
return
}
glog.V(0).Info("Removed host ", hostId)
w.WriteJson(&SimpleResponse{"Removed host", hostsLinks()})
}
示例11: RestAddPool
func RestAddPool(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
var payload dao.ResourcePool
var poolId string
err := r.DecodeJsonPayload(&payload)
if err != nil {
glog.V(1).Info("Could not decode pool payload: ", err)
RestBadRequest(w)
return
}
err = client.AddResourcePool(payload, &poolId)
if err != nil {
glog.Error("Unable to add pool: ", err)
RestServerError(w)
return
}
glog.V(0).Info("Added pool ", poolId)
w.WriteJson(&SimpleResponse{"Added resource pool", poolLinks(poolId)})
}
示例12: RestDeployAppTemplate
func RestDeployAppTemplate(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
var payload dao.ServiceTemplateDeploymentRequest
err := r.DecodeJsonPayload(&payload)
if err != nil {
glog.V(1).Info("Could not decode deployment payload: ", err)
RestBadRequest(w)
return
}
var unused int
err = client.DeployTemplate(payload, &unused)
if err != nil {
glog.Error("Could not deploy template: ", err)
RestServerError(w)
return
}
glog.V(0).Info("Deployed template ", payload)
w.WriteJson(&SimpleResponse{"Deployed app template", servicesLinks()})
}
示例13: RestGetTopServices
func RestGetTopServices(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
var allServices []*dao.Service
topServices := []*dao.Service{}
err := client.GetServices(&empty, &allServices)
if err != nil {
glog.Errorf("Could not get services: %v", err)
RestServerError(w)
return
}
for _, service := range allServices {
if len(service.ParentServiceId) == 0 {
topServices = append(topServices, service)
}
}
glog.V(2).Infof("Returning %d services as top services", len(topServices))
w.WriteJson(&topServices)
}
示例14: RestGetRunningForService
func RestGetRunningForService(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
serviceId, err := url.QueryUnescape(r.PathParam("serviceId"))
if err != nil {
RestBadRequest(w)
return
}
var services []*dao.RunningService
err = client.GetRunningServicesForService(serviceId, &services)
if err != nil {
glog.Errorf("Could not get services: %v", err)
RestServerError(w)
return
}
if services == nil {
glog.V(3).Info("Running services was nil, returning empty list instead")
services = []*dao.RunningService{}
}
glog.V(2).Infof("Returning %d running services for service %s", len(services), serviceId)
w.WriteJson(&services)
}
示例15: RestGetHostsForResourcePool
func RestGetHostsForResourcePool(w *rest.ResponseWriter, r *rest.Request, client *serviced.ControlClient) {
var poolHosts []*dao.PoolHost
poolId, err := url.QueryUnescape(r.PathParam("poolId"))
if err != nil {
glog.V(1).Infof("Unable to acquire pool ID: %v", err)
RestBadRequest(w)
return
}
err = client.GetHostsForResourcePool(poolId, &poolHosts)
if err != nil {
glog.Errorf("Could not get hosts: %v", err)
RestServerError(w)
return
}
if poolHosts == nil {
glog.V(3).Info("Pool hosts was nil, returning empty list instead")
poolHosts = []*dao.PoolHost{}
}
glog.V(2).Infof("Returning %d hosts for pool %s", len(poolHosts), poolId)
w.WriteJson(&poolHosts)
}