Search in sources :

Example 16 with ServiceDocument

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

the class TestUtils method doPost.

/**
 * Generic doPost.
 *
 * @param host VerificationHost
 * @param inState Body to POST
 * @param type Body type to return
 * @param uri URI to post to
 * @param <T> type
 * @return State of service after POST
 * @throws Throwable
 */
public static <T extends ServiceDocument, B extends ServiceDocument> B doPost(VerificationHost host, T inState, Class<B> type, URI uri) throws Throwable {
    final ServiceDocument[] doc = { null };
    host.testStart(1);
    Operation post = Operation.createPost(uri).setBody(inState).setCompletion((o, e) -> {
        if (e != null) {
            host.failIteration(e);
            return;
        }
        doc[0] = o.getBody(ServiceDocument.class);
        host.completeIteration();
    });
    host.send(post);
    host.testWait();
    host.logThroughput();
    B outState = host.getServiceState(null, type, UriUtils.buildUri(uri.getHost(), uri.getPort(), doc[0].documentSelfLink, null));
    return outState;
}
Also used : ServiceDocument(com.vmware.xenon.common.ServiceDocument) Operation(com.vmware.xenon.common.Operation)

Example 17 with ServiceDocument

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

the class TestUtils method doPost.

/**
 * Generic doPost.
 *
 * @param host VerificationHost
 * @param type Body type to return
 * @param uri URI to post to
 * @param <T> type
 * @return State of service after POST
 * @throws Throwable
 */
public static <T extends ServiceDocument, B extends ServiceDocument> B doPost(VerificationHost host, Class<B> type, URI uri) throws Throwable {
    final ServiceDocument[] doc = { null };
    host.testStart(1);
    Operation post = Operation.createPost(uri).setCompletion((o, e) -> {
        if (e != null) {
            host.failIteration(e);
            return;
        }
        doc[0] = o.getBody(ServiceDocument.class);
        host.completeIteration();
    });
    host.send(post);
    host.testWait();
    host.logThroughput();
    B outState = host.getServiceState(null, type, UriUtils.buildUri(uri.getHost(), uri.getPort(), doc[0].documentSelfLink, null));
    return outState;
}
Also used : ServiceDocument(com.vmware.xenon.common.ServiceDocument) Operation(com.vmware.xenon.common.Operation)

Example 18 with ServiceDocument

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

the class ComputeService method getDocumentTemplate.

@Override
public ServiceDocument getDocumentTemplate() {
    ServiceDocument td = super.getDocumentTemplate();
    // enable metadata indexing
    td.documentDescription.documentIndexingOptions = EnumSet.of(DocumentIndexingOption.INDEX_METADATA);
    ServiceUtils.setRetentionLimit(td);
    ComputeState template = (ComputeState) td;
    template.id = UUID.randomUUID().toString();
    template.primaryMAC = "01:23:45:67:89:ab";
    template.descriptionLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, "on-prem-one-cpu-vm-guest");
    template.resourcePoolLink = null;
    template.type = ComputeType.VM_GUEST;
    template.environmentName = ENVIRONMENT_NAME_ON_PREMISE;
    template.adapterManagementReference = URI.create("https://esxhost-01:443/sdk");
    return template;
}
Also used : ServiceDocument(com.vmware.xenon.common.ServiceDocument)

Example 19 with ServiceDocument

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

the class ResourceOperationSpecService method getDocumentTemplate.

@Override
public ServiceDocument getDocumentTemplate() {
    ServiceDocument template = super.getDocumentTemplate();
    ServiceUtils.setRetentionLimit(template);
    return template;
}
Also used : ServiceDocument(com.vmware.xenon.common.ServiceDocument)

Example 20 with ServiceDocument

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

the class AzureTestUtil method assertResourceDisassociated.

/**
 * Assert that a resource with the provided name exist in the document store.
 *
 * @param factoryLink
 *            Factory link to the stateful service which states to check.
 * @param name
 *            name of the resource to assert if exists.
 * @param isDisassociated
 *            whether to assert if a resource exists or not.
 */
public static void assertResourceDisassociated(VerificationHost host, String factoryLink, String name, boolean isDisassociated) {
    ServiceDocumentQueryResult result = host.getExpandedFactoryState(UriUtils.buildUri(host, factoryLink));
    boolean disassociated = false;
    for (Object document : result.documents.values()) {
        // Read doc as ServiceDocument to access its 'documentKind'
        ServiceDocument serviceDoc = Utils.fromJson(document, ServiceDocument.class);
        Class<? extends ResourceState> resourceClass = ENDPOINT_LINK_EXPLICIT_SUPPORT.stream().filter(clazz -> serviceDoc.documentKind.equals(Utils.buildKind(clazz))).findFirst().orElse(null);
        if (resourceClass != null) {
            // Read doc as ResourceState to access its 'endpointLinks'
            ResourceState resource = Utils.fromJson(document, resourceClass);
            if (Objects.equals(name, resource.name) && resource.endpointLinks.isEmpty()) {
                String endpointLink = PhotonModelUtils.getEndpointLink(resource);
                if (endpointLink == null || endpointLink.isEmpty()) {
                    disassociated = true;
                    break;
                }
            }
        }
    }
    assertEquals("isDisassociated", isDisassociated, disassociated);
}
Also used : ServiceDocument(com.vmware.xenon.common.ServiceDocument) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Aggregations

ServiceDocument (com.vmware.xenon.common.ServiceDocument)47 Operation (com.vmware.xenon.common.Operation)11 URI (java.net.URI)6 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)5 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)5 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)5 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)5 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)5 CompletionHandler (com.vmware.xenon.common.Operation.CompletionHandler)5 UriUtils (com.vmware.xenon.common.UriUtils)5 List (java.util.List)5 UriPaths (com.vmware.photon.controller.model.UriPaths)4 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)4 TaskState (com.vmware.xenon.common.TaskState)4 TaskStage (com.vmware.xenon.common.TaskState.TaskStage)4 Utils (com.vmware.xenon.common.Utils)4 TaskService (com.vmware.xenon.services.common.TaskService)4 TimeUnit (java.util.concurrent.TimeUnit)4 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)3 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)3