Search in sources :

Example 46 with Operation

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

the class TestVSphereOvfProvisionTaskBase method deployOvfAndReturnComputeState.

private ComputeService.ComputeState deployOvfAndReturnComputeState(boolean isStoragePolicyBased, boolean withAdditionalDisks, Map<String, String> customProperties, boolean isSnapshotLimitCase) throws Throwable {
    ComputeService.ComputeState vm = null;
    // Create a resource pool where the VM will be housed
    this.resourcePool = createResourcePool();
    this.auth = createAuth();
    this.computeHostDescription = createComputeDescription();
    this.computeHost = createComputeHost(this.computeHostDescription);
    ComputeDescriptionService.ComputeDescription computeDesc = createTemplate();
    ImportOvfRequest req = new ImportOvfRequest();
    req.ovfUri = this.ovfUri;
    req.template = computeDesc;
    Operation op = Operation.createPatch(this.host, OvfImporterService.SELF_LINK).setBody(req).setReferer(this.host.getPublicUri());
    CompletableFuture<Operation> f = this.host.sendWithFuture(op);
    // depending on OVF location you may want to increase the timeout
    f.get(360, TimeUnit.SECONDS);
    snapshotFactoryState("ovf", ComputeDescriptionService.class);
    enumerateComputes(this.computeHost);
    String descriptionLink = findFirstOvfDescriptionLink();
    this.bootDisk = createBootDiskWithCustomProperties(CLOUD_CONFIG_DATA, isStoragePolicyBased, customProperties);
    vm = createVmState(descriptionLink, withAdditionalDisks, customProperties, isSnapshotLimitCase);
    // set timeout for the next step, vmdk upload may take some time
    host.setTimeoutSeconds(60 * 5);
    // provision
    ProvisionComputeTaskService.ProvisionComputeTaskState outTask = createProvisionTask(vm);
    awaitTaskEnd(outTask);
    vm = getComputeState(vm);
    snapshotFactoryState("ovf", ComputeService.class);
    if (!isMock() && withAdditionalDisks || customProperties.get(PROVISION_TYPE) != null) {
        BasicConnection connection = createConnection();
        GetMoRef get = new GetMoRef(connection);
        List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
        if (customProperties.get(PROVISION_TYPE) != null) {
            VirtualDiskType diskProvisionType = VirtualDiskType.fromValue(customProperties.get(PROVISION_TYPE));
            VirtualDisk bootDisk = virtualDisks.stream().filter(vd -> vd.getUnitNumber() == 0).findFirst().orElse(null);
            VirtualDiskFlatVer2BackingInfo backing = (VirtualDiskFlatVer2BackingInfo) bootDisk.getBacking();
            if (VirtualDiskType.THIN == diskProvisionType) {
                assertTrue(backing.isThinProvisioned());
            } else if (VirtualDiskType.THICK == diskProvisionType) {
                assertFalse(backing.isThinProvisioned());
            } else if (VirtualDiskType.EAGER_ZEROED_THICK == diskProvisionType) {
                assertFalse(backing.isThinProvisioned());
                assertTrue(backing.isEagerlyScrub());
            }
        }
        if (withAdditionalDisks) {
            assertEquals(3, virtualDisks.size());
        }
    }
    return vm;
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) VirtualDiskType(com.vmware.vim25.VirtualDiskType) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) Operation(com.vmware.xenon.common.Operation) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VirtualDisk(com.vmware.vim25.VirtualDisk) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) VirtualDiskFlatVer2BackingInfo(com.vmware.vim25.VirtualDiskFlatVer2BackingInfo) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) ImportOvfRequest(com.vmware.photon.controller.model.adapters.vsphere.ovf.ImportOvfRequest)

Example 47 with Operation

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

the class TestVSphereOvfProvisionTaskBase method findFirstOvfDescriptionLink.

