Search in sources :

Example 51 with DeferredResult

use of com.vmware.xenon.common.DeferredResult in project photon-model by vmware.

the class AWSNetworkClient method deleteNATGateway.

/**
 * Delete a NAT Gateway
 * It waits for the NAT gateway to get into the Deleted state before returning.
 */
public DeferredResult<Void> deleteNATGateway(String natGatewayId, TaskManager taskManager, long taskExpirationMicros) {
    DeleteNatGatewayRequest req = new DeleteNatGatewayRequest().withNatGatewayId(natGatewayId);
    String message = "Delete AWS NAT Gateway with id [" + natGatewayId + "].";
    AWSDeferredResultAsyncHandler<DeleteNatGatewayRequest, DeleteNatGatewayResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message);
    this.client.deleteNatGatewayAsync(req, handler);
    return handler.toDeferredResult().thenCompose(ignore -> waitForNatGatewayState(natGatewayId, taskManager, taskExpirationMicros, AWSTaskStatusChecker.AWS_DELETED_NAME)).thenApply(ignore -> null);
}
Also used : AWSTaskStatusChecker(com.vmware.photon.controller.model.adapters.awsadapter.AWSTaskStatusChecker) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) ReleaseAddressRequest(com.amazonaws.services.ec2.model.ReleaseAddressRequest) AllocateAddressRequest(com.amazonaws.services.ec2.model.AllocateAddressRequest) AttachInternetGatewayRequest(com.amazonaws.services.ec2.model.AttachInternetGatewayRequest) AssociateRouteTableRequest(com.amazonaws.services.ec2.model.AssociateRouteTableRequest) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) NatGateway(com.amazonaws.services.ec2.model.NatGateway) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) CreateNatGatewayResult(com.amazonaws.services.ec2.model.CreateNatGatewayResult) DeleteSubnetResult(com.amazonaws.services.ec2.model.DeleteSubnetResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) DeleteVpcRequest(com.amazonaws.services.ec2.model.DeleteVpcRequest) AWS_MAIN_ROUTE_ASSOCIATION(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_MAIN_ROUTE_ASSOCIATION) StatelessService(com.vmware.xenon.common.StatelessService) CreateRouteResult(com.amazonaws.services.ec2.model.CreateRouteResult) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) List(java.util.List) DescribeRouteTablesRequest(com.amazonaws.services.ec2.model.DescribeRouteTablesRequest) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) CreateNatGatewayRequest(com.amazonaws.services.ec2.model.CreateNatGatewayRequest) AssociateRouteTableResult(com.amazonaws.services.ec2.model.AssociateRouteTableResult) DeleteRouteTableRequest(com.amazonaws.services.ec2.model.DeleteRouteTableRequest) AllocateAddressResult(com.amazonaws.services.ec2.model.AllocateAddressResult) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) DescribeRouteTablesResult(com.amazonaws.services.ec2.model.DescribeRouteTablesResult) ROUTE_DEST_ALL(com.vmware.photon.controller.model.adapters.awsadapter.AWSNetworkService.ROUTE_DEST_ALL) DeleteInternetGatewayRequest(com.amazonaws.services.ec2.model.DeleteInternetGatewayRequest) DomainType(com.amazonaws.services.ec2.model.DomainType) DeleteNatGatewayResult(com.amazonaws.services.ec2.model.DeleteNatGatewayResult) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) CreateRouteTableResult(com.amazonaws.services.ec2.model.CreateRouteTableResult) ArrayList(java.util.ArrayList) CreateVpcResult(com.amazonaws.services.ec2.model.CreateVpcResult) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) Filter(com.amazonaws.services.ec2.model.Filter) RouteTable(com.amazonaws.services.ec2.model.RouteTable) Subnet(com.amazonaws.services.ec2.model.Subnet) CreateVpcRequest(com.amazonaws.services.ec2.model.CreateVpcRequest) AWS_TAG_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_TAG_NAME) CreateTagsResult(com.amazonaws.services.ec2.model.CreateTagsResult) ReleaseAddressResult(com.amazonaws.services.ec2.model.ReleaseAddressResult) Vpc(com.amazonaws.services.ec2.model.Vpc) DeleteRouteTableResult(com.amazonaws.services.ec2.model.DeleteRouteTableResult) CreateInternetGatewayResult(com.amazonaws.services.ec2.model.CreateInternetGatewayResult) DetachInternetGatewayRequest(com.amazonaws.services.ec2.model.DetachInternetGatewayRequest) DeleteNatGatewayRequest(com.amazonaws.services.ec2.model.DeleteNatGatewayRequest) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) CreateRouteTableRequest(com.amazonaws.services.ec2.model.CreateRouteTableRequest) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) CreateRouteRequest(com.amazonaws.services.ec2.model.CreateRouteRequest) DeleteNatGatewayResult(com.amazonaws.services.ec2.model.DeleteNatGatewayResult) DeleteNatGatewayRequest(com.amazonaws.services.ec2.model.DeleteNatGatewayRequest)

