You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2015/03/31 14:37:15 UTC
ambari git commit: AMBARI-10288. RU: Add host should not rely on
Finalize action (ncole)
Repository: ambari
Updated Branches:
refs/heads/trunk cf094a7e5 -> 4acfcf20d
AMBARI-10288. RU: Add host should not rely on Finalize action (ncole)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4acfcf20
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4acfcf20
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4acfcf20
Branch: refs/heads/trunk
Commit: 4acfcf20ddfd678543f1ed6de01cf90f087be1a4
Parents: cf094a7
Author: Nate Cole <nc...@hortonworks.com>
Authored: Mon Mar 30 17:39:22 2015 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Tue Mar 31 08:36:25 2015 -0400
----------------------------------------------------------------------
.../AmbariCustomCommandExecutionHelper.java | 61 ++++++++++++++++++--
.../upgrades/FinalizeUpgradeAction.java | 14 -----
.../upgrades/UpgradeActionTest.java | 31 +++++++++-
3 files changed, 86 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/4acfcf20/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 e7bfbe0..cfc1d4e 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
@@ -65,6 +65,9 @@ import org.apache.ambari.server.controller.internal.RequestResourceFilter;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.metadata.ActionMetadata;
import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
+import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
+import org.apache.ambari.server.orm.entities.RepositoryEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.CommandScriptDefinition;
@@ -92,6 +95,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -941,22 +947,24 @@ public class AmbariCustomCommandExecutionHelper {
* @throws AmbariException if the repository information can not be obtained
*/
public String getRepoInfo(Cluster cluster, Host host) throws AmbariException {
+
StackId stackId = cluster.getDesiredStackVersion();
Map<String, List<RepositoryInfo>> repos = ambariMetaInfo.getRepository(
stackId.getStackName(), stackId.getStackVersion());
- String repoInfo = "";
String family = os_family.find(host.getOsType());
if (null == family) {
family = host.getOsFamily();
}
+ JsonElement gsonList = null;
+
// !!! check for the most specific first
if (repos.containsKey(host.getOsType())) {
- repoInfo = gson.toJson(repos.get(host.getOsType()));
+ gsonList = gson.toJsonTree(repos.get(host.getOsType()));
} else if (null != family && repos.containsKey(family)) {
- repoInfo = gson.toJson(repos.get(family));
+ gsonList = gson.toJsonTree(repos.get(family));
} else {
LOG.warn("Could not retrieve repo information for host"
+ ", hostname=" + host.getHostName()
@@ -964,7 +972,52 @@ public class AmbariCustomCommandExecutionHelper {
+ ", stackInfo=" + stackId.getStackId());
}
- return repoInfo;
+ if (null != gsonList) {
+ updateBaseUrls(cluster, JsonArray.class.cast(gsonList));
+ return gsonList.toString();
+ } else {
+ return "";
+ }
+ }
+
+ /**
+ * Checks repo URLs against the current version for the cluster and makes
+ * adjustments to the Base URL when the current is different.
+ * @param cluster the cluster to load the current version
+ * @param jsonArray the array containing stack repo data
+ */
+ private void updateBaseUrls(Cluster cluster, JsonArray jsonArray) {
+ ClusterVersionEntity cve = cluster.getCurrentClusterVersion();
+ if (null == cve || null == cve.getRepositoryVersion()) {
+ return;
+ }
+
+ RepositoryVersionEntity rve = cve.getRepositoryVersion();
+
+ for (JsonElement e : jsonArray) {
+ 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)) {
+ for (RepositoryEntity re : ose.getRepositories()) {
+ if (re.getName().equals(repoName) &&
+ re.getRepositoryId().equals(repoId) &&
+ !re.getBaseUrl().equals(baseUrl)) {
+ obj.addProperty("baseUrl", re.getBaseUrl());
+ }
+ }
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/4acfcf20/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
index 586e98c..01bd9c7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FinalizeUpgradeAction.java
@@ -38,8 +38,6 @@ import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
import org.apache.ambari.server.orm.entities.HostEntity;
import org.apache.ambari.server.orm.entities.HostVersionEntity;
-import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
-import org.apache.ambari.server.orm.entities.RepositoryEntity;
import org.apache.ambari.server.serveraction.AbstractServerAction;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
@@ -206,18 +204,6 @@ public class FinalizeUpgradeAction extends AbstractServerAction {
outSB.append(String.format("Will finalize the version for cluster %s.\n", clusterName));
cluster.transitionClusterVersion(stackId, version, RepositoryVersionState.CURRENT);
- // !!! update the stack-defined repo url
- for (OperatingSystemEntity ose : upgradingClusterVersion.getRepositoryVersion().getOperatingSystems()) {
- for (RepositoryEntity re : ose.getRepositories()) {
- ambariMetaInfo.updateRepoBaseURL(
- upgradingClusterVersion.getRepositoryVersion().getStackName(),
- upgradingClusterVersion.getRepositoryVersion().getStackVersion(),
- ose.getOsType(),
- re.getRepositoryId(),
- re.getBaseUrl());
- }
- }
-
outSB.append("Upgrade was successful!\n");
return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", outSB.toString(), errSB.toString());
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/4acfcf20/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
index 1c0e195..87dd18b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java
@@ -19,6 +19,7 @@ package org.apache.ambari.server.serveraction.upgrades;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.HashMap;
@@ -30,6 +31,7 @@ import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.agent.CommandReport;
import org.apache.ambari.server.agent.ExecutionCommand;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.controller.AmbariCustomCommandExecutionHelper;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.OrmTestHelper;
@@ -49,6 +51,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
@@ -261,10 +267,31 @@ public class UpgradeActionTest {
assertEquals(HostRoleStatus.COMPLETED.name(), report.getStatus());
- // !!! verify the metainfo url has been updated
+ // !!! verify the metainfo url has not been updated, but an output command has
AmbariMetaInfo metaInfo = m_injector.getInstance(AmbariMetaInfo.class);
RepositoryInfo repo = metaInfo.getRepository("HDP", "2.1.1", "redhat6", "HDP-2.1.1");
- assertEquals("http://foo1", repo.getBaseUrl());
+ assertEquals("http://s3.amazonaws.com/dev.hortonworks.com/HDP/centos6/2.x/BUILDS/2.1.1.0-118", repo.getBaseUrl());
+
+ // !!! verify that a command will return the correct host info
+ AmbariCustomCommandExecutionHelper helper = m_injector.getInstance(
+ AmbariCustomCommandExecutionHelper.class);
+ Clusters clusters = m_injector.getInstance(Clusters.class);
+ Host host = clusters.getHost("h1");
+ Cluster cluster = clusters.getCluster("c1");
+
+ String repoInfo = helper.getRepoInfo(cluster, host);
+
+ Gson gson = new Gson();
+
+ JsonElement element = gson.fromJson(repoInfo, JsonElement.class);
+ assertTrue(element.isJsonArray());
+
+ JsonArray list = JsonArray.class.cast(element);
+ assertEquals(1, list.size());
+
+ JsonObject o = list.get(0).getAsJsonObject();
+ assertTrue(o.has("baseUrl"));
+ assertEquals("http://foo1", o.get("baseUrl").getAsString());
}