Search in sources :

Example 1 with ResourceGroupsInner

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);
}
Also used : ResourceGroupsInner(com.microsoft.azure.management.resources.implementation.ResourceGroupsInner) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default)

Example 2 with ResourceGroupsInner

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);
}
Also used : AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) ResourceGroupsInner(com.microsoft.azure.management.resources.implementation.ResourceGroupsInner)

Example 3 with ResourceGroupsInner

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));
}
Also used : ServiceCallback(com.microsoft.rest.ServiceCallback) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) AzureDecommissionCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDecommissionCallback) ResourceGroupsInner(com.microsoft.azure.management.resources.implementation.ResourceGroupsInner)

Aggregations

ResourceGroupsInner (com.microsoft.azure.management.resources.implementation.ResourceGroupsInner)3 AzureDeferredResultServiceCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback)2 ServiceCallback (com.microsoft.rest.ServiceCallback)1 AzureDecommissionCallback (com.vmware.photon.controller.model.adapters.azure.utils.AzureDecommissionCallback)1 Default (com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default)1