You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2013/03/26 02:21:12 UTC
svn commit: r1460943 - in /incubator/ambari/trunk: ./
ambari-server/src/main/java/org/apache/ambari/server/controller/
ambari-server/src/main/resources/stacks/HDP/1.3.0/
ambari-server/src/test/java/org/apache/ambari/server/controller/
Author: swagle
Date: Tue Mar 26 01:21:11 2013
New Revision: 1460943
URL: http://svn.apache.org/r1460943
Log:
AMBARI-1707. Upgrade should check if another upgrade request is active as well as if any MASTER components have not stopped. (Sumit Mohanty via swagle)
Added:
incubator/ambari/trunk/ambari-server/src/main/resources/stacks/HDP/1.3.0/metainfo.xml
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1460943&r1=1460942&r2=1460943&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Tue Mar 26 01:21:11 2013
@@ -12,6 +12,9 @@ Trunk (unreleased changes):
NEW FEATURES
+ AMBARI-1707. Upgrade should check if another upgrade request is active as well as
+ if any MASTER components have not stopped. (Sumit Mohanty via swagle)
+
AMBARI-1673. Configuring Hue to work with a secure HDP cluster and making changes
to the Enable Security feature. (swagle)
Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1460943&r1=1460942&r2=1460943&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Tue Mar 26 01:21:11 2013
@@ -49,6 +49,7 @@ import org.apache.ambari.server.ServiceN
import org.apache.ambari.server.StackAccessException;
import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.actionmanager.HostRoleCommand;
+import org.apache.ambari.server.actionmanager.HostRoleStatus;
import org.apache.ambari.server.actionmanager.RequestStatus;
import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.actionmanager.StageFactory;
@@ -1487,10 +1488,9 @@ public class AmbariManagementControllerI
}
}
- boolean activeComponentExists = checkIfActiveComponentsExist(cluster);
- if (activeComponentExists) {
- throw new AmbariException("Upgrade needs all services to be stopped.");
- }
+ checkIfActiveComponentsExist(cluster, currentVersion);
+
+ checkIfAnotherUpgradeCommandIsActive();
// TODO Ensure no other upgrade is active
/**
@@ -1550,6 +1550,27 @@ public class AmbariManagementControllerI
return null;
}
+ private void checkIfAnotherUpgradeCommandIsActive() throws AmbariException {
+ List<Long> requestIds = actionManager.getRequestsByStatus(RequestStatus.IN_PROGRESS);
+ if (requestIds != null) {
+ for (Long requestId : requestIds) {
+ List<HostRoleCommand> commands = actionManager.getRequestTasks(requestId);
+ if (commands != null) {
+ for (HostRoleCommand command : commands) {
+ if (command.getRoleCommand() == RoleCommand.UPGRADE
+ && (command.getStatus() == HostRoleStatus.QUEUED
+ || command.getStatus() == HostRoleStatus.PENDING
+ || command.getStatus() == HostRoleStatus.IN_PROGRESS)) {
+ throw new AmbariException("A prior upgrade request with id " + requestId
+ + " is in progress. Upgrade can "
+ + "only be retried after the prior command has completed.");
+ }
+ }
+ }
+ }
+ }
+ }
+
private void addFinalizeUpgradeAction(Cluster cluster, List<Stage> stages) throws AmbariException {
// Add server side action as the last Stage
Stage lastStage = stages.get(stages.size() - 1);
@@ -1667,27 +1688,42 @@ public class AmbariManagementControllerI
}
}
- private boolean checkIfActiveComponentsExist(Cluster c) {
- boolean activeComponentExists = false;
+ private void checkIfActiveComponentsExist(Cluster c, StackId currentStackId)
+ throws AmbariException {
+ String stackName = currentStackId.getStackName();
+ String stackVersion = currentStackId.getStackVersion();
+ StringBuilder sb = new StringBuilder("Upgrade needs all services to be stopped. ");
for (Service service : c.getServices().values()) {
- if (activeComponentExists || service.getDesiredState() != State.INSTALLED) {
- activeComponentExists = true;
- break;
+ if (service.getDesiredState() != State.INSTALLED) {
+ sb.append("Service " + service.getName() + " is not stopped.");
+ throw new AmbariException(sb.toString());
}
for (ServiceComponent component : service.getServiceComponents().values()) {
- if (activeComponentExists || component.getDesiredState() != State.INSTALLED) {
- activeComponentExists = true;
- break;
+ if (component.getDesiredState() != State.INSTALLED) {
+ sb.append("Component " + component.getName() + " of service "
+ + service.getName() + " is not stopped.");
+ throw new AmbariException(sb.toString());
}
for (ServiceComponentHost componentHost : component.getServiceComponentHosts().values()) {
- if (activeComponentExists || componentHost.getDesiredState() != State.INSTALLED) {
- activeComponentExists = true;
- break;
+ if (componentHost.getDesiredState() != State.INSTALLED) {
+ sb.append("Component " + component.getName() + " of service "
+ + service.getName() + " on host "
+ + componentHost.getHostName() + " is not stopped.");
+ throw new AmbariException(sb.toString());
+ }
+ if(componentHost.getState() == State.STARTED) {
+ ComponentInfo compInfo = ambariMetaInfo.getComponent(stackName, stackVersion,
+ componentHost.getServiceName(), componentHost.getServiceComponentName());
+ if(compInfo.isMaster()) {
+ sb.append("Component " + component.getName() + " of service "
+ + service.getName() + " on host "
+ + componentHost.getHostName() + " is not yet stopped.");
+ throw new AmbariException(sb.toString());
+ }
}
}
}
}
- return activeComponentExists;
}
// FIXME refactor code out of all update functions
Added: incubator/ambari/trunk/ambari-server/src/main/resources/stacks/HDP/1.3.0/metainfo.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/resources/stacks/HDP/1.3.0/metainfo.xml?rev=1460943&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/resources/stacks/HDP/1.3.0/metainfo.xml (added)
+++ incubator/ambari/trunk/ambari-server/src/main/resources/stacks/HDP/1.3.0/metainfo.xml Tue Mar 26 01:21:11 2013
@@ -0,0 +1,22 @@
+<?xml version="1.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.
+-->
+<metainfo>
+ <versions>
+ <upgrade>1.2.0</upgrade>
+ </versions>
+</metainfo>
Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1460943&r1=1460942&r2=1460943&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java Tue Mar 26 01:21:11 2013
@@ -4567,10 +4567,10 @@ public class AmbariManagementControllerT
@Test
public void testUpdateClusterVersionBasic() throws AmbariException {
String clusterName = "foo1";
- String serviceName = "PIG";
+ String serviceName = "MAPREDUCE";
String host1 = "h1";
String host2 = "h2";
- String componentName = "PIG";
+ String componentName = "JOBTRACKER";
StackId currentStackId = new StackId("HDP-0.1");
Map<String, String> mapRequestProps = new HashMap<String, String>();
@@ -4604,6 +4604,10 @@ public class AmbariManagementControllerT
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
.setDesiredState(State.STARTED);
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host1)
+ .setState(State.INSTALLED);
+ c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
+ .setState(State.STARTED);
+ c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host1)
.setStackVersion(currentStackId);
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
.setStackVersion(currentStackId);
@@ -4611,7 +4615,7 @@ public class AmbariManagementControllerT
ClusterRequest r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.0.1", null);
try {
controller.updateCluster(r, mapRequestProps);
- fail("Update cluster creation should fail");
+ fail("Update cluster should fail");
} catch (AmbariException e) {
Assert.assertTrue(e.getMessage().contains("must be greater than current version"));
}
@@ -4619,7 +4623,7 @@ public class AmbariManagementControllerT
r = new ClusterRequest(c.getClusterId(), clusterName, "HDPLocal-1.2.2", null);
try {
controller.updateCluster(r, mapRequestProps);
- fail("Update cluster creation should fail");
+ fail("Update cluster should fail");
} catch (AmbariException e) {
Assert.assertTrue(e.getMessage().contains("Upgrade not possible between different stacks"));
}
@@ -4627,13 +4631,26 @@ public class AmbariManagementControllerT
r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
try {
controller.updateCluster(r, mapRequestProps);
- fail("Update cluster creation should fail");
+ fail("Update cluster should fail");
} catch (AmbariException e) {
Assert.assertTrue(e.getMessage().contains("Upgrade needs all services to be stopped"));
+ Assert.assertTrue(e.getMessage().contains(serviceName));
}
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
.setDesiredState(State.INSTALLED);
+
+ r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
+ try {
+ controller.updateCluster(r, mapRequestProps);
+ fail("Update cluster should fail");
+ } catch (AmbariException e) {
+ Assert.assertTrue(e.getMessage().contains("Upgrade needs all services to be stopped"));
+ Assert.assertTrue(e.getMessage().contains(componentName));
+ }
+
+ c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host2)
+ .setState(State.INSTALLED);
controller.updateCluster(r, mapRequestProps);
StackId expectedStackId = new StackId("HDP-0.2");
Assert.assertTrue(expectedStackId.equals(c.getDesiredStackVersion()));
@@ -4652,6 +4669,14 @@ public class AmbariManagementControllerT
Assert.assertEquals(State.UPGRADING, sc.getServiceComponentHost(host1).getState());
Assert.assertEquals(State.UPGRADING, sc.getServiceComponentHost(host2).getState());
+ // Fail as another request is active
+ try {
+ controller.updateCluster(r, mapRequestProps);
+ fail("Update cluster should fail");
+ } catch (AmbariException e) {
+ Assert.assertTrue(e.getMessage().contains("A prior upgrade request with id"));
+ }
+
// cases where there is no update required
c.getService(serviceName).getServiceComponent(componentName).getServiceComponentHost(host1)
.setDesiredState(State.INSTALLED);
@@ -4781,6 +4806,7 @@ public class AmbariManagementControllerT
resetServiceState(mrServiceName, currentStackId, c);
// Upgrade a cluster with two service
+ actionDB.abortOperation(trackAction.getRequestId());
r = new ClusterRequest(c.getClusterId(), clusterName, "HDP-0.2", null);
trackAction = controller.updateCluster(r, mapRequestProps);
stages = actionDB.getAllStages(trackAction.getRequestId());
@@ -4791,6 +4817,7 @@ public class AmbariManagementControllerT
validateGeneratedStages(stages, 5, expectedTasks);
// Upgrade again
+ actionDB.abortOperation(trackAction.getRequestId());
trackAction = controller.updateCluster(r, mapRequestProps);
stages = actionDB.getAllStages(trackAction.getRequestId());
validateGeneratedStages(stages, 5, expectedTasks);
@@ -4805,6 +4832,7 @@ public class AmbariManagementControllerT
c.getService(pigServiceName).getServiceComponent(pigComponentName).getServiceComponentHost(host2)
.setStackVersion(desiredStackId);
+ actionDB.abortOperation(trackAction.getRequestId());
trackAction = controller.updateCluster(r, mapRequestProps);
stages = actionDB.getAllStages(trackAction.getRequestId());
validateGeneratedStages(stages, 5, expectedTasks);
@@ -4813,6 +4841,7 @@ public class AmbariManagementControllerT
.setState(State.UPGRADE_FAILED);
c.getService(mrServiceName).getServiceComponent(mrTaskTrackerComp).getServiceComponentHost(host2)
.setState(State.UPGRADE_FAILED);
+ actionDB.abortOperation(trackAction.getRequestId());
trackAction = controller.updateCluster(r, mapRequestProps);
stages = actionDB.getAllStages(trackAction.getRequestId());
validateGeneratedStages(stages, 5, expectedTasks);
@@ -4832,6 +4861,7 @@ public class AmbariManagementControllerT
resetServiceState(mrServiceName, currentStackId, c);
resetServiceState(pigServiceName, currentStackId, c);
+ actionDB.abortOperation(trackAction.getRequestId());
trackAction = controller.updateCluster(r, mapRequestProps);
stages = actionDB.getAllStages(trackAction.getRequestId());
@@ -4849,9 +4879,9 @@ public class AmbariManagementControllerT
validateGeneratedStages(stages, 8, expectedTasks);
}
- private void resetServiceState(String hdfsService, StackId currentStackId, Cluster c) throws AmbariException {
- c.getService(hdfsService).setDesiredState(State.INSTALLED);
- for (ServiceComponent sc : c.getService(hdfsService).getServiceComponents().values()) {
+ private void resetServiceState(String service, StackId currentStackId, Cluster c) throws AmbariException {
+ c.getService(service).setDesiredState(State.INSTALLED);
+ for (ServiceComponent sc : c.getService(service).getServiceComponents().values()) {
sc.setDesiredState(State.INSTALLED);
for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
sch.setDesiredState(State.INSTALLED);