Package org.apache.ambari.server.api.services

Examples of org.apache.ambari.server.api.services.Result


   // Get a result from this query.
  private Result getResult(Resource parentResource)
      throws UnsupportedPropertyException, SystemException, NoSuchResourceException, NoSuchParentResourceException {

    Result result = new ResultImpl(true);
    Resource.Type resourceType = getResourceDefinition().getType();
    TreeNode<Resource> tree = result.getResultTree();

    if (isCollectionResource()) {
      tree.setProperty("isCollection", "true");
    }
View Full Code Here


  public void testSerialize() throws Exception {
    UriInfo uriInfo = createMock(UriInfo.class);
    Resource resource = createMock(Resource.class);
    //Resource resource2 = createMock(Resource.class);

    Result result = new ResultImpl(true);
    result.setResultStatus(new ResultStatus(ResultStatus.STATUS.OK));
    TreeNode<Resource> tree = result.getResultTree();
    //tree.setName("items");
    TreeNode<Resource> child = tree.addChild(resource, "resource1");
    //child.addChild(resource2, "sub-resource");

    // resource properties
View Full Code Here

    expect(resource1.getType()).andReturn(Resource.Type.Cluster).anyTimes();
    expect(resource2.getType()).andReturn(Resource.Type.Cluster).anyTimes();

    replay(request, resource, pm, status, resource1, resource2, userPredicate, query);

    Result result = new TestDeleteHandler(pm).handleRequest(request);

    assertNotNull(result);
    TreeNode<Resource> tree = result.getResultTree();
    assertEquals(1, tree.getChildren().size());
    TreeNode<Resource> resourcesNode = tree.getChild("resources");
    assertEquals(2, resourcesNode.getChildren().size());
    boolean foundResource1 = false;
    boolean foundResource2 = false;
    for(TreeNode<Resource> child : resourcesNode.getChildren()) {
      Resource r = child.getObject();
      if (r == resource1 && ! foundResource1) {
        foundResource1 = true;
      } else if (r == resource2 && ! foundResource2) {
        foundResource2 = true;
      } else {
        fail();
      }
    }

    assertEquals(ResultStatus.STATUS.OK, result.getStatus().getStatus());
    verify(request, resource, pm, status, resource1, resource2, userPredicate, query);
  }
View Full Code Here

    expect(resource2.getType()).andReturn(Resource.Type.Cluster).anyTimes();
    expect(status.getRequestResource()).andReturn(requestResource).anyTimes();

    replay(request, resource, pm, status, resource1, resource2, requestResource);

    Result result = new TestDeleteHandler(pm).handleRequest(request);

    assertNotNull(result);
    TreeNode<Resource> tree = result.getResultTree();
    assertEquals(2, tree.getChildren().size());
    TreeNode<Resource> resourcesNode = tree.getChild("resources");
    assertEquals(2, resourcesNode.getChildren().size());
    boolean foundResource1 = false;
    boolean foundResource2 = false;
    for(TreeNode<Resource> child : resourcesNode.getChildren()) {
      Resource r = child.getObject();
      if (r == resource1 && ! foundResource1) {
        foundResource1 = true;
      } else if (r == resource2 && ! foundResource2) {
        foundResource2 = true;
      } else {
        fail();
      }
    }

    TreeNode<Resource> statusNode = tree.getChild("request");
    assertNotNull(statusNode);
    assertEquals(0, statusNode.getChildren().size());
    assertSame(requestResource, statusNode.getObject());
    assertEquals(ResultStatus.STATUS.ACCEPTED, result.getStatus().getStatus());

    verify(request, resource, pm, status, resource1, resource2, requestResource);
  }
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);

    replay(m_controller, result, componentResourceInstance, componentResourceDefinition, hostResourceInstance, componentSchema, componentResource,
        hostComponentQuery, hostComponentQueryResult);

    QueryImpl query = new TestQuery(componentResourceInstance, result);
View Full Code Here

    assertEquals("false", hostComponentResultNode.getProperty("isCollection"));
  }

  @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();

    expect(componentSchema.getCategoryProperties()).andReturn(mapProperties).anyTimes();
    expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(componentPropertyId).anyTimes();
    expect(componentSchema.getKeyPropertyId(Resource.Type.Cluster)).andReturn("clusterId").anyTimes();
    expect(componentSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("serviceId").anyTimes();

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

    expect(m_controller.getResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(setPropertyIds)),
        eq(predicate))).andReturn(listResources);

    replay(m_controller, result,componentResourceInstance, componentResourceDefinition, componentSchema, componentResource);
View Full Code Here

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

  @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();

    expect(clusterSchema.getCategoryProperties()).andReturn(mapProperties);
    expect(clusterSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(clusterPropertyId).atLeastOnce();

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

    expect(m_controller.getResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(Collections.singleton(clusterPropertyId))),
        (Predicate) isNull())).andReturn(listResources);

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();
    expect(clusterSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(clusterPropertyId).anyTimes();

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

    expect(m_controller.getResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(Collections.singleton(clusterPropertyId))),
        eq(userPredicate))).andReturn(listResources);

    replay(m_controller, result,clusterResourceInstance, clusterResourceDefinition, clusterSchema, clusterResource, userPredicate);
View Full Code Here

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

  @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();
    expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(componentPropertyId).atLeastOnce();
    expect(componentSchema.getKeyPropertyId(Resource.Type.Cluster)).andReturn("clusterId").anyTimes();
    expect(componentSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("serviceId").anyTimes();

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

    expect(m_controller.getResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(setPropertyIds)),
        eq(predicate))).andReturn(listResources);

    replay(m_controller, result, componentResourceInstance, componentResourceDefinition, componentSchema, componentResource);
View Full Code Here

    expect(resource1.getType()).andReturn(Resource.Type.Cluster).anyTimes();
    expect(resource2.getType()).andReturn(Resource.Type.Cluster).anyTimes();

    replay(request, resource, pm, status, resource1, resource2, userPredicate, query);

    Result result = new TestUpdateHandler(pm).handleRequest(request);

    assertNotNull(result);
    TreeNode<Resource> tree = result.getResultTree();
    assertEquals(1, tree.getChildren().size());
    TreeNode<Resource> resourcesNode = tree.getChild("resources");
    assertEquals(2, resourcesNode.getChildren().size());
    boolean foundResource1 = false;
    boolean foundResource2 = false;
    for(TreeNode<Resource> child : resourcesNode.getChildren()) {
      Resource r = child.getObject();
      if (r == resource1 && ! foundResource1) {
        foundResource1 = true;
      } else if (r == resource2 && ! foundResource2) {
        foundResource2 = true;
      } else {
        fail();
      }
    }

    assertEquals(ResultStatus.STATUS.OK, result.getStatus().getStatus());
    verify(request, resource, pm, status, resource1, resource2, userPredicate, query);
  }
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.api.services.Result

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.