From 000c639e1548cc19fbfec2fdc026440cc723ec96 Mon Sep 17 00:00:00 2001 From: Pierre Frayer Date: Tue, 25 Jul 2023 12:15:19 +0200 Subject: [PATCH] feat(ldp): add stream subscriptions ref: OB-5034 --- .../netboot/translations/Messages_fr_FR.json | 0 .../home/logs-streams-home.controller.js | 18 ++- .../streams/home/logs-streams-home.html | 5 + .../src/logs/detail/streams/streams.module.js | 2 + .../streams-subscriptions.controller.js | 124 ++++++++++++++++++ .../subscriptions/streams-subscriptions.html | 61 +++++++++ .../streams-subscriptions.service.js | 60 +++++++++ .../subscriptions/subscriptions.component.js | 8 ++ .../subscriptions/subscriptions.module.js | 30 +++++ .../subscriptions/subscriptions.routing.js | 10 ++ .../translations/Messages_fr_FR.json | 3 + .../src/logs/translations/Messages_fr_FR.json | 13 +- 12 files changed, 331 insertions(+), 3 deletions(-) create mode 100644 packages/manager/apps/dedicated/client/app/dedicated/server/netboot/translations/Messages_fr_FR.json create mode 100644 packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.controller.js create mode 100644 packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.html create mode 100644 packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.service.js create mode 100644 packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.component.js create mode 100644 packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.module.js create mode 100644 packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.routing.js create mode 100644 packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/translations/Messages_fr_FR.json diff --git a/packages/manager/apps/dedicated/client/app/dedicated/server/netboot/translations/Messages_fr_FR.json b/packages/manager/apps/dedicated/client/app/dedicated/server/netboot/translations/Messages_fr_FR.json new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/home/logs-streams-home.controller.js b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/home/logs-streams-home.controller.js index d5cbd5def7ed..57b0d9803880 100644 --- a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/home/logs-streams-home.controller.js +++ b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/home/logs-streams-home.controller.js @@ -186,9 +186,9 @@ export default class LogsStreamsHomeCtrl { } /** - * navigates to the alerts page + * navigates to the archives page * - * @param {any} stream, stream for which alerts should be managed + * @param {any} stream, stream for which archives should be managed * @memberof LogsStreamsHomeCtrl */ gotoArchives(stream) { @@ -199,6 +199,20 @@ export default class LogsStreamsHomeCtrl { }); } + /** + * navigates to the subscriptions page + * + * @param {object} stream, stream for which subscriptions should be managed + * @memberof LogsStreamsHomeCtrl + */ + gotoSubscriptions(stream) { + this.CucCloudMessage.flushChildMessage(); + this.$state.go('dbaas-logs.detail.streams.stream.subscriptions', { + serviceName: this.serviceName, + streamId: stream.streamId, + }); + } + /** * navigates to follow live stream page * diff --git a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/home/logs-streams-home.html b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/home/logs-streams-home.html index 3ef4c1c1042f..7f8697776dec 100644 --- a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/home/logs-streams-home.html +++ b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/home/logs-streams-home.html @@ -144,6 +144,11 @@

on-click="ctrl.gotoArchives($row)" > + + this.LogsStreamsService.getStream(this.serviceName, this.streamId), + }); + } + + /** + * Retrieve subscription list, according to pagination/sort/filter + * + * @param offset int element offset to retrieve results from + * @param pageSize int Number of results to retrieve + * @param sort Object Sort object from ovh-ui datagrid + * @param criteria Object Criteria object from ovh-ui datagrid + * @return {*|Promise} + */ + loadSubscriptions({ offset, pageSize = 1, sort, criteria }) { + const filters = criteria.map((c) => { + const name = c.property || 'resource.name'; + return datagridToIcebergFilter(name, c.operator, c.value); + }); + const pageOffset = Math.ceil(offset / pageSize); + return this.LogsStreamsSubscriptionsService.getPaginatedStreamSubscriptions( + this.serviceName, + this.streamId, + pageOffset, + pageSize, + { name: sort.property, dir: sort.dir === -1 ? 'DESC' : 'ASC' }, + filters, + ); + } + + /** + * Display a modal to confirm subscription deletion + * + * @param subscription Object Subscription object from API + * @return {*|Promise} + */ + showSubscriptionDeleteConfirm(subscription) { + this.CucCloudMessage.flushChildMessage(); + return this.CucControllerHelper.modal + .showDeleteModal({ + titleText: this.$translate.instant( + 'streams_subscriptions_delete_modal_title', + ), + textHtml: this.$translate.instant( + 'streams_subscriptions_delete_modal_content', + { + resourceName: `${subscription.resource.name}`, + }, + ), + }) + .then(() => this.removeSubscription(subscription)); + } + + /** + * Delete a subscription on API + * Update datagrid accordingly + * + * @param subscription Object Subscription object from API + */ + removeSubscription(subscription) { + this.CucCloudMessage.flushChildMessage(); + this.deleteSubscriptionLoading = true; + this.LogsStreamsSubscriptionsService.deleteSubscription( + this.serviceName, + this.streamId, + subscription, + ) + .then((operation) => + this.LogsHelperService.handleOperation( + this.serviceName, + operation.data || operation, + 'streams_subscriptions_delete_success', + { resourceName: subscription.resource.name }, + ), + ) + .catch((err) => { + this.LogsHelperService.handleError( + 'streams_subscriptions_delete_error', + err, + { resourceName: subscription.resource.name }, + ); + }) + .finally(() => { + this.deleteSubscriptionLoading = false; + this.ouiDatagridService.refresh('subscriptions-datagrid', true); + this.CucControllerHelper.scrollPageToTop(); + }); + } +} diff --git a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.html b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.html new file mode 100644 index 000000000000..b657a130bb75 --- /dev/null +++ b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.html @@ -0,0 +1,61 @@ +
+ + +
+ {{'streams_subscriptions_current_title' | translate:{ name: + ctrl.stream.data.title } }} +
+

