use of com.vmware.photon.controller.model.query.QueryUtils.QueryTop in project photon-model by vmware.
the class TestAzureImageEnumerationTask method assertDefaultImages.
/**
* Validate 11 image states are created.
*/
private void assertDefaultImages(ImageEnumerationTaskState task) {
QueryTop<ImageState> queryAll = new QueryTop<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, task.tenantLinks);
Map<String, List<ImageState>> imagesByOsFamily = PhotonModelUtils.waitToComplete(queryAll.collectDocuments(Collectors.groupingBy(imageState -> imageState.osFamily)));
Assert.assertEquals("The OS families of default images enumerated is incorrect", Sets.newHashSet(OS_TYPE_LINUX_NAME, OS_TYPE_WINDOWS_NAME), imagesByOsFamily.keySet());
Assert.assertEquals("The count of default Linux images enumerated is incorrect", 7, imagesByOsFamily.get(OS_TYPE_LINUX_NAME).size());
for (ImageState imageState : imagesByOsFamily.get(OS_TYPE_LINUX_NAME)) {
Assert.assertEquals(StringUtils.split(imageState.id, ":").length, 4);
Assert.assertTrue(imageState.id.endsWith(":latest"));
Assert.assertNotNull(imageState.regionId);
Assert.assertNotNull(imageState.name);
Assert.assertNotNull(imageState.description);
}
Assert.assertEquals("The count of default Windows images enumerated is incorrect", 4, imagesByOsFamily.get(OS_TYPE_WINDOWS_NAME).size());
for (ImageState imageState : imagesByOsFamily.get(OS_TYPE_WINDOWS_NAME)) {
Assert.assertEquals(StringUtils.split(imageState.id, ":").length, 4);
Assert.assertTrue(imageState.id.endsWith(":latest"));
Assert.assertNotNull(imageState.regionId);
Assert.assertNotNull(imageState.name);
Assert.assertNotNull(imageState.description);
}
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryTop in project photon-model by vmware.
the class TestAWSImageEnumerationTask method testPublicImageEnumeration_partitioning.
@Test
public void testPublicImageEnumeration_partitioning() throws Throwable {
Assume.assumeFalse(this.isMock);
// Important: MUST share same Endpoint between the two enum runs.
final EndpointState endpointState = createEndpointState();
// Validate NONE PARAVIRTUAL and HVM images are loaded
{
ImageEnumerationTaskState task = kickOffImageEnumeration(endpointState, PUBLIC, AMAZON_PUBLIC_IMAGE_FILTER_PARTITIONING_NO_MATCH);
QueryTop<ImageState> queryAll = new QueryTop<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, task.tenantLinks);
long imagesCount = waitToComplete(queryAll.collectDocuments(Collectors.counting()));
Assert.assertEquals("No images expected", 0, imagesCount);
}
// Validate one PARAVIRTUAL and one HVM image are load
{
ImageEnumerationTaskState task = kickOffImageEnumeration(endpointState, PUBLIC, AMAZON_PUBLIC_IMAGE_FILTER_PARTITIONING);
QueryTop<ImageState> queryAll = new QueryTop<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, task.tenantLinks);
List<ImageState> images = waitToComplete(queryAll.collectDocuments(Collectors.toList()));
Assert.assertEquals("Only TWO images expected", 2, images.size());
Assert.assertTrue(AMAZON_PARAVIRTUAL_IMAGE_NAME + " is missing", images.stream().filter(image -> image.name.equals(AMAZON_PARAVIRTUAL_IMAGE_NAME)).findFirst().isPresent());
Assert.assertTrue(AMAZON_HVM_IMAGE_NAME + " is missing", images.stream().filter(image -> image.name.equals(AMAZON_HVM_IMAGE_NAME)).findFirst().isPresent());
}
}
use of com.vmware.photon.controller.model.query.QueryUtils.QueryTop in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method queryForDiagnosticStorageDescriptions.
/**
* Get all storage descriptions responsible for diagnostics of given VMs.
*/
private void queryForDiagnosticStorageDescriptions(EnumerationContext ctx, ComputeEnumerationSubStages next) {
List<String> diagnosticStorageAccountUris = new ArrayList<>();
String storageAccountProperty = QuerySpecification.buildCompositeFieldName(StorageDescription.FIELD_NAME_CUSTOM_PROPERTIES, AZURE_STORAGE_ACCOUNT_URI);
ctx.virtualMachines.keySet().stream().filter(instanceId -> ctx.virtualMachines.get(instanceId) != null && ctx.virtualMachines.get(instanceId).diagnosticsProfile() != null && ctx.virtualMachines.get(instanceId).diagnosticsProfile().bootDiagnostics() != null && ctx.virtualMachines.get(instanceId).diagnosticsProfile().bootDiagnostics().storageUri() != null).forEach(instanceId -> {
diagnosticStorageAccountUris.add(ctx.virtualMachines.get(instanceId).diagnosticsProfile().bootDiagnostics().storageUri());
});
if (diagnosticStorageAccountUris.isEmpty()) {
ctx.subStage = next;
handleSubStage(ctx);
return;
}
Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(StorageDescription.class).addInClause(storageAccountProperty, diagnosticStorageAccountUris);
QueryTop<StorageDescription> queryDiskStates = new QueryTop<>(getHost(), qBuilder.build(), StorageDescription.class, ctx.parentCompute.tenantLinks, // endpointLink
null, ctx.parentCompute.documentSelfLink).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
queryDiskStates.queryDocuments(storageDesc -> {
ctx.storageDescriptions.put(storageDesc.customProperties.get(AZURE_STORAGE_ACCOUNT_URI), storageDesc);
}).thenRun(() -> logFine(() -> String.format("Found %d matching diagnostics storage accounts", ctx.storageDescriptions.size()))).whenComplete(thenHandleSubStage(ctx, next));
}
Aggregations