Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Prevent crash when network or cluster is offline (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzdunek authored Apr 6, 2022
1 parent d779206 commit 9707ef9
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions packages/teleterm/src/ui/services/clusters/clustersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ export class ClustersService extends ImmutableStore<ClustersServiceState> {

async syncRootCluster(clusterUri: string) {
try {
await this.syncClusterInfo(clusterUri);

this.syncLeafClusters(clusterUri);
this.syncKubes(clusterUri);
this.syncApps(clusterUri);
this.syncDbs(clusterUri);
this.syncServers(clusterUri);
this.syncKubes(clusterUri);
this.syncGateways();
await Promise.all([
this.syncClusterInfo(clusterUri),
this.syncLeafClusters(clusterUri),
]);
} catch (e) {
this.notificationsService.notifyError({
title: `Could not synchronize cluster ${
routing.parseClusterUri(clusterUri).params.rootClusterId
}`,
description: e.message,
});
throw e;
}
this.syncKubes(clusterUri);
this.syncApps(clusterUri);
this.syncDbs(clusterUri);
this.syncServers(clusterUri);
this.syncKubes(clusterUri);
this.syncGateways();
}

async syncLeafCluster(clusterUri: string) {
Expand All @@ -92,12 +92,20 @@ export class ClustersService extends ImmutableStore<ClustersServiceState> {
}

async syncRootClusters() {
const clusters = await this.client.listRootClusters();
this.setState(draft => {
draft.clusters = new Map(clusters.map(c => [c.uri, c]));
});

clusters.filter(c => c.connected).forEach(c => this.syncRootCluster(c.uri));
try {
const clusters = await this.client.listRootClusters();
this.setState(draft => {
draft.clusters = new Map(clusters.map(c => [c.uri, c]));
});
clusters
.filter(c => c.connected)
.forEach(c => this.syncRootCluster(c.uri));
} catch (error) {
this.notificationsService.notifyError({
title: 'Could not fetch root clusters',
description: error.message,
});
}
}

async syncCluster(clusterUri: string) {
Expand All @@ -114,10 +122,17 @@ export class ClustersService extends ImmutableStore<ClustersServiceState> {
}

async syncGateways() {
const gws = await this.client.listGateways();
this.setState(draft => {
draft.gateways = new Map(gws.map(g => [g.uri, g]));
});
try {
const gws = await this.client.listGateways();
this.setState(draft => {
draft.gateways = new Map(gws.map(g => [g.uri, g]));
});
} catch (error) {
this.notificationsService.notifyError({
title: 'Could not fetch databases',
description: error.message,
});
}
}

async syncKubes(clusterUri: string) {
Expand Down

0 comments on commit 9707ef9

Please # to comment.