Search in sources :

Example 36 with ServiceDocumentQueryResult

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;
            }
        }
    }
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 37 with ServiceDocumentQueryResult

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);
    }
}
Also used : NicSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs.NicSpec) NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) IpAssignment(com.vmware.photon.controller.model.resources.NetworkInterfaceDescriptionService.IpAssignment) AzureTestUtil.deleteVMs(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.deleteVMs) SHARED_NETWORK_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.SHARED_NETWORK_NIC_SPEC) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) NetworkInterfaceStateWithDescription(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceStateWithDescription) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Map(java.util.Map) After(org.junit.After) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) Assert.fail(org.junit.Assert.fail) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) OSDisk(com.microsoft.azure.management.compute.OSDisk) EnumSet(java.util.EnumSet) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) DEFAULT_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.DEFAULT_NIC_SPEC) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) VMResourceSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.VMResourceSpec) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) AzureTestUtil.createPrivateImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createPrivateImageSource) AzureTestUtil.createVMResourceFromSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createVMResourceFromSpec) Collectors(java.util.stream.Collectors) NO_PUBLIC_IP_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.NO_PUBLIC_IP_NIC_SPEC) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureTestUtil.createImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createImageSource) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) UriUtils(com.vmware.xenon.common.UriUtils) Optional(java.util.Optional) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) AzureEnumerationAdapterService(com.vmware.photon.controller.model.adapters.azure.enumeration.AzureEnumerationAdapterService) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) DiskService(com.vmware.photon.controller.model.resources.DiskService) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceGroupStateType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType) ResourceGroupInner(com.microsoft.azure.management.resources.implementation.ResourceGroupInner) PhotonModelMetricServices(com.vmware.photon.controller.model.PhotonModelMetricServices) Function(java.util.function.Function) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) AzureTestUtil.createDefaultVMResource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultVMResource) Level(java.util.logging.Level) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) Assume(org.junit.Assume) IMAGE_REFERENCE(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.IMAGE_REFERENCE) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AzureNicSpecs(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs) PRIVATE_IP_NIC_SPEC(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.PRIVATE_IP_NIC_SPEC) DataDisk(com.microsoft.azure.management.compute.DataDisk) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) ImageSource(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext.ImageSource) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) AZURE_CUSTOM_DATA_DISK_SIZE(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AZURE_CUSTOM_DATA_DISK_SIZE) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) AzureTestUtil.generateName(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.generateName) Assert.assertEquals(org.junit.Assert.assertEquals) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) AzureTestUtil.createPrivateImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createPrivateImageSource) AzureTestUtil.createImageSource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createImageSource) ImageSource(com.vmware.photon.controller.model.adapters.util.instance.BaseComputeInstanceContext.ImageSource) VMResourceSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.VMResourceSpec) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 38 with ServiceDocumentQueryResult

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;
    });
}
Also used : ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

Example 39 with ServiceDocumentQueryResult

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);
    }
}
Also used : StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)

Example 40 with ServiceDocumentQueryResult

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"));
        }
    }
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Region(com.microsoft.azure.management.resources.fluentcore.arm.Region) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Level(java.util.logging.Level) HashSet(java.util.HashSet) Utils(com.vmware.xenon.common.Utils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImagesLoadMode(com.vmware.photon.controller.model.adapters.azure.enumeration.AzureImageEnumerationAdapterService.ImagesLoadMode) Map(java.util.Map) After(org.junit.After) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) ProvisioningUtils.queryDocumentsAndAssertExpectedCount(com.vmware.photon.controller.model.tasks.ProvisioningUtils.queryDocumentsAndAssertExpectedCount) Assume(org.junit.Assume) ImageService(com.vmware.photon.controller.model.resources.ImageService) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Collection(java.util.Collection) DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ImageEnumerationTaskService(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Ignore(org.junit.Ignore) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) AzureAdaptersTestUtils(com.vmware.photon.controller.model.adapters.azure.base.AzureAdaptersTestUtils) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Assert(org.junit.Assert) Collection(java.util.Collection) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) 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