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;
}
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);
}
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);
}
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));
}
}
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();
});
}
Aggregations