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-16889. RU: install version should be blocked while upgrade in progress (ncole)
Date Thu, 26 May 2016 16:23:49 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 9703f2408 -> 456d2e547


AMBARI-16889. RU: install version should be blocked while upgrade in progress (ncole)


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

Branch: refs/heads/branch-2.4
Commit: 456d2e547ce9327b7c5e486024d2649eee116a2d
Parents: 9703f24
Author: Nate Cole <ncole@hortonworks.com>
Authored: Thu May 26 12:20:28 2016 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Thu May 26 12:20:28 2016 -0400

----------------------------------------------------------------------
 .../ClusterStackVersionResourceProvider.java    | 17 +++++-
 .../server/state/cluster/ClusterImpl.java       |  6 +-
 .../src/main/resources/version_definition.xsd   |  1 +
 ...ClusterStackVersionResourceProviderTest.java | 59 ++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/456d2e54/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
index 05ee6c9..532ab2f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java
@@ -68,6 +68,7 @@ import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
 import org.apache.ambari.server.orm.entities.RepositoryEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -282,14 +283,17 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
   public RequestStatus createResources(Request request) throws SystemException,
           UnsupportedPropertyException, ResourceAlreadyExistsException,
           NoSuchParentResourceException {
+
+    if (request.getProperties().size() > 1) {
+      throw new UnsupportedOperationException("Multiple requests cannot be executed at the
same time.");
+    }
+
     Iterator<Map<String, Object>> iterator = request.getProperties().iterator();
+
     String clName;
     final String desiredRepoVersion;
     String stackName;
     String stackVersion;
-    if (request.getProperties().size() != 1) {
-      throw new UnsupportedOperationException("Multiple requests cannot be executed at the
same time.");
-    }
 
     Map<String, Object> propertyMap = iterator.next();
 
@@ -321,6 +325,13 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
       throw new NoSuchParentResourceException(e.getMessage(), e);
     }
 
+    UpgradeEntity entity = cluster.getUpgradeInProgress();
+    if (null != entity) {
+      throw new IllegalArgumentException(String.format(
+          "Cluster %s %s is in progress.  Cannot install packages.",
+          cluster.getClusterName(), entity.getDirection().getText(false)));
+    }
+
     // get all of the host eligible for stack distribution
     List<Host> hosts = getHostsForStackDistribution(cluster);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/456d2e54/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
index 4a214e1..9e9128e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java
@@ -1215,10 +1215,14 @@ public class ClusterImpl implements Cluster {
       return upgradeInProgress;
     }
 
-    // perform a search for any upgrade which shoudl also return upgrades which
+    // perform a search for any upgrade which should also return upgrades which
     // are suspended
     UpgradeEntity mostRecentUpgrade = upgradeDAO.findLastUpgradeOrDowngradeForCluster(getClusterId());
     if (mostRecentUpgrade != null) {
+      if (mostRecentUpgrade.isSuspended()) {
+        return mostRecentUpgrade;
+      }
+
       List<HostRoleStatus> UNFINISHED_STATUSES = new ArrayList<>();
       UNFINISHED_STATUSES.add(HostRoleStatus.PENDING);
       UNFINISHED_STATUSES.add(HostRoleStatus.ABORTED);

http://git-wip-us.apache.org/repos/asf/ambari/blob/456d2e54/ambari-server/src/main/resources/version_definition.xsd
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/version_definition.xsd b/ambari-server/src/main/resources/version_definition.xsd
index b6360ee..8c20c06 100644
--- a/ambari-server/src/main/resources/version_definition.xsd
+++ b/ambari-server/src/main/resources/version_definition.xsd
@@ -50,6 +50,7 @@
     <xs:restriction base="xs:string">
       <xs:enumeration value="redhat6" />
       <xs:enumeration value="redhat7" />
+      <xs:enumeration value="debian6" />
       <xs:enumeration value="debian7" />
       <xs:enumeration value="ubuntu12" />
       <xs:enumeration value="ubuntu14" />

http://git-wip-us.apache.org/repos/asf/ambari/blob/456d2e54/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
index 8347a7b..403f426 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
@@ -80,6 +80,7 @@ import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.ResourceEntity;
 import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
+import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.security.authorization.ResourceType;
 import org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction;
 import org.apache.ambari.server.state.Cluster;
@@ -96,6 +97,7 @@ import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.ServiceOsSpecific;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.cluster.ClusterImpl;
+import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.topology.TopologyManager;
 import org.apache.ambari.server.utils.StageUtils;
 import org.apache.commons.io.IOUtils;
@@ -1500,7 +1502,64 @@ public class ClusterStackVersionResourceProviderTest {
 
   }
 
+  @Test
+  public void testCreateResourcesExistingUpgrade() throws Exception {
+    Resource.Type type = Resource.Type.ClusterStackVersion;
 
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+
+    expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
+
+    UpgradeEntity upgrade = new UpgradeEntity();
+    upgrade.setDirection(Direction.UPGRADE);
+
+    expect(cluster.getClusterName()).andReturn("c1").atLeastOnce();
+    expect(cluster.getClusterId()).andReturn(1L).anyTimes();
+    expect(cluster.getUpgradeInProgress()).andReturn(upgrade).once();
+
+    // replay
+    replay(managementController, clusters, cluster);
+
+    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    injector.injectMembers(provider);
+
+    // add the property map to a set for the request.  add more maps for multiple creates
+    Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String,
Object>>();
+
+    Map<String, Object> properties = new LinkedHashMap<String, Object>();
+
+    // add properties to the request map
+    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID,
"Cluster100");
+    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
"2.2.0.1-885");
+    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_STACK_PROPERTY_ID,
"HDP");
+    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID,
"2.1.1");
+
+    propertySet.add(properties);
+
+    // create the request
+    Request request = PropertyHelper.getCreateRequest(propertySet, null);
+
+    try {
+      provider.createResources(request);
+      Assert.fail("Expecting the create to fail due to an already installed version");
+    } catch (IllegalArgumentException iae) {
+      // !!! expected
+      Assert.assertEquals("Cluster c1 upgrade is in progress.  Cannot install packages.",
iae.getMessage());
+    }
+
+    verify(cluster);
+
+  }
   private class MockModule extends AbstractModule {
     @Override
     protected void configure() {


Mime
View raw message