ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [13/50] [abbrv] ambari git commit: AMBARI-20971 - Repository Resource Providers Should Expose the Repository ID by Default on Minimal Responses (jonathanhurley)
Date Wed, 31 May 2017 20:12:44 GMT
AMBARI-20971 - Repository Resource Providers Should Expose the Repository ID by Default on
Minimal Responses (jonathanhurley)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b1f704df
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b1f704df
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b1f704df

Branch: refs/heads/trunk
Commit: b1f704dfb9b54a57b14ecb5314b65bee7288eeb1
Parents: a263267
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Tue May 9 17:05:09 2017 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Tue May 9 17:05:09 2017 -0400

----------------------------------------------------------------------
 .../AbstractAuthorizedResourceProvider.java     | 21 ++++++++++++++++++++
 .../AbstractControllerResourceProvider.java     |  9 +++++++--
 ...atibleRepositoryVersionResourceProvider.java | 17 ++++++++--------
 .../internal/ReadOnlyResourceProvider.java      | 20 +++++++++++++++++++
 .../internal/RepositoryResourceProvider.java    |  2 +-
 .../RepositoryVersionResourceProvider.java      | 21 ++++++++------------
 6 files changed, 65 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b1f704df/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractAuthorizedResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractAuthorizedResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractAuthorizedResourceProvider.java
index 92a7256..32e59eb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractAuthorizedResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractAuthorizedResourceProvider.java
@@ -34,6 +34,7 @@ import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.security.authorization.AuthorizationHelper;
 import org.apache.ambari.server.security.authorization.ResourceType;
@@ -91,6 +92,26 @@ public abstract class AbstractAuthorizedResourceProvider extends AbstractResourc
   }
 
   /**
+   * Create a new resource provider. This constructor will initialize the
+   * specified {@link Resource.Type} with the provided keys. It should be used
+   * in cases where the provider declares its own keys instead of reading them
+   * from a JSON file.
+   *
+   * @param type
+   *          the type to set the properties for (not {@code null}).
+   * @param propertyIds
+   *          the property ids
+   * @param keyPropertyIds
+   *          the key property ids
+   */
+  AbstractAuthorizedResourceProvider(Resource.Type type, Set<String> propertyIds,
+      Map<Resource.Type, String> keyPropertyIds) {
+    this(propertyIds, keyPropertyIds);
+    PropertyHelper.setPropertyIds(type, propertyIds);
+    PropertyHelper.setKeyPropertyIds(type, keyPropertyIds);
+  }
+
+  /**
    * Gets the authorizations for which one is needed to the grant access to <b>create</b>
resources
    * or a particular resource.
    * <p/>

http://git-wip-us.apache.org/repos/asf/ambari/blob/b1f704df/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
index a27a5d0..a762e2b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractControllerResourceProvider.java
@@ -59,8 +59,13 @@ public abstract class AbstractControllerResourceProvider extends AbstractAuthori
   }
 
   /**
-   * Create a new resource provider for the given management controller.
+   * Create a new resource provider for the given management controller. This
+   * constructor will initialize the specified {@link Resource.Type} with the
+   * provided keys. It should be used in cases where the provider declares its
+   * own keys instead of reading them from a JSON file.
    *
+   * @param type
+   *          the type to set the properties for (not {@code null}).
    * @param propertyIds
    *          the property ids
    * @param keyPropertyIds
@@ -68,7 +73,7 @@ public abstract class AbstractControllerResourceProvider extends AbstractAuthori
    * @param managementController
    *          the management controller
    */
