1package hdinsight 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/tracing" 25 "net/http" 26) 27 28// ScriptExecutionHistoryClient is the hDInsight Management Client 29type ScriptExecutionHistoryClient struct { 30 BaseClient 31} 32 33// NewScriptExecutionHistoryClient creates an instance of the ScriptExecutionHistoryClient client. 34func NewScriptExecutionHistoryClient(subscriptionID string) ScriptExecutionHistoryClient { 35 return NewScriptExecutionHistoryClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewScriptExecutionHistoryClientWithBaseURI creates an instance of the ScriptExecutionHistoryClient client using a 39// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, 40// Azure stack). 41func NewScriptExecutionHistoryClientWithBaseURI(baseURI string, subscriptionID string) ScriptExecutionHistoryClient { 42 return ScriptExecutionHistoryClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// List lists all scripts' execution history for the specified cluster. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// clusterName - the name of the cluster. 49func (client ScriptExecutionHistoryClient) List(ctx context.Context, resourceGroupName string, clusterName string) (result ScriptActionExecutionHistoryListPage, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/ScriptExecutionHistoryClient.List") 52 defer func() { 53 sc := -1 54 if result.saehl.Response.Response != nil { 55 sc = result.saehl.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 result.fn = client.listNextResults 61 req, err := client.ListPreparer(ctx, resourceGroupName, clusterName) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "hdinsight.ScriptExecutionHistoryClient", "List", nil, "Failure preparing request") 64 return 65 } 66 67 resp, err := client.ListSender(req) 68 if err != nil { 69 result.saehl.Response = autorest.Response{Response: resp} 70 err = autorest.NewErrorWithError(err, "hdinsight.ScriptExecutionHistoryClient", "List", resp, "Failure sending request") 71 return 72 } 73 74 result.saehl, err = client.ListResponder(resp) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "hdinsight.ScriptExecutionHistoryClient", "List", resp, "Failure responding to request") 77 return 78 } 79 if result.saehl.hasNextLink() && result.saehl.IsEmpty() { 80 err = result.NextWithContext(ctx) 81 return 82 } 83 84 return 85} 86 87// ListPreparer prepares the List request. 88func (client ScriptExecutionHistoryClient) ListPreparer(ctx context.Context, resourceGroupName string, clusterName string) (*http.Request, error) { 89 pathParameters := map[string]interface{}{ 90 "clusterName": autorest.Encode("path", clusterName), 91 "resourceGroupName": autorest.Encode("path", resourceGroupName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 } 94 95 const APIVersion = "2015-03-01-preview" 96 queryParameters := map[string]interface{}{ 97 "api-version": APIVersion, 98 } 99 100 preparer := autorest.CreatePreparer( 101 autorest.AsGet(), 102 autorest.WithBaseURL(client.BaseURI), 103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/scriptExecutionHistory", pathParameters), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// ListSender sends the List request. The method will close the 109// http.Response Body if it receives an error. 110func (client ScriptExecutionHistoryClient) ListSender(req *http.Request) (*http.Response, error) { 111 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 112} 113 114// ListResponder handles the response to the List request. The method always 115// closes the http.Response Body. 116func (client ScriptExecutionHistoryClient) ListResponder(resp *http.Response) (result ScriptActionExecutionHistoryList, err error) { 117 err = autorest.Respond( 118 resp, 119 azure.WithErrorUnlessStatusCode(http.StatusOK), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// listNextResults retrieves the next set of results, if any. 127func (client ScriptExecutionHistoryClient) listNextResults(ctx context.Context, lastResults ScriptActionExecutionHistoryList) (result ScriptActionExecutionHistoryList, err error) { 128 req, err := lastResults.scriptActionExecutionHistoryListPreparer(ctx) 129 if err != nil { 130 return result, autorest.NewErrorWithError(err, "hdinsight.ScriptExecutionHistoryClient", "listNextResults", nil, "Failure preparing next results request") 131 } 132 if req == nil { 133 return 134 } 135 resp, err := client.ListSender(req) 136 if err != nil { 137 result.Response = autorest.Response{Response: resp} 138 return result, autorest.NewErrorWithError(err, "hdinsight.ScriptExecutionHistoryClient", "listNextResults", resp, "Failure sending next results request") 139 } 140 result, err = client.ListResponder(resp) 141 if err != nil { 142 err = autorest.NewErrorWithError(err, "hdinsight.ScriptExecutionHistoryClient", "listNextResults", resp, "Failure responding to next results request") 143 } 144 return 145} 146 147// ListComplete enumerates all values, automatically crossing page boundaries as required. 148func (client ScriptExecutionHistoryClient) ListComplete(ctx context.Context, resourceGroupName string, clusterName string) (result ScriptActionExecutionHistoryListIterator, err error) { 149 if tracing.IsEnabled() { 150 ctx = tracing.StartSpan(ctx, fqdn+"/ScriptExecutionHistoryClient.List") 151 defer func() { 152 sc := -1 153 if result.Response().Response.Response != nil { 154 sc = result.page.Response().Response.Response.StatusCode 155 } 156 tracing.EndSpan(ctx, sc, err) 157 }() 158 } 159 result.page, err = client.List(ctx, resourceGroupName, clusterName) 160 return 161} 162 163// Promote promotes the specified ad-hoc script execution to a persisted script. 164// Parameters: 165// resourceGroupName - the name of the resource group. 166// clusterName - the name of the cluster. 167// scriptExecutionID - the script execution Id 168func (client ScriptExecutionHistoryClient) Promote(ctx context.Context, resourceGroupName string, clusterName string, scriptExecutionID string) (result autorest.Response, err error) { 169 if tracing.IsEnabled() { 170 ctx = tracing.StartSpan(ctx, fqdn+"/ScriptExecutionHistoryClient.Promote") 171 defer func() { 172 sc := -1 173 if result.Response != nil { 174 sc = result.Response.StatusCode 175 } 176 tracing.EndSpan(ctx, sc, err) 177 }() 178 } 179 req, err := client.PromotePreparer(ctx, resourceGroupName, clusterName, scriptExecutionID) 180 if err != nil { 181 err = autorest.NewErrorWithError(err, "hdinsight.ScriptExecutionHistoryClient", "Promote", nil, "Failure preparing request") 182 return 183 } 184 185 resp, err := client.PromoteSender(req) 186 if err != nil { 187 result.Response = resp 188 err = autorest.NewErrorWithError(err, "hdinsight.ScriptExecutionHistoryClient", "Promote", resp, "Failure sending request") 189 return 190 } 191 192 result, err = client.PromoteResponder(resp) 193 if err != nil { 194 err = autorest.NewErrorWithError(err, "hdinsight.ScriptExecutionHistoryClient", "Promote", resp, "Failure responding to request") 195 return 196 } 197 198 return 199} 200 201// PromotePreparer prepares the Promote request. 202func (client ScriptExecutionHistoryClient) PromotePreparer(ctx context.Context, resourceGroupName string, clusterName string, scriptExecutionID string) (*http.Request, error) { 203 pathParameters := map[string]interface{}{ 204 "clusterName": autorest.Encode("path", clusterName), 205 "resourceGroupName": autorest.Encode("path", resourceGroupName), 206 "scriptExecutionId": autorest.Encode("path", scriptExecutionID), 207 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 208 } 209 210 const APIVersion = "2015-03-01-preview" 211 queryParameters := map[string]interface{}{ 212 "api-version": APIVersion, 213 } 214 215 preparer := autorest.CreatePreparer( 216 autorest.AsPost(), 217 autorest.WithBaseURL(client.BaseURI), 218 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/scriptExecutionHistory/{scriptExecutionId}/promote", pathParameters), 219 autorest.WithQueryParameters(queryParameters)) 220 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 221} 222 223// PromoteSender sends the Promote request. The method will close the 224// http.Response Body if it receives an error. 225func (client ScriptExecutionHistoryClient) PromoteSender(req *http.Request) (*http.Response, error) { 226 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 227} 228 229// PromoteResponder handles the response to the Promote request. The method always 230// closes the http.Response Body. 231func (client ScriptExecutionHistoryClient) PromoteResponder(resp *http.Response) (result autorest.Response, err error) { 232 err = autorest.Respond( 233 resp, 234 azure.WithErrorUnlessStatusCode(http.StatusOK), 235 autorest.ByClosing()) 236 result.Response = resp 237 return 238} 239