本文整理汇总了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)
}
示例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
}