本文整理汇总了Golang中github.com/control-center/serviced/domain/servicestate.ServiceState.ValidEntity方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceState.ValidEntity方法的具体用法?Golang ServiceState.ValidEntity怎么用?Golang ServiceState.ValidEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/control-center/serviced/domain/servicestate.ServiceState
的用法示例。
在下文中一共展示了ServiceState.ValidEntity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addInstance
// addInstance creates a new service state and host instance
func addInstance(conn client.Connection, state ss.ServiceState) error {
glog.V(2).Infof("Adding instance %+v", state)
// check the object
if err := state.ValidEntity(); err != nil {
glog.Errorf("Could not validate service state %+v: %s", state, err)
return err
}
// CC-1050: we need to trigger the scheduler in case we only have a
// partial create.
svclock := newStateLock(conn, state.ServiceID)
if err := svclock.Lock(); err != nil {
glog.Errorf("Could not set lock on service %s: %s", state.ServiceID, err)
return err
}
defer svclock.Unlock()
lock := newInstanceLock(conn, state.ID)
if err := lock.Lock(); err != nil {
glog.Errorf("Could not set lock for service instance %s for service %s on host %s: %s", state.ID, state.ServiceID, state.HostID, err)
return err
}
glog.V(2).Infof("Acquired lock for instance %s", state.ID)
defer lock.Unlock()
var err error
defer func() {
if err != nil {
conn.Delete(hostpath(state.HostID, state.ID))
conn.Delete(servicepath(state.ServiceID, state.ID))
rmInstanceLock(conn, state.ID)
}
}()
// Create node on the service
spath := servicepath(state.ServiceID, state.ID)
snode := &ServiceStateNode{ServiceState: &state}
if err = conn.Create(spath, snode); err != nil {
glog.Errorf("Could not create service state %s for service %s: %s", state.ID, state.ServiceID, err)
return err
} else if err = conn.Set(spath, snode); err != nil {
glog.Errorf("Could not set service state %s for node %+v: %s", state.ID, snode, err)
return err
}
// Create node on the host
hpath := hostpath(state.HostID, state.ID)
hnode := NewHostState(&state)
glog.V(2).Infof("Host node: %+v", hnode)
if err = conn.Create(hpath, hnode); err != nil {
glog.Errorf("Could not create host state %s for host %s: %s", state.ID, state.HostID, err)
return err
} else if err = conn.Set(hpath, hnode); err != nil {
glog.Errorf("Could not set host state %s for node %+v: %s", state.ID, hnode, err)
return err
}
glog.V(2).Infof("Releasing lock for instance %s", state.ID)
return nil
}
示例2: UpdateServiceState
// UpdateServiceState does a full update of a service state
func UpdateServiceState(conn client.Connection, state *ss.ServiceState) error {
if err := state.ValidEntity(); err != nil {
glog.Errorf("Could not validate service state %+v: %s", state, err)
return err
}
return updateInstance(conn, state.HostID, state.ID, func(_ *HostState, ssdata *ss.ServiceState) {
*ssdata = *state
})
}