Repository: ambari Updated Branches: refs/heads/trunk 4ae9bb9c8 -> f6248ae5f
Revert "AMBARI-8618. Distribute repositories action: Add command report parsing (INSTALLING->INSTALLED) transition (Dmitry Lisnichenko via ncole)" Causing Host Check to hang. This reverts commit 89dc6c1c5bfe06eac6bd188a53103bc766218f81. Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f6248ae5 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f6248ae5 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f6248ae5 Branch: refs/heads/trunk Commit: f6248ae5f65ff403311262eb5e51631b9f5081c0 Parents: 4ae9bb9 Author: Yusaku Sako <[email protected]> Authored: Wed Dec 10 15:19:24 2014 -0800 Committer: Yusaku Sako <[email protected]> Committed: Wed Dec 10 15:19:56 2014 -0800 ---------------------------------------------------------------------- .../org/apache/ambari/server/RoleCommand.java | 8 - .../server/actionmanager/ActionManager.java | 8 +- .../server/actionmanager/ActionScheduler.java | 29 +-- .../ambari/server/agent/HeartBeatHandler.java | 22 +-- .../DistributeRepositoriesStructuredOutput.java | 61 ------- .../ClusterStackVersionResourceProvider.java | 31 ++-- .../HostStackVersionResourceProvider.java | 32 ++-- .../events/ActionFinalReportReceivedEvent.java | 78 -------- .../ambari/server/events/AmbariEvent.java | 7 +- .../DistributeRepositoriesActionListener.java | 178 ------------------- .../server/orm/dao/ClusterVersionDAO.java | 8 +- .../org/apache/ambari/server/state/Cluster.java | 22 +-- .../server/state/RepositoryVersionState.java | 17 +- .../server/state/cluster/ClusterImpl.java | 121 ++----------- .../actionmanager/TestActionDBAccessorImpl.java | 2 +- .../server/actionmanager/TestActionManager.java | 6 +- .../actionmanager/TestActionScheduler.java | 57 +++--- .../server/agent/TestHeartbeatHandler.java | 12 +- ...ClusterStackVersionResourceProviderTest.java | 3 +- .../HostStackVersionResourceProviderTest.java | 7 +- .../test/python/custom_actions/TestCheckHost.py | 102 +++++------ 21 files changed, 158 insertions(+), 653 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java b/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java index 5607c60..b98c50c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/RoleCommand.java @@ -33,14 +33,6 @@ public enum RoleCommand { ABORT, UPGRADE, SERVICE_CHECK, - - /** - * Represents any custom command - */ CUSTOM_COMMAND, - - /** - * Represents any action - */ ACTIONEXECUTE } http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java index c8ed235..6d1d87f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java @@ -19,16 +19,15 @@ package org.apache.ambari.server.actionmanager; import com.google.inject.Inject; import com.google.inject.Singleton; -import com.google.inject.assistedinject.Assisted; import com.google.inject.name.Named; import com.google.inject.persist.UnitOfWork; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.agent.ActionQueue; import org.apache.ambari.server.agent.CommandReport; +import org.apache.ambari.server.api.services.BaseRequest; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.ExecuteActionRequest; import org.apache.ambari.server.controller.HostsMap; -import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.utils.StageUtils; import org.slf4j.Logger; @@ -61,12 +60,11 @@ public class ActionManager { @Named("actionTimeout") long actionTimeout, ActionQueue aq, Clusters fsm, ActionDBAccessor db, HostsMap hostsMap, UnitOfWork unitOfWork, - RequestFactory requestFactory, Configuration configuration, - AmbariEventPublisher ambariEventPublisher) { + RequestFactory requestFactory, Configuration configuration) { this.actionQueue = aq; this.db = db; scheduler = new ActionScheduler(schedulerSleepTime, actionTimeout, db, - actionQueue, fsm, 2, hostsMap, unitOfWork, ambariEventPublisher, configuration); + actionQueue, fsm, 2, hostsMap, unitOfWork, configuration); requestCounter = new AtomicLong( db.getLastPersistedRequestIdWhenInitialized()); this.requestFactory = requestFactory; http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java index 17e492c..b3dcca4 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java @@ -43,8 +43,6 @@ import org.apache.ambari.server.agent.CommandReport; import org.apache.ambari.server.agent.ExecutionCommand; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.HostsMap; -import org.apache.ambari.server.events.ActionFinalReportReceivedEvent; -import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.ambari.server.serveraction.ServerActionExecutor; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; @@ -69,6 +67,7 @@ import com.google.common.reflect.TypeToken; import com.google.inject.persist.UnitOfWork; + /** * This class encapsulates the action scheduler thread. * Action schedule frequently looks at action database and determines if @@ -90,7 +89,6 @@ class ActionScheduler implements Runnable { private final short maxAttempts; private final ActionQueue actionQueue; private final Clusters fsmObject; - private final AmbariEventPublisher ambariEventPublisher; private boolean taskTimeoutAdjustment = true; private final HostsMap hostsMap; private final Object wakeupSyncObject = new Object(); @@ -126,17 +124,15 @@ class ActionScheduler implements Runnable { private Cache<String, Map<String, String>> hostParamsStageCache; public ActionScheduler(long sleepTimeMilliSec, long actionTimeoutMilliSec, - ActionDBAccessor db, ActionQueue actionQueue, Clusters fsmObject, - int maxAttempts, HostsMap hostsMap, - UnitOfWork unitOfWork, AmbariEventPublisher ambariEventPublisher, - Configuration configuration) { + ActionDBAccessor db, ActionQueue actionQueue, Clusters fsmObject, + int maxAttempts, HostsMap hostsMap, + UnitOfWork unitOfWork, Configuration configuration) { this.sleepTime = sleepTimeMilliSec; this.hostsMap = hostsMap; this.actionTimeout = actionTimeoutMilliSec; this.db = db; this.actionQueue = actionQueue; this.fsmObject = fsmObject; - this.ambariEventPublisher = ambariEventPublisher; this.maxAttempts = (short) maxAttempts; this.serverActionExecutor = new ServerActionExecutor(db, sleepTimeMilliSec); this.unitOfWork = unitOfWork; @@ -845,23 +841,6 @@ class ActionScheduler implements Runnable { cancelCommand.setReason(reason); actionQueue.enqueue(hostRoleCommand.getHostName(), cancelCommand); } - // If host role is an Action, we have to send an event - if (hostRoleCommand.getRoleCommand().equals(RoleCommand.ACTIONEXECUTE)) { - String clusterName = hostRoleCommand.getExecutionCommandWrapper().getExecutionCommand().getClusterName(); - try { - // Usually clusterId is defined (except the awkward case when - // "Distribute repositories/install packages" action has been issued - // against a concrete host without binding to a cluster) - Long clusterId = clusterName != null ? - fsmObject.getCluster(clusterName).getClusterId() : null; - ActionFinalReportReceivedEvent event = new ActionFinalReportReceivedEvent( - clusterId, hostRoleCommand.getHostName(), null, - hostRoleCommand.getRole().toString()); - ambariEventPublisher.publish(event); - } catch (AmbariException e) { - LOG.error(String.format("Can not get cluster %s", clusterName), e); - } - } } } http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java index 91713ad..d482109 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java @@ -39,11 +39,9 @@ import org.apache.ambari.server.actionmanager.HostRoleStatus; import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.MaintenanceStateHelper; -import org.apache.ambari.server.events.ActionFinalReportReceivedEvent; import org.apache.ambari.server.events.AlertEvent; import org.apache.ambari.server.events.AlertReceivedEvent; import org.apache.ambari.server.events.publishers.AlertEventPublisher; -import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.ambari.server.metadata.ActionMetadata; import org.apache.ambari.server.state.AgentVersion; import org.apache.ambari.server.state.Alert; @@ -126,9 +124,6 @@ public class HeartBeatHandler { @Inject private AlertEventPublisher alertEventPublisher; - @Inject - private AmbariEventPublisher ambariEventPublisher; - private Map<String, Long> hostResponseIds = new ConcurrentHashMap<String, Long>(); private Map<String, HeartBeatResponse> hostResponses = new ConcurrentHashMap<String, HeartBeatResponse>(); @@ -362,7 +357,7 @@ public class HeartBeatHandler { host.persist(); } - //If host doesn't belong to any cluster + //If host doesn't belongs to any cluster if ((clusterFsm.getClustersForHost(host.getHostName())).size() == 0) { healthStatus = HealthStatus.HEALTHY; host.setStatus(healthStatus.name()); @@ -385,22 +380,9 @@ public class HeartBeatHandler { Iterator<HostRoleCommand> hostRoleCommandIterator = commands.iterator(); for (CommandReport report : reports) { - - Long clusterId = report.getClusterName() != null ? - clusterFsm.getCluster(report.getClusterName()).getClusterId() : null; - LOG.debug("Received command report: " + report); // Fetch HostRoleCommand that corresponds to a given task ID HostRoleCommand hostRoleCommand = hostRoleCommandIterator.next(); - - // Send event for final command reports for actions - if (RoleCommand.valueOf(report.getRoleCommand()) == RoleCommand.ACTIONEXECUTE && - HostRoleStatus.valueOf(report.getStatus()).isCompletedState()) { - ActionFinalReportReceivedEvent event = new ActionFinalReportReceivedEvent( - clusterId, hostname, report, report.getRole()); - ambariEventPublisher.publish(event); - } - // Skip sending events for command reports for ABORTed commands if (hostRoleCommand.getStatus() == HostRoleStatus.ABORTED) { continue; @@ -432,7 +414,7 @@ public class HeartBeatHandler { ServiceComponentHost scHost = svcComp.getServiceComponentHost(hostname); String schName = scHost.getServiceComponentName(); - if (report.getStatus().equals(HostRoleStatus.COMPLETED.toString())) { + if (report.getStatus().equals("COMPLETED")) { // Updating stack version, if needed if (scHost.getState().equals(State.UPGRADING)) { scHost.setStackVersion(scHost.getDesiredStackVersion()); http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/DistributeRepositoriesStructuredOutput.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/DistributeRepositoriesStructuredOutput.java b/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/DistributeRepositoriesStructuredOutput.java deleted file mode 100644 index be7e602..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/bootstrap/DistributeRepositoriesStructuredOutput.java +++ /dev/null @@ -1,61 +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.bootstrap; - -import com.google.gson.annotations.SerializedName; - -import java.util.List; - -/** - * This class is used for mapping json of structured output for - * "Distribute repositories/install packages" action. - */ -public class DistributeRepositoriesStructuredOutput { - - /** - * Repository version that has been (re)installed as a result of current custom action - */ - @SerializedName("installed_repository_version") - private String installedRepositoryVersion; - - /** - * All Ambari-managed repositories that are installed side by side on host - */ - @SerializedName("ambari_repositories") - private List<String> ambariRepositories; - - /** - * Either SUCCESS or FAIL - */ - @SerializedName("package_installation_result") - private String packageInstallationResult; - - public String getInstalledRepositoryVersion() { - return installedRepositoryVersion; - } - - public List<String> getAmbariRepositories() { - return ambariRepositories; - } - - public String getPackageInstallationResult() { - return packageInstallationResult; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java index 7c533b6..9b7c3c9 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java @@ -226,23 +226,15 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou if (request.getProperties().size() != 1) { throw new UnsupportedOperationException("Multiple requests cannot be executed at the same time."); } - Map<String, Object> propertyMap = iterator.next(); - - Set<String> requiredProperties = new HashSet<String>(){{ - add(CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID); - add(CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID); - add(CLUSTER_STACK_VERSION_STACK_PROPERTY_ID); - add(CLUSTER_STACK_VERSION_VERSION_PROPERTY_ID); - }}; - for (String requiredProperty : requiredProperties) { - if (! propertyMap.containsKey(requiredProperty)) { - throw new IllegalArgumentException( - String.format("The required property %s is not defined", - requiredProperty)); - } + Map<String, Object> propertyMap = iterator.next(); + if (!propertyMap.containsKey(CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID) || + !propertyMap.containsKey(CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID)) { + throw new IllegalArgumentException( + String.format("%s or %s not defined", + CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID, + CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID)); } - clName = (String) propertyMap.get(CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID); desiredRepoVersion = (String) propertyMap.get(CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID); @@ -368,8 +360,9 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou ClusterVersionEntity existingCSVer = clusterVersionDAO.findByClusterAndStackAndVersion(clName, stackId, desiredRepoVersion); if (existingCSVer == null) { try { // Create/persist new cluster stack version - cluster.createClusterVersion(stackId, desiredRepoVersion, managementController.getAuthName(), RepositoryVersionState.INSTALLING); - existingCSVer = clusterVersionDAO.findByClusterAndStackAndVersion(clName, stackId, desiredRepoVersion); + cluster.createClusterVersion(stackId, desiredRepoVersion, managementController.getAuthName(), RepositoryVersionState.INSTALLED); + ClusterVersionEntity newCSVer = clusterVersionDAO.findByClusterAndStackAndVersion(clName, stackId, desiredRepoVersion); + cluster.initHostVersions(newCSVer); } catch (AmbariException e) { throw new SystemException( String.format( @@ -377,11 +370,7 @@ public class ClusterStackVersionResourceProvider extends AbstractControllerResou desiredRepoVersion, clName), e); } - } else { - // Move CSV into INSTALLING state (retry installation) - cluster.transitionClusterVersion(stackId, desiredRepoVersion, RepositoryVersionState.INSTALLING); } - cluster.inferHostVersions(existingCSVer); req.persist(); http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java index 4850c33..2886266 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProvider.java @@ -81,7 +81,10 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource protected static final String HOST_STACK_VERSION_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("HostStackVersions", "version"); protected static final String HOST_STACK_VERSION_STATE_PROPERTY_ID = PropertyHelper.getPropertyId("HostStackVersions", "state"); protected static final String HOST_STACK_VERSION_REPOSITORIES_PROPERTY_ID = PropertyHelper.getPropertyId("HostStackVersions", "repositories"); - protected static final String HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("HostStackVersions", "repository_version"); + + protected static final String STACK_VERSION_REPO_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("StackVersion", "repository_version"); + protected static final String STACK_VERSION_STACK_PROPERTY_ID = PropertyHelper.getPropertyId("StackVersion", "stack"); + protected static final String STACK_VERSION_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("StackVersion", "version"); protected static final String INSTALL_PACKAGES_ACTION = "install_packages"; protected static final String INSTALL_PACKAGES_FULL_NAME = "Distribute repositories/install packages"; @@ -95,7 +98,9 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource add(HOST_STACK_VERSION_ID_PROPERTY_ID); add(HOST_STACK_VERSION_STACK_PROPERTY_ID); add(HOST_STACK_VERSION_VERSION_PROPERTY_ID); - add(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); + add(STACK_VERSION_REPO_VERSION_PROPERTY_ID); + add(STACK_VERSION_STACK_PROPERTY_ID); + add(STACK_VERSION_VERSION_PROPERTY_ID); } }; @@ -109,7 +114,9 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource add(HOST_STACK_VERSION_VERSION_PROPERTY_ID); add(HOST_STACK_VERSION_STATE_PROPERTY_ID); add(HOST_STACK_VERSION_REPOSITORIES_PROPERTY_ID); - add(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); + add(STACK_VERSION_REPO_VERSION_PROPERTY_ID); + add(STACK_VERSION_STACK_PROPERTY_ID); + add(STACK_VERSION_VERSION_PROPERTY_ID); } }; @@ -121,7 +128,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource put(Type.HostStackVersion, HOST_STACK_VERSION_ID_PROPERTY_ID); put(Type.Stack, HOST_STACK_VERSION_STACK_PROPERTY_ID); put(Type.StackVersion, HOST_STACK_VERSION_VERSION_PROPERTY_ID); - put(Type.RepositoryVersion, HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); + put(Type.RepositoryVersion, STACK_VERSION_REPO_VERSION_PROPERTY_ID); } }; @@ -214,7 +221,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource if (repoVerEntity!=null) { Long repoVersionId = repoVerEntity.getId(); - setResourceProperty(resource, HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID, repoVersionId, requestedIds); + setResourceProperty(resource, STACK_VERSION_REPO_VERSION_PROPERTY_ID, repoVersionId, requestedIds); } resources.add(resource); @@ -239,9 +246,9 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource Set<String> requiredProperties = new HashSet<String>(){{ add(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID); - add(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); - add(HOST_STACK_VERSION_STACK_PROPERTY_ID); - add(HOST_STACK_VERSION_VERSION_PROPERTY_ID); + add(STACK_VERSION_REPO_VERSION_PROPERTY_ID); + add(STACK_VERSION_STACK_PROPERTY_ID); + add(STACK_VERSION_VERSION_PROPERTY_ID); }}; for (String requiredProperty : requiredProperties) { @@ -253,7 +260,7 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource } String clName = (String) propertyMap.get(HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID); hostName = (String) propertyMap.get(HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID); - desiredRepoVersion = (String) propertyMap.get(HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID); + desiredRepoVersion = (String) propertyMap.get(STACK_VERSION_REPO_VERSION_PROPERTY_ID); Host host; try { @@ -265,8 +272,8 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource AmbariManagementController managementController = getManagementController(); AmbariMetaInfo ami = managementController.getAmbariMetaInfo(); - stackName = (String) propertyMap.get(HOST_STACK_VERSION_STACK_PROPERTY_ID); - stackVersion = (String) propertyMap.get(HOST_STACK_VERSION_VERSION_PROPERTY_ID); + stackName = (String) propertyMap.get(STACK_VERSION_STACK_PROPERTY_ID); + stackVersion = (String) propertyMap.get(STACK_VERSION_VERSION_PROPERTY_ID); String stackId = new StackId(stackName, stackVersion).getStackId(); if (!ami.isSupportedStack(stackName, stackVersion)) { throw new NoSuchParentResourceException(String.format("Stack %s is not supported", @@ -400,6 +407,9 @@ public class HostStackVersionResourceProvider extends AbstractControllerResource try { req.persist(); + + //TODO: create cluster version entity + //clusterVersionDAO.create(); } catch (AmbariException e) { throw new SystemException("Can not persist request", e); } http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/events/ActionFinalReportReceivedEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/ActionFinalReportReceivedEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/ActionFinalReportReceivedEvent.java deleted file mode 100644 index 3ff5031..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/events/ActionFinalReportReceivedEvent.java +++ /dev/null @@ -1,78 +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.events; - -import org.apache.ambari.server.actionmanager.HostRoleCommand; -import org.apache.ambari.server.agent.CommandReport; - -/** - * The {@link ActionFinalReportReceivedEvent} is fired when a - * command report action is received. Event is fired only if command state - * is COMPLETED/FAILED/ABORTED. - */ -public final class ActionFinalReportReceivedEvent extends AmbariEvent { - - private Long clusterId; - private String hostname; - private CommandReport commandReport; - private String role; - - /** - * Constructor. - * - * @param clusterId (beware, may be null if action is not bound to cluster) - * @param hostname host that is an origin for a command report - * @param report full command report (may be null if action has been cancelled) - * @param role host command role. It is usually present at report entity, but - * if report is null, we still need some way to determine action type. - */ - public ActionFinalReportReceivedEvent(Long clusterId, String hostname, - CommandReport report, String role) { - super(AmbariEventType.ACTION_EXECUTION_FINISHED); - this.clusterId = clusterId; - this.hostname = hostname; - this.commandReport = report; - this.role = role; - } - - public Long getClusterId() { - return clusterId; - } - - public String getHostname() { - return hostname; - } - - public CommandReport getCommandReport() { - return commandReport; - } - - public String getRole() { - return role; - } - - @Override - public String toString() { - return "ActionFinalReportReceivedEvent{" + - "clusterId=" + clusterId + - ", hostname='" + hostname + '\'' + - ", commandReportStatus=" + commandReport.getStatus() + - ", commandReportRole=" + role + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java index 04217f1..e708473 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/events/AmbariEvent.java @@ -85,12 +85,7 @@ public abstract class AmbariEvent { /** * A host/service/component has had a maintenance mode change. */ - MAINTENANCE_MODE, - - /** - * Received a final command report for some action - */ - ACTION_EXECUTION_FINISHED + MAINTENANCE_MODE; } /** http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java deleted file mode 100644 index 428a0d2..0000000 --- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/DistributeRepositoriesActionListener.java +++ /dev/null @@ -1,178 +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.events.listeners.upgrade; - -import com.google.common.eventbus.AllowConcurrentEvents; -import com.google.common.eventbus.Subscribe; -import com.google.gson.JsonSyntaxException; -import com.google.inject.Inject; -import com.google.inject.Provider; -import com.google.inject.Singleton; -import org.apache.ambari.server.AmbariException; -import org.apache.ambari.server.EagerSingleton; -import org.apache.ambari.server.actionmanager.HostRoleStatus; -import org.apache.ambari.server.bootstrap.DistributeRepositoriesStructuredOutput; -import org.apache.ambari.server.controller.RootServiceResponseFactory.Services; -import org.apache.ambari.server.events.ActionFinalReportReceivedEvent; -import org.apache.ambari.server.events.AlertReceivedEvent; -import org.apache.ambari.server.events.AlertStateChangeEvent; -import org.apache.ambari.server.events.publishers.AlertEventPublisher; -import org.apache.ambari.server.events.publishers.AmbariEventPublisher; -import org.apache.ambari.server.orm.dao.AlertDefinitionDAO; -import org.apache.ambari.server.orm.dao.AlertsDAO; -import org.apache.ambari.server.orm.dao.ClusterVersionDAO; -import org.apache.ambari.server.orm.dao.HostVersionDAO; -import org.apache.ambari.server.orm.entities.AlertCurrentEntity; -import org.apache.ambari.server.orm.entities.AlertDefinitionEntity; -import org.apache.ambari.server.orm.entities.AlertHistoryEntity; -import org.apache.ambari.server.orm.entities.HostVersionEntity; -import org.apache.ambari.server.state.Alert; -import org.apache.ambari.server.state.AlertState; -import org.apache.ambari.server.state.Cluster; -import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.Host; -import org.apache.ambari.server.state.MaintenanceState; -import org.apache.ambari.server.state.RepositoryVersionState; -import org.apache.ambari.server.state.Service; -import org.apache.ambari.server.state.ServiceComponentHost; -import org.apache.ambari.server.utils.StageUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * The {@link org.apache.ambari.server.events.listeners.upgrade.DistributeRepositoriesActionListener} class - * handles {@link org.apache.ambari.server.events.ActionFinalReportReceivedEvent} - * for "Distribute repositories/install packages" action. - * It processes command reports and and updates host stack version state acordingly. - */ -@Singleton -@EagerSingleton -public class DistributeRepositoriesActionListener { - /** - * Logger. - */ - private static final Logger LOG = LoggerFactory.getLogger(DistributeRepositoriesActionListener.class); - public static final String INSTALL_PACKAGES = "install_packages"; - - @Inject - private Provider<HostVersionDAO> hostVersionDAO; - - @Inject - private Provider<Clusters> clusters; - - @Inject - private Provider<ClusterVersionDAO> clusterVersionDAO; - - private AmbariEventPublisher publisher; - - - /** - * Constructor. - * - * @param publisher - */ - @Inject - public DistributeRepositoriesActionListener(AmbariEventPublisher publisher) { - this.publisher = publisher; - publisher.register(this); - } - - @Subscribe - // @AllowConcurrentEvents //TODO: is it thread safe? - public void onActionFinished(ActionFinalReportReceivedEvent event) { - // Check if it is "Distribute repositories/install packages" action. - if (! event.getRole().equals(INSTALL_PACKAGES)) { - return; - } - - if (LOG.isDebugEnabled()) { - LOG.debug(event.toString()); - } - - RepositoryVersionState newHostState; - - String repositoryVersion = null; - Long clusterId = event.getClusterId(); - - if (event.getCommandReport() == null) { - // Something has gone wrong on host - // That's why we mark all host stack versions that are at - // INSTALLING state as failed - // This decision should not be a problem because there should not be more - // then 1 concurrent host stack version installation - LOG.warn("Command report is null, marking action as INSTALL_FAILED"); - newHostState = RepositoryVersionState.INSTALL_FAILED; - } else { - // Parse structured output - try { - DistributeRepositoriesStructuredOutput structuredOutput = StageUtils.getGson().fromJson( - event.getCommandReport().getStructuredOut(), - DistributeRepositoriesStructuredOutput.class); - if (event.getCommandReport().getStatus().equals(HostRoleStatus.COMPLETED.toString())) { - newHostState = RepositoryVersionState.INSTALLED; - } else { - newHostState = RepositoryVersionState.INSTALL_FAILED; - } - repositoryVersion = structuredOutput.getInstalledRepositoryVersion(); - } catch (JsonSyntaxException e) { - LOG.error("Can not parse structured output %s", e); - newHostState = RepositoryVersionState.INSTALL_FAILED; - } - } - List<HostVersionEntity> hostVersions = hostVersionDAO.get().findByHost(event.getHostname()); - for (HostVersionEntity hostVersion : hostVersions) { - if (repositoryVersion != null && ! hostVersion.getVersion().equals(repositoryVersion)) { - // Are we going to update state of a concrete host stack version? - continue; - } - // Typically, there will be single execution of code below - if (hostVersion.getState() == RepositoryVersionState.INSTALLING) { - hostVersion.setState(newHostState); - - if (clusterId != null) { // Update state of a cluster stack version - try { - Cluster cluster = clusters.get().getClusterById(clusterId); - cluster.recalculateClusterVersionState(hostVersion.getVersion()); - } catch (AmbariException e) { - LOG.error("Can not get cluster with Id " + clusterId, e); - } - } else { - LOG.warn("Can not determine cluster for stack version state update"); - // Recalculate state of all clusters to ensure consistency - try { - Set<Cluster> clustersForHost = clusters.get().getClustersForHost(event.getHostname()); - for (Cluster cluster : clustersForHost) { - cluster.recalculateClusterVersionState(hostVersion.getVersion()); - } - } catch (AmbariException e) { - LOG.error("Can not update state of clusters", e); - } - } - } else { - LOG.error( - String.format("Can not transition host stack version state from %s to %s for" + - "host %s", - hostVersion.getState(), newHostState, event.getHostname())); - } - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterVersionDAO.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterVersionDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterVersionDAO.java index b7e0d1c..1ce4a73 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterVersionDAO.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterVersionDAO.java @@ -47,8 +47,8 @@ public class ClusterVersionDAO extends CrudDAO<ClusterVersionEntity, Long>{ /** * Retrieve all of the cluster versions for the given stack and version. * - * @param stack Stack id (e.g., HDP-2.2) - * @param version Repository version (e.g., 2.2.0.1-995) + * @param stack Stack name (e.g., HDP) + * @param version Stack version (e.g., 2.2.0.1-995) * @return Return a list of cluster versions that match the stack and version. */ @RequiresSession @@ -64,8 +64,8 @@ public class ClusterVersionDAO extends CrudDAO<ClusterVersionEntity, Long>{ * Get the cluster version for the given cluster name, stack name, and stack version. * * @param clusterName Cluster name - * @param stack Stack id (e.g., HDP-2.2) - * @param version Repository version (e.g., 2.2.0.1-995) + * @param stack Stack name (e.g., HDP) + * @param version Stack version (e.g., 2.2.0.1-995) * @return Return all of the cluster versions associated with the given cluster. */ @RequiresSession http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java index 0cc6a24..3308f83 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java @@ -121,33 +121,19 @@ public interface Cluster { public void setCurrentStackVersion(StackId stackVersion) throws AmbariException; /** - * Create host versions for all of the hosts that don't already have the stack version. + * Create host versions for all of the hosts with the applied desired state using the cluster's current stack version. * @param hostNames Collection of host names - * @param currentClusterVersion Entity that contains the cluster's current stack (with its name and version) * @param desiredState Desired state must be {@link RepositoryVersionState#CURRENT} or {@link RepositoryVersionState#UPGRADING} * @throws AmbariException */ public void mapHostVersions(Set<String> hostNames, ClusterVersionEntity currentClusterVersion, RepositoryVersionState desiredState) throws AmbariException; /** - * Create/update host versions for all of the hosts within a cluster based on state of cluster stack version. - * The difference of this method compared to {@link Cluster#mapHostVersions} - * is that it affects all hosts (not only missing hosts). Also, current method contains some additional logics to allow only INSTALLING - * state for hosts. - * @param sourceClusterVersion cluster version to be queried for a stack name/version info and desired RepositoryVersionState. The only valid state - * of a cluster version is {@link RepositoryVersionState#INSTALLING} + * Create host versions for all of the hosts within a cluster with the INSTALLED state. + * @param currentClusterVersion cluster version to be queried for a stack name/version info * @throws AmbariException */ - public void inferHostVersions(ClusterVersionEntity sourceClusterVersion) throws AmbariException; - - /** - * Update state of a cluster stack version for cluster based on states of host versions. - * May be called multiple times. - * As of now, only transition from INSTALLING to INSTALLING/INSTALLED/INSTALL_FAILED - * is supported - * @throws AmbariException - */ - void recalculateClusterVersionState(String repositoryVersion) throws AmbariException; + public void initHostVersions(ClusterVersionEntity currentClusterVersion) throws AmbariException; /** * Create a cluster version for the given stack and version, whose initial state must either http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryVersionState.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryVersionState.java b/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryVersionState.java index 453864c..1f14ece 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryVersionState.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/RepositoryVersionState.java @@ -29,24 +29,11 @@ package org.apache.ambari.server.state; * Step 1: Initial Configuration * Version 1 is CURRENT * - * Step 2: Add another repository and trigger distributing repositories/installing packages - * Version 1: CURRENT - * Version 2: INSTALLING - * - * Step 3: distributing repositories/installing packages action finishes successfully or fails - * Version 1: CURRENT - * Version 2: INSTALLED - * - * or - * - * Version 1: CURRENT - * Version 2: INSTALL_FAILED (a retry can set this back to INSTALLING) - * - * Step 4: Start an upgrade from Version 1 to Version 2 + * Step 2: Add another repository and start an upgrade from Version 1 to Version 2 * Version 1: CURRENT * Version 2: UPGRADING * - * Step 5: Upgrade can either complete successfully or fail + * Step 3: Upgrade can either complete successfully or fail * Version 1: CURRENT * Version 2: UPGRADE_FAILED (a retry can set this back to UPGRADING) * http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java index 9848069..a8abd71 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java @@ -81,7 +81,6 @@ import org.apache.ambari.server.state.Alert; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.ClusterHealthReport; import org.apache.ambari.server.state.Clusters; -import org.apache.ambari.server.state.HostState; import org.apache.ambari.server.state.RepositoryVersionState; import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigFactory; @@ -1120,6 +1119,13 @@ public class ClusterImpl implements Cluster { return clusterVersionDAO.findByCluster(this.getClusterName()); } + /** + * Create host versions for all of the hosts that don't already have the stack version. + * @param hostNames Collection of host names + * @param currentClusterVersion Entity that contains the cluster's current stack (with its name and version) + * @param desiredState Desired state must be {@link RepositoryVersionState#CURRENT} or {@link RepositoryVersionState#UPGRADING} + * @throws AmbariException + */ @Override public void mapHostVersions(Set<String> hostNames, ClusterVersionEntity currentClusterVersion, RepositoryVersionState desiredState) throws AmbariException { if (currentClusterVersion == null) { @@ -1168,111 +1174,23 @@ public class ClusterImpl implements Cluster { } @Override - public void inferHostVersions(ClusterVersionEntity sourceClusterVersion) throws AmbariException { - if (sourceClusterVersion == null) { + public void initHostVersions(ClusterVersionEntity currentClusterVersion) throws AmbariException { + if (currentClusterVersion == null) { throw new AmbariException("Could not find current stack version of cluster " + this.getClusterName()); } - RepositoryVersionState desiredState = sourceClusterVersion.getState(); - - Set<RepositoryVersionState> validStates = new HashSet<RepositoryVersionState>(){{ - add(RepositoryVersionState.INSTALLING); - }}; - - if (!validStates.contains(desiredState)) { - throw new AmbariException("The state must be one of " + validStates); - } - clusterGlobalLock.readLock().lock(); try { readWriteLock.writeLock().lock(); try { - Set<String> existingHostsWithClusterStackAndVersion = new HashSet<String>(); - HashMap<String, HostVersionEntity> existingHostStackVersions = new HashMap<String, HostVersionEntity>(); - List<HostVersionEntity> existingHostVersionEntities = hostVersionDAO.findByClusterStackAndVersion(this.getClusterName(), - sourceClusterVersion.getStack(), sourceClusterVersion.getVersion()); - if (existingHostVersionEntities != null) { - for (HostVersionEntity entity : existingHostVersionEntities) { - existingHostsWithClusterStackAndVersion.add(entity.getHostName()); - existingHostStackVersions.put(entity.getHostName(), entity); - } - } - Map<String, Host> hosts = clusters.getHostsForCluster(this.getClusterName()); - - Sets.SetView<String> hostsMissingRepoVersion = Sets.difference(hosts.keySet(), existingHostsWithClusterStackAndVersion); - for (String hostname : hosts.keySet()) { - if (hostsMissingRepoVersion.contains(hostname)) { - // Create new host stack version - HostEntity hostEntity = hostDAO.findByName(hostname); - HostVersionEntity hostVersionEntity = new HostVersionEntity(hostname, sourceClusterVersion.getStack(), - sourceClusterVersion.getVersion(), RepositoryVersionState.INSTALLING); - hostVersionEntity.setHostEntity(hostEntity); - hostVersionDAO.create(hostVersionEntity); - } else { - // Update existing host stack version - HostVersionEntity hostVersionEntity = existingHostStackVersions.get(hostname); - hostVersionEntity.setState(desiredState); - hostVersionDAO.merge(hostVersionEntity); - } - } - } finally { - readWriteLock.writeLock().unlock(); - } - } finally { - clusterGlobalLock.readLock().unlock(); - } - } - - @Override - public void recalculateClusterVersionState(String repositoryVersion) throws AmbariException { - clusterGlobalLock.readLock().lock(); - try { - readWriteLock.writeLock().lock(); - try { - Map<String, Host> hosts = clusters.getHostsForCluster(this.getClusterName()); - String stackId = this.getCurrentStackVersion().getStackId(); - ClusterVersionEntity clusterVersion = clusterVersionDAO.findByClusterAndStackAndVersion(this.getClusterName(), - stackId, repositoryVersion); - - if (clusterVersion == null) { - throw new AmbariException("Repository version is null"); + HostEntity hostEntity = hostDAO.findByName(hostname); + HostVersionEntity hostVersionEntity = new HostVersionEntity(hostname, currentClusterVersion.getStack(), + currentClusterVersion.getVersion(), RepositoryVersionState.INSTALLED); + hostVersionEntity.setHostEntity(hostEntity); + hostVersionDAO.create(hostVersionEntity); } - - RepositoryVersionState worstState; - if (clusterVersion.getState() != RepositoryVersionState.INSTALL_FAILED && - clusterVersion.getState() != RepositoryVersionState.INSTALLING) { - // anything else is not supported as of now - return; - } - // Process transition from INSTALLING state - worstState = RepositoryVersionState.INSTALLED; - for (Host host : hosts.values()) { - String hostName = host.getHostName(); - if (host.getState() != HostState.HEALTHY) { - worstState = RepositoryVersionState.INSTALL_FAILED; - LOG.warn(String.format("Host %s is in unhealthy state, treating as %s", - hostName, worstState)); - continue; - } - - HostVersionEntity hostVersion = hostVersionDAO.findByClusterStackVersionAndHost(this.getClusterName(), - stackId, repositoryVersion, hostName); - if (hostVersion == null) { - throw new AmbariException(String.format("Repo version %s is not installed on host %s", - repositoryVersion, hostName)); - } - if (hostVersion.getState() != worstState) { - worstState = hostVersion.getState(); - } - } - if (worstState != clusterVersion.getState()) { - // Any mismatch will be catched while transitioning - transitionClusterVersion(stackId, repositoryVersion, worstState); - } - clusterVersionDAO.merge(clusterVersion); - } finally { readWriteLock.writeLock().unlock(); } @@ -1300,8 +1218,10 @@ public class ClusterImpl implements Cluster { Set<RepositoryVersionState> allowedStates = new HashSet<RepositoryVersionState>(); if (this.clusterEntity.getClusterVersionEntities() == null || this.clusterEntity.getClusterVersionEntities().isEmpty()) { allowedStates.add(RepositoryVersionState.CURRENT); + allowedStates.add(RepositoryVersionState.INSTALLED); // TODO: dlysnichenko: remove when 2-stage api refactor is ready } else { - allowedStates.add(RepositoryVersionState.INSTALLING); + allowedStates.add(RepositoryVersionState.UPGRADING); + allowedStates.add(RepositoryVersionState.INSTALLED); // TODO: dlysnichenko: remove when 2-stage api refactor is ready } if (! allowedStates.contains(state)) { @@ -1347,13 +1267,8 @@ public class ClusterImpl implements Cluster { switch (existingClusterVersion.getState()) { case CURRENT: allowedStates.add(RepositoryVersionState.INSTALLED); - case INSTALLING: - allowedStates.add(RepositoryVersionState.INSTALLED); - allowedStates.add(RepositoryVersionState.INSTALL_FAILED); - case INSTALL_FAILED: - allowedStates.add(RepositoryVersionState.INSTALLING); case INSTALLED: - allowedStates.add(RepositoryVersionState.UPGRADING); + allowedStates.add(RepositoryVersionState.CURRENT); case UPGRADING: allowedStates.add(RepositoryVersionState.CURRENT); allowedStates.add(RepositoryVersionState.UPGRADE_FAILED); http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java index a756275..3da931f 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java @@ -103,7 +103,7 @@ public class TestActionDBAccessorImpl { am = new ActionManager(5000, 1200000, new ActionQueue(), clusters, db, new HostsMap((String) null), injector.getInstance(UnitOfWork.class), - injector.getInstance(RequestFactory.class), null, null); + injector.getInstance(RequestFactory.class), null); } @After http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java index 01a40f4..ed1318c 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java @@ -85,7 +85,7 @@ public class TestActionManager { ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class); ActionManager am = new ActionManager(5000, 1200000, new ActionQueue(), clusters, db, new HostsMap((String) null), unitOfWork, - injector.getInstance(RequestFactory.class), null, null); + injector.getInstance(RequestFactory.class), null); populateActionDB(db, hostname); Stage stage = db.getAllStages(requestId).get(0); Assert.assertEquals(stageId, stage.getStageId()); @@ -128,7 +128,7 @@ public class TestActionManager { ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class); ActionManager am = new ActionManager(5000, 1200000, new ActionQueue(), clusters, db, new HostsMap((String) null), unitOfWork, - injector.getInstance(RequestFactory.class), null, null); + injector.getInstance(RequestFactory.class), null); populateActionDB(db, hostname); Stage stage = db.getAllStages(requestId).get(0); Assert.assertEquals(stageId, stage.getStageId()); @@ -218,7 +218,7 @@ public class TestActionManager { replay(queue, db, clusters); ActionManager manager = new ActionManager(0, 0, queue, clusters, db, null, unitOfWork, - injector.getInstance(RequestFactory.class), null, null); + injector.getInstance(RequestFactory.class), null); assertSame(listStages, manager.getActions(requestId)); verify(queue, db, clusters); http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java index b389644..e61c1a9 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java @@ -43,7 +43,6 @@ import org.apache.ambari.server.agent.CommandReport; import org.apache.ambari.server.agent.ExecutionCommand; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.HostsMap; -import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.ambari.server.serveraction.MockServerAction; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; @@ -134,7 +133,7 @@ public class TestActionScheduler { //Keep large number of attempts so that the task is not expired finally //Small action timeout to test rescheduling ActionScheduler scheduler = new ActionScheduler(100, 5, db, aq, fsm, - 10000, new HostsMap((String) null), unitOfWork, null, conf); + 10000, new HostsMap((String) null), unitOfWork, conf); scheduler.setTaskTimeoutAdjustment(false); List<AgentCommand> ac = waitForQueueSize(hostname, aq, 1, scheduler); @@ -236,7 +235,7 @@ public class TestActionScheduler { //Small action timeout to test rescheduling ActionScheduler scheduler = new ActionScheduler(100, 0, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); scheduler.setTaskTimeoutAdjustment(false); // Start the thread @@ -263,7 +262,6 @@ public class TestActionScheduler { } - @Ignore @Test public void testActionTimeoutForLostHost() throws Exception { ActionQueue aq = new ActionQueue(); @@ -316,7 +314,7 @@ public class TestActionScheduler { //Small action timeout to test rescheduling ActionScheduler scheduler = EasyMock.createMockBuilder(ActionScheduler.class). withConstructor((long) 100, (long) 50, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, EasyMock.anyObject(AmbariEventPublisher.class), null, conf). + new HostsMap((String) null), unitOfWork, conf). addMockedMethod("cancelHostRoleCommands"). createMock(); scheduler.cancelHostRoleCommands((Collection<HostRoleCommand>)EasyMock.anyObject(),EasyMock.anyObject(String.class)); @@ -431,7 +429,7 @@ public class TestActionScheduler { // Make sure the NN install doesn't timeout ActionScheduler scheduler = new ActionScheduler(100, 50000, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); scheduler.setTaskTimeoutAdjustment(false); int cycleCount=0; @@ -556,7 +554,7 @@ public class TestActionScheduler { }).when(db).getTasksByHostRoleAndStatus(anyString(), anyString(), any(HostRoleStatus.class)); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); int cycleCount = 0; while (!stages.get(0).getHostRoleStatus(serverHostname, "AMBARI_SERVER_ACTION") @@ -649,7 +647,7 @@ public class TestActionScheduler { ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); int cycleCount = 0; while (!stages.get(0).getHostRoleStatus(serverHostname, "AMBARI_SERVER_ACTION").isCompletedState() @@ -733,7 +731,7 @@ public class TestActionScheduler { }).when(db).getTasksByHostRoleAndStatus(anyString(), anyString(), any(HostRoleStatus.class)); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); int cycleCount = 0; while (!stages.get(0).getHostRoleStatus(serverHostname, "AMBARI_SERVER_ACTION") @@ -832,11 +830,11 @@ public class TestActionScheduler { Properties properties = new Properties(); Configuration conf = new Configuration(properties); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); ActionManager am = new ActionManager( 2, 2, aq, fsm, db, new HostsMap((String) null), - unitOfWork, requestFactory, conf, null); + unitOfWork, requestFactory, conf); scheduler.doWork(); @@ -917,12 +915,12 @@ public class TestActionScheduler { Configuration conf = new Configuration(properties); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), - unitOfWork, null, conf); + unitOfWork, conf); ActionManager am = new ActionManager( 2, 2, aq, fsm, db, new HostsMap((String) null), unitOfWork, - requestFactory, conf, null); + requestFactory, conf); scheduler.doWork(); @@ -991,12 +989,12 @@ public class TestActionScheduler { Configuration conf = new Configuration(properties); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), - unitOfWork, null, conf); + unitOfWork, conf); ActionManager am = new ActionManager( 2, 2, aq, fsm, db, new HostsMap((String) null), unitOfWork, - requestFactory, conf, null); + requestFactory, conf); scheduler.doWork(); @@ -1006,7 +1004,7 @@ public class TestActionScheduler { Assert.assertEquals(HostRoleStatus.QUEUED, stages.get(1).getHostRoleStatus(hostname1, "GANGLIA_MONITOR")); } - @Ignore + @Test public void testRequestFailureOnStageFailure() throws Exception { ActionQueue aq = new ActionQueue(); @@ -1116,7 +1114,7 @@ public class TestActionScheduler { ActionScheduler scheduler = EasyMock.createMockBuilder(ActionScheduler.class). withConstructor((long)100, (long)50, db, aq, fsm, 3, new HostsMap((String) null), - unitOfWork, null, conf). + unitOfWork, conf). addMockedMethod("cancelHostRoleCommands"). createMock(); scheduler.cancelHostRoleCommands(EasyMock.capture(cancelCommandList), @@ -1125,8 +1123,7 @@ public class TestActionScheduler { EasyMock.replay(scheduler); ActionManager am = new ActionManager( - 2, 2, aq, fsm, db, new HostsMap((String) null), unitOfWork, requestFactory, conf, - EasyMock.createNiceMock(AmbariEventPublisher.class)); + 2, 2, aq, fsm, db, new HostsMap((String) null), unitOfWork, requestFactory, conf); scheduler.doWork(); @@ -1286,9 +1283,9 @@ public class TestActionScheduler { Configuration conf = new Configuration(properties); ActionScheduler scheduler = new ActionScheduler(100, 10000, db, aq, fsm, 3, new HostsMap((String) null), - unitOfWork, null, conf); + unitOfWork, conf); ActionManager am = new ActionManager( - 2, 10000, aq, fsm, db, new HostsMap((String) null), unitOfWork, requestFactory, conf, null); + 2, 10000, aq, fsm, db, new HostsMap((String) null), unitOfWork, requestFactory, conf); scheduler.doWork(); @@ -1471,9 +1468,9 @@ public class TestActionScheduler { Configuration conf = new Configuration(properties); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, new HostsMap((String) null), - unitOfWork, null, conf); + unitOfWork, conf); ActionManager am = new ActionManager( - 2, 2, aq, fsm, db, new HostsMap((String) null), unitOfWork, requestFactory, conf, null); + 2, 2, aq, fsm, db, new HostsMap((String) null), unitOfWork, requestFactory, conf); scheduler.doWork(); @@ -1642,7 +1639,7 @@ public class TestActionScheduler { //Keep large number of attempts so that the task is not expired finally //Small action timeout to test rescheduling ActionScheduler scheduler = new ActionScheduler(100, 100, db, aq, fsm, - 10000, new HostsMap((String) null), unitOfWork, null, conf); + 10000, new HostsMap((String) null), unitOfWork, conf); scheduler.setTaskTimeoutAdjustment(false); List<AgentCommand> ac = waitForQueueSize(hostname, aq, 1, scheduler); @@ -1721,7 +1718,7 @@ public class TestActionScheduler { when(db.getStagesInProgress()).thenReturn(stages); ActionScheduler scheduler = new ActionScheduler(100, 50000, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); final CountDownLatch abortCalls = new CountDownLatch(2); @@ -1835,7 +1832,7 @@ public class TestActionScheduler { }).when(db).getTask(anyLong()); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); int cycleCount = 0; while (!stages.get(0).getHostRoleStatus(serverHostname, "AMBARI_SERVER_ACTION") @@ -1966,11 +1963,11 @@ public class TestActionScheduler { Configuration conf = new Configuration(properties); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); ActionManager am = new ActionManager( 2, 2, aq, fsm, db, new HostsMap((String) null), - unitOfWork, requestFactory, conf, null); + unitOfWork, requestFactory, conf); scheduler.doWork(); @@ -2132,11 +2129,11 @@ public class TestActionScheduler { Configuration conf = new Configuration(properties); ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, - new HostsMap((String) null), unitOfWork, null, conf); + new HostsMap((String) null), unitOfWork, conf); ActionManager am = new ActionManager( 2, 2, aq, fsm, db, new HostsMap((String) null), - unitOfWork, requestFactory, conf, null); + unitOfWork, requestFactory, conf); // Execution of request 1 http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java index 210611b..ff406b3 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java @@ -75,7 +75,6 @@ import org.apache.ambari.server.agent.HostStatus.Status; import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.HostsMap; -import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.state.Alert; @@ -98,7 +97,6 @@ import org.apache.ambari.server.utils.StageUtils; import org.codehaus.jackson.JsonGenerationException; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -725,7 +723,7 @@ public class TestHeartbeatHandler { clusters.addCluster(DummyCluster); ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class); ActionManager am = new ActionManager(5000, 1200000, new ActionQueue(), clusters, db, - new HostsMap((String) null), unitOfWork, injector.getInstance(RequestFactory.class), null, null); + new HostsMap((String) null), unitOfWork, injector.getInstance(RequestFactory.class), null); populateActionDB(db, DummyHostname1); Stage stage = db.getAllStages(requestId).get(0); Assert.assertEquals(stageId, stage.getStageId()); @@ -1058,7 +1056,6 @@ public class TestHeartbeatHandler { assertTrue(registrationResponse.getStatusCommands().get(0).equals(statusCmd1)); } - @Ignore @Test @SuppressWarnings("unchecked") public void testTaskInProgressHandling() throws AmbariException, InvalidStateTransitionException { @@ -1121,7 +1118,6 @@ public class TestHeartbeatHandler { assertEquals("Host state should still be installing", State.INSTALLING, componentState1); } - @Ignore @Test @SuppressWarnings("unchecked") public void testOPFailedEventForAbortedTask() throws AmbariException, InvalidStateTransitionException { @@ -1330,7 +1326,6 @@ public class TestHeartbeatHandler { State.INSTALLED, serviceComponentHost1.getState()); } - @Ignore @Test @SuppressWarnings("unchecked") public void testUpgradeSpecificHandling() throws AmbariException, InvalidStateTransitionException { @@ -1595,7 +1590,6 @@ public class TestHeartbeatHandler { stack122, serviceComponentHost2.getStackVersion()); } - @Ignore @Test @SuppressWarnings("unchecked") public void testComponentUpgradeInProgressReport() throws AmbariException, InvalidStateTransitionException { @@ -1686,7 +1680,6 @@ public class TestHeartbeatHandler { } - @Ignore @Test @SuppressWarnings("unchecked") public void testComponentUpgradeFailReport() throws AmbariException, InvalidStateTransitionException { @@ -2004,7 +1997,6 @@ public class TestHeartbeatHandler { assertEquals(HostHealthStatus.HealthStatus.ALERT.name(), hostObject.getStatus()); } - @Ignore @Test @SuppressWarnings("unchecked") public void testIgnoreCustomActionReport() throws AmbariException, InvalidStateTransitionException { @@ -2123,7 +2115,7 @@ public class TestHeartbeatHandler { addMockedMethod("getTasks"). withConstructor((long)0, (long)0, actionQueueMock, clustersMock, actionDBAccessor, new HostsMap((String) null), unitOfWork, - injector.getInstance(RequestFactory.class), configurationMock, createNiceMock(AmbariEventPublisher.class)). + injector.getInstance(RequestFactory.class), configurationMock). createMock(); return actionManager; } http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java index d9b7b2a..f48381c 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java @@ -64,7 +64,6 @@ import org.apache.ambari.server.state.StackInfo; import org.apache.ambari.server.state.fsm.InvalidStateTransitionException; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -140,7 +139,7 @@ public class ClusterStackVersionResourceProviderTest { injector.getInstance(PersistService.class).stop(); } - @Ignore + @Test public void testCreateResources() throws Exception { Resource.Type type = Resource.Type.ClusterStackVersion; http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java index aabe366..d387732 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java @@ -45,6 +45,7 @@ import org.apache.ambari.server.state.ServiceComponentHost; 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.StackInfo; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -191,9 +192,9 @@ public class HostStackVersionResourceProviderTest { // add properties to the request map properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID, "Cluster100"); - properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_REPO_VERSION_PROPERTY_ID, "2.2.0.1-885"); - properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_STACK_PROPERTY_ID, "HDP"); - properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_VERSION_PROPERTY_ID, "2.0.1"); + properties.put(HostStackVersionResourceProvider.STACK_VERSION_REPO_VERSION_PROPERTY_ID, "2.2.0.1-885"); + properties.put(HostStackVersionResourceProvider.STACK_VERSION_STACK_PROPERTY_ID, "HDP"); + properties.put(HostStackVersionResourceProvider.STACK_VERSION_VERSION_PROPERTY_ID, "2.0.1"); properties.put(HostStackVersionResourceProvider.HOST_STACK_VERSION_HOST_NAME_PROPERTY_ID, "host1"); propertySet.add(properties); http://git-wip-us.apache.org/repos/asf/ambari/blob/f6248ae5/ambari-server/src/test/python/custom_actions/TestCheckHost.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/custom_actions/TestCheckHost.py b/ambari-server/src/test/python/custom_actions/TestCheckHost.py index 9ce71c6..d1aeb16 100644 --- a/ambari-server/src/test/python/custom_actions/TestCheckHost.py +++ b/ambari-server/src/test/python/custom_actions/TestCheckHost.py @@ -230,54 +230,54 @@ class TestCheckHost(TestCase): self.assertTrue(structured_out_mock.called) structured_out_mock.assert_called_with({}) -# @patch.object(Script, 'get_config') -# @patch.object(Script, 'get_tmp_dir') -# @patch('resource_management.libraries.script.Script.put_structured_out') -# @patch('ambari_agent.HostInfo.HostInfo.javaProcs') -# @patch('ambari_agent.HostInfo.HostInfo.checkLiveServices') -# @patch('ambari_agent.HostInfo.HostInfo.getUMask') -# @patch('ambari_agent.HostInfo.HostInfo.getTransparentHugePage') -# @patch('ambari_agent.HostInfo.HostInfo.checkIptables') -# @patch('ambari_agent.HostInfo.HostInfo.checkReverseLookup') -# @patch('time.time') -# def testLastAgentEnv(self, time_mock, checkReverseLookup_mock, checkIptables_mock, getTransparentHugePage_mock, -# getUMask_mock, checkLiveServices_mock, javaProcs_mock, put_structured_out_mock, -# get_tmp_dir_mock, get_config_mock): -# jsonFilePath = os.path.join("../resources/custom_actions", "check_last_agent_env.json") -# with open(jsonFilePath, "r") as jsonFile: -# jsonPayload = json.load(jsonFile) -# -# get_config_mock.return_value = ConfigDictionary(jsonPayload) -# get_tmp_dir_mock.return_value = "/tmp" -# -# checkHost = CheckHost() -# checkHost.actionexecute(None) -# -# # ensure the correct function was called -# self.assertTrue(time_mock.called) -# self.assertTrue(checkReverseLookup_mock.called) -# self.assertTrue(checkIptables_mock.called) -# self.assertTrue(getTransparentHugePage_mock.called) -# self.assertTrue(getUMask_mock.called) -# self.assertTrue(checkLiveServices_mock.called) -# self.assertTrue(javaProcs_mock.called) -# self.assertTrue(put_structured_out_mock.called) -# # ensure the correct keys are in the result map -# last_agent_env_check_result = put_structured_out_mock.call_args[0][0] -# self.assertTrue('last_agent_env_check' in last_agent_env_check_result) -# self.assertTrue('hostHealth' in last_agent_env_check_result['last_agent_env_check']) -# self.assertTrue('iptablesIsRunning' in last_agent_env_check_result['last_agent_env_check']) -# self.assertTrue('reverseLookup' in last_agent_env_check_result['last_agent_env_check']) -# self.assertTrue('alternatives' in last_agent_env_check_result['last_agent_env_check']) -# self.assertTrue('umask' in last_agent_env_check_result['last_agent_env_check']) -# self.assertTrue('stackFoldersAndFiles' in last_agent_env_check_result['last_agent_env_check']) -# self.assertTrue('existingRepos' in last_agent_env_check_result['last_agent_env_check']) -# self.assertTrue('installedPackages' in last_agent_env_check_result['last_agent_env_check']) -# self.assertTrue('existingUsers' in last_agent_env_check_result['last_agent_env_check']) -# -# # try it now with errors -# javaProcs_mock.side_effect = Exception("test exception") -# checkHost.actionexecute(None) -# -# #ensure the correct response is returned -# put_structured_out_mock.assert_called_with({'last_agent_env_check': {'message': 'test exception', 'exit_code': 1}}) + @patch.object(Script, 'get_config') + @patch.object(Script, 'get_tmp_dir') + @patch('resource_management.libraries.script.Script.put_structured_out') + @patch('ambari_agent.HostInfo.HostInfo.javaProcs') + @patch('ambari_agent.HostInfo.HostInfo.checkLiveServices') + @patch('ambari_agent.HostInfo.HostInfo.getUMask') + @patch('ambari_agent.HostInfo.HostInfo.getTransparentHugePage') + @patch('ambari_agent.HostInfo.HostInfo.checkIptables') + @patch('ambari_agent.HostInfo.HostInfo.checkReverseLookup') + @patch('time.time') + def testLastAgentEnv(self, time_mock, checkReverseLookup_mock, checkIptables_mock, getTransparentHugePage_mock, + getUMask_mock, checkLiveServices_mock, javaProcs_mock, put_structured_out_mock, + get_tmp_dir_mock, get_config_mock): + jsonFilePath = os.path.join("../resources/custom_actions", "check_last_agent_env.json") + with open(jsonFilePath, "r") as jsonFile: + jsonPayload = json.load(jsonFile) + + get_config_mock.return_value = ConfigDictionary(jsonPayload) + get_tmp_dir_mock.return_value = "/tmp" + + checkHost = CheckHost() + checkHost.actionexecute(None) + + # ensure the correct function was called + self.assertTrue(time_mock.called) + self.assertTrue(checkReverseLookup_mock.called) + self.assertTrue(checkIptables_mock.called) + self.assertTrue(getTransparentHugePage_mock.called) + self.assertTrue(getUMask_mock.called) + self.assertTrue(checkLiveServices_mock.called) + self.assertTrue(javaProcs_mock.called) + self.assertTrue(put_structured_out_mock.called) + # ensure the correct keys are in the result map + last_agent_env_check_result = put_structured_out_mock.call_args[0][0] + self.assertTrue('last_agent_env_check' in last_agent_env_check_result) + self.assertTrue('hostHealth' in last_agent_env_check_result['last_agent_env_check']) + self.assertTrue('iptablesIsRunning' in last_agent_env_check_result['last_agent_env_check']) + self.assertTrue('reverseLookup' in last_agent_env_check_result['last_agent_env_check']) + self.assertTrue('alternatives' in last_agent_env_check_result['last_agent_env_check']) + self.assertTrue('umask' in last_agent_env_check_result['last_agent_env_check']) + self.assertTrue('stackFoldersAndFiles' in last_agent_env_check_result['last_agent_env_check']) + self.assertTrue('existingRepos' in last_agent_env_check_result['last_agent_env_check']) + self.assertTrue('installedPackages' in last_agent_env_check_result['last_agent_env_check']) + self.assertTrue('existingUsers' in last_agent_env_check_result['last_agent_env_check']) + + # try it now with errors + javaProcs_mock.side_effect = Exception("test exception") + checkHost.actionexecute(None) + + #ensure the correct response is returned + put_structured_out_mock.assert_called_with({'last_agent_env_check': {'message': 'test exception', 'exit_code': 1}}) \ No newline at end of file
