...

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

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

View as plain text