Search in sources :

Example 16 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.

the class TestAzureImageEnumerationTask method testPublicImageEnumeration_all.

@Test
public void testPublicImageEnumeration_all() throws Throwable {
    Assume.assumeFalse(this.isMock);
    Assume.assumeTrue(this.enableLongRunning);
    // This test takes about 30 mins!
    getHost().setTimeoutSeconds((int) TimeUnit.MINUTES.toSeconds(40));
    ImageEnumerationTaskState task = kickOffImageEnumeration(this.endpointState, PUBLIC, null);
    // Validate at least 4.5K image states are created
    QueryByPages<ImageState> queryAll = new QueryByPages<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, task.tenantLinks);
    queryAll.setMaxPageSize(QueryUtils.DEFAULT_MAX_RESULT_LIMIT);
    Long imagesCount = PhotonModelUtils.waitToComplete(queryAll.collectLinks(Collectors.counting()));
    Assert.assertTrue("Expected at least " + 4_500 + " images, but found only " + imagesCount, imagesCount > 4_500);
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 17 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState 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)

Example 18 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.

the class TestAzureImageEnumerationTask method testPublicImageEnumeration_multi.

@Test
public void testPublicImageEnumeration_multi() throws Throwable {
    Assume.assumeFalse(this.isMock);
    // This test takes about less than 2 mins!
    getHost().setTimeoutSeconds((int) TimeUnit.MINUTES.toSeconds(2));
    ImageEnumerationTaskState task = kickOffImageEnumeration(this.endpointState, PUBLIC, AZURE_MULTI_IMAGES_FILTER);
    // Validate at least 200+ image states are created.
    QueryByPages<ImageState> queryAll = new QueryByPages<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, task.tenantLinks);
    queryAll.setMaxPageSize(QueryUtils.DEFAULT_MAX_RESULT_LIMIT);
    Long imagesCount = PhotonModelUtils.waitToComplete(queryAll.collectLinks(Collectors.counting()));
    Assert.assertTrue("Expected at least " + 200 + " images, but found only " + imagesCount, imagesCount > 200);
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 19 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.

the class TestAzureImageEnumerationTask method afterImageEnumTest.

@After
public final void afterImageEnumTest() throws Throwable {
    QueryByPages<ImageState> queryAll = new QueryByPages<ImageState>(getHost(), Builder.create().addKindFieldClause(ImageState.class).build(), ImageState.class, null);
    queryAll.setMaxPageSize(QueryUtils.DEFAULT_MAX_RESULT_LIMIT);
    AtomicInteger counter = new AtomicInteger(0);
    PhotonModelUtils.waitToComplete(queryAll.queryLinks(imageLink -> {
        try {
            deleteServiceSynchronously(imageLink);
            counter.incrementAndGet();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }));
    getHost().log(Level.INFO, "[" + this.currentTestName.getMethodName() + "] Deleted " + counter + " ImageStates");
}
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) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) After(org.junit.After)

Example 20 with ImageState

use of com.vmware.photon.controller.model.resources.ImageService.ImageState 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)

Aggregations

ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)31 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)12 Test (org.junit.Test)12 List (java.util.List)9 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)7 HashSet (java.util.HashSet)7 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)6 QueryTop (com.vmware.photon.controller.model.query.QueryUtils.QueryTop)6 DiskConfiguration (com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration)6 ImageEnumerationTaskState (com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState)6 AzureBaseTest (com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest)5 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)5 QueryByPages (com.vmware.photon.controller.model.query.QueryUtils.QueryByPages)5 ImageService (com.vmware.photon.controller.model.resources.ImageService)5 Operation (com.vmware.xenon.common.Operation)5 Utils (com.vmware.xenon.common.Utils)5 Builder (com.vmware.xenon.services.common.QueryTask.Query.Builder)5 DeferredResult (com.vmware.xenon.common.DeferredResult)4 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)3 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)3