...

Source file src/github.com/Azure/azure-sdk-for-go/services/hybriddatamanager/mgmt/2019-06-01/hybriddata/jobs.go

Documentation: github.com/Azure/azure-sdk-for-go/services/hybriddatamanager/mgmt/2019-06-01/hybriddata

     1  package hybriddata
     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/autorest/validation"
    14  	"github.com/Azure/go-autorest/tracing"
    15  	"net/http"
    16  )
    17  
    18  // JobsClient is the client for the Jobs methods of the Hybriddata service.
    19  type JobsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewJobsClient creates an instance of the JobsClient client.
    24  func NewJobsClient(subscriptionID string) JobsClient {
    25  	return NewJobsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewJobsClientWithBaseURI creates an instance of the JobsClient client using a custom endpoint.  Use this when
    29  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    30  func NewJobsClientWithBaseURI(baseURI string, subscriptionID string) JobsClient {
    31  	return JobsClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Cancel cancels the given job.
    35  // Parameters:
    36  // dataServiceName - the name of the data service of the job definition.
    37  // jobDefinitionName - the name of the job definition of the job.
    38  // jobID - the job id of the job queried.
    39  // resourceGroupName - the Resource Group Name
    40  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
    41  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
    42  func (client JobsClient) Cancel(ctx context.Context, dataServiceName string, jobDefinitionName string, jobID string, resourceGroupName string, dataManagerName string) (result JobsCancelFuture, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Cancel")
    45  		defer func() {
    46  			sc := -1
    47  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    48  				sc = result.FutureAPI.Response().StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	if err := validation.Validate([]validation.Validation{
    54  		{TargetValue: dataManagerName,
    55  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
    56  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
    57  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
    58  		return result, validation.NewError("hybriddata.JobsClient", "Cancel", err.Error())
    59  	}
    60  
    61  	req, err := client.CancelPreparer(ctx, dataServiceName, jobDefinitionName, jobID, resourceGroupName, dataManagerName)
    62  	if err != nil {
    63  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "Cancel", nil, "Failure preparing request")
    64  		return
    65  	}
    66  
    67  	result, err = client.CancelSender(req)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "Cancel", result.Response(), "Failure sending request")
    70  		return
    71  	}
    72  
    73  	return
    74  }
    75  
    76  // CancelPreparer prepares the Cancel request.
    77  func (client JobsClient) CancelPreparer(ctx context.Context, dataServiceName string, jobDefinitionName string, jobID string, resourceGroupName string, dataManagerName string) (*http.Request, error) {
    78  	pathParameters := map[string]interface{}{
    79  		"dataManagerName":   autorest.Encode("path", dataManagerName),
    80  		"dataServiceName":   autorest.Encode("path", dataServiceName),
    81  		"jobDefinitionName": autorest.Encode("path", jobDefinitionName),
    82  		"jobId":             autorest.Encode("path", jobID),
    83  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    84  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    85  	}
    86  
    87  	const APIVersion = "2019-06-01"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  
    92  	preparer := autorest.CreatePreparer(
    93  		autorest.AsPost(),
    94  		autorest.WithBaseURL(client.BaseURI),
    95  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/dataServices/{dataServiceName}/jobDefinitions/{jobDefinitionName}/jobs/{jobId}/cancel", pathParameters),
    96  		autorest.WithQueryParameters(queryParameters))
    97  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    98  }
    99  
   100  // CancelSender sends the Cancel request. The method will close the
   101  // http.Response Body if it receives an error.
   102  func (client JobsClient) CancelSender(req *http.Request) (future JobsCancelFuture, err error) {
   103  	var resp *http.Response
   104  	future.FutureAPI = &azure.Future{}
   105  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   106  	if err != nil {
   107  		return
   108  	}
   109  	var azf azure.Future
   110  	azf, err = azure.NewFutureFromResponse(resp)
   111  	future.FutureAPI = &azf
   112  	future.Result = future.result
   113  	return
   114  }
   115  
   116  // CancelResponder handles the response to the Cancel request. The method always
   117  // closes the http.Response Body.
   118  func (client JobsClient) CancelResponder(resp *http.Response) (result autorest.Response, err error) {
   119  	err = autorest.Respond(
   120  		resp,
   121  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   122  		autorest.ByClosing())
   123  	result.Response = resp
   124  	return
   125  }
   126  
   127  // Get this method gets a data manager job given the jobId.
   128  // Parameters:
   129  // dataServiceName - the name of the data service of the job definition.
   130  // jobDefinitionName - the name of the job definition of the job.
   131  // jobID - the job id of the job queried.
   132  // resourceGroupName - the Resource Group Name
   133  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
   134  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
   135  // expand - $expand is supported on details parameter for job, which provides details on the job stages.
   136  func (client JobsClient) Get(ctx context.Context, dataServiceName string, jobDefinitionName string, jobID string, resourceGroupName string, dataManagerName string, expand string) (result Job, err error) {
   137  	if tracing.IsEnabled() {
   138  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Get")
   139  		defer func() {
   140  			sc := -1
   141  			if result.Response.Response != nil {
   142  				sc = result.Response.Response.StatusCode
   143  			}
   144  			tracing.EndSpan(ctx, sc, err)
   145  		}()
   146  	}
   147  	if err := validation.Validate([]validation.Validation{
   148  		{TargetValue: dataManagerName,
   149  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   150  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
   151  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
   152  		return result, validation.NewError("hybriddata.JobsClient", "Get", err.Error())
   153  	}
   154  
   155  	req, err := client.GetPreparer(ctx, dataServiceName, jobDefinitionName, jobID, resourceGroupName, dataManagerName, expand)
   156  	if err != nil {
   157  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "Get", nil, "Failure preparing request")
   158  		return
   159  	}
   160  
   161  	resp, err := client.GetSender(req)
   162  	if err != nil {
   163  		result.Response = autorest.Response{Response: resp}
   164  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "Get", resp, "Failure sending request")
   165  		return
   166  	}
   167  
   168  	result, err = client.GetResponder(resp)
   169  	if err != nil {
   170  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "Get", resp, "Failure responding to request")
   171  		return
   172  	}
   173  
   174  	return
   175  }
   176  
   177  // GetPreparer prepares the Get request.
   178  func (client JobsClient) GetPreparer(ctx context.Context, dataServiceName string, jobDefinitionName string, jobID string, resourceGroupName string, dataManagerName string, expand string) (*http.Request, error) {
   179  	pathParameters := map[string]interface{}{
   180  		"dataManagerName":   autorest.Encode("path", dataManagerName),
   181  		"dataServiceName":   autorest.Encode("path", dataServiceName),
   182  		"jobDefinitionName": autorest.Encode("path", jobDefinitionName),
   183  		"jobId":             autorest.Encode("path", jobID),
   184  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   185  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   186  	}
   187  
   188  	const APIVersion = "2019-06-01"
   189  	queryParameters := map[string]interface{}{
   190  		"api-version": APIVersion,
   191  	}
   192  	if len(expand) > 0 {
   193  		queryParameters["$expand"] = autorest.Encode("query", expand)
   194  	}
   195  
   196  	preparer := autorest.CreatePreparer(
   197  		autorest.AsGet(),
   198  		autorest.WithBaseURL(client.BaseURI),
   199  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/dataServices/{dataServiceName}/jobDefinitions/{jobDefinitionName}/jobs/{jobId}", pathParameters),
   200  		autorest.WithQueryParameters(queryParameters))
   201  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   202  }
   203  
   204  // GetSender sends the Get request. The method will close the
   205  // http.Response Body if it receives an error.
   206  func (client JobsClient) GetSender(req *http.Request) (*http.Response, error) {
   207  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   208  }
   209  
   210  // GetResponder handles the response to the Get request. The method always
   211  // closes the http.Response Body.
   212  func (client JobsClient) GetResponder(resp *http.Response) (result Job, err error) {
   213  	err = autorest.Respond(
   214  		resp,
   215  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   216  		autorest.ByUnmarshallingJSON(&result),
   217  		autorest.ByClosing())
   218  	result.Response = autorest.Response{Response: resp}
   219  	return
   220  }
   221  
   222  // ListByDataManager this method gets all the jobs at the data manager resource level.
   223  // Parameters:
   224  // resourceGroupName - the Resource Group Name
   225  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
   226  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
   227  // filter - oData Filter options
   228  func (client JobsClient) ListByDataManager(ctx context.Context, resourceGroupName string, dataManagerName string, filter string) (result JobListPage, err error) {
   229  	if tracing.IsEnabled() {
   230  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByDataManager")
   231  		defer func() {
   232  			sc := -1
   233  			if result.jl.Response.Response != nil {
   234  				sc = result.jl.Response.Response.StatusCode
   235  			}
   236  			tracing.EndSpan(ctx, sc, err)
   237  		}()
   238  	}
   239  	if err := validation.Validate([]validation.Validation{
   240  		{TargetValue: dataManagerName,
   241  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   242  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
   243  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
   244  		return result, validation.NewError("hybriddata.JobsClient", "ListByDataManager", err.Error())
   245  	}
   246  
   247  	result.fn = client.listByDataManagerNextResults
   248  	req, err := client.ListByDataManagerPreparer(ctx, resourceGroupName, dataManagerName, filter)
   249  	if err != nil {
   250  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "ListByDataManager", nil, "Failure preparing request")
   251  		return
   252  	}
   253  
   254  	resp, err := client.ListByDataManagerSender(req)
   255  	if err != nil {
   256  		result.jl.Response = autorest.Response{Response: resp}
   257  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "ListByDataManager", resp, "Failure sending request")
   258  		return
   259  	}
   260  
   261  	result.jl, err = client.ListByDataManagerResponder(resp)
   262  	if err != nil {
   263  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "ListByDataManager", resp, "Failure responding to request")
   264  		return
   265  	}
   266  	if result.jl.hasNextLink() && result.jl.IsEmpty() {
   267  		err = result.NextWithContext(ctx)
   268  		return
   269  	}
   270  
   271  	return
   272  }
   273  
   274  // ListByDataManagerPreparer prepares the ListByDataManager request.
   275  func (client JobsClient) ListByDataManagerPreparer(ctx context.Context, resourceGroupName string, dataManagerName string, filter string) (*http.Request, error) {
   276  	pathParameters := map[string]interface{}{
   277  		"dataManagerName":   autorest.Encode("path", dataManagerName),
   278  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   279  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   280  	}
   281  
   282  	const APIVersion = "2019-06-01"
   283  	queryParameters := map[string]interface{}{
   284  		"api-version": APIVersion,
   285  	}
   286  	if len(filter) > 0 {
   287  		queryParameters["$filter"] = autorest.Encode("query", filter)
   288  	}
   289  
   290  	preparer := autorest.CreatePreparer(
   291  		autorest.AsGet(),
   292  		autorest.WithBaseURL(client.BaseURI),
   293  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/jobs", pathParameters),
   294  		autorest.WithQueryParameters(queryParameters))
   295  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   296  }
   297  
   298  // ListByDataManagerSender sends the ListByDataManager request. The method will close the
   299  // http.Response Body if it receives an error.
   300  func (client JobsClient) ListByDataManagerSender(req *http.Request) (*http.Response, error) {
   301  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   302  }
   303  
   304  // ListByDataManagerResponder handles the response to the ListByDataManager request. The method always
   305  // closes the http.Response Body.
   306  func (client JobsClient) ListByDataManagerResponder(resp *http.Response) (result JobList, err error) {
   307  	err = autorest.Respond(
   308  		resp,
   309  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   310  		autorest.ByUnmarshallingJSON(&result),
   311  		autorest.ByClosing())
   312  	result.Response = autorest.Response{Response: resp}
   313  	return
   314  }
   315  
   316  // listByDataManagerNextResults retrieves the next set of results, if any.
   317  func (client JobsClient) listByDataManagerNextResults(ctx context.Context, lastResults JobList) (result JobList, err error) {
   318  	req, err := lastResults.jobListPreparer(ctx)
   319  	if err != nil {
   320  		return result, autorest.NewErrorWithError(err, "hybriddata.JobsClient", "listByDataManagerNextResults", nil, "Failure preparing next results request")
   321  	}
   322  	if req == nil {
   323  		return
   324  	}
   325  	resp, err := client.ListByDataManagerSender(req)
   326  	if err != nil {
   327  		result.Response = autorest.Response{Response: resp}
   328  		return result, autorest.NewErrorWithError(err, "hybriddata.JobsClient", "listByDataManagerNextResults", resp, "Failure sending next results request")
   329  	}
   330  	result, err = client.ListByDataManagerResponder(resp)
   331  	if err != nil {
   332  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "listByDataManagerNextResults", resp, "Failure responding to next results request")
   333  	}
   334  	return
   335  }
   336  
   337  // ListByDataManagerComplete enumerates all values, automatically crossing page boundaries as required.
   338  func (client JobsClient) ListByDataManagerComplete(ctx context.Context, resourceGroupName string, dataManagerName string, filter string) (result JobListIterator, err error) {
   339  	if tracing.IsEnabled() {
   340  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByDataManager")
   341  		defer func() {
   342  			sc := -1
   343  			if result.Response().Response.Response != nil {
   344  				sc = result.page.Response().Response.Response.StatusCode
   345  			}
   346  			tracing.EndSpan(ctx, sc, err)
   347  		}()
   348  	}
   349  	result.page, err = client.ListByDataManager(ctx, resourceGroupName, dataManagerName, filter)
   350  	return
   351  }
   352  
   353  // ListByDataService this method gets all the jobs of a data service type in a given resource.
   354  // Parameters:
   355  // dataServiceName - the name of the data service of interest.
   356  // resourceGroupName - the Resource Group Name
   357  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
   358  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
   359  // filter - oData Filter options
   360  func (client JobsClient) ListByDataService(ctx context.Context, dataServiceName string, resourceGroupName string, dataManagerName string, filter string) (result JobListPage, err error) {
   361  	if tracing.IsEnabled() {
   362  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByDataService")
   363  		defer func() {
   364  			sc := -1
   365  			if result.jl.Response.Response != nil {
   366  				sc = result.jl.Response.Response.StatusCode
   367  			}
   368  			tracing.EndSpan(ctx, sc, err)
   369  		}()
   370  	}
   371  	if err := validation.Validate([]validation.Validation{
   372  		{TargetValue: dataManagerName,
   373  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   374  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
   375  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
   376  		return result, validation.NewError("hybriddata.JobsClient", "ListByDataService", err.Error())
   377  	}
   378  
   379  	result.fn = client.listByDataServiceNextResults
   380  	req, err := client.ListByDataServicePreparer(ctx, dataServiceName, resourceGroupName, dataManagerName, filter)
   381  	if err != nil {
   382  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "ListByDataService", nil, "Failure preparing request")
   383  		return
   384  	}
   385  
   386  	resp, err := client.ListByDataServiceSender(req)
   387  	if err != nil {
   388  		result.jl.Response = autorest.Response{Response: resp}
   389  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "ListByDataService", resp, "Failure sending request")
   390  		return
   391  	}
   392  
   393  	result.jl, err = client.ListByDataServiceResponder(resp)
   394  	if err != nil {
   395  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "ListByDataService", resp, "Failure responding to request")
   396  		return
   397  	}
   398  	if result.jl.hasNextLink() && result.jl.IsEmpty() {
   399  		err = result.NextWithContext(ctx)
   400  		return
   401  	}
   402  
   403  	return
   404  }
   405  
   406  // ListByDataServicePreparer prepares the ListByDataService request.
   407  func (client JobsClient) ListByDataServicePreparer(ctx context.Context, dataServiceName string, resourceGroupName string, dataManagerName string, filter string) (*http.Request, error) {
   408  	pathParameters := map[string]interface{}{
   409  		"dataManagerName":   autorest.Encode("path", dataManagerName),
   410  		"dataServiceName":   autorest.Encode("path", dataServiceName),
   411  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   412  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   413  	}
   414  
   415  	const APIVersion = "2019-06-01"
   416  	queryParameters := map[string]interface{}{
   417  		"api-version": APIVersion,
   418  	}
   419  	if len(filter) > 0 {
   420  		queryParameters["$filter"] = autorest.Encode("query", filter)
   421  	}
   422  
   423  	preparer := autorest.CreatePreparer(
   424  		autorest.AsGet(),
   425  		autorest.WithBaseURL(client.BaseURI),
   426  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/dataServices/{dataServiceName}/jobs", pathParameters),
   427  		autorest.WithQueryParameters(queryParameters))
   428  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   429  }
   430  
   431  // ListByDataServiceSender sends the ListByDataService request. The method will close the
   432  // http.Response Body if it receives an error.
   433  func (client JobsClient) ListByDataServiceSender(req *http.Request) (*http.Response, error) {
   434  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   435  }
   436  
   437  // ListByDataServiceResponder handles the response to the ListByDataService request. The method always
   438  // closes the http.Response Body.
   439  func (client JobsClient) ListByDataServiceResponder(resp *http.Response) (result JobList, err error) {
   440  	err = autorest.Respond(
   441  		resp,
   442  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   443  		autorest.ByUnmarshallingJSON(&result),
   444  		autorest.ByClosing())
   445  	result.Response = autorest.Response{Response: resp}
   446  	return
   447  }
   448  
   449  // listByDataServiceNextResults retrieves the next set of results, if any.
   450  func (client JobsClient) listByDataServiceNextResults(ctx context.Context, lastResults JobList) (result JobList, err error) {
   451  	req, err := lastResults.jobListPreparer(ctx)
   452  	if err != nil {
   453  		return result, autorest.NewErrorWithError(err, "hybriddata.JobsClient", "listByDataServiceNextResults", nil, "Failure preparing next results request")
   454  	}
   455  	if req == nil {
   456  		return
   457  	}
   458  	resp, err := client.ListByDataServiceSender(req)
   459  	if err != nil {
   460  		result.Response = autorest.Response{Response: resp}
   461  		return result, autorest.NewErrorWithError(err, "hybriddata.JobsClient", "listByDataServiceNextResults", resp, "Failure sending next results request")
   462  	}
   463  	result, err = client.ListByDataServiceResponder(resp)
   464  	if err != nil {
   465  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "listByDataServiceNextResults", resp, "Failure responding to next results request")
   466  	}
   467  	return
   468  }
   469  
   470  // ListByDataServiceComplete enumerates all values, automatically crossing page boundaries as required.
   471  func (client JobsClient) ListByDataServiceComplete(ctx context.Context, dataServiceName string, resourceGroupName string, dataManagerName string, filter string) (result JobListIterator, err error) {
   472  	if tracing.IsEnabled() {
   473  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByDataService")
   474  		defer func() {
   475  			sc := -1
   476  			if result.Response().Response.Response != nil {
   477  				sc = result.page.Response().Response.Response.StatusCode
   478  			}
   479  			tracing.EndSpan(ctx, sc, err)
   480  		}()
   481  	}
   482  	result.page, err = client.ListByDataService(ctx, dataServiceName, resourceGroupName, dataManagerName, filter)
   483  	return
   484  }
   485  
   486  // ListByJobDefinition this method gets all the jobs of a given job definition.
   487  // Parameters:
   488  // dataServiceName - the name of the data service of the job definition.
   489  // jobDefinitionName - the name of the job definition for which jobs are needed.
   490  // resourceGroupName - the Resource Group Name
   491  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
   492  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
   493  // filter - oData Filter options
   494  func (client JobsClient) ListByJobDefinition(ctx context.Context, dataServiceName string, jobDefinitionName string, resourceGroupName string, dataManagerName string, filter string) (result JobListPage, err error) {
   495  	if tracing.IsEnabled() {
   496  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByJobDefinition")
   497  		defer func() {
   498  			sc := -1
   499  			if result.jl.Response.Response != nil {
   500  				sc = result.jl.Response.Response.StatusCode
   501  			}
   502  			tracing.EndSpan(ctx, sc, err)
   503  		}()
   504  	}
   505  	if err := validation.Validate([]validation.Validation{
   506  		{TargetValue: dataManagerName,
   507  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   508  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
   509  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
   510  		return result, validation.NewError("hybriddata.JobsClient", "ListByJobDefinition", err.Error())
   511  	}
   512  
   513  	result.fn = client.listByJobDefinitionNextResults
   514  	req, err := client.ListByJobDefinitionPreparer(ctx, dataServiceName, jobDefinitionName, resourceGroupName, dataManagerName, filter)
   515  	if err != nil {
   516  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "ListByJobDefinition", nil, "Failure preparing request")
   517  		return
   518  	}
   519  
   520  	resp, err := client.ListByJobDefinitionSender(req)
   521  	if err != nil {
   522  		result.jl.Response = autorest.Response{Response: resp}
   523  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "ListByJobDefinition", resp, "Failure sending request")
   524  		return
   525  	}
   526  
   527  	result.jl, err = client.ListByJobDefinitionResponder(resp)
   528  	if err != nil {
   529  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "ListByJobDefinition", resp, "Failure responding to request")
   530  		return
   531  	}
   532  	if result.jl.hasNextLink() && result.jl.IsEmpty() {
   533  		err = result.NextWithContext(ctx)
   534  		return
   535  	}
   536  
   537  	return
   538  }
   539  
   540  // ListByJobDefinitionPreparer prepares the ListByJobDefinition request.
   541  func (client JobsClient) ListByJobDefinitionPreparer(ctx context.Context, dataServiceName string, jobDefinitionName string, resourceGroupName string, dataManagerName string, filter string) (*http.Request, error) {
   542  	pathParameters := map[string]interface{}{
   543  		"dataManagerName":   autorest.Encode("path", dataManagerName),
   544  		"dataServiceName":   autorest.Encode("path", dataServiceName),
   545  		"jobDefinitionName": autorest.Encode("path", jobDefinitionName),
   546  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   547  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   548  	}
   549  
   550  	const APIVersion = "2019-06-01"
   551  	queryParameters := map[string]interface{}{
   552  		"api-version": APIVersion,
   553  	}
   554  	if len(filter) > 0 {
   555  		queryParameters["$filter"] = autorest.Encode("query", filter)
   556  	}
   557  
   558  	preparer := autorest.CreatePreparer(
   559  		autorest.AsGet(),
   560  		autorest.WithBaseURL(client.BaseURI),
   561  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/dataServices/{dataServiceName}/jobDefinitions/{jobDefinitionName}/jobs", pathParameters),
   562  		autorest.WithQueryParameters(queryParameters))
   563  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   564  }
   565  
   566  // ListByJobDefinitionSender sends the ListByJobDefinition request. The method will close the
   567  // http.Response Body if it receives an error.
   568  func (client JobsClient) ListByJobDefinitionSender(req *http.Request) (*http.Response, error) {
   569  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   570  }
   571  
   572  // ListByJobDefinitionResponder handles the response to the ListByJobDefinition request. The method always
   573  // closes the http.Response Body.
   574  func (client JobsClient) ListByJobDefinitionResponder(resp *http.Response) (result JobList, err error) {
   575  	err = autorest.Respond(
   576  		resp,
   577  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   578  		autorest.ByUnmarshallingJSON(&result),
   579  		autorest.ByClosing())
   580  	result.Response = autorest.Response{Response: resp}
   581  	return
   582  }
   583  
   584  // listByJobDefinitionNextResults retrieves the next set of results, if any.
   585  func (client JobsClient) listByJobDefinitionNextResults(ctx context.Context, lastResults JobList) (result JobList, err error) {
   586  	req, err := lastResults.jobListPreparer(ctx)
   587  	if err != nil {
   588  		return result, autorest.NewErrorWithError(err, "hybriddata.JobsClient", "listByJobDefinitionNextResults", nil, "Failure preparing next results request")
   589  	}
   590  	if req == nil {
   591  		return
   592  	}
   593  	resp, err := client.ListByJobDefinitionSender(req)
   594  	if err != nil {
   595  		result.Response = autorest.Response{Response: resp}
   596  		return result, autorest.NewErrorWithError(err, "hybriddata.JobsClient", "listByJobDefinitionNextResults", resp, "Failure sending next results request")
   597  	}
   598  	result, err = client.ListByJobDefinitionResponder(resp)
   599  	if err != nil {
   600  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "listByJobDefinitionNextResults", resp, "Failure responding to next results request")
   601  	}
   602  	return
   603  }
   604  
   605  // ListByJobDefinitionComplete enumerates all values, automatically crossing page boundaries as required.
   606  func (client JobsClient) ListByJobDefinitionComplete(ctx context.Context, dataServiceName string, jobDefinitionName string, resourceGroupName string, dataManagerName string, filter string) (result JobListIterator, err error) {
   607  	if tracing.IsEnabled() {
   608  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByJobDefinition")
   609  		defer func() {
   610  			sc := -1
   611  			if result.Response().Response.Response != nil {
   612  				sc = result.page.Response().Response.Response.StatusCode
   613  			}
   614  			tracing.EndSpan(ctx, sc, err)
   615  		}()
   616  	}
   617  	result.page, err = client.ListByJobDefinition(ctx, dataServiceName, jobDefinitionName, resourceGroupName, dataManagerName, filter)
   618  	return
   619  }
   620  
   621  // Resume resumes the given job.
   622  // Parameters:
   623  // dataServiceName - the name of the data service of the job definition.
   624  // jobDefinitionName - the name of the job definition of the job.
   625  // jobID - the job id of the job queried.
   626  // resourceGroupName - the Resource Group Name
   627  // dataManagerName - the name of the DataManager Resource within the specified resource group. DataManager
   628  // names must be between 3 and 24 characters in length and use any alphanumeric and underscore only
   629  func (client JobsClient) Resume(ctx context.Context, dataServiceName string, jobDefinitionName string, jobID string, resourceGroupName string, dataManagerName string) (result JobsResumeFuture, err error) {
   630  	if tracing.IsEnabled() {
   631  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Resume")
   632  		defer func() {
   633  			sc := -1
   634  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   635  				sc = result.FutureAPI.Response().StatusCode
   636  			}
   637  			tracing.EndSpan(ctx, sc, err)
   638  		}()
   639  	}
   640  	if err := validation.Validate([]validation.Validation{
   641  		{TargetValue: dataManagerName,
   642  			Constraints: []validation.Constraint{{Target: "dataManagerName", Name: validation.MaxLength, Rule: 24, Chain: nil},
   643  				{Target: "dataManagerName", Name: validation.MinLength, Rule: 3, Chain: nil},
   644  				{Target: "dataManagerName", Name: validation.Pattern, Rule: `^[-\w\.]+$`, Chain: nil}}}}); err != nil {
   645  		return result, validation.NewError("hybriddata.JobsClient", "Resume", err.Error())
   646  	}
   647  
   648  	req, err := client.ResumePreparer(ctx, dataServiceName, jobDefinitionName, jobID, resourceGroupName, dataManagerName)
   649  	if err != nil {
   650  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "Resume", nil, "Failure preparing request")
   651  		return
   652  	}
   653  
   654  	result, err = client.ResumeSender(req)
   655  	if err != nil {
   656  		err = autorest.NewErrorWithError(err, "hybriddata.JobsClient", "Resume", result.Response(), "Failure sending request")
   657  		return
   658  	}
   659  
   660  	return
   661  }
   662  
   663  // ResumePreparer prepares the Resume request.
   664  func (client JobsClient) ResumePreparer(ctx context.Context, dataServiceName string, jobDefinitionName string, jobID string, resourceGroupName string, dataManagerName string) (*http.Request, error) {
   665  	pathParameters := map[string]interface{}{
   666  		"dataManagerName":   autorest.Encode("path", dataManagerName),
   667  		"dataServiceName":   autorest.Encode("path", dataServiceName),
   668  		"jobDefinitionName": autorest.Encode("path", jobDefinitionName),
   669  		"jobId":             autorest.Encode("path", jobID),
   670  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   671  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   672  	}
   673  
   674  	const APIVersion = "2019-06-01"
   675  	queryParameters := map[string]interface{}{
   676  		"api-version": APIVersion,
   677  	}
   678  
   679  	preparer := autorest.CreatePreparer(
   680  		autorest.AsPost(),
   681  		autorest.WithBaseURL(client.BaseURI),
   682  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridData/dataManagers/{dataManagerName}/dataServices/{dataServiceName}/jobDefinitions/{jobDefinitionName}/jobs/{jobId}/resume", pathParameters),
   683  		autorest.WithQueryParameters(queryParameters))
   684  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   685  }
   686  
   687  // ResumeSender sends the Resume request. The method will close the
   688  // http.Response Body if it receives an error.
   689  func (client JobsClient) ResumeSender(req *http.Request) (future JobsResumeFuture, err error) {
   690  	var resp *http.Response
   691  	future.FutureAPI = &azure.Future{}
   692  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   693  	if err != nil {
   694  		return
   695  	}
   696  	var azf azure.Future
   697  	azf, err = azure.NewFutureFromResponse(resp)
   698  	future.FutureAPI = &azf
   699  	future.Result = future.result
   700  	return
   701  }
   702  
   703  // ResumeResponder handles the response to the Resume request. The method always
   704  // closes the http.Response Body.
   705  func (client JobsClient) ResumeResponder(resp *http.Response) (result autorest.Response, err error) {
   706  	err = autorest.Respond(
   707  		resp,
   708  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   709  		autorest.ByClosing())
   710  	result.Response = resp
   711  	return
   712  }
   713  

View as plain text