Class AbstractAPIManager

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void addParameter​(java.util.Map<java.lang.String,​java.lang.String[]> params, java.lang.String name, java.lang.Object val)  
      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)  
      protected void validateRequired​(java.lang.String name, java.lang.Object v)  
      <T> T withTransaction​(java.lang.String auditUser, java.util.concurrent.Callable<T> callable)
      Allows for a set of AbstractAPIManager actions to be wrapped into a single transaction.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractAPIManager

        public AbstractAPIManager()
    • Method Detail

      • withTransaction

        public <T> T withTransaction​(java.lang.String auditUser,
                                     java.util.concurrent.Callable<T> callable)
                              throws java.lang.Exception
        Allows for a set of AbstractAPIManager actions to be wrapped into a single transaction. Any exception will result in all actions within the supplied Callable being rolled back, with the transaction being committed if there is no failure. Operations called within the Callable can be any implementation of AbstractAPIManager, 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.
      • 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