diff --git a/profiles/preview/preview/workloadmonitor/mgmt/workloadmonitor/models.go b/profiles/preview/preview/workloadmonitor/mgmt/workloadmonitor/models.go index e42d5ca864df..026a75a525c1 100644 --- a/profiles/preview/preview/workloadmonitor/mgmt/workloadmonitor/models.go +++ b/profiles/preview/preview/workloadmonitor/mgmt/workloadmonitor/models.go @@ -120,8 +120,6 @@ type MonitorsCollectionPage = original.MonitorsCollectionPage type NotificationSetting = original.NotificationSetting type NotificationSettingProperties = original.NotificationSettingProperties type NotificationSettingsCollection = original.NotificationSettingsCollection -type NotificationSettingsCollectionIterator = original.NotificationSettingsCollectionIterator -type NotificationSettingsCollectionPage = original.NotificationSettingsCollectionPage type Operation = original.Operation type OperationListResult = original.OperationListResult type OperationListResultIterator = original.OperationListResultIterator diff --git a/services/preview/workloadmonitor/mgmt/2018-08-31-preview/workloadmonitor/models.go b/services/preview/workloadmonitor/mgmt/2018-08-31-preview/workloadmonitor/models.go index 50217f15f978..03089d482fc9 100644 --- a/services/preview/workloadmonitor/mgmt/2018-08-31-preview/workloadmonitor/models.go +++ b/services/preview/workloadmonitor/mgmt/2018-08-31-preview/workloadmonitor/models.go @@ -1169,11 +1169,9 @@ func (page MonitorsCollectionPage) Values() []Monitor { return *page.mc.Value } -// NotificationSetting model for component. +// NotificationSetting model for NotificationSetting. type NotificationSetting struct { - // Etag - For optimistic concurrency control. - Etag *string `json:"etag,omitempty"` - // NotificationSettingProperties - Properties of the component. + // NotificationSettingProperties - Properties of Notification Settings *NotificationSettingProperties `json:"properties,omitempty"` // ID - Fully qualified resource Id for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName} ID *string `json:"id,omitempty"` @@ -1186,9 +1184,6 @@ type NotificationSetting struct { // MarshalJSON is the custom marshaler for NotificationSetting. func (ns NotificationSetting) MarshalJSON() ([]byte, error) { objectMap := make(map[string]interface{}) - if ns.Etag != nil { - objectMap["etag"] = ns.Etag - } if ns.NotificationSettingProperties != nil { objectMap["properties"] = ns.NotificationSettingProperties } @@ -1213,15 +1208,6 @@ func (ns *NotificationSetting) UnmarshalJSON(body []byte) error { } for k, v := range m { switch k { - case "etag": - if v != nil { - var etag string - err = json.Unmarshal(*v, &etag) - if err != nil { - return err - } - ns.Etag = &etag - } case "properties": if v != nil { var notificationSettingProperties NotificationSettingProperties @@ -1266,145 +1252,89 @@ func (ns *NotificationSetting) UnmarshalJSON(body []byte) error { // NotificationSettingProperties model for properties of a NotificationSetting. type NotificationSettingProperties struct { - // ActionGroups - List of action group resource ids to be notified - ActionGroups *[]string `json:"actionGroups,omitempty"` + // ActionGroupResourceIds - List of action group resource ids to be notified + ActionGroupResourceIds *[]string `json:"actionGroupResourceIds,omitempty"` } // NotificationSettingsCollection model for collection of notificationSettings. type NotificationSettingsCollection struct { - autorest.Response `json:"-"` - // NextLink - URL to the next set of results. - NextLink *string `json:"nextLink,omitempty"` - // Value - Collection of components. - Value *[]NotificationSetting `json:"value,omitempty"` -} - -// NotificationSettingsCollectionIterator provides access to a complete listing of NotificationSetting -// values. -type NotificationSettingsCollectionIterator struct { - i int - page NotificationSettingsCollectionPage + autorest.Response `json:"-"` + *NotificationSetting `json:"properties,omitempty"` + // Name - Resource name of NotificationSettings + Name *string `json:"name,omitempty"` + // ID - ARM resource ID of notification settings + ID *string `json:"id,omitempty"` + // Type - Resource type of NotificationSettings + Type *string `json:"type,omitempty"` } -// 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 *NotificationSettingsCollectionIterator) NextWithContext(ctx context.Context) (err error) { - if tracing.IsEnabled() { - ctx = tracing.StartSpan(ctx, fqdn+"/NotificationSettingsCollectionIterator.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 +// MarshalJSON is the custom marshaler for NotificationSettingsCollection. +func (nsc NotificationSettingsCollection) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if nsc.NotificationSetting != nil { + objectMap["properties"] = nsc.NotificationSetting } - err = iter.page.NextWithContext(ctx) - if err != nil { - iter.i-- - return err + if nsc.Name != nil { + objectMap["name"] = nsc.Name } - 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 *NotificationSettingsCollectionIterator) Next() error { - return iter.NextWithContext(context.Background()) -} - -// NotDone returns true if the enumeration should be started or is not yet complete. -func (iter NotificationSettingsCollectionIterator) 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 NotificationSettingsCollectionIterator) Response() NotificationSettingsCollection { - 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 NotificationSettingsCollectionIterator) Value() NotificationSetting { - if !iter.page.NotDone() { - return NotificationSetting{} + if nsc.ID != nil { + objectMap["id"] = nsc.ID } - return iter.page.Values()[iter.i] -} - -// IsEmpty returns true if the ListResult contains no values. -func (nsc NotificationSettingsCollection) IsEmpty() bool { - return nsc.Value == nil || len(*nsc.Value) == 0 -} - -// notificationSettingsCollectionPreparer prepares a request to retrieve the next set of results. -// It returns nil if no more results exist. -func (nsc NotificationSettingsCollection) notificationSettingsCollectionPreparer(ctx context.Context) (*http.Request, error) { - if nsc.NextLink == nil || len(to.String(nsc.NextLink)) < 1 { - return nil, nil + if nsc.Type != nil { + objectMap["type"] = nsc.Type } - return autorest.Prepare((&http.Request{}).WithContext(ctx), - autorest.AsJSON(), - autorest.AsGet(), - autorest.WithBaseURL(to.String(nsc.NextLink))) -} - -// NotificationSettingsCollectionPage contains a page of NotificationSetting values. -type NotificationSettingsCollectionPage struct { - fn func(context.Context, NotificationSettingsCollection) (NotificationSettingsCollection, error) - nsc NotificationSettingsCollection + return json.Marshal(objectMap) } -// 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 *NotificationSettingsCollectionPage) NextWithContext(ctx context.Context) (err error) { - if tracing.IsEnabled() { - ctx = tracing.StartSpan(ctx, fqdn+"/NotificationSettingsCollectionPage.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.nsc) +// UnmarshalJSON is the custom unmarshaler for NotificationSettingsCollection struct. +func (nsc *NotificationSettingsCollection) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) if err != nil { return err } - page.nsc = 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 *NotificationSettingsCollectionPage) Next() error { - return page.NextWithContext(context.Background()) -} - -// NotDone returns true if the page enumeration should be started or is not yet complete. -func (page NotificationSettingsCollectionPage) NotDone() bool { - return !page.nsc.IsEmpty() -} - -// Response returns the raw server response from the last page request. -func (page NotificationSettingsCollectionPage) Response() NotificationSettingsCollection { - return page.nsc -} - -// Values returns the slice of values for the current page or nil if there are no values. -func (page NotificationSettingsCollectionPage) Values() []NotificationSetting { - if page.nsc.IsEmpty() { - return nil + for k, v := range m { + switch k { + case "properties": + if v != nil { + var notificationSetting NotificationSetting + err = json.Unmarshal(*v, ¬ificationSetting) + if err != nil { + return err + } + nsc.NotificationSetting = ¬ificationSetting + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + nsc.Name = &name + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + nsc.ID = &ID + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + nsc.Type = &typeVar + } + } } - return *page.nsc.Value + + return nil } // Operation operation supported by the resource provider. diff --git a/services/preview/workloadmonitor/mgmt/2018-08-31-preview/workloadmonitor/notificationsettings.go b/services/preview/workloadmonitor/mgmt/2018-08-31-preview/workloadmonitor/notificationsettings.go index 14165ba6d6df..8bd5673c9734 100644 --- a/services/preview/workloadmonitor/mgmt/2018-08-31-preview/workloadmonitor/notificationsettings.go +++ b/services/preview/workloadmonitor/mgmt/2018-08-31-preview/workloadmonitor/notificationsettings.go @@ -47,14 +47,13 @@ func NewNotificationSettingsClientWithBaseURI(baseURI string, subscriptionID str // resourceNamespace - the Namespace of the resource. // resourceType - the type of the resource. // resourceName - name of the resource. -// skiptoken - the page-continuation token to use with a paged version of this API. -func (client NotificationSettingsClient) ListByResource(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, skiptoken string) (result NotificationSettingsCollectionPage, err error) { +func (client NotificationSettingsClient) ListByResource(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string) (result NotificationSettingsCollection, err error) { if tracing.IsEnabled() { ctx = tracing.StartSpan(ctx, fqdn+"/NotificationSettingsClient.ListByResource") defer func() { sc := -1 - if result.nsc.Response.Response != nil { - sc = result.nsc.Response.Response.StatusCode + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode } tracing.EndSpan(ctx, sc, err) }() @@ -69,8 +68,7 @@ func (client NotificationSettingsClient) ListByResource(ctx context.Context, res return result, validation.NewError("workloadmonitor.NotificationSettingsClient", "ListByResource", err.Error()) } - result.fn = client.listByResourceNextResults - req, err := client.ListByResourcePreparer(ctx, resourceGroupName, resourceNamespace, resourceType, resourceName, skiptoken) + req, err := client.ListByResourcePreparer(ctx, resourceGroupName, resourceNamespace, resourceType, resourceName) if err != nil { err = autorest.NewErrorWithError(err, "workloadmonitor.NotificationSettingsClient", "ListByResource", nil, "Failure preparing request") return @@ -78,12 +76,12 @@ func (client NotificationSettingsClient) ListByResource(ctx context.Context, res resp, err := client.ListByResourceSender(req) if err != nil { - result.nsc.Response = autorest.Response{Response: resp} + result.Response = autorest.Response{Response: resp} err = autorest.NewErrorWithError(err, "workloadmonitor.NotificationSettingsClient", "ListByResource", resp, "Failure sending request") return } - result.nsc, err = client.ListByResourceResponder(resp) + result, err = client.ListByResourceResponder(resp) if err != nil { err = autorest.NewErrorWithError(err, "workloadmonitor.NotificationSettingsClient", "ListByResource", resp, "Failure responding to request") } @@ -92,7 +90,7 @@ func (client NotificationSettingsClient) ListByResource(ctx context.Context, res } // ListByResourcePreparer prepares the ListByResource request. -func (client NotificationSettingsClient) ListByResourcePreparer(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, skiptoken string) (*http.Request, error) { +func (client NotificationSettingsClient) ListByResourcePreparer(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string) (*http.Request, error) { pathParameters := map[string]interface{}{ "resourceGroupName": autorest.Encode("path", resourceGroupName), "resourceName": autorest.Encode("path", resourceName), @@ -105,9 +103,6 @@ func (client NotificationSettingsClient) ListByResourcePreparer(ctx context.Cont queryParameters := map[string]interface{}{ "api-version": APIVersion, } - if len(skiptoken) > 0 { - queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) - } preparer := autorest.CreatePreparer( autorest.AsGet(), @@ -137,39 +132,96 @@ func (client NotificationSettingsClient) ListByResourceResponder(resp *http.Resp return } -// listByResourceNextResults retrieves the next set of results, if any. -func (client NotificationSettingsClient) listByResourceNextResults(ctx context.Context, lastResults NotificationSettingsCollection) (result NotificationSettingsCollection, err error) { - req, err := lastResults.notificationSettingsCollectionPreparer(ctx) - if err != nil { - return result, autorest.NewErrorWithError(err, "workloadmonitor.NotificationSettingsClient", "listByResourceNextResults", nil, "Failure preparing next results request") +// Update sends the update request. +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// resourceNamespace - the Namespace of the resource. +// resourceType - the type of the resource. +// resourceName - name of the resource. +// body - body of the NotificationSetting PUT object. +func (client NotificationSettingsClient) Update(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, body NotificationSetting) (result NotificationSettingsCollection, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/NotificationSettingsClient.Update") + defer func() { + sc := -1 + if result.Response.Response != nil { + sc = result.Response.Response.StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() } - if req == nil { + if err := validation.Validate([]validation.Validation{ + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("workloadmonitor.NotificationSettingsClient", "Update", err.Error()) + } + + req, err := client.UpdatePreparer(ctx, resourceGroupName, resourceNamespace, resourceType, resourceName, body) + if err != nil { + err = autorest.NewErrorWithError(err, "workloadmonitor.NotificationSettingsClient", "Update", nil, "Failure preparing request") return } - resp, err := client.ListByResourceSender(req) + + resp, err := client.UpdateSender(req) if err != nil { result.Response = autorest.Response{Response: resp} - return result, autorest.NewErrorWithError(err, "workloadmonitor.NotificationSettingsClient", "listByResourceNextResults", resp, "Failure sending next results request") + err = autorest.NewErrorWithError(err, "workloadmonitor.NotificationSettingsClient", "Update", resp, "Failure sending request") + return } - result, err = client.ListByResourceResponder(resp) + + result, err = client.UpdateResponder(resp) if err != nil { - err = autorest.NewErrorWithError(err, "workloadmonitor.NotificationSettingsClient", "listByResourceNextResults", resp, "Failure responding to next results request") + err = autorest.NewErrorWithError(err, "workloadmonitor.NotificationSettingsClient", "Update", resp, "Failure responding to request") } + return } -// ListByResourceComplete enumerates all values, automatically crossing page boundaries as required. -func (client NotificationSettingsClient) ListByResourceComplete(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, skiptoken string) (result NotificationSettingsCollectionIterator, err error) { - if tracing.IsEnabled() { - ctx = tracing.StartSpan(ctx, fqdn+"/NotificationSettingsClient.ListByResource") - defer func() { - sc := -1 - if result.Response().Response.Response != nil { - sc = result.page.Response().Response.Response.StatusCode - } - tracing.EndSpan(ctx, sc, err) - }() +// UpdatePreparer prepares the Update request. +func (client NotificationSettingsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, resourceNamespace string, resourceType string, resourceName string, body NotificationSetting) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "resourceName": autorest.Encode("path", resourceName), + "resourceNamespace": autorest.Encode("path", resourceNamespace), + "resourceType": autorest.Encode("path", resourceType), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), } - result.page, err = client.ListByResource(ctx, resourceGroupName, resourceNamespace, resourceType, resourceName, skiptoken) + + const APIVersion = "2018-08-31-preview" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceNamespace}/{resourceType}/{resourceName}/providers/Microsoft.WorkloadMonitor/notificationSettings", pathParameters), + autorest.WithJSON(body), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpdateSender sends the Update request. The method will close the +// http.Response Body if it receives an error. +func (client NotificationSettingsClient) UpdateSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// UpdateResponder handles the response to the Update request. The method always +// closes the http.Response Body. +func (client NotificationSettingsClient) UpdateResponder(resp *http.Response) (result NotificationSettingsCollection, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} return }