ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject ambari git commit: AMBARI-22110. Some ResourceProviders Are Not Transactional (ncole)
Date Mon, 02 Oct 2017 20:38:59 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 4de5cb22b -> 504ea2aa8


AMBARI-22110. Some ResourceProviders Are Not Transactional (ncole)


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

Branch: refs/heads/branch-2.6
Commit: 504ea2aa8b09468c4ecd045190b139c7547e01f0
Parents: 4de5cb2
Author: Nate Cole <ncole@hortonworks.com>
Authored: Mon Oct 2 10:51:35 2017 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Mon Oct 2 15:57:05 2017 -0400

----------------------------------------------------------------------
 .../server/controller/ControllerModule.java     |   4 +
 .../controller/ResourceProviderFactory.java     |   8 +
 .../AbstractControllerResourceProvider.java     |   4 +
 .../internal/AlertTargetResourceProvider.java   |  29 +--
 .../internal/ClientConfigResourceProvider.java  |  41 ++---
 .../internal/DefaultProviderModule.java         |   4 -
 .../internal/ViewInstanceResourceProvider.java  | 178 +++++++++++--------
 7 files changed, 149 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/504ea2aa/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index e3f1458..fc64f0f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -62,6 +62,7 @@ import org.apache.ambari.server.cleanup.ClasspathScannerUtils;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.configuration.Configuration.ConnectionPoolType;
 import org.apache.ambari.server.configuration.Configuration.DatabaseType;
+import org.apache.ambari.server.controller.internal.AlertTargetResourceProvider;
 import org.apache.ambari.server.controller.internal.ClusterStackVersionResourceProvider;
 import org.apache.ambari.server.controller.internal.ComponentResourceProvider;
 import org.apache.ambari.server.controller.internal.CredentialResourceProvider;
@@ -73,6 +74,7 @@ import org.apache.ambari.server.controller.internal.MemberResourceProvider;
 import org.apache.ambari.server.controller.internal.RepositoryVersionResourceProvider;
 import org.apache.ambari.server.controller.internal.ServiceResourceProvider;
 import org.apache.ambari.server.controller.internal.UpgradeResourceProvider;
+import org.apache.ambari.server.controller.internal.ViewInstanceResourceProvider;
 import org.apache.ambari.server.controller.logging.LoggingRequestHelperFactory;
 import org.apache.ambari.server.controller.logging.LoggingRequestHelperFactoryImpl;
 import org.apache.ambari.server.controller.metrics.MetricPropertyProviderFactory;
