com.azure.ai.metricsadvisor.implementation.util.Utility Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-ai-metricsadvisor Show documentation
Show all versions of azure-ai-metricsadvisor Show documentation
This package contains the Microsoft Azure Cognitive Services Metrics Advisor SDK.
The newest version!
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
package com.azure.ai.metricsadvisor.implementation.util;
import com.azure.ai.metricsadvisor.administration.models.DataFeedIngestionProgress;
import com.azure.ai.metricsadvisor.administration.models.DataFeedIngestionStatus;
import com.azure.ai.metricsadvisor.administration.models.IngestionStatusType;
import com.azure.ai.metricsadvisor.implementation.models.AnomalyDimensionQuery;
import com.azure.ai.metricsadvisor.implementation.models.DetectionAnomalyFilterCondition;
import com.azure.ai.metricsadvisor.implementation.models.DetectionAnomalyResultQuery;
import com.azure.ai.metricsadvisor.implementation.models.DetectionIncidentFilterCondition;
import com.azure.ai.metricsadvisor.implementation.models.DetectionIncidentResultQuery;
import com.azure.ai.metricsadvisor.implementation.models.DimensionGroupIdentity;
import com.azure.ai.metricsadvisor.implementation.models.EnrichmentStatusQueryOption;
import com.azure.ai.metricsadvisor.implementation.models.MetricDataQueryOptions;
import com.azure.ai.metricsadvisor.implementation.models.MetricDimensionQueryOptions;
import com.azure.ai.metricsadvisor.implementation.models.MetricSeriesQueryOptions;
import com.azure.ai.metricsadvisor.models.AnomalyIncident;
import com.azure.ai.metricsadvisor.models.DimensionKey;
import com.azure.ai.metricsadvisor.models.ListAnomaliesDetectedOptions;
import com.azure.ai.metricsadvisor.models.ListAnomalyDimensionValuesOptions;
import com.azure.ai.metricsadvisor.models.ListIncidentsDetectedOptions;
import com.azure.ai.metricsadvisor.models.ListMetricDimensionValuesOptions;
import com.azure.ai.metricsadvisor.models.ListMetricSeriesDefinitionOptions;
import com.azure.ai.metricsadvisor.models.MetricFeedback;
import com.azure.core.util.Context;
import com.azure.core.util.CoreUtils;
import com.azure.core.util.logging.ClientLogger;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* Helper utility class to manage common methods.
*/
public final class Utility {
private static final ClientLogger LOGGER = new ClientLogger(Utility.class);
private static final String HTTP_REST_PROXY_SYNC_PROXY_ENABLE = "com.azure.core.http.restproxy.syncproxy.enable";
private static final Context CONTEXT_WITH_SYNC = new Context(HTTP_REST_PROXY_SYNC_PROXY_ENABLE, true);
/**
* Extracts the result ID from the location URL.
*
* @param operationLocation The URL specified in the 'Location' response header containing the
* resultId used to track the progress and obtain the result of the operation.
*
* @return The resultId used to track the progress.
*/
public static String parseOperationId(String operationLocation) {
if (!CoreUtils.isNullOrEmpty(operationLocation)) {
int lastIndex = operationLocation.lastIndexOf('/');
if (lastIndex != -1) {
return operationLocation.substring(lastIndex + 1);
}
}
throw LOGGER.logExceptionAsError(
new RuntimeException("Failed to parse operation header for result Id from: " + operationLocation));
}
/**
* Returns toString or null if object passed is null.
* @param obj the object
* @return Returns toString or null if object passed is null.
*/
public static String toStringOrNull(Object obj) {
return obj != null ? obj.toString() : null;
}
public static List toDataFeedIngestionStatus(
List ingestionStatusList) {
return ingestionStatusList.stream().map(ingestionStatus -> {
DataFeedIngestionStatus dataFeedIngestionStatus = new DataFeedIngestionStatus();
DataFeedIngestionStatusHelper.setMessage(dataFeedIngestionStatus, ingestionStatus.getMessage());
DataFeedIngestionStatusHelper.setIngestionStatusType(dataFeedIngestionStatus,
IngestionStatusType.fromString(toStringOrNull(ingestionStatus.getStatus())));
DataFeedIngestionStatusHelper.setTimestamp(dataFeedIngestionStatus, ingestionStatus.getTimestamp());
return dataFeedIngestionStatus;
}).collect(Collectors.toList());
}
public static DataFeedIngestionProgress toDataFeedIngestionProgress(
com.azure.ai.metricsadvisor.implementation.models.DataFeedIngestionProgress dataFeedIngestionProgressResponse) {
DataFeedIngestionProgress dataFeedIngestionProgress = new DataFeedIngestionProgress();
DataFeedIngestionProgressHelper.setLatestActiveTimestamp(dataFeedIngestionProgress,
dataFeedIngestionProgressResponse.getLatestActiveTimestamp());
DataFeedIngestionProgressHelper.setLatestSuccessTimestamp(dataFeedIngestionProgress,
dataFeedIngestionProgressResponse.getLatestSuccessTimestamp());
return dataFeedIngestionProgress;
}
public static ListAnomaliesDetectedOptions getListAnomaliesDetectedOptions(ListAnomaliesDetectedOptions options,
DetectionAnomalyResultQuery query, ClientLogger logger) {
if (options == null) {
options = new ListAnomaliesDetectedOptions();
}
if (options.getFilter() != null) {
DetectionAnomalyFilterCondition innerFilter = AnomalyTransforms.toInnerFilter(options.getFilter(), logger);
if (innerFilter != null) {
query.setFilter(innerFilter);
}
}
return options;
}
public static ListIncidentsDetectedOptions getListIncidentsDetectedOptions(ListIncidentsDetectedOptions options,
DetectionIncidentResultQuery query) {
if (options == null) {
options = new ListIncidentsDetectedOptions();
}
if (options.getDimensionsToFilter() != null) {
List innerDimensionsToFilter = new ArrayList<>();
for (DimensionKey dimensionToFilter : options.getDimensionsToFilter()) {
innerDimensionsToFilter.add(new DimensionGroupIdentity().setDimension(dimensionToFilter.asMap()));
}
if (!innerDimensionsToFilter.isEmpty()) {
query.setFilter(new DetectionIncidentFilterCondition().setDimensionFilter(innerDimensionsToFilter));
}
}
return options;
}
public static ListAnomalyDimensionValuesOptions
getListAnomalyDimensionValuesOptions(ListAnomalyDimensionValuesOptions options, AnomalyDimensionQuery query) {
if (options == null) {
options = new ListAnomalyDimensionValuesOptions();
}
if (options.getDimensionToFilter() != null) {
query.setDimensionFilter(new DimensionGroupIdentity().setDimension(options.getDimensionToFilter().asMap()));
}
return options;
}
public static MetricDimensionQueryOptions getMetricDimensionQueryOptions(String dimensionName,
ListMetricDimensionValuesOptions options) {
if (options == null) {
options = new ListMetricDimensionValuesOptions();
}
return new MetricDimensionQueryOptions().setDimensionName(dimensionName)
.setDimensionValueFilter(options.getDimensionValueToFilter());
}
public static MetricDataQueryOptions getMetricDataQueryOptions(OffsetDateTime startTime,
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy