Search in sources :

Example 86 with QueryTask

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

the class TestVSphereProvisionFromImageLink method findImage.

private String findImage() {
    Query q = Query.Builder.create().addKindFieldClause(ImageState.class).addFieldClause(ImageState.FIELD_NAME_NAME, "*" + this.libraryItemName, MatchType.WILDCARD).build();
    QueryTask task = QueryTask.Builder.createDirectTask().setQuery(q).build();
    Operation op = QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
    Operation result = this.host.waitForResponse(op);
    try {
        return result.getBody(QueryTask.class).results.documentLinks.get(0);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
        return null;
    }
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Operation(com.vmware.xenon.common.Operation)

Example 87 with QueryTask

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

the class TestVSphereProvisionWithCloudConfigTask method findTemplate.

private ComputeState findTemplate() throws InterruptedException, ExecutionException, TimeoutException {
    String templateVmName = System.getProperty("vc.templateVmName");
    Query q = Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_NAME, templateVmName).addKindFieldClause(ComputeState.class).build();
    QueryTask task = QueryTask.Builder.createDirectTask().addOption(QueryOption.EXPAND_CONTENT).setQuery(q).build();
    Operation op = QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
    QueryTask result = this.host.waitForResponse(op).getBody(QueryTask.class);
    Object firstResult = result.results.documents.values().iterator().next();
    return Utils.fromJson(firstResult, ComputeState.class);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Operation(com.vmware.xenon.common.Operation)

Example 88 with QueryTask

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

the class TestVSphereProvisionWithStaticIpTask method findPortGroup.

protected String findPortGroup(String name) throws Throwable {
    Query q = Query.Builder.create().addKindFieldClause(SubnetState.class).addFieldClause(NetworkState.FIELD_NAME_NAME, name).build();
    QueryTask task = QueryTask.Builder.createDirectTask().setQuery(q).build();
    Operation op = QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
    Operation result = this.host.waitForResponse(op);
    try {
        return result.getBody(QueryTask.class).results.documentLinks.get(0);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
        return null;
    }
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Operation(com.vmware.xenon.common.Operation) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 89 with QueryTask

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

the class TestVSphereOvfImport method importOvfAsDescriptions.

@Test
public void importOvfAsDescriptions() throws Throwable {
    this.resourcePool = createResourcePool();
    this.auth = createAuth();
    this.computeHostDescription = createComputeDescription();
    createComputeHost();
    ComputeDescription computeDesc = new ComputeDescription();
    computeDesc.supportedChildren = new ArrayList<>();
    computeDesc.instanceAdapterReference = UriUtils.buildUri(this.host, VSphereUriPaths.INSTANCE_SERVICE);
    computeDesc.authCredentialsLink = this.auth.documentSelfLink;
    computeDesc.name = computeDesc.id;
    computeDesc.dataStoreId = this.dataStoreId;
    ImportOvfRequest req = new ImportOvfRequest();
    req.ovfUri = new File("src/test/resources/vcenter.ovf").toURI();
    req.template = computeDesc;
    Operation op = Operation.createPatch(this.host, OvfImporterService.SELF_LINK).setBody(req).setReferer(this.host.getPublicUri());
    op = this.host.waitForResponse(op);
    assertEquals(Operation.STATUS_CODE_OK, op.getStatusCode());
    Query q = Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_ID, "ovf-", MatchType.PREFIX).build();
    QueryTask task = QueryTask.Builder.createDirectTask().setQuery(q).build();
    QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
    task = this.host.waitForResponse(op).getBody(QueryTask.class);
    assertTrue(task.results.documentLinks.size() > 5);
    snapshotFactoryState("ovf", ComputeDescriptionService.class);
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ImportOvfRequest(com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest) Operation(com.vmware.xenon.common.Operation) File(java.io.File) Test(org.junit.Test)

Example 90 with QueryTask

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

the class TestVSphereEnumerationTask method findRandomHost.

private ComputeState findRandomHost() throws InterruptedException, TimeoutException, ExecutionException {
    Query q = Query.Builder.create().addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.TYPE, VimNames.TYPE_HOST).addKindFieldClause(ComputeState.class).build();
    QueryTask qt = QueryTask.Builder.createDirectTask().setQuery(q).addOption(QueryOption.EXPAND_CONTENT).build();
    Operation op = QueryUtils.createQueryTaskOperation(this.host, qt, ServiceTypeCluster.INVENTORY_SERVICE);
    QueryTask result = this.host.waitForResponse(op).getBody(QueryTask.class);
    Object firstResult = result.results.documents.values().iterator().next();
    return Utils.fromJson(firstResult, ComputeState.class);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) Operation(com.vmware.xenon.common.Operation)

Aggregations

QueryTask (com.vmware.xenon.services.common.QueryTask)147 Query (com.vmware.xenon.services.common.QueryTask.Query)62 Operation (com.vmware.xenon.common.Operation)61 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)39 ArrayList (java.util.ArrayList)26 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)20 List (java.util.List)20 ResourceMetrics (com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)19 UriUtils (com.vmware.xenon.common.UriUtils)18 Utils (com.vmware.xenon.common.Utils)17 HashSet (java.util.HashSet)16 HashMap (java.util.HashMap)14 QueryOption (com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption)12 TimeUnit (java.util.concurrent.TimeUnit)12 ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)11 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)11 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)11 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)11 URI (java.net.URI)11 Set (java.util.Set)11