ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From magyari_san...@apache.org
Subject ambari git commit: AMBARI-19749. Run ru_set_all script after installing packages on single host not belonging to any cluster (magyari_sandor)
Date Mon, 30 Jan 2017 16:11:26 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 d6a654e19 -> c12fbcc2d


AMBARI-19749. Run ru_set_all script after installing packages on single host not belonging
to any cluster (magyari_sandor)


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

Branch: refs/heads/branch-2.5
Commit: c12fbcc2d72a120df9abee1d8fe947a7f1fbd72d
Parents: d6a654e
Author: Sandor Magyari <smagyari@hortonworks.com>
Authored: Fri Jan 27 19:23:10 2017 +0100
Committer: Sandor Magyari <smagyari@hortonworks.com>
Committed: Mon Jan 30 17:10:41 2017 +0100

----------------------------------------------------------------------
 .../HostStackVersionResourceProvider.java       | 46 +++++++++++++++++++-
 .../HostStackVersionResourceProviderTest.java   | 11 +++++
 2 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c12fbcc2/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 364a61e..8f2d4e6 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
@@ -94,6 +94,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
 
   /**
    * Whether to force creating of install command on a host which is not member of any cluster
yet.
+   * This will also run hdp-select for specified stack version.
    */
   protected static final String HOST_STACK_VERSION_FORCE_INSTALL_ON_NON_MEMBER_HOST_PROPERTY_ID
= PropertyHelper
     .getPropertyId("HostStackVersions", "force_non_member_install");
@@ -105,6 +106,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
   protected static final String COMPONENT_NAME_PROPERTY_ID = "name";
 
   protected static final String INSTALL_PACKAGES_ACTION = "install_packages";
+  protected static final String STACK_SELECT_ACTION = "ru_set_all";
   protected static final String INSTALL_PACKAGES_FULL_NAME = "Install version";
 
 
@@ -303,7 +305,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
 
   private RequestStageContainer createInstallPackagesRequest(String hostName, final String
desiredRepoVersion,
                                                              String stackName, String stackVersion,
String clName,
-                                                             boolean forceInstallOnNonMemberHost,
+                                                             final boolean forceInstallOnNonMemberHost,
                                                              Set<Map<String, String>>
componentNames)
     throws NoSuchParentResourceException, SystemException {
 
@@ -523,6 +525,11 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
       throw new SystemException("Can not modify stage", e);
     }
 
+    if (forceInstallOnNonMemberHost) {
+      addSelectStackStage(desiredRepoVersion, forceInstallOnNonMemberHost, cluster, filter,
caption, req,
+        hostLevelParams, clusterHostInfoJson);
+    }
+
     try {
       if (!forceInstallOnNonMemberHost) {
         hostVersEntity.setState(RepositoryVersionState.INSTALLING);
@@ -536,6 +543,43 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
     return req;
   }
 
+  private void addSelectStackStage(String desiredRepoVersion, boolean forceInstallOnNonMemberHost,
Cluster cluster,
+                                 RequestResourceFilter filter, String caption, RequestStageContainer
req, Map<String, String> hostLevelParams, String clusterHostInfoJson) throws SystemException
{
+    Stage stage;
+    long stageId;
+    ActionExecutionContext actionContext;
+    Map<String, String> commandParams = new HashMap();
+    commandParams.put("version", desiredRepoVersion);
+
+    stage = stageFactory.createNew(req.getId(),
+      "/tmp/ambari",
+      cluster.getClusterName(),
+      cluster.getClusterId(),
+      caption,
+      clusterHostInfoJson,
+      StageUtils.getGson().toJson(commandParams),
+      StageUtils.getGson().toJson(hostLevelParams));
+
+    stageId = req.getLastStageId() + 1;
+    if (0L == stageId) {
+      stageId = 1L;
+    }
+    stage.setStageId(stageId);
+    req.addStages(Collections.singletonList(stage));
+
+    actionContext = new ActionExecutionContext(
+      cluster.getClusterName(), STACK_SELECT_ACTION,
+      Collections.singletonList(filter),
+      Collections.<String, String>emptyMap());
+    actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout(true)));
+
+    try {
+      actionExecutionHelper.get().addExecutionCommandsToStage(actionContext, stage, null,
!forceInstallOnNonMemberHost);
+    } catch (AmbariException e) {
+      throw new SystemException("Can not modify stage", e);
+    }
+  }
+
 
   private RequestStageContainer createRequest(String caption) {
     ActionManager actionManager = getManagementController().getActionManager();

http://git-wip-us.apache.org/repos/asf/ambari/blob/c12fbcc2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
index ecbd273..406d70b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
@@ -21,11 +21,13 @@ package org.apache.ambari.server.controller.internal;
 import static junit.framework.Assert.assertEquals;
 import static org.easymock.EasyMock.anyLong;
 import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.newCapture;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 
@@ -44,6 +46,7 @@ import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.ExecuteActionRequest;
 import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.apache.ambari.server.controller.ResourceProviderFactory;
 import org.apache.ambari.server.controller.spi.Predicate;
@@ -72,6 +75,7 @@ import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.cluster.ClusterImpl;
 import org.apache.ambari.server.topology.TopologyManager;
 import org.apache.ambari.server.utils.StageUtils;
+import org.easymock.Capture;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -99,6 +103,8 @@ public class HostStackVersionResourceProviderTest {
   private ResourceProviderFactory resourceProviderFactory;
   private ResourceProvider csvResourceProvider;
   private ActionManager actionManager;
+  private Capture<org.apache.ambari.server.actionmanager.Request> requestCapture;
+  private Capture<ExecuteActionRequest> executeActionRequestCapture;
   private HostVersionEntity hostVersionEntityMock;
   private RepositoryVersionEntity repoVersion;
   private Resource.Type type = Resource.Type.HostStackVersion;
@@ -337,6 +343,9 @@ public class HostStackVersionResourceProviderTest {
         anyObject(String.class))).andReturn(repoVersion);
 
     expect(actionManager.getRequestTasks(anyLong())).andReturn(Collections.<HostRoleCommand>emptyList()).anyTimes();
+    requestCapture = newCapture();
+    executeActionRequestCapture = newCapture();
+    actionManager.sendActions(capture(requestCapture), capture(executeActionRequestCapture));
 
     StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
@@ -384,6 +393,8 @@ public class HostStackVersionResourceProviderTest {
 
     // verify
     verify(managementController, response, clusters);
+
+    assertEquals(requestCapture.getValue().getStages().size(), 2);
   }
 
   @Test


Mime
View raw message