Skip to content

Commit

Permalink
feat(ldp): add stream subscriptions
Browse files Browse the repository at this point in the history
ref: OB-5034
  • Loading branch information
pfrayer committed Jul 26, 2023
1 parent f3a98f2 commit 000c639
Show file tree
Hide file tree
Showing 12 changed files with 331 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ <h3 data-translate="logs_streams_title"></h3>
on-click="ctrl.gotoArchives($row)"
><span data-translate="logs_streams_archives"></span
></oui-action-menu-item>
<oui-action-menu-item
disabled="$row.nbSubscription === 0"
on-click="ctrl.gotoSubscriptions($row)"
><span data-translate="logs_streams_subscriptions"></span
></oui-action-menu-item>
<oui-action-menu-item
disabled="!$row.isEditable"
on-click="ctrl.showDeleteConfirm($row)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import follow from './follow/follow.module';
import home from './home/home.module';
import routing from './streams.routing';
import service from './logs-streams.service';
import subscriptions from './subscriptions/subscriptions.module';

const moduleName = 'ovhManagerDbaasLogsDetailStreams';

Expand All @@ -35,6 +36,7 @@ angular
edit,
follow,
home,
subscriptions,
])
.config(routing)
.service('LogsStreamsService', service)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import datagridToIcebergFilter from '../../logs-iceberg.utils';

export default class LogsStreamsSubscriptionsCtrl {
/* @ngInject */
constructor(
$stateParams,
$translate,
ouiDatagridService,
CucCloudMessage,
CucControllerHelper,
LogsStreamsService,
LogsStreamsSubscriptionsService,
) {
this.$stateParams = $stateParams;
this.$translate = $translate;
this.ouiDatagridService = ouiDatagridService;
this.CucCloudMessage = CucCloudMessage;
this.CucControllerHelper = CucControllerHelper;
this.LogsStreamsService = LogsStreamsService;
this.LogsStreamsSubscriptionsService = LogsStreamsSubscriptionsService;

this.serviceName = this.$stateParams.serviceName;
this.streamId = this.$stateParams.streamId;
this.initLoaders();
}

$onInit() {
this.stream.load();
}

/**
* Load the current stream
*/
initLoaders() {
this.stream = this.CucControllerHelper.request.getHashLoader({
loaderFunction: () =>
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<any>}
*/
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<any>}
*/
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: `<strong>${subscription.resource.name}</strong>`,
},
),
})
.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();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<div class="subscriptions-home">
<oui-back-button
><span data-translate="logs_streams_subscriptions"></span
></oui-back-button>

<h6>
{{'streams_subscriptions_current_title' | translate:{ name:
ctrl.stream.data.title } }}
</h6>
<p data-translate="streams_subscriptions_intro_text"></p>

<oui-datagrid
id="subscriptions-datagrid"
rows-loader="ctrl.loadSubscriptions($config)"
>
<oui-datagrid-topbar>
<oui-spinner
size="s"
data-ng-if="ctrl.deleteSubscriptionLoading"
></oui-spinner>
</oui-datagrid-topbar>

<oui-datagrid-column
data-title="::'streams_subscriptions_resource_name_label' | translate"
data-property="resource.name"
data-type="string"
data-sortable
data-searchable
data-filterable
></oui-datagrid-column>
<oui-datagrid-column
data-title="::'streams_subscriptions_resource_type_label' | translate"
data-property="resource.type"
data-type="string"
data-sortable="asc"
data-searchable
data-filterable
>
<span>
{{ ::'streams_subscriptions_resource_products_' +
$row.resource.type | translate }}
</span>
</oui-datagrid-column>
<oui-datagrid-column
data-title="::'logs_home_start_date' | translate"
data-property="createdAt"
data-sortable
data-type="date"
>
{{ $row.createdAt | cucMomentFormat:'L'}}
</oui-datagrid-column>

<oui-action-menu compact data-placement="end">
<oui-action-menu-item
data-on-click="ctrl.showSubscriptionDeleteConfirm($row)"
>
<span data-translate="logs_delete"></span>
</oui-action-menu-item>
</oui-action-menu>
</oui-datagrid>
</div>
Original file line number Diff line number Diff line change
@@ -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<any>}
*/
deleteSubscription(serviceName, streamId, subscription) {
return this.$http.delete(
`/dbaas/logs/${serviceName}/output/graylog/stream/${streamId}/subscription/${subscription.subscriptionId}`,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import controller from './streams-subscriptions.controller';
import template from './streams-subscriptions.html';

export default {
controller,
controllerAs: 'ctrl',
template,
};
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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'),
},
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dbaas_logs_streams_subscriptions": "Abonnements"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 000c639

Please sign in to comment.