...

Source file src/github.com/Azure/azure-sdk-for-go/services/storsimple1200series/mgmt/2016-10-01/storsimple/jobs.go

Documentation: github.com/Azure/azure-sdk-for-go/services/storsimple1200series/mgmt/2016-10-01/storsimple

     1  package storsimple
     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 Storsimple 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  // Get returns the properties of the specified job name.
    35  // Parameters:
    36  // deviceName - the device name.
    37  // jobName - the job name.
    38  // resourceGroupName - the resource group name
    39  // managerName - the manager name
    40  func (client JobsClient) Get(ctx context.Context, deviceName string, jobName string, resourceGroupName string, managerName string) (result Job, err error) {
    41  	if tracing.IsEnabled() {
    42  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.Get")
    43  		defer func() {
    44  			sc := -1
    45  			if result.Response.Response != nil {
    46  				sc = result.Response.Response.StatusCode
    47  			}
    48  			tracing.EndSpan(ctx, sc, err)
    49  		}()
    50  	}
    51  	if err := validation.Validate([]validation.Validation{
    52  		{TargetValue: managerName,
    53  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    54  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
    55  		return result, validation.NewError("storsimple.JobsClient", "Get", err.Error())
    56  	}
    57  
    58  	req, err := client.GetPreparer(ctx, deviceName, jobName, resourceGroupName, managerName)
    59  	if err != nil {
    60  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "Get", nil, "Failure preparing request")
    61  		return
    62  	}
    63  
    64  	resp, err := client.GetSender(req)
    65  	if err != nil {
    66  		result.Response = autorest.Response{Response: resp}
    67  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "Get", resp, "Failure sending request")
    68  		return
    69  	}
    70  
    71  	result, err = client.GetResponder(resp)
    72  	if err != nil {
    73  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "Get", resp, "Failure responding to request")
    74  		return
    75  	}
    76  
    77  	return
    78  }
    79  
    80  // GetPreparer prepares the Get request.
    81  func (client JobsClient) GetPreparer(ctx context.Context, deviceName string, jobName string, resourceGroupName string, managerName string) (*http.Request, error) {
    82  	pathParameters := map[string]interface{}{
    83  		"deviceName":        autorest.Encode("path", deviceName),
    84  		"jobName":           autorest.Encode("path", jobName),
    85  		"managerName":       autorest.Encode("path", managerName),
    86  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    87  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    88  	}
    89  
    90  	const APIVersion = "2016-10-01"
    91  	queryParameters := map[string]interface{}{
    92  		"api-version": APIVersion,
    93  	}
    94  
    95  	preparer := autorest.CreatePreparer(
    96  		autorest.AsGet(),
    97  		autorest.WithBaseURL(client.BaseURI),
    98  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/jobs/{jobName}", pathParameters),
    99  		autorest.WithQueryParameters(queryParameters))
   100  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   101  }
   102  
   103  // GetSender sends the Get request. The method will close the
   104  // http.Response Body if it receives an error.
   105  func (client JobsClient) GetSender(req *http.Request) (*http.Response, error) {
   106  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   107  }
   108  
   109  // GetResponder handles the response to the Get request. The method always
   110  // closes the http.Response Body.
   111  func (client JobsClient) GetResponder(resp *http.Response) (result Job, err error) {
   112  	err = autorest.Respond(
   113  		resp,
   114  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   115  		autorest.ByUnmarshallingJSON(&result),
   116  		autorest.ByClosing())
   117  	result.Response = autorest.Response{Response: resp}
   118  	return
   119  }
   120  
   121  // ListByDevice retrieves all the jobs in a device.
   122  // Parameters:
   123  // deviceName - the device name.
   124  // resourceGroupName - the resource group name
   125  // managerName - the manager name
   126  // filter - oData Filter options
   127  func (client JobsClient) ListByDevice(ctx context.Context, deviceName string, resourceGroupName string, managerName string, filter string) (result JobListPage, err error) {
   128  	if tracing.IsEnabled() {
   129  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByDevice")
   130  		defer func() {
   131  			sc := -1
   132  			if result.jl.Response.Response != nil {
   133  				sc = result.jl.Response.Response.StatusCode
   134  			}
   135  			tracing.EndSpan(ctx, sc, err)
   136  		}()
   137  	}
   138  	if err := validation.Validate([]validation.Validation{
   139  		{TargetValue: managerName,
   140  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   141  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   142  		return result, validation.NewError("storsimple.JobsClient", "ListByDevice", err.Error())
   143  	}
   144  
   145  	result.fn = client.listByDeviceNextResults
   146  	req, err := client.ListByDevicePreparer(ctx, deviceName, resourceGroupName, managerName, filter)
   147  	if err != nil {
   148  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "ListByDevice", nil, "Failure preparing request")
   149  		return
   150  	}
   151  
   152  	resp, err := client.ListByDeviceSender(req)
   153  	if err != nil {
   154  		result.jl.Response = autorest.Response{Response: resp}
   155  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "ListByDevice", resp, "Failure sending request")
   156  		return
   157  	}
   158  
   159  	result.jl, err = client.ListByDeviceResponder(resp)
   160  	if err != nil {
   161  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "ListByDevice", resp, "Failure responding to request")
   162  		return
   163  	}
   164  	if result.jl.hasNextLink() && result.jl.IsEmpty() {
   165  		err = result.NextWithContext(ctx)
   166  		return
   167  	}
   168  
   169  	return
   170  }
   171  
   172  // ListByDevicePreparer prepares the ListByDevice request.
   173  func (client JobsClient) ListByDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string, managerName string, filter string) (*http.Request, error) {
   174  	pathParameters := map[string]interface{}{
   175  		"deviceName":        autorest.Encode("path", deviceName),
   176  		"managerName":       autorest.Encode("path", managerName),
   177  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   178  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   179  	}
   180  
   181  	const APIVersion = "2016-10-01"
   182  	queryParameters := map[string]interface{}{
   183  		"api-version": APIVersion,
   184  	}
   185  	if len(filter) > 0 {
   186  		queryParameters["$filter"] = autorest.Encode("query", filter)
   187  	}
   188  
   189  	preparer := autorest.CreatePreparer(
   190  		autorest.AsGet(),
   191  		autorest.WithBaseURL(client.BaseURI),
   192  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/jobs", pathParameters),
   193  		autorest.WithQueryParameters(queryParameters))
   194  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   195  }
   196  
   197  // ListByDeviceSender sends the ListByDevice request. The method will close the
   198  // http.Response Body if it receives an error.
   199  func (client JobsClient) ListByDeviceSender(req *http.Request) (*http.Response, error) {
   200  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   201  }
   202  
   203  // ListByDeviceResponder handles the response to the ListByDevice request. The method always
   204  // closes the http.Response Body.
   205  func (client JobsClient) ListByDeviceResponder(resp *http.Response) (result JobList, err error) {
   206  	err = autorest.Respond(
   207  		resp,
   208  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   209  		autorest.ByUnmarshallingJSON(&result),
   210  		autorest.ByClosing())
   211  	result.Response = autorest.Response{Response: resp}
   212  	return
   213  }
   214  
   215  // listByDeviceNextResults retrieves the next set of results, if any.
   216  func (client JobsClient) listByDeviceNextResults(ctx context.Context, lastResults JobList) (result JobList, err error) {
   217  	req, err := lastResults.jobListPreparer(ctx)
   218  	if err != nil {
   219  		return result, autorest.NewErrorWithError(err, "storsimple.JobsClient", "listByDeviceNextResults", nil, "Failure preparing next results request")
   220  	}
   221  	if req == nil {
   222  		return
   223  	}
   224  	resp, err := client.ListByDeviceSender(req)
   225  	if err != nil {
   226  		result.Response = autorest.Response{Response: resp}
   227  		return result, autorest.NewErrorWithError(err, "storsimple.JobsClient", "listByDeviceNextResults", resp, "Failure sending next results request")
   228  	}
   229  	result, err = client.ListByDeviceResponder(resp)
   230  	if err != nil {
   231  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "listByDeviceNextResults", resp, "Failure responding to next results request")
   232  	}
   233  	return
   234  }
   235  
   236  // ListByDeviceComplete enumerates all values, automatically crossing page boundaries as required.
   237  func (client JobsClient) ListByDeviceComplete(ctx context.Context, deviceName string, resourceGroupName string, managerName string, filter string) (result JobListIterator, err error) {
   238  	if tracing.IsEnabled() {
   239  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByDevice")
   240  		defer func() {
   241  			sc := -1
   242  			if result.Response().Response.Response != nil {
   243  				sc = result.page.Response().Response.Response.StatusCode
   244  			}
   245  			tracing.EndSpan(ctx, sc, err)
   246  		}()
   247  	}
   248  	result.page, err = client.ListByDevice(ctx, deviceName, resourceGroupName, managerName, filter)
   249  	return
   250  }
   251  
   252  // ListByManager retrieves all the jobs in a manager.
   253  // Parameters:
   254  // resourceGroupName - the resource group name
   255  // managerName - the manager name
   256  // filter - oData Filter options
   257  func (client JobsClient) ListByManager(ctx context.Context, resourceGroupName string, managerName string, filter string) (result JobListPage, err error) {
   258  	if tracing.IsEnabled() {
   259  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByManager")
   260  		defer func() {
   261  			sc := -1
   262  			if result.jl.Response.Response != nil {
   263  				sc = result.jl.Response.Response.StatusCode
   264  			}
   265  			tracing.EndSpan(ctx, sc, err)
   266  		}()
   267  	}
   268  	if err := validation.Validate([]validation.Validation{
   269  		{TargetValue: managerName,
   270  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   271  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   272  		return result, validation.NewError("storsimple.JobsClient", "ListByManager", err.Error())
   273  	}
   274  
   275  	result.fn = client.listByManagerNextResults
   276  	req, err := client.ListByManagerPreparer(ctx, resourceGroupName, managerName, filter)
   277  	if err != nil {
   278  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "ListByManager", nil, "Failure preparing request")
   279  		return
   280  	}
   281  
   282  	resp, err := client.ListByManagerSender(req)
   283  	if err != nil {
   284  		result.jl.Response = autorest.Response{Response: resp}
   285  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "ListByManager", resp, "Failure sending request")
   286  		return
   287  	}
   288  
   289  	result.jl, err = client.ListByManagerResponder(resp)
   290  	if err != nil {
   291  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "ListByManager", resp, "Failure responding to request")
   292  		return
   293  	}
   294  	if result.jl.hasNextLink() && result.jl.IsEmpty() {
   295  		err = result.NextWithContext(ctx)
   296  		return
   297  	}
   298  
   299  	return
   300  }
   301  
   302  // ListByManagerPreparer prepares the ListByManager request.
   303  func (client JobsClient) ListByManagerPreparer(ctx context.Context, resourceGroupName string, managerName string, filter string) (*http.Request, error) {
   304  	pathParameters := map[string]interface{}{
   305  		"managerName":       autorest.Encode("path", managerName),
   306  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   307  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   308  	}
   309  
   310  	const APIVersion = "2016-10-01"
   311  	queryParameters := map[string]interface{}{
   312  		"api-version": APIVersion,
   313  	}
   314  	if len(filter) > 0 {
   315  		queryParameters["$filter"] = autorest.Encode("query", filter)
   316  	}
   317  
   318  	preparer := autorest.CreatePreparer(
   319  		autorest.AsGet(),
   320  		autorest.WithBaseURL(client.BaseURI),
   321  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/jobs", pathParameters),
   322  		autorest.WithQueryParameters(queryParameters))
   323  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   324  }
   325  
   326  // ListByManagerSender sends the ListByManager request. The method will close the
   327  // http.Response Body if it receives an error.
   328  func (client JobsClient) ListByManagerSender(req *http.Request) (*http.Response, error) {
   329  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   330  }
   331  
   332  // ListByManagerResponder handles the response to the ListByManager request. The method always
   333  // closes the http.Response Body.
   334  func (client JobsClient) ListByManagerResponder(resp *http.Response) (result JobList, err error) {
   335  	err = autorest.Respond(
   336  		resp,
   337  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   338  		autorest.ByUnmarshallingJSON(&result),
   339  		autorest.ByClosing())
   340  	result.Response = autorest.Response{Response: resp}
   341  	return
   342  }
   343  
   344  // listByManagerNextResults retrieves the next set of results, if any.
   345  func (client JobsClient) listByManagerNextResults(ctx context.Context, lastResults JobList) (result JobList, err error) {
   346  	req, err := lastResults.jobListPreparer(ctx)
   347  	if err != nil {
   348  		return result, autorest.NewErrorWithError(err, "storsimple.JobsClient", "listByManagerNextResults", nil, "Failure preparing next results request")
   349  	}
   350  	if req == nil {
   351  		return
   352  	}
   353  	resp, err := client.ListByManagerSender(req)
   354  	if err != nil {
   355  		result.Response = autorest.Response{Response: resp}
   356  		return result, autorest.NewErrorWithError(err, "storsimple.JobsClient", "listByManagerNextResults", resp, "Failure sending next results request")
   357  	}
   358  	result, err = client.ListByManagerResponder(resp)
   359  	if err != nil {
   360  		err = autorest.NewErrorWithError(err, "storsimple.JobsClient", "listByManagerNextResults", resp, "Failure responding to next results request")
   361  	}
   362  	return
   363  }
   364  
   365  // ListByManagerComplete enumerates all values, automatically crossing page boundaries as required.
   366  func (client JobsClient) ListByManagerComplete(ctx context.Context, resourceGroupName string, managerName string, filter string) (result JobListIterator, err error) {
   367  	if tracing.IsEnabled() {
   368  		ctx = tracing.StartSpan(ctx, fqdn+"/JobsClient.ListByManager")
   369  		defer func() {
   370  			sc := -1
   371  			if result.Response().Response.Response != nil {
   372  				sc = result.page.Response().Response.Response.StatusCode
   373  			}
   374  			tracing.EndSpan(ctx, sc, err)
   375  		}()
   376  	}
   377  	result.page, err = client.ListByManager(ctx, resourceGroupName, managerName, filter)
   378  	return
   379  }
   380  

View as plain text