Search in sources :

Example 26 with ServiceDocumentQueryResult

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

the class AWSComputeDiskDay2ServiceTest method createAndAttachExternalDisks.

private ComputeState createAndAttachExternalDisks(Instance instance, List<String> existingNames, ComputeState vmStateBeforeAttach, List<String> externallyProvisionedDisks, int numDisks) throws Throwable {
    for (int i = 2, j = 1; i < numDisks + 2; i++, j++) {
        // create disk
        DiskState diskSpec = createAWSDiskState(this.host, this.endpointState, this.currentTestName.getMethodName() + "_disk" + i, !(j == numDisks), this.zoneId, regionId);
        provisionSingleDisk(diskSpec);
        assertEquals(1, diskSpec.endpointLinks.size());
        ServiceDocumentQueryResult diskQueryResult = ProvisioningUtils.queryDiskInstances(this.host, vmStateBeforeAttach.diskLinks.size() + 1);
        DiskState provisionedDisk = new Gson().fromJson(diskQueryResult.documents.get(diskSpec.documentSelfLink).toString(), DiskState.class);
        // assert that the disk is available
        assertEquals("disk status not matching", DiskService.DiskStatus.AVAILABLE, provisionedDisk.status);
        assertNotNull("Disk creation time cannot be empty", provisionedDisk.creationTimeMicros);
        // collect external disks into a list
        externallyProvisionedDisks.add(provisionedDisk.documentSelfLink);
        // attach disk to the vm.
        performDiskOperationAndVerify(vmStateBeforeAttach.documentSelfLink, Arrays.asList(externallyProvisionedDisks.get(i - 2)), ResourceOperation.ATTACH_DISK.operation, DiskTaskService.DiskTaskState.SubStage.FINISHED);
        ComputeState vmStateAfterAttach = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
        // assert the number of disklinks have increased by 1.
        assertEquals(vmStateBeforeAttach.diskLinks.size() + 1, vmStateAfterAttach.diskLinks.size());
        DiskState attachedDisk = this.host.getServiceState(null, DiskState.class, UriUtils.buildUri(this.host, provisionedDisk.documentSelfLink));
        // assert that the attached disk has one endpoint in its endpointLinks.
        assertEquals(1, attachedDisk.endpointLinks.size());
        // assert that the disk is attached.
        assertEquals("disk status not matching", DiskService.DiskStatus.ATTACHED, attachedDisk.status);
        // assert the used device name is same as expected returned by AWS Device name utility.
        assertDeviceName(instance, attachedDisk, existingNames);
        vmStateBeforeAttach = vmStateAfterAttach;
    }
    return vmStateBeforeAttach;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) TestProvisionAWSDisk.createAWSDiskState(com.vmware.photon.controller.model.adapters.awsadapter.TestProvisionAWSDisk.createAWSDiskState) Gson(com.google.gson.Gson) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 27 with ServiceDocumentQueryResult

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

the class AWSComputeDiskDay2ServiceTest method testDiskOperations.

/**
 * This test performs the following steps in sequence.
 * 1. provision a VM with one bootdisk, two new inline disks and one existing disk.
 * 2. Create three independent disks and then explicitly attach all of them to the VM
 * 3. Detach the first two disks that are explicitly attached.
 * 4. Delete VM(all the attached disks which are marked are not marked to persist will also be deleted).
 */
