Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of UI: Fix enabling replication capabilities bug into release/1.17.x #28375

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{{/if}}
</div>
{{#if (eq this.data.mode "primary")}}
{{#if @canEnablePrimary}}
{{#if this.canEnablePrimary}}
<div class="field">
<label for="primary_cluster_addr" class="is-label">
Primary cluster address
Expand All @@ -55,7 +55,7 @@
</p>
{{/if}}
{{else}}
{{#if @canEnableSecondary}}
{{#if this.canEnableSecondary}}
{{#if (and (eq @replicationMode "dr") this.performanceReplicationEnabled (has-feature "Performance Replication"))}}
<div>
<ToggleButton
Expand Down Expand Up @@ -169,7 +169,9 @@
{{/if}}
</div>
{{#if
(or (and (eq this.data.mode "primary") @canEnablePrimary) (and (eq this.data.mode "secondary") @canEnableSecondary))
(or
(and (eq this.data.mode "primary") this.canEnablePrimary) (and (eq this.data.mode "secondary") this.canEnableSecondary)
)
}}
<div class="field is-grouped box is-fullwidth is-bottomless">
<Hds::Button @text="Enable Replication" type="submit" disabled={{this.disallowEnable}} data-test-replication-enable />
Expand Down
22 changes: 20 additions & 2 deletions ui/lib/replication/addon/components/enable-replication-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import { waitFor } from '@ember/test-waiters';
* ```js
* <EnableReplicationForm @replicationMode="dr" @canEnablePrimary={{true}} @canEnableSecondary={{false}} @performanceReplicationDisabled={{false}} @onSuccess={{this.reloadCluster}} />
* @param {string} replicationMode - should be one of "dr" or "performance"
* @param {boolean} canEnablePrimary - if the capabilities allow the user to enable a primary cluster
* @param {boolean} canEnableSecondary - if the capabilities allow the user to enable a secondary cluster
* @param {boolean} canEnablePrimaryDr - if the capabilities allow the user to enable a DR primary cluster
* @param {boolean} canEnablePrimaryPerformance - if the capabilities allow the user to enable a Performance primary cluster
* @param {boolean} canEnableSecondaryDr - if the capabilities allow the user to enable a DR secondary cluster
* @param {boolean} canEnableSecondaryPerformance - if the capabilities allow the user to enable a Performance secondary cluster
* @param {boolean} performanceMode - should be "primary", "secondary", or "disabled". If enabled, form will show a warning when attempting to enable DR secondary
* @param {Promise} onSuccess - (optional) callback called after successful replication enablement. Must be a promise.
* @param {boolean} doTransition - (optional) if provided, passed to onSuccess callback to determine if a transition should be done
Expand Down Expand Up @@ -58,6 +60,22 @@ export default class EnableReplicationFormComponent extends Component {
return true;
}

get canEnablePrimary() {
const { replicationMode, canEnablePrimaryDr, canEnablePrimaryPerformance } = this.args;
if (replicationMode === 'dr') {
return canEnablePrimaryDr !== false;
}
return canEnablePrimaryPerformance !== false;
}

get canEnableSecondary() {
const { replicationMode, canEnableSecondaryDr, canEnableSecondaryPerformance } = this.args;
if (replicationMode === 'dr') {
return canEnableSecondaryDr !== false;
}
return canEnableSecondaryPerformance !== false;
}

async onSuccess(resp, clusterMode) {
// clear form
this.data.reset();
Expand Down
6 changes: 4 additions & 2 deletions ui/lib/replication/addon/components/page/mode-index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@
</div>
<EnableReplicationForm
@replicationMode={{@replicationMode}}
@canEnablePrimary={{@cluster.canEnablePrimary}}
@canEnableSecondary={{@cluster.canEnableSecondary}}
@canEnablePrimaryDr={{@cluster.canEnablePrimaryDr}}
@canEnablePrimaryPerformance={{@cluster.canEnablePrimaryPerformance}}
@canEnableSecondaryDr={{@cluster.canEnableSecondaryDr}}
@canEnableSecondaryPerformance={{@cluster.canEnableSecondaryPerformance}}
@performanceReplicationDisabled={{@cluster.performance.replicationDisabled}}
@performanceMode={{if @cluster.performance.replicationDisabled "disabled" @cluster.performance.modeForUrl}}
@onSuccess={{@onEnableSuccess}}
Expand Down
37 changes: 26 additions & 11 deletions ui/lib/replication/addon/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,34 @@ export default Route.extend(ClusterRoute, {

afterModel(model) {
return hash({
canEnablePrimary: this.store
.findRecord('capabilities', 'sys/replication/primary/enable')
canEnablePrimaryPerformance: this.store
.findRecord('capabilities', 'sys/replication/performance/primary/enable')
.then((c) => c.canUpdate),
canEnableSecondary: this.store
.findRecord('capabilities', 'sys/replication/secondary/enable')
canEnableSecondaryPerformance: this.store
.findRecord('capabilities', 'sys/replication/performance/secondary/enable')
.then((c) => c.canUpdate),
}).then(({ canEnablePrimary, canEnableSecondary }) => {
setProperties(model, {
canEnablePrimary,
canEnableSecondary,
});
return model;
});
canEnablePrimaryDr: this.store
.findRecord('capabilities', 'sys/replication/dr/primary/enable')
.then((c) => c.canUpdate),
canEnableSecondaryDr: this.store
.findRecord('capabilities', 'sys/replication/dr/secondary/enable')
.then((c) => c.canUpdate),
}).then(
({
canEnablePrimaryPerformance,
canEnableSecondaryPerformance,
canEnablePrimaryDr,
canEnableSecondaryDr,
}) => {
setProperties(model, {
canEnablePrimaryPerformance,
canEnableSecondaryPerformance,
canEnablePrimaryDr,
canEnableSecondaryDr,
});
return model;
}
);
},
actions: {
refresh() {
Expand Down
48 changes: 32 additions & 16 deletions ui/tests/integration/components/enable-replication-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ module('Integration | Component | enable-replication-form', function (hooks) {
await render(
hbs`<EnableReplicationForm
@replicationMode={{this.replicationMode}}
@canEnablePrimary={{true}}
@canEnableSecondary={{true}}
@canEnablePrimaryDr={{true}}
@canEnablePrimaryPerformance={{true}}
@canEnableSecondaryDr={{true}}
@canEnableSecondaryPerformance={{true}}
@performanceMode="disabled"
/>`,
this.context
Expand Down Expand Up @@ -74,8 +76,10 @@ module('Integration | Component | enable-replication-form', function (hooks) {
await render(
hbs`<EnableReplicationForm
@replicationMode={{this.replicationMode}}
@canEnablePrimary={{false}}
@canEnableSecondary={{false}}
@canEnablePrimaryDr={{false}}
@canEnablePrimaryPerformance={{false}}
@canEnableSecondaryDr={{false}}
@canEnableSecondaryPerformance={{false}}
@performanceMode="disabled"
/>`,
this.context
Expand Down Expand Up @@ -105,8 +109,10 @@ module('Integration | Component | enable-replication-form', function (hooks) {
await render(
hbs`<EnableReplicationForm
@replicationMode={{this.replicationMode}}
@canEnablePrimary={{true}}
@canEnableSecondary={{true}}
@canEnablePrimaryDr={{true}}
@canEnablePrimaryPerformance={{true}}
@canEnableSecondaryDr={{true}}
@canEnableSecondaryPerformance={{true}}
@performanceMode={{this.performanceMode}}
/>`,
this.context
Expand Down Expand Up @@ -146,8 +152,10 @@ module('Integration | Component | enable-replication-form', function (hooks) {
await render(
hbs`<EnableReplicationForm
@replicationMode="performance"
@canEnablePrimary={{true}}
@canEnableSecondary={{true}}
@canEnablePrimaryDr={{true}}
@canEnablePrimaryPerformance={{true}}
@canEnableSecondaryDr={{true}}
@canEnableSecondaryPerformance={{true}}
@performanceMode="disabled"
/>`,
this.context
Expand Down Expand Up @@ -178,8 +186,10 @@ module('Integration | Component | enable-replication-form', function (hooks) {
await render(
hbs`<EnableReplicationForm
@replicationMode={{this.replicationMode}}
@canEnablePrimary={{true}}
@canEnableSecondary={{true}}
@canEnablePrimaryDr={{true}}
@canEnablePrimaryPerformance={{true}}
@canEnableSecondaryDr={{true}}
@canEnableSecondaryPerformance={{true}}
@performanceMode="disabled"
@onSuccess={{this.onSuccess}}
@doTransition={{false}}
Expand Down Expand Up @@ -217,8 +227,10 @@ module('Integration | Component | enable-replication-form', function (hooks) {
await render(
hbs`<EnableReplicationForm
@replicationMode={{this.replicationMode}}
@canEnablePrimary={{true}}
@canEnableSecondary={{true}}
@canEnablePrimaryDr={{true}}
@canEnablePrimaryPerformance={{true}}
@canEnableSecondaryDr={{true}}
@canEnableSecondaryPerformance={{true}}
@performanceMode="disabled"
@onSuccess={{this.onSuccess}}
@doTransition={{true}}
Expand Down Expand Up @@ -258,8 +270,10 @@ module('Integration | Component | enable-replication-form', function (hooks) {
await render(
hbs`<EnableReplicationForm
@replicationMode={{this.replicationMode}}
@canEnablePrimary={{true}}
@canEnableSecondary={{true}}
@canEnablePrimaryDr={{true}}
@canEnablePrimaryPerformance={{true}}
@canEnableSecondaryDr={{true}}
@canEnableSecondaryPerformance={{true}}
@performanceMode="disabled"
@onSuccess={{this.onSuccess}}
/>`,
Expand All @@ -277,8 +291,10 @@ module('Integration | Component | enable-replication-form', function (hooks) {
await render(
hbs`<EnableReplicationForm
@replicationMode={{this.replicationMode}}
@canEnablePrimary={{true}}
@canEnableSecondary={{true}}
@canEnablePrimaryDr={{true}}
@canEnablePrimaryPerformance={{true}}
@canEnableSecondaryDr={{true}}
@canEnableSecondaryPerformance={{true}}
@performanceMode="disabled"
@onSuccess={{this.onSuccess}}
/>`,
Expand Down
Loading