Skip to content

Commit

Permalink
support DataFeedDetail in createDataFeed
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft committed Mar 14, 2022
1 parent bb9de3d commit 91c4c54
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,28 @@ PagedFlux<DataFeedDetail> listDataFeeds(ListDataFeedOptions listDataFeedOptions,
return mapPage(this.listDataFeeds(requestOptions), data -> data.toObject(DataFeedDetail.class));
}

/**
* Create a new data feed.
*
* @param dataFeed the data feed.
* @return the created data feed on successful completion of {@link Mono}.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Mono<DataFeedDetail> createDataFeed(DataFeedDetail dataFeed) {
return createDataFeed(dataFeed, Context.NONE);
}

Mono<DataFeedDetail> createDataFeed(DataFeedDetail dataFeed, Context context) {
RequestOptions requestOptions = new RequestOptions().setContext(context);
return this.serviceClient.createDataFeedWithResponseAsync(BinaryData.fromObject(dataFeed), requestOptions)
.flatMap(response -> {
String uri = response.getHeaders().getValue("location");
String id = uri.substring(uri.lastIndexOf("/") + 1);
return this.getDataFeedByIdWithResponse(id, null);
})
.map(response -> response.getValue().toObject(DataFeedDetail.class));
}

private static <T, S> PagedFlux<S> mapPage(PagedFlux<T> pagedFlux, Function<T, S> mapper) {
Supplier<PageRetriever<String, PagedResponse<S>>> provider = () -> (continuationToken, pageSize) -> {
Flux<PagedResponse<T>> flux = (continuationToken == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2544,4 +2544,15 @@ public PagedIterable<BinaryData> getEnrichmentStatusByMetric(
public PagedIterable<DataFeedDetail> listDataFeeds(ListDataFeedOptions options, Context context) {
return new PagedIterable<>(this.asyncClient.listDataFeeds(options, context));
}

/**
* Create a new data feed.
*
* @param dataFeed the data feed.
* @return the created data feed.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public DataFeedDetail createDataFeed(DataFeedDetail dataFeed) {
return this.asyncClient.createDataFeed(dataFeed, Context.NONE).block();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,54 @@

package com.azure.ai.metricsadvisor;

import com.azure.core.http.rest.RequestOptions;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import com.azure.ai.metricsadvisor.models.AuthenticationTypeEnum;
import com.azure.ai.metricsadvisor.models.DataFeedDetail;
import com.azure.ai.metricsadvisor.models.Dimension;
import com.azure.ai.metricsadvisor.models.FillMissingPointType;
import com.azure.ai.metricsadvisor.models.Granularity;
import com.azure.ai.metricsadvisor.models.Metric;
import com.azure.ai.metricsadvisor.models.NeedRollupEnum;
import com.azure.ai.metricsadvisor.models.RollUpMethod;
import com.azure.ai.metricsadvisor.models.SqlServerDataFeed;
import com.azure.ai.metricsadvisor.models.SqlSourceParameter;
import com.azure.ai.metricsadvisor.models.ViewMode;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Arrays;

public final class CreateANewDataFeedTests extends MetricsAdvisorClientTestBase {
@Test
public void testCreateANewDataFeedTests() {
BinaryData body =
BinaryData.fromString(
"{\"allUpIdentification\":\"__SUM__\",\"authenticationType\":\"Basic\",\"dataFeedDescription\":\"This is a sample data feed.\",\"dataFeedName\":\"Sample - cost/revenue - city/category\",\"dataSourceParameter\":{\"connectionString\":\"Server=PlaceholderSqlServer,1433;Initial Catalog=PlaceholderDatabase;User ID=PlaceholderUserName;Password=PlaceholderPassword;\",\"query\":\"select * from your_table where timestamp = @StartTime\"},\"dataSourceType\":\"SqlServer\",\"dataStartFrom\":\"2020-01-01T00:00:00.000Z\",\"dimension\":[{\"dimensionDisplayName\":\"category\",\"dimensionName\":\"category\"},{\"dimensionDisplayName\":\"city\",\"dimensionName\":\"city\"}],\"fillMissingPointType\":\"SmartFilling\",\"granularityName\":\"Daily\",\"maxConcurrency\":5,\"metrics\":[{\"metricDisplayName\":\"cost\",\"metricName\":\"cost\"},{\"metricDisplayName\":\"revenue\",\"metricName\":\"revenue\"}],\"minRetryIntervalInSeconds\":3600,\"needRollup\":\"NeedRollup\",\"rollUpMethod\":\"Sum\",\"startOffsetInSeconds\":86400,\"stopRetryAfterInSeconds\":604800,\"timestampColumn\":\"timestamp\",\"viewMode\":\"Private\"}");
RequestOptions requestOptions = new RequestOptions();
Response<Void> response = metricsAdvisorClient.createDataFeedWithResponse(body, requestOptions);
Assertions.assertEquals(201, response.getStatusCode());
Assertions.assertNotNull(response.getHeaders().get("Location").getValue());
DataFeedDetail dataFeed = new SqlServerDataFeed()
.setAllUpIdentification("__SUM__")
.setAuthenticationType(AuthenticationTypeEnum.BASIC)
.setDataFeedDescription("This is a sample data feed.")
.setDataFeedName("Sample - cost/revenue - city/category")
.setDataSourceParameter(new SqlSourceParameter()
.setConnectionString("Server=PlaceholderSqlServer,1433;Initial Catalog=PlaceholderDatabase;User ID=PlaceholderUserName;Password=PlaceholderPassword;")
.setQuery("select * from your_table where timestamp = @StartTime"))
.setDataStartFrom("2020-01-01T00:00:00.000Z")
.setDimension(Arrays.asList(
new Dimension().setDimensionDisplayName("category").setDimensionName("category"),
new Dimension().setDimensionDisplayName("city").setDimensionName("city")
))
.setFillMissingPointType(FillMissingPointType.SMART_FILLING)
.setGranularityName(Granularity.DAILY)
.setMaxConcurrency(5)
.setMetrics(Arrays.asList(
new Metric().setMetricDisplayName("cost").setMetricName("cost"),
new Metric().setMetricDisplayName("revenue").setMetricName("revenue")
))
.setMinRetryIntervalInSeconds(3600L)
.setNeedRollup(NeedRollupEnum.NEED_ROLLUP)
.setRollUpMethod(RollUpMethod.SUM)
.setStartOffsetInSeconds(86400L)
.setStopRetryAfterInSeconds(604800L)
.setTimestampColumn("timestamp")
.setViewMode(ViewMode.PRIVATE);

DataFeedDetail createdDataFeed = metricsAdvisorClient.createDataFeed(dataFeed);
Assertions.assertEquals("Sample - cost/revenue - city/category", createdDataFeed.getDataFeedName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,36 @@
"Content-Type" : "application/json"
},
"Response" : {
"x-request-id" : "0b8b4ebb-ef95-46b4-9cde-8d06fe216686",
"x-request-id" : "076661ec-3955-4f07-8e90-a56e55446310",
"content-length" : "0",
"x-envoy-upstream-service-time" : "1981",
"x-envoy-upstream-service-time" : "1523",
"Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload",
"x-content-type-options" : "nosniff",
"apim-request-id" : "0b8b4ebb-ef95-46b4-9cde-8d06fe216686",
"apim-request-id" : "076661ec-3955-4f07-8e90-a56e55446310",
"retry-after" : "0",
"StatusCode" : "201",
"Date" : "Mon, 14 Mar 2022 04:54:08 GMT",
"Location" : "https://metricsadvisor-weidxu.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds/a4c95870-7426-488f-a1b6-5cee2115bd32"
"Date" : "Mon, 14 Mar 2022 06:28:47 GMT",
"Location" : "https://metricsadvisor-weidxu.cognitiveservices.azure.com/metricsadvisor/v1.0/dataFeeds/9a76030b-0b37-45fb-a238-47ff8ad6417e"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://REDACTED.cognitiveservices.azure.com//metricsadvisor/v1.0/dataFeeds/9a76030b-0b37-45fb-a238-47ff8ad6417e",
"Headers" : {
"User-Agent" : "azsdk-java-azure-ai-metricsadvisor/1.0.0-beta.1 (17.0.1; Windows 11; 10.0)"
},
"Response" : {
"x-request-id" : "f6dbc852-6bc8-4885-b02e-f741b75e2b02",
"content-length" : "1306",
"x-envoy-upstream-service-time" : "537",
"Strict-Transport-Security" : "max-age=31536000; includeSubDomains; preload",
"x-content-type-options" : "nosniff",
"apim-request-id" : "f6dbc852-6bc8-4885-b02e-f741b75e2b02",
"retry-after" : "0",
"StatusCode" : "200",
"Body" : "{\"dataFeedId\":\"9a76030b-0b37-45fb-a238-47ff8ad6417e\",\"dataFeedName\":\"Sample - cost/revenue - city/category\",\"metrics\":[{\"metricId\":\"8248ae1b-ff7a-44b2-81d0-c402eab01a34\",\"metricName\":\"cost\",\"metricDisplayName\":\"cost\",\"metricDescription\":\"\"},{\"metricId\":\"d32f9d9b-f0bd-479e-920f-1c7effb64f88\",\"metricName\":\"revenue\",\"metricDisplayName\":\"revenue\",\"metricDescription\":\"\"}],\"dimension\":[{\"dimensionName\":\"category\",\"dimensionDisplayName\":\"category\"},{\"dimensionName\":\"city\",\"dimensionDisplayName\":\"city\"}],\"dataStartFrom\":\"2020-01-01T00:00:00Z\",\"dataSourceType\":\"SqlServer\",\"timestampColumn\":\"timestamp\",\"startOffsetInSeconds\":86400,\"maxQueryPerMinute\":30.0,\"granularityName\":\"Daily\",\"allUpIdentification\":\"__SUM__\",\"needRollup\":\"NeedRollup\",\"fillMissingPointType\":\"SmartFilling\",\"fillMissingPointValue\":0.0,\"rollUpMethod\":\"Sum\",\"dataFeedDescription\":\"This is a sample data feed.\",\"stopRetryAfterInSeconds\":604800,\"minRetryIntervalInSeconds\":3600,\"maxConcurrency\":5,\"viewMode\":\"Private\",\"admins\":[\"09cc0fa8-7726-4f19-9216-8e9b0321cfa2\"],\"viewers\":[],\"creator\":\"09cc0fa8-7726-4f19-9216-8e9b0321cfa2\",\"status\":\"Active\",\"createdTime\":\"2022-03-14T06:28:46Z\",\"isAdmin\":true,\"actionLinkTemplate\":\"\",\"dataSourceParameter\":{\"query\":\"select * from your_table where timestamp = @StartTime\"},\"authenticationType\":\"Basic\"}",
"Date" : "Mon, 14 Mar 2022 06:28:49 GMT",
"Content-Type" : "application/json; charset=utf-8"
},
"Exception" : null
} ],
Expand Down

0 comments on commit 91c4c54

Please sign in to comment.