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-21832. Reject PATCH VDFs with Services that are not Included in the Cluster (dlysnichenko)
Date Mon, 04 Sep 2017 16:11:49 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 6174afff1 -> 9e4324fcf


AMBARI-21832. Reject PATCH VDFs with Services that are not Included in the Cluster (dlysnichenko)


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

Branch: refs/heads/branch-2.6
Commit: 9e4324fcfcf54760f0b080d79c4939cc3977895a
Parents: 6174aff
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Mon Sep 4 19:08:11 2017 +0300
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Mon Sep 4 19:08:11 2017 +0300

----------------------------------------------------------------------
 .../ClusterStackVersionResourceProvider.java    |  45 +++++++-
 ...ClusterStackVersionResourceProviderTest.java | 103 ++++++++++++++++++-
 2 files changed, 141 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9e4324fc/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 2083365..f96f257 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
@@ -20,6 +20,7 @@ package org.apache.ambari.server.controller.internal;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JDK_LOCATION;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.EnumSet;
@@ -76,6 +77,8 @@ import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.StackInfo;
+import org.apache.ambari.server.state.repository.AvailableService;
 import org.apache.ambari.server.state.repository.ClusterVersionSummary;
 import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
@@ -179,6 +182,9 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
   @Inject
   private static RepositoryVersionHelper repoVersionHelper;
 
+  @Inject
+  private static Provider<AmbariMetaInfo> metaInfo;
+
 
 
   @Inject
@@ -554,6 +560,9 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
       // determine services for the repo
       Set<String> serviceNames = new HashSet<>();
 
+
+      checkPatchVDFAvailableServices(cluster, repoVersionEnt, desiredVersionDefinition);
+
       // !!! limit the serviceNames to those that are detailed for the repository.
       // TODO packages don't have component granularity
       if (RepositoryType.STANDARD != repoVersionEnt.getType()) {
@@ -593,6 +602,38 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
     return req;
   }
 
+  /**
+   * Reject PATCH VDFs with Services that are not included in the Cluster
+   * @param cluster cluster instance
+   * @param repoVersionEnt repo version entity
+   * @param desiredVersionDefinition VDF
+   * @throws IllegalArgumentException thrown if VDF includes services that are not installed
+   * @throws AmbariException thrown if could not load stack for repo repoVersionEnt
+   */
+  protected void checkPatchVDFAvailableServices(Cluster cluster, RepositoryVersionEntity
repoVersionEnt,
+                                              VersionDefinitionXml desiredVersionDefinition)
throws SystemException, AmbariException {
+    if (repoVersionEnt.getType() == RepositoryType.PATCH) {
+
+      Collection<String> notPresentServices = new ArrayList<>();
+      Collection<String> presentServices = new ArrayList<>();
+
+      presentServices.addAll(cluster.getServices().keySet());
+      final StackInfo stack;
+      stack = metaInfo.get().getStack(repoVersionEnt.getStackName(), repoVersionEnt.getStackVersion());
+
+      for (AvailableService availableService : desiredVersionDefinition.getAvailableServices(stack))
{
+        String name = availableService.getName();
+        if (!presentServices.contains(name)) {
+          notPresentServices.add(name);
+        }
+      }
+      if (!notPresentServices.isEmpty()) {
+        throw new IllegalArgumentException(String.format("%s VDF includes services that are
not installed: %s",
+            RepositoryType.PATCH, StringUtils.join(notPresentServices, ",")));
+      }
+    }
+  }
+
   private ActionExecutionContext getHostVersionInstallCommand(RepositoryVersionEntity repoVersion,
       Cluster cluster, AmbariManagementController managementController, AmbariMetaInfo ami,
       final StackId stackId, Set<String> repoServices, Map<String, List<RepositoryEntity>>
perOsRepos, Stage stage1, Host host)
@@ -684,7 +725,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
 
     RequestStageContainer requestStages = new RequestStageContainer(
             actionManager.getNextRequestId(), null, requestFactory, actionManager);
-    requestStages.setRequestContext(String.format(INSTALL_PACKAGES_FULL_NAME));
+    requestStages.setRequestContext(INSTALL_PACKAGES_FULL_NAME);
 
     return requestStages;
   }
@@ -728,7 +769,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
 
     compare = v2 - v1;
 
-    return (compare == 0) ? 0 : (compare < 0) ? -1 : 1;
+    return Integer.compare(compare, 0);
   }
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9e4324fc/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 bd6de5e..42b2a4c 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
@@ -35,6 +35,7 @@ import java.lang.reflect.Field;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
@@ -91,11 +92,14 @@ import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
-import org.apache.ambari.server.state.ServiceInfo;
+ import org.apache.ambari.server.state.ServiceImpl;
+ 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.repository.VersionDefinitionXml;
+ import org.apache.ambari.server.state.StackInfo;
+ import org.apache.ambari.server.state.cluster.ClusterImpl;
+ import org.apache.ambari.server.state.repository.AvailableService;
+ import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.apache.ambari.server.topology.TopologyManager;
@@ -111,8 +115,9 @@ import org.junit.Before;
 import org.junit.Test;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
+ import org.springframework.test.annotation.ExpectedException;
 
-import com.google.common.collect.ImmutableMap;
+ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Sets;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
@@ -1524,7 +1529,7 @@ public class ClusterStackVersionResourceProviderTest {
         "   }\n" +
         "]";
     expect(repoVersion.getOperatingSystems()).andReturn(rvh.parseOperatingSystems(os_json)).anyTimes();
-    expect(repoVersion.getType()).andReturn(RepositoryType.STANDARD);
+    expect(repoVersion.getType()).andReturn(RepositoryType.STANDARD).anyTimes();
 
     Map<String, Host> hostsForCluster = new HashMap<>();
     int hostCount = 2;
@@ -1808,6 +1813,94 @@ public class ClusterStackVersionResourceProviderTest {
 
   }
 
+  @Test
+  public void testCheckPatchVDFAvailableServices() throws Exception {
+    Cluster cluster = createNiceMock(Cluster.class);
+    RepositoryVersionEntity repoVersionEnt = createNiceMock(RepositoryVersionEntity.class);
+    VersionDefinitionXml desiredVersionDefinition = createNiceMock(VersionDefinitionXml.class);
+
+    expect(repoVersionEnt.getType()).andReturn(RepositoryType.PATCH).once();
+
+    Service service1 = createNiceMock(Service.class);
+    expect(service1.getName()).andReturn("SERVICE1").anyTimes();
+    expect(service1.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>());
+
+    Service service2 = createNiceMock(Service.class);
+    expect(service2.getName()).andReturn("SERVICE2").anyTimes();
+    expect(service2.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>());
+
+    Map<String, Service> clusterServices = new HashMap<>();
+    clusterServices.put("SERVICE1",service1);
+    clusterServices.put("SERVICE2",service2);
+
+    expect(cluster.getServices()).andReturn(clusterServices).once();
+    expect(repoVersionEnt.getStackName()).andReturn("HDP").once();
+    expect(repoVersionEnt.getStackVersion()).andReturn("2.5.0").once();
+
+    AvailableService availableService1 = createNiceMock(AvailableService.class);
+    expect(availableService1.getName()).andReturn("SERVICE1").anyTimes();
+
+    AvailableService availableService2 = createNiceMock(AvailableService.class);
+    expect(availableService2.getName()).andReturn("SERVICE2").anyTimes();
+
+    Collection<AvailableService> availableServices = new ArrayList<>();
+    availableServices.add(availableService1);
+    availableServices.add(availableService2);
+
+    expect(desiredVersionDefinition.getAvailableServices((StackInfo)EasyMock.anyObject())).andReturn(availableServices).once();
+
+
+    replay(cluster, repoVersionEnt, desiredVersionDefinition, service1, service2, availableService1,
availableService2);
+
+    ClusterStackVersionResourceProvider provider = new ClusterStackVersionResourceProvider(null);
+    injector.injectMembers(provider);
+    provider.checkPatchVDFAvailableServices(cluster, repoVersionEnt, desiredVersionDefinition);
+  }
+
+   @Test
+   public void testCheckPatchVDFAvailableServicesFail() throws Exception {
+     Cluster cluster = createNiceMock(Cluster.class);
+     RepositoryVersionEntity repoVersionEnt = createNiceMock(RepositoryVersionEntity.class);
+     VersionDefinitionXml desiredVersionDefinition = createNiceMock(VersionDefinitionXml.class);
+
+     expect(repoVersionEnt.getType()).andReturn(RepositoryType.PATCH).once();
+
+     Service service1 = createNiceMock(Service.class);
+     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
+     expect(service1.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>());
+
+     Map<String, Service> clusterServices = new HashMap<>();
+     clusterServices.put("SERVICE1",service1);
+
+     expect(cluster.getServices()).andReturn(clusterServices).once();
+     expect(repoVersionEnt.getStackName()).andReturn("HDP").once();
+     expect(repoVersionEnt.getStackVersion()).andReturn("2.5.0").once();
+
+     AvailableService availableService1 = createNiceMock(AvailableService.class);
+     expect(availableService1.getName()).andReturn("SERVICE1").anyTimes();
+
+     AvailableService availableService2 = createNiceMock(AvailableService.class);
+     expect(availableService2.getName()).andReturn("SERVICE2").anyTimes();
+
+     Collection<AvailableService> availableServices = new ArrayList<>();
+     availableServices.add(availableService1);
+     availableServices.add(availableService2);
+
+     expect(desiredVersionDefinition.getAvailableServices((StackInfo)EasyMock.anyObject())).andReturn(availableServices).once();
+
+
+     replay(cluster, repoVersionEnt, desiredVersionDefinition, service1, availableService1,
availableService2);
+
+     ClusterStackVersionResourceProvider provider = new ClusterStackVersionResourceProvider(null);
+     injector.injectMembers(provider);
+     try {
+       provider.checkPatchVDFAvailableServices(cluster, repoVersionEnt, desiredVersionDefinition);
+       Assert.fail("Expected an exception when PATCH VDF includes services that are not installed");
+     } catch (IllegalArgumentException expected) {
+       // !!! expected
+       Assert.assertEquals(expected.getMessage(),"PATCH VDF includes services that are not
installed: SERVICE2");
+     }
+   }
 
    private void testCreateResourcesExistingUpgrade(Authentication authentication) throws
Exception {
     Resource.Type type = Resource.Type.ClusterStackVersion;


Mime
View raw message