@Test
public void testDiskOperations() throws Throwable {
    Gson gson = new Gson();
    DiskState diskspec1 = createAWSDiskState(this.host, this.endpointState, this.currentTestName.getMethodName() + "_disk1", Boolean.FALSE, this.zoneId, regionId);
    // create a disk
    provisionSingleDisk(diskspec1);
    assertEquals(1, diskspec1.endpointLinks.size());
    // attach a disk while provisioning the vm
    provisionVMAndAttachDisk(this.zoneId, diskspec1.documentSelfLink, true);
    // check that the VM has been created
    ServiceDocumentQueryResult computeQueryResult = ProvisioningUtils.queryComputeInstances(this.host, 2);
    ComputeState vmStateAfterAttach1 = gson.fromJson(computeQueryResult.documents.get(this.vmState.documentSelfLink).toString(), ComputeState.class);
    Instance instance = null;
    if (!this.isMock) {
        List<Instance> instances = getAwsInstancesByIds(this.client, this.host, Collections.singletonList(vmStateAfterAttach1.id));
        instance = instances.get(0);
        ComputeState vm = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, this.vmState.documentSelfLink));
        assertAndSetVMSecurityGroupsToBeDeleted(instance, vm);
        // verify that the disk is attached while provisioning the vm.
        DiskState attachedDisk1 = this.host.getServiceState(null, DiskState.class, UriUtils.buildUri(this.host, diskspec1.documentSelfLink));
        assertEquals("disk status not matching", DiskService.DiskStatus.ATTACHED, attachedDisk1.status);
        assertEquals(1, attachedDisk1.endpointLinks.size());
        this.volumeId = attachedDisk1.id;
    }
    ServiceDocumentQueryResult initialDiskQueryResult = ProvisioningUtils.queryDiskInstances(this.host, vmStateAfterAttach1.diskLinks.size());
    List<String> existingNames = new ArrayList<>();
    for (String diskLink : initialDiskQueryResult.documentLinks) {
        DiskState diskState = Utils.fromJson(initialDiskQueryResult.documents.get(diskLink), DiskState.class);
        existingNames.add(diskState.customProperties.get(AWSConstants.DEVICE_NAME));
    }
    ComputeState vmStateBeforeAttach = vmStateAfterAttach1;
    int numExternalDisks = 3;
    List<String> externallyProvisionedDisks = new ArrayList<>();
    ComputeState vmAfterExternalDiskAttach = createAndAttachExternalDisks(instance, existingNames, vmStateBeforeAttach, externallyProvisionedDisks, numExternalDisks);
    List<String> diskLinksToDetach = externallyProvisionedDisks.stream().filter(diskLink -> !diskLink.equals(externallyProvisionedDisks.get(numExternalDisks - 1))).collect(Collectors.toList());
    // detach disks from the vm and verify the details of the detached disks
    ComputeState vmStateAfterExplicitDetach = detachDiskAndVerify(vmAfterExternalDiskAttach, diskLinksToDetach, this.disksToCleanUp);
    assertEquals(5, vmStateAfterExplicitDetach.diskLinks.size());
    // On VM delete, two inline(Test_Volume_1 and Test_Volume_2), one non-inline external(*_disk1),
    // one external-disk should be deleted. Only one of the attached disks should be persisted.
    deleteVMAndVerifyDisks(vmStateAfterExplicitDetach.documentSelfLink, vmStateAfterExplicitDetach.diskLinks);
}
Also used : Arrays(java.util.Arrays) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) TestAWSSetupUtils.createAWSComputeHost(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSComputeHost) ServiceMetadata(com.vmware.photon.controller.model.util.StartServicesHelper.ServiceMetadata) PhotonModelServices(com.vmware.photon.controller.model.PhotonModelServices) VerificationHost(com.vmware.xenon.common.test.VerificationHost) TestAWSSetupUtils.createAWSResourcePool(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSResourcePool) TestAWSSetupUtils.tearDownTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.tearDownTestVpc) DEVICE_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_NAME) TestAWSSetupUtils.setUpTestVpc(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.setUpTestVpc) ResourceOperationRequest(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationRequest) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) StartServicesHelper(com.vmware.photon.controller.model.util.StartServicesHelper) Gson(com.google.gson.Gson) AWSBlockDeviceNameMapper(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSBlockDeviceNameMapper) TestAWSSetupUtils.verifyRemovalOfResourceState(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.verifyRemovalOfResourceState) Duration(java.time.Duration) Map(java.util.Map) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier) After(org.junit.After) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) TestUtils.getExecutor(com.vmware.photon.controller.model.adapters.awsadapter.TestUtils.getExecutor) ProvisionDiskTaskService(com.vmware.photon.controller.model.tasks.ProvisionDiskTaskService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Collector(java.util.stream.Collector) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) AWS_VM_REQUEST_TIMEOUT_MINUTES(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AWS_VM_REQUEST_TIMEOUT_MINUTES) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) CompletionException(java.util.concurrent.CompletionException) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) Collectors(java.util.stream.Collectors) TestAWSSetupUtils.getResourceState(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getResourceState) TestAWSSetupUtils.avalabilityZoneIdentifier(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.avalabilityZoneIdentifier) TestAWSSetupUtils.getSecurityGroupsIdUsingEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getSecurityGroupsIdUsingEC2Client) List(java.util.List) TestAWSSetupUtils.getAwsDisksByIds(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getAwsDisksByIds) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) AWSSupportedOS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSSupportedOS) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) FactoryService(com.vmware.xenon.common.FactoryService) DiskService(com.vmware.photon.controller.model.resources.DiskService) TaskService(com.vmware.xenon.services.common.TaskService) ServiceMetadata.factoryService(com.vmware.photon.controller.model.util.StartServicesHelper.ServiceMetadata.factoryService) TestAWSSetupUtils.deleteSecurityGroupUsingEC2Client(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.deleteSecurityGroupUsingEC2Client) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TestAWSSetupUtils.getAwsInstancesByIds(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.getAwsInstancesByIds) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) TestProvisionAWSDisk.createAWSDiskState(com.vmware.photon.controller.model.adapters.awsadapter.TestProvisionAWSDisk.createAWSDiskState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) TestName(org.junit.rules.TestName) Volume(com.amazonaws.services.ec2.model.Volume) PLACEMENT_LINK(com.vmware.photon.controller.model.ComputeProperties.PLACEMENT_LINK) DEVICE_TYPE(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.DEVICE_TYPE) Instance(com.amazonaws.services.ec2.model.Instance) Before(org.junit.Before) TestAWSSetupUtils.createAWSAuthentication(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSAuthentication) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Assert.assertNotNull(org.junit.Assert.assertNotNull) AWSStorageType(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSStorageType) Operation(com.vmware.xenon.common.Operation) SecurityGroupService(com.vmware.photon.controller.model.resources.SecurityGroupService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AWSSupportedVirtualizationTypes(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSSupportedVirtualizationTypes) TimeUnit(java.util.concurrent.TimeUnit) TestAWSSetupUtils.createAWSVMResource(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.createAWSVMResource) Rule(org.junit.Rule) TestContext(com.vmware.xenon.common.test.TestContext) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) TestAWSSetupUtils.regionId(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.regionId) TestAWSSetupUtils.setAwsClientMockInfo(com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.setAwsClientMockInfo) IpPermission(com.amazonaws.services.ec2.model.IpPermission) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Instance(com.amazonaws.services.ec2.model.Instance) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) TestProvisionAWSDisk.createAWSDiskState(com.vmware.photon.controller.model.adapters.awsadapter.TestProvisionAWSDisk.createAWSDiskState) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

