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