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

[Data Factory] Adding configure factory repo operation #4360

Merged
merged 7 commits into from
May 23, 2018
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 @@ -44,6 +44,41 @@ public class TriggerJsonSamples : JsonSampleCollection<TriggerJsonSamples>
}
}";

[JsonSample]
public const string BlobEventsTriggerSample = @"
{
name: ""myDemoBlobEventsTrigger"",
properties: {
type: ""BlobEventsTrigger"",
typeProperties: {
blobPathBeginsWith: ""/containerName/blobs/folderName"",
events: [
""Microsoft.Storage.BlobCreated""
],
scope: ""/subscriptions/297556dc-ea2f-4d52-b390-084a6fc53194/resourceGroups/testresourcegroup/providers/Microsoft.Storage/storageAccounts/teststorageaccount"",
},
pipelines: [
{
pipelineReference: {
type: ""PipelineReference"",
referenceName: ""myCopyPipeline""
},
parameters: {
mySinkDatasetFolderPath: ""sinkcontainer"",
mySourceDatasetFolderPath: {
type: ""Expression"",
value: ""@triggerBody().folderPath""
},
mySourceDatasetFilePath: {
type: ""Expression"",
value: ""@triggerBody().fileName""
}
}
}
]
}
}";

[JsonSample]
public const string ScheduleTriggerSample = @"
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"parameters": {
"subscriptionId": "12345678-1234-1234-12345678abc",
"locationId": "eastus",
"factoryRepoUpdate": {
"factoryResourceId": "/subscriptions/12345678-1234-1234-12345678abc/resourceGroups/exampleResourceGroup/providers/Microsoft.DataFactory/factories/exampleFactoryName",
"ResourceGroupName": "exampleResourceGroup",
"vstsConfiguration": {
"AccountName": "ADF",
"ProjectName": "project",
"RepositoryName": "repo",
"CollaborationBranch": "master",
"RootFolder": "/",
"LastCommitId": "",
"TenantId": ""
}
},
"api-version": "2017-09-01-preview"
},
"responses": {
"200": {
"headers": {
"Date": "Wed, 13 Sep 2017 17:33:55 GMT",
"x-ms-request-id": "3223701f-ce33-4a58-bb14-d3d53569d4f0",
"X-Content-Type-Options": "nosniff",
"x-ms-ratelimit-remaining-subscription-writes": "1197",
"x-ms-correlation-request-id": "ec4ce622-a1dd-4c49-a324-17e8d4d1fe83"
},
"body": {
"name": "exampleFactoryName",
"tags": {
"exampleTag": "exampleValue"
},
"properties": {
"provisioningState": "Succeeded",
"createTime": "2017-09-13T17:33:54.0294655Z",
"version": "2017-09-01-preview",
"vstsConfiguration": {
"accountName": "ADF",
"projectName": "project",
"repositoryName": "repo",
"collaborationBranch": "master",
"rootFolder": "/",
"lastCommitId": "",
"tenantId": ""
}
},
"id": "/subscriptions/12345678-1234-1234-12345678abc/resourceGroups/exampleresourcegroup/providers/Microsoft.DataFactory/factories/exampleFactoryName",
"type": "Microsoft.DataFactory/factories",
"location": "East US"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ public void Factories_Update()
});
}

[Fact]
public void Factories_ConfigureRepo()
{
RunTest("Factories_ConfigureRepo", (example, client, responseCode) =>
{
Factory resource = client.Factories.ConfigureFactoryRepo(LN(example), GetTypedParameter<FactoryRepoUpdate>(example, client, "factoryRepoUpdate"));
CheckResponseBody(example, client, responseCode, resource);
});
}

