diff --git a/profiles/latest/alertsmanagement/mgmt/alertsmanagement/models.go b/profiles/latest/alertsmanagement/mgmt/alertsmanagement/models.go index 7f23a2b9d71d..25d5f9997f4b 100644 --- a/profiles/latest/alertsmanagement/mgmt/alertsmanagement/models.go +++ b/profiles/latest/alertsmanagement/mgmt/alertsmanagement/models.go @@ -182,6 +182,8 @@ type SmartGroupModificationProperties = original.SmartGroupModificationPropertie type SmartGroupProperties = original.SmartGroupProperties type SmartGroupsClient = original.SmartGroupsClient type SmartGroupsList = original.SmartGroupsList +type SmartGroupsListIterator = original.SmartGroupsListIterator +type SmartGroupsListPage = original.SmartGroupsListPage func New(subscriptionID string) BaseClient { return original.New(subscriptionID) @@ -216,6 +218,12 @@ func NewSmartGroupsClient(subscriptionID string) SmartGroupsClient { func NewSmartGroupsClientWithBaseURI(baseURI string, subscriptionID string) SmartGroupsClient { return original.NewSmartGroupsClientWithBaseURI(baseURI, subscriptionID) } +func NewSmartGroupsListIterator(page SmartGroupsListPage) SmartGroupsListIterator { + return original.NewSmartGroupsListIterator(page) +} +func NewSmartGroupsListPage(getNextPage func(context.Context, SmartGroupsList) (SmartGroupsList, error)) SmartGroupsListPage { + return original.NewSmartGroupsListPage(getNextPage) +} func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { return original.NewWithBaseURI(baseURI, subscriptionID) } diff --git a/profiles/preview/alertsmanagement/mgmt/alertsmanagement/models.go b/profiles/preview/alertsmanagement/mgmt/alertsmanagement/models.go index 2ca7f0eba322..2d8878aedc55 100644 --- a/profiles/preview/alertsmanagement/mgmt/alertsmanagement/models.go +++ b/profiles/preview/alertsmanagement/mgmt/alertsmanagement/models.go @@ -182,6 +182,8 @@ type SmartGroupModificationProperties = original.SmartGroupModificationPropertie type SmartGroupProperties = original.SmartGroupProperties type SmartGroupsClient = original.SmartGroupsClient type SmartGroupsList = original.SmartGroupsList +type SmartGroupsListIterator = original.SmartGroupsListIterator +type SmartGroupsListPage = original.SmartGroupsListPage func New(subscriptionID string) BaseClient { return original.New(subscriptionID) @@ -216,6 +218,12 @@ func NewSmartGroupsClient(subscriptionID string) SmartGroupsClient { func NewSmartGroupsClientWithBaseURI(baseURI string, subscriptionID string) SmartGroupsClient { return original.NewSmartGroupsClientWithBaseURI(baseURI, subscriptionID) } +func NewSmartGroupsListIterator(page SmartGroupsListPage) SmartGroupsListIterator { + return original.NewSmartGroupsListIterator(page) +} +func NewSmartGroupsListPage(getNextPage func(context.Context, SmartGroupsList) (SmartGroupsList, error)) SmartGroupsListPage { + return original.NewSmartGroupsListPage(getNextPage) +} func NewWithBaseURI(baseURI string, subscriptionID string) BaseClient { return original.NewWithBaseURI(baseURI, subscriptionID) } diff --git a/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/alertsmanagementapi/interfaces.go b/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/alertsmanagementapi/interfaces.go index 505f16debc58..c49917380add 100644 --- a/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/alertsmanagementapi/interfaces.go +++ b/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/alertsmanagementapi/interfaces.go @@ -43,7 +43,7 @@ var _ AlertsClientAPI = (*alertsmanagement.AlertsClient)(nil) // SmartGroupsClientAPI contains the set of methods on the SmartGroupsClient type. type SmartGroupsClientAPI interface { ChangeState(ctx context.Context, smartGroupID string, newState alertsmanagement.AlertState) (result alertsmanagement.SmartGroup, err error) - GetAll(ctx context.Context, targetResource string, targetResourceGroup string, targetResourceType string, monitorService alertsmanagement.MonitorService, monitorCondition alertsmanagement.MonitorCondition, severity alertsmanagement.Severity, smartGroupState alertsmanagement.AlertState, timeRange alertsmanagement.TimeRange, pageCount *int32, sortBy alertsmanagement.SmartGroupsSortByFields, sortOrder string) (result alertsmanagement.SmartGroupsList, err error) + GetAll(ctx context.Context, targetResource string, targetResourceGroup string, targetResourceType string, monitorService alertsmanagement.MonitorService, monitorCondition alertsmanagement.MonitorCondition, severity alertsmanagement.Severity, smartGroupState alertsmanagement.AlertState, timeRange alertsmanagement.TimeRange, pageCount *int32, sortBy alertsmanagement.SmartGroupsSortByFields, sortOrder string) (result alertsmanagement.SmartGroupsListPage, err error) GetByID(ctx context.Context, smartGroupID string) (result alertsmanagement.SmartGroup, err error) GetHistory(ctx context.Context, smartGroupID string) (result alertsmanagement.SmartGroupModification, err error) } diff --git a/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/models.go b/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/models.go index d9d2818125f8..8a702973c1ac 100644 --- a/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/models.go +++ b/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/models.go @@ -916,3 +916,140 @@ type SmartGroupsList struct { // Value - List of alerts Value *[]SmartGroup `json:"value,omitempty"` } + +// SmartGroupsListIterator provides access to a complete listing of SmartGroup values. +type SmartGroupsListIterator struct { + i int + page SmartGroupsListPage +} + +// NextWithContext advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *SmartGroupsListIterator) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SmartGroupsListIterator.NextWithContext") + defer func() { + sc := -1 + if iter.Response().Response.Response != nil { + sc = iter.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err = iter.page.NextWithContext(ctx) + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (iter *SmartGroupsListIterator) Next() error { + return iter.NextWithContext(context.Background()) +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter SmartGroupsListIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter SmartGroupsListIterator) Response() SmartGroupsList { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter SmartGroupsListIterator) Value() SmartGroup { + if !iter.page.NotDone() { + return SmartGroup{} + } + return iter.page.Values()[iter.i] +} + +// Creates a new instance of the SmartGroupsListIterator type. +func NewSmartGroupsListIterator(page SmartGroupsListPage) SmartGroupsListIterator { + return SmartGroupsListIterator{page: page} +} + +// IsEmpty returns true if the ListResult contains no values. +func (sgl SmartGroupsList) IsEmpty() bool { + return sgl.Value == nil || len(*sgl.Value) == 0 +} + +// smartGroupsListPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (sgl SmartGroupsList) smartGroupsListPreparer(ctx context.Context) (*http.Request, error) { + if sgl.NextLink == nil || len(to.String(sgl.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare((&http.Request{}).WithContext(ctx), + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(sgl.NextLink))) +} + +// SmartGroupsListPage contains a page of SmartGroup values. +type SmartGroupsListPage struct { + fn func(context.Context, SmartGroupsList) (SmartGroupsList, error) + sgl SmartGroupsList +} + +// NextWithContext advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *SmartGroupsListPage) NextWithContext(ctx context.Context) (err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SmartGroupsListPage.NextWithContext") + defer func() { + sc := -1 + if page.Response().Response.Response != nil { + sc = page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + next, err := page.fn(ctx, page.sgl) + if err != nil { + return err + } + page.sgl = next + return nil +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +// Deprecated: Use NextWithContext() instead. +func (page *SmartGroupsListPage) Next() error { + return page.NextWithContext(context.Background()) +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page SmartGroupsListPage) NotDone() bool { + return !page.sgl.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page SmartGroupsListPage) Response() SmartGroupsList { + return page.sgl +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page SmartGroupsListPage) Values() []SmartGroup { + if page.sgl.IsEmpty() { + return nil + } + return *page.sgl.Value +} + +// Creates a new instance of the SmartGroupsListPage type. +func NewSmartGroupsListPage(getNextPage func(context.Context, SmartGroupsList) (SmartGroupsList, error)) SmartGroupsListPage { + return SmartGroupsListPage{fn: getNextPage} +} diff --git a/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/smartgroups.go b/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/smartgroups.go index 1b0fb8293511..650c56d40604 100644 --- a/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/smartgroups.go +++ b/services/alertsmanagement/mgmt/2018-05-05/alertsmanagement/smartgroups.go @@ -133,17 +133,18 @@ func (client SmartGroupsClient) ChangeStateResponder(resp *http.Response) (resul // sortBy - sort the query results by input field. Default value is sort by 'lastModifiedDateTime'. // sortOrder - sort the query results order in either ascending or descending. Default value is 'desc' for // time fields and 'asc' for others. -func (client SmartGroupsClient) GetAll(ctx context.Context, targetResource string, targetResourceGroup string, targetResourceType string, monitorService MonitorService, monitorCondition MonitorCondition, severity Severity, smartGroupState AlertState, timeRange TimeRange, pageCount *int32, sortBy SmartGroupsSortByFields, sortOrder string) (result SmartGroupsList, err error) { +func (client SmartGroupsClient) GetAll(ctx context.Context, targetResource string, targetResourceGroup string, targetResourceType string, monitorService MonitorService, monitorCondition MonitorCondition, severity Severity, smartGroupState AlertState, timeRange TimeRange, pageCount *int32, sortBy SmartGroupsSortByFields, sortOrder string) (result SmartGroupsListPage, err error) { if tracing.IsEnabled() { ctx = tracing.StartSpan(ctx, fqdn+"/SmartGroupsClient.GetAll") defer func() { sc := -1 - if result.Response.Response != nil { - sc = result.Response.Response.StatusCode + if result.sgl.Response.Response != nil { + sc = result.sgl.Response.Response.StatusCode } tracing.EndSpan(ctx, sc, err) }() } + result.fn = client.getAllNextResults req, err := client.GetAllPreparer(ctx, targetResource, targetResourceGroup, targetResourceType, monitorService, monitorCondition, severity, smartGroupState, timeRange, pageCount, sortBy, sortOrder) if err != nil { err = autorest.NewErrorWithError(err, "alertsmanagement.SmartGroupsClient", "GetAll", nil, "Failure preparing request") @@ -152,12 +153,12 @@ func (client SmartGroupsClient) GetAll(ctx context.Context, targetResource strin resp, err := client.GetAllSender(req) if err != nil { - result.Response = autorest.Response{Response: resp} + result.sgl.Response = autorest.Response{Response: resp} err = autorest.NewErrorWithError(err, "alertsmanagement.SmartGroupsClient", "GetAll", resp, "Failure sending request") return } - result, err = client.GetAllResponder(resp) + result.sgl, err = client.GetAllResponder(resp) if err != nil { err = autorest.NewErrorWithError(err, "alertsmanagement.SmartGroupsClient", "GetAll", resp, "Failure responding to request") } @@ -237,6 +238,43 @@ func (client SmartGroupsClient) GetAllResponder(resp *http.Response) (result Sma return } +// getAllNextResults retrieves the next set of results, if any. +func (client SmartGroupsClient) getAllNextResults(ctx context.Context, lastResults SmartGroupsList) (result SmartGroupsList, err error) { + req, err := lastResults.smartGroupsListPreparer(ctx) + if err != nil { + return result, autorest.NewErrorWithError(err, "alertsmanagement.SmartGroupsClient", "getAllNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.GetAllSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "alertsmanagement.SmartGroupsClient", "getAllNextResults", resp, "Failure sending next results request") + } + result, err = client.GetAllResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "alertsmanagement.SmartGroupsClient", "getAllNextResults", resp, "Failure responding to next results request") + } + return +} + +// GetAllComplete enumerates all values, automatically crossing page boundaries as required. +func (client SmartGroupsClient) GetAllComplete(ctx context.Context, targetResource string, targetResourceGroup string, targetResourceType string, monitorService MonitorService, monitorCondition MonitorCondition, severity Severity, smartGroupState AlertState, timeRange TimeRange, pageCount *int32, sortBy SmartGroupsSortByFields, sortOrder string) (result SmartGroupsListIterator, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/SmartGroupsClient.GetAll") + defer func() { + sc := -1 + if result.Response().Response.Response != nil { + sc = result.page.Response().Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + result.page, err = client.GetAll(ctx, targetResource, targetResourceGroup, targetResourceType, monitorService, monitorCondition, severity, smartGroupState, timeRange, pageCount, sortBy, sortOrder) + return +} + // GetByID get information related to a specific Smart Group. // Parameters: // smartGroupID - smart group unique id.