Package com.carfey.ops.api.embedded
Class AbstractAPIManager
- java.lang.Object
-
- com.carfey.ops.api.embedded.AbstractAPIManager
-
- Direct Known Subclasses:
CustomCalendarManager,HostManager,JobManager,LogManager,NotificationManager,RuntimeManager,ScheduleAliasManager,StatsManager,SystemParameterManager,SystemRestoreManager,UserManager
public abstract class AbstractAPIManager extends java.lang.ObjectBase class for all implementations of the Obsidian public embedded API. Implementations of note are:JobManagerRuntimeManagerHostManagerLogManagerCustomCalendarManagerNotificationManagerSystemParameterManagerSystemRestoreManagerUserManager
Methods called by implementations of
AbstractAPIManagerare normally run in their own transaction, which is committed after the operation completes.If you wish to perform multiple actions in an atomic block which will roll back everything upon failure, see
withTransaction(String, Callable), which can be invoked on any subclass ofAbstractAPIManager.- Since:
- 2.3
- See Also:
- Embedded API Wiki, REST API Wiki, Carfey Date
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractAPIManager.ActionCallable
-
Constructor Summary
Constructors Constructor Description AbstractAPIManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddParameter(java.util.Map<java.lang.String,java.lang.String[]> params, java.lang.String name, java.lang.Object val)protected <T> TrunApiTarget(com.carfey.ops.rest.RestAction action, java.lang.Object request, java.lang.Class<T> returnType, java.util.Map<java.lang.String,?> actionParams, java.util.Map<java.lang.String,java.lang.String[]> requestParameters, java.lang.String auditUser)protected voidvalidateRequired(java.lang.String name, java.lang.Object v)<T> TwithTransaction(java.lang.String auditUser, java.util.concurrent.Callable<T> callable)Allows for a set ofAbstractAPIManageractions to be wrapped into a single transaction.
-
-
-
Method Detail
-
withTransaction
public <T> T withTransaction(java.lang.String auditUser, java.util.concurrent.Callable<T> callable) throws java.lang.ExceptionAllows for a set ofAbstractAPIManageractions to be wrapped into a single transaction. Any exception will result in all actions within the suppliedCallablebeing rolled back, with the transaction being committed if there is no failure. Operations called within theCallablecan be any implementation ofAbstractAPIManager, and can include calls on different types of manager classes.Note that this method is re-entrant. If nested calls are made with this method, the top-level invocation will initiate and commit/rollback the transaction.
Example:
public static void main(String[] args) throws Exception { List<HostDetail> updated = new HostManager().withTransaction("auditUser", new Callable<List<HostDetail>glt;() { public List<HostDetail> call() throws Exception { // disable some hosts in an atomic manager (does not have to be the same instance of even type of Manager class) HostDetail hostA = new HostManager().updateHost("hostA", new HostUpdateRequest().withEnabled(false), "auditUser"); HostDetail hostB = new HostManager().updateHost("hostB", new HostUpdateRequest().withEnabled(false), "auditUser"); return Arrays.asList(hostA, hostB); } }); System.out.println("Updated hosts: " + updated); }- Type Parameters:
T- generic type to return- Parameters:
auditUser- Optional user that is marked in audit columns. Defaults to "embeddedAPI".callable- A callable containing all actions to perform.- Returns:
- the value returned by the callable instance
- Throws:
java.lang.Exception- An exception thrown from within the callable, or when managing the transaction.
-
validateRequired
protected void validateRequired(java.lang.String name, java.lang.Object v) throws ValidationException- Throws:
ValidationException
-
addParameter
protected void addParameter(java.util.Map<java.lang.String,java.lang.String[]> params, java.lang.String name, java.lang.Object val)
-
runApiTarget
protected <T> T runApiTarget(com.carfey.ops.rest.RestAction action, java.lang.Object request, java.lang.Class<T> returnType, java.util.Map<java.lang.String,?> actionParams, java.util.Map<java.lang.String,java.lang.String[]> requestParameters, java.lang.String auditUser) throws java.lang.Exception- Throws:
java.lang.Exception
-
-