use of com.microsoft.azure.management.storage.implementation.StorageAccountsInner in project photon-model by vmware.
the class AzureStorageEnumerationAdapterService method createStorageDescriptions.
/*
* Create all storage descriptions Storage descriptions mapping to Azure storage accounts have
* an additional custom property {"storageType" : "Microsoft.Storage/storageAccounts"}
*/
private void createStorageDescriptions(StorageEnumContext context, StorageEnumStages next) {
if (context.storageAccountsToUpdateCreate.size() == 0) {
if (context.enumNextPageLink != null) {
context.subStage = StorageEnumStages.GET_STORAGE_ACCOUNTS;
handleSubStage(context);
return;
}
logFine(() -> "No storage account found for creation");
context.subStage = next;
handleSubStage(context);
return;
}
logFine(() -> String.format("%d storage description to be created", context.storageAccountsToUpdateCreate.size()));
Consumer<Throwable> failure = e -> {
logWarning("Failure getting Azure storage accounts [EndpointLink:%s] [Exception:%s]", context.request.endpointLink, e.getMessage());
handleError(context, e);
};
PhotonModelUtils.runInExecutor(this.executorService, () -> {
StorageAccountsInner stOps = context.azureSdkClients.getAzureClient().storageAccounts().inner();
List<DeferredResult<StorageDescription>> results = context.storageAccountsToUpdateCreate.values().stream().map(sa -> createStorageDescription(context, sa, stOps)).collect(java.util.stream.Collectors.toList());
DeferredResult.allOf(results).whenComplete((sds, e) -> {
if (e != null) {
logWarning(() -> String.format("Error: %s", e.getMessage()));
}
context.subStage = next;
handleSubStage(context);
});
}, failure);
}
use of com.microsoft.azure.management.storage.implementation.StorageAccountsInner in project photon-model by vmware.
the class AzureStorageEnumerationAdapterService method createStorageDescription.
private DeferredResult<StorageDescription> createStorageDescription(StorageEnumContext context, StorageAccount storageAccount, StorageAccountsInner stOps) {
String resourceGroupName = getResourceGroupName(storageAccount.id);
AzureDeferredResultServiceCallback<StorageAccountListKeysResultInner> handler = new Default<>(this, "Load account keys for storage: " + storageAccount.name);
PhotonModelUtils.runInExecutor(this.executorService, () -> {
stOps.listKeysAsync(resourceGroupName, storageAccount.name, handler);
}, handler::failure);
return handler.toDeferredResult().thenCompose(keys -> AzureUtils.storeKeys(getHost(), keys, context.request.endpointLink, context.parentCompute.tenantLinks)).thenApply(auth -> {
String connectionString = String.format(STORAGE_CONNECTION_STRING, storageAccount.name, auth.customProperties.get(AZURE_STORAGE_ACCOUNT_KEY1));
context.storageConnectionStrings.put(storageAccount.id, connectionString);
return auth;
}).thenApply(auth -> {
StorageDescription storageDesc = AzureUtils.constructStorageDescription(context.parentCompute, context.request, storageAccount, auth.documentSelfLink);
return storageDesc;
}).thenCompose(sd -> sendWithDeferredResult(Operation.createPost(context.request.buildUri(StorageDescriptionService.FACTORY_LINK)).setBody(sd).setCompletion((o, e) -> {
if (e != null) {
logWarning("Unable to store storage description for storage account:[%s], reason: %s", storageAccount.name, Utils.toJsonHtml(e));
} else {
StorageDescription storageDescription = o.getBody(StorageDescription.class);
context.storageDescriptionsForPatching.put(storageDescription.id, storageDescription);
}
}), StorageDescription.class));
}
use of com.microsoft.azure.management.storage.implementation.StorageAccountsInner in project photon-model by vmware.
the class AzureStorageEnumerationAdapterService method patchAdditionalFields.
/**
* Patch additional values to storage description fetched from azure's storage account.
*/
private void patchAdditionalFields(StorageEnumContext context, StorageEnumStages next) {
if (context.storageDescriptionsForPatching.size() == 0) {
logFine(() -> "No storage accounts need to be patched.");
context.subStage = next;
handleSubStage(context);
return;
}
// Patching power state and network Information. Hence 2.
// If we patch more fields, this number should be increased accordingly.
Consumer<Throwable> failure = e -> {
logWarning("Failure getting Azure storage accounts [EndpointLink:%s] [Exception:%s]", context.request.endpointLink, e.getMessage());
handleError(context, e);
};
PhotonModelUtils.runInExecutor(this.executorService, () -> {
Azure azureClient = context.azureSdkClients.getAzureClient();
StorageAccountsInner stOps = azureClient.storageAccounts().inner();
DeferredResult.allOf(context.storageDescriptionsForPatching.values().stream().map(storageDescription -> patchStorageDetails(stOps, storageDescription)).map(dr -> dr.thenCompose(storageDescription -> sendWithDeferredResult(Operation.createPatch(context.request.buildUri(storageDescription.documentSelfLink)).setBody(storageDescription).setCompletion((o, e) -> {
if (e != null) {
logWarning(() -> String.format("Error updating Storage:[%s], reason: %s", storageDescription.name, e));
}
})))).collect(Collectors.toList())).whenComplete((all, e) -> {
if (e != null) {
logWarning(() -> String.format("Error: %s", e));
}
context.subStage = next;
handleSubStage(context);
});
}, failure);
}
Aggregations