Example 52 with DeferredResult

use of com.vmware.xenon.common.DeferredResult in project photon-model by vmware.

the class AWSNetworkClient method waitForNatGatewayState.

/**
 * Wait for NAT Gateway to go into the desired state
 */
private DeferredResult<String> waitForNatGatewayState(String natGatewayId, TaskManager taskManager, long taskExpirationMicros, String desiredState) {
    DeferredResult<String> waitCompleted = new DeferredResult<>();
    AWSTaskStatusChecker.create(this.client, natGatewayId, desiredState, (ignore) -> waitCompleted.complete(natGatewayId), taskManager, this.service, taskExpirationMicros).start(new NatGateway());
    return waitCompleted;
}
Also used : AWSTaskStatusChecker(com.vmware.photon.controller.model.adapters.awsadapter.AWSTaskStatusChecker) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) ReleaseAddressRequest(com.amazonaws.services.ec2.model.ReleaseAddressRequest) AllocateAddressRequest(com.amazonaws.services.ec2.model.AllocateAddressRequest) AttachInternetGatewayRequest(com.amazonaws.services.ec2.model.AttachInternetGatewayRequest) AssociateRouteTableRequest(com.amazonaws.services.ec2.model.AssociateRouteTableRequest) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) NatGateway(com.amazonaws.services.ec2.model.NatGateway) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) CreateNatGatewayResult(com.amazonaws.services.ec2.model.CreateNatGatewayResult) DeleteSubnetResult(com.amazonaws.services.ec2.model.DeleteSubnetResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) DeleteVpcRequest(com.amazonaws.services.ec2.model.DeleteVpcRequest) AWS_MAIN_ROUTE_ASSOCIATION(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_MAIN_ROUTE_ASSOCIATION) StatelessService(com.vmware.xenon.common.StatelessService) CreateRouteResult(com.amazonaws.services.ec2.model.CreateRouteResult) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) List(java.util.List) DescribeRouteTablesRequest(com.amazonaws.services.ec2.model.DescribeRouteTablesRequest) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) CreateNatGatewayRequest(com.amazonaws.services.ec2.model.CreateNatGatewayRequest) AssociateRouteTableResult(com.amazonaws.services.ec2.model.AssociateRouteTableResult) DeleteRouteTableRequest(com.amazonaws.services.ec2.model.DeleteRouteTableRequest) AllocateAddressResult(com.amazonaws.services.ec2.model.AllocateAddressResult) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) DescribeRouteTablesResult(com.amazonaws.services.ec2.model.DescribeRouteTablesResult) ROUTE_DEST_ALL(com.vmware.photon.controller.model.adapters.awsadapter.AWSNetworkService.ROUTE_DEST_ALL) DeleteInternetGatewayRequest(com.amazonaws.services.ec2.model.DeleteInternetGatewayRequest) DomainType(com.amazonaws.services.ec2.model.DomainType) DeleteNatGatewayResult(com.amazonaws.services.ec2.model.DeleteNatGatewayResult) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) CreateRouteTableResult(com.amazonaws.services.ec2.model.CreateRouteTableResult) ArrayList(java.util.ArrayList) CreateVpcResult(com.amazonaws.services.ec2.model.CreateVpcResult) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) Filter(com.amazonaws.services.ec2.model.Filter) RouteTable(com.amazonaws.services.ec2.model.RouteTable) Subnet(com.amazonaws.services.ec2.model.Subnet) CreateVpcRequest(com.amazonaws.services.ec2.model.CreateVpcRequest) AWS_TAG_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_TAG_NAME) CreateTagsResult(com.amazonaws.services.ec2.model.CreateTagsResult) ReleaseAddressResult(com.amazonaws.services.ec2.model.ReleaseAddressResult) Vpc(com.amazonaws.services.ec2.model.Vpc) DeleteRouteTableResult(com.amazonaws.services.ec2.model.DeleteRouteTableResult) CreateInternetGatewayResult(com.amazonaws.services.ec2.model.CreateInternetGatewayResult) DetachInternetGatewayRequest(com.amazonaws.services.ec2.model.DetachInternetGatewayRequest) DeleteNatGatewayRequest(com.amazonaws.services.ec2.model.DeleteNatGatewayRequest) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) CreateRouteTableRequest(com.amazonaws.services.ec2.model.CreateRouteTableRequest) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) CreateRouteRequest(com.amazonaws.services.ec2.model.CreateRouteRequest) NatGateway(com.amazonaws.services.ec2.model.NatGateway) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 53 with DeferredResult

