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-9242. API does not allow Repo URL to be changed if the repo version is current (Yurii Shylov via ncole)
Date Tue, 27 Jan 2015 18:36:25 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 39a8b24c4 -> 59711d336


AMBARI-9242. API does not allow Repo URL to be changed if the repo version is current (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/59711d33
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/59711d33
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/59711d33

Branch: refs/heads/trunk
Commit: 59711d3369e797198755f24cdfce5cc0094f63d3
Parents: 39a8b24
Author: Nate Cole <ncole@hortonworks.com>
Authored: Tue Jan 27 13:35:38 2015 -0500
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Tue Jan 27 13:35:38 2015 -0500

----------------------------------------------------------------------
 .../RepositoryVersionResourceProvider.java      | 39 ++++++++------------
 .../RepositoryVersionResourceProviderTest.java  | 37 ++++++++++++++++++-
 2 files changed, 52 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/59711d33/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 a463439..5422bdf 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
@@ -47,23 +47,15 @@ import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 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.state.OperatingSystemInfo;
-import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
-import org.apache.ambari.server.state.stack.UpgradePack;
 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.ArrayListMultimap;
-import com.google.common.collect.Multimap;
 import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
 import com.google.inject.Inject;
 
 /**
@@ -241,31 +233,32 @@ public class RepositoryVersionResourceProvider extends AbstractResourceProvider
             throw new ObjectNotFoundException("There is no repository version with id " +
id);
           }
 
-          if (propertyMap.get(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID) != null) {
-
+          if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID))))
{
             final List<ClusterVersionEntity> clusterVersionEntities =
                 clusterVersionDAO.findByStackAndVersion(entity.getStack(), entity.getVersion());
 
             if (!clusterVersionEntities.isEmpty()) {
               final ClusterVersionEntity firstClusterVersion = clusterVersionEntities.get(0);
-              throw new AmbariException("Repository version can't be updated as it is " +
+              throw new AmbariException("Upgrade pack can't be changed for repository version
which is " +
                 firstClusterVersion.getState().name() + " on cluster " + firstClusterVersion.getClusterEntity().getClusterName());
             }
 
-            if (propertyMap.get(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID) != null) {
-              final Object operatingSystems = propertyMap.get(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID);
-              final String operatingSystemsJson = gson.toJson(operatingSystems);
-              try {
-                repositoryVersionHelper.parseOperatingSystems(operatingSystemsJson);
-              } catch (Exception ex) {
-                throw new AmbariException("Json structure for operating systems is incorrect",
ex);
-              }
-              entity.setOperatingSystems(operatingSystemsJson);
-            }
+            final String upgradePackage = propertyMap.get(REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID).toString();
+            entity.setUpgradePackage(upgradePackage);
+          }
 
+          if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID))))
{
+            final Object operatingSystems = propertyMap.get(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID);
+            final String operatingSystemsJson = gson.toJson(operatingSystems);
+            try {
+              repositoryVersionHelper.parseOperatingSystems(operatingSystemsJson);
+            } catch (Exception ex) {
+              throw new AmbariException("Json structure for operating systems is incorrect",
ex);
+            }
+            entity.setOperatingSystems(operatingSystemsJson);
           }
 
-          if (propertyMap.get(REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID) != null) {
+          if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID))))
{
             entity.setDisplayName(propertyMap.get(REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID).toString());
           }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/59711d33/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 17fa2c2..3516ffe 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
@@ -18,10 +18,12 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -37,7 +39,9 @@ import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
 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.StackInfo;
@@ -69,11 +73,13 @@ public class RepositoryVersionResourceProviderTest {
   public void before() throws Exception {
     final Set<String> validVersions = Sets.newHashSet("1.1", "1.1-17", "1.1.1.1", "1.1.343432.2",
"1.1.343432.2-234234324");
     final AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class);
+    final ClusterVersionDAO clusterVersionDAO = Mockito.mock(ClusterVersionDAO.class);
     final InMemoryDefaultTestModule injectorModule = new InMemoryDefaultTestModule() {
       @Override
       protected void configure() {
         super.configure();
         bind(AmbariMetaInfo.class).toInstance(ambariMetaInfo);
+        bind(ClusterVersionDAO.class).toInstance(clusterVersionDAO);
       };
     };
     injector = Guice.createInjector(injectorModule);
@@ -142,6 +148,23 @@ public class RepositoryVersionResourceProviderTest {
       }
     });
 
+    Mockito.when(clusterVersionDAO.findByStackAndVersion(Mockito.anyString(), Mockito.anyString())).thenAnswer(new
Answer<List<ClusterVersionEntity>>() {
+
+      @Override
+      public List<ClusterVersionEntity> answer(InvocationOnMock invocation)
+          throws Throwable {
+        final String stack = invocation.getArguments()[0].toString();
+        final String version = invocation.getArguments()[1].toString();
+        if (stack.equals("HDP-1.1") && version.equals("1.1.1.1")) {
+          final List<ClusterVersionEntity> notEmptyList = new ArrayList<ClusterVersionEntity>();
+          notEmptyList.add(null);
+          return notEmptyList;
+        } else {
+          return new ArrayList<ClusterVersionEntity>();
+        }
+      }
+    });
+
     injector.getInstance(GuiceJpaInitializer.class);
   }
 
@@ -255,7 +278,7 @@ public class RepositoryVersionResourceProviderTest {
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID,
"HDP");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID,
"pack1");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID,
"1.1");
-    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
"1.1.1.1");
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
"1.1.1.2");
     propertySet.add(properties);
 
     final Predicate predicateStackName = new PredicateBuilder().property(RepositoryVersionResourceProvider.REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID).equals("HDP").toPredicate();
@@ -302,12 +325,24 @@ public class RepositoryVersionResourceProviderTest {
     Assert.assertEquals(1, provider.getResources(getRequest, new AndPredicate(predicateStackName,
predicateStackVersion)).size());
     Assert.assertEquals("name", provider.getResources(getRequest, new AndPredicate(predicateStackName,
predicateStackVersion)).iterator().next().getPropertyValue(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID));
 
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID,
null);
+
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_ID_PROPERTY_ID, "1");
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID,
"name2");
     final Request updateRequest = PropertyHelper.getUpdateRequest(properties, null);
     provider.updateResources(updateRequest, new AndPredicate(predicateStackName, predicateStackVersion));
 
     Assert.assertEquals("name2", provider.getResources(getRequest, new AndPredicate(predicateStackName,
predicateStackVersion)).iterator().next().getPropertyValue(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID));
+
+    properties.put(RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID,
new Gson().fromJson("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"2\",\"Repositories/repo_name\":\"2\",\"Repositories/base_url\":\"2\"}]}]",
Object.class));
+    provider.updateResources(updateRequest, new AndPredicate(predicateStackName, predicateStackVersion));
+
+    properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_UPGRADE_PACK_PROPERTY_ID,
"pack2");
+    try {
+      provider.updateResources(updateRequest, new AndPredicate(predicateStackName, predicateStackVersion));
+      Assert.fail("Update of upgrade pack should not be allowed when repo version is installed
on any cluster");
+    } catch (Exception ex) {
+    }
   }
 
   @After


Mime
View raw message