Search in sources :

Example 1 with IAzureOperation

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;
}
Also used : IAzureOperation(com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation) Setter(lombok.Setter) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) Accessors(lombok.experimental.Accessors) Getter(lombok.Getter) RequiredArgsConstructor(lombok.RequiredArgsConstructor) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) AzureToolkitException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitException) HttpResponseException(com.azure.core.exception.HttpResponseException) AzureOperationRef(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Map(java.util.Map) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) IAzureOperation(com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) ManagementException(com.azure.core.management.exception.ManagementException) AzureTaskContext(com.microsoft.azure.toolkit.lib.common.task.AzureTaskContext) Objects(java.util.Objects) List(java.util.List) Action(com.microsoft.azure.toolkit.lib.common.action.Action) Optional(java.util.Optional) AzureOperationException(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationException) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) Nonnull(javax.annotation.Nonnull)

Example 2 with IAzureOperation

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;
}
Also used : IAzureOperation(com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) IAzureOperation(com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation) AzureOperationRef(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull)

Example 3 with IAzureOperation

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();
    }
}
Also used : IAzureOperation(com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation) Setter(lombok.Setter) AzureMessager(com.microsoft.azure.toolkit.lib.common.messager.AzureMessager) Getter(lombok.Getter) Log(lombok.extern.java.Log) InterruptedIOException(java.io.InterruptedIOException) Objects(java.util.Objects) AzureTelemeter(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemeter) AccessLevel(lombok.AccessLevel) Utils(com.microsoft.azure.toolkit.lib.common.utils.Utils) Optional(java.util.Optional) IAzureOperation(com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) InterruptedIOException(java.io.InterruptedIOException)

Example 4 with IAzureOperation

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;
}
Also used : IAzureOperation(com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation) Nullable(javax.annotation.Nullable)

Aggregations

IAzureOperation (com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation)4 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 AzureOperationRef (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef)2 LinkedList (java.util.LinkedList)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Getter (lombok.Getter)2 Setter (lombok.Setter)2 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)2 HttpResponseException (com.azure.core.exception.HttpResponseException)1 ManagementException (com.azure.core.management.exception.ManagementException)1 Streams (com.google.common.collect.Streams)1 Action (com.microsoft.azure.toolkit.lib.common.action.Action)1 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)1 Cacheable (com.microsoft.azure.toolkit.lib.common.cache.Cacheable)1 AzureToolkitException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitException)1 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)1 AzureMessager (com.microsoft.azure.toolkit.lib.common.messager.AzureMessager)1