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___NoBodyProps() throws Exception {
    ResourceInstance resource = createMock(ResourceInstance.class);
    ResourceDefinition resourceDefinition = createMock(ResourceDefinition.class);
    ClusterController controller = createMock(ClusterController.class);
    Schema schema = createMock(Schema.class);
    String clusterId = "clusterId";
    String serviceId = "serviceId";
    String componentId = "componentId";
    Request serverRequest = createStrictMock(Request.class);
    RequestBody body = new RequestBody();

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

    Set<Map<String, Object>> setExpected = new HashSet<Map<String, Object>>();
    Map<String, Object> mapExpected = new HashMap<String, Object>();
    mapExpected.put(clusterId, "clusterId");
    mapExpected.put(serviceId, "serviceId");
    mapExpected.put(componentId, "componentId");
    setExpected.add(mapExpected);

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


    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);
    RequestBody body = new RequestBody();

    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");

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

    Map<String, Object> mapResourceProps2 = new HashMap<String, Object>();
    mapResourceProps1.put("componentId", "id2");
    mapResourceProps2.put(PropertyHelper.getPropertyId("foo", "bar2"), "value2");

    NamedPropertySet namedPropSet1 = new NamedPropertySet("", mapResourceProps1);
    NamedPropertySet namedPropSet2 = new NamedPropertySet("", mapResourceProps2);

    body.addPropertySet(namedPropSet1);
    body.addPropertySet(namedPropSet2);

    Set<Map<String, Object>> setExpected = new HashSet<Map<String, Object>>();
    Map<String, Object> mapExpected1 = new HashMap<String, Object>(mapResourceProps1);
    mapExpected1.put(clusterId, "clusterId");
    mapExpected1.put(serviceId, "serviceId");
    setExpected.add(mapExpected1);
    Map<String, Object> mapExpected2 = new HashMap<String, Object>(mapResourceProps2);
    mapExpected2.put(clusterId, "clusterId");
    mapExpected2.put(serviceId, "serviceId");
    setExpected.add(mapExpected2);

    //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);
    RequestBody body = new RequestBody();

    Map<String, Object> mapProperties = new HashMap<String, Object>();
    mapProperties.put(PropertyHelper.getPropertyId("foo", "bar"), "value");
    NamedPropertySet namedPropSet = new NamedPropertySet("", mapProperties);
    body.addPropertySet(namedPropSet);

    Set<Map<String, Object>> setExpected = new HashSet<Map<String, Object>>();
    setExpected.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);
    RequestBody body = new RequestBody();

    //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

          "Multiple sub-resource types may not be created in the same request.");
    }

    // only get first element because we currently only support creation of a single sub-resource type
    final Map.Entry<Resource.Type, Set<Map<String, Object>>> entry = mapProperties.entrySet().iterator().next();
    ResourceInstance createResource = getResourceFactory().createResource(
        entry.getKey(), request.getResource().getIds());

    RequestBody requestBody = new RequestBody();
    requestBody.setBody(request.getBody().getBody());
    for (Map<String, Object> map : entry.getValue()) {
View Full Code Here

    Set<NamedPropertySet> setRequestProps = request.getBody().getNamedPropertySets();

    HashMap<Resource.Type, Set<Map<String, Object>>> mapProps =
        new HashMap<Resource.Type, Set<Map<String, Object>>>();

    ResourceInstance  resource            = request.getResource();
    Resource.Type     type                = resource.getResourceDefinition().getType();
    ClusterController controller          = getClusterController();
    String            resourceKeyProperty = controller.getSchema(type).getKeyPropertyId(type);

    TreeNode<Resource> tree = queryResult.getResultTree();
    Collection<TreeNode<Resource>> treeChildren = tree.getChildren();
    for (TreeNode<Resource> node : treeChildren) {
      Resource r = node.getObject();
      Object keyVal = r.getPropertyValue(resourceKeyProperty);

      for (NamedPropertySet namedProps : setRequestProps) {
        for (Map.Entry<String, Object> entry : namedProps.getProperties().entrySet()) {
          Set<Map<String, Object>> set = (Set<Map<String, Object>>) entry.getValue();
          for (Map<String, Object> map : set) {
            Map<String, Object> mapResourceProps = new HashMap<String, Object>(map);
            Resource.Type       createType       = getCreateType(resource, entry.getKey());
            mapResourceProps.put(controller.getSchema(createType).
                getKeyPropertyId(resource.getResourceDefinition().getType()), keyVal);
            Set<Map<String, Object>> setCreateProps = mapProps.get(createType);
            if (setCreateProps == null) {
              setCreateProps = new HashSet<Map<String, Object>>();
              mapProps.put(createType, setCreateProps);
            }
View Full Code Here

public class ReadHandlerTest {

  @Test
  public void testHandleRequest__InvalidField() {
    Request request = createNiceMock(Request.class);
    ResourceInstance resource = createNiceMock(ResourceInstance.class);
    Query query = createStrictMock(Query.class);

    Map<String, TemporalInfo> mapPartialResponseFields = new HashMap<String, TemporalInfo>();
    mapPartialResponseFields.put("foo/bar", null);

    expect(request.getResource()).andReturn(resource);
    expect(request.getFields()).andReturn(mapPartialResponseFields);
    expect(resource.getQuery()).andReturn(query);

    query.addProperty("foo", "bar", null);
    expectLastCall().andThrow(new IllegalArgumentException("testMsg"));

    replay(request, resource, query);
View Full Code Here

  }

  @Test
  public void testHandleRequest__OK() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);
    Result result = createStrictMock(Result.class);
    Capture<ResultStatus> resultStatusCapture = new Capture<ResultStatus>();

    Map<String, TemporalInfo> mapPartialResponseFields = new HashMap<String, TemporalInfo>();
    mapPartialResponseFields.put("foo", null);
    mapPartialResponseFields.put("bar/c", null);
    mapPartialResponseFields.put("bar/d/e", null);
    mapPartialResponseFields.put("category/", null);
    //expectations
    expect(request.getResource()).andReturn(resource);
    expect(resource.getQuery()).andReturn(query);

    expect(request.getFields()).andReturn(mapPartialResponseFields);
    expect(request.getPageRequest()).andReturn(null);
    query.addProperty(null, "foo", null);
    query.addProperty("bar", "c", null);
View Full Code Here

   */
  private Resource.Type getCreateType(ResourceInstance resource, String subResourceName) throws IllegalArgumentException{
    if (subResourceName == null || subResourceName.equals("")) {
      throw new IllegalArgumentException("A sub-resource name must be supplied.");
    }
    ResourceInstance res = resource.getSubResources().get(subResourceName);

    if (res == null) {
      throw new IllegalArgumentException("The specified sub-resource name is not valid: '" + subResourceName + "'.");
    }

    return res.getResourceDefinition().getType();
  }
View Full Code Here

  }

  @Test
  public void testHandleRequest__SystemException() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);

    expect(request.getResource()).andReturn(resource);
    expect(resource.getQuery()).andReturn(query);

    expect(request.getFields()).andReturn(Collections.<String, TemporalInfo>emptyMap());
    expect(request.getPageRequest()).andReturn(null);

    expect(request.getQueryPredicate()).andReturn(predicate);
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.