ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject ambari git commit: AMBARI-9214 - Upgrades: Make a ResourceDefinition for UpgradeResourceProvider for downgrade directive (tbeerbower)
Date Tue, 20 Jan 2015 18:45:21 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 3ae28d8b2 -> 0898c7373


AMBARI-9214 - Upgrades: Make a ResourceDefinition for UpgradeResourceProvider for downgrade
directive (tbeerbower)


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

Branch: refs/heads/trunk
Commit: 0898c7373c39247c413b806bb2f5ecc5ce6d1f66
Parents: 3ae28d8
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Tue Jan 20 13:44:48 2015 -0500
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Tue Jan 20 13:44:48 2015 -0500

----------------------------------------------------------------------
 .../api/resources/BaseResourceDefinition.java   | 26 ++++++++-
 .../ClientConfigResourceDefinition.java         | 15 +----
 .../resources/ResourceInstanceFactoryImpl.java  |  4 +-
 .../api/resources/SimpleResourceDefinition.java | 19 +++++++
 .../resources/UpgradeResourceDefinition.java    | 41 ++++++++++++++
 .../internal/UpgradeResourceProvider.java       | 38 ++++++++-----
 .../resources/BaseResourceDefinitionTest.java   | 30 ++++++++++
 .../resources/SimpleResourceDefinitionTest.java | 18 ++++++
 .../UpgradeResourceDefinitionTest.java          | 59 ++++++++++++++++++++
 .../internal/UpgradeResourceProviderTest.java   | 14 +++--
 10 files changed, 229 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/main/java/org/apache/ambari/server/api/resources/BaseResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/BaseResourceDefinition.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/BaseResourceDefinition.java
