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);
}
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());
}
}
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));
}
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;
}
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);
}
}
}
Aggregations