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 2017/07/13 19:14:42 UTC
[24/37] ambari git commit: AMBARI-21450. Initial cherry-picking for
feature branch (ncole)
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
index 328fe22..1a8b7e7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/host/HostImpl.java
@@ -148,7 +148,7 @@ public class HostImpl implements Host {
private long lastHeartbeatTime = 0L;
private AgentEnv lastAgentEnv = null;
- private List<DiskInfo> disksInfo = new CopyOnWriteArrayList<DiskInfo>();
+ private List<DiskInfo> disksInfo = new CopyOnWriteArrayList<>();
private RecoveryReport recoveryReport = new RecoveryReport();
private Integer currentPingPort = null;
@@ -481,7 +481,7 @@ public class HostImpl implements Host {
// FIXME add all other information into host attributes
setAgentVersion(new AgentVersion(hostInfo.getAgentUserId()));
- Map<String, String> attrs = new HashMap<String, String>();
+ Map<String, String> attrs = new HashMap<>();
if (hostInfo.getHardwareIsa() != null) {
attrs.put(HARDWAREISA, hostInfo.getHardwareIsa());
}
@@ -828,7 +828,7 @@ public class HostImpl implements Host {
Map<String, String> hostAttrs = gson.fromJson(hostEntity.getHostAttributes(), hostAttributesType);
if (hostAttrs == null) {
- hostAttrs = new ConcurrentHashMap<String, String>();
+ hostAttrs = new ConcurrentHashMap<>();
}
hostAttrs.putAll(hostAttributes);
@@ -939,24 +939,20 @@ public class HostImpl implements Host {
HostResponse r = new HostResponse(getHostName());
r.setAgentVersion(getAgentVersion());
- r.setAvailableMemBytes(getAvailableMemBytes());
r.setPhCpuCount(getPhCpuCount());
r.setCpuCount(getCpuCount());
r.setDisksInfo(getDisksInfo());
r.setHealthStatus(getHealthStatus());
r.setHostAttributes(getHostAttributes());
r.setIpv4(getIPv4());
- r.setIpv6(getIPv6());
r.setLastHeartbeatTime(getLastHeartbeatTime());
r.setLastAgentEnv(lastAgentEnv);
r.setLastRegistrationTime(getLastRegistrationTime());
r.setOsArch(getOsArch());
- r.setOsInfo(getOsInfo());
r.setOsType(getOsType());
r.setRackInfo(getRackInfo());
r.setTotalMemBytes(getTotalMemBytes());
r.setPublicHostName(getPublicHostName());
- r.setHostState(getState().toString());
r.setStatus(getStatus());
r.setRecoveryReport(getRecoveryReport());
r.setRecoverySummary(getRecoveryReport().getSummary());
@@ -1024,7 +1020,7 @@ public class HostImpl implements Host {
@Override
public Map<String, DesiredConfig> getDesiredConfigs(long clusterId) {
- Map<String, DesiredConfig> map = new HashMap<String, DesiredConfig>();
+ Map<String, DesiredConfig> map = new HashMap<>();
for (HostConfigMapping e : hostConfigMappingDAO.findSelected(
clusterId, getHostId())) {
@@ -1045,10 +1041,10 @@ public class HostImpl implements Host {
@Override
public Map<String, HostConfig> getDesiredHostConfigs(Cluster cluster,
Map<String, DesiredConfig> clusterDesiredConfigs) throws AmbariException {
- Map<String, HostConfig> hostConfigMap = new HashMap<String, HostConfig>();
+ Map<String, HostConfig> hostConfigMap = new HashMap<>();
if( null == cluster ){
- clusterDesiredConfigs = new HashMap<String, DesiredConfig>();
+ clusterDesiredConfigs = new HashMap<>();
}
// per method contract, fetch if not supplied
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java b/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java
index 69399d6..97f391e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/repository/VersionDefinitionXml.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -143,6 +143,27 @@ public class VersionDefinitionXml {
}
/**
+ * Gets the set of services that are included in this XML
+ * @return an empty set for STANDARD repositories, or a non-empty set for PATCH type.
+ */
+ public Set<String> getAvailableServiceNames() {
+ if (availableServices.isEmpty()) {
+ return Collections.emptySet();
+ } else {
+ Set<String> serviceNames = new HashSet<>();
+
+ Map<String, ManifestService> manifest = buildManifest();
+
+ for (AvailableServiceReference ref : availableServices) {
+ ManifestService ms = manifest.get(ref.serviceIdReference);
+ serviceNames.add(ms.serviceName);
+ }
+
+ return serviceNames;
+ }
+ }
+
+ /**
* Gets if the version definition was built as the default for a stack
* @return {@code true} if default for a stack
*/
@@ -353,7 +374,6 @@ public class VersionDefinitionXml {
/**
* Builds a Version Definition that is the default for the stack
- * @param stack
* @return the version definition
*/
public static VersionDefinitionXml build(StackInfo stackInfo) {
@@ -441,4 +461,4 @@ public class VersionDefinitionXml {
}
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/services/RetryUpgradeActionService.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/services/RetryUpgradeActionService.java b/ambari-server/src/main/java/org/apache/ambari/server/state/services/RetryUpgradeActionService.java
index 91898dc..a19e83e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/services/RetryUpgradeActionService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/services/RetryUpgradeActionService.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -30,11 +30,12 @@ import org.apache.ambari.server.AmbariService;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
+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.stack.upgrade.Direction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -165,24 +166,21 @@ public class RetryUpgradeActionService extends AbstractScheduledService {
* @return Request Id of active stack upgrade.
*/
private Long getActiveUpgradeRequestId(Cluster cluster) {
- ClusterVersionEntity currentVersion = cluster.getCurrentClusterVersion();
-
- if (currentVersion == null) {
- LOG.debug("No Cluster Version exists as CURRENT. Skip retrying failed tasks.");
- return null;
- }
// May be null, and either upgrade or downgrade
UpgradeEntity currentUpgrade = cluster.getUpgradeInProgress();
if (currentUpgrade == null) {
- LOG.debug("There is no active stack upgrade in progress. Skip retrying failed tasks.");
+ LOG.debug("There is no active upgrade in progress. Skip retrying failed tasks.");
return null;
}
- LOG.debug("Found an active stack upgrade with id: {}, direction: {}, type: {}, from version: {}, to version: {}",
- currentUpgrade.getId(), currentUpgrade.getDirection(), currentUpgrade.getUpgradeType(),
- currentUpgrade.getFromRepositoryVersion().getVersion(),
- currentUpgrade.getToRepositoryVersion().getVersion());
+ Direction direction = currentUpgrade.getDirection();
+ RepositoryVersionEntity repositoryVersion = currentUpgrade.getRepositoryVersion();
+
+ LOG.debug(
+ "Found an active upgrade with id: {}, direction: {}, {} {}", currentUpgrade.getId(),
+ direction, currentUpgrade.getUpgradeType(), direction.getPreposition(),
+ repositoryVersion.getVersion());
return currentUpgrade.getRequestId();
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
index c45ec24..5ac7752 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ClusterGrouping.java
@@ -224,7 +224,7 @@ public class ClusterGrouping extends Grouping {
if (null == hosts || hosts.hosts.isEmpty()) {
return null;
} else {
- realHosts = new LinkedHashSet<String>(hosts.hosts);
+ realHosts = new LinkedHashSet<>(hosts.hosts);
}
}
@@ -269,7 +269,7 @@ public class ClusterGrouping extends Grouping {
if (hosts != null) {
- Set<String> realHosts = new LinkedHashSet<String>(hosts.hosts);
+ Set<String> realHosts = new LinkedHashSet<>(hosts.hosts);
if (ExecuteHostType.MASTER == et.hosts && null != hosts.master) {
realHosts = Collections.singleton(hosts.master);
}
@@ -292,7 +292,7 @@ public class ClusterGrouping extends Grouping {
}
return new StageWrapper(
- StageWrapper.Type.RU_TASKS,
+ StageWrapper.Type.UPGRADE_TASKS,
execution.title,
new TaskWrapper(service, component, realHosts, et));
}
@@ -300,7 +300,7 @@ public class ClusterGrouping extends Grouping {
// no service and no component will distributed the task to all healthy
// hosts not in maintenance mode
Cluster cluster = ctx.getCluster();
- Set<String> hostNames = new HashSet<String>();
+ Set<String> hostNames = new HashSet<>();
for (Host host : ctx.getCluster().getHosts()) {
MaintenanceState maintenanceState = host.getMaintenanceState(cluster.getClusterId());
if (maintenanceState == MaintenanceState.OFF) {
@@ -309,7 +309,7 @@ public class ClusterGrouping extends Grouping {
}
return new StageWrapper(
- StageWrapper.Type.RU_TASKS,
+ StageWrapper.Type.UPGRADE_TASKS,
execution.title,
new TaskWrapper(service, component, hostNames, et));
}
@@ -349,7 +349,7 @@ public class ClusterGrouping extends Grouping {
@Override
public void merge(Iterator<Grouping> iterator) throws AmbariException {
if (executionStages == null) {
- executionStages = new ArrayList<ExecuteStage>();
+ executionStages = new ArrayList<>();
}
Map<String, List<ExecuteStage>> skippedStages = new HashMap<>();
while (iterator.hasNext()) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Direction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Direction.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Direction.java
index cb4f501..d6edd56 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Direction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Direction.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -79,4 +79,13 @@ public enum Direction {
}
+ /**
+ * Gets the preposition based on the direction. Since the repository is
+ * singular, it will either be "to repo" or "from repo".
+ *
+ * @return "to" or "from"
+ */
+ public String getPreposition() {
+ return (this == UPGRADE) ? "to" : "from";
+ }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ExecuteTask.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ExecuteTask.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ExecuteTask.java
index 3995cb6..0716481 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ExecuteTask.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/ExecuteTask.java
@@ -68,7 +68,7 @@ public class ExecuteTask extends Task {
@Override
public StageWrapper.Type getStageWrapperType() {
- return StageWrapper.Type.RU_TASKS;
+ return StageWrapper.Type.UPGRADE_TASKS;
}
@Override
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Grouping.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Grouping.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Grouping.java
index 9ea4de3..fed5b77 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Grouping.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Grouping.java
@@ -71,7 +71,7 @@ public class Grouping {
public boolean allowRetry = true;
@XmlElement(name="service")
- public List<UpgradePack.OrderService> services = new ArrayList<UpgradePack.OrderService>();
+ public List<UpgradePack.OrderService> services = new ArrayList<>();
@XmlElement(name="service-check", defaultValue="true")
public boolean performServiceCheck = true;
@@ -101,8 +101,8 @@ public class Grouping {
private static class DefaultBuilder extends StageWrapperBuilder {
- private List<StageWrapper> m_stages = new ArrayList<StageWrapper>();
- private Set<String> m_servicesToCheck = new HashSet<String>();
+ private List<StageWrapper> m_stages = new ArrayList<>();
+ private Set<String> m_servicesToCheck = new HashSet<>();
private boolean m_serviceCheck = true;
private DefaultBuilder(Grouping grouping, boolean serviceCheck) {
@@ -167,7 +167,7 @@ public class Grouping {
* @return List of list of TaskWrappers, where each outer list is a separate stage.
*/
private List<List<TaskWrapper>> organizeTaskWrappersBySyncRules(List<TaskWrapper> tasks) {
- List<List<TaskWrapper>> groupedTasks = new ArrayList<List<TaskWrapper>>();
+ List<List<TaskWrapper>> groupedTasks = new ArrayList<>();
List<TaskWrapper> subTasks = new ArrayList<>();
for (TaskWrapper tw : tasks) {
@@ -247,8 +247,8 @@ public class Grouping {
m_stages.addAll(0, stageWrappers);
}
- List<TaskWrapper> tasks = new ArrayList<TaskWrapper>();
- List<String> displays = new ArrayList<String>();
+ List<TaskWrapper> tasks = new ArrayList<>();
+ List<String> displays = new ArrayList<>();
for (String service : m_servicesToCheck) {
tasks.add(new TaskWrapper(
service, "", Collections.<String>emptySet(), new ServiceCheckTask()));
@@ -277,7 +277,7 @@ public class Grouping {
return Collections.emptyList();
}
- List<TaskBucket> holders = new ArrayList<TaskBucket>();
+ List<TaskBucket> holders = new ArrayList<>();
TaskBucket current = null;
@@ -301,7 +301,7 @@ public class Grouping {
private static class TaskBucket {
private StageWrapper.Type type;
- private List<Task> tasks = new ArrayList<Task>();
+ private List<Task> tasks = new ArrayList<>();
private TaskBucket(Task initial) {
switch (initial.getType()) {
case CONFIGURE:
@@ -310,7 +310,7 @@ public class Grouping {
type = StageWrapper.Type.SERVER_SIDE_ACTION;
break;
case EXECUTE:
- type = StageWrapper.Type.RU_TASKS;
+ type = StageWrapper.Type.UPGRADE_TASKS;
break;
case CONFIGURE_FUNCTION:
type = StageWrapper.Type.CONFIGURE;
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java
index b55d185..dd2dd02 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -33,6 +33,7 @@ import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.HostRoleCommandFactory;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.metadata.RoleCommandOrder;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.stack.HostsType;
import org.apache.ambari.server.stageplanner.RoleGraph;
import org.apache.ambari.server.stageplanner.RoleGraphFactory;
@@ -55,7 +56,7 @@ import com.google.gson.JsonObject;
public class HostOrderGrouping extends Grouping {
private static final String TYPE = "type";
private static final String HOST = "host";
- private static Logger LOG = LoggerFactory.getLogger(HostOrderGrouping.class);
+ private static final Logger LOG = LoggerFactory.getLogger(HostOrderGrouping.class);
/**
* Contains the ordered actions to schedule for this grouping.
@@ -173,10 +174,14 @@ public class HostOrderGrouping extends Grouping {
// either doesn't exist or the downgrade is to the current target version.
// hostsType better not be null either, but check anyway
if (null != hostsType && !hostsType.hosts.contains(hostName)) {
+ RepositoryVersionEntity targetRepositoryVersion = upgradeContext.getTargetRepositoryVersion(
+ sch.getServiceName());
+
LOG.warn("Host {} could not be orchestrated. Either there are no components for {}/{} " +
"or the target version {} is already current.",
hostName, sch.getServiceName(), sch.getServiceComponentName(),
- upgradeContext.getTargetRepositoryVersion().getVersion());
+ targetRepositoryVersion.getVersion());
+
continue;
}
@@ -226,7 +231,7 @@ public class HostOrderGrouping extends Grouping {
// create task wrappers
List<TaskWrapper> taskWrappers = new ArrayList<>();
for (HostRoleCommand command : stageCommandsForHost) {
- StackId stackId = upgradeContext.getTargetStackId();
+ StackId stackId = upgradeContext.getRepositoryVersion().getStackId();
String componentName = command.getRole().name();
String serviceName = null;
@@ -288,7 +293,6 @@ public class HostOrderGrouping extends Grouping {
/**
* @param upgradeContext the context
- * @param hosts the list of hostnames
* @return the wrappers for a host
*/
private List<StageWrapper> buildServiceChecks(UpgradeContext upgradeContext, List<String> serviceChecks) {
@@ -330,7 +334,10 @@ public class HostOrderGrouping extends Grouping {
* @return {@code true} if the host component advertises its version
*/
private boolean isVersionAdvertised(UpgradeContext upgradeContext, ServiceComponentHost sch) {
- StackId targetStack = upgradeContext.getTargetStackId();
+ RepositoryVersionEntity targetRepositoryVersion = upgradeContext.getTargetRepositoryVersion(
+ sch.getServiceName());
+
+ StackId targetStack = targetRepositoryVersion.getStackId();
try {
ComponentInfo component = upgradeContext.getAmbariMetaInfo().getComponent(
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/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 ef40211..471e30f 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
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -19,18 +19,33 @@ package org.apache.ambari.server.state.stack.upgrade;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import org.apache.ambari.server.AmbariException;
+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.configuration.Configuration;
+import org.apache.ambari.server.controller.ActionExecutionContext;
+import org.apache.ambari.server.controller.ActionExecutionContext.ExecutionCommandVisitor;
+import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.internal.OperatingSystemResourceProvider;
import org.apache.ambari.server.controller.internal.RepositoryResourceProvider;
import org.apache.ambari.server.controller.internal.RepositoryVersionResourceProvider;
+import org.apache.ambari.server.controller.spi.SystemException;
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.RepositoryInfo;
+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.VersionDefinitionXml;
import org.apache.ambari.server.state.stack.UpgradePack;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@@ -44,6 +59,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.inject.Inject;
+import com.google.inject.Provider;
import com.google.inject.Singleton;
/**
@@ -57,8 +73,11 @@ public class RepositoryVersionHelper {
@Inject
private Gson gson;
- @Inject(optional = true)
- private AmbariMetaInfo ambariMetaInfo;
+ @Inject
+ private Provider<AmbariMetaInfo> ami;
+
+ @Inject
+ private Provider<Configuration> configuration;
/**
* Parses operating systems json to a list of entities. Expects json like:
@@ -86,7 +105,7 @@ public class RepositoryVersionHelper {
* @throws Exception if any kind of json parsing error happened
*/
public List<OperatingSystemEntity> parseOperatingSystems(String repositoriesJson) throws Exception {
- final List<OperatingSystemEntity> operatingSystems = new ArrayList<OperatingSystemEntity>();
+ final List<OperatingSystemEntity> operatingSystems = new ArrayList<>();
final JsonArray rootJson = new JsonParser().parse(repositoriesJson).getAsJsonArray();
for (JsonElement operatingSystemJson: rootJson) {
JsonObject osObj = operatingSystemJson.getAsJsonObject();
@@ -106,8 +125,11 @@ public class RepositoryVersionHelper {
repositoryEntity.setBaseUrl(repositoryJson.get(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID).getAsString());
repositoryEntity.setName(repositoryJson.get(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID).getAsString());
repositoryEntity.setRepositoryId(repositoryJson.get(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID).getAsString());
- if (repositoryJson.get(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID) != null) {
- repositoryEntity.setUnique(repositoryJson.get(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID).getAsBoolean());
+ if (repositoryJson.get(RepositoryResourceProvider.REPOSITORY_MIRRORS_LIST_PROPERTY_ID) != null) {
+ repositoryEntity.setMirrorsList(repositoryJson.get(RepositoryResourceProvider.REPOSITORY_MIRRORS_LIST_PROPERTY_ID).getAsString());
+ }
+ if (repositoryJson.getAsJsonObject().get(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID) != null) {
+ repositoryEntity.setUnique(repositoryJson.getAsJsonObject().get(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID).getAsBoolean());
}
operatingSystemEntity.getRepositories().add(repositoryEntity);
}
@@ -156,6 +178,7 @@ public class RepositoryVersionHelper {
repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID, repository.getBaseUrl());
repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID, repository.getRepoName());
repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID, repository.getRepoId());
+ repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_MIRRORS_LIST_PROPERTY_ID, repository.getMirrorsList());
repositoryJson.addProperty(RepositoryResourceProvider.REPOSITORY_UNIQUE_PROPERTY_ID, repository.isUnique());
repositoriesJson.add(repositoryJson);
operatingSystemJson.addProperty(OperatingSystemResourceProvider.OPERATING_SYSTEM_AMBARI_MANAGED_REPOS, repository.isAmbariManagedRepositories());
@@ -194,7 +217,7 @@ public class RepositoryVersionHelper {
* @throws AmbariException if no upgrade packs suit the requirements
*/
public String getUpgradePackageName(String stackName, String stackVersion, String repositoryVersion, UpgradeType upgradeType) throws AmbariException {
- final Map<String, UpgradePack> upgradePacks = ambariMetaInfo.getUpgradePacks(stackName, stackVersion);
+ final Map<String, UpgradePack> upgradePacks = ami.get().getUpgradePacks(stackName, stackVersion);
for (UpgradePack upgradePack : upgradePacks.values()) {
final String upgradePackName = upgradePack.getName();
@@ -214,4 +237,107 @@ public class RepositoryVersionHelper {
throw new AmbariException("There were no suitable upgrade packs for stack " + stackName + " " + stackVersion +
((null != upgradeType) ? " and upgrade type " + upgradeType : ""));
}
+
+ /**
+ * Build the role parameters for an install command.
+ *
+ * @param amc the management controller. Tests don't use the same instance that gets injected.
+ * @param repoVersion the repository version
+ * @param osFamily the os family
+ * @param servicesOnHost the set of services to check for packages
+ * @return a Map<String, String> to use in
+ */
+ public Map<String, String> buildRoleParams(AmbariManagementController amc, RepositoryVersionEntity repoVersion, String osFamily, Set<String> servicesOnHost)
+ throws SystemException {
+
+ StackId stackId = repoVersion.getStackId();
+
+ List<ServiceOsSpecific.Package> packages = new ArrayList<>();
+
+ for (String serviceName : servicesOnHost) {
+ ServiceInfo info;
+
+ try {
+ if (ami.get().isServiceRemovedInStack(stackId.getStackName(), stackId.getStackVersion(), serviceName)) {
+ LOG.info(String.format("%s has been removed from stack %s-%s. Skip calculating its installation packages", stackId.getStackName(), stackId.getStackVersion(), serviceName));
+ continue; //No need to calculate install packages for removed services
+ }
+
+ info = ami.get().getService(stackId.getStackName(), stackId.getStackVersion(), serviceName);
+ } catch (AmbariException e) {
+ throw new SystemException(String.format("Cannot obtain stack information for %s-%s", stackId.getStackName(), stackId.getStackVersion()), e);
+ }
+
+ List<ServiceOsSpecific.Package> packagesForService = amc.getPackagesForServiceHost(info,
+ new HashMap<String, String>(), osFamily);
+
+ List<String> blacklistedPackagePrefixes = configuration.get().getRollingUpgradeSkipPackagesPrefixes();
+
+ for (ServiceOsSpecific.Package aPackage : packagesForService) {
+ if (!aPackage.getSkipUpgrade()) {
+ boolean blacklisted = false;
+ for (String prefix : blacklistedPackagePrefixes) {
+ if (aPackage.getName().startsWith(prefix)) {
+ blacklisted = true;
+ break;
+ }
+ }
+ if (! blacklisted) {
+ packages.add(aPackage);
+ }
+ }
+ }
+ }
+
+ Map<String, String> roleParams = new HashMap<>();
+ roleParams.put("stack_id", stackId.getStackId());
+ roleParams.put("repository_version", repoVersion.getVersion());
+ // !!! TODO make roleParams <String, Object> so we don't have to do this awfulness.
+ roleParams.put(KeyNames.PACKAGE_LIST, gson.toJson(packages));
+ roleParams.put(KeyNames.REPO_VERSION_ID, repoVersion.getId().toString());
+
+ VersionDefinitionXml xml = null;
+ try {
+ xml = repoVersion.getRepositoryXml();
+ } catch (Exception e) {
+ throw new SystemException(String.format("Could not load xml from repo version %s",
+ repoVersion.getVersion()));
+ }
+
+ if (null != xml && StringUtils.isNotBlank(xml.getPackageVersion(osFamily))) {
+ roleParams.put(KeyNames.PACKAGE_VERSION, xml.getPackageVersion(osFamily));
+ }
+
+ return roleParams;
+ }
+
+ /**
+ * Adds a command repository to the action context
+ * @param context the context
+ * @param osFamily the OS family
+ * @param repoVersion the repository version entity
+ * @param repos the repository entities
+ */
+ public void addCommandRepository(ActionExecutionContext context, String osFamily,
+ RepositoryVersionEntity repoVersion, List<RepositoryEntity> repos) {
+ StackId stackId = repoVersion.getStackId();
+
+ final CommandRepository commandRepo = new CommandRepository();
+ commandRepo.setRepositories(osFamily, repos);
+ commandRepo.setRepositoryVersion(repoVersion.getVersion());
+ commandRepo.setRepositoryVersionId(repoVersion.getId());
+ commandRepo.setStackName(stackId.getStackName());
+ commandRepo.setUniqueSuffix(String.format("-repo-%s", repoVersion.getId()));
+
+ context.addVisitor(new ExecutionCommandVisitor() {
+ @Override
+ public void visit(ExecutionCommand command) {
+ if (null == command.getRepositoryFile()) {
+ command.setRepositoryFile(commandRepo);
+ }
+ }
+ });
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapper.java
index 77b82e7..70589ec 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapper.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -93,7 +93,7 @@ public class StageWrapper {
* Gets the tasks json.
*/
public String getTasksJson() {
- List<Task> realTasks = new ArrayList<Task>();
+ List<Task> realTasks = new ArrayList<>();
for (TaskWrapper tw : tasks) {
realTasks.addAll(tw.getTasks());
}
@@ -105,7 +105,7 @@ public class StageWrapper {
* @return the set of hosts for all tasks
*/
public Set<String> getHosts() {
- Set<String> hosts = new HashSet<String>();
+ Set<String> hosts = new HashSet<>();
for (TaskWrapper tw : tasks) {
hosts.addAll(tw.getHosts());
}
@@ -155,7 +155,7 @@ public class StageWrapper {
public enum Type {
SERVER_SIDE_ACTION,
RESTART,
- RU_TASKS,
+ UPGRADE_TASKS,
SERVICE_CHECK,
STOP,
START,
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapperBuilder.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapperBuilder.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapperBuilder.java
index 3cf3f8b..7fd8938 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapperBuilder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/StageWrapperBuilder.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Task.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Task.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Task.java
index 5c7cb6c..6ab2fd2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Task.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/Task.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapper.java
index dfa6159..8a87ff1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapper.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -42,10 +42,10 @@ public class TaskWrapper {
private Set<String> timeoutKeys = new HashSet<>();
/**
- * @param s the service name for the tasks
- * @param c the component name for the tasks
- * @param hosts the set of hosts that the tasks are for
- * @param tasks an array of tasks as a convenience
+ * @param s the service name for the task
+ * @param c the component name for the task
+ * @param hosts the set of hosts that the task is for
+ * @param task a single task
*/
public TaskWrapper(String s, String c, Set<String> hosts, Task task) {
this(s, c, hosts, null, task);
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java
index 73ff2ca..23f2557 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/TaskWrapperBuilder.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
*/
public class TaskWrapperBuilder {
- private static Logger LOG = LoggerFactory.getLogger(TaskWrapperBuilder.class);
+ private static final Logger LOG = LoggerFactory.getLogger(TaskWrapperBuilder.class);
/**
* Creates a collection of task wrappers based on the set of hosts they are allowed to run on
@@ -56,7 +56,7 @@ public class TaskWrapperBuilder {
// to create.
String ambariServerHostname = StageUtils.getHostName();
- List<TaskWrapper> collection = new ArrayList<TaskWrapper>();
+ List<TaskWrapper> collection = new ArrayList<>();
for (Task t : tasks) {
// only add the server-side task if there are actual hosts for the service/component
@@ -114,7 +114,7 @@ public class TaskWrapperBuilder {
* @return Returns the union of the hosts scheduled to perform the tasks.
*/
public static Set<String> getEffectiveHosts(List<TaskWrapper> tasks) {
- Set<String> effectiveHosts = new HashSet<String>();
+ Set<String> effectiveHosts = new HashSet<>();
for(TaskWrapper t : tasks) {
effectiveHosts.addAll(t.getHosts());
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
index 0ff4dad..f9d3cfc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostImpl.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
@@ -43,12 +42,14 @@ import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
import org.apache.ambari.server.orm.dao.HostDAO;
+import org.apache.ambari.server.orm.dao.HostVersionDAO;
import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
import org.apache.ambari.server.orm.dao.StackDAO;
import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
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.RepositoryVersionEntity;
import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
import org.apache.ambari.server.orm.entities.StackEntity;
@@ -62,6 +63,7 @@ import org.apache.ambari.server.state.HostComponentAdminState;
import org.apache.ambari.server.state.HostConfig;
import org.apache.ambari.server.state.HostState;
import org.apache.ambari.server.state.MaintenanceState;
+import org.apache.ambari.server.state.RepositoryVersionState;
import org.apache.ambari.server.state.SecurityState;
import org.apache.ambari.server.state.ServiceComponent;
import org.apache.ambari.server.state.ServiceComponentHost;
@@ -82,6 +84,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.ImmutableList;
+import com.google.common.util.concurrent.Striped;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
@@ -108,6 +111,9 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
@Inject
private RepositoryVersionDAO repositoryVersionDAO;
+ @Inject
+ private HostVersionDAO hostVersionDAO;
+
private final ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO;
private final Clusters clusters;
@@ -156,6 +162,12 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
private ImmutableList<Map<String, String>> processes = ImmutableList.of();
/**
+ * Used for preventing multiple components on the same host from trying to
+ * recalculate versions concurrently.
+ */
+ private static final Striped<Lock> HOST_VERSION_LOCK = Striped.lazyWeakLock(20);
+
+ /**
* The name of the host (which should never, ever change)
*/
private final String hostName;
@@ -678,10 +690,8 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
ServiceComponentHostInstallEvent e =
(ServiceComponentHostInstallEvent) event;
if (LOG.isDebugEnabled()) {
- LOG.debug("Updating live stack version during INSTALL event"
- + ", new stack version=" + e.getStackId());
+ LOG.debug("Updating live stack version during INSTALL event, new stack version={}", e.getStackId());
}
- impl.setStackVersion(new StackId(e.getStackId()));
}
}
}
@@ -770,7 +780,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
throw new RuntimeException(e);
}
- StackId stackId = serviceComponent.getDesiredStackVersion();
+ StackId stackId = serviceComponent.getDesiredStackId();
StackEntity stackEntity = stackDAO.find(stackId.getStackName(),
stackId.getStackVersion());
@@ -782,7 +792,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
stateEntity.setHostEntity(hostEntity);
stateEntity.setCurrentState(stateMachine.getCurrentState());
stateEntity.setUpgradeState(UpgradeState.NONE);
- stateEntity.setCurrentStack(stackEntity);
HostComponentDesiredStateEntity desiredStateEntity = new HostComponentDesiredStateEntity();
desiredStateEntity.setClusterId(serviceComponent.getClusterId());
@@ -790,7 +799,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
desiredStateEntity.setServiceName(serviceComponent.getServiceName());
desiredStateEntity.setHostEntity(hostEntity);
desiredStateEntity.setDesiredState(State.INIT);
- desiredStateEntity.setDesiredStack(stackEntity);
if(!serviceComponent.isMasterComponent() && !serviceComponent.isClientComponent()) {
desiredStateEntity.setAdminState(HostComponentAdminState.INSERVICE);
@@ -1002,9 +1010,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
public void handleEvent(ServiceComponentHostEvent event)
throws InvalidStateTransitionException {
if (LOG.isDebugEnabled()) {
- LOG.debug("Handling ServiceComponentHostEvent event,"
- + " eventType=" + event.getType().name()
- + ", event=" + event.toString());
+ LOG.debug("Handling ServiceComponentHostEvent event, eventType={}, event={}", event.getType().name(), event);
}
State oldState = getState();
try {
@@ -1036,13 +1042,8 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
+ ", oldState=" + oldState
+ ", currentState=" + getState());
if (LOG.isDebugEnabled()) {
- LOG.debug("ServiceComponentHost transitioned to a new state"
- + ", serviceComponentName=" + getServiceComponentName()
- + ", hostName=" + getHostName()
- + ", oldState=" + oldState
- + ", currentState=" + getState()
- + ", eventType=" + event.getType().name()
- + ", event=" + event);
+ LOG.debug("ServiceComponentHost transitioned to a new state, serviceComponentName={}, hostName={}, oldState={}, currentState={}, eventType={}, event={}",
+ getServiceComponentName(), getHostName(), oldState, getState(), event.getType().name(), event);
}
}
}
@@ -1125,36 +1126,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
}
@Override
- public StackId getStackVersion() {
- HostComponentStateEntity schStateEntity = getStateEntity();
- return getStackVersionFromSCHStateEntity(schStateEntity);
- }
-
- private StackId getStackVersionFromSCHStateEntity(HostComponentStateEntity schStateEntity) {
- if (schStateEntity == null) {
- return new StackId();
- }
-
- StackEntity currentStackEntity = schStateEntity.getCurrentStack();
- return new StackId(currentStackEntity.getStackName(), currentStackEntity.getStackVersion());
- }
-
- @Override
- public void setStackVersion(StackId stackId) {
- StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion());
-
- HostComponentStateEntity stateEntity = getStateEntity();
- if (stateEntity != null) {
- stateEntity.setCurrentStack(stackEntity);
- stateEntity = hostComponentStateDAO.merge(stateEntity);
- } else {
- LOG.warn("Setting a member on an entity object that may have been "
- + "previously deleted, serviceName = " + getServiceName() + ", " + "componentName = "
- + getServiceComponentName() + ", " + "hostName = " + getHostName());
- }
- }
-
- @Override
public State getDesiredState() {
HostComponentDesiredStateEntity desiredStateEntity = getDesiredStateEntity();
if (desiredStateEntity != null) {
@@ -1185,38 +1156,6 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
}
@Override
- public StackId getDesiredStackVersion() {
- HostComponentDesiredStateEntity desiredStateEntity = getDesiredStateEntity();
- return getDesiredStackVersionFromHostComponentDesiredStateEntity(desiredStateEntity);
- }
-
- private StackId getDesiredStackVersionFromHostComponentDesiredStateEntity(HostComponentDesiredStateEntity desiredStateEntity) {
- if (desiredStateEntity != null) {
- StackEntity desiredStackEntity = desiredStateEntity.getDesiredStack();
- return new StackId(desiredStackEntity.getStackName(), desiredStackEntity.getStackVersion());
- } else {
- LOG.warn("Trying to fetch a member from an entity object that may "
- + "have been previously deleted, serviceName = " + getServiceName() + ", "
- + "componentName = " + getServiceComponentName() + ", " + "hostName = " + getHostName());
- }
- return null;
- }
-
- @Override
- public void setDesiredStackVersion(StackId stackId) {
- LOG.debug("Set DesiredStackVersion on serviceName = {} componentName = {} hostName = {} to {}",
- getServiceName(), getServiceComponentName(), getHostName(), stackId);
-
- HostComponentDesiredStateEntity desiredStateEntity = getDesiredStateEntity();
- if (desiredStateEntity != null) {
- StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion());
-
- desiredStateEntity.setDesiredStack(stackEntity);
- hostComponentDesiredStateDAO.merge(desiredStateEntity);
- }
- }
-
- @Override
public HostComponentAdminState getComponentAdminState() {
HostComponentDesiredStateEntity desiredStateEntity = getDesiredStateEntity();
return getComponentAdminStateFromDesiredStateEntity(desiredStateEntity);
@@ -1255,14 +1194,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
public ServiceComponentHostResponse convertToResponse(Map<String, DesiredConfig> desiredConfigs) {
HostComponentStateEntity hostComponentStateEntity = getStateEntity();
HostEntity hostEntity = hostComponentStateEntity.getHostEntity();
- if (null == hostComponentStateEntity) {
- LOG.warn(
- "Could not convert ServiceComponentHostResponse to a response. It's possible that Host {} was deleted.",
- getHostName());
- return null;
- }
- StackId stackVersion = getStackVersionFromSCHStateEntity(hostComponentStateEntity);
HostComponentDesiredStateEntity hostComponentDesiredStateEntity = getDesiredStateEntity();
String clusterName = serviceComponent.getClusterName();
@@ -1271,14 +1203,14 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
String hostName = getHostName();
String publicHostName = hostEntity.getPublicHostName();
String state = getState().toString();
- String stackId = stackVersion.getStackId();
String desiredState = (hostComponentDesiredStateEntity == null) ? null : hostComponentDesiredStateEntity.getDesiredState().toString();
- String desiredStackId = getDesiredStackVersionFromHostComponentDesiredStateEntity(hostComponentDesiredStateEntity).getStackId();
+ String desiredStackId = serviceComponent.getDesiredStackId().getStackId();
HostComponentAdminState componentAdminState = getComponentAdminStateFromDesiredStateEntity(hostComponentDesiredStateEntity);
UpgradeState upgradeState = hostComponentStateEntity.getUpgradeState();
String displayName = null;
try {
+ StackId stackVersion = serviceComponent.getDesiredStackId();
ComponentInfo compInfo = ambariMetaInfo.getComponent(stackVersion.getStackName(),
stackVersion.getStackVersion(), serviceName, serviceComponentName);
displayName = compInfo.getDisplayName();
@@ -1286,9 +1218,15 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
displayName = serviceComponentName;
}
+ String desiredRepositoryVersion = null;
+ RepositoryVersionEntity repositoryVersion = serviceComponent.getDesiredRepositoryVersion();
+ if (null != repositoryVersion) {
+ desiredRepositoryVersion = repositoryVersion.getVersion();
+ }
+
ServiceComponentHostResponse r = new ServiceComponentHostResponse(clusterName, serviceName,
- serviceComponentName, displayName, hostName, publicHostName, state, stackId,
- desiredState, desiredStackId, componentAdminState);
+ serviceComponentName, displayName, hostName, publicHostName, state, getVersion(),
+ desiredState, desiredStackId, desiredRepositoryVersion, componentAdminState);
r.setActualConfigs(actualConfigs);
r.setUpgradeState(upgradeState);
@@ -1317,11 +1255,11 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
.append(", serviceName=")
.append(serviceComponent.getServiceName())
.append(", desiredStackVersion=")
- .append(getDesiredStackVersion())
+ .append(serviceComponent.getDesiredStackId())
.append(", desiredState=")
.append(getDesiredState())
- .append(", stackVersion=")
- .append(getStackVersion())
+ .append(", version=")
+ .append(getVersion())
.append(", state=")
.append(getState())
.append(", securityState=")
@@ -1382,7 +1320,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
// completed, but only if it was persisted
if (fireRemovalEvent) {
long clusterId = getClusterId();
- StackId stackId = getStackVersion();
+ StackId stackId = serviceComponent.getDesiredStackId();
String stackVersion = stackId.getStackVersion();
String stackName = stackId.getStackName();
String serviceName = getServiceName();
@@ -1447,7 +1385,7 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
Long groupId = Long.parseLong(overrideEntry.getKey());
hc.getConfigGroupOverrides().put(groupId, overrideEntry.getValue());
if (!configGroupMap.containsKey(groupId)) {
- LOG.debug("Config group does not exist, id = " + groupId);
+ LOG.debug("Config group does not exist, id = {}", groupId);
}
}
}
@@ -1557,46 +1495,46 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
}
/**
- * Bootstrap any Repo Version, and potentially transition the Host Version across states.
- * If a Host Component has a valid version, then create a Host Version if it does not already exist.
- * If a Host Component does not have a version, return right away because no information is known.
- * @return Return the Repository Version object
- * @throws AmbariException
+ * {@inheritDoc}
*/
@Override
- public RepositoryVersionEntity recalculateHostVersionState() throws AmbariException {
- RepositoryVersionEntity repositoryVersion = null;
- String version = getVersion();
- if (getUpgradeState().equals(UpgradeState.IN_PROGRESS) ||
- getUpgradeState().equals(UpgradeState.VERSION_MISMATCH) ||
- State.UNKNOWN.toString().equals(version)) {
- // TODO: we still recalculate host version if upgrading component failed. It seems to be ok
- // Recalculate only if no upgrade in progress/no version mismatch
- return null;
- }
-
- final String hostName = getHostName();
- final long hostId = getHost().getHostId();
- final Set<Cluster> clustersForHost = clusters.getClustersForHost(hostName);
- if (clustersForHost.size() != 1) {
- throw new AmbariException("Host " + hostName + " should be assigned only to one cluster");
- }
- final Cluster cluster = clustersForHost.iterator().next();
- final StackId stackId = cluster.getDesiredStackVersion();
- final StackInfo stackInfo = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion());
+ @Transactional
+ public HostVersionEntity recalculateHostVersionState() throws AmbariException {
+ RepositoryVersionEntity repositoryVersion = serviceComponent.getDesiredRepositoryVersion();
+ HostEntity hostEntity = host.getHostEntity();
+ HostVersionEntity hostVersionEntity = hostVersionDAO.findHostVersionByHostAndRepository(
+ hostEntity, repositoryVersion);
+
+ Lock lock = HOST_VERSION_LOCK.get(host.getHostName());
+ lock.lock();
+ try {
+ // Create one if it doesn't already exist. It will be possible to make
+ // further transitions below.
+ if (hostVersionEntity == null) {
+ hostVersionEntity = new HostVersionEntity(hostEntity, repositoryVersion,
+ RepositoryVersionState.INSTALLING);
+
+ LOG.info("Creating host version for {}, state={}, repo={} (repo_id={})",
+ hostVersionEntity.getHostName(), hostVersionEntity.getState(),
+ hostVersionEntity.getRepositoryVersion().getVersion(),
+ hostVersionEntity.getRepositoryVersion().getId());
+
+ hostVersionDAO.create(hostVersionEntity);
+ }
- // Check if there is a Repo Version already for the version.
- // If it doesn't exist, will have to create it.
- repositoryVersion = repositoryVersionDAO.findByStackNameAndVersion(stackId.getStackName(), version);
+ final ServiceComponentHostSummary hostSummary = new ServiceComponentHostSummary(
+ ambariMetaInfo, hostEntity, repositoryVersion);
- if (null == repositoryVersion) {
- repositoryVersion = createRepositoryVersion(version, stackId, stackInfo);
+ if (hostSummary.isVersionCorrectForAllHosts(repositoryVersion)) {
+ if (hostVersionEntity.getState() != RepositoryVersionState.CURRENT) {
+ hostVersionEntity.setState(RepositoryVersionState.CURRENT);
+ hostVersionEntity = hostVersionDAO.merge(hostVersionEntity);
+ }
+ }
+ } finally {
+ lock.unlock();
}
-
- final HostEntity host = hostDAO.findById(hostId);
- cluster.transitionHostVersionState(host, repositoryVersion, stackId);
-
- return repositoryVersion;
+ return hostVersionEntity;
}
/**
@@ -1619,4 +1557,20 @@ public class ServiceComponentHostImpl implements ServiceComponentHost {
return hostComponentStateDAO.findById(hostComponentStateId);
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public ServiceComponent getServiceComponent() {
+ return serviceComponent;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public StackId getDesiredStackId() {
+ return serviceComponent.getDesiredStackId();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostSummary.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostSummary.java b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostSummary.java
index bccdb25..e9359ef 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostSummary.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostSummary.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -19,19 +19,19 @@
package org.apache.ambari.server.state.svccomphost;
+import java.util.Collection;
+import java.util.HashSet;
+
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
import org.apache.ambari.server.orm.entities.HostEntity;
-import org.apache.ambari.server.orm.entities.UpgradeEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
import org.apache.ambari.server.state.ComponentInfo;
-import org.apache.ambari.server.state.StackId;
import org.apache.ambari.server.state.State;
import org.apache.ambari.server.state.UpgradeState;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
+import org.apache.commons.lang.StringUtils;
/**
@@ -43,14 +43,28 @@ public class ServiceComponentHostSummary {
private Collection<HostComponentStateEntity> haveAdvertisedVersion;
private Collection<HostComponentStateEntity> waitingToAdvertiseVersion;
private Collection<HostComponentStateEntity> noVersionToAdvertise;
- private Set<String> versions;
- public ServiceComponentHostSummary(AmbariMetaInfo ambariMetaInfo, HostEntity host, String stackName, String stackVersion) throws AmbariException {
+ /**
+ * Constructor.
+ *
+ * @param ambariMetaInfo
+ * used to lookup whether a component advertises a version (not
+ * {@code null}).
+ * @param host
+ * the host to generate a component summary for (not {@code null}).
+ * @param repositoryVersion
+ * the repository to generate a summary for (not {@code null}).
+ * @throws AmbariException
+ */
+ public ServiceComponentHostSummary(AmbariMetaInfo ambariMetaInfo, HostEntity host,
+ RepositoryVersionEntity repositoryVersion) throws AmbariException {
allHostComponents = host.getHostComponentStateEntities();
haveAdvertisedVersion = new HashSet<>();
waitingToAdvertiseVersion = new HashSet<>();
noVersionToAdvertise = new HashSet<>();
- versions = new HashSet<>();
+
+ String stackName = repositoryVersion.getStackName();
+ String stackVersion = repositoryVersion.getStackVersion();
for (HostComponentStateEntity hostComponentStateEntity : allHostComponents) {
ComponentInfo compInfo = ambariMetaInfo.getComponent(
@@ -60,64 +74,50 @@ public class ServiceComponentHostSummary {
if (!compInfo.isVersionAdvertised()) {
// Some Components cannot advertise a version. E.g., ZKF, AMBARI_METRICS, Kerberos
noVersionToAdvertise.add(hostComponentStateEntity);
- } else {
- if (hostComponentStateEntity.getUpgradeState().equals(UpgradeState.IN_PROGRESS) ||
- hostComponentStateEntity.getVersion().equalsIgnoreCase(State.UNKNOWN.toString())) {
- waitingToAdvertiseVersion.add(hostComponentStateEntity);
- } else {
- haveAdvertisedVersion.add(hostComponentStateEntity);
- versions.add(hostComponentStateEntity.getVersion());
- } // TODO: what if component reported wrong version?
+ continue;
}
- }
- }
-
- public ServiceComponentHostSummary(AmbariMetaInfo ambariMetaInfo, HostEntity host, StackId stackId) throws AmbariException {
- this(ambariMetaInfo, host, stackId.getStackName(), stackId.getStackVersion());
- }
-
- public Collection<HostComponentStateEntity> getHaveAdvertisedVersion() {
- return haveAdvertisedVersion;
- }
- public boolean isUpgradeFinished() {
- return haveAllComponentsFinishedAdvertisingVersion() && noComponentVersionMismatches(getHaveAdvertisedVersion());
- }
-
- /**
- * @param upgradeEntity Upgrade info about update on given host
- * @return Return true if multiple component versions are found for this host, or if it does not coincide with the
- * CURRENT repo version.
- */
- public boolean isUpgradeInProgress(UpgradeEntity upgradeEntity) {
- // Exactly one CURRENT version must exist
- // We can only detect an upgrade if the Host has at least one component that advertises a version and has done so already
- // If distinct versions have been advertises, then an upgrade is in progress.
- // If exactly one version has been advertises, but it doesn't coincide with the CURRENT HostVersion, then an upgrade is in progress.
- return upgradeEntity != null;
- }
+ String versionAdvertised = hostComponentStateEntity.getVersion();
+ if (hostComponentStateEntity.getUpgradeState() == UpgradeState.IN_PROGRESS
+ || StringUtils.equals(versionAdvertised, State.UNKNOWN.name())) {
+ waitingToAdvertiseVersion.add(hostComponentStateEntity);
+ continue;
+ }
- /**
- * Determine if all of the components on that need to advertise a version have finished doing so.
- * @return Return a bool indicating if all components that can report a version have done so.
- */
- public boolean haveAllComponentsFinishedAdvertisingVersion() {
- return waitingToAdvertiseVersion.isEmpty();
+ haveAdvertisedVersion.add(hostComponentStateEntity);
+ }
}
/**
- * Checks that every component has really advertised version (in other words, we are not waiting
- * for version advertising), and that no version mismatch occurred
+ * Gets whether all hosts for a service component have reported the correct
+ * version.
*
- * @param hostComponents host components
- * @return true if components have advertised the same version, or collection is empty, false otherwise.
+ * @param repositoryVersion
+ * the version to report (not {@code null}).
+ * @return {@code true} if all hosts for this service component have reported
+ * the correct version, {@code false} othwerise.
*/
- public static boolean noComponentVersionMismatches(Collection<HostComponentStateEntity> hostComponents) {
- for (HostComponentStateEntity hostComponent : hostComponents) {
+ public boolean isVersionCorrectForAllHosts(RepositoryVersionEntity repositoryVersion) {
+ if (!waitingToAdvertiseVersion.isEmpty()) {
+ return false;
+ }
+
+ for (HostComponentStateEntity hostComponent : haveAdvertisedVersion) {
if (UpgradeState.VERSION_NON_ADVERTISED_STATES.contains(hostComponent.getUpgradeState())) {
return false;
}
+
+ ServiceComponentDesiredStateEntity desiredState = hostComponent.getServiceComponentDesiredStateEntity();
+ RepositoryVersionEntity desiredRepositoryVersion = desiredState.getDesiredRepositoryVersion();
+ if (!desiredRepositoryVersion.equals(repositoryVersion)) {
+ continue;
+ }
+
+ if (!StringUtils.equals(hostComponent.getVersion(), desiredRepositoryVersion.getVersion())) {
+ return false;
+ }
}
+
return true;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
index 04f5ec3..e1e4ef6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java
@@ -17,10 +17,6 @@
*/
package org.apache.ambari.server.upgrade;
-import javax.persistence.EntityManager;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
import java.io.File;
import java.io.FileReader;
import java.io.StringReader;
@@ -42,6 +38,10 @@ import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
+import javax.persistence.EntityManager;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
@@ -102,8 +102,6 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
protected DBAccessor dbAccessor;
@Inject
protected Configuration configuration;
- @Inject
- protected StackUpgradeUtil stackUpgradeUtil;
protected Injector injector;
@@ -139,7 +137,7 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
private static final Logger LOG = LoggerFactory.getLogger
(AbstractUpgradeCatalog.class);
private static final Map<String, UpgradeCatalog> upgradeCatalogMap =
- new HashMap<String, UpgradeCatalog>();
+ new HashMap<>();
protected String ambariUpgradeConfigUpdatesFileName;
@@ -374,9 +372,9 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
if (clusterMap != null && !clusterMap.isEmpty()) {
for (Cluster cluster : clusterMap.values()) {
- Map<String, Set<String>> toAddProperties = new HashMap<String, Set<String>>();
- Map<String, Set<String>> toUpdateProperties = new HashMap<String, Set<String>>();
- Map<String, Set<String>> toRemoveProperties = new HashMap<String, Set<String>>();
+ Map<String, Set<String>> toAddProperties = new HashMap<>();
+ Map<String, Set<String>> toUpdateProperties = new HashMap<>();
+ Map<String, Set<String>> toRemoveProperties = new HashMap<>();
Set<PropertyInfo> stackProperties = configHelper.getStackProperties(cluster);
@@ -494,7 +492,7 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
if (clusterMap != null && !clusterMap.isEmpty()) {
for (Cluster cluster : clusterMap.values()) {
- Map<String, String> properties = new HashMap<String, String>();
+ Map<String, String> properties = new HashMap<>();
for(String propertyName:propertyNames) {
String propertyValue = configHelper.getPropertyValueFromStackDefinitions(cluster, configType, propertyName);
@@ -548,7 +546,7 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
"Skipping configuration properties update");
return;
} else if (oldConfig == null) {
- oldConfigProperties = new HashMap<String, String>();
+ oldConfigProperties = new HashMap<>();
} else {
oldConfigProperties = oldConfig.getProperties();
}
@@ -655,7 +653,7 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
Map<String, String> newProperties,
boolean updateIfExists, Multimap<AbstractUpgradeCatalog.ConfigUpdateType, Entry<String, String>> propertiesToLog) {
- Map<String, String> properties = new HashMap<String, String>(originalProperties);
+ Map<String, String> properties = new HashMap<>(originalProperties);
for (Map.Entry<String, String> entry : newProperties.entrySet()) {
if (!properties.containsKey(entry.getKey())) {
properties.put(entry.getKey(), entry.getValue());
@@ -671,12 +669,12 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
private Map<String, String> removeProperties(Map<String, String> originalProperties,
Set<String> removeList, Multimap<AbstractUpgradeCatalog.ConfigUpdateType, Entry<String, String>> propertiesToLog){
- Map<String, String> properties = new HashMap<String, String>();
+ Map<String, String> properties = new HashMap<>();
properties.putAll(originalProperties);
for (String removeProperty: removeList){
if (originalProperties.containsKey(removeProperty)){
properties.remove(removeProperty);
- propertiesToLog.put(ConfigUpdateType.REMOVED, new AbstractMap.SimpleEntry<String, String>(removeProperty, ""));
+ propertiesToLog.put(ConfigUpdateType.REMOVED, new AbstractMap.SimpleEntry<>(removeProperty, ""));
}
}
return properties;
@@ -780,7 +778,7 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog {
ArtifactDAO artifactDAO = injector.getInstance(ArtifactDAO.class);
KerberosDescriptor artifactDescriptor = null;
ArtifactEntity artifactEntity = artifactDAO.findByNameAndForeignKeys("kerberos_descriptor",
- new TreeMap<String, String>(Collections.singletonMap("cluster", String.valueOf(cluster.getClusterId()))));
+ new TreeMap<>(Collections.singletonMap("cluster", String.valueOf(cluster.getClusterId()))));
if (artifactEntity != null) {
Map<String, Object> data = artifactEntity.getArtifactData();
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
index af2a7d1..a1d2b87 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/SchemaUpgradeHelper.java
@@ -39,13 +39,13 @@ import org.apache.ambari.server.utils.EventBusSynchronizer;
import org.apache.ambari.server.utils.VersionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.jdbc.support.JdbcUtils;
import com.google.inject.Guice;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.persist.PersistService;
-import org.springframework.jdbc.support.JdbcUtils;
public class SchemaUpgradeHelper {
private static final Logger LOG = LoggerFactory.getLogger
@@ -178,19 +178,6 @@ public class SchemaUpgradeHelper {
// Add binding to each newly created catalog
Multibinder<UpgradeCatalog> catalogBinder =
Multibinder.newSetBinder(binder(), UpgradeCatalog.class);
- catalogBinder.addBinding().to(UpgradeCatalog200.class);
- catalogBinder.addBinding().to(UpgradeCatalog210.class);
- catalogBinder.addBinding().to(UpgradeCatalog211.class);
- catalogBinder.addBinding().to(UpgradeCatalog212.class);
- catalogBinder.addBinding().to(UpgradeCatalog2121.class);
- catalogBinder.addBinding().to(UpgradeCatalog220.class);
- catalogBinder.addBinding().to(UpgradeCatalog221.class);
- catalogBinder.addBinding().to(UpgradeCatalog222.class);
- catalogBinder.addBinding().to(UpgradeCatalog230.class);
- catalogBinder.addBinding().to(UpgradeCatalog240.class);
- catalogBinder.addBinding().to(UpgradeCatalog2402.class);
- catalogBinder.addBinding().to(UpgradeCatalog242.class);
- catalogBinder.addBinding().to(UpgradeCatalog250.class);
catalogBinder.addBinding().to(UpgradeCatalog251.class);
catalogBinder.addBinding().to(UpgradeCatalog252.class);
catalogBinder.addBinding().to(FinalUpgradeCatalog.class);
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeHelper.java
deleted file mode 100644
index b1c643a..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeHelper.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.upgrade;
-
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.InputMismatchException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.ambari.server.controller.ControllerModule;
-import org.apache.ambari.server.orm.DBAccessor;
-import org.apache.ambari.server.orm.dao.MetainfoDAO;
-import org.apache.ambari.server.orm.entities.MetainfoEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.gson.Gson;
-import com.google.inject.Guice;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
-import com.google.inject.persist.Transactional;
-
-public class StackUpgradeHelper {
- private static final Logger LOG = LoggerFactory.getLogger
- (StackUpgradeHelper.class);
-
- private static final String STACK_ID_UPDATE_ACTION = "updateStackId";
- private static final String METAINFO_UPDATE_ACTION = "updateMetaInfo";
- private static final String STACK_ID_STACK_NAME_KEY = "stackName";
-
- @Inject
- private DBAccessor dbAccessor;
- @Inject
- private PersistService persistService;
- @Inject
- private MetainfoDAO metainfoDAO;
- @Inject
- private StackUpgradeUtil stackUpgradeUtil;
-
- private void startPersistenceService() {
- persistService.start();
- }
-
- private void stopPersistenceService() {
- persistService.stop();
- }
-
- /**
- * Add key value to the metainfo table.
- * @param data
- * @throws SQLException
- */
- @Transactional
- void updateMetaInfo(Map<String, String> data) throws SQLException {
- if (data != null && !data.isEmpty()) {
- for (Map.Entry<String, String> entry : data.entrySet()) {
- MetainfoEntity metainfoEntity = metainfoDAO.findByKey(entry.getKey());
- if (metainfoEntity != null) {
- metainfoEntity.setMetainfoName(entry.getKey());
- metainfoEntity.setMetainfoValue(entry.getValue());
- metainfoDAO.merge(metainfoEntity);
- } else {
- metainfoEntity = new MetainfoEntity();
- metainfoEntity.setMetainfoName(entry.getKey());
- metainfoEntity.setMetainfoValue(entry.getValue());
- metainfoDAO.create(metainfoEntity);
- }
- }
- }
- }
-
- /**
- * Change the stack id in the Ambari DB.
- * @param stackInfo
- * @throws SQLException
- */
- public void updateStackVersion(Map<String, String> stackInfo) throws Exception {
- if (stackInfo == null || stackInfo.isEmpty()) {
- throw new IllegalArgumentException("Empty stack id. " + stackInfo);
- }
-
- String repoUrl = stackInfo.remove("repo_url");
- String repoUrlOs = stackInfo.remove("repo_url_os");
-
- Iterator<Map.Entry<String, String>> stackIdEntry = stackInfo.entrySet().iterator();
- Map.Entry<String, String> stackEntry = stackIdEntry.next();
-
- String stackName = stackEntry.getKey();
- String stackVersion = stackEntry.getValue();
-
- LOG.info("Updating stack id, stackName = " + stackName + ", " +
- "stackVersion = "+ stackVersion);
-
- stackUpgradeUtil.updateStackDetails(stackName, stackVersion);
-
- if (null != repoUrl) {
- stackUpgradeUtil.updateLocalRepo(stackName, stackVersion, repoUrl, repoUrlOs);
- }
-
- dbAccessor.updateTable("hostcomponentstate", "current_state", "INSTALLED", "where current_state = 'UPGRADING'");
- }
-
- private List<String> getValidActions() {
- return new ArrayList<String>() {{
- add(STACK_ID_UPDATE_ACTION);
- add(METAINFO_UPDATE_ACTION);
- }};
- }
-
- /**
- * Support changes need to support upgrade of Stack
- * @param args Simple key value json map
- */
- public static void main(String[] args) {
- try {
- if (args.length < 2) {
- throw new InputMismatchException("Need to provide action, " +
- "stack name and stack version.");
- }
-
- String action = args[0];
- String valueMap = args[1];
-
- Injector injector = Guice.createInjector(new ControllerModule());
- StackUpgradeHelper stackUpgradeHelper = injector.getInstance(StackUpgradeHelper.class);
- Gson gson = injector.getInstance(Gson.class);
-
- if (!stackUpgradeHelper.getValidActions().contains(action)) {
- throw new IllegalArgumentException("Unsupported action. Allowed " +
- "actions: " + stackUpgradeHelper.getValidActions());
- }
-
-
- stackUpgradeHelper.startPersistenceService();
- Map values = gson.fromJson(valueMap, Map.class);
-
- if (action.equals(STACK_ID_UPDATE_ACTION)) {
- stackUpgradeHelper.updateStackVersion(values);
-
- } else if (action.equals(METAINFO_UPDATE_ACTION)) {
-
- stackUpgradeHelper.updateMetaInfo(values);
- }
-
- stackUpgradeHelper.stopPersistenceService();
-
- } catch (Throwable t) {
- LOG.error("Caught exception on upgrade. Exiting...", t);
- System.exit(1);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java
deleted file mode 100644
index 8c629ca..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/StackUpgradeUtil.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.upgrade;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.orm.dao.ClusterDAO;
-import org.apache.ambari.server.orm.dao.ClusterStateDAO;
-import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
-import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
-import org.apache.ambari.server.orm.dao.MetainfoDAO;
-import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
-import org.apache.ambari.server.orm.dao.ServiceDesiredStateDAO;
-import org.apache.ambari.server.orm.dao.StackDAO;
-import org.apache.ambari.server.orm.entities.ClusterEntity;
-import org.apache.ambari.server.orm.entities.ClusterStateEntity;
-import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
-import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
-import org.apache.ambari.server.orm.entities.MetainfoEntity;
-import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
-import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
-import org.apache.ambari.server.orm.entities.StackEntity;
-import org.apache.ambari.server.state.OperatingSystemInfo;
-import org.apache.ambari.server.state.stack.OsFamily;
-
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.persist.Transactional;
-
-public class StackUpgradeUtil {
- @Inject
- private Injector injector;
-
- @Transactional
- public void updateStackDetails(String stackName, String stackVersion) {
- ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
- StackDAO stackDAO = injector.getInstance(StackDAO.class);
- List<Long> clusterIds = new ArrayList<Long>();
-
- StackEntity stackEntity = stackDAO.find(stackName, stackVersion);
-
- List<ClusterEntity> clusterEntities = clusterDAO.findAll();
- if (clusterEntities != null && !clusterEntities.isEmpty()) {
- for (ClusterEntity entity : clusterEntities) {
- clusterIds.add(entity.getClusterId());
- entity.setDesiredStack(stackEntity);
- clusterDAO.merge(entity);
- }
- }
-
- ClusterStateDAO clusterStateDAO = injector.getInstance(ClusterStateDAO.class);
-
- for (Long clusterId : clusterIds) {
- ClusterStateEntity clusterStateEntity = clusterStateDAO.findByPK(clusterId);
- clusterStateEntity.setCurrentStack(stackEntity);
- clusterStateDAO.merge(clusterStateEntity);
- }
-
- HostComponentStateDAO hostComponentStateDAO = injector.getInstance
- (HostComponentStateDAO.class);
- List<HostComponentStateEntity> hcEntities = hostComponentStateDAO.findAll();
-
- if (hcEntities != null) {
- for (HostComponentStateEntity hc : hcEntities) {
- hc.setCurrentStack(stackEntity);
- hostComponentStateDAO.merge(hc);
- }
- }
-
- HostComponentDesiredStateDAO hostComponentDesiredStateDAO =
- injector.getInstance(HostComponentDesiredStateDAO.class);
-
- List<HostComponentDesiredStateEntity> hcdEntities = hostComponentDesiredStateDAO.findAll();
-
- if (hcdEntities != null) {
- for (HostComponentDesiredStateEntity hcd : hcdEntities) {
- hcd.setDesiredStack(stackEntity);
- hostComponentDesiredStateDAO.merge(hcd);
- }
- }
-
- ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO =
- injector.getInstance(ServiceComponentDesiredStateDAO.class);
-
- List<ServiceComponentDesiredStateEntity> scdEntities =
- serviceComponentDesiredStateDAO.findAll();
-
- if (scdEntities != null) {
- for (ServiceComponentDesiredStateEntity scd : scdEntities) {
- scd.setDesiredStack(stackEntity);
- serviceComponentDesiredStateDAO.merge(scd);
- }
- }
-
- ServiceDesiredStateDAO serviceDesiredStateDAO = injector.getInstance(ServiceDesiredStateDAO.class);
-
- List<ServiceDesiredStateEntity> sdEntities = serviceDesiredStateDAO.findAll();
-
- if (sdEntities != null) {
- for (ServiceDesiredStateEntity sd : sdEntities) {
- sd.setDesiredStack(stackEntity);
- serviceDesiredStateDAO.merge(sd);
- }
- }
- }
-
- /**
- * @param stackName
- * @param stackVersion
- * @param repoUrl
- * @param repoUrlOs
- * @throws Exception
- */
- public void updateLocalRepo(String stackName, String stackVersion,
- String repoUrl, String repoUrlOs) throws Exception {
-
- if (null == repoUrl ||
- repoUrl.isEmpty() ||
- !repoUrl.startsWith("http")) {
- return;
- }
-
- String[] oses = new String[0];
-
- if (null != repoUrlOs) {
- oses = repoUrlOs.split(",");
- }
-
- AmbariMetaInfo ami = injector.getInstance(AmbariMetaInfo.class);
- MetainfoDAO metaDao = injector.getInstance(MetainfoDAO.class);
- OsFamily os_family = injector.getInstance(OsFamily.class);
-
- String stackRepoId = stackName + "-" + stackVersion;
-
- if (0 == oses.length) {
- // do them all
- for (OperatingSystemInfo osi : ami.getOperatingSystems(stackName, stackVersion)) {
- ami.updateRepoBaseURL(stackName, stackVersion, osi.getOsType(),
- stackRepoId, repoUrl);
- }
-
- } else {
- for (String os : oses) {
-
- String family = os_family.find(os);
- if (null != family) {
- String key = ami.generateRepoMetaKey(stackName, stackVersion, os,
- stackRepoId, AmbariMetaInfo.REPOSITORY_XML_PROPERTY_BASEURL);
-
- String familyKey = ami.generateRepoMetaKey(stackName, stackVersion, family,
- stackRepoId, AmbariMetaInfo.REPOSITORY_XML_PROPERTY_BASEURL);
-
- // need to use (for example) redhat6 if the os is centos6
- MetainfoEntity entity = metaDao.findByKey(key);
- if (null == entity) {
- entity = new MetainfoEntity();
- entity.setMetainfoName(key);
- entity.setMetainfoValue(repoUrl);
- metaDao.merge(entity);
- } else {
- entity.setMetainfoValue(repoUrl);
- metaDao.merge(entity);
- }
-
- entity = metaDao.findByKey(familyKey);
- if (null == entity) {
- entity = new MetainfoEntity();
- entity.setMetainfoName(familyKey);
- entity.setMetainfoValue(repoUrl);
- metaDao.merge(entity);
- } else {
- entity.setMetainfoValue(repoUrl);
- metaDao.merge(entity);
- }
- }
- }
- }
- }
-
-}
\ No newline at end of file