+ + + + + + + + + + {{ ::'streams_subscriptions_resource_products_' + + $row.resource.type | translate }} + + + + {{ $row.createdAt | cucMomentFormat:'L'}} + + + + + + + + +
diff --git a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.service.js b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.service.js new file mode 100644 index 000000000000..671f21b370e1 --- /dev/null +++ b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/streams-subscriptions.service.js @@ -0,0 +1,60 @@ +export default class LogsStreamsSubscriptionsService { + /* @ngInject */ + constructor($http, iceberg) { + this.$http = $http; + this.iceberg = iceberg; + } + + /** + * Retrieve list of stream's subscription with pagination, sorts, filters etc. + * @param serviceName string LDP service name + * @param streamId string LDP stream UUID + * @param offset int Offset to start from + * @param pageSize int Number of results to retrieve from API + * @param sort string Name of field to sort from + * @param filters Array List of Iceberg filters to apply + * @return {Object} + */ + getPaginatedStreamSubscriptions( + serviceName, + streamId, + offset = 0, + pageSize = 25, + sort = { name: 'nbArchive', dir: 'desc' }, + filters = null, + ) { + let res = this.iceberg( + `/dbaas/logs/${serviceName}/output/graylog/stream/${streamId}/subscription`, + ) + .query() + .expand('CachedObjectList-Pages') + .limit(pageSize) + .offset(offset) + .sort(sort.name, sort.dir); + if (filters !== null) { + filters.forEach((filter) => { + res = res.addFilter(filter.name, filter.operator, filter.value); + }); + } + return res.execute().$promise.then((response) => ({ + data: response.data, + meta: { + totalCount: + parseInt(response.headers['x-pagination-elements'], 10) || 0, + }, + })); + } + + /** + * Delete a subscription on the API side + * @param serviceName string LDP service name + * @param streamId string LDP stream UUID + * @param subscription Object Subscription object to delete + * @return {Promise} + */ + deleteSubscription(serviceName, streamId, subscription) { + return this.$http.delete( + `/dbaas/logs/${serviceName}/output/graylog/stream/${streamId}/subscription/${subscription.subscriptionId}`, + ); + } +} diff --git a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.component.js b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.component.js new file mode 100644 index 000000000000..5ad8e677cc3c --- /dev/null +++ b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.component.js @@ -0,0 +1,8 @@ +import controller from './streams-subscriptions.controller'; +import template from './streams-subscriptions.html'; + +export default { + controller, + controllerAs: 'ctrl', + template, +}; diff --git a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.module.js b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.module.js new file mode 100644 index 000000000000..1b3ec7289118 --- /dev/null +++ b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.module.js @@ -0,0 +1,30 @@ +import angular from 'angular'; + +import '@ovh-ux/manager-core'; +import '@ovh-ux/ng-ovh-cloud-universe-components'; +import '@uirouter/angularjs'; +import 'angular-translate'; +import 'ovh-api-services'; +import '@ovh-ux/ui-kit'; + +import component from './subscriptions.component'; +import routing from './subscriptions.routing'; +import service from './streams-subscriptions.service'; + +const moduleName = 'ovhManagerDbaasLogsDetailStreamsSubscriptions'; + +angular + .module(moduleName, [ + 'ngOvhCloudUniverseComponents', + 'oui', + 'ovhManagerCore', + 'ovh-api-services', + 'pascalprecht.translate', + 'ui.router', + ]) + .config(routing) + .service('LogsStreamsSubscriptionsService', service) + .component('dbaasLogsDetailStreamsSubscriptions', component) + .run(/* @ngTranslationsInject:json ./translations */); + +export default moduleName; diff --git a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.routing.js b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.routing.js new file mode 100644 index 000000000000..58730a73c051 --- /dev/null +++ b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/subscriptions.routing.js @@ -0,0 +1,10 @@ +export default /* @ngInject */ ($stateProvider) => { + $stateProvider.state('dbaas-logs.detail.streams.stream.subscriptions', { + url: '/subscriptions', + component: 'dbaasLogsDetailStreamsSubscriptions', + resolve: { + breadcrumb: /* @ngInject */ ($translate) => + $translate.instant('dbaas_logs_streams_subscriptions'), + }, + }); +}; diff --git a/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/translations/Messages_fr_FR.json b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/translations/Messages_fr_FR.json new file mode 100644 index 000000000000..22df2e1f638d --- /dev/null +++ b/packages/manager/modules/dbaas-logs/src/logs/detail/streams/subscriptions/translations/Messages_fr_FR.json @@ -0,0 +1,3 @@ +{ + "dbaas_logs_streams_subscriptions": "Abonnements" +} diff --git a/packages/manager/modules/dbaas-logs/src/logs/translations/Messages_fr_FR.json b/packages/manager/modules/dbaas-logs/src/logs/translations/Messages_fr_FR.json index 084980d662af..76493d155b06 100644 --- a/packages/manager/modules/dbaas-logs/src/logs/translations/Messages_fr_FR.json +++ b/packages/manager/modules/dbaas-logs/src/logs/translations/Messages_fr_FR.json @@ -767,5 +767,16 @@ "logs_tile_subscription_contact_admin": "Administrateur", "logs_tile_subscription_contact_billing": "Facturation", "logs_tile_subscription_contact_technical": "Technique", - "logs_order": "Commander" + "logs_order": "Commander", + "logs_streams_subscriptions": "Abonnements", + "streams_subscriptions_current_title": "Gestion de vos abonnements pour le flux '{{ name }}'", + "streams_subscriptions_intro_text": "Ces abonnements vous permettent de récupérer les logs de vos produits OVHcloud dans vos propres flux de données.", + "streams_subscriptions_resource_type_label": "Type de la resource", + "streams_subscriptions_resource_name_label": "Nom de la resource", + "streams_subscriptions_delete_modal_title": "Supprimer l'abonnement", + "streams_subscriptions_delete_modal_content": "Êtes-vous sûr de vouloir supprimer l'abonnement à la ressource {{resourceName}} ?", + "streams_subscriptions_delete_success": "L'abonnement à la ressource '{{resourceName}}' a été supprimée avec succès.", + "streams_subscriptions_delete_error": "Une erreur est survenue lors de la suppression de l'abonnement à la ressource '{{resourceName}}': {{message}}", + "streams_subscriptions_resource_products_ldp": "Logs Data Platform", + "streams_subscriptions_resource_products_webhosting": "Web Hosting" }