Package org.apache.ambari.server.api.resources

Examples of org.apache.ambari.server.api.resources.ResourceInstance


    verify(resource, resourceDefinition, controller, schema, serverRequest);
  }

  @Test
  public void testCreate__MultipleResources() throws Exception {
    ResourceInstance resource = createMock(ResourceInstance.class);
    ResourceDefinition resourceDefinition = createMock(ResourceDefinition.class);
    ClusterController controller = createMock(ClusterController.class);
    Schema schema = createMock(Schema.class);
    Request serverRequest = createStrictMock(Request.class);

    String clusterId = "clusterId";
    String serviceId = "serviceId";


    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
    mapResourceIds.put(Resource.Type.Cluster, "clusterId");
    mapResourceIds.put(Resource.Type.Service, "serviceId");

    Set<Map<String, Object>> setProperties = new HashSet<Map<String, Object>>();

    Map<String, Object> mapResourceProps1 = new HashMap<String, Object>();
    mapResourceProps1.put(clusterId, "clusterId");
    mapResourceProps1.put(serviceId, "serviceId");
    mapResourceProps1.put(PropertyHelper.getPropertyId("foo", "bar"), "value");

    Map<String, Object> mapResourceProps2 = new HashMap<String, Object>();
    mapResourceProps2.put(clusterId, "clusterId");
    mapResourceProps2.put(serviceId, "serviceId2");
    mapResourceProps2.put(PropertyHelper.getPropertyId("foo", "bar2"), "value2");

    setProperties.add(mapResourceProps1);
    setProperties.add(mapResourceProps2);

    //expectations
    expect(resource.getIds()).andReturn(mapResourceIds);
    expect(resource.getResourceDefinition()).andReturn(resourceDefinition);
    expect(resourceDefinition.getType()).andReturn(Resource.Type.Component);
    expect(controller.getSchema(Resource.Type.Component)).andReturn(schema);
    expect(schema.getKeyPropertyId(Resource.Type.Cluster)).andReturn(clusterId).times(2);
    expect(schema.getKeyPropertyId(Resource.Type.Service)).andReturn(serviceId).times(2);
View Full Code Here


    verify(resource, resourceDefinition, controller, schema, serverRequest);
  }

  @Test
  public void testUpdate() throws Exception {
    ResourceInstance resource = createMock(ResourceInstance.class);
    ResourceDefinition resourceDefinition = createMock(ResourceDefinition.class);
    ClusterController controller = createMock(ClusterController.class);
    Schema schema = createMock(Schema.class);
    Request serverRequest = createStrictMock(Request.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);

    Set<Map<String, Object>> setProperties = new HashSet<Map<String, Object>>();
    Map<String, Object> mapProperties = new HashMap<String, Object>();
    mapProperties.put(PropertyHelper.getPropertyId("foo", "bar"), "value");
    setProperties.add(mapProperties);

    //expectations
    expect(resource.getResourceDefinition()).andReturn(resourceDefinition);
    expect(resourceDefinition.getType()).andReturn(Resource.Type.Component);
    expect(resource.getQuery()).andReturn(query);
    expect(query.getPredicate()).andReturn(predicate);

    expect(controller.updateResources(Resource.Type.Component, serverRequest, predicate)).andReturn(new RequestStatusImpl(null));

    replay(resource, resourceDefinition, controller, schema, serverRequest, query, predicate);
View Full Code Here

    verify(resource, resourceDefinition, controller, schema, serverRequest, query, predicate);
  }

  @Test
  public void testDelete() throws Exception {
    ResourceInstance resource = createNiceMock(ResourceInstance.class);
    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
    ClusterController controller = createMock(ClusterController.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);

    //expectations
    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
    expect(resourceDefinition.getType()).andReturn(Resource.Type.Component).anyTimes();
    expect(resource.getQuery()).andReturn(query).anyTimes();
    expect(query.getPredicate()).andReturn(predicate).anyTimes();

    expect(controller.deleteResources(Resource.Type.Component, predicate)).andReturn(new RequestStatusImpl(null));

    replay(resource, resourceDefinition, controller, query, predicate);
View Full Code Here

  ClusterController m_controller = createNiceMock(ClusterController.class);

  @Test
  public void testExecute__Component_instance_noSpecifiedProps() throws Exception {
    Result result = createNiceMock(Result.class);
    ResourceInstance componentResourceInstance = createNiceMock(ResourceInstance.class);
    ResourceDefinition componentResourceDefinition = createNiceMock(ResourceDefinition.class);
    ResourceInstance hostResourceInstance = createNiceMock(ResourceInstance.class);
    ResourceDefinition hostResourceDefinition = createNiceMock(ResourceDefinition.class);
    Schema componentSchema = createNiceMock(Schema.class);
    Resource componentResource = createNiceMock(Resource.class);
    String componentPropertyId = "componentId";
    Query hostComponentQuery = createStrictMock(Query.class);
    Result hostComponentQueryResult = createNiceMock(Result.class);

    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
    TreeNode<Resource> hostComponentResultNode = new TreeNodeImpl<Resource>(null, null, null);
    List<Resource> listResources = Collections.singletonList(componentResource);

    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
    mapResourceIds.put(Resource.Type.Cluster, "clusterName");
    mapResourceIds.put(Resource.Type.Service, "serviceName");
    mapResourceIds.put(Resource.Type.Component, "componentName");

    Map<String, ResourceInstance> mapChildren = new HashMap<String, ResourceInstance>();
    mapChildren.put("host_components", hostResourceInstance);

    PredicateBuilder pb = new PredicateBuilder();
    Predicate predicate = pb.property("clusterId").equals("clusterName").and().
        property("serviceId").equals("serviceName").and().
        property("componentId").equals("componentName").toPredicate();

    // expectations
    expect(componentResourceInstance.getResourceDefinition()).andReturn(componentResourceDefinition).anyTimes();
    expect(componentResourceInstance.getSubResources()).andReturn(mapChildren).anyTimes();
    expect(componentResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();

    expect(componentResourceDefinition.getType()).andReturn(Resource.Type.Component).anyTimes();

    expect(componentResource.getType()).andReturn(Resource.Type.Component).anyTimes();
    expect(componentResource.getPropertyValue(componentPropertyId)).andReturn("keyVal");

    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes();

    expect(componentSchema.getCategoryProperties()).andReturn(Collections.<String, Set<String>>emptyMap()).anyTimes();
    expect(componentSchema.getKeyPropertyId(Resource.Type.Cluster)).andReturn("clusterId");
    expect(componentSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("serviceId");
    expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(componentPropertyId).atLeastOnce();

    expect(m_controller.getResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(Collections.<String>emptySet())),
        eq(predicate))).andReturn(listResources);

    expect(result.getResultTree()).andReturn(tree).anyTimes();

    Map<Resource.Type, String> mapResourceIdsSet = new HashMap<Resource.Type, String>(mapResourceIds);
    mapResourceIdsSet.put(Resource.Type.Component, "keyVal");
    hostResourceInstance.setIds(mapResourceIdsSet);
    expect(hostResourceInstance.getResourceDefinition()).andReturn(hostResourceDefinition).anyTimes();
    expect(hostResourceInstance.getQuery()).andReturn(hostComponentQuery).anyTimes();

    expect(hostResourceDefinition.getType()).andReturn(Resource.Type.Host);
    expect(hostComponentQuery.execute()).andReturn(hostComponentQueryResult);
    expect(hostComponentQueryResult.getResultTree()).andReturn(hostComponentResultNode);
View Full Code Here

  }

  @Test
  public void testExecute__Component_collection_noSpecifiedProps() throws Exception {
    Result result = createNiceMock(Result.class);
    ResourceInstance componentResourceInstance = createNiceMock(ResourceInstance.class);
    ResourceDefinition componentResourceDefinition = createNiceMock(ResourceDefinition.class);
    Schema componentSchema = createNiceMock(Schema.class);
    Resource componentResource = createNiceMock(Resource.class);
    String componentPropertyId = "componentId";
    String servicePropertyId = "serviceId";
    String clusterPropertyId = "clusterId";

    Set<String> setPropertyIds = new HashSet<String>();
    setPropertyIds.add(clusterPropertyId);
    setPropertyIds.add(servicePropertyId);
    setPropertyIds.add(componentPropertyId);

    Map<String, Set<String>> mapProperties = new HashMap<String, Set<String>>();
    Set<String> setAllProps = new HashSet<String>();
    setAllProps.add("clusterId");
    setAllProps.add("serviceId");
    setAllProps.add("componentId");
    mapProperties.put(null, setAllProps);

    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
    List<Resource> listResources = Collections.singletonList(componentResource);

    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
    mapResourceIds.put(Resource.Type.Cluster, "clusterName");
    mapResourceIds.put(Resource.Type.Service, "serviceName");
    mapResourceIds.put(Resource.Type.Component, null);

    PredicateBuilder pb = new PredicateBuilder();
    Predicate predicate = pb.property("clusterId").equals("clusterName").and().
        property("serviceId").equals("serviceName").toPredicate();

    // expectations
    expect(componentResource.getType()).andReturn(Resource.Type.Component).anyTimes();

    expect(componentResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();
    expect(componentResourceInstance.getResourceDefinition()).andReturn(componentResourceDefinition).anyTimes();

    expect(componentResourceDefinition.getType()).andReturn(Resource.Type.Component).anyTimes();

    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes();
View Full Code Here

  }

  @Test
  public void testExecute__collection_nullInternalPredicate_nullUserPredicate() throws Exception {
    Result result = createNiceMock(Result.class);
    ResourceInstance clusterResourceInstance = createNiceMock(ResourceInstance.class);
    ResourceDefinition clusterResourceDefinition = createNiceMock(ResourceDefinition.class);
    Schema clusterSchema = createNiceMock(Schema.class);
    Resource clusterResource = createNiceMock(Resource.class);
    String clusterPropertyId = "clusterId";

    Map<String, Set<String>> mapProperties = new HashMap<String, Set<String>>();
    mapProperties.put(null, Collections.singleton("clusterId"));

    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
    List<Resource> listResources = Collections.singletonList(clusterResource);

    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();

    // expectations
    expect(clusterResource.getType()).andReturn(Resource.Type.Cluster).anyTimes();

    expect(clusterResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();
    expect(clusterResourceInstance.getResourceDefinition()).andReturn(clusterResourceDefinition).anyTimes();

    expect(clusterResourceDefinition.getType()).andReturn(Resource.Type.Component).anyTimes();

    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(clusterSchema).atLeastOnce();
View Full Code Here

  }

  @Test
  public void testExecute__collection_nullInternalPredicate_nonNullUserPredicate() throws Exception {
    Result result = createNiceMock(Result.class);
    ResourceInstance clusterResourceInstance = createNiceMock(ResourceInstance.class);
    ResourceDefinition clusterResourceDefinition = createNiceMock(ResourceDefinition.class);
    Schema clusterSchema = createNiceMock(Schema.class);
    Resource clusterResource = createNiceMock(Resource.class);
    String clusterPropertyId = "clusterId";
    Predicate userPredicate = createNiceMock(Predicate.class);

    Map<String, Set<String>> mapProperties = new HashMap<String, Set<String>>();
    mapProperties.put(null, Collections.singleton("clusterId"));

    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
    List<Resource> listResources = Collections.singletonList(clusterResource);

    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();

    // expectations
    expect(clusterResource.getType()).andReturn(Resource.Type.Cluster).anyTimes();

    expect(clusterResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();
    expect(clusterResourceInstance.getResourceDefinition()).andReturn(clusterResourceDefinition).anyTimes();

    expect(clusterResourceDefinition.getType()).andReturn(Resource.Type.Component).atLeastOnce();

    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(clusterSchema).anyTimes();
    expect(clusterSchema.getCategoryProperties()).andReturn(mapProperties).anyTimes();
View Full Code Here

  }

  @Test
  public void testExecute__collection_nonNullInternalPredicate_nonNullUserPredicate() throws Exception {
    Result result = createNiceMock(Result.class);
    ResourceInstance componentResourceInstance = createNiceMock(ResourceInstance.class);
    ResourceDefinition componentResourceDefinition = createNiceMock(ResourceDefinition.class);
    Schema componentSchema = createNiceMock(Schema.class);
    Resource componentResource = createNiceMock(Resource.class);
    String componentPropertyId = "componentId";
    String servicePropertyId = "serviceId";
    String clusterPropertyId = "clusterId";

    Set<String> setPropertyIds = new HashSet<String>();
    setPropertyIds.add(clusterPropertyId);
    setPropertyIds.add(servicePropertyId);
    setPropertyIds.add(componentPropertyId);

    Map<String, Set<String>> mapProperties = new HashMap<String, Set<String>>();
    Set<String> setAllProps = new HashSet<String>();
    setAllProps.add("clusterId");
    setAllProps.add("serviceId");
    setAllProps.add("componentId");
    mapProperties.put(null, setAllProps);


    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
    List<Resource> listResources = Collections.singletonList(componentResource);

    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
    mapResourceIds.put(Resource.Type.Cluster, "clusterName");
    mapResourceIds.put(Resource.Type.Service, "serviceName");
    mapResourceIds.put(Resource.Type.Component, null);

    PredicateBuilder pb = new PredicateBuilder();
    Predicate internalPredicate = pb.property("clusterId").equals("clusterName").and().
        property("serviceId").equals("serviceName").toPredicate();

    pb = new PredicateBuilder();
    Predicate userPredicate = pb.property("foo").equals("bar").toPredicate();
    // combine internal predicate and user predicate
    //todo: for now, need to cast to BasePredicate
    Predicate predicate = new AndPredicate((BasePredicate) internalPredicate, (BasePredicate) userPredicate);

    // expectations
    expect(componentResource.getType()).andReturn(Resource.Type.Component).anyTimes();

    expect(componentResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();
    expect(componentResourceInstance.getResourceDefinition()).andReturn(componentResourceDefinition).anyTimes();

    expect(componentResourceDefinition.getType()).andReturn(Resource.Type.Component).anyTimes();

    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes();
    expect(componentSchema.getCategoryProperties()).andReturn(mapProperties).anyTimes();
View Full Code Here

    assertEquals(0, componentNode.getChildren().size());
  }

  @Test
  public void testAddProperty__localProperty() throws Exception {
    ResourceInstance resource = createNiceMock(ResourceInstance.class);
    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
    Schema schema = createNiceMock(Schema.class);

    Map<String, Set<String>> mapSchemaProps = new HashMap<String, Set<String>>();
    mapSchemaProps.put("category", Collections.singleton("property"));
    mapSchemaProps.put(null, Collections.singleton("property2"));

    //expectations
    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();

    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();

    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema);
    expect(schema.getCategoryProperties()).andReturn(mapSchemaProps);
View Full Code Here

  // this is the case where service can't differentiate category and property name
  // the category name is give as the property name
  @Test
  public void testAddProperty__localCategory_asPropertyName() throws Exception  {
    ResourceInstance resource = createNiceMock(ResourceInstance.class);
    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
    Schema schema = createNiceMock(Schema.class);

    Map<String, Set<String>> mapSchemaProps = new HashMap<String, Set<String>>();
    Set<String> setProps = new HashSet<String>();
    setProps.add("property");
    setProps.add("property2");
    mapSchemaProps.put("category", setProps);
    Set<String> setInnerProps = new HashSet<String>();
    setInnerProps.add("property3");
    setInnerProps.add("property4");
    mapSchemaProps.put("category/nestedCategory", setInnerProps);
    mapSchemaProps.put(null, Collections.singleton("property5"));

    //expectations
    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();

    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();

    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
    expect(schema.getCategoryProperties()).andReturn(mapSchemaProps).anyTimes();
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.api.resources.ResourceInstance

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.