Package org.apache.ambari.server.controller.spi

Examples of org.apache.ambari.server.controller.spi.ResourceProvider


    HostGroupComponentEntity hostGroupComponent1 = createNiceMock(HostGroupComponentEntity.class);
    HostGroupComponentEntity hostGroupComponent2 = createNiceMock(HostGroupComponentEntity.class);
    HostGroupComponentEntity hostGroupComponent3 = createNiceMock(HostGroupComponentEntity.class);

    ServiceResourceProvider serviceResourceProvider = createStrictMock(ServiceResourceProvider.class);
    ResourceProvider componentResourceProvider = createStrictMock(ResourceProvider.class);
    ResourceProvider hostResourceProvider = createStrictMock(ResourceProvider.class);
    ResourceProvider hostComponentResourceProvider = createStrictMock(ResourceProvider.class);
    PersistKeyValueImpl persistKeyValue = createNiceMock(PersistKeyValueImpl.class);

    Capture<ClusterRequest> createClusterRequestCapture = new Capture<ClusterRequest>();
    Capture<Set<ClusterRequest>> updateClusterRequestCapture = new Capture<Set<ClusterRequest>>();
    Capture<Map<String, String>> updateClusterPropertyMapCapture = new Capture<Map<String, String>>();
    Capture<Set<ClusterRequest>> updateClusterRequestCapture2 = new Capture<Set<ClusterRequest>>();
    Capture<Map<String, String>> updateClusterPropertyMapCapture2 = new Capture<Map<String, String>>();
    Capture<Set<ClusterRequest>> updateClusterRequestCapture3 = new Capture<Set<ClusterRequest>>();
    Capture<Map<String, String>> updateClusterPropertyMapCapture3 = new Capture<Map<String, String>>();

    Capture<Request> serviceRequestCapture = new Capture<Request>();
    Capture<Request> componentRequestCapture = new Capture<Request>();
    Capture<Request> componentRequestCapture2 = new Capture<Request>();
    Capture<Request> hostRequestCapture = new Capture<Request>();
    Capture<Request> hostComponentRequestCapture = new Capture<Request>();

    Set<StackServiceResponse> stackServiceResponses = new LinkedHashSet<StackServiceResponse>();
    stackServiceResponses.add(stackServiceResponse1);
    stackServiceResponses.add(stackServiceResponse2);

    // service1 has 2 components
    Set<StackServiceComponentResponse> stackServiceComponentResponses1 = new LinkedHashSet<StackServiceComponentResponse>();
    stackServiceComponentResponses1.add(stackServiceComponentResponse1);
    stackServiceComponentResponses1.add(stackServiceComponentResponse2);

    // service2 has 1 components
    Set<StackServiceComponentResponse> stackServiceComponentResponses2 = new LinkedHashSet<StackServiceComponentResponse>();
    stackServiceComponentResponses2.add(stackServiceComponentResponse3);

    // service1 has 1 config
    Set<StackConfigurationResponse> stackConfigurationResponses1 = new LinkedHashSet<StackConfigurationResponse>();
    stackConfigurationResponses1.add(stackConfigurationResponse1);

    // service2 has 3 config
    Set<StackConfigurationResponse> stackConfigurationResponses2 = new LinkedHashSet<StackConfigurationResponse>();
    stackConfigurationResponses2.add(stackConfigurationResponse2);
    stackConfigurationResponses2.add(stackConfigurationResponse3);
    stackConfigurationResponses2.add(stackConfigurationResponse4);

    Collection<HostGroupComponentEntity> hostGroupComponents = new LinkedHashSet<HostGroupComponentEntity>();
    hostGroupComponents.add(hostGroupComponent1);
    hostGroupComponents.add(hostGroupComponent2);
    hostGroupComponents.add(hostGroupComponent3);

    // request properties
    Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>();
    Map<String, Object> properties = new LinkedHashMap<String, Object>();

    properties.put(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID, "c1");
    properties.put(ClusterResourceProvider.BLUEPRINT_PROPERTY_ID, blueprintName);
    propertySet.add(properties);

    Collection<Map<String, Object>> hostGroups = new ArrayList<Map<String, Object>>();
    Map<String, Object> hostGroupProperties = new HashMap<String, Object>();
    hostGroups.add(hostGroupProperties);
    hostGroupProperties.put("name", "group1");
    Collection<Map<String, String>> hostGroupHosts = new ArrayList<Map<String, String>>();
    hostGroupProperties.put("hosts", hostGroupHosts);
    Map<String, String> hostGroupHostProperties = new HashMap<String, String>();
    hostGroupHostProperties.put("fqdn", "host.domain");
    hostGroupHosts.add(hostGroupHostProperties);
    properties.put("host-groups", hostGroups);

    // blueprint cluster configuration properties
    Map<String, String> blueprintConfigProperties = new HashMap<String, String>();
    blueprintConfigProperties.put("property1", "value2");
    blueprintConfigProperties.put("new.property", "new.property.value");

    // expectations
    expect(request.getProperties()).andReturn(propertySet).anyTimes();
    expect(blueprintDAO.findByName(blueprintName)).andReturn(blueprint);
    expect(blueprint.getStackName()).andReturn(stackName);
    expect(blueprint.getStackVersion()).andReturn(stackVersion);
    expect(blueprint.getConfigurations()).andReturn(Collections.<BlueprintConfigEntity>singletonList(blueprintConfig));

    expect(managementController.getStackServices(capture(stackServiceRequestCapture))).andReturn(stackServiceResponses);
    expect(stackServiceResponse1.getServiceName()).andReturn("service1");
    expect(stackServiceResponse2.getServiceName()).andReturn("service2");

    expect(managementController.getStackComponents(capture(serviceComponentRequestCapture1))).
        andReturn(stackServiceComponentResponses1);
    expect(stackServiceComponentResponse1.getComponentName()).andReturn("component1");
    expect(stackServiceComponentResponse2.getComponentName()).andReturn("component2");

    expect(managementController.getStackConfigurations(capture(serviceConfigurationRequestCapture1))).
        andReturn(stackConfigurationResponses1);
    expect(stackConfigurationResponse1.getType()).andReturn("core-site.xml");
    expect(stackConfigurationResponse1.getPropertyName()).andReturn("property1");
    expect(stackConfigurationResponse1.getPropertyValue()).andReturn("value1");

    expect(managementController.getStackComponents(capture(serviceComponentRequestCapture2))).
        andReturn(stackServiceComponentResponses2);
    expect(stackServiceComponentResponse3.getComponentName()).andReturn("component3");

    expect(managementController.getStackConfigurations(capture(serviceConfigurationRequestCapture2))).
        andReturn(stackConfigurationResponses2);
    expect(stackConfigurationResponse2.getType()).andReturn("hdfs-site.xml");
    expect(stackConfigurationResponse2.getPropertyName()).andReturn("property2");
    expect(stackConfigurationResponse2.getPropertyValue()).andReturn("value2");

    expect(stackConfigurationResponse3.getType()).andReturn("global.xml");
    expect(stackConfigurationResponse3.getPropertyName()).andReturn("oozie_user");
    expect(stackConfigurationResponse3.getPropertyValue()).andReturn("oozie");

    expect(stackConfigurationResponse4.getType()).andReturn("core-site.xml");
    expect(stackConfigurationResponse4.getPropertyName()).andReturn("property3");
    expect(stackConfigurationResponse4.getPropertyValue()).andReturn("value3");

    expect(blueprintConfig.getBlueprintName()).andReturn("test-blueprint").anyTimes();
    expect(blueprintConfig.getType()).andReturn("core-site").anyTimes();
    expect(blueprintConfig.getConfigData()).andReturn(new Gson().toJson(blueprintConfigProperties));

    expect(blueprint.getHostGroups()).andReturn(Collections.singleton(hostGroup));
    expect(hostGroup.getName()).andReturn("group1");
    expect(hostGroup.getComponents()).andReturn(hostGroupComponents);
    expect(hostGroupComponent1.getName()).andReturn("component1");
    expect(hostGroupComponent2.getName()).andReturn("component2");
    expect(hostGroupComponent3.getName()).andReturn("component3");

    managementController.createCluster(capture(createClusterRequestCapture));
    expect(managementController.updateClusters(capture(updateClusterRequestCapture),
        capture(updateClusterPropertyMapCapture))).andReturn(null);
    expect(managementController.updateClusters(capture(updateClusterRequestCapture2),
        capture(updateClusterPropertyMapCapture2))).andReturn(null);
    expect(managementController.updateClusters(capture(updateClusterRequestCapture3),
        capture(updateClusterPropertyMapCapture3))).andReturn(null);

    expect(serviceResourceProvider.createResources(capture(serviceRequestCapture))).andReturn(null);
    expect(componentResourceProvider.createResources(capture(componentRequestCapture))).andReturn(null);
    expect(componentResourceProvider.createResources(capture(componentRequestCapture2))).andReturn(null);
    expect(hostResourceProvider.createResources(capture(hostRequestCapture))).andReturn(null);
    expect(hostComponentResourceProvider.createResources(capture(hostComponentRequestCapture))).andReturn(null);

    expect(serviceResourceProvider.installAndStart("c1")).andReturn(response);

    persistKeyValue.put("CLUSTER_CURRENT_STATUS", "{\"clusterState\":\"CLUSTER_STARTED_5\"}");

    replay(blueprintDAO, managementController, request, response, blueprint, stackServiceResponse1, stackServiceResponse2,
           stackServiceComponentResponse1, stackServiceComponentResponse2, stackServiceComponentResponse3,
           stackConfigurationResponse1, stackConfigurationResponse2, stackConfigurationResponse3, stackConfigurationResponse4,
           blueprintConfig, hostGroup, hostGroupComponent1, hostGroupComponent2, hostGroupComponent3, serviceResourceProvider,
           componentResourceProvider, hostResourceProvider, hostComponentResourceProvider, persistKeyValue);

    // test
    ClusterResourceProvider.injectBlueprintDAO(blueprintDAO);
    PersistKeyValueService.init(persistKeyValue);
    ResourceProvider provider = new TestClusterResourceProvider(
        managementController, serviceResourceProvider, componentResourceProvider,
        hostResourceProvider, hostComponentResourceProvider);

    RequestStatus requestStatus = provider.createResources(request);

    assertEquals(RequestStatus.Status.InProgress, requestStatus.getStatus());

    Set<StackServiceRequest> stackServiceRequests = stackServiceRequestCapture.getValue();
    assertEquals(1, stackServiceRequests.size());
