Search in sources :

Example 31 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class TestAWSEnumerationTask method removeS3BucketRegionFromDiskState.

private void removeS3BucketRegionFromDiskState() {
    Query query = Query.Builder.create().addKindFieldClause(DiskState.class).addFieldClause(DiskState.FIELD_NAME_ID, TEST_BUCKET_NAME).build();
    QueryTask queryTask = QueryTask.Builder.createDirectTask().setQuery(query).addOption(QueryOption.EXPAND_CONTENT).build();
    Operation getTestBucketState = QueryUtils.createQueryTaskOperation(this.host, queryTask, ServiceTypeCluster.INVENTORY_SERVICE).setReferer(this.host.getUri());
    Operation response = this.host.waitForResponse(getTestBucketState);
    QueryTask queryTaskResponse = response.getBody(QueryTask.class);
    DiskState testBucketDiskState = Utils.fromJson(queryTaskResponse.results.documents.get(queryTaskResponse.results.documentLinks.get(0)), DiskState.class);
    testBucketDiskState.regionId = null;
    Operation setNullRegionOp = Operation.createPatch(this.host, testBucketDiskState.documentSelfLink).setBody(testBucketDiskState).setReferer(this.host.getUri());
    response = this.host.waitForResponse(setNullRegionOp);
    // TODO : This test is broken - Setting the regionId to null does not do anything to the underlying state
    if (response.hasPragmaDirective(Operation.PRAGMA_DIRECTIVE_STATE_NOT_MODIFIED)) {
        this.isTestBucketPatched = false;
    } else {
        this.isTestBucketPatched = true;
    }
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Operation(com.vmware.xenon.common.Operation)

Example 32 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class TestAWSSetupUtils method getAdditionalDiskConfiguration.

/**
 * Returns 2 Test diskStates. first disk is marked for encryption and to persistent on vm delete.
 */
private static List<DiskState> getAdditionalDiskConfiguration(VerificationHost host, EndpointState endpointState, ComputeState computeHost, Boolean persistent) throws Throwable {
    List<String[]> additionalDiskConfigs = new ArrayList<>();
    String[] disk1properties = { "ebs", "gp2" };
    String[] disk2properties = { "ebs", "io1", "900" };
    additionalDiskConfigs.add(disk1properties);
    additionalDiskConfigs.add(disk2properties);
    List<DiskState> disks = new ArrayList<>();
    for (int i = 0; i < additionalDiskConfigs.size(); i++) {
        DiskState disk = new DiskState();
        disk.id = UUID.randomUUID().toString();
        disk.documentSelfLink = disk.id;
        disk.bootOrder = null;
        disk.name = "Test_Volume_" + i;
        disk.sourceImageReference = URI.create(imageId);
        disk.capacityMBytes = ADDITIONAL_DISK_SIZE_IN_MEBI_BYTES;
        // add custom properties to root disk from profile
        disk.customProperties = new HashMap<>();
        disk.customProperties.put(DEVICE_TYPE, additionalDiskConfigs.get(i)[0]);
        disk.customProperties.put(VOLUME_TYPE, additionalDiskConfigs.get(i)[1]);
        if (additionalDiskConfigs.get(i).length > 2) {
            disk.customProperties.put(DISK_IOPS, additionalDiskConfigs.get(i)[2]);
        }
        disk.regionId = regionId;
        disk.endpointLink = endpointState.documentSelfLink;
        disk.endpointLinks = new HashSet<>();
        disk.endpointLinks.add(endpointState.documentSelfLink);
        disk.authCredentialsLink = endpointState.authCredentialsLink;
        disk.tenantLinks = endpointState.tenantLinks;
        disk.computeHostLink = endpointState.computeHostLink;
        disk.diskAdapterReference = UriUtils.buildUri(host, AWSDiskService.SELF_LINK);
        disk.persistent = (i == 0) ? persistent : null;
        disk.encrypted = (i == 0) ? true : null;
        disk = TestUtils.doPost(host, disk, DiskService.DiskState.class, UriUtils.buildUri(host, DiskService.FACTORY_LINK));
        disks.add(disk);
    }
    return disks;
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ArrayList(java.util.ArrayList)

Example 33 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class BaseVSphereAdapterTest method createDiskWithDatastore.

/**
 * Create a new disk state to attach it to the virtual machine.
 */
protected DiskState createDiskWithDatastore(String alias, DiskService.DiskType type, int bootOrder, URI sourceImageReference, long capacityMBytes, HashMap<String, String> customProperties) throws Throwable {
    DiskState diskState = constructDiskState(alias, type, bootOrder, sourceImageReference, capacityMBytes, customProperties);
    diskState.storageDescriptionLink = createStorageDescriptionState().documentSelfLink;
    return doPost(this.host, diskState, DiskState.class, UriUtils.buildUri(this.host, DiskService.FACTORY_LINK));
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState)

Example 34 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class BaseVSphereAdapterTest method createCDromWithIso.

/**
 * Create a new CD ROM disk state with ISO Image data.
 */
protected DiskState createCDromWithIso(String alias, DiskService.DiskType type, int bootOrder, URI sourceImageReference, long capacityMBytes, HashMap<String, String> customProperties, boolean insertCDRom, boolean withStorageDescription) throws Throwable {
    DiskState diskState = constructDiskState(alias, type, bootOrder, sourceImageReference, capacityMBytes, customProperties);
    // 150KB
    byte[] iso = new byte[150 * 1024];
    // of zeroes
    Arrays.fill(iso, (byte) 0);
    ContentService.ContentState state = new ContentService.ContentState();
    state.binaryData = iso;
    state = doPost(this.host, state, ContentService.ContentState.class, UriUtils.buildUri(this.host, ContentService.FACTORY_LINK));
    CustomProperties.of(diskState).put(PhotonModelConstants.DISK_CONTENT_LINK, state.documentSelfLink);
    if (insertCDRom) {
        CustomProperties.of(diskState).put(INSERT_CDROM, true);
    }
    if (withStorageDescription) {
        diskState.storageDescriptionLink = createStorageDescriptionState().documentSelfLink;
    }
    return doPost(this.host, diskState, DiskState.class, UriUtils.buildUri(this.host, DiskService.FACTORY_LINK));
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) ContentService(com.vmware.photon.controller.model.resources.ContentService)

Example 35 with DiskState

use of com.vmware.photon.controller.model.resources.DiskService.DiskState in project photon-model by vmware.

the class AWSComputeDiskDay2ServiceTest method verifyPersistedDisks.

private void verifyPersistedDisks(boolean isMock, List<DiskState> persistedDisks) throws Throwable {
    for (DiskState diskState : persistedDisks) {
        assertNotNull(diskState);
        assertNotNull(diskState.persistent);
        assertTrue(diskState.persistent);
        assertNotNull(diskState.id);
        if (!isMock) {
            assertTrue(diskState.id.startsWith("vol-"));
            List<Volume> volumes = getAwsDisksByIds(this.client, this.host, Collections.singletonList(diskState.id));
            Volume volume = volumes.get(0);
            assertNotNull(volume);
        }
    }
}
Also used : Volume(com.amazonaws.services.ec2.model.Volume) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) TestProvisionAWSDisk.createAWSDiskState(com.vmware.photon.controller.model.adapters.awsadapter.TestProvisionAWSDisk.createAWSDiskState)

Aggregations

DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)77 ArrayList (java.util.ArrayList)24 Operation (com.vmware.xenon.common.Operation)23 DiskService (com.vmware.photon.controller.model.resources.DiskService)18 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)16 List (java.util.List)15 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)13 UriUtils (com.vmware.xenon.common.UriUtils)13 Utils (com.vmware.xenon.common.Utils)13 HashMap (java.util.HashMap)13 TimeUnit (java.util.concurrent.TimeUnit)13 QueryTask (com.vmware.xenon.services.common.QueryTask)12 Query (com.vmware.xenon.services.common.QueryTask.Query)12 HashSet (java.util.HashSet)12 Test (org.junit.Test)11 AzureConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants)10 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)10 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)10 AuthCredentialsService (com.vmware.xenon.services.common.AuthCredentialsService)10 Map (java.util.Map)10