...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/machinelearning/mgmt/2016-05-01-preview/commitmentplans/commitmentassociations.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/machinelearning/mgmt/2016-05-01-preview/commitmentplans

     1  package commitmentplans
     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  
     9  import (
    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  // CommitmentAssociationsClient is the these APIs allow end users to operate on Azure Machine Learning Commitment Plans
    18  // resources and their child Commitment Association resources. They support CRUD operations for commitment plans, get
    19  // and list operations for commitment associations, moving commitment associations between commitment plans, and
    20  // retrieving commitment plan usage history.
    21  type CommitmentAssociationsClient struct {
    22  	BaseClient
    23  }
    24  
    25  // NewCommitmentAssociationsClient creates an instance of the CommitmentAssociationsClient client.
    26  func NewCommitmentAssociationsClient(subscriptionID string) CommitmentAssociationsClient {
    27  	return NewCommitmentAssociationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    28  }
    29  
    30  // NewCommitmentAssociationsClientWithBaseURI creates an instance of the CommitmentAssociationsClient client using a
    31  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    32  // Azure stack).
    33  func NewCommitmentAssociationsClientWithBaseURI(baseURI string, subscriptionID string) CommitmentAssociationsClient {
    34  	return CommitmentAssociationsClient{NewWithBaseURI(baseURI, subscriptionID)}
    35  }
    36  
    37  // Get get a commitment association.
    38  // Parameters:
    39  // resourceGroupName - the resource group name.
    40  // commitmentPlanName - the Azure ML commitment plan name.
    41  // commitmentAssociationName - the commitment association name.
    42  func (client CommitmentAssociationsClient) Get(ctx context.Context, resourceGroupName string, commitmentPlanName string, commitmentAssociationName string) (result CommitmentAssociation, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/CommitmentAssociationsClient.Get")
    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.GetPreparer(ctx, resourceGroupName, commitmentPlanName, commitmentAssociationName)
    54  	if err != nil {
    55  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "Get", nil, "Failure preparing request")
    56  		return
    57  	}
    58  
    59  	resp, err := client.GetSender(req)
    60  	if err != nil {
    61  		result.Response = autorest.Response{Response: resp}
    62  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "Get", resp, "Failure sending request")
    63  		return
    64  	}
    65  
    66  	result, err = client.GetResponder(resp)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "Get", resp, "Failure responding to request")
    69  		return
    70  	}
    71  
    72  	return
    73  }
    74  
    75  // GetPreparer prepares the Get request.
    76  func (client CommitmentAssociationsClient) GetPreparer(ctx context.Context, resourceGroupName string, commitmentPlanName string, commitmentAssociationName string) (*http.Request, error) {
    77  	pathParameters := map[string]interface{}{
    78  		"commitmentAssociationName": autorest.Encode("path", commitmentAssociationName),
    79  		"commitmentPlanName":        autorest.Encode("path", commitmentPlanName),
    80  		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
    81  		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
    82  	}
    83  
    84  	const APIVersion = "2016-05-01-preview"
    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.MachineLearning/commitmentPlans/{commitmentPlanName}/commitmentAssociations/{commitmentAssociationName}", pathParameters),
    93  		autorest.WithQueryParameters(queryParameters))
    94  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    95  }
    96  
    97  // GetSender sends the Get request. The method will close the
    98  // http.Response Body if it receives an error.
    99  func (client CommitmentAssociationsClient) GetSender(req *http.Request) (*http.Response, error) {
   100  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   101  }
   102  
   103  // GetResponder handles the response to the Get request. The method always
   104  // closes the http.Response Body.
   105  func (client CommitmentAssociationsClient) GetResponder(resp *http.Response) (result CommitmentAssociation, 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  
   115  // List get all commitment associations for a parent commitment plan.
   116  // Parameters:
   117  // resourceGroupName - the resource group name.
   118  // commitmentPlanName - the Azure ML commitment plan name.
   119  // skipToken - continuation token for pagination.
   120  func (client CommitmentAssociationsClient) List(ctx context.Context, resourceGroupName string, commitmentPlanName string, skipToken string) (result CommitmentAssociationListResultPage, err error) {
   121  	if tracing.IsEnabled() {
   122  		ctx = tracing.StartSpan(ctx, fqdn+"/CommitmentAssociationsClient.List")
   123  		defer func() {
   124  			sc := -1
   125  			if result.calr.Response.Response != nil {
   126  				sc = result.calr.Response.Response.StatusCode
   127  			}
   128  			tracing.EndSpan(ctx, sc, err)
   129  		}()
   130  	}
   131  	result.fn = client.listNextResults
   132  	req, err := client.ListPreparer(ctx, resourceGroupName, commitmentPlanName, skipToken)
   133  	if err != nil {
   134  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "List", nil, "Failure preparing request")
   135  		return
   136  	}
   137  
   138  	resp, err := client.ListSender(req)
   139  	if err != nil {
   140  		result.calr.Response = autorest.Response{Response: resp}
   141  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "List", resp, "Failure sending request")
   142  		return
   143  	}
   144  
   145  	result.calr, err = client.ListResponder(resp)
   146  	if err != nil {
   147  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "List", resp, "Failure responding to request")
   148  		return
   149  	}
   150  	if result.calr.hasNextLink() && result.calr.IsEmpty() {
   151  		err = result.NextWithContext(ctx)
   152  		return
   153  	}
   154  
   155  	return
   156  }
   157  
   158  // ListPreparer prepares the List request.
   159  func (client CommitmentAssociationsClient) ListPreparer(ctx context.Context, resourceGroupName string, commitmentPlanName string, skipToken string) (*http.Request, error) {
   160  	pathParameters := map[string]interface{}{
   161  		"commitmentPlanName": autorest.Encode("path", commitmentPlanName),
   162  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   163  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   164  	}
   165  
   166  	const APIVersion = "2016-05-01-preview"
   167  	queryParameters := map[string]interface{}{
   168  		"api-version": APIVersion,
   169  	}
   170  	if len(skipToken) > 0 {
   171  		queryParameters["$skipToken"] = autorest.Encode("query", skipToken)
   172  	}
   173  
   174  	preparer := autorest.CreatePreparer(
   175  		autorest.AsGet(),
   176  		autorest.WithBaseURL(client.BaseURI),
   177  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearning/commitmentPlans/{commitmentPlanName}/commitmentAssociations", pathParameters),
   178  		autorest.WithQueryParameters(queryParameters))
   179  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   180  }
   181  
   182  // ListSender sends the List request. The method will close the
   183  // http.Response Body if it receives an error.
   184  func (client CommitmentAssociationsClient) ListSender(req *http.Request) (*http.Response, error) {
   185  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   186  }
   187  
   188  // ListResponder handles the response to the List request. The method always
   189  // closes the http.Response Body.
   190  func (client CommitmentAssociationsClient) ListResponder(resp *http.Response) (result CommitmentAssociationListResult, err error) {
   191  	err = autorest.Respond(
   192  		resp,
   193  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   194  		autorest.ByUnmarshallingJSON(&result),
   195  		autorest.ByClosing())
   196  	result.Response = autorest.Response{Response: resp}
   197  	return
   198  }
   199  
   200  // listNextResults retrieves the next set of results, if any.
   201  func (client CommitmentAssociationsClient) listNextResults(ctx context.Context, lastResults CommitmentAssociationListResult) (result CommitmentAssociationListResult, err error) {
   202  	req, err := lastResults.commitmentAssociationListResultPreparer(ctx)
   203  	if err != nil {
   204  		return result, autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "listNextResults", nil, "Failure preparing next results request")
   205  	}
   206  	if req == nil {
   207  		return
   208  	}
   209  	resp, err := client.ListSender(req)
   210  	if err != nil {
   211  		result.Response = autorest.Response{Response: resp}
   212  		return result, autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "listNextResults", resp, "Failure sending next results request")
   213  	}
   214  	result, err = client.ListResponder(resp)
   215  	if err != nil {
   216  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "listNextResults", resp, "Failure responding to next results request")
   217  	}
   218  	return
   219  }
   220  
   221  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   222  func (client CommitmentAssociationsClient) ListComplete(ctx context.Context, resourceGroupName string, commitmentPlanName string, skipToken string) (result CommitmentAssociationListResultIterator, err error) {
   223  	if tracing.IsEnabled() {
   224  		ctx = tracing.StartSpan(ctx, fqdn+"/CommitmentAssociationsClient.List")
   225  		defer func() {
   226  			sc := -1
   227  			if result.Response().Response.Response != nil {
   228  				sc = result.page.Response().Response.Response.StatusCode
   229  			}
   230  			tracing.EndSpan(ctx, sc, err)
   231  		}()
   232  	}
   233  	result.page, err = client.List(ctx, resourceGroupName, commitmentPlanName, skipToken)
   234  	return
   235  }
   236  
   237  // Move re-parent a commitment association from one commitment plan to another.
   238  // Parameters:
   239  // resourceGroupName - the resource group name.
   240  // commitmentPlanName - the Azure ML commitment plan name.
   241  // commitmentAssociationName - the commitment association name.
   242  // movePayload - the move request payload.
   243  func (client CommitmentAssociationsClient) Move(ctx context.Context, resourceGroupName string, commitmentPlanName string, commitmentAssociationName string, movePayload MoveCommitmentAssociationRequest) (result CommitmentAssociation, err error) {
   244  	if tracing.IsEnabled() {
   245  		ctx = tracing.StartSpan(ctx, fqdn+"/CommitmentAssociationsClient.Move")
   246  		defer func() {
   247  			sc := -1
   248  			if result.Response.Response != nil {
   249  				sc = result.Response.Response.StatusCode
   250  			}
   251  			tracing.EndSpan(ctx, sc, err)
   252  		}()
   253  	}
   254  	req, err := client.MovePreparer(ctx, resourceGroupName, commitmentPlanName, commitmentAssociationName, movePayload)
   255  	if err != nil {
   256  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "Move", nil, "Failure preparing request")
   257  		return
   258  	}
   259  
   260  	resp, err := client.MoveSender(req)
   261  	if err != nil {
   262  		result.Response = autorest.Response{Response: resp}
   263  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "Move", resp, "Failure sending request")
   264  		return
   265  	}
   266  
   267  	result, err = client.MoveResponder(resp)
   268  	if err != nil {
   269  		err = autorest.NewErrorWithError(err, "commitmentplans.CommitmentAssociationsClient", "Move", resp, "Failure responding to request")
   270  		return
   271  	}
   272  
   273  	return
   274  }
   275  
   276  // MovePreparer prepares the Move request.
   277  func (client CommitmentAssociationsClient) MovePreparer(ctx context.Context, resourceGroupName string, commitmentPlanName string, commitmentAssociationName string, movePayload MoveCommitmentAssociationRequest) (*http.Request, error) {
   278  	pathParameters := map[string]interface{}{
   279  		"commitmentAssociationName": autorest.Encode("path", commitmentAssociationName),
   280  		"commitmentPlanName":        autorest.Encode("path", commitmentPlanName),
   281  		"resourceGroupName":         autorest.Encode("path", resourceGroupName),
   282  		"subscriptionId":            autorest.Encode("path", client.SubscriptionID),
   283  	}
   284  
   285  	const APIVersion = "2016-05-01-preview"
   286  	queryParameters := map[string]interface{}{
   287  		"api-version": APIVersion,
   288  	}
   289  
   290  	preparer := autorest.CreatePreparer(
   291  		autorest.AsContentType("application/json; charset=utf-8"),
   292  		autorest.AsPost(),
   293  		autorest.WithBaseURL(client.BaseURI),
   294  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearning/commitmentPlans/{commitmentPlanName}/commitmentAssociations/{commitmentAssociationName}/move", pathParameters),
   295  		autorest.WithJSON(movePayload),
   296  		autorest.WithQueryParameters(queryParameters))
   297  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   298  }
   299  
   300  // MoveSender sends the Move request. The method will close the
   301  // http.Response Body if it receives an error.
   302  func (client CommitmentAssociationsClient) MoveSender(req *http.Request) (*http.Response, error) {
   303  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   304  }
   305  
   306  // MoveResponder handles the response to the Move request. The method always
   307  // closes the http.Response Body.
   308  func (client CommitmentAssociationsClient) MoveResponder(resp *http.Response) (result CommitmentAssociation, err error) {
   309  	err = autorest.Respond(
   310  		resp,
   311  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   312  		autorest.ByUnmarshallingJSON(&result),
   313  		autorest.ByClosing())
   314  	result.Response = autorest.Response{Response: resp}
   315  	return
   316  }
   317  

View as plain text