use of com.vmware.photon.controller.model.adapters.azure.utils.AzureDecommissionCallback 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