Example 28 with ServiceDocumentQueryResult

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

the class LongRunEndToEndStatsAggregationTest method runStatsCollectionAndAggregationLogNodeStatsPeriodically.

/**
 * Periodically runs stats collection and aggregation and logs node stats.
 */
private void runStatsCollectionAndAggregationLogNodeStatsPeriodically() {
    this.host.getScheduledExecutor().scheduleAtFixedRate(() -> {
        try {
            this.host.log(Level.INFO, "Running stats collection...");
            // perform stats collection on given AWS endpoint.
            resourceStatsCollection(this.host, this.isMock, this.computeHost.resourcePoolLink);
            ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)));
            this.host.log(Level.INFO, "Running stats aggregation...");
            resourceStatsAggregation(this.host, this.computeHost.resourcePoolLink);
            logNodeStats(this.host.getServiceStats(this.nodeStatsUri));
            ServiceDocumentQueryResult aggrResult = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, ResourceMetricsService.FACTORY_LINK));
            // check compute resource has stats generated for all metric keys
            checkInMemoryStatsPresent(res);
            // check expiration time for all resource aggregate metric documents
            checkExpirationTime(aggrResult);
            // check to verify appropriate resource metrics entries are present for compute resources.
            verifyResourceMetricEntries(res);
            // verify time bin metrics for every compute resource and endpoint estimated charges
            verifyTimeBinMetrics(res);
        } catch (Throwable e) {
            this.host.log(Level.WARNING, "Error running stats aggregation in test" + e.getMessage());
        }
    }, 0, this.aggregationFrequencyInMinutes, TimeUnit.MINUTES);
}
Also used : ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 29 with ServiceDocumentQueryResult

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

