You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ha...@apache.org on 2017/11/13 16:31:38 UTC
[1/2] ambari git commit: AMBARI-22318 repositoryFile entity
populating for wrong repository for RU (dgrinenko)
Repository: ambari
Updated Branches:
refs/heads/branch-2.6 36f2ad4e1 -> 6a09885d5
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/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 11142e4..de16bf6 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
@@ -1914,11 +1914,56 @@ public class ClusterStackVersionResourceProviderTest {
stackEntity.setStackName("HDP");
stackEntity.setStackVersion("2.1.1");
- File f = new File("src/test/resources/hbase_version_test.xml");
+ String hbaseVersionTestXML = "\n" +
+ "<repository-version xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
+ " xsi:noNamespaceSchemaLocation=\"version_definition.xsd\">\n" +
+ " \n" +
+ " <release>\n" +
+ " <type>PATCH</type>\n" +
+ " <stack-id>HDP-2.3</stack-id>\n" +
+ " <version>2.3.4.0</version>\n" +
+ " <build>3396</build>\n" +
+ " <compatible-with>2.3.2.[0-9]</compatible-with>\n" +
+ " <release-notes>http://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.3.4/</release-notes>\n" +
+ " </release>\n" +
+ " \n" +
+ " <manifest>\n" +
+ " <service id=\"HBASE-112\" name=\"HBASE\" version=\"1.1.2\" version-id=\"2_3_4_0-3396\" />\n" +
+ " </manifest>\n" +
+ " \n" +
+ " <available-services>\n" +
+ " <service idref=\"HBASE-112\" />\n" +
+ " </available-services>\n" +
+ " \n" +
+ " <repository-info>\n" +
+ " <os family=\"redhat6\">\n" +
+ " <package-version>2_3_4_0_3396</package-version>\n" +
+ " <repo>\n" +
+ " <baseurl>http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.3.4.0</baseurl>\n" +
+ " <repoid>HDP-2.3</repoid>\n" +
+ " <reponame>HDP</reponame>\n" +
+ " <unique>true</unique>\n" +
+ " </repo>\n" +
+ " <repo>\n" +
+ " <baseurl>http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/centos6</baseurl>\n" +
+ " <repoid>HDP-UTILS-1.1.0.20</repoid>\n" +
+ " <reponame>HDP-UTILS</reponame>\n" +
+ " <unique>false</unique>\n" +
+ " </repo>\n" +
+ " </os>\n" +
+ " </repository-info>\n" +
+ " \n" +
+ " <upgrade>\n" +
+ " <configuration type=\"hdfs-site\">\n" +
+ " <set key=\"foo\" value=\"bar\" />\n" +
+ " </configuration>\n" +
+ " </upgrade>\n" +
+ "</repository-version>";
+
RepositoryVersionEntity repoVersion = new RepositoryVersionEntity();
repoVersion.setId(1l);
repoVersion.setOperatingSystems(os_json);
- repoVersion.setVersionXml(IOUtils.toString(new FileInputStream(f)));
+ repoVersion.setVersionXml(hbaseVersionTestXML);
repoVersion.setVersionXsd("version_definition.xsd");
repoVersion.setType(RepositoryType.PATCH);
repoVersion.setStack(stackEntity);
@@ -2009,7 +2054,7 @@ public class ClusterStackVersionResourceProviderTest {
expect(managementController.findConfigurationTagsWithOverrides(anyObject(Cluster.class), EasyMock.anyString()))
.andReturn(new HashMap<String, Map<String, String>>()).anyTimes();
- expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
+ expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster).anyTimes();
expect(clusters.getHostsForCluster(anyObject(String.class))).andReturn(
hostsForCluster).anyTimes();
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index 477b776..a8c0954 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -214,23 +214,25 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
StackEntity stackEntity220 = stackDAO.find("HDP", "2.2.0");
StackId stack211 = new StackId(stackEntity211);
+ String operatingSystems = "[{\"OperatingSystems/ambari_managed_repositories\":\"true\",\"repositories\":[{\"Repositories/repo_id\":\"HDP\",\"Repositories/base_url\":\"\",\"Repositories/repo_name\":\"HDP\"},{\"Repositories/repo_id\":\"HDP-UTILS\",\"Repositories/base_url\":\"\",\"Repositories/repo_name\":\"HDP-UTILS\"}],\"OperatingSystems/os_type\":\"redhat6\"}]";
+
repoVersionEntity2110 = new RepositoryVersionEntity();
repoVersionEntity2110.setDisplayName("My New Version 1");
- repoVersionEntity2110.setOperatingSystems("");
+ repoVersionEntity2110.setOperatingSystems(operatingSystems);
repoVersionEntity2110.setStack(stackEntity211);
repoVersionEntity2110.setVersion("2.1.1.0");
repoVersionDao.create(repoVersionEntity2110);
repoVersionEntity2111 = new RepositoryVersionEntity();
repoVersionEntity2111.setDisplayName("My New Version 2 for minor upgrade");
- repoVersionEntity2111.setOperatingSystems("");
+ repoVersionEntity2111.setOperatingSystems(operatingSystems);
repoVersionEntity2111.setStack(stackEntity211);
repoVersionEntity2111.setVersion("2.1.1.1");
repoVersionDao.create(repoVersionEntity2111);
repoVersionEntity2112 = new RepositoryVersionEntity();
repoVersionEntity2112.setDisplayName("My New Version 3 for patch upgrade");
- repoVersionEntity2112.setOperatingSystems("");
+ repoVersionEntity2112.setOperatingSystems(operatingSystems);
repoVersionEntity2112.setStack(stackEntity211);
repoVersionEntity2112.setVersion("2.1.1.2");
repoVersionEntity2112.setType(RepositoryType.PATCH);
@@ -239,7 +241,7 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
repoVersionEntity2200 = new RepositoryVersionEntity();
repoVersionEntity2200.setDisplayName("My New Version 4 for major upgrade");
- repoVersionEntity2200.setOperatingSystems("");
+ repoVersionEntity2200.setOperatingSystems(operatingSystems);
repoVersionEntity2200.setStack(stackEntity220);
repoVersionEntity2200.setVersion("2.2.0.0");
repoVersionDao.create(repoVersionEntity2200);
@@ -1931,7 +1933,7 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
StackEntity stackEntity = stackDAO.find("HDP", "2.1.1");
RepositoryVersionEntity repoVersionEntity = new RepositoryVersionEntity();
repoVersionEntity.setDisplayName("My New Version 3");
- repoVersionEntity.setOperatingSystems("");
+ repoVersionEntity.setOperatingSystems("[{\"OperatingSystems/ambari_managed_repositories\":\"true\",\"repositories\":[{\"Repositories/repo_id\":\"HDP\",\"Repositories/base_url\":\"\",\"Repositories/repo_name\":\"HDP\"},{\"Repositories/repo_id\":\"HDP-UTILS\",\"Repositories/base_url\":\"\",\"Repositories/repo_name\":\"HDP-UTILS\"}],\"OperatingSystems/os_type\":\"redhat6\"}]");
repoVersionEntity.setStack(stackEntity);
repoVersionEntity.setVersion("2.2.2.3");
repoVersionDao.create(repoVersionEntity);
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
index c905a42..a2406ea 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
@@ -670,8 +670,10 @@ public class OrmTestHelper {
if (repositoryVersion == null) {
try {
+ String operatingSystems = "[{\"OperatingSystems/ambari_managed_repositories\":\"true\",\"repositories\":[{\"Repositories/repo_id\":\"HDP\",\"Repositories/base_url\":\"\",\"Repositories/repo_name\":\"HDP\"},{\"Repositories/repo_id\":\"HDP-UTILS\",\"Repositories/base_url\":\"\",\"Repositories/repo_name\":\"HDP-UTILS\"}],\"OperatingSystems/os_type\":\"redhat6\"}]";
+
repositoryVersion = repositoryVersionDAO.create(stackEntity, version,
- String.valueOf(System.currentTimeMillis()) + uniqueCounter.incrementAndGet(), "");
+ String.valueOf(System.currentTimeMillis()) + uniqueCounter.incrementAndGet(), operatingSystems);
} catch (Exception ex) {
LOG.error("Caught exception", ex);
[2/2] ambari git commit: AMBARI-22318 repositoryFile entity
populating for wrong repository for RU (dgrinenko)
Posted by ha...@apache.org.
AMBARI-22318 repositoryFile entity populating for wrong repository for RU (dgrinenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/6a09885d
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/6a09885d
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/6a09885d
Branch: refs/heads/branch-2.6
Commit: 6a09885d5b3048a3016703671392eda3b3b31fc7
Parents: 36f2ad4
Author: Dmytro Grinenko <ha...@apache.org>
Authored: Mon Nov 13 18:30:47 2017 +0200
Committer: Dmytro Grinenko <ha...@apache.org>
Committed: Mon Nov 13 18:30:47 2017 +0200
----------------------------------------------------------------------
.../actionmanager/ExecutionCommandWrapper.java | 36 +++
.../ambari/server/agent/CommandRepository.java | 2 +-
.../controller/ActionExecutionContext.java | 6 +-
.../controller/AmbariActionExecutionHelper.java | 71 +----
.../AmbariCustomCommandExecutionHelper.java | 265 +----------------
.../AmbariManagementControllerImpl.java | 14 +-
.../ClusterStackVersionResourceProvider.java | 16 +-
.../HostStackVersionResourceProvider.java | 3 +-
.../stack/upgrade/RepositoryVersionHelper.java | 297 ++++++++++++++++++-
.../AmbariCustomCommandExecutionHelperTest.java | 13 +-
.../AmbariManagementControllerTest.java | 174 +++++------
...ClusterStackVersionResourceProviderTest.java | 51 +++-
.../internal/UpgradeResourceProviderTest.java | 12 +-
.../apache/ambari/server/orm/OrmTestHelper.java | 4 +-
14 files changed, 525 insertions(+), 439 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java
index 054ab47..4107370 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapper.java
@@ -30,24 +30,30 @@ import org.apache.ambari.server.ClusterNotFoundException;
import org.apache.ambari.server.RoleCommand;
import org.apache.ambari.server.ServiceNotFoundException;
import org.apache.ambari.server.agent.AgentCommand.AgentCommandType;
+import org.apache.ambari.server.agent.CommandRepository;
import org.apache.ambari.server.agent.ExecutionCommand;
import org.apache.ambari.server.agent.ExecutionCommand.KeyNames;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.spi.SystemException;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
+import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.orm.entities.UpgradeEntity;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.ConfigHelper;
import org.apache.ambari.server.state.DesiredConfig;
+import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.Service;
import org.apache.ambari.server.state.ServiceComponent;
+import org.apache.ambari.server.state.ServiceComponentImpl;
import org.apache.ambari.server.state.ServiceInfo;
import org.apache.ambari.server.state.StackId;
import org.apache.ambari.server.state.StackInfo;
import org.apache.ambari.server.state.UpgradeContext;
import org.apache.ambari.server.state.UpgradeContext.UpgradeSummary;
import org.apache.ambari.server.state.UpgradeContextFactory;
+import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@@ -79,6 +85,9 @@ public class ExecutionCommandWrapper {
@Inject
private UpgradeContextFactory upgradeContextFactory;
+ @Inject
+ private RepositoryVersionHelper repoVersionHelper;
+
/**
* Used for injecting hooks and common-services into the command.
*/
@@ -216,9 +225,36 @@ public class ExecutionCommandWrapper {
if (null != upgrade) {
UpgradeContext upgradeContext = upgradeContextFactory.create(cluster, upgrade);
UpgradeSummary upgradeSummary = upgradeContext.getUpgradeSummary();
+
executionCommand.setUpgradeSummary(upgradeSummary);
}
+ // setting repositoryFile
+ final Host host = cluster.getHost(executionCommand.getHostname()); // can be null on internal commands
+ final String serviceName = executionCommand.getServiceName(); // can be null on executing special RU tasks
+
+ if (null == executionCommand.getRepositoryFile() && null != host && null != serviceName) {
+ final CommandRepository commandRepository;
+ final Service service = cluster.getService(serviceName);
+ final String componentName = executionCommand.getComponentName();
+
+ try {
+
+ if (null != componentName) {
+ ServiceComponent serviceComponent = service.getServiceComponent(componentName);
+ commandRepository = repoVersionHelper.getCommandRepository(null, serviceComponent, host);
+ } else {
+ RepositoryVersionEntity repoVersion = service.getDesiredRepositoryVersion();
+ OperatingSystemEntity osEntity = repoVersionHelper.getOSEntityForHost(host, repoVersion);
+ commandRepository = repoVersionHelper.getCommandRepository(repoVersion, osEntity);
+ }
+ executionCommand.setRepositoryFile(commandRepository);
+
+ } catch (SystemException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
} catch (ClusterNotFoundException cnfe) {
// it's possible that there are commands without clusters; in such cases,
// just return the de-serialized command and don't try to read configs
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java
index 912e05f..e207ac5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/CommandRepository.java
@@ -52,7 +52,7 @@ public class CommandRepository {
private String m_repoFileName;
@SerializedName("feature")
- private CommandRepositoryFeature feature = new CommandRepositoryFeature();
+ private final CommandRepositoryFeature feature = new CommandRepositoryFeature();
/**
* Provides {@link CommandRepository} feature
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionExecutionContext.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionExecutionContext.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionExecutionContext.java
index 9939ce7..207dbfb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionExecutionContext.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionExecutionContext.java
@@ -262,12 +262,12 @@ public class ActionExecutionContext {
}
/**
+ *
* Interface that allows a final attempt to setting values on an {@link ExecutionCommand}
- * @author ncole
*
*/
- public static interface ExecutionCommandVisitor {
- public void visit(ExecutionCommand command);
+ public interface ExecutionCommandVisitor {
+ void visit(ExecutionCommand command);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
index 80677fd..43fead0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
@@ -22,11 +22,8 @@ import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AGENT_STA
import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AGENT_STACK_RETRY_ON_UNAVAILABILITY;
import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMPONENT_CATEGORY;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.REPO_INFO;
import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT;
import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT_TYPE;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_NAME;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_VERSION;
import java.util.HashSet;
import java.util.List;
@@ -46,9 +43,9 @@ import org.apache.ambari.server.agent.ExecutionCommand.KeyNames;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.internal.RequestResourceFilter;
+import org.apache.ambari.server.controller.spi.SystemException;
import org.apache.ambari.server.customactions.ActionDefinition;
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.Cluster;
import org.apache.ambari.server.state.Clusters;
@@ -58,14 +55,13 @@ 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.StackId;
+import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpInProgressEvent;
import org.apache.ambari.server.utils.SecretReference;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -77,6 +73,7 @@ public class AmbariActionExecutionHelper {
private final static Logger LOG =
LoggerFactory.getLogger(AmbariActionExecutionHelper.class);
private static final String TYPE_PYTHON = "PYTHON";
+ private static final String ACTION_FILE_EXTENSION = "py";
private static final String ACTION_UPDATE_REPO = "update_repo";
private static final String SUCCESS_FACTOR_PARAMETER = "success_factor";
@@ -84,15 +81,23 @@ public class AmbariActionExecutionHelper {
@Inject
private Clusters clusters;
+
@Inject
private AmbariManagementController managementController;
+
@Inject
private AmbariMetaInfo ambariMetaInfo;
+
@Inject
private MaintenanceStateHelper maintenanceStateHelper;
+
@Inject
private Configuration configs;
+ @Inject
+ private RepositoryVersionHelper repoVersionHelper;
+
+
/**
* Validates the request to execute an action.
* @param actionRequest
@@ -416,7 +421,7 @@ public class AmbariActionExecutionHelper {
commandParams.put(KeyNames.LOG_OUTPUT, requestParams.get(KeyNames.LOG_OUTPUT));
}
- commandParams.put(SCRIPT, actionName + ".py");
+ commandParams.put(SCRIPT, actionName + "." + ACTION_FILE_EXTENSION);
commandParams.put(SCRIPT_TYPE, TYPE_PYTHON);
ExecutionCommand execCmd = stage.getExecutionCommandWrapper(hostName,
@@ -464,10 +469,10 @@ public class AmbariActionExecutionHelper {
if (StringUtils.isNotBlank(serviceName)) {
Service service = cluster.getService(serviceName);
- addRepoInfoToHostLevelParams(actionContext, service.getDesiredRepositoryVersion(),
+ repoVersionHelper.addRepoInfoToHostLevelParams(cluster, actionContext, service.getDesiredRepositoryVersion(),
hostLevelParams, hostName);
} else {
- addRepoInfoToHostLevelParams(actionContext, null, hostLevelParams, hostName);
+ repoVersionHelper.addRepoInfoToHostLevelParams(cluster, actionContext, null, hostLevelParams, hostName);
}
Map<String, String> roleParams = execCmd.getRoleParams();
@@ -524,52 +529,4 @@ public class AmbariActionExecutionHelper {
}
}
- /*
- * This method builds and adds repo info
- * to hostLevelParams of action
- *
- * */
-
- private void addRepoInfoToHostLevelParams(ActionExecutionContext actionContext,
- RepositoryVersionEntity repositoryVersion, Map<String, String> hostLevelParams,
- String hostName) throws AmbariException {
-
- // if the repo is null, see if any values from the context should go on the
- // host params and then return
- if (null == repositoryVersion) {
- // see if the action context has a repository set to use for the command
- if (null != actionContext.getRepositoryVersion()) {
- StackId stackId = actionContext.getRepositoryVersion().getStackId();
- hostLevelParams.put(STACK_NAME, stackId.getStackName());
- hostLevelParams.put(STACK_VERSION, stackId.getStackVersion());
- }
-
- return;
- } else {
- StackId stackId = repositoryVersion.getStackId();
- hostLevelParams.put(STACK_NAME, stackId.getStackName());
- hostLevelParams.put(STACK_VERSION, stackId.getStackVersion());
- }
-
- JsonObject rootJsonObject = new JsonObject();
- JsonArray repositories = new JsonArray();
-
- String hostOsFamily = clusters.getHost(hostName).getOsFamily();
- for (OperatingSystemEntity operatingSystemEntity : repositoryVersion.getOperatingSystems()) {
- // ostype in OperatingSystemEntity it's os family. That should be fixed
- // in OperatingSystemEntity.
- if (operatingSystemEntity.getOsType().equals(hostOsFamily)) {
- for (RepositoryEntity repositoryEntity : operatingSystemEntity.getRepositories()) {
- JsonObject repositoryInfo = new JsonObject();
- repositoryInfo.addProperty("base_url", repositoryEntity.getBaseUrl());
- repositoryInfo.addProperty("repo_name", repositoryEntity.getName());
- repositoryInfo.addProperty("repo_id", repositoryEntity.getRepositoryId());
-
- repositories.add(repositoryInfo);
- }
- rootJsonObject.add("repositories", repositories);
- }
- }
- hostLevelParams.put(REPO_INFO, rootJsonObject.toString());
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index e5f6bfa..04719a4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -74,6 +74,7 @@ import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.internal.RequestOperationLevel;
import org.apache.ambari.server.controller.internal.RequestResourceFilter;
import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
import org.apache.ambari.server.metadata.ActionMetadata;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
@@ -102,6 +103,7 @@ import org.apache.ambari.server.state.StackId;
import org.apache.ambari.server.state.StackInfo;
import org.apache.ambari.server.state.State;
import org.apache.ambari.server.state.stack.OsFamily;
+import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpInProgressEvent;
import org.apache.ambari.server.utils.StageUtils;
import org.apache.commons.lang.StringUtils;
@@ -179,6 +181,9 @@ public class AmbariCustomCommandExecutionHelper {
@Inject
private HostRoleCommandDAO hostRoleCommandDAO;
+ @Inject
+ private RepositoryVersionHelper repoVersionHelper;
+
private Map<String, Map<String, Map<String, String>>> configCredentialsForService = new HashMap<>();
protected static final String SERVICE_CHECK_COMMAND_NAME = "SERVICE_CHECK";
@@ -414,7 +419,11 @@ public class AmbariCustomCommandExecutionHelper {
hostLevelParams.put(CUSTOM_COMMAND, commandName);
// Set parameters required for re-installing clients on restart
- hostLevelParams.put(REPO_INFO, getRepoInfo(cluster, component, host));
+ try {
+ hostLevelParams.put(REPO_INFO, repoVersionHelper.getRepoInfo(cluster, component, host));
+ } catch (SystemException e) {
+ throw new AmbariException("", e);
+ }
hostLevelParams.put(STACK_NAME, stackId.getStackName());
hostLevelParams.put(STACK_VERSION, stackId.getStackVersion());
@@ -512,8 +521,6 @@ public class AmbariCustomCommandExecutionHelper {
execCmd.setCommandParams(commandParams);
execCmd.setRoleParams(roleParams);
- execCmd.setRepositoryFile(getCommandRepository(cluster, component, host));
-
// perform any server side command related logic - eg - set desired states on restart
applyCustomCommandBackendLogic(cluster, serviceName, componentName, commandName, hostName);
}
@@ -837,7 +844,8 @@ public class AmbariCustomCommandExecutionHelper {
* calls into the implementation of a custom command
*/
private void addDecommissionAction(final ActionExecutionContext actionExecutionContext,
- final RequestResourceFilter resourceFilter, Stage stage, ExecuteCommandJson executeCommandJson) throws AmbariException {
+ final RequestResourceFilter resourceFilter, Stage stage, ExecuteCommandJson executeCommandJson)
+ throws AmbariException {
String clusterName = actionExecutionContext.getClusterName();
final Cluster cluster = clusters.getCluster(clusterName);
@@ -1134,7 +1142,8 @@ public class AmbariCustomCommandExecutionHelper {
* @throws AmbariException if the commands can not be added
*/
public void addExecutionCommandsToStage(ActionExecutionContext actionExecutionContext,
- Stage stage, Map<String, String> requestParams, ExecuteCommandJson executeCommandJson) throws AmbariException {
+ Stage stage, Map<String, String> requestParams, ExecuteCommandJson executeCommandJson)
+ throws AmbariException {
List<RequestResourceFilter> resourceFilters = actionExecutionContext.getResourceFilters();
@@ -1199,235 +1208,6 @@ public class AmbariCustomCommandExecutionHelper {
}
/**
- * Get repository info given a cluster and host.
- *
- * @param cluster the cluster
- * @param host the host
- *
- * @return the repo info
- *
- * @deprecated use {@link #getCommandRepository(Cluster, ServiceComponent, Host)} instead.
- * @throws AmbariException if the repository information can not be obtained
- */
- @Deprecated
- public String getRepoInfo(Cluster cluster, ServiceComponent component, Host host) throws AmbariException {
-
- Function<List<RepositoryInfo>, JsonArray> function = new Function<List<RepositoryInfo>, JsonArray>() {
- @Override
- public JsonArray apply(List<RepositoryInfo> input) {
- return null == input ? null : (JsonArray) gson.toJsonTree(input);
- }
- };
-
- final JsonArray gsonList = getBaseUrls(cluster, component, host, function);
-
- if (null == gsonList) {
- return "";
- }
-
- BaseUrlUpdater<JsonArray> updater = new BaseUrlUpdater<JsonArray>(gsonList) {
- @Override
- public JsonArray apply(final RepositoryVersionEntity rve) {
-
- JsonArray result = new JsonArray();
-
- for (JsonElement e : gsonList) {
- JsonObject obj = e.getAsJsonObject();
-
- String repoId = obj.has("repoId") ? obj.get("repoId").getAsString() : null;
- String repoName = obj.has("repoName") ? obj.get("repoName").getAsString() : null;
- String baseUrl = obj.has("baseUrl") ? obj.get("baseUrl").getAsString() : null;
- String osType = obj.has("osType") ? obj.get("osType").getAsString() : null;
-
- if (null == repoId || null == baseUrl || null == osType || null == repoName) {
- continue;
- }
-
- for (OperatingSystemEntity ose : rve.getOperatingSystems()) {
- if (ose.getOsType().equals(osType) && ose.isAmbariManagedRepos()) {
- for (RepositoryEntity re : ose.getRepositories()) {
- if (re.getName().equals(repoName) &&
- !re.getBaseUrl().equals(baseUrl)) {
- obj.addProperty("baseUrl", re.getBaseUrl());
- }
- }
- result.add(e);
- }
- }
- }
-
- return result;
- }
- };
-
- return updateBaseUrls(cluster, component, updater).toString();
- }
-
- /**
- * Builds repository information for inclusion in a command. This replaces escaping json on
- * a command.
- *
- * @param cluster the cluster
- * @param host the host
- * @return the command repository
- * @throws AmbariException
- */
- @Experimental(feature=ExperimentalFeature.PATCH_UPGRADES)
- public CommandRepository getCommandRepository(final Cluster cluster, ServiceComponent component, final Host host) throws AmbariException {
-
- final CommandRepository commandRepo = new CommandRepository();
- boolean sysPreppedHost = configs.areHostsSysPrepped().equalsIgnoreCase("true");
- StackId stackId = component.getDesiredStackId();
- commandRepo.setRepositories(Collections.<RepositoryInfo>emptyList());
- commandRepo.setStackName(stackId.getStackName());
- commandRepo.getFeature().setPreInstalled(configs.areHostsSysPrepped());
- commandRepo.getFeature().setIsScoped(!sysPreppedHost);
- final ListMultimap<String, RepositoryInfo> stackReposByOs =
- ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion()).getRepositoriesByOs();
-
- @Experimental(feature = ExperimentalFeature.CUSTOM_SERVICE_REPOS,
- comment = "Remove logic for handling custom service repos after enabling multi-mpack cluster deployment")
- final BaseUrlUpdater<Void> updater = new BaseUrlUpdater<Void>(null) {
- @Override
- public Void apply(RepositoryVersionEntity rve) {
- commandRepo.setRepositoryVersionId(rve.getId());
- commandRepo.setRepositoryVersion(rve.getVersion());
- commandRepo.setResolved(rve.isResolved());
- commandRepo.setStackName(rve.getStackName());
-
- // !!! a repository version entity has all the repos worked out. We shouldn't use
- // the stack at all.
- // NOTE: The only exception here is we will add applicableServices from the stack model
- // if the repository version entity doesn't include it.
- for (OperatingSystemEntity osEntity : rve.getOperatingSystems()) {
- String osEntityFamily = os_family.find(osEntity.getOsType());
- if (osEntityFamily.equals(host.getOsFamily())) {
-
- commandRepo.setRepositories(osEntity.getOsType(), osEntity.getRepositories());
- for(CommandRepository.Repository repo : commandRepo.getRepositories()) {
- List<String> applicableServices = repo.getApplicableServices();
- if(applicableServices == null || applicableServices.isEmpty()) {
- List<RepositoryInfo> stackRepos = stackReposByOs.get(osEntity.getOsType());
- for(RepositoryInfo stackRepo : stackRepos) {
- if(stackRepo.getRepoName().equals(repo.getRepoName()) && stackRepo.getRepoId().equals(repo.getRepoId())) {
- repo.setApplicableServices(stackRepo.getApplicableServices());
- }
- }
- }
- }
-
- if (!osEntity.isAmbariManagedRepos()) {
- commandRepo.setNonManaged();
- } else {
- if (rve.isLegacy()){
- commandRepo.setLegacyRepoId(rve.getVersion());
- commandRepo.setLegacyRepoFileName(rve.getStackName(), rve.getVersion());
- commandRepo.getFeature().setIsScoped(false);
- } else {
- commandRepo.setRepoFileName(rve.getStackName(), rve.getId());
- commandRepo.setUniqueSuffix(String.format("-repo-%s", rve.getId()));
- }
- }
- }
- }
-
- return null;
- }
- };
-
- updateBaseUrls(cluster, component, updater);
-
- if (configs.arePackagesLegacyOverridden()) {
- LOG.warn("Legacy override option is turned on, disabling CommandRepositoryFeature.scoped feature");
- commandRepo.getFeature().setIsScoped(false);
- }
-
- return commandRepo;
- }
-
- /**
- * Executed by two different representations of repos. When we are comfortable with the new
- * implementation, this may be removed and called inline in {@link #getCommandRepository(Cluster, ServiceComponent, Host)}
- *
- * @param cluster the cluster to isolate the stack
- * @param component the component
- * @param host used to resolve the family for the repositories
- * @param function function that will transform the supplied repositories for specific use.
- * @return <T> the type as defined by the supplied {@code function}.
- * @throws AmbariException
- */
- @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES)
- private <T> T getBaseUrls(Cluster cluster, ServiceComponent component, Host host,
- Function<List<RepositoryInfo>, T> function) throws AmbariException {
-
- String hostOsType = host.getOsType();
- String hostOsFamily = host.getOsFamily();
- String hostName = host.getHostName();
-
- StackId stackId = component.getDesiredStackId();
-
- Map<String, List<RepositoryInfo>> repos = ambariMetaInfo.getRepository(
- stackId.getStackName(), stackId.getStackVersion());
-
- String family = os_family.find(hostOsType);
- if (null == family) {
- family = hostOsFamily;
- }
-
- final List<RepositoryInfo> repoInfos;
-
- // !!! check for the most specific first
- if (repos.containsKey(hostOsType)) {
- repoInfos = repos.get(hostOsType);
- } else if (null != family && repos.containsKey(family)) {
- repoInfos = repos.get(family);
- } else {
- repoInfos = null;
- LOG.warn("Could not retrieve repo information for host"
- + ", hostname=" + hostName
- + ", clusterName=" + cluster.getClusterName()
- + ", stackInfo=" + stackId.getStackId());
- }
-
- // leave it to function implementation to handle null.
- return function.apply(repoInfos);
- }
-
- /**
- * Checks repo URLs against the current version for the cluster and makes
- * adjustments to the Base URL when the current is different.
- *
- * @param <T> the result after appling the repository version, if found.
- */
- @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES)
- private <T> T updateBaseUrls(Cluster cluster, ServiceComponent component, BaseUrlUpdater<T> function) throws AmbariException {
-
- RepositoryVersionEntity repositoryEntity = null;
-
- // !!! try to find the component repo first
- if (null != component) {
- repositoryEntity = component.getDesiredRepositoryVersion();
- } else {
- LOG.info("Service component not passed in, attempt to resolve the repository for cluster {}",
- cluster.getClusterName());
- }
-
- if (null == repositoryEntity && null != component) {
- Service service = cluster.getService(component.getServiceName());
-
- repositoryEntity = service.getDesiredRepositoryVersion();
- }
-
- if (null == repositoryEntity) {
- LOG.info("Cluster {} has no specific Repository Versions. Using stack-defined values", cluster.getClusterName());
- return function.getDefault();
- }
-
- return function.apply(repositoryEntity);
- }
-
-
- /**
* Helper method to fill execution command information.
*
* @param actionExecContext the context
@@ -1662,21 +1442,4 @@ public class AmbariCustomCommandExecutionHelper {
return removedHosts;
}
- /**
- * Class that is used to update base urls. There are two implementations of this - when we no
- * longer are sure the deprecated repo info can be removed, so too can this class.
- */
- @Experimental(feature=ExperimentalFeature.PATCH_UPGRADES)
- abstract static class BaseUrlUpdater<T> implements Function<RepositoryVersionEntity, T> {
- private T m_default;
-
- private BaseUrlUpdater(T defaultValue) {
- m_default = defaultValue;
- }
-
- private T getDefault() {
- return m_default;
- }
-
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
index 46d0551..a6315f8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
@@ -88,6 +88,7 @@ import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.RequestFactory;
import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.actionmanager.StageFactory;
+import org.apache.ambari.server.agent.CommandRepository;
import org.apache.ambari.server.agent.ExecutionCommand;
import org.apache.ambari.server.agent.ExecutionCommand.KeyNames;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
@@ -106,6 +107,7 @@ import org.apache.ambari.server.controller.metrics.MetricPropertyProviderFactory
import org.apache.ambari.server.controller.metrics.MetricsCollectorHAManager;
import org.apache.ambari.server.controller.metrics.timeline.cache.TimelineMetricCacheProvider;
import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
import org.apache.ambari.server.customactions.ActionDefinition;
import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.metadata.ActionMetadata;
@@ -194,6 +196,7 @@ import org.apache.ambari.server.state.stack.OsFamily;
import org.apache.ambari.server.state.stack.RepositoryXml;
import org.apache.ambari.server.state.stack.WidgetLayout;
import org.apache.ambari.server.state.stack.WidgetLayoutInfo;
+import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostInstallEvent;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpInProgressEvent;
import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpSucceededEvent;
@@ -319,6 +322,9 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
@Inject
protected OsFamily osFamily;
+ @Inject
+ private RepositoryVersionHelper repoVersionHelper;
+
/**
* The KerberosHelper to help setup for enabling for disabling Kerberos
*/
@@ -2450,7 +2456,12 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
commandParams.put(ExecutionCommand.KeyNames.REFRESH_TOPOLOGY, "True");
}
- String repoInfo = customCommandExecutionHelper.getRepoInfo(cluster, component, host);
+ String repoInfo;
+ try {
+ repoInfo = repoVersionHelper.getRepoInfo(cluster, component, host);
+ } catch (SystemException e) {
+ throw new AmbariException("", e);
+ }
if (LOG.isDebugEnabled()) {
LOG.debug("Sending repo information to agent"
+ ", hostname=" + scHost.getHostName()
@@ -2552,7 +2563,6 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
execCmd.setRoleParams(roleParams);
execCmd.setCommandParams(commandParams);
- execCmd.setRepositoryFile(customCommandExecutionHelper.getCommandRepository(cluster, component, host));
execCmdWrapper.setVersions(cluster);
if (execCmd.getConfigurationTags().containsKey("cluster-env")) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/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 0c0f421..d155d46 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
@@ -718,18 +718,10 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
// Determine repositories for host
String osFamily = host.getOsFamily();
+ OperatingSystemEntity osEntity = repoVersionHelper.getOSEntityForHost(host, repoVersion);
- OperatingSystemEntity osEntity = null;
- for (OperatingSystemEntity os : repoVersion.getOperatingSystems()) {
- if (os.getOsType().equals(osFamily)) {
- osEntity = os;
- break;
- }
- }
-
- if (null == osEntity || CollectionUtils.isEmpty(osEntity.getRepositories())) {
- throw new SystemException(String.format("Repositories for os type %s are " +
- "not defined for version %s of Stack %s.",
+ if (CollectionUtils.isEmpty(osEntity.getRepositories())) {
+ throw new SystemException(String.format("Repositories for os type %s are not defined for version %s of Stack %s.",
osFamily, repoVersion.getVersion(), stackId));
}
@@ -761,7 +753,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou
actionContext.setRepositoryVersion(repoVersion);
actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout(true)));
- repoVersionHelper.addCommandRepository(actionContext, cluster, repoVersion, osEntity);
+ repoVersionHelper.addCommandRepositoryToContext(actionContext, osEntity);
return actionContext;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/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 74e4a88..d4c0116 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
@@ -442,8 +442,9 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource
Collections.singletonList(filter),
roleParams);
actionContext.setTimeout(Short.valueOf(configuration.getDefaultAgentTaskTimeout(true)));
+ actionContext.setRepositoryVersion(repoVersionEnt);
- repoVersionHelper.addCommandRepository(actionContext, cluster, repoVersionEnt, osEntity);
+ repoVersionHelper.addCommandRepositoryToContext(actionContext, osEntity);
String caption = String.format(INSTALL_PACKAGES_FULL_NAME + " on host %s", hostName);
RequestStageContainer req = createRequest(caption);
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java
index d734c81..a77caab 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/RepositoryVersionHelper.java
@@ -45,13 +45,18 @@ 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.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.RepositoryInfo;
import org.apache.ambari.server.state.RepositoryType;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceComponent;
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.repository.ClusterVersionSummary;
import org.apache.ambari.server.state.repository.VersionDefinitionXml;
+import org.apache.ambari.server.state.stack.OsFamily;
import org.apache.ambari.server.state.stack.UpgradePack;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@@ -70,6 +75,7 @@ import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
+
/**
* Provides helper methods to manage repository versions.
*/
@@ -87,6 +93,51 @@ public class RepositoryVersionHelper {
@Inject
private Provider<Configuration> configuration;
+ @Inject
+ private Provider<OsFamily> os_family;
+
+ @Inject Provider<Clusters> clusters;
+
+
+ /**
+ * Checks repo URLs against the current version for the cluster and make
+ * adjustments to the Base URL when the current is different.
+ *
+ * @param cluster {@link Cluster} object
+ * @param component resolve {@link RepositoryVersionEntity} for the component, could be {@code null}
+ *
+ * @return {@link RepositoryVersionEntity} retrieved for component if set or cluster if not
+ */
+ @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES)
+ private RepositoryVersionEntity getRepositoryVersionEntity(Cluster cluster, ServiceComponent component) throws SystemException {
+
+ RepositoryVersionEntity repositoryEntity = null;
+
+ // !!! try to find the component repo first
+ if (null != component) {
+ repositoryEntity = component.getDesiredRepositoryVersion();
+ } else {
+ LOG.info("Service component not passed in, attempt to resolve the repository for cluster {}",
+ cluster.getClusterName());
+ }
+
+ if (null == repositoryEntity && null != component) {
+ try {
+ Service service = cluster.getService(component.getServiceName());
+ repositoryEntity = service.getDesiredRepositoryVersion();
+ } catch (AmbariException e) {
+ throw new SystemException("Unhandled exception", e);
+ }
+ }
+
+ if (null == repositoryEntity) {
+ LOG.info("Cluster {} has no specific Repository Versions. Using stack-defined values", cluster.getClusterName());
+ return null;
+ }
+
+ return repositoryEntity;
+ }
+
/**
* Parses operating systems json to a list of entities. Expects json like:
* <pre>
@@ -329,31 +380,62 @@ public class RepositoryVersionHelper {
return roleParams;
}
+
+ /**
+ * Return repositories available for target os version on host based on {@code repoVersion} repository definition
+ * @param host target {@link Host} for providing repositories list
+ * @param repoVersion {@link RepositoryVersionEntity} version definition with all available repositories
+ *
+ * @return {@link OperatingSystemEntity} with available repositories for host
+ * @throws SystemException if no repository available for target {@link Host}
+ */
+ public OperatingSystemEntity getOSEntityForHost(Host host, RepositoryVersionEntity repoVersion) throws SystemException {
+ String osFamily = host.getOsFamily();
+ OperatingSystemEntity osEntity = null;
+ for (OperatingSystemEntity operatingSystem : repoVersion.getOperatingSystems()) {
+ if (osFamily.equals(operatingSystem.getOsType())) {
+ osEntity = operatingSystem;
+ break;
+ }
+ }
+
+ if (null == osEntity) {
+ throw new SystemException(String.format("Operating System matching %s could not be found",
+ osFamily));
+ }
+
+ return osEntity;
+ }
+
/**
* Adds a command repository to the action context
- * @param context the context
* @param osEntity the OS family
- * @param repoVersion the repository version entity
*/
@Experimental(feature = ExperimentalFeature.CUSTOM_SERVICE_REPOS,
comment = "Remove logic for handling custom service repos in Ambari 3.0")
- public void addCommandRepository(ActionExecutionContext context, Cluster cluster,
- final RepositoryVersionEntity repoVersion, OperatingSystemEntity osEntity) throws SystemException {
+ public CommandRepository getCommandRepository(final RepositoryVersionEntity repoVersion,
+ final OperatingSystemEntity osEntity) throws SystemException {
final CommandRepository commandRepo = new CommandRepository();
- boolean sysPreppedHost = configuration.get().areHostsSysPrepped().equalsIgnoreCase("true");
- StackId stackId = repoVersion.getStackId();
- ListMultimap<String, RepositoryInfo> stackReposByOs = null;
+ final boolean sysPreppedHost = configuration.get().areHostsSysPrepped().equalsIgnoreCase("true");
+
+ if (null == repoVersion) {
+ throw new SystemException("Repository version entity is not provided");
+ }
+
+ final StackId stackId = repoVersion.getStackId();
+ final ListMultimap<String, RepositoryInfo> stackReposByOs;
+
try {
- stackReposByOs =
- ami.get().getStack(stackId.getStackName(), stackId.getStackVersion()).getRepositoriesByOs();
+ stackReposByOs = ami.get().getStack(stackId.getStackName(), stackId.getStackVersion()).getRepositoriesByOs();
} catch (AmbariException e) {
throw new SystemException(String.format("Cannot obtain stack information for %s-%s", stackId.getStackName(), stackId.getStackVersion()), e);
}
+
commandRepo.setRepositories(osEntity.getOsType(), osEntity.getRepositories());
for(CommandRepository.Repository repo : commandRepo.getRepositories()) {
List<String> applicableServices = repo.getApplicableServices();
- if(applicableServices == null || applicableServices.isEmpty() && stackReposByOs != null) {
+ if(stackReposByOs != null && (applicableServices == null || applicableServices.isEmpty())) {
List<RepositoryInfo> stackRepos = stackReposByOs.get(osEntity.getOsType());
for(RepositoryInfo stackRepo : stackRepos) {
if(stackRepo.getRepoName().equals(repo.getRepoName()) && stackRepo.getRepoId().equals(repo.getRepoId())) {
@@ -387,10 +469,204 @@ public class RepositoryVersionHelper {
LOG.warn("Legacy override option is turned on, disabling CommandRepositoryFeature.scoped feature");
commandRepo.getFeature().setIsScoped(false);
}
+ return commandRepo;
+ }
+
+
+ /**
+ * Builds repository information for inclusion in a command. This replaces escaping json on
+ * a command.
+ *
+ * @param cluster the cluster
+ * @param host the host
+ * @param component {@link ServiceComponent} object, could be null to return service-related repository
+ * @return the command repository
+ * @throws SystemException
+ */
+ @Experimental(feature=ExperimentalFeature.PATCH_UPGRADES)
+ public CommandRepository getCommandRepository(final Cluster cluster, ServiceComponent component, final Host host)
+ throws SystemException {
+
+ RepositoryVersionEntity repoVersion = getRepositoryVersionEntity(cluster, component);
+ OperatingSystemEntity osEntity = getOSEntityForHost(host, repoVersion);
+
+ return getCommandRepository(repoVersion, osEntity);
+ }
+
+ /**
+ * This method builds and adds repo infoto hostLevelParams of action
+ *
+ * @param cluster cluster to which host level params belongs
+ * @param actionContext context of the action. Must be not {@code null}
+ * @param repositoryVersion repository version entity to use
+ * @param hostLevelParams hasgmap with host level params. Must be not {@code null}
+ * @param hostName host name to which add repo onfo
+ * @throws AmbariException
+ */
+ @Deprecated
+ public void addRepoInfoToHostLevelParams(final Cluster cluster, final ActionExecutionContext actionContext,
+ final RepositoryVersionEntity repositoryVersion, final Map<String, String> hostLevelParams,
+ final String hostName) throws AmbariException {
+
+ // if the repo is null, see if any values from the context should go on the
+ // host params and then return
+ if (null == repositoryVersion) {
+ // see if the action context has a repository set to use for the command
+ if (null != actionContext.getRepositoryVersion()) {
+ StackId stackId = actionContext.getRepositoryVersion().getStackId();
+ hostLevelParams.put(KeyNames.STACK_NAME, stackId.getStackName());
+ hostLevelParams.put(KeyNames.STACK_VERSION, stackId.getStackVersion());
+ }
+
+ return;
+ } else {
+ StackId stackId = repositoryVersion.getStackId();
+ hostLevelParams.put(KeyNames.STACK_NAME, stackId.getStackName());
+ hostLevelParams.put(KeyNames.STACK_VERSION, stackId.getStackVersion());
+ }
+
+ JsonObject rootJsonObject = new JsonObject();
+ JsonArray repositories = new JsonArray();
+
+ String hostOsFamily = cluster.getHost(hostName).getOsFamily();
+ for (OperatingSystemEntity operatingSystemEntity : repositoryVersion.getOperatingSystems()) {
+ // ostype in OperatingSystemEntity it's os family. That should be fixed
+ // in OperatingSystemEntity.
+ if (operatingSystemEntity.getOsType().equals(hostOsFamily)) {
+ for (RepositoryEntity repositoryEntity : operatingSystemEntity.getRepositories()) {
+ JsonObject repositoryInfo = new JsonObject();
+ repositoryInfo.addProperty("base_url", repositoryEntity.getBaseUrl());
+ repositoryInfo.addProperty("repo_name", repositoryEntity.getName());
+ repositoryInfo.addProperty("repo_id", repositoryEntity.getRepositoryId());
+
+ repositories.add(repositoryInfo);
+ }
+ rootJsonObject.add("repositories", repositories);
+ }
+ }
+ hostLevelParams.put(KeyNames.REPO_INFO, rootJsonObject.toString());
+ }
+
+
+ /**
+ * Get repository info given a cluster and host.
+ *
+ * @param cluster the cluster
+ * @param host the host
+ *
+ * @return the repo info
+ *
+ * @deprecated use {@link #getCommandRepository(Cluster, ServiceComponent, Host)} instead.
+ * @throws SystemException if the repository information can not be obtained
+ */
+ @Deprecated
+ public String getRepoInfo(Cluster cluster, ServiceComponent component, Host host) throws SystemException {
+ final JsonArray jsonList = getBaseUrls(cluster, component, host);
+ final RepositoryVersionEntity rve = getRepositoryVersionEntity(cluster, component);
+
+ if (null == rve || null == jsonList) {
+ return "";
+ }
+
+ final JsonArray result = new JsonArray();
+
+ for (JsonElement e : jsonList) {
+ JsonObject obj = e.getAsJsonObject();
+
+ String repoId = obj.has("repoId") ? obj.get("repoId").getAsString() : null;
+ String repoName = obj.has("repoName") ? obj.get("repoName").getAsString() : null;
+ String baseUrl = obj.has("baseUrl") ? obj.get("baseUrl").getAsString() : null;
+ String osType = obj.has("osType") ? obj.get("osType").getAsString() : null;
+
+ if (null == repoId || null == baseUrl || null == osType || null == repoName) {
+ continue;
+ }
+
+ for (OperatingSystemEntity ose : rve.getOperatingSystems()) {
+ if (ose.getOsType().equals(osType) && ose.isAmbariManagedRepos()) {
+ for (RepositoryEntity re : ose.getRepositories()) {
+ if (re.getName().equals(repoName) &&
+ !re.getBaseUrl().equals(baseUrl)) {
+ obj.addProperty("baseUrl", re.getBaseUrl());
+ }
+ }
+ result.add(e);
+ }
+ }
+ }
+ return result.toString();
+ }
+
+
+ /**
+ * Executed by two different representations of repos. When we are comfortable with the new
+ * implementation, this may be removed and called inline in {@link #getCommandRepository(Cluster, ServiceComponent, Host)}
+ *
+ * @param cluster the cluster to isolate the stack
+ * @param component the component
+ * @param host used to resolve the family for the repositories
+ * @return JsonArray the type as defined by the supplied {@code function}.
+ * @throws SystemException
+ */
+ @Deprecated
+ private JsonArray getBaseUrls(Cluster cluster, ServiceComponent component, Host host) throws SystemException {
+
+ String hostOsType = host.getOsType();
+ String hostOsFamily = host.getOsFamily();
+ String hostName = host.getHostName();
+
+ StackId stackId = component.getDesiredStackId();
+ Map<String, List<RepositoryInfo>> repos;
+
+ try {
+ repos = ami.get().getRepository(stackId.getStackName(), stackId.getStackVersion());
+ }catch (AmbariException e) {
+ throw new SystemException("Unhandled exception", e);
+ }
+
+ String family = os_family.get().find(hostOsType);
+ if (null == family) {
+ family = hostOsFamily;
+ }
+
+ final List<RepositoryInfo> repoInfoList;
+
+ // !!! check for the most specific first
+ if (repos.containsKey(hostOsType)) {
+ repoInfoList = repos.get(hostOsType);
+ } else if (null != family && repos.containsKey(family)) {
+ repoInfoList = repos.get(family);
+ } else {
+ repoInfoList = null;
+ LOG.warn("Could not retrieve repo information for host"
+ + ", hostname=" + hostName
+ + ", clusterName=" + cluster.getClusterName()
+ + ", stackInfo=" + stackId.getStackId());
+ }
+
+ return (null == repoInfoList) ? null : (JsonArray) gson.toJsonTree(repoInfoList);
+ }
+
+
+ /**
+ * Adds a command repository to the action context
+ * @param context the context
+ * @param osEntity the OS family
+ */
+ @Experimental(feature = ExperimentalFeature.CUSTOM_SERVICE_REPOS,
+ comment = "Remove logic for handling custom service repos in Ambari 3.0")
+ public void addCommandRepositoryToContext(ActionExecutionContext context,
+ OperatingSystemEntity osEntity) throws SystemException {
+
+ final RepositoryVersionEntity repoVersion = context.getRepositoryVersion();
+ final CommandRepository commandRepo = getCommandRepository(repoVersion, osEntity);
ClusterVersionSummary summary = null;
+
if (RepositoryType.STANDARD != repoVersion.getType()) {
try {
+ final Cluster cluster = clusters.get().getCluster(context.getClusterName());
+
VersionDefinitionXml xml = repoVersion.getRepositoryXml();
summary = xml.getClusterSummary(cluster);
} catch (Exception e) {
@@ -400,6 +676,7 @@ public class RepositoryVersionHelper {
final ClusterVersionSummary clusterSummary = summary;
+
context.addVisitor(new ExecutionCommandVisitor() {
@Override
public void visit(ExecutionCommand command) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
index 2b71af9..ec18a32 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java
@@ -574,14 +574,15 @@ public class AmbariCustomCommandExecutionHelperTest {
Host host = clusters.getHost("c1-c6401");
AmbariCustomCommandExecutionHelper helper = injector.getInstance(AmbariCustomCommandExecutionHelper.class);
+ RepositoryVersionHelper repoHelper = injector.getInstance(RepositoryVersionHelper.class);
StackDAO stackDAO = injector.getInstance(StackDAO.class);
RepositoryVersionDAO repoVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
ServiceComponentDesiredStateDAO componentDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class);
RepositoryVersionHelper repoVersionHelper = injector.getInstance(RepositoryVersionHelper.class);
- CommandRepository commandRepo = helper.getCommandRepository(cluster, componentRM, host);
+ CommandRepository commandRepo = repoHelper.getCommandRepository(cluster, componentRM, host);
+ Assert.assertEquals(2, commandRepo.getRepositories().size());
- Assert.assertEquals(0, commandRepo.getRepositories().size());
RepositoryInfo ri = new RepositoryInfo();
ri.setBaseUrl("http://foo");
@@ -607,18 +608,18 @@ public class AmbariCustomCommandExecutionHelperTest {
componentEntity.setDesiredRepositoryVersion(repositoryVersion);
componentEntity.addVersion(componentVersionEntity);
- componentEntity = componentDAO.merge(componentEntity);
+ componentDAO.merge(componentEntity);
// !!! make sure the override is set
- commandRepo = helper.getCommandRepository(cluster, componentRM, host);
+ commandRepo = repoHelper.getCommandRepository(cluster, componentRM, host);
Assert.assertEquals(1, commandRepo.getRepositories().size());
CommandRepository.Repository repo = commandRepo.getRepositories().iterator().next();
Assert.assertEquals("http://foo", repo.getBaseUrl());
// verify that ZK has no repositories, since we haven't defined a repo version for ZKC
- commandRepo = helper.getCommandRepository(cluster, componentZKC, host);
- Assert.assertEquals(0, commandRepo.getRepositories().size());
+ commandRepo = repoHelper.getCommandRepository(cluster, componentZKC, host);
+ Assert.assertEquals(2, commandRepo.getRepositories().size());
}
private void createClusterFixture(String clusterName, StackId stackId,
http://git-wip-us.apache.org/repos/asf/ambari/blob/6a09885d/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 51ba734..6e9e5ef 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -51,7 +51,6 @@ import java.util.UUID;
import javax.persistence.EntityManager;
-import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.ClusterNotFoundException;
import org.apache.ambari.server.DuplicateResourceException;
import org.apache.ambari.server.H2DatabaseCleaner;
@@ -331,11 +330,11 @@ public class AmbariManagementControllerTest {
host.setHostAttributes(hostAttributes);
}
- private void addHost(String hostname) throws AmbariException {
+ private void addHost(String hostname) throws Exception {
addHostToCluster(hostname, null);
}
- private void addHostToCluster(String hostname, String clusterName) throws AmbariException {
+ private void addHostToCluster(String hostname, String clusterName) throws Exception {
if (!clusters.hostExists(hostname)) {
clusters.addHost(hostname);
@@ -348,27 +347,30 @@ public class AmbariManagementControllerTest {
}
}
- private void deleteHost(String hostname) throws AmbariException {
+ private void deleteHost(String hostname) throws Exception {
clusters.deleteHost(hostname);
}
+
+
/**
* Creates a Cluster object, along with its corresponding ClusterVersion based on the stack.
* @param clusterName Cluster name
- * @throws AmbariException
+ * @throws Exception
*/
- private void createCluster(String clusterName) throws AmbariException, AuthorizationException {
+ private void createCluster(String clusterName) throws Exception{
+ RepositoryVersionDAO repoDAO = injector.getInstance(RepositoryVersionDAO.class);
ClusterRequest r = new ClusterRequest(null, clusterName, State.INSTALLED.name(), SecurityType.NONE, "HDP-0.1", null);
controller.createCluster(r);
}
- private void createService(String clusterName, String serviceName, State desiredState) throws AmbariException, AuthorizationException {
+ private void createService(String clusterName, String serviceName, State desiredState) throws Exception, AuthorizationException {
createService(clusterName, serviceName, repositoryVersion02, desiredState);
}
private void createService(String clusterName, String serviceName,
RepositoryVersionEntity repositoryVersion, State desiredState)
- throws AmbariException, AuthorizationException {
+ throws Exception, AuthorizationException {
String dStateStr = null;
if (desiredState != null) {
dStateStr = desiredState.toString();
@@ -386,7 +388,7 @@ public class AmbariManagementControllerTest {
private void createServiceComponent(String clusterName,
String serviceName, String componentName, State desiredState)
- throws AmbariException, AuthorizationException {
+ throws Exception, AuthorizationException {
String dStateStr = null;
if (desiredState != null) {
dStateStr = desiredState.toString();
@@ -401,7 +403,7 @@ public class AmbariManagementControllerTest {
private void createServiceComponentHost(String clusterName,
String serviceName, String componentName, String hostname,
- State desiredState) throws AmbariException, AuthorizationException {
+ State desiredState) throws Exception, AuthorizationException {
String dStateStr = null;
if (desiredState != null) {
dStateStr = desiredState.toString();
@@ -416,7 +418,7 @@ public class AmbariManagementControllerTest {
private void deleteServiceComponentHost(String clusterName,
String serviceName, String componentName, String hostname,
- State desiredState) throws AmbariException, AuthorizationException {
+ State desiredState) throws Exception, AuthorizationException {
String dStateStr = null;
if (desiredState != null) {
dStateStr = desiredState.toString();
@@ -431,7 +433,7 @@ public class AmbariManagementControllerTest {
private Long createConfigGroup(Cluster cluster, String serviceName, String name, String tag,
List<String> hosts, List<Config> configs)
- throws AmbariException {
+ throws Exception {
Map<Long, Host> hostMap = new HashMap<>();
Map<String, Config> configMap = new HashMap<>();
@@ -458,7 +460,7 @@ public class AmbariManagementControllerTest {
private long stopService(String clusterName, String serviceName,
boolean runSmokeTests, boolean reconfigureClients) throws
- AmbariException, AuthorizationException {
+ Exception, AuthorizationException {
ServiceRequest r = new ServiceRequest(clusterName, serviceName, null, State.INSTALLED.toString(), null);
Set<ServiceRequest> requests = new HashSet<>();
requests.add(r);
@@ -515,7 +517,7 @@ public class AmbariManagementControllerTest {
private long startService(String clusterName, String serviceName,
boolean runSmokeTests, boolean reconfigureClients) throws
- AmbariException, AuthorizationException {
+ Exception, AuthorizationException {
return startService(clusterName, serviceName, runSmokeTests, reconfigureClients, null);
}
@@ -523,7 +525,7 @@ public class AmbariManagementControllerTest {
private long startService(String clusterName, String serviceName,
boolean runSmokeTests, boolean reconfigureClients,
MaintenanceStateHelper maintenanceStateHelper) throws
- AmbariException, AuthorizationException {
+ Exception, AuthorizationException {
ServiceRequest r = new ServiceRequest(clusterName, serviceName, repositoryVersion02.getId(),
State.STARTED.toString(), null);
Set<ServiceRequest> requests = new HashSet<>();
@@ -564,7 +566,7 @@ public class AmbariManagementControllerTest {
private long installService(String clusterName, String serviceName,
boolean runSmokeTests, boolean reconfigureClients)
- throws AmbariException, AuthorizationException {
+ throws Exception, AuthorizationException {
return installService(clusterName, serviceName, runSmokeTests, reconfigureClients, null, null);
}
@@ -577,7 +579,7 @@ public class AmbariManagementControllerTest {
boolean runSmokeTests, boolean reconfigureClients,
MaintenanceStateHelper maintenanceStateHelper,
Map<String, String> mapRequestPropsInput)
- throws AmbariException, AuthorizationException {
+ throws Exception, AuthorizationException {
ServiceRequest r = new ServiceRequest(clusterName, serviceName, repositoryVersion02.getId(),
State.INSTALLED.toString(), null);
@@ -617,7 +619,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateClusterSimple() throws AmbariException, AuthorizationException {
+ public void testCreateClusterSimple() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
Set<ClusterResponse> r =
@@ -630,13 +632,13 @@ public class AmbariManagementControllerTest {
try {
createCluster(cluster1);
fail("Duplicate cluster creation should fail");
- } catch (AmbariException e) {
+ } catch (Exception e) {
// Expected
}
}
@Test
- public void testCreateClusterWithHostMapping() throws AmbariException, AuthorizationException {
+ public void testCreateClusterWithHostMapping() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
String host1 = getUniqueName();
@@ -696,7 +698,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateServicesSimple() throws AmbariException, AuthorizationException {
+ public void testCreateServicesSimple() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
String serviceName = "HDFS";
@@ -721,7 +723,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateServicesWithInvalidRequest() throws AmbariException, AuthorizationException {
+ public void testCreateServicesWithInvalidRequest() throws Exception, AuthorizationException {
// invalid request
// dups in requests
// multi cluster updates
@@ -754,7 +756,7 @@ public class AmbariManagementControllerTest {
set1.add(rInvalid);
ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);
fail("Expected failure for invalid cluster");
- } catch (AmbariException e) {
+ } catch (Exception e) {
// Expected
Assert.assertTrue(checkExceptionType(e, ClusterNotFoundException.class));
}
@@ -826,7 +828,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateServiceWithInvalidInfo() throws AmbariException, AuthorizationException {
+ public void testCreateServiceWithInvalidInfo() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
String serviceName = "HDFS";
@@ -867,7 +869,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateServicesMultiple() throws AmbariException, AuthorizationException {
+ public void testCreateServicesMultiple() throws Exception, AuthorizationException {
Set<ServiceRequest> set1 = new HashSet<>();
String cluster1 = getUniqueName();
@@ -887,7 +889,7 @@ public class AmbariManagementControllerTest {
set1.add(valid2);
ServiceResourceProviderTest.createServices(controller, repositoryVersionDAO, set1);
fail("Expected failure for invalid services");
- } catch (AmbariException e) {
+ } catch (Exception e) {
// Expected
Assert.assertTrue(checkExceptionType(e, DuplicateResourceException.class));
}
@@ -899,7 +901,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateServiceComponentSimple() throws AmbariException, AuthorizationException {
+ public void testCreateServiceComponentSimple() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
String serviceName = "HDFS";
@@ -940,7 +942,7 @@ public class AmbariManagementControllerTest {
@Test
public void testCreateServiceComponentWithInvalidRequest()
- throws AmbariException, AuthorizationException {
+ throws Exception, AuthorizationException {
// multiple clusters
// dup objects
// existing components
@@ -1318,8 +1320,6 @@ public class AmbariManagementControllerTest {
RoleCommand.START);
assertEquals(cluster1, ec.getClusterName());
assertNotNull(ec.getCommandParams());
- assertTrue(ec.getCommandParams().containsKey("custom_folder"));
- assertEquals("dashboards", ec.getCommandParams().get("custom_folder"));
assertNotNull(ec.getHostLevelParams());
assertTrue(ec.getHostLevelParams().containsKey(ExecutionCommand.KeyNames.USER_LIST));
assertEquals("[\"myhdfsuser\"]", ec.getHostLevelParams().get(ExecutionCommand.KeyNames.USER_LIST));
@@ -1330,7 +1330,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateServiceComponentMultiple() throws AmbariException, AuthorizationException {
+ public void testCreateServiceComponentMultiple() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
String cluster2 = getUniqueName();
@@ -1378,7 +1378,7 @@ public class AmbariManagementControllerTest {
}
private void createServiceComponentHostSimple(String clusterName, String host1,
- String host2) throws AmbariException, AuthorizationException {
+ String host2) throws Exception, AuthorizationException {
createCluster(clusterName);
clusters.getCluster(clusterName)
@@ -1477,7 +1477,7 @@ public class AmbariManagementControllerTest {
@Test
public void testCreateServiceComponentHostMultiple()
- throws AmbariException, AuthorizationException {
+ throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
String serviceName = "HDFS";
@@ -1535,7 +1535,7 @@ public class AmbariManagementControllerTest {
@Test
public void testCreateServiceComponentHostWithInvalidRequest()
- throws AmbariException, AuthorizationException {
+ throws Exception, AuthorizationException {
// multiple clusters
// dup objects
// existing components
@@ -1662,7 +1662,7 @@ public class AmbariManagementControllerTest {
set1.add(rInvalid);
controller.createHostComponents(set1);
fail("Expected failure for invalid service");
- } catch (AmbariException e) {
+ } catch (Exception e) {
// Expected
}
@@ -1681,7 +1681,7 @@ public class AmbariManagementControllerTest {
set1.add(rInvalid);
controller.createHostComponents(set1);
fail("Expected failure for invalid host");
- } catch (AmbariException e) {
+ } catch (Exception e) {
// Expected
}
@@ -1708,7 +1708,7 @@ public class AmbariManagementControllerTest {
set1.add(rInvalid);
controller.createHostComponents(set1);
fail("Expected failure for invalid host cluster mapping");
- } catch (AmbariException e) {
+ } catch (Exception e) {
// Expected
}
@@ -1797,7 +1797,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateHostSimple() throws AmbariException {
+ public void testCreateHostSimple() throws Exception {
String cluster1 = getUniqueName();
String host1 = getUniqueName();
String host2 = getUniqueName();
@@ -1850,7 +1850,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateHostMultiple() throws AmbariException {
+ public void testCreateHostMultiple() throws Exception {
String host1 = getUniqueName();
String host2 = getUniqueName();
String host3 = getUniqueName();
@@ -1886,7 +1886,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testCreateHostWithInvalidRequests() throws AmbariException {
+ public void testCreateHostWithInvalidRequests() throws Exception {
// unknown host
// invalid clusters
// duplicate host
@@ -2197,7 +2197,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testGetClusters() throws AmbariException, AuthorizationException {
+ public void testGetClusters() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
clusters.addCluster(cluster1, new StackId("HDP-0.1"));
@@ -2228,7 +2228,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testGetClustersWithFilters() throws AmbariException, AuthorizationException {
+ public void testGetClustersWithFilters() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
String cluster2 = getUniqueName();
String cluster3 = getUniqueName();
@@ -2259,7 +2259,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testGetServices() throws AmbariException {
+ public void testGetServices() throws Exception {
String cluster1 = getUniqueName();
StackId stackId = new StackId("HDP-0.1");
@@ -2288,7 +2288,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testGetServicesWithFilters() throws AmbariException {
+ public void testGetServicesWithFilters() throws Exception {
String cluster1 = getUniqueName();
String cluster2 = getUniqueName();
@@ -2368,7 +2368,7 @@ public class AmbariManagementControllerTest {
@Test
- public void testGetServiceComponents() throws AmbariException {
+ public void testGetServiceComponents() throws Exception {
String cluster1 = getUniqueName();
StackId stackId = new StackId("HDP-0.2");
@@ -2405,7 +2405,7 @@ public class AmbariManagementControllerTest {
@Test
- public void testGetServiceComponentsWithFilters() throws AmbariException {
+ public void testGetServiceComponentsWithFilters() throws Exception {
String cluster1 = getUniqueName();
String cluster2 = getUniqueName();
@@ -2526,7 +2526,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testGetServiceComponentHosts() throws AmbariException, AuthorizationException {
+ public void testGetServiceComponentHosts() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
String host1 = getUniqueName();
@@ -2572,7 +2572,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testGetServiceComponentHostsWithStaleConfigFilter() throws AmbariException, AuthorizationException {
+ public void testGetServiceComponentHostsWithStaleConfigFilter() throws Exception, AuthorizationException {
final String host1 = getUniqueName();
final String host2 = getUniqueName();
@@ -2760,7 +2760,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testHbaseDecommission() throws AmbariException, AuthorizationException {
+ public void testHbaseDecommission() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
clusters.getCluster(cluster1).setDesiredStackVersion(new StackId("HDP-2.0.7"));
@@ -2902,7 +2902,7 @@ public class AmbariManagementControllerTest {
}
private Cluster setupClusterWithHosts(String clusterName, String stackId, List<String> hosts,
- String osType) throws AmbariException, AuthorizationException {
+ String osType) throws Exception, AuthorizationException {
ClusterRequest r = new ClusterRequest(null, clusterName, stackId, null);
controller.createCluster(r);
Cluster c1 = clusters.getCluster(clusterName);
@@ -2913,7 +2913,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testGetServiceComponentHostsWithFilters() throws AmbariException, AuthorizationException {
+ public void testGetServiceComponentHostsWithFilters() throws Exception, AuthorizationException {
final String cluster1 = getUniqueName();
final String host1 = getUniqueName();
final String host2 = getUniqueName();
@@ -3062,7 +3062,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testGetHosts() throws AmbariException, AuthorizationException {
+ public void testGetHosts() throws Exception, AuthorizationException {
final String cluster1 = getUniqueName();
final String cluster2 = getUniqueName();
final String host1 = getUniqueName();
@@ -3136,7 +3136,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testServiceUpdateBasic() throws AmbariException, AuthorizationException {
+ public void testServiceUpdateBasic() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
String serviceName = "HDFS";
@@ -3179,7 +3179,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testServiceUpdateInvalidRequest() throws AmbariException, AuthorizationException {
+ public void testServiceUpdateInvalidRequest() throws Exception, AuthorizationException {
// multiple clusters
// dup services
// multiple diff end states
@@ -3261,7 +3261,7 @@ public class AmbariManagementControllerTest {
}
@Ignore("Something fishy with the stacks here that's causing the RCO to be loaded incorrectly")
- public void testServiceUpdateRecursive() throws AmbariException, AuthorizationException {
+ public void testServiceUpdateRecursive() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
@@ -3516,7 +3516,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testServiceComponentUpdateRecursive() throws AmbariException, AuthorizationException {
+ public void testServiceComponentUpdateRecursive() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
@@ -4055,7 +4055,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testComponentCategorySentWithRestart() throws AmbariException, AuthorizationException {
+ public void testComponentCategorySentWithRestart() throws Exception, AuthorizationException {
final String cluster1 = getUniqueName();
final String host1 = getUniqueName();
@@ -4421,7 +4421,7 @@ public class AmbariManagementControllerTest {
try {
RequestStatusResponse response = controller.createAction(actionRequest, requestProperties);
Assert.fail("createAction should fail");
- } catch (AmbariException ex) {
+ } catch (Exception ex) {
LOG.info(ex.getMessage());
if (!ex.getMessage().contains(message)) {
fail(String.format("Expected '%s' to contain '%s'", ex.getMessage(), message));
@@ -5119,7 +5119,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testReConfigureServiceClient() throws AmbariException, AuthorizationException {
+ public void testReConfigureServiceClient() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
Cluster cluster = clusters.getCluster(cluster1);
@@ -5401,7 +5401,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testClientServiceSmokeTests() throws AmbariException, AuthorizationException {
+ public void testClientServiceSmokeTests() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
String serviceName = "PIG";
@@ -5495,7 +5495,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testSkipTaskOnUnhealthyHosts() throws AmbariException, AuthorizationException {
+ public void testSkipTaskOnUnhealthyHosts() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
clusters.getCluster(cluster1)
@@ -5630,7 +5630,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testServiceCheckWhenHostIsUnhealthy() throws AmbariException, AuthorizationException {
+ public void testServiceCheckWhenHostIsUnhealthy() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
clusters.getCluster(cluster1).setDesiredStackVersion(new StackId("HDP-0.1"));
@@ -5722,13 +5722,13 @@ public class AmbariManagementControllerTest {
try {
response = controller.createAction(actionRequest, requestProperties);
assertTrue("Exception should have been raised.", false);
- } catch (AmbariException e) {
+ } catch (Exception e) {
assertTrue(e.getMessage().contains("there were no healthy eligible hosts"));
}
}
@Test
- public void testReInstallForInstallFailedClient() throws AmbariException, AuthorizationException {
+ public void testReInstallForInstallFailedClient() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
clusters.getCluster(cluster1)
@@ -5857,7 +5857,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testReInstallClientComponentFromServiceChange() throws AmbariException, AuthorizationException {
+ public void testReInstallClientComponentFromServiceChange() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
clusters.getCluster(cluster1)
@@ -6094,7 +6094,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testResourceFiltersWithCustomActions() throws AmbariException, AuthorizationException {
+ public void testResourceFiltersWithCustomActions() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
final String host1 = getUniqueName();
final String host2 = getUniqueName();
@@ -6166,7 +6166,7 @@ public class AmbariManagementControllerTest {
RequestStatusResponse response = null;
try {
response = controller.createAction(actionRequest, requestProperties);
- } catch (AmbariException ae) {
+ } catch (Exception ae) {
LOG.info("Expected exception.", ae);
Assert.assertTrue(ae.getMessage().contains("Custom action definition only " +
"allows one resource filter to be specified"));
@@ -6197,7 +6197,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testResourceFiltersWithCustomCommands() throws AmbariException, AuthorizationException {
+ public void testResourceFiltersWithCustomCommands() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
final String host1 = getUniqueName();
final String host2 = getUniqueName();
@@ -6351,7 +6351,7 @@ public class AmbariManagementControllerTest {
@Test
- public void testConfigsAttachedToServiceChecks() throws AmbariException, AuthorizationException {
+ public void testConfigsAttachedToServiceChecks() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
Cluster cluster = clusters.getCluster(cluster1);
@@ -6433,7 +6433,7 @@ public class AmbariManagementControllerTest {
@Test
@Ignore("Unsuported feature !")
- public void testConfigsAttachedToServiceNotCluster() throws AmbariException, AuthorizationException {
+ public void testConfigsAttachedToServiceNotCluster() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
clusters.getCluster(cluster1).setDesiredStackVersion(new StackId("HDP-0.1"));
@@ -6513,7 +6513,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testHostLevelParamsSentWithCommands() throws AmbariException, AuthorizationException {
+ public void testHostLevelParamsSentWithCommands() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
String serviceName = "PIG";
@@ -6570,7 +6570,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testConfigGroupOverridesWithHostActions() throws AmbariException, AuthorizationException {
+ public void testConfigGroupOverridesWithHostActions() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
Cluster cluster = clusters.getCluster(cluster1);
@@ -6727,7 +6727,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testConfigGroupOverridesWithDecommissionDatanode() throws AmbariException, AuthorizationException {
+ public void testConfigGroupOverridesWithDecommissionDatanode() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
Cluster cluster = clusters.getCluster(cluster1);
@@ -6832,7 +6832,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testConfigGroupOverridesWithServiceCheckActions() throws AmbariException, AuthorizationException {
+ public void testConfigGroupOverridesWithServiceCheckActions() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
createCluster(cluster1);
Cluster cluster = clusters.getCluster(cluster1);
@@ -7321,7 +7321,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testUpdateClusterUpgradabilityCheck() throws AmbariException, AuthorizationException {
+ public void testUpdateClusterUpgradabilityCheck() throws Exception, AuthorizationException {
String cluster1 = getUniqueName();
StackId currentStackId = new StackId("HDP-0.2");
@@ -7334,7 +7334,7 @@ public class AmbariManagementControllerTest {
ClusterRequest r = new ClusterRequest(c.getClusterId(), cluster1, "HDP-0.3", null);
try {
controller.updateClusters(Collections.singleton(r), mapRequestProps);
- } catch (AmbariException e) {
+ } catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("Illegal request to upgrade to"));
}
@@ -7345,7 +7345,7 @@ public class AmbariManagementControllerTest {
r = new ClusterRequest(c.getClusterId(), cluster1, "HDP-0.2", null);
try {
controller.updateClusters(Collections.singleton(r), mapRequestProps);
- } catch (AmbariException e) {
+ } catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("Upgrade is not allowed from"));
}
}
@@ -7613,7 +7613,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testGetTasksByRequestId() throws AmbariException {
+ public void testGetTasksByRequestId() throws Exception {
ActionManager am = injector.getInstance(ActionManager.class);
final long requestId1 = am.getNextRequestId();
@@ -8357,7 +8357,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testExecutionCommandConfiguration() throws AmbariException {
+ public void testExecutionCommandConfiguration() throws Exception {
Map<String, Map<String, String>> config = new HashMap<>();
config.put("type1", new HashMap<String, String>());
config.put("type3", new HashMap<String, String>());
@@ -8400,7 +8400,7 @@ public class AmbariManagementControllerTest {
String tag = "version1";
String type = "core-site";
- AmbariException exception = null;
+ Exception exception = null;
try {
AmbariManagementController amc = injector.getInstance(AmbariManagementController.class);
Clusters clusters = injector.getInstance(Clusters.class);
@@ -8432,7 +8432,7 @@ public class AmbariManagementControllerTest {
amc.createConfiguration(configurationRequest);
amc.createConfiguration(configurationRequest);
- } catch (AmbariException e) {
+ } catch (Exception e) {
exception = e;
}
@@ -9090,7 +9090,7 @@ public class AmbariManagementControllerTest {
private void testRunSmokeTestFlag(Map<String, String> mapRequestProps,
AmbariManagementController amc,
Set<ServiceRequest> serviceRequests)
- throws AmbariException, AuthorizationException {
+ throws Exception, AuthorizationException {
RequestStatusResponse response;//Starting HDFS service. No run_smoke_test flag is set, smoke
String cluster1 = getUniqueName();
@@ -9914,7 +9914,7 @@ public class AmbariManagementControllerTest {
try {
controller.updateClusters(Collections.singleton(cr), new HashMap<String, String>());
Assert.fail("Expect failure when creating a config that exists");
- } catch (AmbariException e) {
+ } catch (Exception e) {
// expected
}
}
@@ -10018,7 +10018,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testConfigAttributesStaleConfigFilter() throws AmbariException, AuthorizationException {
+ public void testConfigAttributesStaleConfigFilter() throws Exception, AuthorizationException {
final String host1 = getUniqueName();
final String host2 = getUniqueName();
@@ -10119,7 +10119,7 @@ public class AmbariManagementControllerTest {
}
@Test
- public void testSecretReferences() throws AmbariException, AuthorizationException {
+ public void testSecretReferences() throws Exception, AuthorizationException {
final String host1 = getUniqueName();
final String host2 = getUniqueName();
@@ -10208,7 +10208,7 @@ public class AmbariManagementControllerTest {
try {
controller.updateClusters(Collections.singleton(crReq), null);
fail("Request need to be failed with wrong secret reference");
- } catch (AmbariException e){
+ } catch (Exception e){
}
// reference to config which does not contain requested property
@@ -10237,7 +10237,7 @@ public class AmbariManagementControllerTest {
try {
controller.updateClusters(Collections.singleton(crReq), null);
fail("Request need to be failed with wrong secret reference");
- } catch (AmbariException e) {
+ } catch (Exception e) {
assertEquals("Error when parsing secret reference. Cluster: " + cluster1 + " ConfigType: hdfs-site ConfigVersion: 4 does not contain property 'test.password'",
e.getMessage());
}