本文整理汇总了Golang中github.com/control-center/serviced/domain/service.Service.DatabaseVersion方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.DatabaseVersion方法的具体用法?Golang Service.DatabaseVersion怎么用?Golang Service.DatabaseVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/control-center/serviced/domain/service.Service
的用法示例。
在下文中一共展示了Service.DatabaseVersion方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AddService
// AddService adds a service; return error if service already exists
func (f *Facade) AddService(ctx datastore.Context, svc service.Service) error {
glog.V(2).Infof("Facade.AddService: %+v", svc)
store := f.serviceStore
_, err := store.Get(ctx, svc.ID)
if err != nil && !datastore.IsErrNoSuchEntity(err) {
return err
} else if err == nil {
return fmt.Errorf("error adding service; %v already exists", svc.ID)
}
// verify the service with parent ID does not exist with the given name
if s, err := store.FindChildService(ctx, svc.DeploymentID, svc.ParentServiceID, svc.Name); err != nil {
glog.Errorf("Could not verify service path for %s: %s", svc.Name, err)
return err
} else if s != nil {
err := fmt.Errorf("service %s found at %s", svc.Name, svc.ParentServiceID)
glog.Errorf("Cannot create service %s: %s", svc.Name, err)
return err
}
// Strip the database version; we already know this is a create
svc.DatabaseVersion = 0
// Save a copy for checking configs later
svcCopy := svc
err = store.Put(ctx, &svc)
if err != nil {
glog.V(2).Infof("Facade.AddService: %+v", err)
return err
}
glog.V(2).Infof("Facade.AddService: id %+v", svc.ID)
// Compare the incoming config files to see if there are modifications from
// the original. If there are, we need to perform an update to add those
// modifications to the service.
if svcCopy.OriginalConfigs != nil && !reflect.DeepEqual(svcCopy.OriginalConfigs, svcCopy.ConfigFiles) {
// Get the current service in order to get the database version. We
// don't save this because it won't have any of the updated config
// files, among other things.
cursvc, err := store.Get(ctx, svc.ID)
if err != nil {
glog.V(2).Infof("Facade.AddService: %+v", err)
return err
}
svcCopy.DatabaseVersion = cursvc.DatabaseVersion
for key, _ := range svcCopy.OriginalConfigs {
glog.V(2).Infof("Facade.AddService: calling updateService for %s due to OriginalConfigs of %+v", svc.Name, key)
}
return f.updateService(ctx, &svcCopy)
}
glog.V(2).Infof("Facade.AddService: calling zk.updateService for %s %d ConfigFiles", svc.Name, len(svc.ConfigFiles))
return zkAPI(f).UpdateService(&svc)
}