Search in sources :

Example 6 with QueryTop

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);
    }
}
Also used : List(java.util.List) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 7 with QueryTop

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());
    }
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState) List(java.util.List) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 8 with QueryTop

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));
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) Arrays(java.util.Arrays) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) Action1(rx.functions.Action1) StringUtils(org.apache.commons.lang3.StringUtils) Azure(com.microsoft.azure.management.Azure) Utils(com.vmware.xenon.common.Utils) Pair(org.apache.commons.lang3.tuple.Pair) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) OSDisk(com.microsoft.azure.management.compute.OSDisk) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) Set(java.util.Set) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) StorageAccountTypes(com.microsoft.azure.management.compute.StorageAccountTypes) TagService(com.vmware.photon.controller.model.resources.TagService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) InstanceViewStatus(com.microsoft.azure.management.compute.InstanceViewStatus) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) AZURE_DATA_DISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DATA_DISK_CACHING) ImageReferenceInner(com.microsoft.azure.management.compute.implementation.ImageReferenceInner) VirtualMachinesInner(com.microsoft.azure.management.compute.implementation.VirtualMachinesInner) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) RegionInfo(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse.RegionInfo) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) ArrayList(java.util.ArrayList) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) OperatingSystemTypes(com.microsoft.azure.management.compute.OperatingSystemTypes) BiConsumer(java.util.function.BiConsumer) AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK) AZURE_STORAGE_ACCOUNT_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_URI) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) DataDisk(com.microsoft.azure.management.compute.DataDisk) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ENVIRONMENT_NAME_AZURE(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ENVIRONMENT_NAME_AZURE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) CUSTOM_OS_TYPE(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_OS_TYPE) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) QueryTask(com.vmware.xenon.services.common.QueryTask) AZURE_RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_RESOURCE_GROUP_NAME) OSType(com.vmware.photon.controller.model.ComputeProperties.OSType) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) AZURE_MANAGED_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_MANAGED_DISK_TYPE) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) AzureUtils.injectOperationContext(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.injectOperationContext) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AzureConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.getQueryResultLimit) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureUtils.getResourceGroupName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getResourceGroupName) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) Entry(java.util.Map.Entry) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) InstanceViewTypes(com.microsoft.azure.management.compute.InstanceViewTypes) TagsUtil.setTagLinksToResourceState(com.vmware.photon.controller.model.adapters.util.TagsUtil.setTagLinksToResourceState) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) DiskService(com.vmware.photon.controller.model.resources.DiskService) AzureUtils.isDiskManaged(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.isDiskManaged) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) AZURE_OSDISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_OSDISK_CACHING) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) HashMap(java.util.HashMap) HashSet(java.util.HashSet) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) TagsUtil.updateLocalTagStates(com.vmware.photon.controller.model.adapters.util.TagsUtil.updateLocalTagStates) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) Operation(com.vmware.xenon.common.Operation) Page(com.microsoft.azure.Page) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) NetworkInterfaceReferenceInner(com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) Query(com.vmware.xenon.services.common.QueryTask.Query) ArrayList(java.util.ArrayList) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)

Aggregations

QueryTop (com.vmware.photon.controller.model.query.QueryUtils.QueryTop)8 Query (com.vmware.xenon.services.common.QueryTask.Query)5 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)4 List (java.util.List)3 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)2 AzureUriPaths (com.vmware.photon.controller.model.adapters.azure.AzureUriPaths)2 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)2 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)2 Operation (com.vmware.xenon.common.Operation)2 StatelessService (com.vmware.xenon.common.StatelessService)2 Utils (com.vmware.xenon.common.Utils)2 Builder (com.vmware.xenon.services.common.QueryTask.Query.Builder)2 Map (java.util.Map)2 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 DescribeSecurityGroupsRequest (com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest)1 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)1 IpPermission (com.amazonaws.services.ec2.model.IpPermission)1 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)1 Tag (com.amazonaws.services.ec2.model.Tag)1 Page (com.microsoft.azure.Page)1