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

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


  }

  @Test
  public void testHandleRequest__NoSuchParentResourceException() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);
    NoSuchParentResourceException exception = new NoSuchParentResourceException("exceptionMsg", new RuntimeException());

    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


  }

  @Test
  public void testHandleRequest__UnsupportedPropertyException() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);
    UnsupportedPropertyException exception = new UnsupportedPropertyException(
        Resource.Type.Cluster, Collections.singleton("foo"));

    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

  }

  @Test
  public void testHandleRequest__NoSuchResourceException_OK() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    Predicate predicate = createMock(Predicate.class);
    NoSuchResourceException exception = new NoSuchResourceException("msg", new RuntimeException());

    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).anyTimes();
View Full Code Here

  }

  @Test
  public void testHandleRequest__NoSuchResourceException_NOT_FOUND() throws Exception {
    Request request = createStrictMock(Request.class);
    ResourceInstance resource = createStrictMock(ResourceInstance.class);
    Query query = createMock(Query.class);
    NoSuchResourceException exception = new NoSuchResourceException("msg", new RuntimeException());

    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(null).anyTimes();
View Full Code Here

      // add a child node for the resource and provide a unique name.  The name is never used.
      //todo: provide a more meaningful node name
      TreeNode<Resource> node = tree.addChild(resource, resource.getType() + ":" + count++);
      for (Map.Entry<String, ResourceInstance> entry : m_mapSubResources.entrySet()) {
        String subResCategory = entry.getKey();
        ResourceInstance r = entry.getValue();

        setParentIdsOnSubResource(resource, r);

        TreeNode<Resource> childResult = r.getQuery().execute().getResultTree();
        childResult.setName(subResCategory);
        childResult.setProperty("isCollection", "false");
        node.addChild(childResult);
      }
    }
View Full Code Here

    }

    int i = path.indexOf("/");
    String p = i == -1 ? path : path.substring(0, i);

    ResourceInstance subResource = m_resource.getSubResources().get(p);
    if (subResource != null) {
      m_mapSubResources.put(p, subResource);
      //todo: handle case of trailing '/' (for example fields=subResource/)

      if (property != null || !path.equals(p)) {
        //only add if a sub property is set or if a sub category is specified
        subResource.getQuery().addProperty(i == -1 ? null : path.substring(i + 1), property, temporalInfo);
      }
      resourceAdded = true;
    }
    return resourceAdded;
  }
View Full Code Here

  protected BaseManagementHandler() {
  }

  public Result handleRequest(Request request) {
    ResourceInstance resource = request.getResource();
    Predicate queryPredicate = request.getQueryPredicate();
    if (queryPredicate != null) {
      resource.getQuery().setUserPredicate(queryPredicate);
    }

    return handleRequest(resource, request.getHttpBodyProperties());
  }
View Full Code Here

      //todo: For case where no resources are returned, will return 200 ok.
      //todo: What is the appropriate status code?
      return queryResult;
    }

    ResourceInstance resource = request.getResource();
    Resource.Type createType = getCreateType(request.getHttpBody(), resource);
    Set<Map<String, Object>> setProperties = buildCreateSet(request, queryResult, createType);
    ResourceInstance createResource = getResourceFactory().createResource(
        createType, request.getResource().getIds());

    return super.handleRequest(createResource, setProperties);
  }
View Full Code Here

  private Set<Map<String, Object>> buildCreateSet(Request request, Result queryResult, Resource.Type createType) {
    Set<Map<String, Object>> setRequestProps = request.getHttpBodyProperties();
    Set<Map<String, Object>> setCreateProps = new HashSet<Map<String, Object>>(setRequestProps.size());

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

    TreeNode<Resource> tree = queryResult.getResultTree();
View Full Code Here

  private Resource.Type getCreateType(String requestBody, ResourceInstance resource) {
    int startIdx = requestBody.indexOf("\"") + 1;
    int endIdx = requestBody.indexOf("\"", startIdx + 1);

    ResourceInstance res =  resource.getSubResources().get(requestBody.substring(startIdx, endIdx));
    return res == null ? null : res.getResourceDefinition().getType();
  }
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.