use of com.vmware.xenon.common.DeferredResult in project photon-model by vmware.

the class TestVSphereLibraryProvisionTaskWithStorage method deployFromLibraryWithAdditionalDisks.

@Test
public void deployFromLibraryWithAdditionalDisks() throws Throwable {
    ComputeService.ComputeState vm = provisionVMAndGetState(true, true);
    try {
        if (vm == null) {
            return;
        }
        // Verify that the disk is resized
        BasicConnection connection = createConnection();
        GetMoRef get = new GetMoRef(connection);
        List<VirtualDisk> virtualDisks = fetchAllVirtualDisks(vm, get);
        assertEquals(3, virtualDisks.size());
        assertEquals(3, vm.diskLinks.size());
        List<DeferredResult<DiskService.DiskState>> disks = vm.diskLinks.stream().map(link -> {
            Operation getOp = Operation.createGet(this.host, link).setReferer(this.host.getReferer());
            return this.host.sendWithDeferredResult(getOp, DiskService.DiskState.class);
        }).collect(Collectors.toList());
        DeferredResult.allOf(disks).thenAccept(diskStates -> diskStates.stream().forEach(ds -> {
            assertNotNull(ds.customProperties);
            assertNotNull(ds.sourceImageReference);
            assertNotNull(ds.customProperties.get(PROVIDER_DISK_UNIQUE_ID));
        }));
    } finally {
        if (vm != null) {
            deleteVmAndWait(vm);
        }
    }
}
Also used : GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) Assert.assertNotNull(org.junit.Assert.assertNotNull) Operation(com.vmware.xenon.common.Operation) Test(org.junit.Test) GetMoRef(com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef) PROVIDER_DISK_UNIQUE_ID(com.vmware.photon.controller.model.adapters.vsphere.CustomProperties.PROVIDER_DISK_UNIQUE_ID) Collectors(java.util.stream.Collectors) List(java.util.List) VirtualDisk(com.vmware.vim25.VirtualDisk) DeferredResult(com.vmware.xenon.common.DeferredResult) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) DiskService(com.vmware.photon.controller.model.resources.DiskService) Assert.assertEquals(org.junit.Assert.assertEquals) BasicConnection(com.vmware.photon.controller.model.adapters.vsphere.util.connection.BasicConnection) Operation(com.vmware.xenon.common.Operation) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) VirtualDisk(com.vmware.vim25.VirtualDisk) DiskService(com.vmware.photon.controller.model.resources.DiskService) DeferredResult(com.vmware.xenon.common.DeferredResult) Test(org.junit.Test)

Example 54 with DeferredResult

use of com.vmware.xenon.common.DeferredResult in project photon-model by vmware.

the class AzureStorageEnumerationAdapterService method getLocalStorageAccountDescriptions.

/**
 * Query all storage descriptions for the cluster filtered by the received set of storage
 * account Ids
 */
