|
@@ -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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|