1package compute
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// LogAnalyticsClient is the compute Client
19type LogAnalyticsClient struct {
20	BaseClient
21}
22
23// NewLogAnalyticsClient creates an instance of the LogAnalyticsClient client.
24func NewLogAnalyticsClient(subscriptionID string) LogAnalyticsClient {
25	return NewLogAnalyticsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewLogAnalyticsClientWithBaseURI creates an instance of the LogAnalyticsClient client using a custom endpoint.  Use
29// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewLogAnalyticsClientWithBaseURI(baseURI string, subscriptionID string) LogAnalyticsClient {
31	return LogAnalyticsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// ExportRequestRateByInterval export logs that show Api requests made by this subscription in the given time window to
35// show throttling activities.
36// Parameters:
37// parameters - parameters supplied to the LogAnalytics getRequestRateByInterval Api.
38// location - the location upon which virtual-machine-sizes is queried.
39func (client LogAnalyticsClient) ExportRequestRateByInterval(ctx context.Context, parameters RequestRateByIntervalInput, location string) (result LogAnalyticsExportRequestRateByIntervalFuture, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/LogAnalyticsClient.ExportRequestRateByInterval")
42		defer func() {
43			sc := -1
44			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
45				sc = result.FutureAPI.Response().StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	if err := validation.Validate([]validation.Validation{
51		{TargetValue: location,
52			Constraints: []validation.Constraint{{Target: "location", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
53		return result, validation.NewError("compute.LogAnalyticsClient", "ExportRequestRateByInterval", err.Error())
54	}
55
56	req, err := client.ExportRequestRateByIntervalPreparer(ctx, parameters, location)
57	if err != nil {
58		err = autorest.NewErrorWithError(err, "compute.LogAnalyticsClient", "ExportRequestRateByInterval", nil, "Failure preparing request")
59		return
60	}
61
62	result, err = client.ExportRequestRateByIntervalSender(req)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "compute.LogAnalyticsClient", "ExportRequestRateByInterval", nil, "Failure sending request")
65		return
66	}
67
68	return
69}
70
71// ExportRequestRateByIntervalPreparer prepares the ExportRequestRateByInterval request.
72func (client LogAnalyticsClient) ExportRequestRateByIntervalPreparer(ctx context.Context, parameters RequestRateByIntervalInput, location string) (*http.Request, error) {
73	pathParameters := map[string]interface{}{
74		"location":       autorest.Encode("path", location),
75		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
76	}
77
78	const APIVersion = "2018-10-01"
79	queryParameters := map[string]interface{}{
80		"api-version": APIVersion,
81	}
82
83	preparer := autorest.CreatePreparer(
84		autorest.AsContentType("application/json; charset=utf-8"),
85		autorest.AsPost(),
86		autorest.WithBaseURL(client.BaseURI),
87		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/logAnalytics/apiAccess/getRequestRateByInterval", pathParameters),
88		autorest.WithJSON(parameters),
89		autorest.WithQueryParameters(queryParameters))
90	return preparer.Prepare((&http.Request{}).WithContext(ctx))
91}
92
93// ExportRequestRateByIntervalSender sends the ExportRequestRateByInterval request. The method will close the
94// http.Response Body if it receives an error.
95func (client LogAnalyticsClient) ExportRequestRateByIntervalSender(req *http.Request) (future LogAnalyticsExportRequestRateByIntervalFuture, err error) {
96	var resp *http.Response
97	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
98	if err != nil {
99		return
100	}
101	var azf azure.Future
102	azf, err = azure.NewFutureFromResponse(resp)
103	future.FutureAPI = &azf
104	future.Result = future.result
105	return
106}
107
108// ExportRequestRateByIntervalResponder handles the response to the ExportRequestRateByInterval request. The method always
109// closes the http.Response Body.
110func (client LogAnalyticsClient) ExportRequestRateByIntervalResponder(resp *http.Response) (result LogAnalyticsOperationResult, err error) {
111	err = autorest.Respond(
112		resp,
113		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
114		autorest.ByUnmarshallingJSON(&result),
115		autorest.ByClosing())
116	result.Response = autorest.Response{Response: resp}
117	return
118}
119
120// ExportThrottledRequests export logs that show total throttled Api requests for this subscription in the given time
121// window.
122// Parameters:
123// parameters - parameters supplied to the LogAnalytics getThrottledRequests Api.
124// location - the location upon which virtual-machine-sizes is queried.
125func (client LogAnalyticsClient) ExportThrottledRequests(ctx context.Context, parameters ThrottledRequestsInput, location string) (result LogAnalyticsExportThrottledRequestsFuture, err error) {
126	if tracing.IsEnabled() {
127		ctx = tracing.StartSpan(ctx, fqdn+"/LogAnalyticsClient.ExportThrottledRequests")
128		defer func() {
129			sc := -1
130			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
131				sc = result.FutureAPI.Response().StatusCode
132			}
133			tracing.EndSpan(ctx, sc, err)
134		}()
135	}
136	if err := validation.Validate([]validation.Validation{
137		{TargetValue: location,
138			Constraints: []validation.Constraint{{Target: "location", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
139		return result, validation.NewError("compute.LogAnalyticsClient", "ExportThrottledRequests", err.Error())
140	}
141
142	req, err := client.ExportThrottledRequestsPreparer(ctx, parameters, location)
143	if err != nil {
144		err = autorest.NewErrorWithError(err, "compute.LogAnalyticsClient", "ExportThrottledRequests", nil, "Failure preparing request")
145		return
146	}
147
148	result, err = client.ExportThrottledRequestsSender(req)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "compute.LogAnalyticsClient", "ExportThrottledRequests", nil, "Failure sending request")
151		return
152	}
153
154	return
155}
156
157// ExportThrottledRequestsPreparer prepares the ExportThrottledRequests request.
158func (client LogAnalyticsClient) ExportThrottledRequestsPreparer(ctx context.Context, parameters ThrottledRequestsInput, location string) (*http.Request, error) {
159	pathParameters := map[string]interface{}{
160		"location":       autorest.Encode("path", location),
161		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
162	}
163
164	const APIVersion = "2018-10-01"
165	queryParameters := map[string]interface{}{
166		"api-version": APIVersion,
167	}
168
169	preparer := autorest.CreatePreparer(
170		autorest.AsContentType("application/json; charset=utf-8"),
171		autorest.AsPost(),
172		autorest.WithBaseURL(client.BaseURI),
173		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/logAnalytics/apiAccess/getThrottledRequests", pathParameters),
174		autorest.WithJSON(parameters),
175		autorest.WithQueryParameters(queryParameters))
176	return preparer.Prepare((&http.Request{}).WithContext(ctx))
177}
178
179// ExportThrottledRequestsSender sends the ExportThrottledRequests request. The method will close the
180// http.Response Body if it receives an error.
181func (client LogAnalyticsClient) ExportThrottledRequestsSender(req *http.Request) (future LogAnalyticsExportThrottledRequestsFuture, err error) {
182	var resp *http.Response
183	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
184	if err != nil {
185		return
186	}
187	var azf azure.Future
188	azf, err = azure.NewFutureFromResponse(resp)
189	future.FutureAPI = &azf
190	future.Result = future.result
191	return
192}
193
194// ExportThrottledRequestsResponder handles the response to the ExportThrottledRequests request. The method always
195// closes the http.Response Body.
196func (client LogAnalyticsClient) ExportThrottledRequestsResponder(resp *http.Response) (result LogAnalyticsOperationResult, err error) {
197	err = autorest.Respond(
198		resp,
199		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
200		autorest.ByUnmarshallingJSON(&result),
201		autorest.ByClosing())
202	result.Response = autorest.Response{Response: resp}
203	return
204}
205