Search in sources :

Example 21 with ImageState

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);
    }
}
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) AzureBaseTest(com.vmware.photon.controller.model.adapters.azure.base.AzureBaseTest) Test(org.junit.Test)

Example 22 with ImageState

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);
}
Also used : ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 23 with ImageState

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();
    }
}
Also used : PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) RuntimeFaultFaultMsg(com.vmware.vim25.RuntimeFaultFaultMsg) VapiClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RpcException(com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException) HashSet(java.util.HashSet) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) Connection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection) ImageService(com.vmware.photon.controller.model.resources.ImageService) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) VapiConnection(com.vmware.photon.controller.model.adapters.vsphere.vapi.VapiConnection) Element(com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element) ObjectContent(com.vmware.vim25.ObjectContent) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) DatacenterLister(com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Set(java.util.Set) IOException(java.io.IOException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) List(java.util.List) InvalidPropertyFaultMsg(com.vmware.vim25.InvalidPropertyFaultMsg) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) LibraryClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.LibraryClient) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) Phaser(java.util.concurrent.Phaser) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) ImageEnumerateRequest(com.vmware.photon.controller.model.adapterapi.ImageEnumerateRequest) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) Phaser(java.util.concurrent.Phaser) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 24 with ImageState

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;
}
Also used : ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 25 with ImageState

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;
}
Also used : DiskConfiguration(com.vmware.photon.controller.model.resources.ImageService.ImageState.DiskConfiguration) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

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