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