ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject ambari git commit: AMBARI-8549. Rolling Upgrade: ClusterStackVersion should display only one repository version (dlysnichenko)
Date Mon, 08 Dec 2014 19:50:57 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 0d6e0c57f -> 9053513f6


AMBARI-8549. Rolling Upgrade: ClusterStackVersion should display only one repository version
(dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 9053513f66023e6d062f94e3df00e9de1791a9f0
Parents: 0d6e0c5
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Mon Dec 8 21:50:01 2014 +0200
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Mon Dec 8 21:50:01 2014 +0200

----------------------------------------------------------------------
 .../services/ClusterStackVersionService.java    | 14 -----
 .../ClusterStackVersionResourceProvider.java    | 63 ++++++++++++--------
 .../HostStackVersionResourceProvider.java       | 47 ++++++++++++---
 .../RepositoryVersionResourceProvider.java      |  6 +-
 .../org/apache/ambari/server/state/Cluster.java |  7 +++
 .../server/state/cluster/ClusterImpl.java       | 38 ++++++++++--
 ...ClusterStackVersionResourceProviderTest.java |  3 +-
 7 files changed, 121 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9053513f/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterStackVersionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterStackVersionService.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterStackVersionService.java
index 97d3bde..406e255 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterStackVersionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/ClusterStackVersionService.java
@@ -85,20 +85,6 @@ public class ClusterStackVersionService extends BaseService {
   }
 
   /**
-   * Handles ANY /{stackVersionId}/repository_versions requests.
-   *
-   * @param stackVersionId cluster stack version id
-   * @return repository version service
-   */
-  @Path("{stackVersionId}/repository_versions")
-  public RepositoryVersionService getRepositoryVersionHandler(@PathParam("stackVersionId")
String stackVersionId) {
-    final Map<Resource.Type, String> stackVersionProperties = new HashMap<Resource.Type,
String>();
-    stackVersionProperties.put(Resource.Type.Cluster, clusterName);
-    stackVersionProperties.put(Resource.Type.ClusterStackVersion, stackVersionId);
-    return new RepositoryVersionService(stackVersionProperties);
-  }
-
-  /**
    * Handles: POST /{clustername}/stack_versions requests
    * Distribute repositories/install packages.
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/9053513f/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 a12bd29..1c2297b 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
@@ -84,10 +84,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
   protected static final String CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID              =
PropertyHelper.getPropertyId("ClusterStackVersions", "version");
   protected static final String CLUSTER_STACK_VERSION_STATE_PROPERTY_ID                =
PropertyHelper.getPropertyId("ClusterStackVersions", "state");
   protected static final String CLUSTER_STACK_VERSION_HOST_STATES_PROPERTY_ID          =
PropertyHelper.getPropertyId("ClusterStackVersions", "host_states");
-
-  protected static final String STACK_VERSION_REPO_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("StackVersion",
"repository_version");
-  protected static final String STACK_VERSION_STACK_PROPERTY_ID    = PropertyHelper.getPropertyId("StackVersion",
"stack");
-  protected static final String STACK_VERSION_VERSION_PROPERTY_ID    = PropertyHelper.getPropertyId("StackVersion",
"version");
+  protected static final String CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID   =
PropertyHelper.getPropertyId("ClusterStackVersions", "repository_version");
 
   protected static final String INSTALL_PACKAGES_ACTION = "install_packages";
   protected static final String INSTALL_PACKAGES_FULL_NAME = "Distribute repositories/install
packages";
@@ -99,9 +96,8 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
       add(CLUSTER_STACK_VERSION_ID_PROPERTY_ID);
       add(CLUSTER_STACK_VERSION_STACK_PROPERTY_ID);
       add(CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID);
-      add(STACK_VERSION_REPO_VERSION_PROPERTY_ID);
-      add(STACK_VERSION_STACK_PROPERTY_ID);
-      add(STACK_VERSION_VERSION_PROPERTY_ID);
+      add(CLUSTER_STACK_VERSION_STATE_PROPERTY_ID);
+      add(CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID);
     }
   };
 
@@ -114,19 +110,19 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
       add(CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID);
       add(CLUSTER_STACK_VERSION_STATE_PROPERTY_ID);
       add(CLUSTER_STACK_VERSION_HOST_STATES_PROPERTY_ID);
-      add(STACK_VERSION_REPO_VERSION_PROPERTY_ID);
-      add(STACK_VERSION_STACK_PROPERTY_ID);
-      add(STACK_VERSION_VERSION_PROPERTY_ID);
+      add(CLUSTER_STACK_VERSION_STATE_PROPERTY_ID);
+      add(CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID);
     }
   };
 
   @SuppressWarnings("serial")
   private static Map<Type, String> keyPropertyIds = new HashMap<Type, String>()
{
     {
-      put(Resource.Type.Cluster, CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID);
-      put(Resource.Type.ClusterStackVersion, CLUSTER_STACK_VERSION_ID_PROPERTY_ID);
-      put(Resource.Type.Stack, CLUSTER_STACK_VERSION_STACK_PROPERTY_ID);
-      put(Resource.Type.StackVersion, CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID);
+      put(Type.Cluster, CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID);
+      put(Type.ClusterStackVersion, CLUSTER_STACK_VERSION_ID_PROPERTY_ID);
+      put(Type.Stack, CLUSTER_STACK_VERSION_STACK_PROPERTY_ID);
+      put(Type.StackVersion, CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID);
+      put(Type.RepositoryVersion, CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID);
     }
   };
 
@@ -196,13 +192,19 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
       for (HostVersionEntity hostVersionEntity: hostVersionDAO.findByClusterStackAndVersion(entity.getClusterEntity().getClusterName(),
entity.getStack(), entity.getVersion())) {
         hostStates.get(hostVersionEntity.getState().name()).add(hostVersionEntity.getHostName());
       }
+      StackId stackId = new StackId(entity.getStack());
+      RepositoryVersionEntity repoVerEntity = repositoryVersionDAO.findByStackAndVersion(stackId.getStackId(),
entity.getVersion());
 
       setResourceProperty(resource, CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID, entity.getClusterEntity().getClusterName(),
requestedIds);
       setResourceProperty(resource, CLUSTER_STACK_VERSION_HOST_STATES_PROPERTY_ID, hostStates,
requestedIds);
       setResourceProperty(resource, CLUSTER_STACK_VERSION_ID_PROPERTY_ID, entity.getId(),
requestedIds);
-      setResourceProperty(resource, CLUSTER_STACK_VERSION_STACK_PROPERTY_ID, entity.getStack(),
requestedIds);
+      setResourceProperty(resource, CLUSTER_STACK_VERSION_STACK_PROPERTY_ID, stackId.getStackName(),
requestedIds);
       setResourceProperty(resource, CLUSTER_STACK_VERSION_STATE_PROPERTY_ID, entity.getState().name(),
requestedIds);
-      setResourceProperty(resource, CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID, entity.getVersion(),
requestedIds);
+      setResourceProperty(resource, CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID, stackId.getStackVersion(),
requestedIds);
+      if (repoVerEntity!=null) {
+        Long repoVersionId = repoVerEntity.getId();
+        setResourceProperty(resource, CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
repoVersionId, requestedIds);
+      }
 
       if (predicate == null || predicate.evaluate(resource)) {
         resources.add(resource);
@@ -211,6 +213,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
     return resources;
   }
 
+
   @Override
   public RequestStatus createResources(Request request) throws SystemException,
           UnsupportedPropertyException, ResourceAlreadyExistsException,
@@ -226,14 +229,14 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
 
     Map<String, Object> propertyMap = iterator.next();
     if (!propertyMap.containsKey(CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID) ||
-            !propertyMap.containsKey(STACK_VERSION_REPO_VERSION_PROPERTY_ID)) {
+            !propertyMap.containsKey(CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID))
{
       throw new IllegalArgumentException(
               String.format("%s or %s not defined",
                       CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID,
-                      STACK_VERSION_REPO_VERSION_PROPERTY_ID));
+                      CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID));
     }
     clName = (String) propertyMap.get(CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID);
-    desiredRepoVersion = (String) propertyMap.get(STACK_VERSION_REPO_VERSION_PROPERTY_ID);
+    desiredRepoVersion = (String) propertyMap.get(CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID);
 
     Cluster cluster;
     Map<String, Host> hostsForCluster;
@@ -248,10 +251,10 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
     }
 
     String stackId;
-    if (propertyMap.containsKey(STACK_VERSION_STACK_PROPERTY_ID) &&
-            propertyMap.containsKey(STACK_VERSION_VERSION_PROPERTY_ID)) {
-      stackName = (String) propertyMap.get(STACK_VERSION_STACK_PROPERTY_ID);
-      stackVersion = (String) propertyMap.get(STACK_VERSION_VERSION_PROPERTY_ID);
+    if (propertyMap.containsKey(CLUSTER_STACK_VERSION_STACK_PROPERTY_ID) &&
+            propertyMap.containsKey(CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID)) {
+      stackName = (String) propertyMap.get(CLUSTER_STACK_VERSION_STACK_PROPERTY_ID);
+      stackVersion = (String) propertyMap.get(CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID);
       stackId = new StackId(stackName, stackVersion).getStackId();
       if (! ami.isSupportedStack(stackName, stackVersion)) {
         throw new NoSuchParentResourceException(String.format("Stack %s is not supported",
@@ -355,8 +358,18 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
     try {
       req.persist();
 
-      //TODO: create cluster version entity
-      //clusterVersionDAO.create();
+      try {  // Create/persist cluster stack version
+        cluster.createClusterVersion(stackId, desiredRepoVersion, managementController.getAuthName(),
RepositoryVersionState.INSTALLED);
+        ClusterVersionEntity newCSVer = clusterVersionDAO.findByClusterAndStackAndVersion(clName,
stackId, desiredRepoVersion);
+        cluster.initHostVersions(newCSVer);
+      } catch (AmbariException e) {
+        throw new SystemException(
+                String.format(
+                        "Can not create cluster stack version %s for cluster %s",
+                        desiredRepoVersion, clName),
+                e);
+      }
+
     } catch (AmbariException e) {
       throw new SystemException("Can not persist request", e);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/9053513f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java
index 1b3eef8..b278177 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java
@@ -123,11 +123,12 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
   @SuppressWarnings("serial")
   private static Map<Type, String> keyPropertyIds = new HashMap<Type, String>()
{
     {
-      put(Resource.Type.Cluster, HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID);
-      put(Resource.Type.Host, HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID);
-      put(Resource.Type.HostStackVersion, HOST_STACK_VERSION_ID_PROPERTY_ID);
-      put(Resource.Type.Stack, HOST_STACK_VERSION_STACK_PROPERTY_ID);
-      put(Resource.Type.StackVersion, HOST_STACK_VERSION_VERSION_PROPERTY_ID);
+      put(Type.Cluster, HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID);
+      put(Type.Host, HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID);
+      put(Type.HostStackVersion, HOST_STACK_VERSION_ID_PROPERTY_ID);
+      put(Type.Stack, HOST_STACK_VERSION_STACK_PROPERTY_ID);
+      put(Type.StackVersion, HOST_STACK_VERSION_VERSION_PROPERTY_ID);
+      put(Type.RepositoryVersion, STACK_VERSION_REPO_VERSION_PROPERTY_ID);
     }
   };
 
@@ -164,10 +165,11 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
     final Set<String> requestedIds = getRequestPropertyIds(request, predicate);
     final Set<Map<String, Object>> propertyMaps = getPropertyMaps(predicate);
 
-    List<HostVersionEntity> requestedEntities = new ArrayList<HostVersionEntity>();
     for (Map<String, Object> propertyMap: propertyMaps) {
       final String hostName = propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID).toString();
+      final String clusterName = propertyMap.get(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID).toString();
       final Long id;
+      List<HostVersionEntity> requestedEntities = new ArrayList<HostVersionEntity>();
       if (propertyMap.get(HOST_STACK_VERSION_ID_PROPERTY_ID) == null && propertyMaps.size()
== 1) {
         requestedEntities = hostVersionDAO.findByHost(hostName);
       } else {
@@ -183,20 +185,47 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
           requestedEntities.add(entity);
         }
       }
+
+      addRequestedEntities(resources, requestedEntities, requestedIds, clusterName);
+
     }
 
+    return resources;
+  }
+
+
+  /**
+   * Adds requested entities to resources
+   * @param resources a list of resources to add to
+   * @param requestedEntities requested entities
+   * @param requestedIds
+   * @param clusterName name of cluster or null if no any
+   */
+  public void addRequestedEntities(Set<Resource> resources,
+                                   List<HostVersionEntity> requestedEntities,
+                                   Set<String> requestedIds,
+                                   String clusterName) {
     for (HostVersionEntity entity: requestedEntities) {
+      StackId stackId = new StackId(entity.getStack());
+
+      RepositoryVersionEntity repoVerEntity = repositoryVersionDAO.findByStackAndVersion(stackId.getStackId(),
entity.getVersion());
+
       final Resource resource = new ResourceImpl(Resource.Type.HostStackVersion);
 
       setResourceProperty(resource, HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID, entity.getHostName(),
requestedIds);
+      setResourceProperty(resource, HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID, clusterName,
requestedIds);
       setResourceProperty(resource, HOST_STACK_VERSION_ID_PROPERTY_ID, entity.getId(), requestedIds);
-      setResourceProperty(resource, HOST_STACK_VERSION_STACK_PROPERTY_ID, entity.getStack(),
requestedIds);
-      setResourceProperty(resource, HOST_STACK_VERSION_VERSION_PROPERTY_ID, entity.getVersion(),
requestedIds);
+      setResourceProperty(resource, HOST_STACK_VERSION_STACK_PROPERTY_ID, stackId.getStackName(),
requestedIds);
+      setResourceProperty(resource, HOST_STACK_VERSION_VERSION_PROPERTY_ID, stackId.getStackVersion(),
requestedIds);
       setResourceProperty(resource, HOST_STACK_VERSION_STATE_PROPERTY_ID, entity.getState().name(),
requestedIds);
 
+      if (repoVerEntity!=null) {
+        Long repoVersionId = repoVerEntity.getId();
+        setResourceProperty(resource, STACK_VERSION_REPO_VERSION_PROPERTY_ID, repoVersionId,
requestedIds);
+      }
+
       resources.add(resource);
     }
-    return resources;
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9053513f/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 c031ac1..db7cb58 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
@@ -97,9 +97,9 @@ public class RepositoryVersionResourceProvider extends AbstractResourceProvider
   @SuppressWarnings("serial")
   private static Map<Type, String> keyPropertyIds = new HashMap<Type, String>()
{
     {
-      put(Resource.Type.Stack, REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID);
-      put(Resource.Type.StackVersion, REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID);
-      put(Resource.Type.RepositoryVersion, REPOSITORY_VERSION_ID_PROPERTY_ID);
+      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);
     }
   };
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9053513f/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
index 125b71b..fedfb8c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
@@ -129,6 +129,13 @@ public interface Cluster {
   public void mapHostVersions(Set<String> hostNames, ClusterVersionEntity currentClusterVersion,
RepositoryVersionState desiredState) throws AmbariException;
 
   /**
+   * Create host versions for all of the hosts within a cluster with the INSTALLED state.
+   * @param currentClusterVersion cluster version to be queried for a stack name/version
info
+   * @throws AmbariException
+   */
+  public void initHostVersions(ClusterVersionEntity currentClusterVersion) throws AmbariException;
+
+  /**
    * Create a cluster version for the given stack and version, whose initial state must either
    * be either {@link RepositoryVersionState#CURRENT} (if no other cluster version exists)
or
    * {@link RepositoryVersionState#UPGRADING} (if at exactly one CURRENT cluster version
already exists).

http://git-wip-us.apache.org/repos/asf/ambari/blob/9053513f/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 5a9731a..5719c1c 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
@@ -1165,6 +1165,32 @@ public class ClusterImpl implements Cluster {
     }
   }
 
+  @Override
+  public void initHostVersions(ClusterVersionEntity currentClusterVersion) throws AmbariException
{
+    if (currentClusterVersion == null) {
+      throw new AmbariException("Could not find current stack version of cluster " + this.getClusterName());
+    }
+
+    clusterGlobalLock.readLock().lock();
+    try {
+      readWriteLock.writeLock().lock();
+      try {
+        Map<String, Host> hosts = clusters.getHostsForCluster(this.getClusterName());
+        for (String hostname : hosts.keySet()) {
+          HostEntity hostEntity = hostDAO.findByName(hostname);
+          HostVersionEntity hostVersionEntity = new HostVersionEntity(hostname, currentClusterVersion.getStack(),
+                  currentClusterVersion.getVersion(), RepositoryVersionState.INSTALLED);
+          hostVersionEntity.setHostEntity(hostEntity);
+          hostVersionDAO.create(hostVersionEntity);
+        }
+      } finally {
+        readWriteLock.writeLock().unlock();
+      }
+    } finally {
+      clusterGlobalLock.readLock().unlock();
+    }
+  }
+
   /**
    * Create a cluster version for the given stack and version, whose initial state must either
    * be either {@link org.apache.ambari.server.state.RepositoryVersionState#CURRENT} (if
no other cluster version exists) or
@@ -1181,15 +1207,17 @@ public class ClusterImpl implements Cluster {
     try {
       readWriteLock.writeLock().lock();
       try {
-        RepositoryVersionState allowedState;
+        Set<RepositoryVersionState> allowedStates = new HashSet<RepositoryVersionState>();
         if (this.clusterEntity.getClusterVersionEntities() == null || this.clusterEntity.getClusterVersionEntities().isEmpty())
{
-          allowedState = RepositoryVersionState.CURRENT;
+          allowedStates.add(RepositoryVersionState.CURRENT);
+          allowedStates.add(RepositoryVersionState.INSTALLED); // TODO: dlysnichenko: remove
when 2-stage api refactor is ready
         } else {
-          allowedState = RepositoryVersionState.UPGRADING;
+          allowedStates.add(RepositoryVersionState.UPGRADING);
+          allowedStates.add(RepositoryVersionState.INSTALLED); // TODO: dlysnichenko: remove
when 2-stage api refactor is ready
         }
 
-        if (allowedState != state) {
-          throw new AmbariException("The allowed state for a new cluster version must be
" + allowedState);
+        if (! allowedStates.contains(state)) {
+          throw new AmbariException("The allowed state for a new cluster version must be
within " + allowedStates);
         }
 
         ClusterVersionEntity existing = clusterVersionDAO.findByClusterAndStackAndVersion(this.getClusterName(),
stack, version);

http://git-wip-us.apache.org/repos/asf/ambari/blob/9053513f/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 0e8269f..f48381c 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
@@ -181,6 +181,7 @@ public class ClusterStackVersionResourceProviderTest {
 
     expect(managementController.getClusters()).andReturn(clusters).anyTimes();
     expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(managementController.getAuthName()).andReturn("admin").anyTimes();
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
@@ -221,7 +222,7 @@ public class ClusterStackVersionResourceProviderTest {
 
     // add properties to the request map
     properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID,
"Cluster100");
-    properties.put(ClusterStackVersionResourceProvider.STACK_VERSION_REPO_VERSION_PROPERTY_ID,
"2.2.0.1-885");
+    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
"2.2.0.1-885");
 
     propertySet.add(properties);
 


Mime
View raw message