use of com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation in project azure-maven-plugins by microsoft.
the class AzureMessage method getContent.
@Nonnull
public String getContent() {
if (!(getPayload() instanceof Throwable)) {
return ObjectUtils.firstNonNull(this.decorateText(this.message, null), this.message.getString());
}
final Throwable throwable = (Throwable) getPayload();
final List<IAzureOperation> operations = this.getOperations();
final String failure = operations.stream().findFirst().map(IAzureOperation::getTitle).map(azureString -> "Failed to " + this.decorateText(azureString, azureString::getString)).orElse("Failed to proceed");
final String cause = Optional.ofNullable(this.getCause(throwable)).map(c -> ", " + c).orElse("");
final String errorAction = Optional.ofNullable(this.getErrorAction(throwable)).map(c -> System.lineSeparator() + c).orElse("");
return failure + cause + errorAction;
}
use of com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation in project azure-maven-plugins by microsoft.
the class AzureMessage method getContextOperations.
@Nonnull
private static List<IAzureOperation> getContextOperations() {
final LinkedList<IAzureOperation> result = new LinkedList<>();
IAzureOperation current = AzureTaskContext.current().currentOperation();
while (Objects.nonNull(current)) {
if (current instanceof AzureOperationRef) {
result.addFirst(current);
final AzureOperation annotation = ((AzureOperationRef) current).getAnnotation(AzureOperation.class);
if (annotation.type() == AzureOperation.Type.ACTION) {
break;
}
}
current = current.getParent();
}
return result;
}
use of com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation in project azure-maven-plugins by microsoft.
the class AzureTaskContext method run.
public static void run(final Runnable runnable, AzureTaskContext context) {
try {
context.setup();
Optional.ofNullable(context.getTask()).ifPresent(task -> {
AzureTelemeter.beforeEnter(task);
AzureTaskContext.current().pushOperation(task);
});
runnable.run();
Optional.ofNullable(context.getTask()).ifPresent(task -> {
final IAzureOperation popped = AzureTaskContext.current().popOperation();
AzureTelemeter.afterExit(task);
assert Objects.equals(task, popped) : String.format("popped op[%s] is not the exiting async task[%s]", popped, task);
});
} catch (final Throwable throwable) {
final Throwable rootCause = ExceptionUtils.getRootCause(throwable);
if (!(rootCause instanceof InterruptedIOException) && !(rootCause instanceof InterruptedException)) {
// Swallow interrupted exception caused by unsubscribe
AzureMessager.getMessager().error(throwable);
}
Optional.ofNullable(context.getTask()).ifPresent(task -> {
final IAzureOperation popped = AzureTaskContext.current().popOperation();
AzureTelemeter.onError(task, throwable);
assert Objects.equals(task, popped) : String.format("popped op[%s] is not the task[%s] throwing exception", popped, task);
});
} finally {
context.dispose();
}
}
use of com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation in project azure-maven-plugins by microsoft.
the class AzureTaskContext method popOperation.
@Nullable
public IAzureOperation popOperation() {
final IAzureOperation popped = this.operation;
assert popped != null : "popped operation is null";
this.operation = popped.getParent();
if (Objects.isNull(this.parent) && Objects.isNull(this.operation)) {
AzureTaskContext.context.remove();
log.fine(String.format("orphan context[%s] is disposed", this));
}
return popped;
}
Aggregations