Skip to content

Commit 0973c22

Browse files
committed
connection tester
1 parent 7a31553 commit 0973c22

File tree

6 files changed

+82
-22
lines changed

6 files changed

+82
-22
lines changed

src/client/modals/cluster-seed-modal/cluster-seed-modal.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import { SupportedType, Cluster } from "../../../common/models/cluster/cluster";
2121

2222
import { FormLabel, Button, Modal, ImmutableInput, ImmutableDropdown } from '../../components/index';
2323
import { STRINGS } from "../../config/constants";
24+
import { Ajax } from '../../utils/ajax/ajax';
25+
import { Notifier } from '../../components/notifications/notifications';
2426
import { CLUSTER as LABELS } from '../../../common/models/labels';
2527
import { generateUniqueName } from '../../../common/utils/string/string';
2628
import { indexByAttribute } from '../../../common/utils/array/array';
@@ -64,11 +66,25 @@ export class ClusterSeedModal extends React.Component<ClusterSeedModalProps, Imm
6466
}
6567

6668
onNext() {
67-
this.props.onNext(this.state.newInstance);
69+
Ajax.query({
70+
method: "POST",
71+
url: 'settings/cluster-connection',
72+
data: {
73+
cluster: this.state.newInstance
74+
}
75+
})
76+
.then(
77+
(resp) => {
78+
var cluster = Cluster.fromJS(resp.cluster);
79+
this.props.onNext(cluster);
80+
},
81+
(xhr: XMLHttpRequest) => Notifier.failure('Woops', 'Something bad happened')
82+
)
83+
.done();
6884
}
6985

7086
render(): JSX.Element {
71-
const { onNext, onCancel } = this.props;
87+
const { onCancel } = this.props;
7288
const { newInstance, errors } = this.state;
7389

7490
if (!newInstance) return null;

src/client/modals/suggestion-modal/suggestion-modal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class SuggestionModal<T> extends React.Component<SuggestionModalProps<T>,
153153
}
154154

155155
renderEmpty() {
156-
const { onClose, title } = this.props;
156+
const { onClose, title, cancelLabel } = this.props;
157157

158158
return <Modal
159159
className="suggestion-modal"
@@ -164,7 +164,7 @@ export class SuggestionModal<T> extends React.Component<SuggestionModalProps<T>,
164164
<div className="message">{STRINGS.thereAreNoSuggestionsAtTheMoment}</div>
165165
</div>
166166
<div className="button-bar">
167-
<Button className="cancel" title={STRINGS.close} type="primary" onClick={onClose}/>
167+
<Button className="cancel" title={cancelLabel || STRINGS.close} type="primary" onClick={onClose}/>
168168
</div>
169169
</Modal>;
170170
}

src/server/routes/settings/settings.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { Router, Request, Response } from 'express';
18-
import { AppSettings } from '../../../common/models/index';
18+
import { AppSettings, Cluster } from '../../../common/models/index';
1919
import { MANIFESTS } from '../../../common/manifests/index';
2020

2121
import { PivotRequest } from '../../utils/index';
@@ -44,6 +44,45 @@ router.get('/', (req: PivotRequest, res: Response) => {
4444

4545
});
4646