protected String findFirstOvfDescriptionLink() throws Exception {
    QueryTask.Query q = QueryTask.Query.Builder.create().addFieldClause(ComputeService.ComputeState.FIELD_NAME_ID, "ovf-", QueryTask.QueryTerm.MatchType.PREFIX).build();
    QueryTask qt = QueryTask.Builder.createDirectTask().setQuery(q).build();
    Operation op = QueryUtils.createQueryTaskOperation(this.host, qt, ServiceTypeCluster.INVENTORY_SERVICE);
    QueryTask result = this.host.waitForResponse(op).getBody(QueryTask.class);
    return result.results.documentLinks.get(0);
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Operation(com.vmware.xenon.common.Operation)

Example 48 with Operation

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

the class TestVSphereProvisionWithStaticIpTask method findTemplate.

private ComputeState findTemplate() throws InterruptedException, ExecutionException, TimeoutException {
    String templateVmName = System.getProperty("vc.templateVmName");
    QuerySpecification qs = new QuerySpecification();
    qs.options.add(QueryOption.EXPAND_CONTENT);
    qs.query.addBooleanClause(Query.Builder.create().addFieldClause(ComputeState.FIELD_NAME_NAME, templateVmName).addFieldClause(ServiceDocument.FIELD_NAME_KIND, Utils.buildKind(ComputeState.class)).build());
    QueryTask qt = QueryTask.create(qs).setDirect(true);
    Operation op = QueryUtils.createQueryTaskOperation(this.host, qt, ServiceTypeCluster.INVENTORY_SERVICE);
    QueryTask result = this.host.sendWithFuture(op).thenApply(o -> o.getBody(QueryTask.class)).get(10, TimeUnit.SECONDS);
    return Utils.fromJson(result.results.documents.values().iterator().next(), ComputeState.class);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) Arrays(java.util.Arrays) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) TimeoutException(java.util.concurrent.TimeoutException) ServiceDocument(com.vmware.xenon.common.ServiceDocument) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) DiskType(com.vmware.photon.controller.model.resources.DiskService.DiskType) ArrayList(java.util.ArrayList) Utils(com.vmware.xenon.common.Utils) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) URI(java.net.URI) VirtualMachineGuestOsIdentifier(com.vmware.vim25.VirtualMachineGuestOsIdentifier) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) NetworkInterfaceDescriptionService(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Test(org.junit.Test) UUID(java.util.UUID) File(java.io.File) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IOUtils(org.apache.commons.io.IOUtils) BootConfig(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) Ignore(org.junit.Ignore) FileEntry(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig.FileEntry) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) NetworkInterfaceDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.NetworkInterfaceDescription) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Assert(org.junit.Assert) DiskService(com.vmware.photon.controller.model.resources.DiskService) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) Assert.assertEquals(org.junit.Assert.assertEquals) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) Operation(com.vmware.xenon.common.Operation)

Example 49 with Operation

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

the class TestVSphereProvisionWithStaticIpTask method fetchServiceState.

private <T extends ServiceDocument> T fetchServiceState(Class<T> bodyType, String networkLink) {
    Operation op = Operation.createGet(this.host, networkLink);
    op = this.host.waitForResponse(op);
    return op.getBody(bodyType);
}
Also used : Operation(com.vmware.xenon.common.Operation)

Example 50 with Operation

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

the class TestDatacenterListerService method listDatacenters.

@Test
public void listDatacenters() {
    EnumerateDatacentersRequest req = new EnumerateDatacentersRequest();
    req.host = URI.create(vcUrl).getHost();
    req.username = vcUsername;
    req.password = vcPassword;
    req.isMock = isMock();
    Operation op = Operation.createPatch(this.host, VSphereUriPaths.DC_ENUMERATOR_SERVICE).setBody(req);
    op = this.host.waitForResponse(op);
    assertEquals(Operation.STATUS_CODE_OK, op.getStatusCode());
    assertNotNull(op.getBodyRaw());
    if (!isMock()) {
        EnumerateDatacentersResponse resp = op.getBody(EnumerateDatacentersResponse.class);
        assertTrue(resp.datacenters.contains(datacenterId));
    }
}
Also used : EnumerateDatacentersResponse(com.vmware.photon.controller.model.adapters.vsphere.DatacenterEnumeratorService.EnumerateDatacentersResponse) Operation(com.vmware.xenon.common.Operation) EnumerateDatacentersRequest(com.vmware.photon.controller.model.adapters.vsphere.DatacenterEnumeratorService.EnumerateDatacentersRequest) Test(org.junit.Test)

Aggregations

Operation (com.vmware.xenon.common.Operation)391 URI (java.net.URI)142 ArrayList (java.util.ArrayList)132 QueryTask (com.vmware.xenon.services.common.QueryTask)118 List (java.util.List)118 Utils (com.vmware.xenon.common.Utils)111 StatelessService (com.vmware.xenon.common.StatelessService)108 UriUtils (com.vmware.xenon.common.UriUtils)106 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)98 Map (java.util.Map)92 HashMap (java.util.HashMap)90 OperationJoin (com.vmware.xenon.common.OperationJoin)86 Query (com.vmware.xenon.services.common.QueryTask.Query)86 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)82 Collectors (java.util.stream.Collectors)79 HashSet (java.util.HashSet)78 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)73 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)70 DeferredResult (com.vmware.xenon.common.DeferredResult)69 Consumer (java.util.function.Consumer)69