Forráskód Böngészése

AMBARI-6710. on host reg failure, exception printed to ambari-server.log (aonishuk)

Andrew Onishuk 10 éve
szülő
commit
a63cf2238d

+ 2 - 1
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java

@@ -18,6 +18,7 @@
 package org.apache.ambari.server.actionmanager;
 
 import com.google.inject.persist.Transactional;
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.agent.CommandReport;
 import org.apache.ambari.server.agent.ExecutionCommand;
 
@@ -66,7 +67,7 @@ public interface ActionDBAccessor {
    * @param request request object
    */
   @Transactional
-  void persistActions(Request request);
+  void persistActions(Request request) throws AmbariException;
 
   @Transactional
   void startRequest(long requestId);

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java

@@ -203,7 +203,7 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
 
   @Override
   @Transactional
-  public void persistActions(Request request) {
+  public void persistActions(Request request) throws AmbariException {
 
     RequestEntity requestEntity = request.constructNewPersistenceEntity();
 
@@ -239,7 +239,7 @@ public class ActionDBAccessorImpl implements ActionDBAccessor {
         if (hostEntity == null) {
           String msg = String.format("Host %s doesn't exist in database", hostRoleCommandEntity.getHostName());
           LOG.error(msg);
-          throw new RuntimeException(msg);
+          throw new AmbariException(msg);
         }
         hostRoleCommandEntity.setHost(hostEntity);
         hostRoleCommandDAO.create(hostRoleCommandEntity);

+ 1 - 1
ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java

@@ -84,7 +84,7 @@ public class ActionManager {
     sendActions(request, actionRequest);
   }
 
-  public void sendActions(Request request, ExecuteActionRequest executeActionRequest) {
+  public void sendActions(Request request, ExecuteActionRequest executeActionRequest) throws AmbariException {
     if (LOG.isDebugEnabled()) {
       LOG.debug(String.format("Persisting Request into DB: %s", request));
 

+ 2 - 1
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestStageContainer.java

@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
@@ -169,7 +170,7 @@ public class RequestStageContainer {
   /**
    * Persist the stages.
    */
-  public void persist() {
+  public void persist() throws AmbariException {
     if (!stages.isEmpty()) {
       Request request = requestFactory.createNewFromStages(stages);
       if (request != null && request.getStages()!= null && !request.getStages().isEmpty()) {

+ 10 - 2
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ServiceResourceProvider.java

@@ -203,7 +203,11 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
 
     RequestStatusResponse response = null;
     if (requestStages != null) {
-      requestStages.persist();
+      try {
+        requestStages.persist();
+      } catch (AmbariException e) {
+        throw new SystemException(e.getMessage(), e);
+      }
       response = requestStages.getRequestStatusResponse();
     }
     notifyUpdate(Resource.Type.Service, request, predicate);
@@ -291,7 +295,11 @@ public class ServiceResourceProvider extends AbstractControllerResourceProvider
       LOG.info("Starting all services");
       doUpdateResources(requestStages, startRequest, startPredicate);
       notifyUpdate(Resource.Type.Service, startRequest, startPredicate);
-      requestStages.persist();
+      try {
+        requestStages.persist();
+      } catch (AmbariException e) {
+        throw new SystemException(e.getMessage(), e);
+      }
       return requestStages.getRequestStatusResponse();
 
     } catch (NoSuchResourceException e) {

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java

@@ -153,7 +153,7 @@ public class ExecutionCommandWrapperTest {
     
   }
   
-  private static void createTask(ActionDBAccessor db, long requestId, long stageId, String hostName, String clusterName) {
+  private static void createTask(ActionDBAccessor db, long requestId, long stageId, String hostName, String clusterName) throws AmbariException {
     
     Stage s = new Stage(requestId, "/var/log", clusterName, 1L, "execution command wrapper test", "clusterHostInfo");
     s.setStageId(stageId);

+ 9 - 9
ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java

@@ -95,7 +95,7 @@ public class TestActionDBAccessorImpl {
   }
 
   @Test
-  public void testActionResponse() {
+  public void testActionResponse() throws AmbariException {
     String hostname = "host1";
     populateActionDB(db, hostname, requestId, stageId);
     Stage stage = db.getAllStages(requestId).get(0);
@@ -122,7 +122,7 @@ public class TestActionDBAccessorImpl {
   }
   
   @Test
-  public void testGetStagesInProgress() {
+  public void testGetStagesInProgress() throws AmbariException {
     String hostname = "host1";
     List<Stage> stages = new ArrayList<Stage>();
     stages.add(createStubStage(hostname, requestId, stageId));
@@ -135,7 +135,7 @@ public class TestActionDBAccessorImpl {
   }
   
   @Test
-  public void testGetStagesInProgressWithFailures() {
+  public void testGetStagesInProgressWithFailures() throws AmbariException {
     String hostname = "host1";
     populateActionDB(db, hostname, requestId, stageId);
     populateActionDB(db, hostname, requestId+1, stageId);
@@ -146,7 +146,7 @@ public class TestActionDBAccessorImpl {
   }
 
   @Test
-  public void testPersistActions() {
+  public void testPersistActions() throws AmbariException {
     populateActionDB(db, hostName, requestId, stageId);
     for (Stage stage : db.getAllStages(requestId)) {
       log.info("taskId={}" + stage.getExecutionCommands(hostName).get(0).
@@ -159,7 +159,7 @@ public class TestActionDBAccessorImpl {
   }
 
   @Test
-  public void testHostRoleScheduled() throws InterruptedException {
+  public void testHostRoleScheduled() throws InterruptedException, AmbariException {
     populateActionDB(db, hostName, requestId, stageId);
     Stage stage = db.getStage(StageUtils.getActionId(requestId, stageId));
     assertEquals(HostRoleStatus.PENDING, stage.getHostRoleStatus(hostName, Role.HBASE_MASTER.toString()));
@@ -194,7 +194,7 @@ public class TestActionDBAccessorImpl {
   }
 
   @Test
-  public void testCustomActionScheduled() throws InterruptedException {
+  public void testCustomActionScheduled() throws InterruptedException, AmbariException {
     populateActionDBWithCustomAction(db, hostName, requestId, stageId);
     Stage stage = db.getStage(StageUtils.getActionId(requestId, stageId));
     assertEquals(HostRoleStatus.PENDING, stage.getHostRoleStatus(hostName, actionName));
@@ -281,7 +281,7 @@ public class TestActionDBAccessorImpl {
   }
 
   @Test
-  public void testGetRequestsByStatusWithParams() {
+  public void testGetRequestsByStatusWithParams() throws AmbariException {
     List<Long> ids = new ArrayList<Long>();
 
     for (long l = 0; l < 10; l++) {
@@ -374,7 +374,7 @@ public class TestActionDBAccessorImpl {
   }
 
   private void populateActionDB(ActionDBAccessor db, String hostname,
-      long requestId, long stageId) {
+      long requestId, long stageId) throws AmbariException {
     Stage s = createStubStage(hostname, requestId, stageId);
     List<Stage> stages = new ArrayList<Stage>();
     stages.add(s);
@@ -399,7 +399,7 @@ public class TestActionDBAccessorImpl {
   }
 
   private void populateActionDBWithCustomAction(ActionDBAccessor db, String hostname,
-                                long requestId, long stageId) {
+                                long requestId, long stageId) throws AmbariException {
     Stage s = new Stage(requestId, "/a/b", "cluster1", 1L, "action db accessor test", "");
     s.setStageId(stageId);
     s.addHostRoleExecutionCommand(hostname, Role.valueOf(actionName),

+ 3 - 3
ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java

@@ -74,7 +74,7 @@ public class TestActionManager {
   }
 
   @Test
-  public void testActionResponse() {
+  public void testActionResponse() throws AmbariException {
     ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class);
     ActionManager am = new ActionManager(5000, 1200000, new ActionQueue(),
         clusters, db, new HostsMap((String) null), null, unitOfWork,
@@ -117,7 +117,7 @@ public class TestActionManager {
   }
   
   @Test
-  public void testLargeLogs() {
+  public void testLargeLogs() throws AmbariException {
     ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class);
     ActionManager am = new ActionManager(5000, 1200000, new ActionQueue(),
         clusters, db, new HostsMap((String) null), null, unitOfWork,
@@ -159,7 +159,7 @@ public class TestActionManager {
             .getHostRoleCommand(hostname, "HBASE_MASTER").getStructuredOut().length());
   }
 
-  private void populateActionDB(ActionDBAccessor db, String hostname) {
+  private void populateActionDB(ActionDBAccessor db, String hostname) throws AmbariException {
     Stage s = new Stage(requestId, "/a/b", "cluster1", 1L, "action manager test", "clusterHostInfo");
     s.setStageId(stageId);
     s.addHostRoleExecutionCommand(hostname, Role.HBASE_MASTER,

+ 1 - 1
ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java

@@ -634,7 +634,7 @@ public class TestHeartbeatHandler {
             s.getExitCode(DummyHostname1, HBASE_MASTER));
   }
 
-  private void populateActionDB(ActionDBAccessor db, String DummyHostname1) {
+  private void populateActionDB(ActionDBAccessor db, String DummyHostname1) throws AmbariException {
     Stage s = new Stage(requestId, "/a/b", DummyCluster, 1L, "heartbeat handler test", "clusterHostInfo");
     s.setStageId(stageId);
     String filename = null;

+ 3 - 2
ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestStageContainerTest.java

@@ -18,6 +18,7 @@
 
 package org.apache.ambari.server.controller.internal;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.Role;
 import org.apache.ambari.server.RoleCommand;
 import org.apache.ambari.server.actionmanager.ActionManager;
@@ -131,7 +132,7 @@ public class RequestStageContainerTest {
   }
 
   @Test
-  public void testPersist() {
+  public void testPersist() throws AmbariException {
     ActionManager actionManager = createStrictMock(ActionManager.class);
     RequestFactory requestFactory = createStrictMock(RequestFactory.class);
     Request request = createStrictMock(Request.class);
@@ -155,7 +156,7 @@ public class RequestStageContainerTest {
   }
 
   @Test
-  public void testPersist_noStages() {
+  public void testPersist_noStages() throws AmbariException {
     ActionManager actionManager = createStrictMock(ActionManager.class);
     RequestFactory requestFactory = createStrictMock(RequestFactory.class);