View Full Code Here


    expect(managementController.getClusters(EasyMock.<Set<ClusterRequest>>anyObject())).andReturn(idResponse).once();

    // replay
    replay(managementController);

    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
        type,
        PropertyHelper.getPropertyIds(type),
        PropertyHelper.getKeyPropertyIds(type),
        managementController);

    Set<String> propertyIds = new HashSet<String>();

    propertyIds.add(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID);
    propertyIds.add(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID);

    // create the request
    Request request = PropertyHelper.getReadRequest(propertyIds);

    // get all ... no predicate
    Set<Resource> resources = provider.getResources(request, null);

    Assert.assertEquals(5, resources.size());
    for (Resource resource : resources) {
      Long id = (Long) resource.getPropertyValue(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID);
      String name = (String) resource.getPropertyValue(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID);
      Assert.assertEquals(name, "Cluster" + id);
    }

    // get cluster named Cluster102
    Predicate predicate =
        new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").
            toPredicate();
    resources = provider.getResources(request, predicate);

    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(102L, resources.iterator().next().
        getPropertyValue(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID));
    Assert.assertEquals("Cluster102", resources.iterator().next().
        getPropertyValue(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID));

    // get cluster with id == 103
    predicate =
        new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID).equals(103L).toPredicate();
    resources = provider.getResources(request, predicate);

    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(103L, resources.iterator().next().
        getPropertyValue(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID));
    Assert.assertEquals("Cluster103", resources.iterator().next().
View Full Code Here

        andReturn(response).once();

    // replay
    replay(managementController, response);

    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
        type,
        PropertyHelper.getPropertyIds(type),
        PropertyHelper.getKeyPropertyIds(type),
        managementController);

    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();

    ((ObservableResourceProvider)provider).addObserver(observer);

    Map<String, Object> properties = new LinkedHashMap<String, Object>();

    properties.put(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID, "HDP-0.1");

    // create the request
    Request request = PropertyHelper.getUpdateRequest(properties, mapRequestProps);

    // update the cluster named Cluster102
    Predicate  predicate = new PredicateBuilder().property(
        ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").toPredicate();
    provider.updateResources(request, predicate);

    // update the cluster where id == 103
    predicate = new PredicateBuilder().property(
        ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID).equals(103L).toPredicate();
    provider.updateResources(request, predicate);

    ResourceProviderEvent lastEvent = observer.getLastEvent();
    Assert.assertNotNull(lastEvent);
    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
    Assert.assertEquals(ResourceProviderEvent.Type.Update, lastEvent.getType());
View Full Code Here

    Request request = new RequestImpl(null, propertySet, mapRequestProps, null);

    Predicate  predicate = new PredicateBuilder().property(
        ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").toPredicate();
   
    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
        Resource.Type.Cluster,
        PropertyHelper.getPropertyIds(Resource.Type.Cluster),
        PropertyHelper.getKeyPropertyIds(Resource.Type.Cluster),
        managementController);

    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();

    ((ObservableResourceProvider)provider).addObserver(observer);

    provider.updateResources(request, predicate);

    ResourceProviderEvent lastEvent = observer.getLastEvent();
    Assert.assertNotNull(lastEvent);
    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
    Assert.assertEquals(ResourceProviderEvent.Type.Update, lastEvent.getType());
View Full Code Here

        AbstractResourceProviderTest.Matcher.getClusterRequest(103L, null, null, null));

    // replay
    replay(managementController, response);

    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
        type,
        PropertyHelper.getPropertyIds(type),
        PropertyHelper.getKeyPropertyIds(type),
        managementController);

    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();

    ((ObservableResourceProvider)provider).addObserver(observer);

    // delete the cluster named Cluster102
    Predicate  predicate = new PredicateBuilder().property(
        ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").toPredicate();
    provider.deleteResources(predicate);

    // delete the cluster where id == 103
    predicate = new PredicateBuilder().property(
        ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID).equals(103L).toPredicate();
    provider.deleteResources(predicate);

    ResourceProviderEvent lastEvent = observer.getLastEvent();
    Assert.assertNotNull(lastEvent);
    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
    Assert.assertEquals(ResourceProviderEvent.Type.Delete, lastEvent.getType());
View Full Code Here

  public void testGetResourceProvider() throws Exception {
    ClusterDefinition clusterDefinition = new ClusterDefinition(new TestStateProvider(), new TestClusterDefinitionProvider(), new TestHostInfoProvider());
    clusterDefinition.setServiceState("HDFS", "INSTALLED");

    for (Resource.Type type : types) {
      ResourceProvider provider = AbstractResourceProvider.getResourceProvider(type, clusterDefinition);
      Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(), null);

      for (Resource resource : resources) {
        Assert.assertEquals(type, resource.getType());
      }
    }
View Full Code Here

    managementController.createCluster(Matchers.clusterRequest(99L, null, "HDP-0.1", null));

    // replay
    replay(managementController, response);

    ResourceProvider provider = ResourceProviderImpl.getResourceProvider(
        type,
        PropertyHelper.getPropertyIds(type),
        PropertyHelper.getKeyPropertyIds(type),
        managementController);

    TestObserver observer = new TestObserver();

    ((ObservableResourceProvider)provider).addObserver(observer);

    // add the property map to a set for the request.  add more maps for multiple creates
    Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>();

    // Cluster 1: create a map of properties for the request
    Map<String, Object> properties = new LinkedHashMap<String, Object>();

    // add the cluster name to the properties map
    properties.put(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID, "Cluster100");

    // add the version to the properties map
    properties.put(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID, "HDP-0.1");

    propertySet.add(properties);

    // Cluster 2: create a map of properties for the request
    properties = new LinkedHashMap<String, Object>();

    // add the cluster id to the properties map
    properties.put(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID, 99L);

    // add the version to the properties map
    properties.put(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID, "HDP-0.1");

    propertySet.add(properties);

    // create the request
    Request request = PropertyHelper.getCreateRequest(propertySet);

    provider.createResources(request);

    ResourceProviderEvent lastEvent = observer.getLastEvent();
    Assert.assertNotNull(lastEvent);
    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
    Assert.assertEquals(ResourceProviderEvent.Type.Create, lastEvent.getType());
View Full Code Here

    expect(managementController.getClusters(anyObject(Set.class))).andReturn(idResponse).once();

    // replay
    replay(managementController);

    ResourceProvider provider = ResourceProviderImpl.getResourceProvider(
        type,
        PropertyHelper.getPropertyIds(type),
        PropertyHelper.getKeyPropertyIds(type),
        managementController);

    Set<String> propertyIds = new HashSet<String>();

    propertyIds.add(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID);
    propertyIds.add(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID);

    // create the request
    Request request = PropertyHelper.getReadRequest(propertyIds);

    // get all ... no predicate
    Set<Resource> resources = provider.getResources(request, null);

    Assert.assertEquals(5, resources.size());
    for (Resource resource : resources) {
      Long id = (Long) resource.getPropertyValue(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID);
      String name = (String) resource.getPropertyValue(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID);
      Assert.assertEquals(name, "Cluster" + id);
    }

    // get cluster named Cluster102
    Predicate  predicate = new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").toPredicate();
    resources = provider.getResources(request, predicate);

    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(102L, resources.iterator().next().getPropertyValue(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID));
    Assert.assertEquals("Cluster102", resources.iterator().next().getPropertyValue(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID));

    // get cluster with id == 103
    predicate = new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID).equals(103L).toPredicate();
    resources = provider.getResources(request, predicate);

    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(103L, resources.iterator().next().getPropertyValue(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID));
    Assert.assertEquals("Cluster103", resources.iterator().next().getPropertyValue(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID));
