Search in sources :

Example 56 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class TestAWSSetupUtils method getComputeByAWSId.

/**
 * Lookup a Compute by aws Id
 */
public static ComputeState getComputeByAWSId(VerificationHost host, String awsId) throws Throwable {
    URI computesURI = UriUtils.buildUri(host, ComputeService.FACTORY_LINK);
    computesURI = UriUtils.buildExpandLinksQueryUri(computesURI);
    computesURI = UriUtils.appendQueryParam(computesURI, "$filter", String.format("id eq %s", awsId));
    Operation op = host.waitForResponse(Operation.createGet(computesURI));
    ServiceDocumentQueryResult result = op.getBody(ServiceDocumentQueryResult.class);
    assertNotNull(result);
    assertNotNull(result.documents);
    assertEquals(1, result.documents.size());
    return Utils.fromJson(result.documents.values().iterator().next(), ComputeState.class);
}
Also used : Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) ProvisioningUtils.createServiceURI(com.vmware.photon.controller.model.tasks.ProvisioningUtils.createServiceURI) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 57 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class TestAWSSetupUtils method getLoadBalancerByAWSId.

/**
 * Lookup a Load Balancer by aws Id
 */
public static LoadBalancerState getLoadBalancerByAWSId(VerificationHost host, String awsId) throws Throwable {
    URI lbURI = UriUtils.buildUri(host, LoadBalancerService.FACTORY_LINK);
    lbURI = UriUtils.buildExpandLinksQueryUri(lbURI);
    lbURI = UriUtils.appendQueryParam(lbURI, "$filter", String.format("id eq %s", awsId));
    Operation op = host.waitForResponse(Operation.createGet(lbURI));
    ServiceDocumentQueryResult result = op.getBody(ServiceDocumentQueryResult.class);
    assertNotNull(result);
    assertNotNull(result.documents);
    assertEquals(1, result.documents.size());
    return Utils.fromJson(result.documents.values().iterator().next(), LoadBalancerState.class);
}
Also used : Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) ProvisioningUtils.createServiceURI(com.vmware.photon.controller.model.tasks.ProvisioningUtils.createServiceURI) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 58 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class TestAWSMissingEnumerationResourcesService method verifyLinkedAccountsCreation.

private void verifyLinkedAccountsCreation(Request request, int expectedCount) {
    this.host.waitFor("Timeout while waiting for verifyLinkedAccountsCreation()", () -> {
        ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(getQuerySpecForComputeStates(request), expectedCount, expectedCount);
        Collection<Object> values = result.documents.values();
        if (values.size() != expectedCount) {
            return false;
        }
        for (Object computeState : result.documents.values()) {
            ComputeState cs = Utils.fromJson(computeState, ComputeState.class);
            if (!cs.descriptionLink.equals(linkedAccountDescriptions.get(cs.name).documentSelfLink)) {
                return false;
            }
            if (!cs.endpointLink.equals(request.primaryAccountCompute.endpointLink)) {
                return false;
            }
            if (cs.creationTimeMicros == null) {
                return false;
            }
        }
        return true;
    });
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 59 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class TestAWSEnumerationTask method validateTagInEntity.

/**
 * Validates that the given internal tag is present on the passed in entity.
 */
private void validateTagInEntity(ServiceDocumentQueryResult queryResult, Class<?> documentKind, String internalTagType) {
    ServiceDocumentQueryResult tagsResult;
    String tagLink;
    tagsResult = getInternalTagsByType(this.host, internalTagType);
    assertEquals(count1, tagsResult.documentLinks.size());
    tagLink = tagsResult.documentLinks.get(0);
    for (Map.Entry<String, Object> resourceMap : queryResult.documents.entrySet()) {
        if (documentKind == ComputeState.class) {
            ComputeState compute = Utils.fromJson(resourceMap.getValue(), ComputeState.class);
            if (!compute.type.equals(ComputeType.ZONE) && !compute.type.equals(ComputeType.ENDPOINT_HOST)) {
                assertTrue(compute.tagLinks.contains(tagLink));
            }
        } else {
            ResourceState resourceState = Utils.fromJson(resourceMap.getValue(), ResourceState.class);
            if (resourceState.tagLinks != null) {
                assertTrue(resourceState.tagLinks.contains(tagLink));
            }
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Map(java.util.Map) HashMap(java.util.HashMap) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 60 with ServiceDocumentQueryResult

use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.

the class BaseTestCase method verifyService.

protected void verifyService(URI factoryUri, FactoryService factoryInstance, Class<? extends ServiceDocument> serviceDocumentType, TestServiceDocumentInitialization serviceDocumentInit, TestServiceDocumentAssertion assertion) throws Throwable {
    int childCount = 1;
    TestContext ctx = testCreate(childCount);
    String prefix = "example-";
    URI[] childURIs = new URI[childCount];
    for (int i = 0; i < childCount; i++) {
        ServiceDocument serviceDocument = serviceDocumentInit.create(prefix, i);
        final int finalI = i;
        // create a ServiceDocument instance.
        Operation createPost = createForcedPost(factoryUri).setBody(serviceDocument).setCompletion((o, e) -> {
            if (e != null) {
                ctx.failIteration(e);
                return;
            }
            ServiceDocument rsp = o.getBody(serviceDocumentType);
            childURIs[finalI] = UriUtils.buildUri(this.host, rsp.documentSelfLink);
            ctx.completeIteration();
        });
        this.host.send(createPost);
    }
    try {
        // verify factory and service instance wiring.
        factoryInstance.setHost(this.host);
        Service serviceInstance = factoryInstance.createServiceInstance();
        serviceInstance.setHost(this.host);
        assertNotNull(serviceInstance);
        ctx.await();
        // do GET on all child URIs
        Map<URI, ? extends ServiceDocument> childStates = this.host.getServiceState(null, serviceDocumentType, childURIs);
        for (ServiceDocument s : childStates.values()) {
            assertion.assertState(prefix, s);
        }
        // verify template GET works on factory
        ServiceDocumentQueryResult templateResult = this.host.getServiceState(null, ServiceDocumentQueryResult.class, UriUtils.extendUri(factoryUri, ServiceHost.SERVICE_URI_SUFFIX_TEMPLATE));
        assertTrue(templateResult.documentLinks.size() == templateResult.documents.size());
        ServiceDocument childTemplate = Utils.fromJson(templateResult.documents.get(templateResult.documentLinks.iterator().next()), serviceDocumentType);
        assertTrue(childTemplate.documentDescription != null);
        assertTrue(childTemplate.documentDescription.propertyDescriptions != null && childTemplate.documentDescription.propertyDescriptions.size() > 0);
    } catch (Throwable t) {
        if (t instanceof RuntimeException) {
            throw t;
        }
        throw new RuntimeException(t);
    }
}
Also used : TestContext(com.vmware.xenon.common.test.TestContext) Service(com.vmware.xenon.common.Service) StatefulService(com.vmware.xenon.common.StatefulService) FactoryService(com.vmware.xenon.common.FactoryService) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Aggregations

ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)64 Test (org.junit.Test)26 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)25 ArrayList (java.util.ArrayList)15 QueryTask (com.vmware.xenon.services.common.QueryTask)14 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)13 Operation (com.vmware.xenon.common.Operation)13 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)12 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)12 HashMap (java.util.HashMap)12 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)11 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)11 URI (java.net.URI)11 Map (java.util.Map)11 List (java.util.List)10 StatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState)8 UriUtils (com.vmware.xenon.common.UriUtils)8 Utils (com.vmware.xenon.common.Utils)8 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)7 ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)7