the class TestAWSEndpointService method testCreateAndThenValidate.

@Test
public void testCreateAndThenValidate() throws Throwable {
    this.endpointTestsRunner.testCreateAndThenValidate(this.endpointState);
    // Tests that EndpointService QueryTasks can use SELECT_LINKS + EXPAND_LINKS
    Query query = Builder.create().addKindFieldClause(EndpointState.class).build();
    QueryTask queryTask = QueryTask.Builder.createDirectTask().addOptions(EnumSet.of(QueryOption.EXPAND_CONTENT, QueryOption.SELECT_LINKS, QueryOption.EXPAND_LINKS)).addLinkTerm(EndpointState.FIELD_NAME_AUTH_CREDENTIALS_LINK).setQuery(query).build();
    this.host.createQueryTaskService(queryTask, false, true, queryTask, null);
    ServiceDocumentQueryResult results = queryTask.results;
    assertEquals(Long.valueOf(1), results.documentCount);
    assertEquals(1, results.selectedLinks.size());
    assertEquals(1, results.selectedDocuments.size());
    QueryResultsProcessor processor = QueryResultsProcessor.create(results);
    for (EndpointState endpoint : processor.documents(EndpointState.class)) {
        String authCredentialSelfLink = endpoint.authCredentialsLink;
        assertNotNull(authCredentialSelfLink);
        assertNotNull(processor.selectedDocument(authCredentialSelfLink, AuthCredentialsServiceState.class));
    }
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) QueryTask(com.vmware.xenon.services.common.QueryTask) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Query(com.vmware.xenon.services.common.QueryTask.Query) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

Example 30 with ServiceDocumentQueryResult

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

the class TestVSphereStatsTask method testCollectStats.

@Test
public void testCollectStats() throws Throwable {
    // Create a resource pool where the VM will be housed
    this.resourcePool = createResourcePool();
    this.auth = createAuth();
    this.computeHostDescription = createComputeDescription();
    this.computeHost = createComputeHost();
    // collect data
    doRefresh();
    // collect stats for a few instances
    StatsCollectionTaskService.StatsCollectionTaskState statCollectionState = new StatsCollectionTaskService.StatsCollectionTaskState();
    statCollectionState.resourcePoolLink = this.resourcePool.documentSelfLink;
    ScheduledTaskState statsCollectionTaskState = new ScheduledTaskState();
    statsCollectionTaskState.factoryLink = StatsCollectionTaskService.FACTORY_LINK;
    statsCollectionTaskState.initialStateJson = Utils.toJson(statCollectionState);
    statsCollectionTaskState.intervalMicros = TimeUnit.MINUTES.toMicros(1);
    TestUtils.doPost(this.host, statsCollectionTaskState, ScheduledTaskState.class, UriUtils.buildUri(this.host, ScheduledTaskService.FACTORY_LINK));
    if (isMock()) {
        return;
    }
    // wait up to 5 minutes as first call to perfManager can take a while.
    host.setTimeoutSeconds(5 * 60);
    host.waitFor("No stats inserted", () -> {
        ServiceDocumentQueryResult state = host.getFactoryState(UriUtils.buildFactoryUri(TestVSphereStatsTask.this.host, ResourceMetricsService.class));
        return !state.documentLinks.isEmpty();
    });
}
Also used : ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) StatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

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