Search in sources :

Example 56 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState 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 57 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState 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 58 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestAWSImageEnumerationTask method createDummyEndpointState.

private EndpointState createDummyEndpointState(EndpointType endpointType) throws Throwable {
    EndpointState endpoint = new EndpointState();
    endpoint.endpointType = endpointType.name();
    endpoint.id = endpointType.name() + "-id";
    endpoint.name = endpointType.name() + "-name";
    return TestUtils.doPost(host, endpoint, EndpointState.class, UriUtils.buildUri(host, EndpointService.FACTORY_LINK));
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Example 59 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestAWSImageEnumerationTask method createEndpointState.

private EndpointState createEndpointState() throws Throwable {
    EndpointType endpointType = EndpointType.aws;
    EndpointState endpoint;
    {
        endpoint = new EndpointState();
        endpoint.endpointType = endpointType.name();
        endpoint.id = endpointType.name() + "-id";
        endpoint.name = endpointType.name() + "-name";
        endpoint.endpointProperties = new HashMap<>();
        endpoint.endpointProperties.put(PRIVATE_KEY_KEY, this.secretKey);
        endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, this.accessKey);
    }
    EndpointAllocationTaskState allocateEndpoint = new EndpointAllocationTaskState();
    allocateEndpoint.endpointState = endpoint;
    allocateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
    allocateEndpoint.taskInfo = new TaskState();
    allocateEndpoint.taskInfo.isDirect = true;
    allocateEndpoint.tenantLinks = Arrays.asList(endpointType.name() + "-tenant");
    allocateEndpoint = TestUtils.doPost(this.host, allocateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    return allocateEndpoint.endpointState;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) HashMap(java.util.HashMap) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) TaskState(com.vmware.xenon.common.TaskState) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState)

Example 60 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState 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

EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)69 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)23 Operation (com.vmware.xenon.common.Operation)22 Test (org.junit.Test)16 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)13 URI (java.net.URI)13 HashMap (java.util.HashMap)13 Query (com.vmware.xenon.services.common.QueryTask.Query)12 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)11 UriUtils (com.vmware.xenon.common.UriUtils)11 Utils (com.vmware.xenon.common.Utils)11 List (java.util.List)11 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)10 ServiceDocument (com.vmware.xenon.common.ServiceDocument)10 Collectors (java.util.stream.Collectors)10 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9