private void getLocalStorageAccountDescriptions(StorageEnumContext context, StorageEnumStages next) {
    if (context.storageAccountsToUpdateCreate.isEmpty()) {
        context.subStage = StorageEnumStages.CREATE_STORAGE_DESCRIPTIONS;
        handleSubStage(context);
        return;
    }
    context.storageDescriptions.clear();
    Query.Builder qBuilder = Query.Builder.create().addKindFieldClause(StorageDescription.class);
    Query.Builder instanceIdFilterParentQuery = Query.Builder.create(Occurance.MUST_OCCUR);
    for (Map.Entry<String, StorageAccount> account : context.storageAccountsToUpdateCreate.entrySet()) {
        Query instanceIdFilter = Query.Builder.create(Occurance.SHOULD_OCCUR).addFieldClause(StorageDescription.FIELD_NAME_ID, canonizeId(account.getValue().id)).build();
        instanceIdFilterParentQuery.addClause(instanceIdFilter);
    }
    qBuilder.addClause(instanceIdFilterParentQuery.build());
    QueryByPages<StorageDescription> queryLocalStates = new QueryByPages<>(getHost(), qBuilder.build(), StorageDescription.class, context.parentCompute.tenantLinks, null, /* endpointLink */
    context.parentCompute.documentSelfLink).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
    queryLocalStates.collectDocuments(Collectors.toList()).whenComplete((sds, ex) -> {
        if (ex != null) {
            handleError(context, ex);
            return;
        }
        logFine(() -> String.format("Found %d matching storage descriptions for Azure" + " storage accounts", sds.size()));
        List<DeferredResult<AuthCredentialsServiceState>> results = sds.stream().map(sd -> {
            context.storageDescriptions.put(sd.id, sd);
            // populate connectionStrings
            if (!context.storageConnectionStrings.containsKey(sd.id)) {
                return loadStorageAuth(context, sd);
            } else {
                return DeferredResult.<AuthCredentialsServiceState>completed(null);
            }
        }).collect(Collectors.toList());
        DeferredResult.allOf(results).whenComplete((creds, e) -> {
            if (e != null) {
                logWarning(() -> String.format("Failed to get storage description" + " credentials: %s", e.getMessage()));
            }
            context.subStage = next;
            handleSubStage(context);
        });
    });
}
Also used : STORAGE_ACCOUNT_REST_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_ACCOUNT_REST_API_VERSION) Arrays(java.util.Arrays) QUERY_PARAM_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.QUERY_PARAM_API_VERSION) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) AZURE_STORAGE_BLOBS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_BLOBS) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) StringUtils(org.apache.commons.lang3.StringUtils) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Azure(com.microsoft.azure.management.Azure) Utils(com.vmware.xenon.common.Utils) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) COMPUTE_HOST_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.COMPUTE_HOST_LINK_PROP_NAME) EnumSet(java.util.EnumSet) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) AZURE_STORAGE_ACCOUNT_KEY1(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_KEY1) StorageAccountListKeysResultInner(com.microsoft.azure.management.storage.implementation.StorageAccountListKeysResultInner) StatelessService(com.vmware.xenon.common.StatelessService) Set(java.util.Set) AdapterUtils.getDeletionState(com.vmware.photon.controller.model.adapters.util.AdapterUtils.getDeletionState) AZURE_STORAGE_CONTAINER_LEASE_STATUS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_STATUS) TagService(com.vmware.photon.controller.model.resources.TagService) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) AZURE_STORAGE_CONTAINER_LEASE_STATE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_STATE) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceGroupStateType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) ArrayList(java.util.ArrayList) StorageException(com.microsoft.azure.storage.StorageException) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) Query(com.vmware.xenon.services.common.QueryTask.Query) AUTH_HEADER_BEARER_PREFIX(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AUTH_HEADER_BEARER_PREFIX) UriPaths(com.vmware.photon.controller.model.UriPaths) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) StorageErrorCode(com.microsoft.azure.storage.StorageErrorCode) EnumUtils(org.apache.commons.lang3.EnumUtils) AZURE_STORAGE_CONTAINER_LEASE_LAST_MODIFIED(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_LAST_MODIFIED) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) LIST_STORAGE_ACCOUNTS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.LIST_STORAGE_ACCOUNTS) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ResultSegment(com.microsoft.azure.storage.ResultSegment) EMPTY_STR(com.vmware.photon.controller.model.constants.PhotonModelConstants.EMPTY_STR) ContainerListingDetails(com.microsoft.azure.storage.blob.ContainerListingDetails) UnknownHostException(java.net.UnknownHostException) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ResultContinuation(com.microsoft.azure.storage.ResultContinuation) URISyntaxException(java.net.URISyntaxException) QueryTask(com.vmware.xenon.services.common.QueryTask) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) DEFAULT_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DEFAULT_DISK_TYPE) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AzureConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.getQueryResultLimit) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AZURE_STORAGE_CONTAINERS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINERS) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) Collectors(java.util.stream.Collectors) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureUtils.getResourceGroupName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getResourceGroupName) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) DiskService(com.vmware.photon.controller.model.resources.DiskService) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) HashMap(java.util.HashMap) Level(java.util.logging.Level) HashSet(java.util.HashSet) AZURE_STORAGE_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_TYPE) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) STORAGE_CONNECTION_STRING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_CONNECTION_STRING) ExecutorService(java.util.concurrent.ExecutorService) StorageAccountResultList(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccountResultList) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) AZURE_STORAGE_DISKS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_DISKS) StorageAccountsInner(com.microsoft.azure.management.storage.implementation.StorageAccountsInner) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) StorageCredentials(com.microsoft.azure.storage.StorageCredentials) AzureUtils.canonizeId(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.canonizeId) BlobListingDetails(com.microsoft.azure.storage.blob.BlobListingDetails) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) StorageAccountInner(com.microsoft.azure.management.storage.implementation.StorageAccountInner) StorageAccount(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount) OperationJoin(com.vmware.xenon.common.OperationJoin) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Query(com.vmware.xenon.services.common.QueryTask.Query) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) StorageAccount(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 55 with DeferredResult

use of com.vmware.xenon.common.DeferredResult in project photon-model by vmware.

the class AzureStorageEnumerationAdapterService method updateStorageDescriptions.

/**
 * Updates matching storage descriptions for given storage accounts.
 */
private void updateStorageDescriptions(StorageEnumContext context, StorageEnumStages next) {
    if (context.storageDescriptions.size() == 0) {
        logFine(() -> "No storage descriptions available for update");
        context.subStage = next;
        handleSubStage(context);
        return;
    }
    List<DeferredResult<Operation>> updates = context.storageDescriptions.values().stream().map(sd -> {
        StorageAccount storageAccount = context.storageAccountsToUpdateCreate.remove(sd.id);
        StorageDescription storageDescriptionToUpdate = new StorageDescription();
        storageDescriptionToUpdate.name = storageAccount.name;
        storageDescriptionToUpdate.authCredentialsLink = sd.authCredentialsLink;
        storageDescriptionToUpdate.regionId = storageAccount.location;
        storageDescriptionToUpdate.documentSelfLink = sd.documentSelfLink;
        if (StringUtils.isEmpty(storageDescriptionToUpdate.endpointLink)) {
            storageDescriptionToUpdate.endpointLink = sd.endpointLink;
        }
        storageDescriptionToUpdate.computeHostLink = sd.computeHostLink;
        // first copy
        storageDescriptionToUpdate.endpointLinks = sd.endpointLinks;
        // then update it
        AdapterUtils.addToEndpointLinks(storageDescriptionToUpdate, context.request.endpointLink);
        storageDescriptionToUpdate.tenantLinks = sd.tenantLinks;
        storageDescriptionToUpdate.regionId = storageAccount.location;
        // Check if SSE (encryption) is enable on azure storage account
        storageDescriptionToUpdate.supportsEncryption = storageAccount.properties.encryption != null ? storageAccount.properties.encryption.services.blob.enabled : false;
        // Set type of azure storage account
        storageDescriptionToUpdate.type = storageAccount.sku.name;
        context.storageDescriptionsForPatching.put(sd.id, sd);
        return storageDescriptionToUpdate;
    }).map(sd -> Operation.createPatch(this, sd.documentSelfLink).setBody(sd).setCompletion((o, e) -> {
        if (e != null) {
            logWarning(() -> String.format("Failed to update storage description:" + " %s", e.getMessage()));
        }
    })).map(o -> sendWithDeferredResult(o)).collect(java.util.stream.Collectors.toList());
    DeferredResult.allOf(updates).whenComplete((ignore, e) -> {
        logFine(() -> "Finished updating storage descriptions");
        context.subStage = next;
        handleSubStage(context);
    });
}
Also used : STORAGE_ACCOUNT_REST_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_ACCOUNT_REST_API_VERSION) Arrays(java.util.Arrays) QUERY_PARAM_API_VERSION(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.QUERY_PARAM_API_VERSION) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) AZURE_STORAGE_BLOBS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_BLOBS) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) StringUtils(org.apache.commons.lang3.StringUtils) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Azure(com.microsoft.azure.management.Azure) Utils(com.vmware.xenon.common.Utils) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) COMPUTE_HOST_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.COMPUTE_HOST_LINK_PROP_NAME) EnumSet(java.util.EnumSet) ListBlobItem(com.microsoft.azure.storage.blob.ListBlobItem) AZURE_STORAGE_ACCOUNT_KEY1(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_KEY1) StorageAccountListKeysResultInner(com.microsoft.azure.management.storage.implementation.StorageAccountListKeysResultInner) StatelessService(com.vmware.xenon.common.StatelessService) Set(java.util.Set) AdapterUtils.getDeletionState(com.vmware.photon.controller.model.adapters.util.AdapterUtils.getDeletionState) AZURE_STORAGE_CONTAINER_LEASE_STATUS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_STATUS) TagService(com.vmware.photon.controller.model.resources.TagService) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) AZURE_STORAGE_CONTAINER_LEASE_STATE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_STATE) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ResourceGroupStateType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) ArrayList(java.util.ArrayList) StorageException(com.microsoft.azure.storage.StorageException) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) Query(com.vmware.xenon.services.common.QueryTask.Query) AUTH_HEADER_BEARER_PREFIX(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AUTH_HEADER_BEARER_PREFIX) UriPaths(com.vmware.photon.controller.model.UriPaths) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) CloudBlobContainer(com.microsoft.azure.storage.blob.CloudBlobContainer) StorageErrorCode(com.microsoft.azure.storage.StorageErrorCode) EnumUtils(org.apache.commons.lang3.EnumUtils) AZURE_STORAGE_CONTAINER_LEASE_LAST_MODIFIED(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINER_LEASE_LAST_MODIFIED) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) LIST_STORAGE_ACCOUNTS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.LIST_STORAGE_ACCOUNTS) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ResultSegment(com.microsoft.azure.storage.ResultSegment) EMPTY_STR(com.vmware.photon.controller.model.constants.PhotonModelConstants.EMPTY_STR) ContainerListingDetails(com.microsoft.azure.storage.blob.ContainerListingDetails) UnknownHostException(java.net.UnknownHostException) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ResultContinuation(com.microsoft.azure.storage.ResultContinuation) URISyntaxException(java.net.URISyntaxException) QueryTask(com.vmware.xenon.services.common.QueryTask) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) DEFAULT_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DEFAULT_DISK_TYPE) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AzureConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.getQueryResultLimit) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AZURE_STORAGE_CONTAINERS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_CONTAINERS) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) Collectors(java.util.stream.Collectors) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureUtils.getResourceGroupName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getResourceGroupName) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) DiskService(com.vmware.photon.controller.model.resources.DiskService) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) HashMap(java.util.HashMap) Level(java.util.logging.Level) HashSet(java.util.HashSet) AZURE_STORAGE_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_TYPE) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) STORAGE_CONNECTION_STRING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.STORAGE_CONNECTION_STRING) ExecutorService(java.util.concurrent.ExecutorService) StorageAccountResultList(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccountResultList) CloudBlobClient(com.microsoft.azure.storage.blob.CloudBlobClient) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) AZURE_STORAGE_DISKS(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_DISKS) StorageAccountsInner(com.microsoft.azure.management.storage.implementation.StorageAccountsInner) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) StorageCredentials(com.microsoft.azure.storage.StorageCredentials) AzureUtils.canonizeId(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.canonizeId) BlobListingDetails(com.microsoft.azure.storage.blob.BlobListingDetails) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) StorageAccountInner(com.microsoft.azure.management.storage.implementation.StorageAccountInner) StorageAccount(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount) OperationJoin(com.vmware.xenon.common.OperationJoin) CloudBlob(com.microsoft.azure.storage.blob.CloudBlob) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) StorageAccount(com.vmware.photon.controller.model.adapters.azure.model.storage.StorageAccount) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) DeferredResult(com.vmware.xenon.common.DeferredResult)

Aggregations

DeferredResult (com.vmware.xenon.common.DeferredResult)77 ArrayList (java.util.ArrayList)57 Operation (com.vmware.xenon.common.Operation)52 List (java.util.List)49 Collectors (java.util.stream.Collectors)43 StatelessService (com.vmware.xenon.common.StatelessService)42 Utils (com.vmware.xenon.common.Utils)38 Map (java.util.Map)38 HashMap (java.util.HashMap)37 UriUtils (com.vmware.xenon.common.UriUtils)36 DiskService (com.vmware.photon.controller.model.resources.DiskService)33 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)33 URI (java.net.URI)33 Collection (java.util.Collection)32 Set (java.util.Set)31 HashSet (java.util.HashSet)30 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)29 QueryTask (com.vmware.xenon.services.common.QueryTask)28 Consumer (java.util.function.Consumer)28 OperationJoin (com.vmware.xenon.common.OperationJoin)26