Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MetricsAdvisor] Fixed UpdateDataFeed methods #21574

Merged
merged 10 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ public MetricsAdvisorAdministrationClient(System.Uri endpoint, Azure.Core.TokenC
public virtual System.Threading.Tasks.Task<Azure.Response> RefreshDataFeedIngestionAsync(string dataFeedId, System.DateTimeOffset startTime, System.DateTimeOffset endTime, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.MetricsAdvisor.Models.AnomalyAlertConfiguration> UpdateAlertConfiguration(Azure.AI.MetricsAdvisor.Models.AnomalyAlertConfiguration alertConfiguration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.MetricsAdvisor.Models.AnomalyAlertConfiguration>> UpdateAlertConfigurationAsync(Azure.AI.MetricsAdvisor.Models.AnomalyAlertConfiguration alertConfiguration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response UpdateDataFeed(string dataFeedId, Azure.AI.MetricsAdvisor.Models.DataFeed dataFeed, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response> UpdateDataFeedAsync(string dataFeedId, Azure.AI.MetricsAdvisor.Models.DataFeed dataFeed, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.MetricsAdvisor.Models.DataFeed> UpdateDataFeed(Azure.AI.MetricsAdvisor.Models.DataFeed dataFeed, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.MetricsAdvisor.Models.DataFeed>> UpdateDataFeedAsync(Azure.AI.MetricsAdvisor.Models.DataFeed dataFeed, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.MetricsAdvisor.Models.DatasourceCredential> UpdateDatasourceCredential(Azure.AI.MetricsAdvisor.Models.DatasourceCredential datasourceCredential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.MetricsAdvisor.Models.DatasourceCredential>> UpdateDatasourceCredentialAsync(Azure.AI.MetricsAdvisor.Models.DatasourceCredential datasourceCredential, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.AI.MetricsAdvisor.Models.AnomalyDetectionConfiguration> UpdateDetectionConfiguration(Azure.AI.MetricsAdvisor.Models.AnomalyDetectionConfiguration detectionConfiguration, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,78 +351,77 @@ public virtual Response<DataFeed> CreateDataFeed(DataFeed dataFeed, Cancellation
}

/// <summary>
/// Updates an existing <see cref="DataFeed"/>.
/// Updates an existing <see cref="DataFeed"/>. In order to update your data feed, you cannot create a <see cref="DataFeed"/>
/// directly from its constructor. You need to obtain an instance via <see cref="GetDataFeedAsync"/> or another CRUD operation and update it
/// before calling this method.
/// </summary>
/// <param name="dataFeedId">The ID of the existing <see cref="DataFeed"/> to update.</param>
/// <param name="dataFeed">The <see cref="DataFeed"/> model containing the updates to be applied.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>
/// A <see cref="Response"/> containing the result of the operation.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="dataFeedId"/> or <paramref name="dataFeed"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="dataFeedId"/> is empty or not a valid GUID.</exception>
public virtual async Task<Response> UpdateDataFeedAsync(string dataFeedId, DataFeed dataFeed, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="dataFeed"/> or <paramref name="dataFeed"/>.Id is null.</exception>
public virtual async Task<Response<DataFeed>> UpdateDataFeedAsync(DataFeed dataFeed, CancellationToken cancellationToken = default)
{
/*
Guid dataFeedGuid = ClientCommon.ValidateGuid(dataFeedId, nameof(dataFeedId));
Argument.AssertNotNull(dataFeed, nameof(dataFeed));
if (!string.IsNullOrEmpty(dataFeed.Id) && !dataFeedId.Equals(dataFeed.Id, StringComparison.OrdinalIgnoreCase))

if (dataFeed.Id == null)
{
throw new ArgumentException($"{nameof(dataFeedId)} does not match {nameof(dataFeed.Id)}");
throw new ArgumentNullException(nameof(dataFeed), $"{nameof(dataFeed)}.Id not available. Call {nameof(GetDataFeedAsync)} and update the returned model before calling this method.");
}

Guid dataFeedGuid = new Guid(dataFeed.Id);

using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorAdministrationClient)}.{nameof(UpdateDataFeed)}");
scope.Start();
try
{
DataFeedDetailPatch patchModel = dataFeed.GetPatchModel();
return await _serviceRestClient.UpdateDataFeedAsync(dataFeedGuid, patchModel, cancellationToken).ConfigureAwait(false);
Response<DataFeedDetail> response = await _serviceRestClient.UpdateDataFeedAsync(dataFeedGuid, patchModel, cancellationToken).ConfigureAwait(false);
return Response.FromValue(new DataFeed(response.Value), response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
*/
await Task.CompletedTask.ConfigureAwait(false);
return default;
}

/// <summary>
/// Updates an existing <see cref="DataFeed"/>.
/// Updates an existing <see cref="DataFeed"/>. In order to update your data feed, you cannot create a <see cref="DataFeed"/>
/// directly from its constructor. You need to obtain an instance via <see cref="GetDataFeedAsync"/> or another CRUD operation and update it
/// before calling this method.
/// </summary>
/// <param name="dataFeedId">The ID of the existing <see cref="DataFeed"/> to update.</param>
/// <param name="dataFeed">The <see cref="DataFeed"/> model containing the updates to be applied.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <returns>
/// A <see cref="Response"/> containing the result of the operation.
/// </returns>
/// <exception cref="ArgumentNullException"><paramref name="dataFeedId"/> or <paramref name="dataFeed"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="dataFeedId"/> is empty or not a valid GUID.</exception>
public virtual Response UpdateDataFeed(string dataFeedId, DataFeed dataFeed, CancellationToken cancellationToken = default)
/// <exception cref="ArgumentNullException"><paramref name="dataFeed"/> or <paramref name="dataFeed"/>.Id is null.</exception>
public virtual Response<DataFeed> UpdateDataFeed(DataFeed dataFeed, CancellationToken cancellationToken = default)
{
/*
Guid dataFeedGuid = ClientCommon.ValidateGuid(dataFeedId, nameof(dataFeedId));
Argument.AssertNotNull(dataFeed, nameof(dataFeed));
if (!string.IsNullOrEmpty(dataFeed.Id) && !dataFeedId.Equals(dataFeed.Id, StringComparison.OrdinalIgnoreCase))

if (dataFeed.Id == null)
{
throw new ArgumentException($"{nameof(dataFeedId)} does not match {nameof(dataFeed.Id)}");
throw new ArgumentNullException(nameof(dataFeed), $"{nameof(dataFeed)}.Id not available. Call {nameof(GetDataFeed)} and update the returned model before calling this method.");
}

Guid dataFeedGuid = new Guid(dataFeed.Id);

using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(MetricsAdvisorAdministrationClient)}.{nameof(UpdateDataFeed)}");
scope.Start();
try
{
DataFeedDetailPatch patchModel = dataFeed.GetPatchModel();
return _serviceRestClient.UpdateDataFeed(dataFeedGuid, patchModel, cancellationToken);
Response<DataFeedDetail> response = _serviceRestClient.UpdateDataFeed(dataFeedGuid, patchModel, cancellationToken);
return Response.FromValue(new DataFeed(response.Value), response.GetRawResponse());
}
catch (Exception ex)
{
scope.Failed(ex);
throw;
}
*/
return default;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public abstract class DataFeedSource
{
internal DataFeedSourceType Type { get; }

internal object Parameter { get; set; }

internal DataFeedSource(DataFeedSourceType dataFeedSourceType)
{
Type = dataFeedSourceType;
Expand Down Expand Up @@ -44,45 +42,62 @@ internal DataFeedDetail InstantiateDataFeedDetail(string name, DataFeedGranulari
{
ingestionStartTime = ClientCommon.NormalizeDateTimeOffset(ingestionStartTime);

return Parameter switch
return this switch
{
AzureApplicationInsightsParameter p => new AzureApplicationInsightsDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
AzureBlobParameter p => new AzureBlobDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
AzureCosmosDBParameter p => new AzureCosmosDBDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
AzureDataLakeStorageGen2Parameter p => new AzureDataLakeStorageGen2DataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
AzureTableParameter p => new AzureTableDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
InfluxDBParameter p => new InfluxDBDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
SqlSourceParameter p when Type == DataFeedSourceType.AzureDataExplorer => new AzureDataExplorerDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
SqlSourceParameter p when Type == DataFeedSourceType.MySql => new MySqlDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
SqlSourceParameter p when Type == DataFeedSourceType.PostgreSql => new PostgreSqlDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
SqlSourceParameter p when Type == DataFeedSourceType.SqlServer => new SQLServerDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
MongoDBParameter p => new MongoDBDataFeed(name, granularityType, metricColumns, ingestionStartTime, p),
AzureApplicationInsightsDataFeedSource d => new AzureApplicationInsightsDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new AzureApplicationInsightsParameter(d.Query) { ApiKey = d.ApiKey, ApplicationId = d.ApplicationId, AzureCloud = d.AzureCloud }),
kinelski marked this conversation as resolved.
Show resolved Hide resolved
AzureBlobDataFeedSource d => new AzureBlobDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new AzureBlobParameter(d.Container, d.BlobTemplate) { ConnectionString = d.ConnectionString }),
AzureCosmosDbDataFeedSource d => new AzureCosmosDBDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new AzureCosmosDBParameter(d.SqlQuery, d.Database, d.CollectionId) { ConnectionString = d.ConnectionString }),
AzureDataExplorerDataFeedSource d => new AzureDataExplorerDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new SqlSourceParameter(d.Query) { ConnectionString = d.ConnectionString }),
AzureDataLakeStorageGen2DataFeedSource d => new AzureDataLakeStorageGen2DataFeed(name, granularityType, metricColumns, ingestionStartTime,
new AzureDataLakeStorageGen2Parameter(d.FileSystemName, d.DirectoryTemplate, d.FileTemplate) { AccountKey = d.AccountKey, AccountName = d.AccountName }),
AzureTableDataFeedSource d => new AzureTableDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new AzureTableParameter(d.Table, d.Query) { ConnectionString = d.ConnectionString }),
InfluxDbDataFeedSource d => new InfluxDBDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new InfluxDBParameter(d.Query) { UserName = d.Username, Password = d.Password, Database = d.Database, ConnectionString = d.ConnectionString }),
MongoDbDataFeedSource d => new MongoDBDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new MongoDBParameter(d.Command) { Database = d.Database, ConnectionString = d.ConnectionString }),
MySqlDataFeedSource d => new MySqlDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new SqlSourceParameter(d.Query) { ConnectionString = d.ConnectionString }),
PostgreSqlDataFeedSource d => new PostgreSqlDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new SqlSourceParameter(d.Query) { ConnectionString = d.ConnectionString }),
SqlServerDataFeedSource d => new SQLServerDataFeed(name, granularityType, metricColumns, ingestionStartTime,
new SqlSourceParameter(d.Query) { ConnectionString = d.ConnectionString }),
_ => throw new InvalidOperationException("Invalid DataFeedDetail type")
};
}

/// <summary>
/// Initializes a new instance of a data source specific DataFeedDetailPatch.
/// </summary>
internal DataFeedDetailPatch InstantiateDataFeedDetailPatch()
internal DataFeedDetailPatch InstantiateDataFeedDetailPatch() => this switch
{
return Parameter switch
{
/*
AzureApplicationInsightsParameter p => new AzureApplicationInsightsDataFeedPatch() { DataSourceParameter = p },
AzureBlobParameter p => new AzureBlobDataFeedPatch() { DataSourceParameter = p },
AzureCosmosDBParameter p => new AzureCosmosDBDataFeedPatch() { DataSourceParameter = p },
AzureDataLakeStorageGen2Parameter p => new AzureDataLakeStorageGen2DataFeedPatch() { DataSourceParameter = p },
AzureTableParameter p => new AzureTableDataFeedPatch() { DataSourceParameter = p },
InfluxDBParameter p => new InfluxDBDataFeedPatch() { DataSourceParameter = p },
SqlSourceParameter p when Type == DataFeedSourceType.AzureDataExplorer => new AzureDataExplorerDataFeedPatch() { DataSourceParameter = p },
SqlSourceParameter p when Type == DataFeedSourceType.MySql => new MySqlDataFeedPatch() { DataSourceParameter = p },
SqlSourceParameter p when Type == DataFeedSourceType.PostgreSql => new PostgreSqlDataFeedPatch() { DataSourceParameter = p },
SqlSourceParameter p when Type == DataFeedSourceType.SqlServer => new SQLServerDataFeedPatch() { DataSourceParameter = p },
MongoDBParameter p => new MongoDBDataFeedPatch() { DataSourceParameter = p },
*/
_ => throw new InvalidOperationException("Invalid DataFeedDetailPatch type")
};
}
AzureApplicationInsightsDataFeedSource d => new AzureApplicationInsightsDataFeedPatch()
{ DataSourceParameter = new() { Query = d.Query, ApiKey = d.ApiKey, ApplicationId = d.ApplicationId, AzureCloud = d.AzureCloud } },
AzureBlobDataFeedSource d => new AzureBlobDataFeedPatch()
{ DataSourceParameter = new() { Container = d.Container, BlobTemplate = d.BlobTemplate, ConnectionString = d.ConnectionString } },
AzureCosmosDbDataFeedSource d => new AzureCosmosDBDataFeedPatch()
{ DataSourceParameter = new() { SqlQuery = d.SqlQuery, Database = d.Database, CollectionId = d.CollectionId, ConnectionString = d.ConnectionString } },
AzureDataExplorerDataFeedSource d => new AzureDataExplorerDataFeedPatch()
{ DataSourceParameter = new() { Query = d.Query, ConnectionString = d.ConnectionString } },
AzureDataLakeStorageGen2DataFeedSource d => new AzureDataLakeStorageGen2DataFeedPatch()
{ DataSourceParameter = new() { FileSystemName = d.FileSystemName, DirectoryTemplate = d.DirectoryTemplate, FileTemplate = d.FileTemplate, AccountKey = d.AccountKey, AccountName = d.AccountName } },
AzureTableDataFeedSource d => new AzureTableDataFeedPatch()
{ DataSourceParameter = new() { Table = d.Table, Query = d.Query, ConnectionString = d.ConnectionString } },
InfluxDbDataFeedSource d => new InfluxDBDataFeedPatch()
{ DataSourceParameter = new() { Query = d.Query, UserName = d.Username, Password = d.Password, Database = d.Database, ConnectionString = d.ConnectionString } },
MongoDbDataFeedSource d => new MongoDBDataFeedPatch()
{ DataSourceParameter = new() { Command = d.Command, Database = d.Database, ConnectionString = d.ConnectionString } },
MySqlDataFeedSource d => new MySqlDataFeedPatch()
{ DataSourceParameter = new() { Query = d.Query, ConnectionString = d.ConnectionString } },
PostgreSqlDataFeedSource d => new PostgreSqlDataFeedPatch()
{ DataSourceParameter = new() { Query = d.Query, ConnectionString = d.ConnectionString } },
SqlServerDataFeedSource d => new SQLServerDataFeedPatch()
{ DataSourceParameter = new() { Query = d.Query, ConnectionString = d.ConnectionString } },
_ => throw new InvalidOperationException("Invalid DataFeedDetailPatch type")
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public AzureApplicationInsightsDataFeedSource(string applicationId, string apiKe
Argument.AssertNotNullOrEmpty(apiKey, nameof(apiKey));
Argument.AssertNotNullOrEmpty(query, nameof(query));

Parameter = new AzureApplicationInsightsParameter(azureCloud, applicationId, apiKey, query);
kinelski marked this conversation as resolved.
Show resolved Hide resolved

ApplicationId = applicationId;
ApiKey = apiKey;
AzureCloud = azureCloud;
Expand All @@ -44,8 +42,6 @@ internal AzureApplicationInsightsDataFeedSource(AzureApplicationInsightsParamete
{
Argument.AssertNotNull(parameter, nameof(parameter));

Parameter = parameter;

ApplicationId = parameter.ApplicationId;
ApiKey = parameter.ApiKey;
AzureCloud = parameter.AzureCloud;
Expand Down
Loading