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/date"
25	"github.com/Azure/go-autorest/autorest/validation"
26	"github.com/Azure/go-autorest/tracing"
27	"net/http"
28)
29
30// ActivityRunsClient is the the Azure Data Factory V2 management API provides a RESTful set of web services that
31// interact with Azure Data Factory V2 services.
32type ActivityRunsClient struct {
33	BaseClient
34}
35
36// NewActivityRunsClient creates an instance of the ActivityRunsClient client.
37func NewActivityRunsClient(subscriptionID string) ActivityRunsClient {
38	return NewActivityRunsClientWithBaseURI(DefaultBaseURI, subscriptionID)
39}
40
41// NewActivityRunsClientWithBaseURI creates an instance of the ActivityRunsClient client using a custom endpoint.  Use
42// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
43func NewActivityRunsClientWithBaseURI(baseURI string, subscriptionID string) ActivityRunsClient {
44	return ActivityRunsClient{NewWithBaseURI(baseURI, subscriptionID)}
45}
46
47// ListByPipelineRun list activity runs based on input filter conditions.
48// Parameters:
49// resourceGroupName - the resource group name.
50// factoryName - the factory name.
51// runID - the pipeline run identifier.
52// startTime - the start time of activity runs in ISO8601 format.
53// endTime - the end time of activity runs in ISO8601 format.
54// status - the status of the pipeline run.
55// activityName - the name of the activity.
56// linkedServiceName - the linked service name.
57func (client ActivityRunsClient) ListByPipelineRun(ctx context.Context, resourceGroupName string, factoryName string, runID string, startTime date.Time, endTime date.Time, status string, activityName string, linkedServiceName string) (result ActivityRunsListResponsePage, err error) {
58	if tracing.IsEnabled() {
59		ctx = tracing.StartSpan(ctx, fqdn+"/ActivityRunsClient.ListByPipelineRun")
60		defer func() {
61			sc := -1
62			if result.arlr.Response.Response != nil {
63				sc = result.arlr.Response.Response.StatusCode
64			}
65			tracing.EndSpan(ctx, sc, err)
66		}()
67	}
68	if err := validation.Validate([]validation.Validation{
69		{TargetValue: resourceGroupName,
70			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
71				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
72				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
73		{TargetValue: factoryName,
74			Constraints: []validation.Constraint{{Target: "factoryName", Name: validation.MaxLength, Rule: 63, Chain: nil},
75				{Target: "factoryName", Name: validation.MinLength, Rule: 3, Chain: nil},
76				{Target: "factoryName", Name: validation.Pattern, Rule: `^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`, Chain: nil}}},
77		{TargetValue: linkedServiceName,
78			Constraints: []validation.Constraint{{Target: "linkedServiceName", Name: validation.Empty, Rule: false,
79				Chain: []validation.Constraint{{Target: "linkedServiceName", Name: validation.MaxLength, Rule: 260, Chain: nil},
80					{Target: "linkedServiceName", Name: validation.MinLength, Rule: 1, Chain: nil},
81					{Target: "linkedServiceName", Name: validation.Pattern, Rule: `^[A-Za-z0-9_][^<>*#.%&:\\+?/]*$`, Chain: nil},
82				}}}}}); err != nil {
83		return result, validation.NewError("datafactory.ActivityRunsClient", "ListByPipelineRun", err.Error())
84	}
85
86	result.fn = client.listByPipelineRunNextResults
87	req, err := client.ListByPipelineRunPreparer(ctx, resourceGroupName, factoryName, runID, startTime, endTime, status, activityName, linkedServiceName)
88	if err != nil {
89		err = autorest.NewErrorWithError(err, "datafactory.ActivityRunsClient", "ListByPipelineRun", nil, "Failure preparing request")
90		return
91	}
92
93	resp, err := client.ListByPipelineRunSender(req)
94	if err != nil {
95		result.arlr.Response = autorest.Response{Response: resp}
96		err = autorest.NewErrorWithError(err, "datafactory.ActivityRunsClient", "ListByPipelineRun", resp, "Failure sending request")
97		return
98	}
99
100	result.arlr, err = client.ListByPipelineRunResponder(resp)
101	if err != nil {
102		err = autorest.NewErrorWithError(err, "datafactory.ActivityRunsClient", "ListByPipelineRun", resp, "Failure responding to request")
103		return
104	}
105	if result.arlr.hasNextLink() && result.arlr.IsEmpty() {
106		err = result.NextWithContext(ctx)
107		return
108	}
109
110	return
111}
112
113// ListByPipelineRunPreparer prepares the ListByPipelineRun request.
114func (client ActivityRunsClient) ListByPipelineRunPreparer(ctx context.Context, resourceGroupName string, factoryName string, runID string, startTime date.Time, endTime date.Time, status string, activityName string, linkedServiceName string) (*http.Request, error) {
115	pathParameters := map[string]interface{}{
116		"factoryName":       autorest.Encode("path", factoryName),
117		"resourceGroupName": autorest.Encode("path", resourceGroupName),
118		"runId":             autorest.Encode("path", runID),
119		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
120	}
121
122	const APIVersion = "2017-09-01-preview"
123	queryParameters := map[string]interface{}{
124		"api-version": APIVersion,
125		"endTime":     autorest.Encode("query", endTime),
126		"startTime":   autorest.Encode("query", startTime),
127	}
128	if len(status) > 0 {
129		queryParameters["status"] = autorest.Encode("query", status)
130	}
131	if len(activityName) > 0 {
132		queryParameters["activityName"] = autorest.Encode("query", activityName)
133	}
134	if len(linkedServiceName) > 0 {
135		queryParameters["linkedServiceName"] = autorest.Encode("query", linkedServiceName)
136	}
137
138	preparer := autorest.CreatePreparer(
139		autorest.AsGet(),
140		autorest.WithBaseURL(client.BaseURI),
141		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns/{runId}/activityruns", pathParameters),
142		autorest.WithQueryParameters(queryParameters))
143	return preparer.Prepare((&http.Request{}).WithContext(ctx))
144}
145
146// ListByPipelineRunSender sends the ListByPipelineRun request. The method will close the
147// http.Response Body if it receives an error.
148func (client ActivityRunsClient) ListByPipelineRunSender(req *http.Request) (*http.Response, error) {
149	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
150}
151
152// ListByPipelineRunResponder handles the response to the ListByPipelineRun request. The method always
153// closes the http.Response Body.
154func (client ActivityRunsClient) ListByPipelineRunResponder(resp *http.Response) (result ActivityRunsListResponse, err error) {
155	err = autorest.Respond(
156		resp,
157		azure.WithErrorUnlessStatusCode(http.StatusOK),
158		autorest.ByUnmarshallingJSON(&result),
159		autorest.ByClosing())
160	result.Response = autorest.Response{Response: resp}
161	return
162}
163
164// listByPipelineRunNextResults retrieves the next set of results, if any.
165func (client ActivityRunsClient) listByPipelineRunNextResults(ctx context.Context, lastResults ActivityRunsListResponse) (result ActivityRunsListResponse, err error) {
166	req, err := lastResults.activityRunsListResponsePreparer(ctx)
167	if err != nil {
168		return result, autorest.NewErrorWithError(err, "datafactory.ActivityRunsClient", "listByPipelineRunNextResults", nil, "Failure preparing next results request")
169	}
170	if req == nil {
171		return
172	}
173	resp, err := client.ListByPipelineRunSender(req)
174	if err != nil {
175		result.Response = autorest.Response{Response: resp}
176		return result, autorest.NewErrorWithError(err, "datafactory.ActivityRunsClient", "listByPipelineRunNextResults", resp, "Failure sending next results request")
177	}
178	result, err = client.ListByPipelineRunResponder(resp)
179	if err != nil {
180		err = autorest.NewErrorWithError(err, "datafactory.ActivityRunsClient", "listByPipelineRunNextResults", resp, "Failure responding to next results request")
181	}
182	return
183}
184
185// ListByPipelineRunComplete enumerates all values, automatically crossing page boundaries as required.
186func (client ActivityRunsClient) ListByPipelineRunComplete(ctx context.Context, resourceGroupName string, factoryName string, runID string, startTime date.Time, endTime date.Time, status string, activityName string, linkedServiceName string) (result ActivityRunsListResponseIterator, err error) {
187	if tracing.IsEnabled() {
188		ctx = tracing.StartSpan(ctx, fqdn+"/ActivityRunsClient.ListByPipelineRun")
189		defer func() {
190			sc := -1
191			if result.Response().Response.Response != nil {
192				sc = result.page.Response().Response.Response.StatusCode
193			}
194			tracing.EndSpan(ctx, sc, err)
195		}()
196	}
197	result.page, err = client.ListByPipelineRun(ctx, resourceGroupName, factoryName, runID, startTime, endTime, status, activityName, linkedServiceName)
198	return
199}
200