View Full Code Here

    expect(managementController.updateCluster(Matchers.clusterRequest(103L, null, "HDP-0.1", null))).andReturn(response).once();

    // replay
    replay(managementController, response);

    ResourceProvider provider = ResourceProviderImpl.getResourceProvider(
        type,
        PropertyHelper.getPropertyIds(type),
        PropertyHelper.getKeyPropertyIds(type),
        managementController);

    TestObserver observer = new TestObserver();

    ((ObservableResourceProvider)provider).addObserver(observer);

    Map<String, Object> properties = new LinkedHashMap<String, Object>();

    properties.put(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID, "HDP-0.1");

    // create the request
    Request request = PropertyHelper.getUpdateRequest(properties);

    // update the cluster named Cluster102
    Predicate  predicate = new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").toPredicate();
    provider.updateResources(request, predicate);

    // update the cluster where id == 103
    predicate = new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID).equals(103L).toPredicate();
    provider.updateResources(request, predicate);

    ResourceProviderEvent lastEvent = observer.getLastEvent();
    Assert.assertNotNull(lastEvent);
    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
    Assert.assertEquals(ResourceProviderEvent.Type.Update, lastEvent.getType());
View Full Code Here

    managementController.deleteCluster(Matchers.clusterRequest(103L, null, null, null));

    // replay
    replay(managementController, response);

    ResourceProvider provider = ResourceProviderImpl.getResourceProvider(
        type,
        PropertyHelper.getPropertyIds(type),
        PropertyHelper.getKeyPropertyIds(type),
        managementController);

    TestObserver observer = new TestObserver();

    ((ObservableResourceProvider)provider).addObserver(observer);

    // delete the cluster named Cluster102
    Predicate  predicate = new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").toPredicate();
    provider.deleteResources(predicate);

    // delete the cluster where id == 103
    predicate = new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID).equals(103L).toPredicate();
    provider.deleteResources(predicate);

    ResourceProviderEvent lastEvent = observer.getLastEvent();
    Assert.assertNotNull(lastEvent);
    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
    Assert.assertEquals(ResourceProviderEvent.Type.Delete, lastEvent.getType());
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.controller.spi.ResourceProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.