Search in sources :

Example 51 with Operation

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

the class TestVSphereDiskService method getStoragePolicyLink.

private String getStoragePolicyLink() {
    QueryTask.Query.Builder builder = QueryTask.Query.Builder.create().addKindFieldClause(ResourceGroupState.class);
    builder.addFieldClause(ResourceGroupState.FIELD_NAME_ID, this.spId);
    builder.addCaseInsensitiveFieldClause(StorageDescriptionService.StorageDescription.FIELD_NAME_NAME, this.spName, QueryTask.QueryTerm.MatchType.TERM, QueryTask.Query.Occurance.MUST_OCCUR);
    QueryTask task = QueryTask.Builder.createDirectTask().setQuery(builder.build()).build();
    Operation op = QueryUtils.createQueryTaskOperation(this.host, task, 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 52 with Operation

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

the class TestVSphereEnumerationTask method testGetAvailableRegions.

@Test
public void testGetAvailableRegions() throws Throwable {
    Assume.assumeFalse(isMock());
    startAdditionalServices();
    this.host.waitForServiceAvailable(VSphereUriPaths.VSPHERE_REGION_ENUMERATION_ADAPTER_SERVICE);
    URI uri = UriUtils.buildUri(ServiceHost.LOCAL_HOST, host.getPort(), UriPaths.AdapterTypePath.REGION_ENUMERATION_ADAPTER.adapterLink(PhotonModelConstants.EndpointType.vsphere.toString().toLowerCase()), null);
    Operation post = Operation.createPost(uri);
    post.setBody(createEndpoint((a) -> {
    }, (b) -> {
    }));
    Operation operation = host.getTestRequestSender().sendAndWait(post);
    RegionEnumerationResponse result = operation.getBody(RegionEnumerationResponse.class);
    assertTrue(!result.regions.isEmpty());
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) TimeoutException(java.util.concurrent.TimeoutException) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) Random(java.util.Random) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) URI(java.net.URI) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) ServiceHost(com.vmware.xenon.common.ServiceHost) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) TagService(com.vmware.photon.controller.model.resources.TagService) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) CUSTOM_PROP_STORAGE_SHARED(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_PROP_STORAGE_SHARED) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Assume(org.junit.Assume) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) VimNames(com.vmware.photon.controller.model.adapters.vsphere.util.VimNames) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) RESOURCE_TYPE_KEY(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_TYPE_KEY) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) Assert.assertEquals(org.junit.Assert.assertEquals) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) Test(org.junit.Test)

Example 53 with Operation

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

the class TestVSphereEnumerationTask method testRefresh.

