Skip to content

Commit

Permalink
fetch replication/mode/status and pass to dashboard component
Browse files Browse the repository at this point in the history
  • Loading branch information
andaley committed May 1, 2020
1 parent 97f272e commit 1949055
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ui/app/adapters/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default ApplicationAdapter.extend({

urlForReplication(replicationMode, clusterMode, endpoint) {
let suffix;
const errString = `Calls to replication ${endpoint} endpoint are not currently allowed in the vault cluster adapter`;
const errString = `Calls to replication ${endpoint} endpoint are not currently allowed in the vault cluster adapater`;
if (clusterMode) {
assert(errString, REPLICATION_ENDPOINTS[clusterMode].includes(endpoint));
suffix = `${replicationMode}/${clusterMode}/${endpoint}`;
Expand Down
14 changes: 14 additions & 0 deletions ui/app/adapters/replication-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ApplicationAdapter from './application';

export default ApplicationAdapter.extend({
getStatusUrl(mode) {
return this.buildURL() + `/replication/${mode}/status`;
},

fetchStatus(mode) {
let url = this.getStatusUrl(mode);
return this.ajax(url, 'GET', { unauthenticated: true }).then(resp => {
return resp.data;
});
},
});
38 changes: 38 additions & 0 deletions ui/app/models/replication-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import DS from 'ember-data';
const { attr } = DS;

/* sample response
{
"request_id": "d81bba81-e8a1-0ee9-240e-a77d36e3e08f",
"lease_id": "",
"renewable": false,
"lease_duration": 0,
"data": {
"cluster_id": "ab7d4191-d1a3-b4d6-6297-5a41af6154ae",
"known_secondaries": [
"test"
],
"last_performance_wal": 72,
"last_reindex_epoch": "1588281113",
"last_wal": 73,
"merkle_root": "c8d258d376f01d98156f74e8d8f82ea2aca8dc4a",
"mode": "primary",
"primary_cluster_addr": "",
"reindex_building_progress": 26838,
"reindex_building_total": 305443,
"reindex_in_progress": true,
"reindex_stage": "building",
"state": "running"
},
"wrap_info": null,
"warnings": null,
"auth": null
}
*/

export default DS.Model.extend({
status: attr('object'),
});
12 changes: 12 additions & 0 deletions ui/app/serializers/replication-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ApplicationSerializer from './application';

export default ApplicationSerializer.extend({
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
const normalizedPayload = {
id: payload.id,
status: payload.data,
};

return this._super(store, primaryModelClass, normalizedPayload, id, requestType);
},
});
22 changes: 22 additions & 0 deletions ui/lib/core/addon/components/replication-page.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import layout from '../templates/components/replication-page';
import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency';

const MODE = {
dr: 'Disaster Recovery',
Expand All @@ -9,6 +11,26 @@ const MODE = {

export default Component.extend({
layout,
store: service(),
reindexingDetails: null,

didReceiveAttrs() {
this._super(arguments);
this.getReplicationModeStatus.perform();
},
getReplicationModeStatus: task(function*() {
let resp;
const { replicationMode } = this.model;
try {
resp = yield this.get('store')
.adapterFor('replication-mode')
.fetchStatus(replicationMode);
} catch (e) {
console.log(e);
}
this.set('reindexingDetails', resp);
}),

replicationMode: computed('model.{replicationMode}', function() {
// dr or performance 🤯
let mode = this.model.replicationMode;
Expand Down
1 change: 0 additions & 1 deletion ui/lib/core/addon/mixins/replication-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default Mixin.create({
}, {});
delete data.replicationMode;
}

return yield this.save.perform(action, replicationMode, clusterMode, data);
}),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{yield (hash
header=(component 'replication-header' data=model title=replicationMode isSecondary=isSecondary)
toggle=(component 'replication-toggle')
dashboard=(component 'replication-dashboard' data=model isSecondary=isSecondary replicationDetails=replicationDetails clusterMode=clusterMode)
dashboard=(component 'replication-dashboard' data=model isSecondary=isSecondary replicationDetails=replicationDetails clusterMode=clusterMode reindexingDetails=reindexingDetails)
isDisabled=isDisabled
message=message
)}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@
{{#if (eq replicationAttrs.mode 'initializing')}}
The cluster is initializing replication. This may take some time.
{{else}}
<p>{{cluster.replicationModeStatus.cluster_id}}</p>
<div class="replication">
<ReplicationPage @model={{cluster}} as |Page|>
<Page.toggle />
Expand Down

0 comments on commit 1949055

Please sign in to comment.