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


Golang node.ControlClient类代码示例

本文整理汇总了Golang中github.com/control-center/serviced/node.ControlClient的典型用法代码示例。如果您正苦于以下问题:Golang ControlClient类的具体用法?Golang ControlClient怎么用?Golang ControlClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: restAddAppTemplate

func restAddAppTemplate(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	// read uploaded file
	file, _, err := r.FormFile("tpl")
	if err != nil {
		restBadRequest(w, err)
		return
	}
	defer file.Close()

	var b bytes.Buffer
	_, err = io.Copy(&b, file)
	template, err := servicetemplate.FromJSON(b.String())
	if err != nil {
		restServerError(w, err)
		return
	}

	var templateId string
	err = client.AddServiceTemplate(*template, &templateId)
	if err != nil {
		restServerError(w, err)
		return
	}

	w.WriteJson(&simpleResponse{templateId, servicesLinks()})
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:26,代码来源:resources.go

示例2: restDeployAppTemplate

func restDeployAppTemplate(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	var payload dao.ServiceTemplateDeploymentRequest
	err := r.DecodeJsonPayload(&payload)
	if err != nil {
		glog.V(1).Info("Could not decode deployment payload: ", err)
		restBadRequest(w, err)
		return
	}
	var tenantID string
	err = client.DeployTemplate(payload, &tenantID)
	if err != nil {
		glog.Error("Could not deploy template: ", err)
		restServerError(w, err)
		return
	}
	glog.V(0).Info("Deployed template ", payload)

	assignmentRequest := dao.AssignmentRequest{tenantID, "", true}
	if err := client.AssignIPs(assignmentRequest, nil); err != nil {
		glog.Error("Could not automatically assign IPs: %v", err)
		return
	}

	glog.Infof("Automatically assigned IP addresses to service: %v", tenantID)
	// end of automatic IP assignment

	w.WriteJson(&simpleResponse{tenantID, servicesLinks()})
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:28,代码来源:resources.go

示例3: restStopService

// restStopService stop the service with the given id and all of its children
func restStopService(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	serviceID, err := url.QueryUnescape(r.PathParam("serviceId"))
	if err != nil {
		restBadRequest(w, err)
		return
	}

	auto := r.FormValue("auto")
	autoLaunch := true

	switch auto {
	case "1", "True", "true":
		autoLaunch = true
	case "0", "False", "false":
		autoLaunch = false
	}

	var affected int
	if err := client.StopService(dao.ScheduleServiceRequest{serviceID, autoLaunch}, &affected); err != nil {
		glog.Errorf("Unexpected error stopping service: %s", err)
		restServerError(w, err)
		return
	}
	w.WriteJson(&simpleResponse{"Stopped service", serviceLinks(serviceID)})
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:26,代码来源:resources.go

示例4: restGetAllRunning

func restGetAllRunning(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	var services []dao.RunningService
	err := client.GetRunningServices(&empty, &services)
	if err != nil {
		glog.Errorf("Could not get services: %v", err)
		restServerError(w, err)
		return
	}
	if services == nil {
		glog.V(3).Info("Services was nil, returning empty list instead")
		services = []dao.RunningService{}
	}

	for ii, rsvc := range services {
		var svc service.Service
		if err := client.GetService(rsvc.ServiceID, &svc); err != nil {
			glog.Errorf("Could not get services: %v", err)
			restServerError(w, err)
		}
		fillBuiltinMetrics(&svc)
		services[ii].MonitoringProfile = svc.MonitoringProfile
	}

	services = append(services, getIRS()...)
	glog.V(2).Infof("Return %d running services", len(services))
	w.WriteJson(&services)
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:27,代码来源:resources.go

示例5: restGetService

func restGetService(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	sid, err := url.QueryUnescape(r.PathParam("serviceId"))
	if err != nil {
		restBadRequest(w, err)
		return
	}

	if strings.Contains(sid, "isvc-") {
		w.WriteJson(isvcs.ISVCSMap[sid])
		return
	}
	svc := service.Service{}
	if err := client.GetService(sid, &svc); err != nil {
		glog.Errorf("Could not get service %v: %v", sid, err)
		restServerError(w, err)
		return
	}

	if svc.ID == sid {
		fillBuiltinMetrics(&svc)
		w.WriteJson(&svc)
		return
	}

	glog.Errorf("No such service [%v]", sid)
	restServerError(w, err)
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:27,代码来源:resources.go

示例6: downloadServiceStateLogs

func downloadServiceStateLogs(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	serviceStateID, err := url.QueryUnescape(r.PathParam("serviceStateId"))
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(fmt.Sprintf("Bad Request: %v", err)))
		return
	}
	serviceID, err := url.QueryUnescape(r.PathParam("serviceId"))
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(fmt.Sprintf("Bad Request: %v", err)))
		return
	}

	request := dao.ServiceStateRequest{serviceID, serviceStateID}

	var logs string
	err = client.GetServiceStateLogs(request, &logs)

	if err != nil {
		glog.Errorf("Unexpected error getting service state logs: %v", err)
		w.WriteHeader(http.StatusInternalServerError)
		w.Write([]byte(fmt.Sprintf("Internal Server Error: %v", err)))
		return
	}

	var filename = serviceID + time.Now().Format("2006-01-02-15-04-05") + ".log"
	w.Header().Set("Content-Disposition", "attachment; filename="+filename)
	w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
	w.Write([]byte(logs))
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:31,代码来源:resources.go

示例7: RestBackupFileList

// RestBackupFileList implements a rest call that will return a list of the current backup files.
// The return value is a JSON struct of type JsonizableFileInfo.
func RestBackupFileList(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	var fileData []dao.BackupFile
	if err := client.ListBackups("", &fileData); err != nil {
		restServerError(w, err)
		return
	}
	w.WriteJson(&fileData)
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:10,代码来源:resources.go

示例8: RestRestoreStatus

func RestRestoreStatus(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	restoreStatus := ""
	err := client.BackupStatus(0, &restoreStatus)
	if err != nil {
		glog.Errorf("Unexpected error during restore status: %v", err)
		writeJSON(w, &simpleResponse{err.Error(), homeLink()}, http.StatusInternalServerError)
		return
	}
	w.WriteJson(&simpleResponse{restoreStatus, servicesLinks()})
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:10,代码来源:resources.go

示例9: RestBackupCreate

func RestBackupCreate(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	dir := ""
	filePath := ""
	err := client.AsyncBackup(dir, &filePath)
	if err != nil {
		glog.Errorf("Unexpected error during backup: %v", err)
		restServerError(w, err)
		return
	}
	w.WriteJson(&simpleResponse{filePath, servicesLinks()})
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:11,代码来源:resources.go

示例10: restDeployAppTemplateActive

func restDeployAppTemplateActive(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	var active []map[string]string

	err := client.DeployTemplateActive("", &active)
	if err != nil {
		glog.Errorf("Unexpected error during template status: %v", err)
		writeJSON(w, &simpleResponse{err.Error(), homeLink()}, http.StatusInternalServerError)
		return
	}
	w.WriteJson(&active)
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:11,代码来源:resources.go

示例11: restGetServiceLogs

func restGetServiceLogs(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	serviceID, err := url.QueryUnescape(r.PathParam("serviceId"))
	if err != nil {
		restBadRequest(w, err)
		return
	}
	var logs string
	err = client.GetServiceLogs(serviceID, &logs)
	if err != nil {
		glog.Errorf("Unexpected error getting service logs: %v", err)
		restServerError(w, err)
		return
	}
	w.WriteJson(&simpleResponse{logs, serviceLinks(serviceID)})
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:15,代码来源:resources.go

示例12: restSnapshotService

func restSnapshotService(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	serviceID, err := url.QueryUnescape(r.PathParam("serviceId"))
	if err != nil {
		restBadRequest(w, err)
		return
	}
	var label string
	err = client.Snapshot(serviceID, &label)
	if err != nil {
		glog.Errorf("Unexpected error snapshotting service: %v", err)
		restServerError(w, err)
		return
	}
	w.WriteJson(&simpleResponse{label, serviceLinks(serviceID)})
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:15,代码来源:resources.go

示例13: getNamedServices

func getNamedServices(client *node.ControlClient, nmregex string, tenantID string) ([]service.Service, error) {
	services := []service.Service{}
	var emptySlice []string
	serviceRequest := dao.ServiceRequest{
		Tags:      emptySlice,
		TenantID:  tenantID,
		NameRegex: nmregex,
	}
	if err := client.GetServices(serviceRequest, &services); err != nil {
		glog.Errorf("Could not get named services: %v", err)
		return nil, err
	}

	return services, nil
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:15,代码来源:resources.go

示例14: getTaggedServices

func getTaggedServices(client *node.ControlClient, tags, nmregex string, tenantID string) ([]service.Service, error) {
	services := []service.Service{}
	tagsSlice := strings.Split(tags, ",")
	serviceRequest := dao.ServiceRequest{
		Tags:      tagsSlice,
		TenantID:  tenantID,
		NameRegex: nmregex,
	}
	if err := client.GetTaggedServices(serviceRequest, &services); err != nil {
		glog.Errorf("Could not get tagged services: %v", err)
		return nil, err
	}

	glog.V(2).Infof("Returning %d tagged services", len(services))
	return services, nil
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:16,代码来源:resources.go

示例15: restRemoveService

func restRemoveService(w *rest.ResponseWriter, r *rest.Request, client *node.ControlClient) {
	var unused int
	serviceID, err := url.QueryUnescape(r.PathParam("serviceId"))
	if err != nil {
		restBadRequest(w, err)
		return
	}
	err = client.RemoveService(serviceID, &unused)
	if err != nil {
		glog.Errorf("Could not remove service: %v", err)
		restServerError(w, err)
		return
	}
	glog.V(0).Info("Removed service ", serviceID)
	w.WriteJson(&simpleResponse{"Removed service", servicesLinks()})
}
开发者ID:eval01-tts,项目名称:serviced,代码行数:16,代码来源:resources.go


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