-  protected AbstractControllerResourceProvider(Resource.Type type, Set<String> propertyIds,
+  AbstractControllerResourceProvider(Resource.Type type, Set<String> propertyIds,
       Map<Resource.Type, String> keyPropertyIds, AmbariManagementController managementController)
{
     this(propertyIds, keyPropertyIds, managementController);
     PropertyHelper.setPropertyIds(type, propertyIds);

http://git-wip-us.apache.org/repos/asf/ambari/blob/b1f704df/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProvider.java
index 98b91b3..fe8df44 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProvider.java
@@ -52,6 +52,7 @@ import org.apache.ambari.server.state.repository.ManifestServiceInfo;
 import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.UpgradePack;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Sets;
 import com.google.inject.Inject;
 import com.google.inject.Provider;
@@ -90,14 +91,12 @@ public class CompatibleRepositoryVersionResourceProvider extends ReadOnlyResourc
     REPOSITORY_VERSION_SERVICES,
     REPOSITORY_VERSION_STACK_SERVICES);
 
-  static Map<Type, String> keyPropertyIds = new HashMap<Type, String>() {
-    {
-      put(Type.Stack, REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID);
-      put(Type.StackVersion, REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID);
-      put(Type.Upgrade, REPOSITORY_UPGRADES_SUPPORTED_TYPES_ID);
-      put(Type.CompatibleRepositoryVersion, REPOSITORY_VERSION_ID_PROPERTY_ID);
-    }
-  };
+  static Map<Type, String> keyPropertyIds = new ImmutableMap.Builder<Type, String>()
+    .put(Type.Stack, REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID)
+    .put(Type.StackVersion, REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID)
+    .put(Type.Upgrade, REPOSITORY_UPGRADES_SUPPORTED_TYPES_ID)
+    .put(Type.CompatibleRepositoryVersion, REPOSITORY_VERSION_ID_PROPERTY_ID)
+    .build();
 
   @Inject
   private static RepositoryVersionDAO s_repositoryVersionDAO;
@@ -109,7 +108,7 @@ public class CompatibleRepositoryVersionResourceProvider extends ReadOnlyResourc
    * Create a new resource provider.
    */
   public CompatibleRepositoryVersionResourceProvider(AmbariManagementController amc) {
-    super(propertyIds, keyPropertyIds, amc);
+    super(Type.CompatibleRepositoryVersion, propertyIds, keyPropertyIds, amc);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/b1f704df/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ReadOnlyResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ReadOnlyResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ReadOnlyResourceProvider.java
index 342983f..fd35673 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ReadOnlyResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ReadOnlyResourceProvider.java
@@ -43,6 +43,26 @@ public abstract class ReadOnlyResourceProvider extends AbstractControllerResourc
     super(propertyIds, keyPropertyIds, managementController);
   }
 
+  /**
+   * Create a new resource provider for the given management controller. This
+   * constructor will initialize the specified {@link Resource.Type} with the
+   * provided keys. It should be used in cases where the provider declares its
+   * own keys instead of reading them from a JSON file.
+   *
+   * @param type
+   *          the type to set the properties for (not {@code null}).
+   * @param propertyIds
+   *          the property ids
+   * @param keyPropertyIds
+   *          the key property ids
+   * @param managementController
+   *          the management controller
+   */
+  ReadOnlyResourceProvider(Resource.Type type, Set<String> propertyIds,
+      Map<Resource.Type, String> keyPropertyIds, AmbariManagementController managementController)
{
+    super(type, propertyIds, keyPropertyIds, managementController);
+  }
+
   @Override
   public RequestStatus createResources(Request request) throws SystemException,
       UnsupportedPropertyException, ResourceAlreadyExistsException,

http://git-wip-us.apache.org/repos/asf/ambari/blob/b1f704df/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java
index 6665087..dd29087 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryResourceProvider.java
@@ -105,7 +105,7 @@ public class RepositoryResourceProvider extends AbstractControllerResourceProvid
   };
 
   public RepositoryResourceProvider(AmbariManagementController managementController) {
-    super(propertyIds, keyPropertyIds, managementController);
+    super(Resource.Type.Repository, propertyIds, keyPropertyIds, managementController);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/b1f704df/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
index a0a3666..ac5fe17 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
@@ -68,6 +68,7 @@ import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Sets;
 import com.google.gson.Gson;
 import com.google.inject.Inject;
@@ -100,11 +101,7 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
   public static final String REPOSITORY_VERSION_HAS_CHILDREN                   = "RepositoryVersions/has_children";
 
   @SuppressWarnings("serial")
-  private static Set<String> pkPropertyIds = new HashSet<String>() {
-    {
-      add(REPOSITORY_VERSION_ID_PROPERTY_ID);
-    }
-  };
+  private static Set<String> pkPropertyIds = Sets.newHashSet(REPOSITORY_VERSION_ID_PROPERTY_ID);
 
   @SuppressWarnings("serial")
   public static Set<String> propertyIds = Sets.newHashSet(
@@ -125,13 +122,11 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
       REPOSITORY_VERSION_STACK_SERVICES);
 
   @SuppressWarnings("serial")
-  public static Map<Type, String> keyPropertyIds = new HashMap<Type, String>()
{
-    {
-      put(Type.Stack, REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID);
-      put(Type.StackVersion, REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID);
-      put(Type.RepositoryVersion, REPOSITORY_VERSION_ID_PROPERTY_ID);
-    }
-  };
+  public static Map<Type, String> keyPropertyIds = new ImmutableMap.Builder<Type,
String>()
+      .put(Type.Stack, REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID)
+      .put(Type.StackVersion, REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID)
+      .put(Type.RepositoryVersion, REPOSITORY_VERSION_ID_PROPERTY_ID)
+      .build();
 
   @Inject
   private Gson gson;
@@ -159,7 +154,7 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
    *
    */
   public RepositoryVersionResourceProvider() {
-    super(propertyIds, keyPropertyIds);
+    super(Resource.Type.RepositoryVersion, propertyIds, keyPropertyIds);
 
     setRequiredCreateAuthorizations(EnumSet.of(RoleAuthorization.AMBARI_MANAGE_STACK_VERSIONS));
     setRequiredDeleteAuthorizations(EnumSet.of(RoleAuthorization.AMBARI_MANAGE_STACK_VERSIONS));


Mime
View raw message