2 * STANDARD_RIFT_IO_COPYRIGHT
4 import RedundancyActions
from './redundancyActions.js';
5 import RedundancySource
from './redundancySource.js';
6 var Utils
= require('utils/utils.js');
7 import ROLES
from 'utils/roleConstants.js';
8 import _
from 'lodash';
9 export default class RedundancyStore
{
11 this.actions
= RedundancyActions(this.alt
);
12 this.bindActions(this.actions
);
13 this.registerAsync(RedundancySource
);
15 this.failoverDecision
= "INDIRECT";
17 'target-endpoint': [],
24 'polling-config' : {},
25 'revertive-preference': {},
26 'geographic-failover-decision': 'INDIRECT',
32 this.siteIdPattern
= /^((((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\p{N}\p{L}]+)?)|(^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))?$))|(((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)|\.)$/;
33 this.siteIdValidation
= [ "^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))?$"
34 , "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\p{N}\p{L}]+)?"
35 , '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)|\.'
37 this.failOverDecisionOptions
= [{ label
: "INDIRECT", value
: "INDIRECT" }, { label
: "DIRECT", value
: "DIRECT" }];
39 this.activeIndex
= null;
40 this.isReadOnly
= true;
41 this.siteOpen
= false;
42 this.hideColumns
= false;
44 this.isEditSite
= true;
45 this.exportPublicMethods({
46 closeSocket
: this.closeSocket
50 * [handleFieldUpdate description]
51 * @param {Object} data {
52 * [store_property] : [value]
54 * @return {[type]} [description]
56 handleUpdateInput(data
) {
59 handleUpdateConfigInput(data
) {
60 let configData
= this.configData
;
61 configData
= _
.merge(configData
, data
);
62 this.setState(configData
);
64 handleFailOverDecisionChange(failoverDecision
) {
65 let configData
= this.configData
;
66 configData
['geographic-failover-decision'] = failoverDecision
67 delete configData
['dns-ip-fqdn'];
68 this.setState({configData
});
73 let data
= arguments
[0];
74 let SiteData
= data
[0];
75 let siteIndex
= data
[1];
76 let isReadOnly
= data
[2];
79 activeIndex
: siteIndex
,
82 isReadOnly
: isReadOnly
,
83 isEditSite
: isReadOnly
,
88 editSite(isReadOnly
) {
89 this.viewSite([this.sites
[this.activeIndex
], this.activeIndex
, isReadOnly
]);
92 handleCloseSitePanel() {
99 handleHideColumns(e
) {
100 if(this.siteOpen
&& e
.currentTarget
.classList
.contains('hideColumns')) {
112 let description
= '';
115 'target-endpoint': [{},{}],
124 this.setState(_
.merge( this.resetSite() ,
134 handleAddTargetEndpoint() {
135 let newSiteData
= this.siteData
;
136 if(!newSiteData
['target-endpoint']) {
137 newSiteData
['target-endpoint'] = [];
139 newSiteData
['target-endpoint'].push({
143 this.setState({siteData
: newSiteData
})
145 handleRemoveTargetEndpoint(data
) {
146 let newSiteData
= this.siteData
;
147 newSiteData
['target-endpoint'].splice(
151 this.setState({siteData
: newSiteData
})
153 handleAddInstance() {
154 let newSiteData
= this.siteData
;
155 if(!newSiteData
['rw-instances']) {
156 newSiteData
['rw-instances'] = [];
158 newSiteData
['rw-instances'].push({
162 this.setState({siteData
: newSiteData
})
164 handleRemoveInstance(data
) {
165 let newSiteData
= this.siteData
;
166 newSiteData
['rw-instances'].splice(
170 this.setState({siteData
: newSiteData
})
172 getSitesSuccess(sites
) {
173 this.alt
.actions
.global
.hideScreenLoader
.defer();
174 this.setState({sites
: sites
});
176 getRedundancySuccess(data
) {
178 this.alt
.actions
.global
.hideScreenLoader
.defer();
179 let sites
= data
.site
&& data
.site
.map(function(site
, i
) {
185 'polling-config' : data
['polling-config'],
186 'revertive-preference': data
['revertive-preference'],
187 'geographic-failover-decision': data
['geographic-failover-decision'],
188 'dns-ip-fqdn': data
['dns-ip-fqdn'],
189 'user-credentials': data
['user-credentials'] || {
196 updateConfigSuccess() {
197 this.alt
.actions
.global
.hideScreenLoader
.defer();
204 updateSiteSuccess() {
205 this.alt
.actions
.global
.hideScreenLoader
.defer();
207 let sites
= this.sites
|| [];
208 sites
[this.activeIndex
] = this.siteData
215 deleteSiteSuccess() {
216 this.alt
.actions
.global
.hideScreenLoader
.defer();
217 let sites
= this.sites
;
218 sites
.splice(this.activeIndex
, 1);
219 this.setState({sites
, siteOpen
: false,isEdit
: true,
222 createSiteSuccess() {
224 this.alt
.actions
.global
.hideScreenLoader
.defer();
225 let sites
= this.sites
|| [];
226 sites
.push(self
.siteData
);
231 activeIndex
: sites
.length
- 1
234 this.setState(newState
);
236 openRedundancyStateSocketSuccess(connection
) {
238 let ws
= window
.multiplexer
.channel(connection
);
239 if (!connection
) return;
242 channelId
: connection
244 ws
.onmessage
= (socket
) => {
246 var data
= JSON
.parse(socket
.data
);
247 var newState
= {status
: data
};
248 Utils
.checkAuthentication(data
.statusCode
, function() {
252 self
.setState(newState
);
254 console
.log('Hit at exception in openRedundancyStateSocketSuccess', error
)
262 closeSocket
= () => {
264 window
.multiplexer
.channel(this.channelId
).close();