Skip to content

Commit

Permalink
feat(octavia): add pool edition view (#10435)
Browse files Browse the repository at this point in the history
ref: MANAGER-12302

Signed-off-by: Jacques Larique <[email protected]>
Co-authored-by: CDS Translator Agent <[email protected]>
  • Loading branch information
JacquesLarique and ovh-cds authored Dec 4, 2023
1 parent 9933d8d commit debae19
Show file tree
Hide file tree
Showing 29 changed files with 325 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@ export const DEFAULT_SESSION_PERSISTENCE_TYPE = 'sourceIP';

export const APP_COOKIE_SESSION_PERSISTENCE = 'appCookie';

const persistenceTypes = [
DEFAULT_SESSION_PERSISTENCE_TYPE,
'httpCookie',
APP_COOKIE_SESSION_PERSISTENCE,
];

export const PROTOCOL_SESSION_PERSISTENCE_TYPE_COMBINATION = {
http: persistenceTypes,
https: persistenceTypes,
tcp: persistenceTypes,
proxy: persistenceTypes,
proxyV2: persistenceTypes,
udp: [DEFAULT_SESSION_PERSISTENCE_TYPE],
sctp: [DEFAULT_SESSION_PERSISTENCE_TYPE],
};

export default {
DEFAULT_ALGORITHM,
DEFAULT_SESSION_PERSISTENCE_TYPE,
APP_COOKIE_SESSION_PERSISTENCE,
PROTOCOL_SESSION_PERSISTENCE_TYPE_COMBINATION,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@ import {
DEFAULT_ALGORITHM,
DEFAULT_SESSION_PERSISTENCE_TYPE,
APP_COOKIE_SESSION_PERSISTENCE,
PROTOCOL_SESSION_PERSISTENCE_TYPE_COMBINATION,
} from './constants';

export default class OctaviaLoadBalancerPoolFormCtrl {
$onInit() {
this.APP_COOKIE_SESSION_PERSISTENCE = APP_COOKIE_SESSION_PERSISTENCE;
this.model.algorithm =
this.model.algorithm ||
this.algorithms.find(
(algorithm) => algorithm.value === DEFAULT_ALGORITHM,
if (!this.model.algorithm?.value) {
this.model.algorithm = this.algorithms.find(
({ value }) => value === (this.model.algorithm || DEFAULT_ALGORITHM),
);
}
if (this.model.persistentSession?.type) {
this.model.persistentSession = this.sessionPersistenceTypes.find(
(session) => session.value === this.model.persistentSession.type,
);
}
this.availableSessionPersistenceTypes = this.getFilteredSessionPersistenceTypes(
this.model.protocol,
);
}

onProtocolChange(protocol) {
this.availableSessionPersistenceTypes = this.getFilteredSessionPersistenceTypes(
protocol,
);
}

onHasSessionChange(hasSession) {
Expand All @@ -29,4 +44,15 @@ export default class OctaviaLoadBalancerPoolFormCtrl {
this.model.cookieName = undefined;
}
}

getFilteredSessionPersistenceTypes(protocol) {
return this.sessionPersistenceTypes.filter(
(type) =>
type.value !== 'disabled' &&
(!protocol ||
PROTOCOL_SESSION_PERSISTENCE_TYPE_COMBINATION[protocol].includes(
type.value,
)),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<oui-select
name="algorithm"
data-required
data-disabled="$ctrl.isEditing"
data-match="label"
data-model="$ctrl.model.algorithm"
data-items="$ctrl.algorithms"
Expand All @@ -51,6 +50,7 @@
data-disabled="$ctrl.isEditing"
data-model="$ctrl.model.protocol"
data-items="$ctrl.protocols"
data-on-change="$ctrl.onProtocolChange(modelValue)"
data-placeholder="{{:: 'octavia_load_balancer_pools_create_protocol_default' | translate }}"
>
</oui-select>
Expand Down Expand Up @@ -79,7 +79,7 @@
data-required
data-model="$ctrl.model.persistentSession"
data-match="label"
data-items="$ctrl.sessionPersistenceTypes"
data-items="$ctrl.availableSessionPersistenceTypes"
data-on-change="$ctrl.onPersistentSessionTypeChange(modelValue)"
>
</oui-select>
Expand Down Expand Up @@ -108,7 +108,7 @@
</fieldset>
<oui-form-actions
data-disabled="!listener.$valid"
data-submit-text="{{:: 'octavia_load_balancer_pools_create_submit' | translate }}"
data-submit-text="{{:: 'octavia_load_balancer_pools_create_submit' + ($ctrl.isEditing ? '_edition' : '') | translate }}"
data-cancel-text="{{:: 'octavia_load_balancer_pools_create_cancel' | translate }}"
data-on-submit="$ctrl.onSubmit()"
data-on-cancel="$ctrl.onCancel()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"octavia_load_balancer_pools_create_persistent_session_appCookie": "Session persistence based on the application cookie.",
"octavia_load_balancer_pools_create_persistent_session_cookie_name": "Cookie name",
"octavia_load_balancer_pools_create_cancel": "Cancel",
"octavia_load_balancer_pools_create_submit": "Add"
"octavia_load_balancer_pools_create_submit": "Add",
"octavia_load_balancer_pools_create_submit_edition": "Edit"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"octavia_load_balancer_pools_create_name": "Nom du pool",
"octavia_load_balancer_pools_create_options": "Options du pool",
"octavia_load_balancer_pools_create_algorithm": "Algorithme",
"octavia_load_balancer_pools_create_algorithm_tooltip": "L’algorithme du Load Balancer qui répartit le trafic entre les membres du pool.",
"octavia_load_balancer_pools_create_algorithm_roundRobin": "Fait pivoter les requêtes uniformément entre plusieurs instances.",
"octavia_load_balancer_pools_create_algorithm_leastConnections": "Alloue les requêtes à l'instance avec le moins de connexions actives.",
"octavia_load_balancer_pools_create_algorithm_sourceIP": "Les requêtes provenant d'une adresse IP source unique sont dirigées de manière cohérente vers la même instance.",
"octavia_load_balancer_pools_create_algorithm_sourceIPPort": "Les requêtes provenant d'une adresse IP source Port source unique sont dirigées de manière cohérente vers la même instance.",
"octavia_load_balancer_pools_create_protocol": "Protocole",
"octavia_load_balancer_pools_create_protocol_tooltip": "Protocole pour lequel ce pool et ses membres écoutent.",
"octavia_load_balancer_pools_create_protocol_default": "Sélectionner un protocole",
"octavia_load_balancer_pools_create_session": "Session persistante",
"octavia_load_balancer_pools_create_session_tooltip": "Type de session permanente pour la distribution du trafic aux membres du pool.",
"octavia_load_balancer_pools_create_persistent_session": "Sélectionner une session persistante",
"octavia_load_balancer_pools_create_persistent_session_sourceIP": "Persistance de session basée sur l'adresse IP source.",
"octavia_load_balancer_pools_create_persistent_session_httpCookie": "Persistance de session basée sur le cookie http.",
"octavia_load_balancer_pools_create_persistent_session_appCookie": "Persistance de session basée sur le cookie d'application.",
"octavia_load_balancer_pools_create_persistent_session_cookie_name": "Nom du cookie",
"octavia_load_balancer_pools_create_cancel": "Annuler",
"octavia_load_balancer_pools_create_submit": "Ajouter",
"octavia_load_balancer_pools_create_submit_edition": "Editer"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
"octavia_load_balancer_pools_create_persistent_session_appCookie": "Persistance de session basée sur le cookie d'application.",
"octavia_load_balancer_pools_create_persistent_session_cookie_name": "Nom du cookie",
"octavia_load_balancer_pools_create_cancel": "Annuler",
"octavia_load_balancer_pools_create_submit": "Ajouter"
"octavia_load_balancer_pools_create_submit": "Ajouter",
"octavia_load_balancer_pools_create_submit_edition": "Editer"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default {
projectId: '<',
region: '<',
loadbalancerId: '<',
pools: '<',
algorithms: '<',
poolProtocols: '<',
sessionPersistenceTypes: '<',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
bindings: {
pool: '<',
listener: '<',
goToPoolEdition: '<',
goToEditName: '<',
goToDelete: '<',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class OctaviaLoadBalancerEditNameCtrl {

update() {
this.isLoading = true;
this.OctaviaLoadBalancerPoolsService.updateName(
this.OctaviaLoadBalancerPoolsService.editPool(
this.projectId,
this.region,
this.pool.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default /* @ngInject */ ($stateProvider) => {
loadbalancerPoolsDetailView: 'octaviaLoadBalancerPoolsDetailOverview',
},
resolve: {
breadcrumb: /* @ngInject */ () => 'General informations',
breadcrumb: /* @ngInject */ ($translate) =>
$translate.instant('load_balancer_pools_detail_info_tab_title'),
goToEditName: /* @ngInject */ ($state) => () =>
$state.go(
'octavia-load-balancer.loadbalancer.pools.detail.general-information.edit-name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<oui-tile
data-heading="{{ 'octavia_load_balancer_pools_detail_overview_management_title' | translate }}"
>
<oui-tile-button data-on-click="$ctrl.goToEdit()">
<oui-tile-button
data-on-click="$ctrl.goToPoolEdition($ctrl.pool)"
>
<span
data-translate="octavia_load_balancer_pools_detail_overview_management_edit"
></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import controller from './controller';
import template from './template.html';

export default {
bindings: {
projectId: '<',
region: '<',
poolId: '<',
pool: '<',
algorithms: '<',
poolProtocols: '<',
sessionPersistenceTypes: '<',
trackEditAction: '<',
trackEditPage: '<',
goBack: '<',
},
controller,
template,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const TRACKING_HIT_PREFIX = 'edit';

export default {
TRACKING_HIT_PREFIX,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export default class OctaviaLoadBalancerPoolsEditCtrl {
/* @ngInject */
constructor(OctaviaLoadBalancerPoolsService, Alerter, $translate) {
this.OctaviaLoadBalancerPoolsService = OctaviaLoadBalancerPoolsService;
this.Alerter = Alerter;
this.$translate = $translate;
}

$onInit() {
this.loading = false;
this.model = {
name: this.pool.name,
algorithm: this.pool.algorithm,
protocol: this.pool.protocol,
persistentSession: this.pool.sessionPersistence,
cookieName: this.pool.sessionPersistence.cookieName,
hasSession: this.pool.sessionPersistence.type !== 'disabled',
};
}

submit() {
this.loading = true;
this.trackEditAction('confirm');
const sessionPersistence = this.model.hasSession
? {
type: this.model.persistentSession.value,
cookieName: this.model.cookieName,
}
: undefined;
this.OctaviaLoadBalancerPoolsService.editPool(
this.projectId,
this.region,
this.poolId,
this.model.name,
this.model.algorithm.value,
sessionPersistence,
)
.then(async () => {
this.trackEditPage('success');
this.Alerter.set(
'alert-success',
this.$translate.instant('octavia_load_balancer_pools_edit_success', {
pool: this.model.name,
}),
null,
'octavia.alerts.global',
);
await this.goBack(true);
})
.catch((error) => {
this.trackEditPage('error');
this.Alerter.error(
this.$translate.instant('octavia_load_balancer_global_error', {
message: error.data?.message,
requestId: error.headers('X-Ovh-Queryid'),
}),
'octavia.alerts.global',
);
})
.finally(() => {
this.loading = false;
});
}

cancel() {
this.trackEditAction('cancel');
this.goBack();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import angular from 'angular';
import '@uirouter/angularjs';
import 'oclazyload';

const moduleName = 'ovhManagerOctaviaLoadBalancerDashboardPoolsEditLazyLoading';

angular.module(moduleName, ['ui.router', 'oc.lazyLoad']).config(
/* @ngInject */ ($stateProvider) => {
$stateProvider.state('octavia-load-balancer.loadbalancer.pools.edit.**', {
url: '/:poolId/edit',
lazyLoad: ($transition$) => {
const $ocLazyLoad = $transition$.injector().get('$ocLazyLoad');

return import('./module').then((mod) =>
$ocLazyLoad.inject(mod.default || mod),
);
},
});
},
);

export default moduleName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import angular from 'angular';

import component from './component';
import routing from './routing';

import poolComponents from '../components';

const moduleName = 'ovhManagerOctaviaLoadBalancerPoolsEdit';

angular
.module(moduleName, [poolComponents])
.config(routing)
.component('octaviaLoadBalancerPoolsEdit', component);

export default moduleName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { TRACKING_HIT_PREFIX } from './constants';
import { TRACKING_SUFFIX } from '../constants';
import { TRACKING_NAME } from '../../constants';

export default /* @ngInject */ ($stateProvider) => {
$stateProvider.state('octavia-load-balancer.loadbalancer.pools.edit', {
url: '/:poolId/edit',
views: {
loadbalancerPoolsView: 'octaviaLoadBalancerPoolsEdit',
},
resolve: {
breadcrumb: () => null,
poolId: /* @ngInject */ ($transition$) => $transition$.params().poolId,
pool: /* @ngInject */ (
OctaviaLoadBalancerPoolsService,
projectId,
region,
poolId,
) => OctaviaLoadBalancerPoolsService.getPool(projectId, region, poolId),
goBack: /* @ngInject */ ($state, poolId) => (reload) =>
$state.go(
'octavia-load-balancer.loadbalancer.pools.detail',
{
poolId,
},
reload
? { reload: 'octavia-load-balancer.loadbalancer.pools.detail' }
: null,
),
trackEditAction: /* @ngInject */ (trackAction) => (hit) =>
trackAction(`${TRACKING_HIT_PREFIX}::${hit}`),
trackEditPage: /* @ngInject */ (trackPage) => (hit) =>
trackPage(`${TRACKING_HIT_PREFIX}-${hit}`),
},
atInternet: {
rename: `${TRACKING_NAME}::${TRACKING_SUFFIX}::${TRACKING_HIT_PREFIX}`,
},
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="text-center" data-ng-if="$ctrl.loading">
<oui-spinner></oui-spinner>
</div>

<octavia-load-balancer-pool-form
data-ng-if="!$ctrl.loading"
data-algorithms="$ctrl.algorithms"
data-protocols="$ctrl.poolProtocols"
data-session-persistence-types="$ctrl.sessionPersistenceTypes"
data-model="$ctrl.model"
data-is-editing="true"
data-on-submit="$ctrl.submit()"
data-on-cancel="$ctrl.cancel()"
></octavia-load-balancer-pool-form>
Loading

0 comments on commit debae19

Please sign in to comment.