本文整理匯總了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
}