Search in sources :

Example 26 with ImageState

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

the class TestAWSImageEnumerationTask method testImageEnumeration_delete.

private void testImageEnumeration_delete(boolean isPublic, String imageFilter) throws Throwable {
    Assume.assumeFalse(this.isMock);
    EndpointState endpointState = createEndpointState();
    // Those images should not be touched by this image enum. {{
    // 
    // Pre-create public and private image in different end-point
    EndpointState azureEndpointState = createDummyEndpointState(EndpointType.azure);
    ImageState publicImageState_diffEP = createImageState(azureEndpointState, true, PUBLIC);
    ImageState privateImageState_diffEP = createImageState(azureEndpointState, true, PRIVATE);
    // Pre-create public and private image in same end-point but different region
    ImageState publicImageState_diffRegion = createImageState(endpointState, false, PUBLIC);
    ImageState privateImageState_diffRegion = createImageState(endpointState, false, PRIVATE);
    // }}
    // Create one stale image that should be deleted by this enumeration
    ImageState staleImageState = createImageState(endpointState, true, isPublic);
    // Validate the 3 image states are preCREATED: 1 stale and 2 vSphere
    int preCreatedCount = 1 + 2 + 2;
    queryDocumentsAndAssertExpectedCount(getHost(), preCreatedCount, ImageService.FACTORY_LINK, EXACT_COUNT);
    // Under TESTING
    kickOffImageEnumeration(endpointState, isPublic, imageFilter);
    // Validate 1 image state is CREATED and the 2 vSphere are UNtouched
    int postEnumCount = 1 + 2 + 2;
    // since we are not deleting stale resource anymore, just disassociating
    postEnumCount++;
    // them
    ServiceDocumentQueryResult imagesAfterEnum = queryDocumentsAndAssertExpectedCount(getHost(), postEnumCount, ImageService.FACTORY_LINK, EXACT_COUNT);
    // Validate 1 stale image state is DISASSOCIATED
    ImageState staleImage = Utils.fromJson(imagesAfterEnum.documents.get(staleImageState.documentSelfLink), ImageState.class);
    Assert.assertTrue("Dummy image should have been disassociated.", staleImage.endpointLinks.isEmpty());
    // Validate vSphere images are untouched
    Assert.assertTrue("Private images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(privateImageState_diffEP.documentSelfLink));
    Assert.assertTrue("Public images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(publicImageState_diffEP.documentSelfLink));
    Assert.assertTrue("Private images from same endpoints but different region should not have been deleted.", imagesAfterEnum.documentLinks.contains(privateImageState_diffRegion.documentSelfLink));
    Assert.assertTrue("Public images from other endpoints should not have been deleted.", imagesAfterEnum.documentLinks.contains(publicImageState_diffRegion.documentSelfLink));
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 27 with ImageState

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

the class TestAWSImageEnumerationTask method updateImageState.

private ImageState updateImageState(String imageToUpdateSelfLink) throws Throwable {
    ImageState toUpdate = new ImageState();
    toUpdate.name = "OVERRIDE";
    toUpdate = patchServiceSynchronously(imageToUpdateSelfLink, toUpdate, ImageState.class);
    return toUpdate;
}
Also used : ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 28 with ImageState

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

the class TestAWSImageEnumerationTask method testPublicImageEnumeration_all.

@Test
public void testPublicImageEnumeration_all() throws Throwable {
    Assume.assumeFalse(this.isMock);
    Assume.assumeTrue(this.enableLongRunning);
    getHost().setTimeoutSeconds((int) TimeUnit.MINUTES.toSeconds(10));
    // Important: MUST share same Endpoint between the two enum runs.
    final EndpointState endpointState = createEndpointState();
    ImageEnumerationTaskState task = kickOffImageEnumeration(endpointState, PUBLIC, AMAZON_PUBLIC_IMAGE_FILTER_ALL);
    // Validate at least 10K image states are created
    // NOTE: do not use queryDocumentsAndAssertExpectedCount
    // since it fails with 'Query returned large number of results'
    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 = waitToComplete(queryAll.collectLinks(Collectors.counting()));
    Assert.assertTrue("Expected at least " + AMAZON_PUBLIC_IMAGES_ALL_COUNT + " images, but found only " + imagesCount, imagesCount > AMAZON_PUBLIC_IMAGES_ALL_COUNT);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) 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) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 29 with ImageState

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

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

the class TestAWSImageEnumerationTask method testPublicImageEnumeration_single.

@Test
public void testPublicImageEnumeration_single() throws Throwable {
    // Important: MUST share same Endpoint between the two enum runs.
    final EndpointState endpointState = createEndpointState();
    ServiceDocumentQueryResult imagesAfterFirstEnum = null;
    ImageState imageAfterFirstEnum = null;
    ServiceDocumentQueryResult imagesAfterSecondEnum = null;
    {
        getHost().log(Level.INFO, "=== First enumeration should create a single '%s' image", AMAZON_PUBLIC_IMAGE_FILTER_SINGLE);
        kickOffImageEnumeration(endpointState, PUBLIC, AMAZON_PUBLIC_IMAGE_FILTER_SINGLE);
        if (!this.isMock) {
            // Validate 1 image state is CREATED
            imagesAfterFirstEnum = queryDocumentsAndAssertExpectedCount(getHost(), 1, ImageService.FACTORY_LINK, EXACT_COUNT);
            imageAfterFirstEnum = Utils.fromJson(imagesAfterFirstEnum.documents.values().iterator().next(), ImageState.class);
            // 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 tenantLinks set.", imageAfterFirstEnum.tenantLinks);
            Assert.assertNotNull("Disk configurations should not be null", imageAfterFirstEnum.diskConfigs);
            Assert.assertTrue("There should be at least one disk configuration for boot disk", imageAfterFirstEnum.diskConfigs.size() > 0);
        }
    }
    {
        getHost().log(Level.INFO, "=== Second enumeration should update the single '%s' image", AMAZON_PUBLIC_IMAGE_FILTER_SINGLE);
        if (!this.isMock) {
            // Update local image state
            updateImageState(imagesAfterFirstEnum.documentLinks.get(0));
        }
        kickOffImageEnumeration(endpointState, PUBLIC, AMAZON_PUBLIC_IMAGE_FILTER_SINGLE);
        if (!this.isMock) {
            // Validate 1 image state is UPDATED (and the local update above is overridden)
            imagesAfterSecondEnum = queryDocumentsAndAssertExpectedCount(getHost(), 1, ImageService.FACTORY_LINK, EXACT_COUNT);
            Assert.assertEquals("Images should be the same after the two enums", imagesAfterFirstEnum.documentLinks, imagesAfterSecondEnum.documentLinks);
            ImageState imageAfterSecondEnum = Utils.fromJson(imagesAfterSecondEnum.documents.values().iterator().next(), ImageState.class);
            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"));
            Assert.assertNotNull("Disk configurations should not be null", imageAfterSecondEnum.diskConfigs);
            Assert.assertTrue("There should be at least one disk configuration for boot disk", imageAfterSecondEnum.diskConfigs.size() > 0);
        }
    }
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

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