/* * Copyright (c) Microsoft Corporation. * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; import { setContinuationToken } from "../pagingHelper"; import { ConsumerGroups } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { EventHubManagementClient } from "../eventHubManagementClient"; import { ConsumerGroup, ConsumerGroupsListByEventHubNextOptionalParams, ConsumerGroupsListByEventHubOptionalParams, ConsumerGroupsListByEventHubResponse, ConsumerGroupsCreateOrUpdateOptionalParams, ConsumerGroupsCreateOrUpdateResponse, ConsumerGroupsDeleteOptionalParams, ConsumerGroupsGetOptionalParams, ConsumerGroupsGetResponse, ConsumerGroupsListByEventHubNextResponse } from "../models"; /// /** Class containing ConsumerGroups operations. */ export class ConsumerGroupsImpl implements ConsumerGroups { private readonly client: EventHubManagementClient; /** * Initialize a new instance of the class ConsumerGroups class. * @param client Reference to the service client */ constructor(client: EventHubManagementClient) { this.client = client; } /** * Gets all the consumer groups in a Namespace. An empty feed is returned if no consumer group exists * in the Namespace. * @param resourceGroupName Name of the resource group within the azure subscription. * @param namespaceName The Namespace name * @param eventHubName The Event Hub name * @param options The options parameters. */ public listByEventHub( resourceGroupName: string, namespaceName: string, eventHubName: string, options?: ConsumerGroupsListByEventHubOptionalParams ): PagedAsyncIterableIterator { const iter = this.listByEventHubPagingAll( resourceGroupName, namespaceName, eventHubName, options ); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listByEventHubPagingPage( resourceGroupName, namespaceName, eventHubName, options, settings ); } }; } private async *listByEventHubPagingPage( resourceGroupName: string, namespaceName: string, eventHubName: string, options?: ConsumerGroupsListByEventHubOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: ConsumerGroupsListByEventHubResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listByEventHub( resourceGroupName, namespaceName, eventHubName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listByEventHubNext( resourceGroupName, namespaceName, eventHubName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listByEventHubPagingAll( resourceGroupName: string, namespaceName: string, eventHubName: string, options?: ConsumerGroupsListByEventHubOptionalParams ): AsyncIterableIterator { for await (const page of this.listByEventHubPagingPage( resourceGroupName, namespaceName, eventHubName, options )) { yield* page; } } /** * Creates or updates an Event Hubs consumer group as a nested resource within a Namespace. * @param resourceGroupName Name of the resource group within the azure subscription. * @param namespaceName The Namespace name * @param eventHubName The Event Hub name * @param consumerGroupName The consumer group name * @param parameters Parameters supplied to create or update a consumer group resource. * @param options The options parameters. */ createOrUpdate( resourceGroupName: string, namespaceName: string, eventHubName: string, consumerGroupName: string, parameters: ConsumerGroup, options?: ConsumerGroupsCreateOrUpdateOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, namespaceName, eventHubName, consumerGroupName, parameters, options }, createOrUpdateOperationSpec ); } /** * Deletes a consumer group from the specified Event Hub and resource group. * @param resourceGroupName Name of the resource group within the azure subscription. * @param namespaceName The Namespace name * @param eventHubName The Event Hub name * @param consumerGroupName The consumer group name * @param options The options parameters. */ delete( resourceGroupName: string, namespaceName: string, eventHubName: string, consumerGroupName: string, options?: ConsumerGroupsDeleteOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, namespaceName, eventHubName, consumerGroupName, options }, deleteOperationSpec ); } /** * Gets a description for the specified consumer group. * @param resourceGroupName Name of the resource group within the azure subscription. * @param namespaceName The Namespace name * @param eventHubName The Event Hub name * @param consumerGroupName The consumer group name * @param options The options parameters. */ get( resourceGroupName: string, namespaceName: string, eventHubName: string, consumerGroupName: string, options?: ConsumerGroupsGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, namespaceName, eventHubName, consumerGroupName, options }, getOperationSpec ); } /** * Gets all the consumer groups in a Namespace. An empty feed is returned if no consumer group exists * in the Namespace. * @param resourceGroupName Name of the resource group within the azure subscription. * @param namespaceName The Namespace name * @param eventHubName The Event Hub name * @param options The options parameters. */ private _listByEventHub( resourceGroupName: string, namespaceName: string, eventHubName: string, options?: ConsumerGroupsListByEventHubOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, namespaceName, eventHubName, options }, listByEventHubOperationSpec ); } /** * ListByEventHubNext * @param resourceGroupName Name of the resource group within the azure subscription. * @param namespaceName The Namespace name * @param eventHubName The Event Hub name * @param nextLink The nextLink from the previous successful call to the ListByEventHub method. * @param options The options parameters. */ private _listByEventHubNext( resourceGroupName: string, namespaceName: string, eventHubName: string, nextLink: string, options?: ConsumerGroupsListByEventHubNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, namespaceName, eventHubName, nextLink, options }, listByEventHubNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventHub/namespaces/{namespaceName}/eventhubs/{eventHubName}/consumergroups/{consumerGroupName}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.ConsumerGroup }, default: { bodyMapper: Mappers.ErrorResponse } }, requestBody: Parameters.parameters7, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.namespaceName, Parameters.eventHubName, Parameters.consumerGroupName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventHub/namespaces/{namespaceName}/eventhubs/{eventHubName}/consumergroups/{consumerGroupName}", httpMethod: "DELETE", responses: { 200: {}, 204: {}, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.namespaceName, Parameters.eventHubName, Parameters.consumerGroupName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventHub/namespaces/{namespaceName}/eventhubs/{eventHubName}/consumergroups/{consumerGroupName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ConsumerGroup }, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion1], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.namespaceName, Parameters.eventHubName, Parameters.consumerGroupName ], headerParameters: [Parameters.accept], serializer }; const listByEventHubOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventHub/namespaces/{namespaceName}/eventhubs/{eventHubName}/consumergroups", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ConsumerGroupListResult }, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion1, Parameters.skip, Parameters.top], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.namespaceName, Parameters.eventHubName ], headerParameters: [Parameters.accept], serializer }; const listByEventHubNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ConsumerGroupListResult }, default: { bodyMapper: Mappers.ErrorResponse } }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.nextLink, Parameters.namespaceName, Parameters.eventHubName ], headerParameters: [Parameters.accept], serializer };