use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class ResourceGroomerTaskService method populateEndpointLinksByDocumentLinks.
/**
* Helper for creating corresponding object and parsing the response for given documentKind
* to store selfLink and endpointLink.
*/
private static void populateEndpointLinksByDocumentLinks(Map<String, Object> documents, Map<String, Set<String>> endpointLinksByDocumentLinks, Map<String, String> endpointLinkByDocumentLinks) {
for (Object document : documents.values()) {
ServiceDocument doc = Utils.fromJson(document, ServiceDocument.class);
Set<String> endpointLinks = new HashSet<>();
if (doc.documentKind.equals(COMPUTE_STATE_DOCUMENT_KIND)) {
ComputeState state = Utils.fromJson(document, ComputeState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(DISK_STATE_DOCUMENT_KIND)) {
DiskState state = Utils.fromJson(document, DiskState.class);
if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
// skip resources that have never been attached to a particular endpoint
continue;
}
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(COMPUTE_DESCRIPTION_DOCUMENT_KIND)) {
ComputeDescription state = Utils.fromJson(document, ComputeDescription.class);
// only deleting discovered resources
if (!(state.customProperties != null && (ResourceEnumerationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK)) || EndpointAllocationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK))))) {
continue;
}
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(NETWORK_STATE_DOCUMENT_KIND)) {
NetworkState state = Utils.fromJson(document, NetworkState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(NETWORK_INTERFACE_STATE_DOCUMENT_KIND)) {
NetworkInterfaceState state = Utils.fromJson(document, NetworkInterfaceState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(SECURITY_GROUP_STATE_DOCUMENT_KIND)) {
SecurityGroupState state = Utils.fromJson(document, SecurityGroupState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(SUBNET_STATE_DOCUMENT_KIND)) {
SubnetState state = Utils.fromJson(document, SubnetState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(LOAD_BALANCER_DOCUMENT_KIND)) {
LoadBalancerState state = Utils.fromJson(document, LoadBalancerState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(STORAGE_DESCRIPTION_DOCUMENT_KIND)) {
StorageDescription state = Utils.fromJson(document, StorageDescription.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(RESOURCE_GROUP_DOCUMENT_KIND)) {
ResourceGroupState state = Utils.fromJson(document, ResourceGroupState.class);
if (state.customProperties != null && state.customProperties.containsKey(ResourceGroupService.PROPERTY_NAME_IS_USER_CREATED)) {
continue;
}
if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
// skip resources that have never been attached to a particular endpoint
continue;
}
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(IMAGE_STATE_KIND)) {
ImageState state = Utils.fromJson(document, ImageState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(ROUTER_STATE_KIND)) {
RouterState state = Utils.fromJson(document, RouterState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(AUTH_CREDENTIALS_SERVICE_STATE_KIND)) {
AuthCredentialsServiceState state = Utils.fromJson(document, AuthCredentialsServiceState.class);
if (state.customProperties != null && state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK) != null) {
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK));
} else {
endpointLinkByDocumentLinks.put(state.documentSelfLink, EMPTY_STRING);
}
}
}
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class AzureUtils method constructStorageDescription.
public static StorageDescription constructStorageDescription(ComputeStateWithDescription parentCompute, ComputeEnumerateResourceRequest request, com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount storageAccount, String keysAuthLink) {
StorageDescription storageDescription = new StorageDescription();
storageDescription.id = storageAccount.id;
storageDescription.regionId = storageAccount.location;
storageDescription.name = storageAccount.name;
storageDescription.authCredentialsLink = keysAuthLink;
storageDescription.resourcePoolLink = request.resourcePoolLink;
storageDescription.documentSelfLink = UUID.randomUUID().toString();
storageDescription.endpointLink = request.endpointLink;
AdapterUtils.addToEndpointLinks(storageDescription, request.endpointLink);
storageDescription.computeHostLink = parentCompute.documentSelfLink;
storageDescription.customProperties = new HashMap<>();
storageDescription.customProperties.put(AZURE_STORAGE_TYPE, AZURE_STORAGE_ACCOUNTS);
storageDescription.customProperties.put(AZURE_STORAGE_ACCOUNT_URI, storageAccount.properties.primaryEndpoints.blob);
storageDescription.tenantLinks = parentCompute.tenantLinks;
storageDescription.regionId = storageAccount.location;
// Set type of azure storage account
storageDescription.type = storageAccount.sku.name;
storageDescription.supportsEncryption = storageAccount.properties.encryption != null ? storageAccount.properties.encryption.services.blob.enabled : // check if
false;
// SSE is enabled on Azure storage account
return storageDescription;
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class BaseVSphereAdapterTest method createStorageDescriptionState.
/**
* Creates datastore as storage description state.
*/
protected StorageDescription createStorageDescriptionState() throws Throwable {
StorageDescription sd = new StorageDescription();
String datastoreId = this.diskDataStoreId != null ? this.diskDataStoreId : this.dataStoreId;
sd.name = sd.id = datastoreId != null ? datastoreId : "testDatastore";
sd = TestUtils.doPost(this.host, sd, StorageDescription.class, UriUtils.buildUri(this.host, StorageDescriptionService.FACTORY_LINK));
return sd;
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class VsphereDatastoreEnumerationHelper method createNewStorageDescription.
private static void createNewStorageDescription(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, DatastoreOverlay ds) {
ComputeEnumerateResourceRequest request = enumerationProgress.getRequest();
String regionId = enumerationProgress.getRegionId();
StorageDescription desc = makeStorageFromResults(request, ds, regionId, enumerationProgress);
desc.tenantLinks = enumerationProgress.getTenantLinks();
service.logFine(() -> String.format("Found new Datastore %s", ds.getName()));
VsphereEnumerationHelper.submitWorkToVSpherePool(service, () -> {
VsphereEnumerationHelper.populateTags(service, enumerationProgress, ds, desc);
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), StorageDescriptionService.FACTORY_LINK)).setBody(desc).setCompletion((o, e) -> {
trackDatastore(enumerationProgress, ds).handle(o, e);
Operation.createPost(PhotonModelUriUtils.createInventoryUri(service.getHost(), ResourceGroupService.FACTORY_LINK)).setBody(makeStorageGroup(ds, enumerationProgress)).sendWith(service);
updateStorageStats(service, ds, o.getBody(ServiceDocument.class).documentSelfLink);
}).sendWith(service);
});
}
use of com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription in project photon-model by vmware.
the class VsphereDatastoreEnumerationHelper method processFoundDatastore.
public static void processFoundDatastore(VSphereIncrementalEnumerationService service, EnumerationProgress enumerationProgress, DatastoreOverlay ds) {
QueryTask task = queryForStorage(enumerationProgress, ds.getName(), VimUtils.convertMoRefToString(ds.getId()), null);
withTaskResults(service, task, result -> {
if (result.documentLinks.isEmpty()) {
createNewStorageDescription(service, enumerationProgress, ds);
} else {
StorageDescription oldDocument = convertOnlyResultToDocument(result, StorageDescription.class);
updateStorageDescription(service, oldDocument, enumerationProgress, ds, true);
}
});
}
Aggregations