Search in sources :

Example 1 with AzureOperationRef

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef 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 2 with AzureOperationRef

use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef in project azure-maven-plugins by microsoft.

the class AzureTelemeter method getParameterProperties.

private static Map<String, String> getParameterProperties(AzureOperationRef ref) {
    final HashMap<String, String> properties = new HashMap<>();
    final Object[] paramValues = ref.getParamValues();
    final Parameter[] parameters = ref.getMethod().getParameters();
    for (int i = 0; i < parameters.length; i++) {
        final Parameter param = parameters[i];
        final Object value = paramValues[i];
        Optional.ofNullable(param.getAnnotation(Property.class)).map(Property::value).map(n -> Property.PARAM_NAME.equals(n) ? param.getName() : n).ifPresent((name) -> properties.put(name, Optional.ofNullable(value).map(Object::toString).orElse("")));
        Optional.ofNullable(param.getAnnotation(Properties.class)).map(Properties::value).map(AzureTelemeter::instantiate).map(converter -> converter.convert(value)).ifPresent(properties::putAll);
    }
    return properties;
}
Also used : Setter(lombok.Setter) Getter(lombok.Getter) SneakyThrows(lombok.SneakyThrows) HashMap(java.util.HashMap) Instant(java.time.Instant) Property(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Property) Objects(java.util.Objects) AzureOperationRef(com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef) Parameter(java.lang.reflect.Parameter) Properties(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Properties) Map(java.util.Map) 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) HashMap(java.util.HashMap) Properties(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Properties) Parameter(java.lang.reflect.Parameter) Property(com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Property)

Aggregations

AzureOperationRef (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationRef)2 IAzureOperation (com.microsoft.azure.toolkit.lib.common.operation.IAzureOperation)2 Nonnull (javax.annotation.Nonnull)2 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)1 Properties (com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Properties)1 Property (com.microsoft.azure.toolkit.lib.common.telemetry.AzureTelemetry.Property)1 Parameter (java.lang.reflect.Parameter)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 Getter (lombok.Getter)1 Setter (lombok.Setter)1 SneakyThrows (lombok.SneakyThrows)1 ExceptionUtils (org.apache.commons.lang3.exception.ExceptionUtils)1