ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject ambari git commit: AMBARI-16279. Re-installation of components when there are no INSTALL_FAILED components returns 500 error (ncole)
Date Mon, 09 May 2016 21:59:32 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 477e5848a -> f66f08a92


AMBARI-16279. Re-installation of components when there are no INSTALL_FAILED components returns
500 error (ncole)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f66f08a9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f66f08a9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f66f08a9

Branch: refs/heads/trunk
Commit: f66f08a92bafa4134f80d866c8a09a9b178737d4
Parents: 477e584
Author: Nate Cole <ncole@hortonworks.com>
Authored: Thu May 5 15:27:02 2016 -0400
Committer: Nate Cole <ncole@hortonworks.com>
Committed: Mon May 9 17:58:53 2016 -0400

----------------------------------------------------------------------
 .../internal/HostComponentResourceProvider.java | 17 +++-
 .../HostComponentResourceProviderTest.java      | 98 +++++++++++++++++++-
 2 files changed, 110 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f66f08a9/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
index 83bfeaa..9d8389a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostComponentResourceProvider.java
@@ -779,6 +779,12 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
       }
     }
 
+    if (requests.isEmpty()) {
+      String msg = String.format("Skipping updating hosts: no matching requests for %s",
predicate);
+      LOG.info(msg);
+      throw new NoSuchResourceException(msg);
+    }
+
     RequestStageContainer requestStages = modifyResources(new Command<RequestStageContainer>()
{
       @Override
       public RequestStageContainer invoke() throws AmbariException {
@@ -789,11 +795,16 @@ public class HostComponentResourceProvider extends AbstractControllerResourcePro
             stageContainer = updateHostComponents(stages, requests, request.getRequestInfoProperties(),
                 runSmokeTest);
           } catch (Exception e) {
-            LOG.info("Caught an exception while updating host components, retrying : " +
e);
             if (--retriesRemaining == 0) {
-              e.printStackTrace();
-              throw new RuntimeException("Update Host request submission failed: " + e, e);
+              LOG.info("Caught an exception while updating host components, will not try
again: {}", e.getMessage(), e);
+              // !!! IllegalArgumentException results in a 400 response, RuntimeException
results in 500.
+              if (IllegalArgumentException.class.isInstance(e)) {
+                throw (IllegalArgumentException) e;
+              } else {
+                throw new RuntimeException("Update Host request submission failed: " + e,
e);
+              }
             } else {
+              LOG.info("Caught an exception while updating host components, retrying : "
+ e);
               try {
                 Thread.sleep(250);
               } catch (InterruptedException ie) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/f66f08a9/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
index 683a235..ef1b821 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostComponentResourceProviderTest.java
@@ -26,6 +26,7 @@ import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.lang.reflect.Field;
 import java.util.ArrayList;
@@ -44,6 +45,7 @@ import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.apache.ambari.server.controller.ResourceProviderFactory;
 import org.apache.ambari.server.controller.ServiceComponentHostRequest;
 import org.apache.ambari.server.controller.ServiceComponentHostResponse;
+import org.apache.ambari.server.controller.spi.NoSuchResourceException;
 import org.apache.ambari.server.controller.spi.Predicate;
 import org.apache.ambari.server.controller.spi.Request;
 import org.apache.ambari.server.controller.spi.RequestStatus;
@@ -67,11 +69,11 @@ import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-
-import com.google.inject.Injector;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
 
+import com.google.inject.Injector;
+
 /**
  * HostComponentResourceProvider tests.
  */
@@ -512,6 +514,98 @@ public class HostComponentResourceProviderTest {
     Assert.assertTrue(unsupported.isEmpty());
   }
 
+  @Test
+  public void testUpdateResourcesNothingToUpdate() throws Exception {
+    Authentication authentication = TestAuthenticationFactory.createServiceAdministrator();
+    Resource.Type type = Resource.Type.HostComponent;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    HostVersionDAO hostVersionDAO = createMock(HostVersionDAO.class);
+//    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+    ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
+    Injector injector = createNiceMock(Injector.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service = createNiceMock(Service.class);
+    ServiceComponent component = createNiceMock(ServiceComponent.class);
+    ServiceComponentHost componentHost = createNiceMock(ServiceComponentHost.class);
+    RequestStageContainer stageContainer = createNiceMock(RequestStageContainer.class);
+    MaintenanceStateHelper maintenanceStateHelper = createNiceMock(MaintenanceStateHelper.class);
+
+
+    Map<String, String> mapRequestProps = new HashMap<String, String>();
+    mapRequestProps.put("context", "Called from a test");
+
+    Set<ServiceComponentHostResponse> nameResponse = new HashSet<ServiceComponentHostResponse>();
+    nameResponse.add(new ServiceComponentHostResponse(
+        "Cluster102", "Service100", "Component100", "Component 100", "Host100", "INSTALLED",
"", "", "", null));
+
+    // set expectations
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.findServiceName(cluster, "Component100")).andReturn("Service100").anyTimes();
+    expect(clusters.getCluster("Cluster102")).andReturn(cluster).anyTimes();
+    expect(cluster.getClusterId()).andReturn(2L).anyTimes();
+    expect(cluster.getService("Service100")).andReturn(service).anyTimes();
+    expect(service.getServiceComponent("Component100")).andReturn(component).anyTimes();
+    expect(component.getServiceComponentHost("Host100")).andReturn(componentHost).anyTimes();
+    expect(component.getName()).andReturn("Component100").anyTimes();
+    expect(componentHost.getState()).andReturn(State.INSTALLED).anyTimes();
+
+    //Cluster is default type.  Maintenance mode is not being tested here so the default
is returned.
+    expect(maintenanceStateHelper.isOperationAllowed(Resource.Type.Cluster, componentHost)).andReturn(true).anyTimes();
+
+    expect(managementController.getHostComponents(
+        EasyMock.<Set<ServiceComponentHostRequest>>anyObject())).andReturn(Collections.<ServiceComponentHostResponse>emptySet()).once();
+
+    Map<String, Map<State, List<ServiceComponentHost>>> changedHosts =
new HashMap<String, Map<State, List<ServiceComponentHost>>>();
+    List<ServiceComponentHost> changedComponentHosts = new ArrayList<ServiceComponentHost>();
+    changedComponentHosts.add(componentHost);
+    changedHosts.put("Component100", Collections.singletonMap(State.STARTED, changedComponentHosts));
+
+    TestHostComponentResourceProvider provider =
+        new TestHostComponentResourceProvider(PropertyHelper.getPropertyIds(type),
+            PropertyHelper.getKeyPropertyIds(type),
+            managementController, injector);
+    provider.setFieldValue("maintenanceStateHelper", maintenanceStateHelper);
+    provider.setFieldValue("hostVersionDAO", hostVersionDAO);
+
+    expect(resourceProviderFactory.getHostComponentResourceProvider(EasyMock.<Set<String>>anyObject(),
+        EasyMock.<Map<Type,String>>anyObject(),
+        eq(managementController))).
+        andReturn(provider).anyTimes();
+
+    // replay
+    replay(managementController, resourceProviderFactory, clusters, cluster, service,
+        component, componentHost, stageContainer, maintenanceStateHelper);
+
+    SecurityContextHolder.getContext().setAuthentication(authentication);
+
+    Map<String, Object> properties = new LinkedHashMap<String, Object>();
+
+    properties.put(HostComponentResourceProvider.HOST_COMPONENT_STATE_PROPERTY_ID, "STARTED");
+
+    // create the request
+    Request request = PropertyHelper.getUpdateRequest(properties, mapRequestProps);
+
+    // update the cluster named Cluster102
+    Predicate predicate = new PredicateBuilder().property(
+        HostComponentResourceProvider.HOST_COMPONENT_CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").and().
+        property(HostComponentResourceProvider.HOST_COMPONENT_STATE_PROPERTY_ID).equals("INSTALLED").and().
+        property(HostComponentResourceProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID).equals("Component100").toPredicate();
+
+
+    try {
+      provider.updateResources(request, predicate);
+      fail("Expected exception when no resources are found to be updatable");
+    } catch (NoSuchResourceException e) {
+      // !!! expected
+    }
+
+
+    // verify
+    verify(managementController, resourceProviderFactory, stageContainer);
+  }
+
   // Used to directly call updateHostComponents on the resource provider.
   // This exists as a temporary solution as a result of moving updateHostComponents from
   // AmbariManagentControllerImpl to HostComponentResourceProvider.


Mime
View raw message