Search in sources :

Example 6 with StorageDescription

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);
            }
        }
    }
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) RouterState(com.vmware.photon.controller.model.resources.RouterService.RouterState) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) HashSet(java.util.HashSet) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState)

Example 7 with StorageDescription

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;
}
Also used : StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)

Example 8 with 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;
}
Also used : StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)

Example 9 with StorageDescription

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);
    });
}
Also used : STORAGE_USED_BYTES(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_USED_BYTES) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) PhotonModelUriUtils(com.vmware.photon.controller.model.util.PhotonModelUriUtils) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ObjectUpdateKind(com.vmware.vim25.ObjectUpdateKind) ServiceDocument(com.vmware.xenon.common.ServiceDocument) HashMap(java.util.HashMap) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) CUSTOM_PROP_STORAGE_SHARED(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_PROP_STORAGE_SHARED) Utils(com.vmware.xenon.common.Utils) VsphereEnumerationHelper.convertOnlyResultToDocument(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.convertOnlyResultToDocument) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) StatsUtil(com.vmware.photon.controller.model.tasks.monitoring.StatsUtil) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) SingleResourceStatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService) TimeUnit(java.util.concurrent.TimeUnit) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) STORAGE_AVAILABLE_BYTES(com.vmware.photon.controller.model.constants.PhotonModelConstants.STORAGE_AVAILABLE_BYTES) List(java.util.List) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) UriUtils(com.vmware.xenon.common.UriUtils) VsphereEnumerationHelper.withTaskResults(com.vmware.photon.controller.model.adapters.vsphere.VsphereEnumerationHelper.withTaskResults) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceDocument(com.vmware.xenon.common.ServiceDocument) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)

Example 10 with StorageDescription

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);
        }
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)

Aggregations

StorageDescription (com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription)24 ResourceGroupState (com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState)13 Operation (com.vmware.xenon.common.Operation)13 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)11 UriUtils (com.vmware.xenon.common.UriUtils)11 Utils (com.vmware.xenon.common.Utils)11 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)11 QueryTask (com.vmware.xenon.services.common.QueryTask)11 List (java.util.List)11 ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)10 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)10 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)10 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)10 StorageDescriptionService (com.vmware.photon.controller.model.resources.StorageDescriptionService)10 CompletionHandler (com.vmware.xenon.common.Operation.CompletionHandler)10 ResourceGroupService (com.vmware.photon.controller.model.resources.ResourceGroupService)9 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)9 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 TimeUnit (java.util.concurrent.TimeUnit)9