47+
router.post('/cluster-connection', (req: PivotRequest, res: Response) => {
48+
var { cluster } = req.body;
49+
50+
if (typeof cluster === 'undefined') {
51+
res.status(400).send({
52+
error: 'must have a cluster'
53+
});
54+
return;
55+
}
56+
57+
try {
58+
var testCluster = Cluster.fromJS(cluster);
59+
} catch (e) {
60+
res.status(400).send({
61+
error: 'invalid cluster',
62+
message: e.message
63+
});
64+
return;
65+
}
66+
67+
SETTINGS_MANAGER.checkClusterConnectionInfo(testCluster)
68+
.then(
69+
(cluster) => {
70+
res.send({ cluster: cluster });
71+
},
72+
(e: Error) => {
73+
console.log('error:', e.message);
74+
if (e.hasOwnProperty('stack')) {
75+
console.log((<any>e).stack);
76+
}
77+
res.status(500).send({
78+
error: 'could not compute',
79+
message: e.message
80+
});
81+
}
82+
)
83+
.done();
84+
});
85+
4786
router.get('/cluster-sources', (req: PivotRequest, res: Response) => {
4887
SETTINGS_MANAGER.getAllClusterSources()
4988
.then(

src/server/utils/cluster-manager/cluster-manager.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ export class ClusterManager {
7474
this.updateRequester();
7575
}
7676

77-
// Do initialization
78-
public init(): Q.Promise<any> {
79-
const { cluster, logger } = this;
80-
81-
return Q(null)
82-
.then(() => this.establishInitialConnection());
83-
}
84-
8577
public destroy() {
8678
if (this.initialConnectionTimer) {
8779
clearTimeout(this.initialConnectionTimer);
@@ -133,7 +125,7 @@ export class ClusterManager {
133125
});
134126
}
135127

136-
private establishInitialConnection(): Q.Promise<any> {
128+
public establishInitialConnection(maxRetries = Infinity): Q.Promise<any> {
137129
const { logger, verbose, cluster } = this;
138130

139131
var deferred: Q.Deferred<any> = Q.defer();
@@ -159,7 +151,11 @@ export class ClusterManager {
159151
var msSinceLastTry = Date.now() - lastTryAt;
160152
var msToWait = Math.max(1, CONNECTION_RETRY_TIMEOUT - msSinceLastTry);
161153
logger.error(`Failed to connect to cluster '${cluster.name}' because: ${e.message} (will retry in ${msToWait}ms)`);
162-
this.initialConnectionTimer = setTimeout(attemptConnection, msToWait);
154+
if (retryNumber < maxRetries) {
155+
this.initialConnectionTimer = setTimeout(attemptConnection, msToWait);
156+
} else {
157+
deferred.reject(new Error('too many failed attempts'));
158+
}
163159
}
164160
);
165161
};

src/server/utils/file-manager/file-manager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ export class FileManager {
6767
this.verbose = Boolean(options.verbose);
6868
}
6969

70-
// Do initialization
71-
public init(): Q.Promise<Dataset> {
70+
public loadDataset(): Q.Promise<Dataset> {
7271
const { logger, anchorPath, uri } = this;
7372

7473
var filePath = path.resolve(anchorPath, uri);

src/server/utils/settings-manager/settings-manager.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export class SettingsManager {
150150
});
151151

152152
this.clusterManagers.push(clusterManager);
153-
return clusterManager.init();
153+
return clusterManager.establishInitialConnection();
154154
}
155155

156156
private removeClusterManager(cluster: Cluster): void {
@@ -224,7 +224,7 @@ export class SettingsManager {
224224
});
225225

226226
this.fileManagers.push(fileManager);
227-
return fileManager.init().then((dataset) => {
227+
return fileManager.loadDataset().then((dataset) => {
228228
var newExecutor = basicExecutorFactory({
229229
datasets: { main: dataset }
230230
});
@@ -307,9 +307,19 @@ export class SettingsManager {
307307
});
308308
}
309309

310-
// getClusterConnectionInfo(bareCluster: Cluster): Q.Promise<Cluster> {
311-
//
312-
// }
310+
checkClusterConnectionInfo(cluster: Cluster): Q.Promise<Cluster> {
311+
const { verbose, logger, anchorPath } = this;
312+
313+
var clusterManager = new ClusterManager(cluster, {
314+
logger,
315+
verbose,
316+
anchorPath
317+
});
318+
319+
return clusterManager.establishInitialConnection().then(() => {
320+
return clusterManager.cluster;
321+
});
322+
}
313323

314324
getAllClusterSources(): Q.Promise<ClusterSource> {
315325
var clusterSources = this.clusterManagers.map((clusterManager) => {

0 commit comments

Comments
 (0)