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-9275. Cannot delete registered-version with invalid repo URLs (Yurii Shylov via ncole)
Date Tue, 27 Jan 2015 18:58:41 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 59711d336 -> 14852dc8a


AMBARI-9275. Cannot delete registered-version with invalid repo URLs (Yurii Shylov via ncole)


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

Branch: refs/heads/trunk
Commit: 14852dc8a75d137b362668d546dfb0af141f354b
Parents: 59711d3
Author: Nate Cole <ncole@hortonworks.com>
Authored: Tue Jan 27 13:58:31 2015 -0500
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Tue Jan 27 13:58:31 2015 -0500

----------------------------------------------------------------------
 .../RepositoryVersionResourceProvider.java      | 21 ++++++++++++--------
 .../RepositoryVersionResourceProviderTest.java  | 10 +++++++++-
 2 files changed, 22 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/14852dc8/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 5422bdf..b72f872 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
@@ -18,18 +18,14 @@
 package org.apache.ambari.server.controller.internal;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
-import java.util.regex.Pattern;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ObjectNotFoundException;
-import org.apache.ambari.server.StaticallyInject;
 import org.apache.ambari.server.api.resources.RepositoryResourceDefinition;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
@@ -49,12 +45,14 @@ import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.OperatingSystemInfo;
+import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
 
+import com.google.common.collect.Lists;
 import com.google.gson.Gson;
 import com.google.inject.Inject;
 
@@ -294,10 +292,17 @@ public class RepositoryVersionResourceProvider extends AbstractResourceProvider
       final List<ClusterVersionEntity> clusterVersionEntities =
           clusterVersionDAO.findByStackAndVersion(entity.getStack(), entity.getVersion());
 
-      if (!clusterVersionEntities.isEmpty()) {
-        final ClusterVersionEntity firstClusterVersion = clusterVersionEntities.get(0);
-        throw new SystemException("Repository version can't be deleted as it is " +
-          firstClusterVersion.getState().name() + " on cluster " + firstClusterVersion.getClusterEntity().getClusterName());
+      final List<RepositoryVersionState> forbiddenToDeleteStates = Lists.newArrayList(
+          RepositoryVersionState.CURRENT,
+          RepositoryVersionState.INSTALLED,
+          RepositoryVersionState.INSTALLING,
+          RepositoryVersionState.UPGRADED,
+          RepositoryVersionState.UPGRADING);
+      for (ClusterVersionEntity clusterVersionEntity : clusterVersionEntities) {
+        if (clusterVersionEntity.getRepositoryVersion().getId().equals(id) && forbiddenToDeleteStates.contains(clusterVersionEntity.getState()))
{
+          throw new SystemException("Repository version can't be deleted as it is " +
+              clusterVersionEntity.getState().name() + " on cluster " + clusterVersionEntity.getClusterEntity().getClusterName());
+        }
       }
 
       entitiesToBeRemoved.add(entity);

http://git-wip-us.apache.org/repos/asf/ambari/blob/14852dc8/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
index 3516ffe..4efdb0c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
@@ -44,6 +44,7 @@ import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.OperatingSystemInfo;
+import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.junit.After;
@@ -160,7 +161,14 @@ public class RepositoryVersionResourceProviderTest {
           notEmptyList.add(null);
           return notEmptyList;
         } else {
-          return new ArrayList<ClusterVersionEntity>();
+          final List<ClusterVersionEntity> clusterVersions = new ArrayList<ClusterVersionEntity>();
+          final RepositoryVersionEntity repositoryVersion = new RepositoryVersionEntity();
+          repositoryVersion.setId(1L);
+          final ClusterVersionEntity installFailedVersion = new ClusterVersionEntity();
+          installFailedVersion.setState(RepositoryVersionState.INSTALL_FAILED);
+          installFailedVersion.setRepositoryVersion(repositoryVersion);
+          clusterVersions.add(installFailedVersion);
+          return clusterVersions;
         }
       }
     });


Mime
View raw message