index 1cd7e17..f98779c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/BaseResourceDefinition.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/BaseResourceDefinition.java
@@ -52,6 +52,11 @@ public abstract class BaseResourceDefinition implements ResourceDefinition
{
   private final Set<SubResourceDefinition> subResourceDefinitions;
 
   /**
+   * The set of create directives for the resource which can be modified by sub resources.
+   */
+  private final Collection<String> createDirectives = new HashSet<String>();
+
+  /**
    * Constructor.
    *
    * @param resourceType resource type
@@ -76,6 +81,25 @@ public abstract class BaseResourceDefinition implements ResourceDefinition
{
     }
   }
 
+  /**
+   * Constructor.
+   *
+   * @param resourceType      the resource type
+   * @param subTypes          the sub-resource types
+   * @param createDirectives  the set of create directives for the resource
+   */
+  public BaseResourceDefinition(Resource.Type resourceType,
+                                Set<Resource.Type> subTypes,
+                                Collection<String> createDirectives) {
+    m_type = resourceType;
+    subResourceDefinitions =  new HashSet<SubResourceDefinition>();
+
+    for (Resource.Type subType : subTypes) {
+      subResourceDefinitions.add(new SubResourceDefinition(subType));
+    }
+    this.createDirectives.addAll(createDirectives);
+  }
+
   @Override
   public Resource.Type getType() {
     return m_type;
@@ -112,7 +136,7 @@ public abstract class BaseResourceDefinition implements ResourceDefinition
{
   @Override
   public Collection<String> getCreateDirectives() {
     // return a collection which can be modified by sub resources
-    return new HashSet<String>();
+    return createDirectives;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClientConfigResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClientConfigResourceDefinition.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClientConfigResourceDefinition.java
index 4ff37ac..d255716 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClientConfigResourceDefinition.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ClientConfigResourceDefinition.java
@@ -18,22 +18,17 @@
 
 package org.apache.ambari.server.api.resources;
 
-import org.apache.ambari.server.api.query.render.ClusterBlueprintRenderer;
 import org.apache.ambari.server.api.query.render.DefaultRenderer;
-import org.apache.ambari.server.api.query.render.MinimalRenderer;
 import org.apache.ambari.server.api.query.render.Renderer;
 import org.apache.ambari.server.controller.spi.Resource;
 
-import java.util.Collection;
-
 
 /**
- * Blueprint resource definition.
+ * Client configuration resource definition.
  */
 public class ClientConfigResourceDefinition extends BaseResourceDefinition {
   /**
    * Constructor.
-   *
    */
   public ClientConfigResourceDefinition() {
     super(Resource.Type.ClientConfig);
@@ -57,12 +52,4 @@ public class ClientConfigResourceDefinition extends BaseResourceDefinition
{
       return super.getRenderer(name);
     }
   }
-
-  @Override
-  public Collection<String> getCreateDirectives() {
-    Collection<String> directives = super.getCreateDirectives();
-    directives.add("validate_topology");
-
-    return directives;
-  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
index fc28c13..5da9847 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/ResourceInstanceFactoryImpl.java
@@ -318,9 +318,7 @@ public class ResourceInstanceFactoryImpl implements ResourceInstanceFactory
{
         break;
 
       case Upgrade:
-        resourceDefinition = new SimpleResourceDefinition(
-            Resource.Type.Upgrade, "upgrade", "upgrades",
-            Resource.Type.UpgradeGroup);
+        resourceDefinition = new UpgradeResourceDefinition();
         break;
 
       case UpgradeGroup:

http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/main/java/org/apache/ambari/server/api/resources/SimpleResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/SimpleResourceDefinition.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/SimpleResourceDefinition.java
index 92ecd1e..394e295 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/SimpleResourceDefinition.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/SimpleResourceDefinition.java
@@ -20,6 +20,9 @@ package org.apache.ambari.server.api.resources;
 
 import org.apache.ambari.server.controller.spi.Resource;
 
+import java.util.Collection;
+import java.util.Set;
+
 /**
  * Simple concrete resource definition.
  */
@@ -54,6 +57,22 @@ public class SimpleResourceDefinition extends BaseResourceDefinition {
     this.pluralName   = pluralName;
   }
 
+  /**
+   * Constructor.
+   * @param resourceType      the resource type
+   * @param singularName      the resource singular name
+   * @param pluralName        the resource plural name
+   * @param subTypes          the sub-resource types
+   * @param createDirectives  the set of create directives for the resource
+   */
+  public SimpleResourceDefinition(Resource.Type resourceType, String singularName, String
pluralName,
+                                  Set<Resource.Type> subTypes,
+                                  Collection<String> createDirectives) {
+    super(resourceType, subTypes, createDirectives);
+
+    this.singularName = singularName;
+    this.pluralName   = pluralName;
+  }
 
   // ----- ResourceDefinition ------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/main/java/org/apache/ambari/server/api/resources/UpgradeResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/UpgradeResourceDefinition.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/UpgradeResourceDefinition.java
new file mode 100644
index 0000000..bf7860b
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/UpgradeResourceDefinition.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.resources;
+
+import org.apache.ambari.server.controller.spi.Resource;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+/**
+ * Upgrade resource definition.
+ */
+public class UpgradeResourceDefinition extends SimpleResourceDefinition {
+
+  public static String DOWNGRADE_DIRECTIVE           = "downgrade";
+  public static String SKIP_SERVICE_CHECKS_DIRECTIVE = "skip_service_checks";
+
+  /**
+   * Constructor.
+   */
+  public UpgradeResourceDefinition() {
+    super(Resource.Type.Upgrade, "upgrade", "upgrades", Collections.singleton(Resource.Type.UpgradeGroup),
+        Arrays.asList(DOWNGRADE_DIRECTIVE, SKIP_SERVICE_CHECKS_DIRECTIVE));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index d9c9aec..746a04a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -42,6 +42,7 @@ import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.RequestFactory;
 import org.apache.ambari.server.actionmanager.Stage;
 import org.apache.ambari.server.actionmanager.StageFactory;
+import org.apache.ambari.server.api.resources.UpgradeResourceDefinition;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.ActionExecutionContext;
 import org.apache.ambari.server.controller.AmbariActionExecutionHelper;
@@ -96,6 +97,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
   protected static final String UPGRADE_CLUSTER_NAME = "Upgrade/cluster_name";
   protected static final String UPGRADE_VERSION = "Upgrade/repository_version";
   protected static final String UPGRADE_REQUEST_ID = "Upgrade/request_id";
+  // TODO : Get rid of the UPGRADE_FORCE_DOWNGRADE property... should use downgrade create
directive
   protected static final String UPGRADE_FORCE_DOWNGRADE = "Upgrade/force_downgrade";
   protected static final String UPGRADE_FROM_VERSION = "Upgrade/from_version";
   protected static final String UPGRADE_TO_VERSION = "Upgrade/to_version";
@@ -182,13 +184,14 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
 
     // !!! above check ensures only one
     final Map<String, Object> requestMap = requestMaps.iterator().next();
+    final Map<String, String> requestInfoProps = request.getRequestInfoProperties();
 
     UpgradeEntity entity = createResources(new Command<UpgradeEntity>() {
         @Override
         public UpgradeEntity invoke() throws AmbariException {
-          UpgradePack up = validateRequest(requestMap);
+          UpgradePack up = validateRequest(requestMap, requestInfoProps);
 
-          return createUpgrade(up, requestMap);
+          return createUpgrade(up, requestMap, requestInfoProps);
         }
       });
 
@@ -306,13 +309,18 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
    * @return the validated upgrade pack
    * @throws AmbariException
    */
-  private UpgradePack validateRequest(Map<String, Object> requestMap) throws AmbariException
{
+  private UpgradePack validateRequest(Map<String, Object> requestMap, Map<String,
String> requestInfoProps)
+      throws AmbariException {
     String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
     String version = (String) requestMap.get(UPGRADE_VERSION);
-    String forceDowngrade = (String) requestMap.get(UPGRADE_FORCE_DOWNGRADE);
     String versionForUpgradePack = (String) requestMap.get(UPGRADE_FROM_VERSION);
 
-    boolean forDowngrade = (null != forceDowngrade && Boolean.parseBoolean(forceDowngrade));
+    String forceDowngrade = requestInfoProps.get(UpgradeResourceDefinition.DOWNGRADE_DIRECTIVE);
+
+    // check the property if the directive is not specified...
+    if (forceDowngrade == null) {
+      forceDowngrade = (String) requestMap.get(UPGRADE_FORCE_DOWNGRADE);
+    }
 
     if (null == clusterName) {
       throw new AmbariException(String.format("%s is required", UPGRADE_CLUSTER_NAME));
@@ -327,7 +335,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
 
     String repoVersion = version;
 
-    if (forDowngrade && null != versionForUpgradePack) {
+    if (Boolean.valueOf(forceDowngrade) && null != versionForUpgradePack) {
       repoVersion = versionForUpgradePack;
     }
 
@@ -385,8 +393,9 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
     }
   }
 
-  private UpgradeEntity createUpgrade(UpgradePack pack, Map<String, Object> requestMap)
-    throws AmbariException {
+  private UpgradeEntity createUpgrade(UpgradePack pack,
+                                      Map<String, Object> requestMap,
+                                      Map<String, String> requestInfoProps) throws
AmbariException {
 
     String clusterName = (String) requestMap.get(UPGRADE_CLUSTER_NAME);
 
@@ -397,14 +406,19 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
     Cluster cluster = getManagementController().getClusters().getCluster(clusterName);
     ConfigHelper configHelper = getManagementController().getConfigHelper();
 
-    String forceDowngrade = (String) requestMap.get(UPGRADE_FORCE_DOWNGRADE);
+    String forceDowngrade = requestInfoProps.get(UpgradeResourceDefinition.DOWNGRADE_DIRECTIVE);
+
+    // check the property if the directive is not specified...
+    if (forceDowngrade == null) {
+      forceDowngrade = (String) requestMap.get(UPGRADE_FORCE_DOWNGRADE);
+    }
 
     List<UpgradeGroupHolder> groups = null;
 
     // the version being upgraded or downgraded to (ie hdp-2.2.1.0-1234)
     final String version = (String) requestMap.get(UPGRADE_VERSION);
 
-    if (null != forceDowngrade && Boolean.parseBoolean(forceDowngrade)) {
+    if (Boolean.valueOf(forceDowngrade)) {
       MasterHostResolver mhr = new MasterHostResolver(cluster, version);
       groups = s_upgradeHelper.createDowngrade(mhr, pack, version);
     } else {
@@ -459,7 +473,6 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
           // upgrade items match a stage
           createStage(cluster, req, version, itemEntity, wrapper, skippable, allowRetry);
         }
-
       }
 
       groupEntity.setItems(itemEntities);
@@ -508,12 +521,11 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
         makeActionStage(cluster, request, version, entity, wrapper, skippable, allowRetry);
         break;
       case SERVICE_CHECK:
-        makeServiceCheckStage(cluster, request, version, entity, wrapper, skippable, allowRetry);
+          makeServiceCheckStage(cluster, request, version, entity, wrapper, skippable, allowRetry);
         break;
       default:
         break;
     }
-
   }
 
   private void makeActionStage(Cluster cluster, RequestStageContainer request, final String
version,

http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/test/java/org/apache/ambari/server/api/resources/BaseResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/BaseResourceDefinitionTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/BaseResourceDefinitionTest.java
index 73aa828..da3fe3f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/BaseResourceDefinitionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/BaseResourceDefinitionTest.java
@@ -23,6 +23,7 @@ import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.anyObject;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -47,6 +48,9 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -135,6 +139,17 @@ public class BaseResourceDefinitionTest {
     }
   }
 
+  @Test
+  public void testGetCreateDirectives() {
+    ResourceDefinition resource = getResourceDefinition();
+
+    assertEquals(Collections.EMPTY_SET, resource.getCreateDirectives());
+
+    resource = getResourceDefinition("do_something", "do_something_else");
+
+    assertEquals(new HashSet<String>() {{add("do_something"); add("do_something_else");}},
resource.getCreateDirectives());
+  }
+
   private BaseResourceDefinition getResourceDefinition() {
     return new BaseResourceDefinition(Resource.Type.Service) {
       @Override
@@ -148,4 +163,19 @@ public class BaseResourceDefinitionTest {
       }
     };
   }
+
+  private BaseResourceDefinition getResourceDefinition(String ... createDirectives) {
+    return new BaseResourceDefinition(Resource.Type.Service,
+        Collections.<Resource.Type>emptySet(), new HashSet<String>(Arrays.asList(createDirectives)))
{
+      @Override
+      public String getPluralName() {
+        return "pluralName";
+      }
+
+      @Override
+      public String getSingularName() {
+        return "singularName";
+      }
+    };
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/test/java/org/apache/ambari/server/api/resources/SimpleResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/SimpleResourceDefinitionTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/SimpleResourceDefinitionTest.java
index d264511..6169ee7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/SimpleResourceDefinitionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/SimpleResourceDefinitionTest.java
@@ -20,6 +20,10 @@ package org.apache.ambari.server.api.resources;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.junit.Test;
 
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+
 import static org.junit.Assert.assertEquals;
 
 /**
@@ -42,4 +46,18 @@ public class SimpleResourceDefinitionTest {
 
     assertEquals("stage", resourceDefinition.getSingularName());
   }
+
+  @Test
+  public void testGetCreateDirectives() {
+    ResourceDefinition resourceDefinition =
+        new SimpleResourceDefinition(Resource.Type.Stage, "stage", "stages", Resource.Type.Task);
+
+    assertEquals(Collections.EMPTY_SET, resourceDefinition.getCreateDirectives());
+
+    resourceDefinition = new SimpleResourceDefinition(Resource.Type.Stage, "stage", "stages",
+            Collections.singleton(Resource.Type.Task), Arrays.asList("do_something", "do_something_else"));
+
+    assertEquals(new HashSet<String>() {{add("do_something"); add("do_something_else");}},
+        resourceDefinition.getCreateDirectives());
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/test/java/org/apache/ambari/server/api/resources/UpgradeResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/UpgradeResourceDefinitionTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/UpgradeResourceDefinitionTest.java
new file mode 100644
index 0000000..e2db813
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/UpgradeResourceDefinitionTest.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.resources;
+
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.HashSet;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * UpgradeResourceDefinition tests.
+ */
+public class UpgradeResourceDefinitionTest {
+
+  @Test
+  public void testGetSingularName() {
+    ResourceDefinition resourceDefinition = new UpgradeResourceDefinition();
+    assertEquals("upgrade", resourceDefinition.getSingularName());
+  }
+
+  @Test
+  public void testGetPluralName() {
+    ResourceDefinition resourceDefinition = new UpgradeResourceDefinition();
+    assertEquals("upgrades", resourceDefinition.getPluralName());
+  }
+
+  @Test
+  public void testGetType() {
+    ResourceDefinition resourceDefinition = new UpgradeResourceDefinition();
+    assertEquals(Resource.Type.Upgrade, resourceDefinition.getType());
+  }
+
+  @Test
+  public void testGetCreateDirectives() {
+    ResourceDefinition resourceDefinition = new UpgradeResourceDefinition();
+
+    assertEquals(
+        new HashSet<String>() {{add(UpgradeResourceDefinition.DOWNGRADE_DIRECTIVE);
add(UpgradeResourceDefinition.SKIP_SERVICE_CHECKS_DIRECTIVE);}},
+        resourceDefinition.getCreateDirectives());
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/0898c737/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index cd5f23e..abd2c64 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -34,6 +34,7 @@ import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.RequestStatus;
 import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.api.resources.UpgradeResourceDefinition;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.AmbariServer;
 import org.apache.ambari.server.controller.spi.Predicate;
@@ -357,11 +358,13 @@ public class UpgradeResourceProviderTest {
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.2.1");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_FORCE_DOWNGRADE, "true");
+
+    Map<String, String> requestInfoProperties = new HashMap<String, String>();
+    requestInfoProperties.put(UpgradeResourceDefinition.DOWNGRADE_DIRECTIVE, "true");
 
     ResourceProvider upgradeResourceProvider = createProvider(amc);
 
-    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps),
null);
+    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps),
requestInfoProperties);
     upgradeResourceProvider.createResources(request);
 
     upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
@@ -409,9 +412,12 @@ public class UpgradeResourceProviderTest {
 
     requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
     requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_FORCE_DOWNGRADE, "true");
     requestProps.put(UpgradeResourceProvider.UPGRADE_FROM_VERSION, "2.2.2.1");
-    request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
+
+    Map<String, String> requestInfoProperties = new HashMap<String, String>();
+    requestInfoProperties.put(UpgradeResourceDefinition.DOWNGRADE_DIRECTIVE, "true");
+
+    request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), requestInfoProperties);
     status = upgradeResourceProvider.createResources(request);
     assertEquals(1, status.getAssociatedResources().size());
     Resource r = status.getAssociatedResources().iterator().next();


Mime
View raw message