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