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


Golang Service.GetServiceVHosts方法代码示例

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


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

示例1: UpdateService

func (f *Facade) UpdateService(ctx datastore.Context, svc service.Service) error {
	glog.V(2).Infof("Facade.UpdateService: %+v", svc)
	//cannot update service without validating it.
	if svc.DesiredState != int(service.SVCStop) {
		if err := f.validateServicesForStarting(ctx, &svc); err != nil {
			glog.Warningf("Could not validate service %s (%s) for starting: %s", svc.Name, svc.ID, err)
			svc.DesiredState = int(service.SVCStop)
		}

		for _, ep := range svc.GetServiceVHosts() {
			for _, vh := range ep.VHosts {
				//check that vhosts aren't already started elsewhere
				if err := zkAPI(f).CheckRunningVHost(vh, svc.ID); err != nil {
					return err
				}
			}
		}
	}

	return f.updateService(ctx, &svc)
}
开发者ID:carriercomm,项目名称:serviced,代码行数:21,代码来源:service.go

示例2: UpdateServiceVhosts

// UpdateServiceVhosts updates vhosts of a service
func UpdateServiceVhosts(conn client.Connection, svc *service.Service) error {
	glog.V(2).Infof("UpdateServiceVhosts for ID:%s Name:%s", svc.ID, svc.Name)

	// generate map of current vhosts
	currentvhosts := map[string]string{}
	if svcvhosts, err := conn.Children(zkServiceVhosts); err == client.ErrNoNode {
		/*
			// do not do this, otherwise, nodes aren't deleted when calling RemoveServiceVhost

			if exists, err := zzk.PathExists(conn, zkServiceVhosts); err != nil {
				return err
			} else if !exists {
				err := conn.CreateDir(zkServiceVhosts)
				if err != client.ErrNodeExists && err != nil {
					return err
				}
			}
		*/
	} else if err != nil {
		glog.Errorf("UpdateServiceVhosts unable to retrieve vhost children at path %s %s", zkServiceVhosts, err)
		return err
	} else {
		for _, svcvhost := range svcvhosts {
			parts := strings.SplitN(svcvhost, "_", 2)
			vhostname := parts[1]
			currentvhosts[svcvhost] = vhostname
		}
	}
	glog.V(2).Infof("  currentvhosts %+v", currentvhosts)

	// generate map of vhosts in the service
	svcvhosts := map[string]string{}
	for _, ep := range svc.GetServiceVHosts() {
		for _, vhostname := range ep.VHosts {
			svcvhosts[fmt.Sprintf("%s_%s", svc.ID, vhostname)] = vhostname
		}
	}
	glog.V(2).Infof("  svcvhosts %+v", svcvhosts)

	// remove vhosts in current not in svc that match serviceid
	for sv, vhostname := range currentvhosts {
		svcID := strings.SplitN(sv, "_", 2)[0]
		if svcID != svc.ID {
			continue
		}

		if _, ok := svcvhosts[sv]; !ok {
			if err := RemoveServiceVhost(conn, svc.ID, vhostname); err != nil {
				return err
			}
		}
	}

	// add vhosts from svc not in current
	for sv, vhostname := range svcvhosts {
		if _, ok := currentvhosts[sv]; !ok {
			if err := UpdateServiceVhost(conn, svc.ID, vhostname); err != nil {
				return err
			}
		}
	}

	return nil
}
开发者ID:carriercomm,项目名称:serviced,代码行数:65,代码来源:servicevhost.go


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