1package datafactory
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// PipelineRunsClient is the the Azure Data Factory V2 management API provides a RESTful set of web services that
30// interact with Azure Data Factory V2 services.
31type PipelineRunsClient struct {
32	BaseClient
33}
34
35// NewPipelineRunsClient creates an instance of the PipelineRunsClient client.
36func NewPipelineRunsClient(subscriptionID string) PipelineRunsClient {
37	return NewPipelineRunsClientWithBaseURI(DefaultBaseURI, subscriptionID)
38}
39
40// NewPipelineRunsClientWithBaseURI creates an instance of the PipelineRunsClient client using a custom endpoint.  Use
41// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
42func NewPipelineRunsClientWithBaseURI(baseURI string, subscriptionID string) PipelineRunsClient {
43	return PipelineRunsClient{NewWithBaseURI(baseURI, subscriptionID)}
44}
45
46// Cancel cancel a pipeline run by its run ID.
47// Parameters:
48// resourceGroupName - the resource group name.
49// factoryName - the factory name.
50// runID - the pipeline run identifier.
51// isRecursive - if true, cancel all the Child pipelines that are triggered by the current pipeline.
52func (client PipelineRunsClient) Cancel(ctx context.Context, resourceGroupName string, factoryName string, runID string, isRecursive *bool) (result autorest.Response, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/PipelineRunsClient.Cancel")
55		defer func() {
56			sc := -1
57			if result.Response != nil {
58				sc = result.Response.StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	if err := validation.Validate([]validation.Validation{
64		{TargetValue: resourceGroupName,
65			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
66				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
67				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
68		{TargetValue: factoryName,
69			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
70				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
71				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}}}); err != nil {
72		return result, validation.NewError("datafactory.PipelineRunsClient", "Cancel", err.Error())
73	}
74
75	req, err := client.CancelPreparer(ctx, resourceGroupName, factoryName, runID, isRecursive)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "datafactory.PipelineRunsClient", "Cancel", nil, "Failure preparing request")
78		return
79	}
80
81	resp, err := client.CancelSender(req)
82	if err != nil {
83		result.Response = resp
84		err = autorest.NewErrorWithError(err, "datafactory.PipelineRunsClient", "Cancel", resp, "Failure sending request")
85		return
86	}
87
88	result, err = client.CancelResponder(resp)
89	if err != nil {
90		err = autorest.NewErrorWithError(err, "datafactory.PipelineRunsClient", "Cancel", resp, "Failure responding to request")
91	}
92
93	return
94}
95
96// CancelPreparer prepares the Cancel request.
97func (client PipelineRunsClient) CancelPreparer(ctx context.Context, resourceGroupName string, factoryName string, runID string, isRecursive *bool) (*http.Request, error) {
98	pathParameters := map[string]interface{}{
99		"factoryName":       autorest.Encode("path", factoryName),
100		"resourceGroupName": autorest.Encode("path", resourceGroupName),
101		"runId":             autorest.Encode("path", runID),
102		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
103	}
104
105	const APIVersion = "2018-06-01"
106	queryParameters := map[string]interface{}{
107		"api-version": APIVersion,
108	}
109	if isRecursive != nil {
110		queryParameters["isRecursive"] = autorest.Encode("query", *isRecursive)
111	}
112
113	preparer := autorest.CreatePreparer(
114		autorest.AsPost(),
115		autorest.WithBaseURL(client.BaseURI),
116		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns/{runId}/cancel", pathParameters),
117		autorest.WithQueryParameters(queryParameters))
118	return preparer.Prepare((&http.Request{}).WithContext(ctx))
119}
120
121// CancelSender sends the Cancel request. The method will close the
122// http.Response Body if it receives an error.
123func (client PipelineRunsClient) CancelSender(req *http.Request) (*http.Response, error) {
124	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
125}
126
127// CancelResponder handles the response to the Cancel request. The method always
128// closes the http.Response Body.
129func (client PipelineRunsClient) CancelResponder(resp *http.Response) (result autorest.Response, err error) {
130	err = autorest.Respond(
131		resp,
132		client.ByInspecting(),
133		azure.WithErrorUnlessStatusCode(http.StatusOK),
134		autorest.ByClosing())
135	result.Response = resp
136	return
137}
138
139// Get get a pipeline run by its run ID.
140// Parameters:
141// resourceGroupName - the resource group name.
142// factoryName - the factory name.
143// runID - the pipeline run identifier.
144func (client PipelineRunsClient) Get(ctx context.Context, resourceGroupName string, factoryName string, runID string) (result PipelineRun, err error) {
145	if tracing.IsEnabled() {
146		ctx = tracing.StartSpan(ctx, fqdn+"/PipelineRunsClient.Get")
147		defer func() {
148			sc := -1
149			if result.Response.Response != nil {
150				sc = result.Response.Response.StatusCode
151			}
152			tracing.EndSpan(ctx, sc, err)
153		}()
154	}
155	if err := validation.Validate([]validation.Validation{
156		{TargetValue: resourceGroupName,
157			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
158				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
159				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
160		{TargetValue: factoryName,
161			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
162				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
163				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}}}); err != nil {
164		return result, validation.NewError("datafactory.PipelineRunsClient", "Get", err.Error())
165	}
166
167	req, err := client.GetPreparer(ctx, resourceGroupName, factoryName, runID)
168	if err != nil {
169		err = autorest.NewErrorWithError(err, "datafactory.PipelineRunsClient", "Get", nil, "Failure preparing request")
170		return
171	}
172
173	resp, err := client.GetSender(req)
174	if err != nil {
175		result.Response = autorest.Response{Response: resp}
176		err = autorest.NewErrorWithError(err, "datafactory.PipelineRunsClient", "Get", resp, "Failure sending request")
177		return
178	}
179
180	result, err = client.GetResponder(resp)
181	if err != nil {
182		err = autorest.NewErrorWithError(err, "datafactory.PipelineRunsClient", "Get", resp, "Failure responding to request")
183	}
184
185	return
186}
187
188// GetPreparer prepares the Get request.
189func (client PipelineRunsClient) GetPreparer(ctx context.Context, resourceGroupName string, factoryName string, runID string) (*http.Request, error) {
190	pathParameters := map[string]interface{}{
191		"factoryName":       autorest.Encode("path", factoryName),
192		"resourceGroupName": autorest.Encode("path", resourceGroupName),
193		"runId":             autorest.Encode("path", runID),
194		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
195	}
196
197	const APIVersion = "2018-06-01"
198	queryParameters := map[string]interface{}{
199		"api-version": APIVersion,
200	}
201
202	preparer := autorest.CreatePreparer(
203		autorest.AsGet(),
204		autorest.WithBaseURL(client.BaseURI),
205		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns/{runId}", pathParameters),
206		autorest.WithQueryParameters(queryParameters))
207	return preparer.Prepare((&http.Request{}).WithContext(ctx))
208}
209
210// GetSender sends the Get request. The method will close the
211// http.Response Body if it receives an error.
212func (client PipelineRunsClient) GetSender(req *http.Request) (*http.Response, error) {
213	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
214}
215
216// GetResponder handles the response to the Get request. The method always
217// closes the http.Response Body.
218func (client PipelineRunsClient) GetResponder(resp *http.Response) (result PipelineRun, err error) {
219	err = autorest.Respond(
220		resp,
221		client.ByInspecting(),
222		azure.WithErrorUnlessStatusCode(http.StatusOK),
223		autorest.ByUnmarshallingJSON(&result),
224		autorest.ByClosing())
225	result.Response = autorest.Response{Response: resp}
226	return
227}
228
229// QueryByFactory query pipeline runs in the factory based on input filter conditions.
230// Parameters:
231// resourceGroupName - the resource group name.
232// factoryName - the factory name.
233// filterParameters - parameters to filter the pipeline run.
234func (client PipelineRunsClient) QueryByFactory(ctx context.Context, resourceGroupName string, factoryName string, filterParameters RunFilterParameters) (result PipelineRunsQueryResponse, err error) {
235	if tracing.IsEnabled() {
236		ctx = tracing.StartSpan(ctx, fqdn+"/PipelineRunsClient.QueryByFactory")
237		defer func() {
238			sc := -1
239			if result.Response.Response != nil {
240				sc = result.Response.Response.StatusCode
241			}
242			tracing.EndSpan(ctx, sc, err)
243		}()
244	}
245	if err := validation.Validate([]validation.Validation{
246		{TargetValue: resourceGroupName,
247			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
248				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
249				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
250		{TargetValue: factoryName,
251			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
252				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
253				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}},
254		{TargetValue: filterParameters,
255			Constraints: []validation.Constraint{{Target: "filterParameters.LastUpdatedAfter", Name: validation.Null, Rule: true, Chain: nil},
256				{Target: "filterParameters.LastUpdatedBefore", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
257		return result, validation.NewError("datafactory.PipelineRunsClient", "QueryByFactory", err.Error())
258	}
259
260	req, err := client.QueryByFactoryPreparer(ctx, resourceGroupName, factoryName, filterParameters)
261	if err != nil {
262		err = autorest.NewErrorWithError(err, "datafactory.PipelineRunsClient", "QueryByFactory", nil, "Failure preparing request")
263		return
264	}
265
266	resp, err := client.QueryByFactorySender(req)
267	if err != nil {
268		result.Response = autorest.Response{Response: resp}
269		err = autorest.NewErrorWithError(err, "datafactory.PipelineRunsClient", "QueryByFactory", resp, "Failure sending request")
270		return
271	}
272
273	result, err = client.QueryByFactoryResponder(resp)
274	if err != nil {
275		err = autorest.NewErrorWithError(err, "datafactory.PipelineRunsClient", "QueryByFactory", resp, "Failure responding to request")
276	}
277
278	return
279}
280
281// QueryByFactoryPreparer prepares the QueryByFactory request.
282func (client PipelineRunsClient) QueryByFactoryPreparer(ctx context.Context, resourceGroupName string, factoryName string, filterParameters RunFilterParameters) (*http.Request, error) {
283	pathParameters := map[string]interface{}{
284		"factoryName":       autorest.Encode("path", factoryName),
285		"resourceGroupName": autorest.Encode("path", resourceGroupName),
286		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
287	}
288
289	const APIVersion = "2018-06-01"
290	queryParameters := map[string]interface{}{
291		"api-version": APIVersion,
292	}
293
294	preparer := autorest.CreatePreparer(
295		autorest.AsContentType("application/json; charset=utf-8"),
296		autorest.AsPost(),
297		autorest.WithBaseURL(client.BaseURI),
298		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/queryPipelineRuns", pathParameters),
299		autorest.WithJSON(filterParameters),
300		autorest.WithQueryParameters(queryParameters))
301	return preparer.Prepare((&http.Request{}).WithContext(ctx))
302}
303
304// QueryByFactorySender sends the QueryByFactory request. The method will close the
305// http.Response Body if it receives an error.
306func (client PipelineRunsClient) QueryByFactorySender(req *http.Request) (*http.Response, error) {
307	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
308}
309
310// QueryByFactoryResponder handles the response to the QueryByFactory request. The method always
311// closes the http.Response Body.
312func (client PipelineRunsClient) QueryByFactoryResponder(resp *http.Response) (result PipelineRunsQueryResponse, err error) {
313	err = autorest.Respond(
314		resp,
315		client.ByInspecting(),
316		azure.WithErrorUnlessStatusCode(http.StatusOK),
317		autorest.ByUnmarshallingJSON(&result),
318		autorest.ByClosing())
319	result.Response = autorest.Response{Response: resp}
320	return
321}
322