mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 02:28:09 +00:00 
			
		
		
		
	![hashicorp-copywrite[bot]](/assets/img/avatar_default.png) 0b12cdcfd1
			
		
	
	0b12cdcfd1
	
	
	
		
			
			* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
		
			
				
	
	
		
			148 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			148 lines
		
	
	
		
			4.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /**
 | |
|  * Copyright (c) HashiCorp, Inc.
 | |
|  * SPDX-License-Identifier: BUSL-1.1
 | |
|  */
 | |
| 
 | |
| 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';
 | |
| 
 | |
| /**
 | |
|  * @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
 | |
|  * ```js
 | |
|  * <ReplicationPage
 | |
|     @model={{cluster}}
 | |
|     />
 | |
|  * ```
 | |
|  * @param {Object} cluster=null - An Ember data object that is pulled from the Ember Cluster Model.
 | |
|  */
 | |
| 
 | |
| const MODE = {
 | |
|   dr: 'Disaster Recovery',
 | |
|   performance: 'Performance',
 | |
| };
 | |
| 
 | |
| export default Component.extend({
 | |
|   layout,
 | |
|   store: service(),
 | |
|   router: service(),
 | |
|   reindexingDetails: null,
 | |
|   didReceiveAttrs() {
 | |
|     this._super(arguments);
 | |
|     this.getReplicationModeStatus.perform();
 | |
|   },
 | |
|   getReplicationModeStatus: task(function* () {
 | |
|     let resp;
 | |
|     const { replicationMode } = this.model;
 | |
| 
 | |
|     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
 | |
|     }
 | |
|     this.set('reindexingDetails', resp);
 | |
|   }),
 | |
|   isSummaryDashboard: computed('model.{performance.mode,dr.mode}', function () {
 | |
|     const router = this.router;
 | |
|     const currentRoute = router.get('currentRouteName');
 | |
| 
 | |
|     // we only show the summary dashboard in the replication index route
 | |
|     if (currentRoute === 'vault.cluster.replication.index') {
 | |
|       const drMode = this.model.dr.mode;
 | |
|       const performanceMode = this.model.performance.mode;
 | |
|       return drMode === 'primary' && performanceMode === 'primary';
 | |
|     }
 | |
|     return '';
 | |
|   }),
 | |
|   formattedReplicationMode: computed('model.replicationMode', 'isSummaryDashboard', function () {
 | |
|     // dr or performance 🤯
 | |
|     const { isSummaryDashboard } = this;
 | |
|     if (isSummaryDashboard) {
 | |
|       return 'Disaster Recovery & Performance';
 | |
|     }
 | |
|     const mode = this.model.replicationMode;
 | |
|     return MODE[mode];
 | |
|   }),
 | |
|   clusterMode: computed('model.replicationAttrs', 'isSummaryDashboard', function () {
 | |
|     // primary or secondary
 | |
|     const { model } = this;
 | |
|     const { isSummaryDashboard } = this;
 | |
|     if (isSummaryDashboard) {
 | |
|       // replicationAttrs does not exist when summaryDashboard
 | |
|       return 'primary';
 | |
|     }
 | |
|     return model.replicationAttrs.mode;
 | |
|   }),
 | |
|   isLoadingData: computed('clusterMode', 'model.replicationAttrs', function () {
 | |
|     const { clusterMode } = this;
 | |
|     const { model } = this;
 | |
|     const { isSummaryDashboard } = this;
 | |
|     if (isSummaryDashboard) {
 | |
|       return false;
 | |
|     }
 | |
|     const clusterId = model.replicationAttrs.clusterId;
 | |
|     const replicationDisabled = model.replicationAttrs.replicationDisabled;
 | |
|     if (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;
 | |
|   }),
 | |
|   isSecondary: computed('clusterMode', function () {
 | |
|     const { clusterMode } = this;
 | |
|     return clusterMode === 'secondary';
 | |
|   }),
 | |
|   replicationDetailsSummary: computed('isSummaryDashboard', function () {
 | |
|     const { model } = this;
 | |
|     const { isSummaryDashboard } = this;
 | |
|     if (!isSummaryDashboard) {
 | |
|       return;
 | |
|     }
 | |
|     if (isSummaryDashboard) {
 | |
|       const combinedObject = {};
 | |
|       combinedObject.dr = model['dr'];
 | |
|       combinedObject.performance = model['performance'];
 | |
|       return combinedObject;
 | |
|     }
 | |
|     return {};
 | |
|   }),
 | |
|   replicationDetails: computed('model.replicationMode', 'isSummaryDashboard', function () {
 | |
|     const { model } = this;
 | |
|     const { isSummaryDashboard } = this;
 | |
|     if (isSummaryDashboard) {
 | |
|       // Cannot return null
 | |
|       return {};
 | |
|     }
 | |
|     const replicationMode = model.replicationMode;
 | |
|     return model[replicationMode];
 | |
|   }),
 | |
|   isDisabled: computed('replicationDetails.mode', function () {
 | |
|     if (this.replicationDetails.mode === 'disabled' || this.replicationDetails.mode === 'primary') {
 | |
|       return true;
 | |
|     }
 | |
|     return false;
 | |
|   }),
 | |
|   message: computed('model.anyReplicationEnabled', 'formattedReplicationMode', function () {
 | |
|     let msg;
 | |
|     if (this.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;
 | |
|   }),
 | |
| });
 |