-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathreplication-page.js
137 lines (128 loc) · 4.33 KB
/
replication-page.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import { getOwner } from '@ember/owner';
/**
* @module ReplicationPage
* The `ReplicationPage` component is the parent contextual component that holds the replication-dashboard, and various replication-<name>-card components.
* It is the top level component on routes displaying replication dashboards.
*
* @example
* <ReplicationPage @model={{cluster}}/>
*
* @param {Object} model=null - An Ember data object that is pulled from the Ember Cluster Model.
*/
const MODE = {
dr: 'Disaster Recovery',
performance: 'Performance',
};
export default class ReplicationPage extends Component {
@service store;
@tracked reindexingDetails = null;
// This component renders both within and outside the replication engine so we have to dynamically look up the router
get router() {
const owner = getOwner(this);
return owner.lookup('service:router') || owner.lookup('service:app-router');
}
@action onModeUpdate(evt, replicationMode) {
// Called on did-insert and did-update
this.getReplicationModeStatus.perform(replicationMode);
}
@task
@waitFor
*getReplicationModeStatus(replicationMode) {
let resp;
if (this.isSummaryDashboard) {
// the summary dashboard is not mode specific and will error
// while running replication/null/status in the replication-mode adapter
return;
}
try {
resp = yield this.store.adapterFor('replication-mode').fetchStatus(replicationMode);
} catch (e) {
// do not handle error
} finally {
this.reindexingDetails = resp;
}
}
get isSummaryDashboard() {
const currentRoute = this.router.currentRouteName;
// we only show the summary dashboard in the replication index route
if (currentRoute === 'vault.cluster.replication.index') {
const drMode = this.args.model.dr.mode;
const performanceMode = this.args.model.performance.mode;
return drMode === 'primary' && performanceMode === 'primary';
}
return '';
}
get formattedReplicationMode() {
// dr or performance 🤯
if (this.isSummaryDashboard) {
return 'Disaster Recovery & Performance';
}
const mode = this.args.model.replicationMode;
return MODE[mode];
}
get clusterMode() {
// primary or secondary
if (this.isSummaryDashboard) {
// replicationAttrs does not exist when summaryDashboard
return 'primary';
}
return this.args.model.replicationAttrs.mode;
}
get isLoadingData() {
if (this.isSummaryDashboard) {
return false;
}
const { clusterId, replicationDisabled } = this.args.model.replicationAttrs;
if (this.clusterMode === 'bootstrapping' || (!clusterId && !replicationDisabled)) {
// if clusterMode is bootstrapping
// if no clusterId, the data hasn't loaded yet, wait for another status endpoint to be called
return true;
}
return false;
}
get isSecondary() {
return this.clusterMode === 'secondary';
}
get replicationDetailsSummary() {
if (this.isSummaryDashboard) {
const combinedObject = {};
combinedObject.dr = this.args.model['dr'];
combinedObject.performance = this.args.model['performance'];
return combinedObject;
}
return {};
}
get replicationDetails() {
if (this.isSummaryDashboard) {
// Cannot return null
return {};
}
const { replicationMode } = this.args.model;
return this.args.model[replicationMode];
}
get isDisabled() {
if (this.replicationDetails.mode === 'disabled' || this.replicationDetails.mode === 'primary') {
return true;
}
return false;
}
get message() {
let msg;
if (this.args.model.anyReplicationEnabled) {
msg = `This ${this.formattedReplicationMode} secondary has not been enabled. You can do so from the ${this.formattedReplicationMode} Primary.`;
} else {
msg = `This cluster has not been enabled as a ${this.formattedReplicationMode} Secondary. You can do so by enabling replication and adding a secondary from the ${this.formattedReplicationMode} Primary.`;
}
return msg;
}
}