use of com.microsoft.azure.management.resources.implementation.ResourceGroupsInner in project photon-model by vmware.
the class AzureSecurityGroupService method deleteSecurityGroup.
private DeferredResult<AzureSecurityGroupContext> deleteSecurityGroup(AzureSecurityGroupContext context) {
String rgName = null;
if (context.securityGroupState.customProperties != null) {
rgName = context.securityGroupState.customProperties.get(RESOURCE_GROUP_NAME);
}
rgName = rgName != null ? rgName : String.format("%s-rg", context.securityGroupState.name);
ResourceGroupsInner azureClient = context.azureSdkClients.getResourceManagementClientImpl().resourceGroups();
String msg = "Deleting resource group [" + rgName + "] for [" + context.securityGroupState.name + "] network security group";
AzureDeferredResultServiceCallback<Void> callback = new Default<>(this, msg);
azureClient.deleteAsync(rgName, callback);
return callback.toDeferredResult().thenApply(__ -> context);
}
use of com.microsoft.azure.management.resources.implementation.ResourceGroupsInner in project photon-model by vmware.
the class AzureInstanceService method deleteResourceGroup.
private DeferredResult<AzureInstanceContext> deleteResourceGroup(AzureInstanceContext ctx) {
String msg = "Deleting resource group [" + ctx.resourceGroupName + "]";
if (ctx.availabilitySetInners == null || ctx.availabilitySetInners.size() == 0 || ctx.availabilitySetInners.get(0).virtualMachines() == null || ctx.availabilitySetInners.get(0).virtualMachines().size() == 0) {
// there are no other machine in this cluster, delete the resource group
ResourceGroupsInner resourceGoups = getResourceManagementClientImpl(ctx).resourceGroups();
AzureDeferredResultServiceCallback<Void> deleteResourceGroupCallback = new AzureDeferredResultServiceCallback<Void>(this, msg) {
@Override
protected DeferredResult<Void> consumeSuccess(Void result) {
logInfo("Successfully deleted resource group: " + ctx.resourceGroupName);
return DeferredResult.completed(result);
}
};
resourceGoups.deleteAsync(ctx.resourceGroupName, deleteResourceGroupCallback);
return deleteResourceGroupCallback.toDeferredResult().thenApply(result -> ctx);
}
return DeferredResult.completed(ctx);
}
use of com.microsoft.azure.management.resources.implementation.ResourceGroupsInner in project photon-model by vmware.
the class AzureInstanceService method errorHandler.
/**
* The ultimate error handler that should handle errors from all sources.
* <p>
* NOTE: Do not use directly. Use it through
* {@link #handleError(AzureInstanceContext, Throwable)}.
*/
private void errorHandler(AzureInstanceContext ctx) {
logSevere(ctx.error);
if (ctx.computeRequest.isMockRequest) {
finishWithFailure(ctx);
return;
}
if (ctx.computeRequest.requestType != ComputeInstanceRequest.InstanceRequestType.CREATE) {
finishWithFailure(ctx);
return;
}
if (ctx.resourceGroup == null) {
finishWithFailure(ctx);
return;
}
// CREATE request has resulted in RG creation -> clear RG and its content.
String rgName = ctx.resourceGroup.name();
String msg = "Rollback provisioning for [" + ctx.vmName + "] Azure VM";
ResourceGroupsInner azureClient = getResourceManagementClientImpl(ctx).resourceGroups();
AzureDecommissionCallback callback = new AzureDecommissionCallback(this, msg) {
@Override
protected DeferredResult<Void> consumeDecommissionSuccess(Void body) {
return DeferredResult.completed(body);
}
@Override
protected Throwable consumeError(Throwable e) {
String rollbackError = String.format(msg + ": FAILED. Details: %s", Utils.toString(e));
// Wrap original ctx.error with rollback error details.
ctx.error = new IllegalStateException(rollbackError, ctx.error);
return RECOVERED;
}
@Override
protected Runnable checkExistenceCall(ServiceCallback<Boolean> checkExistenceCallback) {
return () -> azureClient.checkExistenceAsync(rgName, checkExistenceCallback);
}
};
azureClient.deleteAsync(rgName, callback);
callback.toDeferredResult().whenComplete((o, e) -> finishWithFailure(ctx));
}
Aggregations