You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vb...@apache.org on 2014/07/10 19:02:55 UTC
git commit: AMBARI-6455. On cluster with HA enabled,
SNameNode state via api is "STARTED".(vbrodetskyi)
Repository: ambari
Updated Branches:
refs/heads/trunk 05630b232 -> edf653280
AMBARI-6455. On cluster with HA enabled, SNameNode state via api is "STARTED".(vbrodetskyi)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/edf65328
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/edf65328
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/edf65328
Branch: refs/heads/trunk
Commit: edf653280eb24358d902144523b454fbcf0dfe96
Parents: 05630b2
Author: Vitaly Brodetskyi <vb...@hortonworks.com>
Authored: Thu Jul 10 19:42:51 2014 +0300
Committer: Vitaly Brodetskyi <vb...@hortonworks.com>
Committed: Thu Jul 10 19:42:51 2014 +0300
----------------------------------------------------------------------
.../internal/ComponentResourceProvider.java | 89 ++++++-
.../internal/ComponentResourceProviderTest.java | 241 ++++++++++++++++++-
2 files changed, 317 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/edf65328/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
index 4c74b64..c6b0970 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ComponentResourceProvider.java
@@ -206,10 +206,15 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide
public RequestStatus deleteResources(Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+ final Set<ServiceComponentRequest> requests = new HashSet<ServiceComponentRequest>();
+ for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
+ requests.add(getRequest(propertyMap));
+ }
+ final Predicate finalPredicate = predicate;
RequestStatusResponse response = modifyResources(new Command<RequestStatusResponse>() {
@Override
public RequestStatusResponse invoke() throws AmbariException {
- return deleteComponents();
+ return deleteComponents(requests);
}
});
@@ -838,8 +843,84 @@ public class ComponentResourceProvider extends AbstractControllerResourceProvide
ignoredScHosts, runSmokeTest, false);
}
- // Delete the components for the given request.
- protected RequestStatusResponse deleteComponents() throws AmbariException {
- throw new AmbariException("Delete components not supported");
+ protected RequestStatusResponse deleteComponents(Set<ServiceComponentRequest> requests) throws AmbariException {
+ AmbariManagementController controller = getManagementController();
+ Clusters clusters = controller.getClusters();
+ AmbariMetaInfo ambariMetaInfo = controller.getAmbariMetaInfo();
+
+ for (ServiceComponentRequest request : requests) {
+
+ if (request.getClusterName() == null || request.getClusterName().isEmpty()
+ || request.getComponentName() == null || request.getComponentName().isEmpty()) {
+ throw new IllegalArgumentException("Invalid arguments"
+ + ", clustername and componentname should be"
+ + " non-null and non-empty when trying to create a"
+ + " component");
+ }
+
+ Cluster cluster;
+ try {
+ cluster = clusters.getCluster(request.getClusterName());
+ } catch (ClusterNotFoundException e) {
+ throw new ParentObjectNotFoundException(
+ "Attempted to add a component to a cluster which doesn't exist:", e);
+ }
+
+ if (request.getServiceName() == null || request.getServiceName().isEmpty()) {
+ StackId stackId = cluster.getDesiredStackVersion();
+ String serviceName = ambariMetaInfo.getComponentToService(stackId.getStackName(),
+ stackId.getStackVersion(), request.getComponentName());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Looking up service name for component"
+ + ", componentName=" + request.getComponentName()
+ + ", serviceName=" + serviceName);
+ }
+
+ if (serviceName == null || serviceName.isEmpty()) {
+ throw new AmbariException("Could not find service for component"
+ + ", componentName=" + request.getComponentName()
+ + ", clusterName=" + cluster.getClusterName()
+ + ", stackInfo=" + stackId.getStackId());
+ }
+ request.setServiceName(serviceName);
+ }
+
+ Service s;
+ try {
+ s = cluster.getService(request.getServiceName());
+ } catch (ServiceNotFoundException e) {
+ throw new ParentObjectNotFoundException(
+ "Attempted to add a component to a service which doesn't exist:", e);
+ }
+
+ ServiceComponent sc = s.getServiceComponent(request.getComponentName());
+ if (sc != null) {
+ if (!sc.getDesiredState().isRemovableState()) {
+ throw new AmbariException("Could not delete service component from cluster. To remove service component," +
+ " it must be in DISABLED/INIT/INSTALLED/INSTALL_FAILED/UNKNOWN/UNINSTALLED/INSTALLING state."
+ + ", clusterName=" + request.getClusterName()
+ + ", serviceName=" + request.getServiceName()
+ + ", componentName=" + request.getComponentName()
+ + ", current state=" + sc.getDesiredState() + ".");
+ }
+
+ for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+ if (!sch.getDesiredState().isRemovableState()) {
+ throw new AmbariException("Found non removable host component when trying to delete service component." +
+ " To remove host component, it must be in DISABLED/INIT/INSTALLED/INSTALL_FAILED/UNKNOWN" +
+ "/UNINSTALLED/INSTALLING state."
+ + ", clusterName=" + request.getClusterName()
+ + ", serviceName=" + request.getServiceName()
+ + ", componentName=" + request.getComponentName()
+ + ", current state=" + sc.getDesiredState() + ".");
+
+ }
+ }
+
+ s.deleteServiceComponent(request.getComponentName());
+ }
+ }
+ return null;
}
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/edf65328/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
index e068520..1455c52 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
@@ -21,6 +21,7 @@ package org.apache.ambari.server.controller.internal;
import static org.easymock.EasyMock.anyBoolean;
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMockBuilder;
+import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.createMock;
@@ -350,32 +351,187 @@ public class ComponentResourceProviderTest {
requestStatusResponse, stackId, maintenanceStateHelper);
}
+ public void testSuccessDeleteResources() throws Exception {
+ Resource.Type type = Resource.Type.Component;
+
+ AmbariManagementController managementController = createMock(AmbariManagementController.class);
+ MaintenanceStateHelper maintenanceStateHelper = createNiceMock(MaintenanceStateHelper.class);
+
+ Clusters clusters = createNiceMock(Clusters.class);
+ Cluster cluster = createNiceMock(Cluster.class);
+ Service service = createNiceMock(Service.class);
+ AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+ ServiceComponent serviceComponent = createNiceMock(ServiceComponent.class);
+ ServiceComponentHost serviceComponentHost = createNiceMock(ServiceComponentHost.class);
+ StackId stackId = createNiceMock(StackId.class);
+
+ Map<String, ServiceComponentHost> serviceComponentHosts = new HashMap<String, ServiceComponentHost>();
+ serviceComponentHosts.put("", serviceComponentHost);
+
+ expect(managementController.getClusters()).andReturn(clusters);
+ expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo);
+
+ expect(clusters.getCluster("Cluster100")).andReturn(cluster);
+ expect(cluster.getService("Service100")).andReturn(service);
+
+ expect(service.getServiceComponent("Component100")).andReturn(serviceComponent);
+
+ expect(serviceComponent.getDesiredState()).andReturn(State.INSTALLED);
+ expect(serviceComponent.getServiceComponentHosts()).andReturn(serviceComponentHosts);
+
+ expect(serviceComponentHost.getDesiredState()).andReturn(State.INSTALLED);
+
+
+ service.deleteServiceComponent("Component100");
+ expectLastCall().once();
+ // replay
+
+ replay(managementController, clusters, cluster, service, stackId, ambariMetaInfo,
+ serviceComponent, serviceComponentHost, maintenanceStateHelper);
+
+ ResourceProvider provider = new ComponentResourceProvider(
+ PropertyHelper.getPropertyIds(type),
+ PropertyHelper.getKeyPropertyIds(type),
+ managementController, maintenanceStateHelper);
+
+ AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
+
+ ((ObservableResourceProvider)provider).addObserver(observer);
+
+
+ Predicate predicate = new PredicateBuilder()
+ .property(ComponentResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID)
+ .equals("Cluster100")
+ .and()
+ .property(ComponentResourceProvider.COMPONENT_SERVICE_NAME_PROPERTY_ID)
+ .equals("Service100")
+ .and()
+ .property(ComponentResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID)
+ .equals("Component100").toPredicate();
+
+ provider.deleteResources(predicate);
+
+ // verify
+ verify(managementController, service);
+ }
+
@Test
- public void testDeleteResources() throws Exception {
+ public void testDeleteResourcesWithEmptyClusterComponentNames() throws Exception {
Resource.Type type = Resource.Type.Component;
+ AmbariManagementController managementController = createMock(AmbariManagementController.class);
MaintenanceStateHelper maintenanceStateHelper = createNiceMock(MaintenanceStateHelper.class);
+
+ Clusters clusters = createNiceMock(Clusters.class);
+ AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+
+ expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+ expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+
+ replay(managementController, clusters, ambariMetaInfo, maintenanceStateHelper);
+
+ ResourceProvider provider = new ComponentResourceProvider(
+ PropertyHelper.getPropertyIds(type),
+ PropertyHelper.getKeyPropertyIds(type),
+ managementController,maintenanceStateHelper);
+
+ AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
+
+ ((ObservableResourceProvider)provider).addObserver(observer);
+
+ Predicate predicate1 = new PredicateBuilder()
+ .property(ComponentResourceProvider.COMPONENT_SERVICE_NAME_PROPERTY_ID)
+ .equals("Service100")
+ .and()
+ .property(ComponentResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID)
+ .equals("Component100").toPredicate();
+
+ try {
+ provider.deleteResources(predicate1);
+ Assert.fail("Expected IllegalArgumentException exception.");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ Predicate predicate2 = new PredicateBuilder()
+ .property(ComponentResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID)
+ .equals("Cluster100")
+ .and()
+ .property(ComponentResourceProvider.COMPONENT_SERVICE_NAME_PROPERTY_ID)
+ .equals("Service100")
+ .and().toPredicate();
+
+ try {
+ provider.deleteResources(predicate2);
+ Assert.fail("Expected IllegalArgumentException exception.");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ // verify
+ verify(managementController);
+ }
+
+ @Test
+ public void testDeleteResourcesWithServiceComponentStarted() throws Exception {
+ Resource.Type type = Resource.Type.Component;
+
AmbariManagementController managementController = createMock(AmbariManagementController.class);
+ MaintenanceStateHelper maintenanceStateHelper = createNiceMock(MaintenanceStateHelper.class);
+
+ Clusters clusters = createNiceMock(Clusters.class);
+ Cluster cluster = createNiceMock(Cluster.class);
+ Service service = createNiceMock(Service.class);
+ AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+ ServiceComponent serviceComponent = createNiceMock(ServiceComponent.class);
+ ServiceComponentHost serviceComponentHost = createNiceMock(ServiceComponentHost.class);
+ StackId stackId = createNiceMock(StackId.class);
+
+ Map<String, ServiceComponentHost> serviceComponentHosts = new HashMap<String, ServiceComponentHost>();
+ serviceComponentHosts.put("", serviceComponentHost);
+
+ expect(managementController.getClusters()).andReturn(clusters);
+ expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo);
+
+ expect(clusters.getCluster("Cluster100")).andReturn(cluster);
+ expect(cluster.getService("Service100")).andReturn(service);
+
+ expect(service.getServiceComponent("Component100")).andReturn(serviceComponent);
+
+ expect(serviceComponent.getDesiredState()).andReturn(State.STARTED);
+ expect(serviceComponent.getServiceComponentHosts()).andReturn(serviceComponentHosts);
+
+ expect(serviceComponentHost.getDesiredState()).andReturn(State.INSTALLED);
+
// replay
- replay(managementController);
+ replay(managementController, clusters, cluster, service, stackId, ambariMetaInfo,
+ serviceComponent, serviceComponentHost, maintenanceStateHelper);
ResourceProvider provider = new ComponentResourceProvider(
- PropertyHelper.getPropertyIds(type),
- PropertyHelper.getKeyPropertyIds(type),
- managementController, maintenanceStateHelper);
+ PropertyHelper.getPropertyIds(type),
+ PropertyHelper.getKeyPropertyIds(type),
+ managementController, maintenanceStateHelper);
AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
((ObservableResourceProvider)provider).addObserver(observer);
- Predicate predicate = new PredicateBuilder().property(
- ComponentResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID).equals("Component100").toPredicate();
+ Predicate predicate = new PredicateBuilder()
+ .property(ComponentResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID)
+ .equals("Cluster100")
+ .and()
+ .property(ComponentResourceProvider.COMPONENT_SERVICE_NAME_PROPERTY_ID)
+ .equals("Service100")
+ .and()
+ .property(ComponentResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID)
+ .equals("Component100").toPredicate();
+
try {
provider.deleteResources(predicate);
Assert.fail("Expected exception.");
- } catch (Exception e) {
- // expected
+ } catch(Exception e) {
+ //expected
}
// verify
@@ -383,6 +539,73 @@ public class ComponentResourceProviderTest {
}
@Test
+ public void testDeleteResourcesWithServiceComponentHostStarted() throws Exception {
+ Resource.Type type = Resource.Type.Component;
+
+ AmbariManagementController managementController = createMock(AmbariManagementController.class);
+ MaintenanceStateHelper maintenanceStateHelper = createNiceMock(MaintenanceStateHelper.class);
+
+ Clusters clusters = createNiceMock(Clusters.class);
+ Cluster cluster = createNiceMock(Cluster.class);
+ Service service = createNiceMock(Service.class);
+ AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+ ServiceComponent serviceComponent = createNiceMock(ServiceComponent.class);
+ ServiceComponentHost serviceComponentHost = createNiceMock(ServiceComponentHost.class);
+ StackId stackId = createNiceMock(StackId.class);
+
+ Map<String, ServiceComponentHost> serviceComponentHosts = new HashMap<String, ServiceComponentHost>();
+ serviceComponentHosts.put("", serviceComponentHost);
+
+ expect(managementController.getClusters()).andReturn(clusters);
+ expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo);
+
+ expect(clusters.getCluster("Cluster100")).andReturn(cluster);
+ expect(cluster.getService("Service100")).andReturn(service);
+
+ expect(service.getServiceComponent("Component100")).andReturn(serviceComponent);
+
+ expect(serviceComponent.getDesiredState()).andReturn(State.INSTALLED);
+ expect(serviceComponent.getServiceComponentHosts()).andReturn(serviceComponentHosts);
+
+ expect(serviceComponentHost.getDesiredState()).andReturn(State.STARTED);
+
+
+ // replay
+ replay(managementController, clusters, cluster, service, stackId, ambariMetaInfo,
+ serviceComponent, serviceComponentHost, maintenanceStateHelper);
+
+ ResourceProvider provider = new ComponentResourceProvider(
+ PropertyHelper.getPropertyIds(type),
+ PropertyHelper.getKeyPropertyIds(type),
+ managementController,maintenanceStateHelper);
+
+ AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
+
+ ((ObservableResourceProvider)provider).addObserver(observer);
+
+ Predicate predicate = new PredicateBuilder()
+ .property(ComponentResourceProvider.COMPONENT_CLUSTER_NAME_PROPERTY_ID)
+ .equals("Cluster100")
+ .and()
+ .property(ComponentResourceProvider.COMPONENT_SERVICE_NAME_PROPERTY_ID)
+ .equals("Service100")
+ .and()
+ .property(ComponentResourceProvider.COMPONENT_COMPONENT_NAME_PROPERTY_ID)
+ .equals("Component100").toPredicate();
+
+ try {
+ provider.deleteResources(predicate);
+ Assert.fail("Expected exception.");
+ } catch(Exception e) {
+ //expected
+ }
+
+ // verify
+ verify(managementController);
+ }
+
+
+ @Test
public void testGetComponents() throws Exception {
// member state mocks
AmbariManagementController managementController = createMock(AmbariManagementController.class);