use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class AzureTestUtil method validateDiskInternalTag.
/**
* Validate DiskStates are populated with the appropriate type tagLinks
*/
public static void validateDiskInternalTag(VerificationHost host) {
ServiceDocumentQueryResult result = host.getExpandedFactoryState(UriUtils.buildUri(host, DiskService.FACTORY_LINK));
List<String> tenantLinks = Collections.singletonList(EndpointType.azure.name() + "-tenant");
String managedDiskTagLink = getTagState(tenantLinks, TAG_KEY_TYPE, AzureResourceType.azure_managed_disk.name()).documentSelfLink;
String vhdTagLink = getTagState(tenantLinks, TAG_KEY_TYPE, AzureResourceType.azure_vhd.name()).documentSelfLink;
String blobTagLink = getTagState(tenantLinks, TAG_KEY_TYPE, AzureResourceType.azure_blob.name()).documentSelfLink;
for (Object document : result.documents.values()) {
DiskState state = Utils.fromJson(document, DiskState.class);
if (state.storageType != null) {
switch(state.storageType) {
case AZURE_STORAGE_DISKS:
if (state.customProperties != null && state.customProperties.containsKey(AzureConstants.AZURE_MANAGED_DISK_TYPE)) {
// check tagLink for managed disks
assertTrue(state.tagLinks.contains(managedDiskTagLink));
} else {
// check tagLink for vhds
assertTrue(state.tagLinks.contains(vhdTagLink));
}
break;
case AZURE_STORAGE_BLOBS:
assertTrue(state.tagLinks.contains(blobTagLink));
break;
default:
break;
}
}
}
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class TestAzureProvisionTask method testProvisionDataDisksAndEnumeration.
/**
* Creates Azure instance with 2 data disks via provision task and enumerate the disks
* and verify disk duplication in local store.
*/
@Test
public void testProvisionDataDisksAndEnumeration() throws Throwable {
ImageSource imageSource = createImageSource(getHost(), this.endpointState, IMAGE_REFERENCE);
// Create a Azure VM compute resource with 2 additional disks.
int numberOfAdditionalDisks = 2;
VMResourceSpec vmResourceSpec = new VMResourceSpec(getHost(), this.computeHost, this.endpointState, azureVMName).withImageSource(imageSource).withNicSpecs(DEFAULT_NIC_SPEC).withNumberOfAdditionalDisks(numberOfAdditionalDisks).withManagedDisk(false);
// create Azure VM compute resource.
this.vmState = createVMResourceFromSpec(vmResourceSpec);
kickOffProvisionTask();
runEnumeration();
// Assert if 2 additional disks were created
List<DiskState> diskStates = this.vmState.diskLinks.stream().map(diskLink -> getHost().getServiceState(null, DiskState.class, UriUtils.buildUri(getHost(), diskLink))).collect(Collectors.toList());
for (DiskState diskState : diskStates) {
if (diskState.bootOrder == 1) {
assertEquals("OS Disk size does not match", AzureTestUtil.AZURE_CUSTOM_OSDISK_SIZE, diskState.capacityMBytes);
} else {
assertEquals("Data Disk size does not match", AzureTestUtil.AZURE_CUSTOM_DATA_DISK_SIZE, diskState.capacityMBytes);
if (!this.isMock) {
assertNotNull(diskState.customProperties);
assertNotNull(diskState.customProperties.get(DISK_CONTROLLER_NUMBER));
}
}
}
// Run enumeration second time to verify disk states are not duplicated
runEnumeration();
ServiceDocumentQueryResult result = ProvisioningUtils.queryAllFactoryResources(this.host, DiskService.FACTORY_LINK);
List<DiskState> diskList = result.documents.keySet().stream().map(diskLink -> getHost().getServiceState(null, DiskState.class, UriUtils.buildUri(getHost(), diskLink))).collect(Collectors.toList());
for (DiskState diskState : diskStates) {
long nameCount = diskList.stream().filter(ds -> ds.name.equalsIgnoreCase(diskState.name)).count();
String msg = String.format("Duplicate of DiskState %s must not be present. ", diskState.name);
assertEquals(msg, 1, nameCount);
long idCount = diskList.stream().filter(ds -> ds.id.equalsIgnoreCase(diskState.id)).count();
String idMsg = String.format("Duplicate of DiskState ID %s must not be present. ", diskState.id);
assertEquals(idMsg, 1, idCount);
}
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class LongRunEndToEndAzureStatsAggregation method testStatsAggregation.
/**
* Test to perform end to end stats aggregation with azure instance adapter.
* Performs enumeration against a real Azure endpoint if provided.
* Test is then performed with periodic execution of stats collection and aggregation.
* Verifies the compute types of resources and their stats for last successful collection time.
* Verifies in memory stats generation for resource aggregate metric documents.
* Verifies expiration time for resource aggregate metric documents.
* Verifies resource metric entries and its time bin entries for resource aggregate metric documents.
*/
@Test
public void testStatsAggregation() throws Throwable {
this.host.log("Running test: " + this.currentTestName);
if (this.isMock) {
return;
}
// perform stats aggregation before stats collection takes place.
// As no stats collection is performed yet, ResourceAggregateMetric document count will be 0.
resourceStatsAggregation(this.host, computeHost.resourcePoolLink);
ServiceDocumentQueryResult aggrRes = this.host.getFactoryState(UriUtils.buildUri(this.host, ResourceMetricsService.FACTORY_LINK));
assertEquals(0, aggrRes.documentLinks.size());
// perform enumeration on given Azure endpoint.
runEnumeration(this.host, computeHost.documentSelfLink, computeHost.resourcePoolLink, endpointState, this.isMock);
// periodically perform stats collection and aggregation on given Azure endpoint
runStatsCollectionAndAggregationLogNodeStatsPeriodically();
this.host.log(Level.INFO, "Waiting for multiple stats aggregation runs...");
this.host.waitFor("Timeout while waiting for test run duration", () -> {
TimeUnit.MINUTES.sleep(this.testRunDurationInMinutes);
this.host.getScheduledExecutor().shutdown();
this.host.getScheduledExecutor().awaitTermination(EXECUTOR_TERMINATION_WAIT_DURATION_MINUTES, TimeUnit.MINUTES);
return true;
});
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class AzureStorageEnumerationServiceTest method testAzureStorageAccountEnumeration.
@Test
public void testAzureStorageAccountEnumeration() throws Throwable {
kickOffStorageAccountEnumeration();
// Exit if it is mock. Nothing to assert.
if (this.isMock) {
return;
}
// Get Storage Descriptions. At least one should exist. Maximum of 2 will be fetched.
ServiceDocumentQueryResult result = ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.getHost(), 1, StorageDescriptionService.FACTORY_LINK, false);
// Assert on returned storage description fields
Iterator<Object> itr = result.documents.values().iterator();
while (itr.hasNext()) {
StorageDescriptionService.StorageDescription storageDescription = Utils.fromJson(itr.next(), StorageDescriptionService.StorageDescription.class);
verifyStorageDescription(storageDescription);
}
}
use of com.vmware.xenon.common.ServiceDocumentQueryResult in project photon-model by vmware.
the class TestAzureImageEnumerationTask method testPublicImageEnumeration_singleAndDefaults.
@Test
public void testPublicImageEnumeration_singleAndDefaults() throws Throwable {
// Important: MUST share same Endpoint between the two enum runs.
ServiceDocumentQueryResult imagesAfterFirstEnum = null;
ImageState imageAfterFirstEnum = null;
ServiceDocumentQueryResult imagesAfterSecondEnum = null;
final Function<Collection<Object>, ImageState> imageFinder = collection -> collection.stream().map(imageStateAsObj -> Utils.fromJson(imageStateAsObj, ImageState.class)).filter(imageState -> imageState.id.startsWith(AZURE_SINGLE_IMAGE_FILTER)).findFirst().get();
{
getHost().log(Level.INFO, "=== First enumeration should create a single '%s' image", AZURE_SINGLE_IMAGE_FILTER);
kickOffImageEnumeration(this.endpointState, PUBLIC, AZURE_SINGLE_IMAGE_FILTER);
if (!this.isMock) {
// Validate 1 image state is CREATED (in addition of 11 default)
imagesAfterFirstEnum = queryDocumentsAndAssertExpectedCount(getHost(), 1 + DEFAULT_IMAGES, ImageService.FACTORY_LINK, EXACT_COUNT);
imageAfterFirstEnum = imageFinder.apply(imagesAfterFirstEnum.documents.values());
// Validate created image is correctly populated
Assert.assertNotNull("Public image must have endpointType set.", imageAfterFirstEnum.endpointType);
Assert.assertNull("Public image must NOT have endpointLink set.", imageAfterFirstEnum.endpointLink);
Assert.assertNull("Public image must NOT have endpointLinks set.", imageAfterFirstEnum.endpointLinks);
Assert.assertNull("Public image must NOT have tenantLinks set.", imageAfterFirstEnum.tenantLinks);
Assert.assertEquals("Image.name is different from the id", imageAfterFirstEnum.id, imageAfterFirstEnum.name);
Assert.assertEquals("Image.description is different from the id", imageAfterFirstEnum.id, imageAfterFirstEnum.description);
Assert.assertEquals("Image.region is invalid", "westus", imageAfterFirstEnum.regionId);
}
}
{
getHost().log(Level.INFO, "=== Second enumeration should update the single '%s' image", AZURE_SINGLE_IMAGE_FILTER);
if (!this.isMock) {
// Update local image state
updateImageState(imageAfterFirstEnum.documentSelfLink);
}
kickOffImageEnumeration(this.endpointState, PUBLIC, AZURE_SINGLE_IMAGE_FILTER);
if (!this.isMock) {
// Validate 1 image state is UPDATED (and the local update above is overridden)
imagesAfterSecondEnum = queryDocumentsAndAssertExpectedCount(getHost(), 1 + DEFAULT_IMAGES, ImageService.FACTORY_LINK, EXACT_COUNT);
Assert.assertEquals("Images should be the same after the two enums", imagesAfterFirstEnum.documents.keySet(), imagesAfterSecondEnum.documents.keySet());
ImageState imageAfterSecondEnum = imageFinder.apply(imagesAfterSecondEnum.documents.values());
Assert.assertNotEquals("Images timestamp should differ after the two enums", imageAfterFirstEnum.documentUpdateTimeMicros, imageAfterSecondEnum.documentUpdateTimeMicros);
Assert.assertTrue("Image name is not updated correctly after second enum.", !imageAfterSecondEnum.name.contains("OVERRIDE"));
}
}
}
Aggregations