Search in sources :

Example 11 with DiskState

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

the class AzureDiskEnumerationAdapterService method disassociateEndpointLinksFromDiskStates.

/**
 * Disassociate EndpointLinks from Disk States (of local store) that are no longer existing in Azure.
 */
private void disassociateEndpointLinksFromDiskStates(DiskEnumContext ctx, DiskEnumStages nextStage) {
    Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(DiskState.class).addFieldClause(DiskState.FIELD_NAME_STATUS, DiskStatus.AVAILABLE).addRangeClause(DiskState.FIELD_NAME_UPDATE_TIME_MICROS, QueryTask.NumericRange.createLessThanRange(ctx.enumerationStartTimeInMicros));
    QueryTop<DiskState> queryLocalDiskStates = new QueryTop<>(getHost(), qBuilder.build(), DiskState.class, ctx.parentCompute.tenantLinks, null, ctx.parentCompute.documentSelfLink).setClusterType(ClusterUtil.ServiceTypeCluster.INVENTORY_SERVICE);
    final String msg = queryLocalDiskStates.documentClass.getSimpleName() + " - Disassociation of endpoint links from disk states ";
    logInfo(() -> msg + " STARTED");
    queryLocalDiskStates.queryDocuments(ds -> {
        // check for diskState which is managed disk type
        if (ds.customProperties != null && ds.customProperties.containsKey(AZURE_MANAGED_DISK_TYPE)) {
            if (!ctx.unattachedDisks.containsKey(ds.id.toLowerCase())) {
                Operation disassociateOp = PhotonModelUtils.createRemoveEndpointLinksOperation(this, ctx.request.endpointLink, ds);
                if (disassociateOp != null) {
                    sendRequest(disassociateOp);
                }
            }
        }
    }).thenRun(() -> logInfo(() -> "Disassociation of endpoint link from disk states which " + "are not present in Azure.")).whenComplete((aVoid, th) -> {
        if (th != null) {
            handleError(ctx, th);
        }
        logFine(() -> msg + ": SUCCESS");
        logFine(() -> String.format("Transition to " + nextStage));
        ctx.subStage = nextStage;
        handleSubStage(ctx);
    });
}
Also used : Query(com.vmware.xenon.services.common.QueryTask.Query) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Operation(com.vmware.xenon.common.Operation)

Example 12 with DiskState

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

the class TestVSphereProvisionFromImageLink method createVmState.

private ComputeState createVmState(ComputeDescription vmDescription, String imageLink) throws Throwable {
    ComputeState computeState = new ComputeState();
    computeState.id = vmDescription.name;
    computeState.documentSelfLink = computeState.id;
    computeState.descriptionLink = vmDescription.documentSelfLink;
    computeState.resourcePoolLink = this.resourcePool.documentSelfLink;
    computeState.adapterManagementReference = getAdapterManagementReference();
    computeState.name = vmDescription.name;
    computeState.powerState = PowerState.ON;
    computeState.parentLink = this.computeHost.documentSelfLink;
    if (this.endpoint != null) {
        computeState.endpointLink = this.endpoint.documentSelfLink;
        computeState.endpointLinks = new HashSet<>(1);
        computeState.endpointLinks.add(this.endpoint.documentSelfLink);
    }
    computeState.networkInterfaceLinks = new ArrayList<>(1);
    computeState.diskLinks = new ArrayList<>(1);
    DiskState bootDisk = createBootDisk(imageLink);
    computeState.diskLinks.add(bootDisk.documentSelfLink);
    CustomProperties.of(computeState).put(ComputeProperties.RESOURCE_GROUP_NAME, this.vcFolder).put(ComputeProperties.PLACEMENT_LINK, selectPlacement());
    ComputeState returnState = TestUtils.doPost(this.host, computeState, ComputeState.class, UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK));
    return returnState;
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState)

Example 13 with DiskState

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

the class TestVSphereProvisionWithCloudConfigTask method createBootDisk.

private DiskState createBootDisk(String cloudConfig) throws Throwable {
    DiskState res = new DiskState();
    res.bootOrder = 1;
    res.type = DiskType.HDD;
    res.id = res.name = "boot-disk";
    res.sourceImageReference = URI.create("file:///dev/null");
    res.bootConfig = new BootConfig();
    res.bootConfig.files = new FileEntry[] { new FileEntry(), new FileEntry() };
    res.bootConfig.files[0].path = "user-data";
    res.bootConfig.files[0].contents = cloudConfig;
    res.bootConfig.files[1].path = "public-keys";
    res.bootConfig.files[1].contents = IOUtils.toString(new File("src/test/resources/testkey.pub").toURI());
    return TestUtils.doPost(this.host, res, DiskState.class, UriUtils.buildUri(this.host, DiskService.FACTORY_LINK));
}
Also used : BootConfig(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) FileEntry(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig.FileEntry) File(java.io.File)

Example 14 with DiskState

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

the class TestVSphereProvisionWithStaticIpTask method createBootDisk.

@SuppressWarnings("unused")
private DiskState createBootDisk(String cloudConfig) throws Throwable {
    DiskState res = new DiskState();
    res.bootOrder = 1;
    res.type = DiskType.HDD;
    res.id = res.name = "boot-disk";
    res.sourceImageReference = URI.create("file:///dev/null");
    res.bootConfig = new BootConfig();
    res.bootConfig.files = new FileEntry[] { new FileEntry(), new FileEntry() };
    res.bootConfig.files[0].path = "user-data";
    res.bootConfig.files[0].contents = cloudConfig;
    res.bootConfig.files[1].path = "public-keys";
    res.bootConfig.files[1].contents = IOUtils.toString(new File("src/test/resources/testkey.pub").toURI());
    return TestUtils.doPost(this.host, res, DiskState.class, UriUtils.buildUri(this.host, DiskService.FACTORY_LINK));
}
Also used : BootConfig(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) FileEntry(com.vmware.photon.controller.model.resources.DiskService.DiskState.BootConfig.FileEntry) File(java.io.File)

Example 15 with DiskState

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

the class TestVSphereDiskService method createDiskWithCustomPropsDataStore.

private DiskState createDiskWithCustomPropsDataStore(String alias, DiskService.DiskType type, long capacityMBytes, HashMap<String, String> customProperties) throws Throwable {
    DiskState diskState = constructDiskState(alias, type, 0, null, capacityMBytes, customProperties);
    // Store the datastore name inside properties
    diskState.customProperties.put(CustomProperties.DISK_DATASTORE_NAME, this.dataStoreId);
    return postDiskStateWithDetails(diskState);
}
Also used : DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState)

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