@@ -468,6 +470,8 @@ public class ControllerModule extends AbstractModule {
         .implement(ResourceProvider.class, Names.named("kerberosDescriptor"), KerberosDescriptorResourceProvider.class)
         .implement(ResourceProvider.class, Names.named("upgrade"), UpgradeResourceProvider.class)
         .implement(ResourceProvider.class, Names.named("clusterStackVersion"), ClusterStackVersionResourceProvider.class)
+        .implement(ResourceProvider.class, Names.named("alertTarget"), AlertTargetResourceProvider.class)
+        .implement(ResourceProvider.class, Names.named("viewInstance"), ViewInstanceResourceProvider.class)
         .build(ResourceProviderFactory.class));
 
     install(new FactoryModuleBuilder().implement(

http://git-wip-us.apache.org/repos/asf/ambari/blob/504ea2aa/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
index 9cd1d74..a198775 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ResourceProviderFactory.java
@@ -22,8 +22,10 @@ package org.apache.ambari.server.controller;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.ambari.server.controller.internal.AlertTargetResourceProvider;
 import org.apache.ambari.server.controller.internal.ClusterStackVersionResourceProvider;
 import org.apache.ambari.server.controller.internal.UpgradeResourceProvider;
+import org.apache.ambari.server.controller.internal.ViewInstanceResourceProvider;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.Resource.Type;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
@@ -72,4 +74,10 @@ public interface ResourceProviderFactory {
   @Named("clusterStackVersion")
   ClusterStackVersionResourceProvider getClusterStackVersionResourceProvider(AmbariManagementController
managementController);
 
+  @Named("alertTarget")
+  AlertTargetResourceProvider getAlertTargetResourceProvider();
+
+  @Named("viewInstance")
+  ViewInstanceResourceProvider getViewInstanceResourceProvider();
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/504ea2aa/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 0782685..dc1207e 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
@@ -254,6 +254,10 @@ public abstract class AbstractControllerResourceProvider extends AbstractAuthori
         return new ClusterKerberosDescriptorResourceProvider(managementController);
       case LoggingQuery:
         return new LoggingResourceProvider(propertyIds, keyPropertyIds, managementController);
+      case AlertTarget:
+        return resourceProviderFactory.getAlertTargetResourceProvider();
+      case ViewInstance:
+        return resourceProviderFactory.getViewInstanceResourceProvider();
       default:
         throw new IllegalArgumentException("Unknown type " + type);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/504ea2aa/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
index 0b7f1db..3ab089b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
@@ -78,18 +78,18 @@ public class AlertTargetResourceProvider extends
   public static final String ALERT_TARGET_GLOBAL = "AlertTarget/global";
   public static final String ALERT_TARGET_ENABLED = "AlertTarget/enabled";
 
-  private static final Set<String> PK_PROPERTY_IDS = new HashSet<String>(
+  private static final Set<String> PK_PROPERTY_IDS = new HashSet<>(
       Arrays.asList(ALERT_TARGET_ID, ALERT_TARGET_NAME));
 
   /**
    * The property ids for an alert target resource.
    */
-  private static final Set<String> PROPERTY_IDS = new HashSet<String>();
+  private static final Set<String> PROPERTY_IDS = new HashSet<>();
 
   /**
    * The key property ids for an alert target resource.
    */
-  private static final Map<Resource.Type, String> KEY_PROPERTY_IDS = new HashMap<Resource.Type,
String>();
+  private static final Map<Resource.Type, String> KEY_PROPERTY_IDS = new HashMap<>();
 
   static {
     // properties
@@ -124,6 +124,7 @@ public class AlertTargetResourceProvider extends
   /**
    * Constructor.
    */
+  @Inject
   AlertTargetResourceProvider() {
     super(PROPERTY_IDS, KEY_PROPERTY_IDS);
 
@@ -156,7 +157,7 @@ public class AlertTargetResourceProvider extends
       throws SystemException, UnsupportedPropertyException,
       NoSuchResourceException, NoSuchParentResourceException {
 
-    Set<Resource> results = new HashSet<Resource>();
+    Set<Resource> results = new HashSet<>();
     Set<String> requestPropertyIds = getRequestPropertyIds(request, predicate);
 
     if( null == predicate ){
@@ -218,7 +219,7 @@ public class AlertTargetResourceProvider extends
     Set<Resource> resources = getResources(new RequestImpl(null, null, null,
         null), predicate);
 
-    Set<Long> targetIds = new HashSet<Long>();
+    Set<Long> targetIds = new HashSet<>();
 
     for (final Resource resource : resources) {
       Long id = (Long) resource.getPropertyValue(ALERT_TARGET_ID);
@@ -310,7 +311,7 @@ public class AlertTargetResourceProvider extends
       // set the states that this alert target cares about
       final Set<AlertState> alertStateSet;
       if (null != alertStates) {
-        alertStateSet = new HashSet<AlertState>(alertStates.size());
+        alertStateSet = new HashSet<>(alertStates.size());
         for (String state : alertStates) {
           alertStateSet.add(AlertState.valueOf(state));
         }
@@ -332,8 +333,8 @@ public class AlertTargetResourceProvider extends
       if (requestMap.containsKey(ALERT_TARGET_GROUPS)) {
         Collection<Long> groupIds = (Collection<Long>) requestMap.get(ALERT_TARGET_GROUPS);
         if( !groupIds.isEmpty() ){
-          Set<AlertGroupEntity> groups = new HashSet<AlertGroupEntity>();
-          List<Long> ids = new ArrayList<Long>(groupIds);
+          Set<AlertGroupEntity> groups = new HashSet<>();
+          List<Long> ids = new ArrayList<>(groupIds);
           groups.addAll(s_dao.findGroupsById(ids));
           entity.setAlertGroups(groups);
         }
@@ -419,7 +420,7 @@ public class AlertTargetResourceProvider extends
       if (alertStates.isEmpty()) {
         alertStateSet = EnumSet.allOf(AlertState.class);
       } else {
-        alertStateSet = new HashSet<AlertState>(alertStates.size());
+        alertStateSet = new HashSet<>(alertStates.size());
         for (String state : alertStates) {
           alertStateSet.add(AlertState.valueOf(state));
         }
@@ -430,8 +431,8 @@ public class AlertTargetResourceProvider extends
 
     // if groups were supplied, replace existing
     if (null != groupIds) {
-      Set<AlertGroupEntity> groups = new HashSet<AlertGroupEntity>();
-      List<Long> ids = new ArrayList<Long>(groupIds);
+      Set<AlertGroupEntity> groups = new HashSet<>();
+      List<Long> ids = new ArrayList<>(groupIds);
 
       if (ids.size() > 0) {
         groups.addAll(s_dao.findGroupsById(ids));
@@ -439,7 +440,7 @@ public class AlertTargetResourceProvider extends
 
       entity.setAlertGroups(groups);
     } else if (entity.isGlobal()){
-      Set<AlertGroupEntity> groups = new HashSet<AlertGroupEntity>(s_dao.findAllGroups());
+      Set<AlertGroupEntity> groups = new HashSet<>(s_dao.findAllGroups());
       entity.setAlertGroups(groups);
     }
 
@@ -486,7 +487,7 @@ public class AlertTargetResourceProvider extends
 
     if (BaseProvider.isPropertyRequested(ALERT_TARGET_GROUPS, requestedIds)) {
       Set<AlertGroupEntity> groupEntities = entity.getAlertGroups();
-      List<AlertGroup> groups = new ArrayList<AlertGroup>(
+      List<AlertGroup> groups = new ArrayList<>(
           groupEntities.size());
 
       for (AlertGroupEntity groupEntity : groupEntities) {
@@ -515,7 +516,7 @@ public class AlertTargetResourceProvider extends
    *         {@code null} if none.
    */
   private Map<String, Object> extractProperties(Map<String, Object> requestMap)
{
-    Map<String, Object> normalizedMap = new HashMap<String, Object>(
+    Map<String, Object> normalizedMap = new HashMap<>(
         requestMap.size());
 
     for (Entry<String, Object> entry : requestMap.entrySet()) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/504ea2aa/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
index 9d2b39e..0b048ad 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProvider.java
@@ -107,7 +107,6 @@ import org.slf4j.LoggerFactory;
 import com.google.gson.Gson;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
-import com.google.inject.persist.Transactional;
 
 /**
  * Resource provider for client config resources.
@@ -126,7 +125,7 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
   private final Gson gson;
 
   private static Set<String> pkPropertyIds =
-          new HashSet<String>(Arrays.asList(new String[]{
+          new HashSet<>(Arrays.asList(new String[]{
                   COMPONENT_CLUSTER_NAME_PROPERTY_ID,
                   COMPONENT_SERVICE_NAME_PROPERTY_ID,
                   COMPONENT_COMPONENT_NAME_PROPERTY_ID}));
@@ -164,13 +163,12 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
   }
 
   @Override
-  @Transactional
   public Set<Resource> getResources(Request request, Predicate predicate)
           throws SystemException, UnsupportedPropertyException, NoSuchResourceException,
NoSuchParentResourceException {
 
-    Set<Resource> resources = new HashSet<Resource>();
+    Set<Resource> resources = new HashSet<>();
 
-    final Set<ServiceComponentHostRequest> requests = new HashSet<ServiceComponentHostRequest>();
+    final Set<ServiceComponentHostRequest> requests = new HashSet<>();
 
     for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
       requests.add(getRequest(propertyMap));
@@ -203,7 +201,7 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
     String requestServiceName = schRequest.getServiceName();
     String requestHostName =  schRequest.getHostname();
 
-    Map<String,List<ServiceComponentHostResponse>> serviceToComponentMap = new
HashMap<String,List<ServiceComponentHostResponse>>();
+    Map<String,List<ServiceComponentHostResponse>> serviceToComponentMap = new
HashMap<>();
 
     // sch response for the service components that have configFiles defined in the stack
definition of the service
     List <ServiceComponentHostResponse> schWithConfigFiles = new ArrayList<>();
@@ -267,10 +265,10 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
         String commandScriptAbsolute = packageFolderAbsolute + File.separator + commandScript;
 
 
-        Map<String, Map<String, String>> configurations = new TreeMap<String,
Map<String, String>>();
-        Map<String, Long> configVersions = new TreeMap<String, Long>();
+        Map<String, Map<String, String>> configurations = new TreeMap<>();
+        Map<String, Long> configVersions = new TreeMap<>();
         Map<String, Map<PropertyType, Set<String>>> configPropertiesTypes
= new TreeMap<>();
-        Map<String, Map<String, Map<String, String>>> configurationAttributes
= new TreeMap<String, Map<String, Map<String, String>>>();
+        Map<String, Map<String, Map<String, String>>> configurationAttributes
= new TreeMap<>();
 
         Map<String, DesiredConfig> desiredClusterConfigs = cluster.getDesiredConfigs();
 
@@ -282,15 +280,14 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
           Config clusterConfig = cluster.getConfig(configType, desiredConfig.getTag());
 
           if (clusterConfig != null) {
-            Map<String, String> props = new HashMap<String, String>(clusterConfig.getProperties());
+            Map<String, String> props = new HashMap<>(clusterConfig.getProperties());
 
             // Apply global properties for this host from all config groups
             Map<String, Map<String, String>> allConfigTags = null;
             allConfigTags = configHelper
               .getEffectiveDesiredTags(cluster, schRequest.getHostname());
 
-            Map<String, Map<String, String>> configTags = new HashMap<String,
-              Map<String, String>>();
+            Map<String, Map<String, String>> configTags = new HashMap<>();
 
             for (Map.Entry<String, Map<String, String>> entry : allConfigTags.entrySet())
{
               if (entry.getKey().equals(clusterConfig.getType())) {
@@ -311,7 +308,7 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
             configVersions.put(clusterConfig.getType(), clusterConfig.getVersion());
             configPropertiesTypes.put(clusterConfig.getType(), clusterConfig.getPropertiesTypes());
 
-            Map<String, Map<String, String>> attrs = new TreeMap<String, Map<String,
String>>();
+            Map<String, Map<String, String>> attrs = new TreeMap<>();
             configHelper.cloneAttributesMap(clusterConfig.getPropertiesAttributes(), attrs);
 
             Map<String, Map<String, Map<String, String>>> attributes =
configHelper
@@ -358,7 +355,7 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
         }
         osFamily = clusters.getHost(hostName).getOsFamily();
 
-        TreeMap<String, String> hostLevelParams = new TreeMap<String, String>();
+        TreeMap<String, String> hostLevelParams = new TreeMap<>();
         hostLevelParams.put(JDK_LOCATION, managementController.getJdkResourceUrl());
         hostLevelParams.put(JAVA_HOME, managementController.getJavaHome());
         hostLevelParams.put(JAVA_VERSION, String.valueOf(configs.getJavaVersion()));
@@ -384,7 +381,7 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
 
         // Build package list that is relevant for host
         List<ServiceOsSpecific.Package> packages =
-          new ArrayList<ServiceOsSpecific.Package>();
+          new ArrayList<>();
         if (anyOs != null) {
           packages.addAll(anyOs.getPackages());
         }
@@ -415,14 +412,14 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
         hostLevelParams.put(NOT_MANAGED_HDFS_PATH_LIST, notManagedHdfsPathList);
 
         String jsonConfigurations = null;
-        Map<String, Object> commandParams = new HashMap<String, Object>();
-        List<Map<String, String>> xmlConfigs = new LinkedList<Map<String,
String>>();
-        List<Map<String, String>> envConfigs = new LinkedList<Map<String,
String>>();
-        List<Map<String, String>> propertiesConfigs = new LinkedList<Map<String,
String>>();
+        Map<String, Object> commandParams = new HashMap<>();
+        List<Map<String, String>> xmlConfigs = new LinkedList<>();
+        List<Map<String, String>> envConfigs = new LinkedList<>();
+        List<Map<String, String>> propertiesConfigs = new LinkedList<>();
 
         //Fill file-dictionary configs from metainfo
         for (ClientConfigFileDefinition clientConfigFile : clientConfigFiles) {
-          Map<String, String> fileDict = new HashMap<String, String>();
+          Map<String, String> fileDict = new HashMap<>();
           fileDict.put(clientConfigFile.getFileName(), clientConfigFile.getDictionaryName());
           if (clientConfigFile.getType().equals("xml")) {
             xmlConfigs.add(fileDict);
@@ -438,7 +435,7 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
         commandParams.put("properties_configs_list", propertiesConfigs);
         commandParams.put("output_file", componentName + "-configs" + Configuration.DEF_ARCHIVE_EXTENSION);
 
-        Map<String, Object> jsonContent = new TreeMap<String, Object>();
+        Map<String, Object> jsonContent = new TreeMap<>();
         jsonContent.put("configurations", configurations);
         jsonContent.put("configuration_attributes", configurationAttributes);
         jsonContent.put("commandParams", commandParams);
@@ -937,7 +934,7 @@ public class ClientConfigResourceProvider extends AbstractControllerResourceProv
   }
 
   private List<ServiceOsSpecific> getOSSpecificsByFamily(Map<String, ServiceOsSpecific>
osSpecifics, String osFamily) {
-    List<ServiceOsSpecific> foundedOSSpecifics = new ArrayList<ServiceOsSpecific>();
+    List<ServiceOsSpecific> foundedOSSpecifics = new ArrayList<>();
     for (Map.Entry<String, ServiceOsSpecific> osSpecific : osSpecifics.entrySet())
{
       if (osSpecific.getKey().indexOf(osFamily) != -1) {
         foundedOSSpecifics.add(osSpecific.getValue());

http://git-wip-us.apache.org/repos/asf/ambari/blob/504ea2aa/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
index 781b015..8b36100 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/DefaultProviderModule.java
@@ -66,8 +66,6 @@ public class DefaultProviderModule extends AbstractProviderModule {
         return new ViewResourceProvider();
       case ViewVersion:
         return new ViewVersionResourceProvider();
-      case ViewInstance:
-        return new ViewInstanceResourceProvider();
       case ViewURL:
         return new ViewURLResourceProvider();
       case StackServiceComponentDependency:
@@ -94,8 +92,6 @@ public class DefaultProviderModule extends AbstractProviderModule {
         return new AlertDefinitionResourceProvider(managementController);
       case AlertHistory:
         return new AlertHistoryResourceProvider(managementController);
-      case AlertTarget:
-        return new AlertTargetResourceProvider();
       case AlertGroup:
         return new AlertGroupResourceProvider(managementController);
       case AlertNotice:

http://git-wip-us.apache.org/repos/asf/ambari/blob/504ea2aa/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
index 63e6c24..5cdc9c0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
@@ -18,8 +18,14 @@
 
 package org.apache.ambari.server.controller.internal;
 
-import com.google.common.base.Strings;
-import com.google.inject.persist.Transactional;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.DuplicateResourceException;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
@@ -44,13 +50,8 @@ import org.apache.ambari.server.view.validation.ValidationResultImpl;
 import org.apache.ambari.view.ClusterType;
 import org.apache.ambari.view.validation.Validator;
 
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
+import com.google.inject.Inject;
+import com.google.inject.persist.Transactional;
 
 /**
  * Resource provider for view instances.
@@ -90,7 +91,7 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
   /**
    * The key property ids for a view instance resource.
    */
-  private static Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type,
String>();
+  private static Map<Resource.Type, String> keyPropertyIds = new HashMap<>();
   static {
     keyPropertyIds.put(Resource.Type.View, VIEW_NAME_PROPERTY_ID);
     keyPropertyIds.put(Resource.Type.ViewVersion, VIEW_VERSION_PROPERTY_ID);
@@ -100,7 +101,7 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
   /**
    * The property ids for a view instance resource.
    */
-  private static Set<String> propertyIds = new HashSet<String>();
+  private static Set<String> propertyIds = new HashSet<>();
   static {
     propertyIds.add(VIEW_NAME_PROPERTY_ID);
     propertyIds.add(VIEW_VERSION_PROPERTY_ID);
@@ -127,6 +128,7 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
   /**
    * Construct a view instance resource provider.
    */
+  @Inject
   public ViewInstanceResourceProvider() {
     super(propertyIds, keyPropertyIds);
 
@@ -155,7 +157,7 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
   public Set<Resource> getResources(Request request, Predicate predicate)
       throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException
{
 
-    Set<Resource> resources    = new HashSet<Resource>();
+    Set<Resource> resources    = new HashSet<>();
     ViewRegistry  viewRegistry = ViewRegistry.getInstance();
     Set<String>   requestedIds = getRequestPropertyIds(request, predicate);
 
@@ -225,7 +227,7 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
 
   @Override
   protected Set<String> getPKPropertyIds() {
-    return new HashSet<String>(keyPropertyIds.values());
+    return new HashSet<>(keyPropertyIds.values());
   }
 
 
@@ -261,7 +263,7 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
           viewInstanceEntity.getPropertyMap(), requestedIds);
     }
 
-    Map<String, String> applicationData = new HashMap<String, String>();
+    Map<String, String> applicationData = new HashMap<>();
 
     String currentUserName = viewInstanceEntity.getCurrentUserName();
     for (ViewInstanceDataEntity viewInstanceDataEntity : viewInstanceEntity.getData()) {
@@ -365,7 +367,7 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
       viewInstanceEntity.setClusterType(ClusterType.valueOf(clusterType));
     }
 
-    Map<String, String> instanceProperties = new HashMap<String, String>();
+    Map<String, String> instanceProperties = new HashMap<>();
 
     boolean isUserAdmin = viewRegistry.checkAdmin();
 
@@ -397,37 +399,9 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
   // Create a create command with all properties set.
   private Command<Void> getCreateCommand(final Map<String, Object> properties)
{
     return new Command<Void>() {
-      @Transactional
       @Override
       public Void invoke() throws AmbariException {
-        try {
-          ViewRegistry       viewRegistry   = ViewRegistry.getInstance();
-          ViewInstanceEntity instanceEntity = toEntity(properties, false);
-
-          ViewEntity viewEntity = instanceEntity.getViewEntity();
-          String     viewName   = viewEntity.getCommonName();
-          String     version    = viewEntity.getVersion();
-          ViewEntity view       = viewRegistry.getDefinition(viewName, version);
-
-          if ( view == null ) {
-            throw new IllegalStateException("The view " + viewName + " is not registered.");
-          }
-
-          // the view must be in the DEPLOYED state to create an instance
-          if (!view.isDeployed()) {
-            throw new IllegalStateException("The view " + viewName + " is not loaded.");
-          }
-
-          if (viewRegistry.instanceExists(instanceEntity)) {
-            throw new DuplicateResourceException("The instance " + instanceEntity.getName()
+ " already exists.");
-          }
-          viewRegistry.installViewInstance(instanceEntity);
-        } catch (org.apache.ambari.view.SystemException e) {
-          throw new AmbariException("Caught exception trying to create view instance.", e);
-        } catch (ValidationException e) {
-          // results in a BAD_REQUEST (400) response for the validation failure.
-          throw new IllegalArgumentException(e.getMessage(), e);
-        }
+        create(properties);
         return null;
       }
     };
@@ -436,23 +410,9 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
   // Create an update command with all properties set.
   private Command<Void> getUpdateCommand(final Map<String, Object> properties)
{
     return new Command<Void>() {
-      @Transactional
       @Override
       public Void invoke() throws AmbariException {
-        ViewInstanceEntity instance = toEntity(properties, true);
-        ViewEntity         view     = instance.getViewEntity();
-
-        if (includeInstance(view.getCommonName(), view.getVersion(), instance.getInstanceName(),
false)) {
-          try {
-            ViewRegistry.getInstance().updateViewInstance(instance);
-            ViewRegistry.getInstance().updateView(instance);
-          } catch (org.apache.ambari.view.SystemException e) {
-            throw new AmbariException("Caught exception trying to update view instance.",
e);
-          } catch (ValidationException e) {
-            // results in a BAD_REQUEST (400) response for the validation failure.
-            throw new IllegalArgumentException(e.getMessage(), e);
-          }
-        }
+        update(properties);
         return null;
       }
     };
@@ -463,32 +423,92 @@ public class ViewInstanceResourceProvider extends AbstractAuthorizedResourceProv
     return new Command<Void>() {
       @Override
       public Void invoke() throws AmbariException {
-        Set<String>  requestedIds = getRequestPropertyIds(PropertyHelper.getReadRequest(),
predicate);
-        ViewRegistry viewRegistry = ViewRegistry.getInstance();
-
-        Set<ViewInstanceEntity> viewInstanceEntities = new HashSet<ViewInstanceEntity>();
-
-        for (ViewEntity viewEntity : viewRegistry.getDefinitions()){
-          // the view must be in the DEPLOYED state to delete an instance
-          if (viewEntity.isDeployed()) {
-            for (ViewInstanceEntity viewInstanceEntity : viewRegistry.getInstanceDefinitions(viewEntity)){
-              Resource resource = toResource(viewInstanceEntity, requestedIds);
-              if (predicate == null || predicate.evaluate(resource)) {
-                if (includeInstance(viewInstanceEntity, false)) {
-                  viewInstanceEntities.add(viewInstanceEntity);
-                }
-              }
+        delete(predicate);
+        return null;
+      }
+    };
+  }
+
+  @Transactional
+  void create(Map<String, Object> properties) throws AmbariException {
+    try {
+      ViewRegistry       viewRegistry   = ViewRegistry.getInstance();
+      ViewInstanceEntity instanceEntity = toEntity(properties, false);
+
+      ViewEntity viewEntity = instanceEntity.getViewEntity();
+      String     viewName   = viewEntity.getCommonName();
+      String     version    = viewEntity.getVersion();
+      ViewEntity view       = viewRegistry.getDefinition(viewName, version);
+
+      if ( view == null ) {
+        throw new IllegalStateException("The view " + viewName + " is not registered.");
+      }
+
+      // the view must be in the DEPLOYED state to create an instance
+      if (!view.isDeployed()) {
+        throw new IllegalStateException("The view " + viewName + " is not loaded.");
+      }
+
+      if (viewRegistry.instanceExists(instanceEntity)) {
+        throw new DuplicateResourceException("The instance " + instanceEntity.getName() +
" already exists.");
+      }
+      viewRegistry.installViewInstance(instanceEntity);
+    } catch (org.apache.ambari.view.SystemException e) {
+      throw new AmbariException("Caught exception trying to create view instance.", e);
+    } catch (ValidationException e) {
+      // results in a BAD_REQUEST (400) response for the validation failure.
+      throw new IllegalArgumentException(e.getMessage(), e);
+    }
+  }
+
+  @Transactional
+  void update(Map<String, Object> properties) throws AmbariException {
+    ViewInstanceEntity instance = toEntity(properties, true);
+    ViewEntity         view     = instance.getViewEntity();
+
+    if (includeInstance(view.getCommonName(), view.getVersion(), instance.getInstanceName(),
false)) {
+      try {
+        ViewRegistry.getInstance().updateViewInstance(instance);
+        ViewRegistry.getInstance().updateView(instance);
+      } catch (org.apache.ambari.view.SystemException e) {
+        throw new AmbariException("Caught exception trying to update view instance.", e);
+      } catch (ValidationException e) {
+        // results in a BAD_REQUEST (400) response for the validation failure.
+        throw new IllegalArgumentException(e.getMessage(), e);
+      }
+    }
+
+  }
+
+  @Transactional
+  void delete(Predicate predicate) {
+    Set<String>  requestedIds = getRequestPropertyIds(PropertyHelper.getReadRequest(),
predicate);
+    ViewRegistry viewRegistry = ViewRegistry.getInstance();
+
+    Set<ViewInstanceEntity> viewInstanceEntities = new HashSet<>();
+
+    for (ViewEntity viewEntity : viewRegistry.getDefinitions()){
+      // the view must be in the DEPLOYED state to delete an instance
+      if (viewEntity.isDeployed()) {
+        for (ViewInstanceEntity viewInstanceEntity : viewRegistry.getInstanceDefinitions(viewEntity)){
+          Resource resource = toResource(viewInstanceEntity, requestedIds);
+          if (predicate == null || predicate.evaluate(resource)) {
+            if (includeInstance(viewInstanceEntity, false)) {
+              viewInstanceEntities.add(viewInstanceEntity);
             }
           }
         }
-        for (ViewInstanceEntity viewInstanceEntity : viewInstanceEntities) {
-          viewRegistry.uninstallViewInstance(viewInstanceEntity);
-        }
-        return null;
       }
-    };
+    }
+    for (ViewInstanceEntity viewInstanceEntity : viewInstanceEntities) {
+      viewRegistry.uninstallViewInstance(viewInstanceEntity);
+    }
+
   }
 
+
+
+
   // get the icon path
   private static String getIconPath(String contextPath, String iconPath){
     return iconPath == null || iconPath.length() == 0 ? null :


Mime
View raw message