Package org.lsst.ccs.services
Class AgentLockService
java.lang.Object
org.lsst.ccs.services.AgentLockService
- All Implemented Interfaces:
LockLevelService,ServiceLifecycle,AgentService
public class AgentLockService
extends Object
implements LockLevelService, ServiceLifecycle, AgentService
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for being notified of lock update events.static interfaceStatic utility methods for handling user settings. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidattachLock(String agentName) Request for this agent to attach a lock on the given subsystem that is already owned by the user.voiddestroyLock(String agentName, String userId) Destroys a lock.voiddetachLock(String agentName) Request for this agent to detach a lock on the given subsystem.Get the name of this service.Returns a list of currently locked subsystems, regardless of whom they are locked by.Returns a list of subsystems locked by the current user but not attached by this subsystem.Returns a list of subsystems locked by the current user and attached by this subsystem.getExistingLockForAgent(String agentName) Returns a lock for the specified subsystem if there is one,nullotherwise.Returns a map of attached locks.intgetLevelForAgent(String agentName) Returns this agent's authorized level at which it can operate the specified subsystem.Returns a list of subsystems locked by the current user and attached by this subsystem.Returns a list of subsystems that can be locked by are not currently locked by anyone.Returns a list of subsystems locked by the current user.getLockForAgent(String agentName) Returns a lock for the specified subsystem if there is one attached to this agent,nullotherwise.getLocks()Returns a map of all existing locks, regardless of who owns them and what agents they are attached to.intgetMaxLevel(String user, String agentName) Returns maximum level at which the specified user is allowed to lock the specified agent.For the given agent, returns a map of users to maximum allowed levels.For the given user, returns a map of subsystem name or name wildcard to maximum allowed level.Returns the current user.voidRequest for this agent to obtain a lock on the given subsystem.voidpreInit()voidpreStart()Called from the enclosingSubsystemwhenorg.lsst.ccs.Subsystem#start()has been called.voidvoidsetLevelForAgent(String agentName, int level) Set this agent's operational level for the given subsystem.voidunlockAgent(String agentName) Request to release a lock on the given subsystem.validateLock(DictionaryCommand command, CommandRequest request) Validates a lock object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.lsst.ccs.services.AgentService
startForAgentMethods inherited from interface org.lsst.ccs.ServiceLifecycle
afterBuild, afterInit, afterStart, preBuild, preShutdown
-
Field Details
-
LOCK_MANAGER_SUBSYSTEM_NAME
- See Also:
-
-
Constructor Details
-
AgentLockService
public AgentLockService()
-
-
Method Details
-
getAgentStateService
-
getAgentLoginService
-
getAgentServiceName
Description copied from interface:AgentServiceGet the name of this service. This name will be used to add the given service to the lookup tree.- Specified by:
getAgentServiceNamein interfaceAgentService- Returns:
- the AgentService name.
-
preInit
public void preInit()- Specified by:
preInitin interfaceServiceLifecycle
-
preStart
public void preStart()Description copied from interface:ServiceLifecycleCalled from the enclosingSubsystemwhenorg.lsst.ccs.Subsystem#start()has been called.The preceding lifecycle step is
HasLifecycle.postInit()The following lifecycle step is
HasLifecycle.start()At the time it is called :-
the
PhaseStateisINITIALIZINGconnection with the messaging layer is effective, the enclosing subsystem has startedStatusHeartBeatpublication- Specified by:
preStartin interfaceServiceLifecycle
-
setLevelForAgent
public void setLevelForAgent(String agentName, int level) throws UnauthorizedLevelException, UnauthorizedLockException Set this agent's operational level for the given subsystem. If this agent does not hold a lock on the subsystem, this method will first attempt to acquire a lock on the subsystem. If successful, registeredAgentLevelListenerwill be notified with the new level value.- Parameters:
agentName- Target subsystem name.level- Desired level.- Throws:
UnauthorizedLevelException- If the lock on the target subsystem has been successfully acquired, but the desired level cannot be set because the current user is not authorized to operate at that level.UnauthorizedLockException- If the target subsystem cannot be locked.RuntimeException- If there was a communication problem on the buses.
-
getLevelForAgent
Returns this agent's authorized level at which it can operate the specified subsystem. Returns 0 if there is no lock owned by the current user and attached to this agent.- Specified by:
getLevelForAgentin interfaceLockLevelService- Parameters:
agentName- Target subsystem name.- Returns:
- Current level, or 0 if there is no attached lock.
-
getLockForAgent
Returns a lock for the specified subsystem if there is one attached to this agent,nullotherwise. In order to be returned by this method, the lock must be owned by the current user and attached to this agent.- Specified by:
getLockForAgentin interfaceLockLevelService- Parameters:
agentName- Target subsystem name.- Returns:
- Lock for the target subsystem if there is one attached.
-
getExistingLockForAgent
Returns a lock for the specified subsystem if there is one,nullotherwise. The lock might be owned by any user and attached to any agent.- Parameters:
agentName- Target subsystem name.- Returns:
- Lock for the target subsystem if it exists,
nullotherwise.
-
lockAgent
Request for this agent to obtain a lock on the given subsystem. If successful, this agent will own a lock on the requested subsystem. registeredAgentLockUpdateListenerwill be notified. The list of owned valid locks will be updated. This command will return only when the lock has been acknowledged trough network exchanges.- Parameters:
agentName- Target subsystem name.- Throws:
UnauthorizedLockException- If the target subsystem cannot be locked.RuntimeException- If there was a communication problem on the buses.
-
unlockAgent
Request to release a lock on the given subsystem. If successful, current user will lose its lock on the requested subsystem. All agents that have attached the lock will lose their version of it and be notified. RegisteredAgentLockUpdateListenerwill be notified. The list of owned valid locks will be updated. Non-blocking. Calling this method for an agent that is already unlocked has no effect.- Parameters:
agentName- Target subsystem name.- Throws:
UnauthorizedLockException- If the target is locked, and the lock is not owned by the current user.RuntimeException- If there was a communication problem on the buses.
-
attachLock
Request for this agent to attach a lock on the given subsystem that is already owned by the user. The list of owned valid locks will be updated. RegisteredAgentLockUpdateListenerwill be notified. This command will return only when the lock has been acknowledged trough network exchanges.- Parameters:
agentName- Target subsystem name.- Throws:
UnauthorizedLockException- If the user does not own a lock on the specified subsystem.RuntimeException- If there was a communication problem on the buses.
-
detachLock
Request for this agent to detach a lock on the given subsystem. If successful, this agent will lose its version of the lock on the requested subsystem, but the lock will still exist and be associated to the user. RegisteredAgentLockUpdateListenerwill be notified. The list of owned valid locks will be updated. Non-blocking.- Parameters:
agentName- Target subsystem name.- Throws:
UnauthorizedLockException- If the user does not have a lock on the specified subsystem.RuntimeException- If there was a communication problem on the buses.
-
getLocks
Returns a map of all existing locks, regardless of who owns them and what agents they are attached to. The returned map will be updated as locks are modified, created, or destroyed.- Returns:
- a map of subsystem names to their current lock.
-
getHeldLocks
Returns a map of attached locks. To be included, a lock must be owned by the current user and attached to this agent. The returned map is a snapshot produced at the time this method is called, and it will not be updated.- Returns:
- Map of target subsystem names to their locks.
-
validateLock
Validates a lock object. This can be used by a worker subsystem to validate a lock attached to a command request.- Parameters:
command- Command.request- Command request.- Returns:
- Error description if the lock is invalid,
nullotherwise.
-
getUserId
Returns the current user.- Specified by:
getUserIdin interfaceLockLevelService- Returns:
- Current user ID.
-
addAgentLockUpdateListener
-
removeAgentLockUpdateListener
-
getLockableAgents
Returns a list of subsystems that can be locked by are not currently locked by anyone.- Returns:
- List of lockable subsystems.
-
getAttachableAgents
Returns a list of subsystems locked by the current user but not attached by this subsystem.- Returns:
- List of attachable subsystems.
-
getDetachableAgents
Returns a list of subsystems locked by the current user and attached by this subsystem.- Returns:
- List of attached subsystems.
-
getLockedAgents
Returns a list of subsystems locked by the current user.- Returns:
- List of subsystems locked by the current user.
-
getAllLockedAgents
Returns a list of currently locked subsystems, regardless of whom they are locked by.- Returns:
- List of subsystems locked by any user.
-
getLocallyLockedAgents
Returns a list of subsystems locked by the current user and attached by this subsystem. Convenience method, same asgetDetachableAgents().- Returns:
- List of attached subsystems.
-
getAllWorkerAgents
-
destroyLock
Destroys a lock. Use in emergency.- Parameters:
agentName- Target subsystem name.userId- User on whose authority the lock should be destroyed.
-
getMaxLevel
Returns maximum level at which the specified user is allowed to lock the specified agent.- Parameters:
user- User ID.agentName- Target agent.- Returns:
- Maximum allowed level.
-
getMaxLevelsUser
public static Map<String,Integer> getMaxLevelsUser(String user, Map<String, Map<String, String>> config) For the given user, returns a map of subsystem name or name wildcard to maximum allowed level. Groups are expanded, level names decoded.- Parameters:
user- User ID.config- Lock manager configuration parameter that defines max levels for all users and agents.- Returns:
- Map of subsystem name or name wildcard to maximum level. May be empty but never
null.
-
getMaxLevelsSubsystem
public static Map<String,Integer> getMaxLevelsSubsystem(String agentName, Map<String, Map<String, String>> config) For the given agent, returns a map of users to maximum allowed levels.- Parameters:
agentName- Agent that executes commands.config- Lock manager configuration parameter that defines max levels for all users and agents.- Returns:
- Map of user ID to max level. May be empty but never
null.
-