1package sql
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/tracing"
14	"net/http"
15)
16
17// ElasticPoolDatabaseActivitiesClient is the the Azure SQL Database management API provides a RESTful set of web
18// services that interact with Azure SQL Database services to manage your databases. The API enables you to create,
19// retrieve, update, and delete databases.
20type ElasticPoolDatabaseActivitiesClient struct {
21	BaseClient
22}
23
24// NewElasticPoolDatabaseActivitiesClient creates an instance of the ElasticPoolDatabaseActivitiesClient client.
25func NewElasticPoolDatabaseActivitiesClient(subscriptionID string) ElasticPoolDatabaseActivitiesClient {
26	return NewElasticPoolDatabaseActivitiesClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewElasticPoolDatabaseActivitiesClientWithBaseURI creates an instance of the ElasticPoolDatabaseActivitiesClient
30// client using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI
31// (sovereign clouds, Azure stack).
32func NewElasticPoolDatabaseActivitiesClientWithBaseURI(baseURI string, subscriptionID string) ElasticPoolDatabaseActivitiesClient {
33	return ElasticPoolDatabaseActivitiesClient{NewWithBaseURI(baseURI, subscriptionID)}
34}
35
36// ListByElasticPool returns activity on databases inside of an elastic pool.
37// Parameters:
38// resourceGroupName - the name of the resource group that contains the resource. You can obtain this value
39// from the Azure Resource Manager API or the portal.
40// serverName - the name of the server.
41// elasticPoolName - the name of the elastic pool.
42func (client ElasticPoolDatabaseActivitiesClient) ListByElasticPool(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (result ElasticPoolDatabaseActivityListResult, err error) {
43	if tracing.IsEnabled() {
44		ctx = tracing.StartSpan(ctx, fqdn+"/ElasticPoolDatabaseActivitiesClient.ListByElasticPool")
45		defer func() {
46			sc := -1
47			if result.Response.Response != nil {
48				sc = result.Response.Response.StatusCode
49			}
50			tracing.EndSpan(ctx, sc, err)
51		}()
52	}
53	req, err := client.ListByElasticPoolPreparer(ctx, resourceGroupName, serverName, elasticPoolName)
54	if err != nil {
55		err = autorest.NewErrorWithError(err, "sql.ElasticPoolDatabaseActivitiesClient", "ListByElasticPool", nil, "Failure preparing request")
56		return
57	}
58
59	resp, err := client.ListByElasticPoolSender(req)
60	if err != nil {
61		result.Response = autorest.Response{Response: resp}
62		err = autorest.NewErrorWithError(err, "sql.ElasticPoolDatabaseActivitiesClient", "ListByElasticPool", resp, "Failure sending request")
63		return
64	}
65
66	result, err = client.ListByElasticPoolResponder(resp)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "sql.ElasticPoolDatabaseActivitiesClient", "ListByElasticPool", resp, "Failure responding to request")
69		return
70	}
71
72	return
73}
74
75// ListByElasticPoolPreparer prepares the ListByElasticPool request.
76func (client ElasticPoolDatabaseActivitiesClient) ListByElasticPoolPreparer(ctx context.Context, resourceGroupName string, serverName string, elasticPoolName string) (*http.Request, error) {
77	pathParameters := map[string]interface{}{
78		"elasticPoolName":   autorest.Encode("path", elasticPoolName),
79		"resourceGroupName": autorest.Encode("path", resourceGroupName),
80		"serverName":        autorest.Encode("path", serverName),
81		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
82	}
83
84	const APIVersion = "2014-04-01"
85	queryParameters := map[string]interface{}{
86		"api-version": APIVersion,
87	}
88
89	preparer := autorest.CreatePreparer(
90		autorest.AsGet(),
91		autorest.WithBaseURL(client.BaseURI),
92		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/elasticPoolDatabaseActivity", pathParameters),
93		autorest.WithQueryParameters(queryParameters))
94	return preparer.Prepare((&http.Request{}).WithContext(ctx))
95}
96
97// ListByElasticPoolSender sends the ListByElasticPool request. The method will close the
98// http.Response Body if it receives an error.
99func (client ElasticPoolDatabaseActivitiesClient) ListByElasticPoolSender(req *http.Request) (*http.Response, error) {
100	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
101}
102
103// ListByElasticPoolResponder handles the response to the ListByElasticPool request. The method always
104// closes the http.Response Body.
105func (client ElasticPoolDatabaseActivitiesClient) ListByElasticPoolResponder(resp *http.Response) (result ElasticPoolDatabaseActivityListResult, err error) {
106	err = autorest.Respond(
107		resp,
108		azure.WithErrorUnlessStatusCode(http.StatusOK),
109		autorest.ByUnmarshallingJSON(&result),
110		autorest.ByClosing())
111	result.Response = autorest.Response{Response: resp}
112	return
113}
114