Skip to content

Commit

Permalink
feat(ldp): add stream subscriptions (#9736)
Browse files Browse the repository at this point in the history
ref: OB-5034

Signed-off-by: Pierre Frayer <[email protected]>
Signed-off-by: CDS Translator Agent <[email protected]>
  • Loading branch information
pfrayer authored and ghyenne committed Oct 5, 2023
1 parent 1824bd4 commit 86a88cc
Show file tree
Hide file tree
Showing 25 changed files with 459 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,33 @@ 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) {
goToArchives(stream) {
this.CucCloudMessage.flushChildMessage();
this.$state.go('dbaas-logs.detail.streams.stream.archives', {
serviceName: this.serviceName,
streamId: stream.streamId,
});
}

/**
* 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 @@ -89,6 +89,15 @@ <h3 data-translate="logs_streams_title"></h3>
>
{{ $row.nbAlertCondition || "-" }}
</oui-datagrid-column>
<oui-datagrid-column
data-title="::'logs_streams_col_subscriptions' | translate"
property="nbSubscription"
sortable
type="number"
filterable
>
{{ $row.nbSubscription || "-" }}
</oui-datagrid-column>
<oui-datagrid-column
data-title="::'logs_col_last_modified' | translate"
property="updatedAt"
Expand Down Expand Up @@ -141,9 +150,14 @@ <h3 data-translate="logs_streams_title"></h3>
></oui-action-menu-item>
<oui-action-menu-item
disabled="!$row.coldStorageEnabled && $row.nbArchive === 0"
on-click="ctrl.gotoArchives($row)"
on-click="ctrl.goToArchives($row)"
><span data-translate="logs_streams_archives"></span
></oui-action-menu-item>
<oui-action-menu-item
disabled="!$row.isEditable || $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,119 @@
import datagridToIcebergFilter from '../../logs-iceberg.utils';

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

this.serviceName = this.$stateParams.serviceName;
this.streamId = this.$stateParams.streamId;
}

$onInit() {
this.stream = this.CucControllerHelper.request.getHashLoader({
loaderFunction: () =>
this.LogsStreamsService.getStream(this.serviceName, this.streamId),
});
this.stream.load();
}

/**
* 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((criterion) => {
const name = criterion.property || 'resource.name';
return datagridToIcebergFilter(name, criterion.operator, criterion.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,
'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,65 @@
<section 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_col_last_modified' | translate"
data-property="updatedAt"
data-sortable
data-type="date"
>
{{ $row.updatedAt | cucMomentFormat:'L'}}
</oui-datagrid-column>
<oui-datagrid-column>
<button
type="button"
class="btn btn-secondary float-right mr-2"
data-ng-click="$ctrl.showSubscriptionDeleteConfirm($row)"
>
<span
class="oui-icon oui-icon-trash_concept"
aria-hidden="true"
></span>
</button>
</oui-datagrid-column>
</oui-datagrid>
</section>
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,7 @@
import controller from './streams-subscriptions.controller';
import template from './streams-subscriptions.html';

export default {
controller,
template,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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-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',
'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
@@ -0,0 +1,3 @@
{
"dbaas_logs_streams_subscriptions": "Subscriptions"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dbaas_logs_streams_subscriptions": "Suscripciones"
}
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
@@ -0,0 +1,3 @@
{
"dbaas_logs_streams_subscriptions": "Abonnements"
}
Loading

0 comments on commit 86a88cc

Please sign in to comment.