@Test
public void testRefresh() throws Throwable {
    // Create a resource pool where the VM will be housed
    this.resourcePool = createResourcePool();
    this.auth = createAuth();
    this.computeHostDescription = createComputeDescription();
    this.computeHost = createComputeHost(this.computeHostDescription);
    // Always create endpoint, so that there is no bogus
    // endpointLink. This enumeration task is started on a real
    // endpoint. This will also help tango based adapters
    // as the existence of endpoint is more critical there to
    // extract data collector identifier.
    EndpointState ep = createEndpointState(this.computeHost, this.computeHostDescription);
    this.endpoint = TestUtils.doPost(this.host, ep, EndpointState.class, UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
    refreshAndRetire();
    if (!isMock()) {
        ComputeState vm = findRandomVm();
        assertInternalPropertiesSet(vm);
        assertNotNull(vm.endpointLink);
        assertNotNull(vm.tenantLinks);
    }
    captureFactoryState("initial");
    String aComputeLink = null;
    String anUsedHostLink = null;
    String anUnusedHostLink = null;
    if (!isMock()) {
        // clone a random compute and save it under different id
        ComputeState randVm = findRandomVm();
        ComputeState vm = Utils.clone(randVm);
        vm.documentSelfLink = null;
        vm.id = "fake-vm-" + vm.id;
        vm.documentSelfLink = null;
        vm = TestUtils.doPost(this.host, vm, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
        aComputeLink = vm.documentSelfLink;
        ComputeState randomHost = findRandomHost();
        {
            ComputeState host = Utils.clone(randomHost);
            host.documentSelfLink = null;
            host.powerState = PowerState.ON;
            host.id = "fake-host-" + host.id;
            host.documentSelfLink = null;
            host = TestUtils.doPost(this.host, host, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
            anUsedHostLink = host.documentSelfLink;
            ComputeState update = new ComputeState();
            update.customProperties = new HashMap<>();
            update.customProperties.put(ComputeProperties.PLACEMENT_LINK, host.documentSelfLink);
            TestUtils.doPatch(this.host, update, ComputeState.class, UriUtils.buildUri(this.host, randVm.documentSelfLink));
        }
        {
            ComputeState host = Utils.clone(randomHost);
            host.documentSelfLink = null;
            host.powerState = PowerState.ON;
            host.id = "fake-host-unused" + host.id;
            host.documentSelfLink = null;
            host = TestUtils.doPost(this.host, host, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
            anUnusedHostLink = host.documentSelfLink;
        }
    }
    // do a second refresh to test update path
    refreshAndRetire();
    captureFactoryState("updated");
    snapshotFactoryState("metrics", ResourceMetricsService.class);
    if (aComputeLink != null) {
        // the second enumeration marked the fake vm as retired
        Operation op = Operation.createGet(this.host, aComputeLink);
        op = this.host.waitForResponse(op);
        ComputeState compute = op.getBody(ComputeState.class);
        assertEquals(compute.lifecycleState, LifecycleState.RETIRED);
        assertEquals(PowerState.OFF, compute.powerState);
    }
    if (anUsedHostLink != null) {
        // the second enumeration marked the fake vm as retired
        Operation op = Operation.createGet(this.host, anUsedHostLink);
        op = this.host.waitForResponse(op);
        ComputeState compute = op.getBody(ComputeState.class);
        assertEquals(compute.lifecycleState, LifecycleState.RETIRED);
        assertEquals(PowerState.OFF, compute.powerState);
    }
    if (anUnusedHostLink != null) {
        // the unused host is wiped out unconditionally
        Operation op = Operation.createGet(this.host, anUnusedHostLink);
        op = this.host.waitForResponse(op);
        assertEquals(op.getStatusCode(), 404);
    }
    verifyDatastoreAndStoragePolicy();
    if (!isMock()) {
        verifyCIGapForComputeResourcesAndVMs();
        verifyCIGapForDatacenterOrFolder(VimNames.TYPE_DATACENTER);
        verifyCIGapForDatacenterOrFolder(VimNames.TYPE_FOLDER);
        verifyCIGapForDatastore();
        verifyCIGapForComputeResource();
    }
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) HashMap(java.util.HashMap) Operation(com.vmware.xenon.common.Operation) Test(org.junit.Test)

Example 54 with Operation

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

the class TestVSphereEnumerationTask method withTaskResults.

private void withTaskResults(QueryTask task, Consumer<ServiceDocumentQueryResult> handler) {
    task.querySpec.options = EnumSet.of(QueryOption.EXPAND_CONTENT);
    task.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(QUERY_TASK_EXPIRY_MICROS);
    Operation op = QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
    QueryTask result = this.host.waitForResponse(op).getBody(QueryTask.class);
    handler.accept(result.results);
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Operation(com.vmware.xenon.common.Operation)

Example 55 with Operation

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

the class TestVSphereCloneTaskBase method findFirstNetwork.

private String findFirstNetwork() {
    QueryTask.Query q = QueryTask.Query.Builder.create().addFieldClause(ServiceDocument.FIELD_NAME_KIND, Utils.buildKind(NetworkService.NetworkState.class)).addCompositeFieldClause(NetworkService.NetworkState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.TYPE, VimNames.TYPE_NETWORK).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) {
        result.fail(e);
        Assert.fail(e.getMessage());
        // never gets here
        return null;
    }
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Operation(com.vmware.xenon.common.Operation)

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