[Fact]
public void Factories_List()
{
Expand Down Expand Up @@ -676,6 +686,10 @@ private string PN(Example example)
{
return (string)example.Parameters["pipelineName"];
}
private string LN(Example example)
{
return (string)example.Parameters["locationId"];
}

private T GetTypedObject<T>(IDataFactoryManagementClient client, object objectRaw)
{
Expand Down
22 changes: 22 additions & 0 deletions src/SDKs/DataFactory/DataFactory.Tests/Utils/ExampleCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void CaptureAllExamples()
// Start Factories operations, leaving factory available
CaptureFactories_CreateOrUpdate(); // 200
CaptureFactories_Update(); // 200
CaptureFactories_ConfigureRepo(); // 200
CaptureFactories_Get(); // 200
CaptureFactories_ListByResourceGroup(); // 200
CaptureFactories_List();
Expand Down Expand Up @@ -219,6 +220,27 @@ private void CaptureFactories_Update()
Factory resource = client.Factories.Update(secrets.ResourceGroupName, secrets.FactoryName, new FactoryUpdateParameters { Tags = tags });
}

private void CaptureFactories_ConfigureRepo()
{
interceptor.CurrentExampleName = "Factories_Update";
var repoUpdate = new FactoryRepoUpdate()
{
FactoryResourceId = string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.DataFactory/factories/{2}", ExampleSecrets.ExampleSubId,ExampleSecrets.ExampleResourceGroupName, ExampleSecrets.ExampleFactoryName),
ResourceGroupName = ExampleSecrets.ExampleResourceGroupName,
VstsConfiguration = new FactoryVSTSConfiguration()
{
AccountName = "ADF",
ProjectName= "project",
RepositoryName= "repo",
CollaborationBranch= "master",
RootFolder= "/",
LastCommitId= "",
TenantId= ""
}
};
Factory resource = client.Factories.ConfigureFactoryRepo(secrets.FactoryLocation, repoUpdate);
}

private void CaptureFactories_Get()
{
interceptor.CurrentExampleName = "Factories_Get";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,202 @@ internal FactoriesOperations(DataFactoryManagementClient client)
return _result;
}

/// <summary>
/// Updates a factory's repo information.
/// </summary>
/// <param name='locationId'>
/// The location identifier.
/// </param>
/// <param name='factoryRepoUpdate'>
/// Update factory repo request definition.
/// </param>
/// <param name='customHeaders'>
/// Headers that will be added to request.
/// </param>
/// <param name='cancellationToken'>
/// The cancellation token.
/// </param>
/// <exception cref="ErrorResponseException">
/// Thrown when the operation returned an invalid status code
/// </exception>
/// <exception cref="SerializationException">
/// Thrown when unable to deserialize the response
/// </exception>
/// <exception cref="ValidationException">
/// Thrown when a required parameter is null
/// </exception>
/// <exception cref="System.ArgumentNullException">
/// Thrown when a required parameter is null
/// </exception>
/// <return>
/// A response object containing the response body and response headers.
/// </return>
public async Task<AzureOperationResponse<Factory>> ConfigureFactoryRepoWithHttpMessagesAsync(string locationId, FactoryRepoUpdate factoryRepoUpdate, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
{
if (Client.SubscriptionId == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId");
}
if (locationId == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "locationId");
}
if (Client.ApiVersion == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion");
}
if (factoryRepoUpdate == null)
{
throw new ValidationException(ValidationRules.CannotBeNull, "factoryRepoUpdate");
}
// Tracing
bool _shouldTrace = ServiceClientTracing.IsEnabled;
string _invocationId = null;
if (_shouldTrace)
{
_invocationId = ServiceClientTracing.NextInvocationId.ToString();
Dictionary<string, object> tracingParameters = new Dictionary<string, object>();
tracingParameters.Add("locationId", locationId);
tracingParameters.Add("factoryRepoUpdate", factoryRepoUpdate);
tracingParameters.Add("cancellationToken", cancellationToken);
ServiceClientTracing.Enter(_invocationId, this, "ConfigureFactoryRepo", tracingParameters);
}
// Construct URL
var _baseUrl = Client.BaseUri.AbsoluteUri;
var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/providers/Microsoft.DataFactory/locations/{locationId}/configureFactoryRepo").ToString();
_url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId));
_url = _url.Replace("{locationId}", System.Uri.EscapeDataString(locationId));
List<string> _queryParameters = new List<string>();
if (Client.ApiVersion != null)
{
_queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion)));
}
if (_queryParameters.Count > 0)
{
_url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters);
}
// Create HTTP transport objects
var _httpRequest = new HttpRequestMessage();
HttpResponseMessage _httpResponse = null;
_httpRequest.Method = new HttpMethod("POST");
_httpRequest.RequestUri = new System.Uri(_url);
// Set Headers
if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value)
{
_httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString());
}
if (Client.AcceptLanguage != null)
{
if (_httpRequest.Headers.Contains("accept-language"))
{
_httpRequest.Headers.Remove("accept-language");
}
_httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage);
}


if (customHeaders != null)
{
foreach(var _header in customHeaders)
{
if (_httpRequest.Headers.Contains(_header.Key))
{
_httpRequest.Headers.Remove(_header.Key);
}
_httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
}
}

// Serialize Request
string _requestContent = null;
if(factoryRepoUpdate != null)
{
_requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(factoryRepoUpdate, Client.SerializationSettings);
_httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
_httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
}
// Set Credentials
if (Client.Credentials != null)
{
cancellationToken.ThrowIfCancellationRequested();
await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
}
// Send Request
if (_shouldTrace)
{
ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
}
cancellationToken.ThrowIfCancellationRequested();
_httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);
if (_shouldTrace)
{
ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
}
HttpStatusCode _statusCode = _httpResponse.StatusCode;
cancellationToken.ThrowIfCancellationRequested();
string _responseContent = null;
if ((int)_statusCode != 200)
{
var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
try
{
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_responseContent, Client.DeserializationSettings);
if (_errorBody != null)
{
ex.Body = _errorBody;
}
}
catch (JsonException)
{
// Ignore the exception
}
ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
if (_shouldTrace)
{
ServiceClientTracing.Error(_invocationId, ex);
}
_httpRequest.Dispose();
if (_httpResponse != null)
{
_httpResponse.Dispose();
}
throw ex;
}
// Create Result
var _result = new AzureOperationResponse<Factory>();
_result.Request = _httpRequest;
_result.Response = _httpResponse;
if (_httpResponse.Headers.Contains("x-ms-request-id"))
{
_result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
}
// Deserialize Response
if ((int)_statusCode == 200)
{
_responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
try
{
_result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Factory>(_responseContent, Client.DeserializationSettings);
}
catch (JsonException ex)
{
_httpRequest.Dispose();
if (_httpResponse != null)
{
_httpResponse.Dispose();
}
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
}
}
if (_shouldTrace)
{
ServiceClientTracing.Exit(_invocationId, _result);
}
return _result;
}

/// <summary>
/// Lists factories.
/// </summary>
Expand Down
Loading