use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.
the class TestAzureImageEnumerationTask method testPublicImageEnumeration_delete.
/**
* Validate that during enum only images of this 'endpointType' are deleted.
*/
@Test
public void testPublicImageEnumeration_delete() throws Throwable {
Assume.assumeFalse(this.isMock);
setImagesLoadMode(ImagesLoadMode.STANDARD);
try {
// Those images should not be touched by this image enum. {{
//
// Pre-create public and private image in different end-point
EndpointState vSphereEndpointState = createEndpointState(EndpointType.vsphere);
ImageState publicImageState_diffEP = createImageState(vSphereEndpointState, true, PUBLIC);
ImageState privateImageState_diffEP = createImageState(vSphereEndpointState, true, PRIVATE);
// Pre-create public and private image in same end-point but different region
ImageState publicImageState_diffRegion = createImageState(this.endpointState, false, PUBLIC);
ImageState privateImageState_diffRegion = createImageState(this.endpointState, false, PRIVATE);
// }}
// Create one stale image that should be deleted by this enumeration
ImageState staleImageState = createImageState(this.endpointState, true, PUBLIC);
// Validate 5 image states are preCREATED: 1 stale and 2 vSphere and 2 diff region
final int preCreatedCount = 1 + 2 + 2;
queryDocumentsAndAssertExpectedCount(getHost(), preCreatedCount, ImageService.FACTORY_LINK, EXACT_COUNT);
// Under TESTING
kickOffImageEnumeration(this.endpointState, PUBLIC, AZURE_SINGLE_IMAGE_FILTER);
// Validate 1 image state is CREATED and the 2 vSphere and 2 diff region are UNtouched
// plus 1 because we are not deleting the
final int postEnumCount = 1 + 2 + 2 + 1;
// resource, only disassociating it.
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));
} finally {
setImagesLoadMode(ImagesLoadMode.ALL);
}
}
use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.
the class TestAzureImageEnumerationTask method updateImageState.
private ImageState updateImageState(String imageToUpdateSelfLink) throws Throwable {
ImageState toUpdate = new ImageState();
toUpdate.name = "OVERRIDE";
return patchServiceSynchronously(imageToUpdateSelfLink, toUpdate, ImageState.class);
}
use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.
the class VSphereAdapterImageEnumerationService method processAllTemplates.
private void processAllTemplates(Set<String> oldImages, String endpointLink, String taskLink, EnumerationClient client, List<String> tenantLinks) throws RuntimeFaultFaultMsg {
PropertyFilterSpec spec = client.createVmFilterSpec(client.getDatacenter());
for (List<ObjectContent> page : client.retrieveObjects(spec)) {
Phaser phaser = new Phaser(1);
for (ObjectContent oc : page) {
if (!VimUtils.isVirtualMachine(oc.getObj())) {
continue;
}
VmOverlay vm = new VmOverlay(oc);
if (!vm.isTemplate()) {
continue;
}
ImageState state = makeImageFromTemplate(vm);
state.documentSelfLink = buildStableImageLink(endpointLink, state.id);
state.endpointLink = endpointLink;
state.tenantLinks = tenantLinks;
state.regionId = VimUtils.convertMoRefToString(client.getDatacenter());
oldImages.remove(state.documentSelfLink);
phaser.register();
Operation.createPost(PhotonModelUriUtils.createInventoryUri(getHost(), ImageService.FACTORY_LINK)).setBody(state).setCompletion((o, e) -> phaser.arrive()).sendWith(this);
}
phaser.arriveAndAwaitAdvance();
}
}
use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.
the class VSphereAdapterImageEnumerationService method makeImageFromItem.
private ImageState makeImageFromItem(ObjectNode lib, ObjectNode item) {
ImageState res = new ImageState();
String itemName = VapiClient.getString(item, "name", VapiClient.K_OPTIONAL);
String libraryName = VapiClient.getString(lib, "name", VapiClient.K_OPTIONAL);
res.name = libraryName + " / " + itemName;
res.description = VapiClient.getString(item, "description", VapiClient.K_OPTIONAL);
res.id = VapiClient.getString(item, "id", VapiClient.K_OPTIONAL);
CustomProperties.of(res).put(CustomProperties.IMAGE_LIBRARY_ID, VapiClient.getString(item, "library_id", VapiClient.K_OPTIONAL));
return res;
}
use of com.vmware.photon.controller.model.resources.ImageService.ImageState in project photon-model by vmware.
the class ImageServiceTest method buildValidStartState.
// Copy-pasted from ImageService.getDocumentTemplate
private static ImageState buildValidStartState() {
ImageState image = new ImageState();
image.id = "endpoint-specific-image-id";
image.name = "endpoint-specific-image-name";
image.description = "User-friendly-image-description";
image.osFamily = "Linux";
image.regionId = "endpoint-specific-image-region-id";
image.endpointLink = buildUriPath(EndpointService.FACTORY_LINK, "the-A-cloud");
image.groupLinks = singleton(buildUriPath(ResourceGroupService.FACTORY_LINK, "the-A-folder"));
image.tenantLinks = singletonList(buildUriPath(TenantService.FACTORY_LINK, "the-A-tenant"));
DiskConfiguration osDiskConfig = new DiskConfiguration();
osDiskConfig.id = Integer.toString(0);
osDiskConfig.capacityMBytes = Integer.MAX_VALUE;
osDiskConfig.encrypted = true;
osDiskConfig.persistent = true;
osDiskConfig.properties = Collections.singletonMap("disk.cp.name", "disk.cp.value");
DiskConfiguration dataDiskConfig = new DiskConfiguration();
dataDiskConfig.id = Integer.toString(1);
dataDiskConfig.capacityMBytes = Integer.MAX_VALUE;
dataDiskConfig.encrypted = true;
dataDiskConfig.persistent = true;
dataDiskConfig.properties = Collections.singletonMap("disk.cp.name", "disk.cp.value");
image.diskConfigs = Arrays.asList(osDiskConfig, dataDiskConfig);
return image;
}
Aggregations