use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class VsphereDatastoreEnumerationHelper method makeStorageFromResults.
private static StorageDescription makeStorageFromResults(ComputeEnumerateResourceRequest request, DatastoreOverlay ds, String regionId, EnumerationProgress ctx) {
StorageDescription res = new StorageDescription();
res.id = res.name = ds.getName();
res.type = ds.getType();
res.resourcePoolLink = request.resourcePoolLink;
res.endpointLink = request.endpointLink;
AdapterUtils.addToEndpointLinks(res, request.endpointLink);
res.adapterManagementReference = request.adapterManagementReference;
res.capacityBytes = ds.getCapacityBytes();
res.regionId = regionId;
CustomProperties.of(res).put(CustomProperties.MOREF, ds.getId()).put(STORAGE_USED_BYTES, ds.getCapacityBytes() - ds.getFreeSpaceBytes()).put(STORAGE_AVAILABLE_BYTES, ds.getFreeSpaceBytes()).put(CUSTOM_PROP_STORAGE_SHARED, ds.isMultipleHostAccess()).put(CustomProperties.TYPE, ds.getType()).put(CustomProperties.DS_PATH, ds.getPath()).put(CustomProperties.DATACENTER_SELF_LINK, ctx.getDcLink()).put(CustomProperties.PROPERTY_NAME, ds.getName()).put(CustomProperties.DS_FREE_SPACE_IN_GB, AdapterUtils.convertBytesToGB(ds.getFreeSpaceBytes()));
VsphereEnumerationHelper.populateResourceStateWithAdditionalProps(res, ctx.getVcUuid());
return res;
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class VsphereStoragePolicyEnumerationHelper method updateStorageDescription.
static void updateStorageDescription(VSphereIncrementalEnumerationService service, Stream<Operation> opStream, String spSelfLink, ServiceDocumentQueryResult result) {
List<Operation> patchOps = new ArrayList<>();
List<String> originalLinks = new ArrayList<>();
if (result.documentLinks != null) {
originalLinks.addAll(result.documentLinks);
}
opStream.forEach(op -> {
StorageDescription storageDescription = op.getBody(StorageDescription.class);
if (result.documentLinks != null && result.documentLinks.contains(storageDescription.documentSelfLink)) {
originalLinks.remove(storageDescription.documentSelfLink);
} else {
if (storageDescription.groupLinks == null) {
storageDescription.groupLinks = new HashSet<>();
}
storageDescription.groupLinks.add(spSelfLink);
patchOps.add(Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), storageDescription.documentSelfLink)).setBody(storageDescription));
}
});
// In this case, we need to update the datastore by removing the policy group link
if (!originalLinks.isEmpty()) {
originalLinks.stream().forEach(link -> {
Map<String, Collection<Object>> collectionsToRemove = Collections.singletonMap(ResourceState.FIELD_NAME_GROUP_LINKS, Collections.singletonList(spSelfLink));
ServiceStateCollectionUpdateRequest updateGroupLinksRequest = ServiceStateCollectionUpdateRequest.create(null, collectionsToRemove);
patchOps.add(Operation.createPatch(PhotonModelUriUtils.createInventoryUri(service.getHost(), link)).setBody(updateGroupLinksRequest));
});
}
if (!patchOps.isEmpty()) {
OperationJoin.create(patchOps).setCompletion((ops, exs) -> {
if (exs != null) {
service.logFine(() -> String.format("Syncing Storage policy failed %s", Utils.toString(exs)));
}
}).sendWith(service);
}
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method queryForDiagnosticStorageDescriptions.
/**
* Get all storage descriptions responsible for diagnostics of given VMs.
*/
private void queryForDiagnosticStorageDescriptions(EnumerationContext ctx, ComputeEnumerationSubStages next) {
List<String> diagnosticStorageAccountUris = new ArrayList<>();
String storageAccountProperty = QuerySpecification.buildCompositeFieldName(StorageDescription.FIELD_NAME_CUSTOM_PROPERTIES, AZURE_STORAGE_ACCOUNT_URI);
ctx.virtualMachines.keySet().stream().filter(instanceId -> ctx.virtualMachines.get(instanceId) != null && ctx.virtualMachines.get(instanceId).diagnosticsProfile() != null && ctx.virtualMachines.get(instanceId).diagnosticsProfile().bootDiagnostics() != null && ctx.virtualMachines.get(instanceId).diagnosticsProfile().bootDiagnostics().storageUri() != null).forEach(instanceId -> {
diagnosticStorageAccountUris.add(ctx.virtualMachines.get(instanceId).diagnosticsProfile().bootDiagnostics().storageUri());
});
if (diagnosticStorageAccountUris.isEmpty()) {
ctx.subStage = next;
handleSubStage(ctx);
return;
}
Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(StorageDescription.class).addInClause(storageAccountProperty, diagnosticStorageAccountUris);
QueryTop<StorageDescription> queryDiskStates = new QueryTop<>(getHost(), qBuilder.build(), StorageDescription.class, ctx.parentCompute.tenantLinks, // endpointLink
null, ctx.parentCompute.documentSelfLink).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
queryDiskStates.queryDocuments(storageDesc -> {
ctx.storageDescriptions.put(storageDesc.customProperties.get(AZURE_STORAGE_ACCOUNT_URI), storageDesc);
}).thenRun(() -> logFine(() -> String.format("Found %d matching diagnostics storage accounts", ctx.storageDescriptions.size()))).whenComplete(thenHandleSubStage(ctx, next));
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method createComputeState.
private ComputeState createComputeState(EnumerationContext ctx, VirtualMachineInner virtualMachine) {
List<String> vmDisks = new ArrayList<>();
if (ctx.diskStates != null && ctx.diskStates.size() > 0) {
String diskUri = getVhdUri(virtualMachine);
if (diskUri != null) {
DiskState state = ctx.diskStates.get(diskUri);
if (state != null) {
vmDisks.add(state.documentSelfLink);
}
}
// add all data disk links of VM
List<String> dataDiskIDs = getDataDisksID(virtualMachine, AzureUtils.isDiskManaged(virtualMachine));
if (dataDiskIDs != null) {
dataDiskIDs.forEach(dataDiskID -> {
DiskState dataDiskState = ctx.diskStates.get(dataDiskID);
if (null != dataDiskState) {
vmDisks.add(dataDiskState.documentSelfLink);
}
});
}
}
// Create compute state
ComputeState computeState = new ComputeState();
computeState.documentSelfLink = UUID.randomUUID().toString();
computeState.id = virtualMachine.id().toLowerCase();
computeState.name = virtualMachine.name();
computeState.regionId = virtualMachine.location();
computeState.type = ComputeType.VM_GUEST;
computeState.environmentName = ComputeDescription.ENVIRONMENT_NAME_AZURE;
computeState.parentLink = ctx.request.resourceLink();
computeState.descriptionLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, ctx.computeDescriptionIds.get(virtualMachine.name()));
computeState.endpointLink = ctx.request.endpointLink;
AdapterUtils.addToEndpointLinks(computeState, ctx.request.endpointLink);
computeState.resourcePoolLink = ctx.request.resourcePoolLink;
computeState.computeHostLink = ctx.parentCompute.documentSelfLink;
computeState.diskLinks = vmDisks;
if (virtualMachine.hardwareProfile() != null && virtualMachine.hardwareProfile().vmSize() != null) {
computeState.instanceType = virtualMachine.hardwareProfile().vmSize().toString();
}
computeState.instanceAdapterReference = ctx.parentCompute.description.instanceAdapterReference;
computeState.statsAdapterReference = ctx.parentCompute.description.statsAdapterReference;
computeState.customProperties = new HashMap<>();
computeState.customProperties.put(CUSTOM_OS_TYPE, getNormalizedOSType(virtualMachine));
String resourceGroupName = getResourceGroupName(virtualMachine.id());
computeState.customProperties.put(AZURE_RESOURCE_GROUP_NAME, resourceGroupName);
if (virtualMachine.diagnosticsProfile() != null && virtualMachine.diagnosticsProfile().bootDiagnostics() != null && virtualMachine.diagnosticsProfile().bootDiagnostics().storageUri() != null) {
String diagnosticsAccountUri = virtualMachine.diagnosticsProfile().bootDiagnostics().storageUri();
StorageDescription storageDesk = ctx.storageDescriptions.get(diagnosticsAccountUri);
if (storageDesk != null) {
computeState.customProperties.put(AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK, storageDesk.documentSelfLink);
}
}
computeState.tenantLinks = ctx.parentCompute.tenantLinks;
// add tag links
setTagLinksToResourceState(computeState, virtualMachine.getTags(), true);
if (computeState.tagLinks == null) {
computeState.tagLinks = new HashSet<>();
}
// add internal type tags
computeState.tagLinks.addAll(ctx.internalTagLinks);
List<String> networkLinks = new ArrayList<>();
NicMetadata nicMeta = ctx.networkInterfaceIds.remove(virtualMachine.networkProfile().networkInterfaces().get(0).id());
if (nicMeta != null) {
computeState.address = nicMeta.publicIp;
computeState.hostName = nicMeta.publicDnsName;
computeState.primaryMAC = nicMeta.macAddress;
networkLinks.add(nicMeta.state.documentSelfLink);
}
computeState.networkInterfaceLinks = networkLinks;
return computeState;
}
Aggregations