1package workloadmonitor 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// MonitorInstancesSummaryClient is the aPIs for workload monitoring 30type MonitorInstancesSummaryClient struct { 31 BaseClient 32} 33 34// NewMonitorInstancesSummaryClient creates an instance of the MonitorInstancesSummaryClient client. 35func NewMonitorInstancesSummaryClient(subscriptionID string) MonitorInstancesSummaryClient { 36 return NewMonitorInstancesSummaryClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewMonitorInstancesSummaryClientWithBaseURI creates an instance of the MonitorInstancesSummaryClient client. 40func NewMonitorInstancesSummaryClientWithBaseURI(baseURI string, subscriptionID string) MonitorInstancesSummaryClient { 41 return MonitorInstancesSummaryClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// List sends the list request. 45// Parameters: 46// selectParameter - properties to be returned in the response. 47// filter - filter to be applied on the operation. 48// apply - apply aggregation. 49// orderby - sort the result on one or more properties. 50// expand - include properties inline in the response. 51// top - limit the result to the specified number of rows. 52// skiptoken - the page-continuation token to use with a paged version of this API. 53func (client MonitorInstancesSummaryClient) List(ctx context.Context, selectParameter string, filter string, apply string, orderby string, expand string, top string, skiptoken string) (result MonitorInstancesCollectionPage, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/MonitorInstancesSummaryClient.List") 56 defer func() { 57 sc := -1 58 if result.mic.Response.Response != nil { 59 sc = result.mic.Response.Response.StatusCode 60 } 61 tracing.EndSpan(ctx, sc, err) 62 }() 63 } 64 if err := validation.Validate([]validation.Validation{ 65 {TargetValue: client.SubscriptionID, 66 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil { 67 return result, validation.NewError("workloadmonitor.MonitorInstancesSummaryClient", "List", err.Error()) 68 } 69 70 result.fn = client.listNextResults 71 req, err := client.ListPreparer(ctx, selectParameter, filter, apply, orderby, expand, top, skiptoken) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorInstancesSummaryClient", "List", nil, "Failure preparing request") 74 return 75 } 76 77 resp, err := client.ListSender(req) 78 if err != nil { 79 result.mic.Response = autorest.Response{Response: resp} 80 err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorInstancesSummaryClient", "List", resp, "Failure sending request") 81 return 82 } 83 84 result.mic, err = client.ListResponder(resp) 85 if err != nil { 86 err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorInstancesSummaryClient", "List", resp, "Failure responding to request") 87 } 88 89 return 90} 91 92// ListPreparer prepares the List request. 93func (client MonitorInstancesSummaryClient) ListPreparer(ctx context.Context, selectParameter string, filter string, apply string, orderby string, expand string, top string, skiptoken string) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 96 } 97 98 const APIVersion = "2018-08-31-preview" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 if len(selectParameter) > 0 { 103 queryParameters["$select"] = autorest.Encode("query", selectParameter) 104 } 105 if len(filter) > 0 { 106 queryParameters["$filter"] = autorest.Encode("query", filter) 107 } 108 if len(apply) > 0 { 109 queryParameters["$apply"] = autorest.Encode("query", apply) 110 } 111 if len(orderby) > 0 { 112 queryParameters["$orderby"] = autorest.Encode("query", orderby) 113 } 114 if len(expand) > 0 { 115 queryParameters["$expand"] = autorest.Encode("query", expand) 116 } 117 if len(top) > 0 { 118 queryParameters["$top"] = autorest.Encode("query", top) 119 } 120 if len(skiptoken) > 0 { 121 queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) 122 } 123 124 preparer := autorest.CreatePreparer( 125 autorest.AsGet(), 126 autorest.WithBaseURL(client.BaseURI), 127 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.WorkloadMonitor/monitorInstancesSummary", pathParameters), 128 autorest.WithQueryParameters(queryParameters)) 129 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 130} 131 132// ListSender sends the List request. The method will close the 133// http.Response Body if it receives an error. 134func (client MonitorInstancesSummaryClient) ListSender(req *http.Request) (*http.Response, error) { 135 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 136 return autorest.SendWithSender(client, req, sd...) 137} 138 139// ListResponder handles the response to the List request. The method always 140// closes the http.Response Body. 141func (client MonitorInstancesSummaryClient) ListResponder(resp *http.Response) (result MonitorInstancesCollection, err error) { 142 err = autorest.Respond( 143 resp, 144 client.ByInspecting(), 145 azure.WithErrorUnlessStatusCode(http.StatusOK), 146 autorest.ByUnmarshallingJSON(&result), 147 autorest.ByClosing()) 148 result.Response = autorest.Response{Response: resp} 149 return 150} 151 152// listNextResults retrieves the next set of results, if any. 153func (client MonitorInstancesSummaryClient) listNextResults(ctx context.Context, lastResults MonitorInstancesCollection) (result MonitorInstancesCollection, err error) { 154 req, err := lastResults.monitorInstancesCollectionPreparer(ctx) 155 if err != nil { 156 return result, autorest.NewErrorWithError(err, "workloadmonitor.MonitorInstancesSummaryClient", "listNextResults", nil, "Failure preparing next results request") 157 } 158 if req == nil { 159 return 160 } 161 resp, err := client.ListSender(req) 162 if err != nil { 163 result.Response = autorest.Response{Response: resp} 164 return result, autorest.NewErrorWithError(err, "workloadmonitor.MonitorInstancesSummaryClient", "listNextResults", resp, "Failure sending next results request") 165 } 166 result, err = client.ListResponder(resp) 167 if err != nil { 168 err = autorest.NewErrorWithError(err, "workloadmonitor.MonitorInstancesSummaryClient", "listNextResults", resp, "Failure responding to next results request") 169 } 170 return 171} 172 173// ListComplete enumerates all values, automatically crossing page boundaries as required. 174func (client MonitorInstancesSummaryClient) ListComplete(ctx context.Context, selectParameter string, filter string, apply string, orderby string, expand string, top string, skiptoken string) (result MonitorInstancesCollectionIterator, err error) { 175 if tracing.IsEnabled() { 176 ctx = tracing.StartSpan(ctx, fqdn+"/MonitorInstancesSummaryClient.List") 177 defer func() { 178 sc := -1 179 if result.Response().Response.Response != nil { 180 sc = result.page.Response().Response.Response.StatusCode 181 } 182 tracing.EndSpan(ctx, sc, err) 183 }() 184 } 185 result.page, err = client.List(ctx, selectParameter, filter, apply, orderby, expand, top, skiptoken) 186 return 187} 188