cluster-ipc refactoring

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman committed 2020-07-21 13:04:33 +03:00
1 parent c0c1c227ca
commit 70bbb9fa62
10 files changed
+76 -53

No files matched your search

+5 -26
View File
@@ -2,10 +2,9 @@ import type http from "http"
import { autorun, reaction } from "mobx";
import { apiKubePrefix } from "../common/vars";
import { ClusterId, clusterStore } from "../common/cluster-store"
import { handleIpc } from "../common/ipc";
import { Cluster, ClusterIpcChannel } from "./cluster"
import { Cluster } from "./cluster"
import { clusterIpc } from "../common/cluster-ipc";
import logger from "./logger";
import { tracker } from "../common/tracker";
export class ClusterManager {
protected activeClusterId: ClusterId;
@@ -53,9 +52,9 @@ export class ClusterManager {
});
// listen for ipc-events that must/can be handled *only* in main-process (nodeIntegration=true)
handleIpc(ClusterIpcChannel.INIT, this.onClusterInit);
handleIpc(ClusterIpcChannel.DISCONNECT, this.onClusterDisconnect);
handleIpc(ClusterIpcChannel.RECONNECT, this.onClusterReconnect);
clusterIpc.refresh.handleInMain();
clusterIpc.disconnect.handleInMain();
clusterIpc.reconnect.handleInMain();
}
stop() {
@@ -64,26 +63,6 @@ export class ClusterManager {
})
}
protected onClusterInit = async (id = clusterStore.activeClusterId) => {
const cluster = this.getCluster(id);
if (cluster) {
logger.info(`[CLUSTER-MANAGER]: init cluster`, cluster.getMeta());
tracker.event("cluster", "activate");
await cluster.refreshStatus();
cluster.pushState();
}
}
protected onClusterDisconnect = (id: ClusterId) => {
tracker.event("cluster", "stop");
this.getCluster(id)?.disconnect();
}
protected onClusterReconnect = (id: ClusterId) => {
tracker.event("cluster", "reconnect");
this.getCluster(id)?.reconnect();
}
protected getCluster(id: ClusterId) {
return clusterStore.getById(id);
}
+3 -7
View File
@@ -13,12 +13,6 @@ import { getFeatures, installFeature, uninstallFeature, upgradeFeature } from ".
import request, { RequestPromiseOptions } from "request-promise-native"
import logger from "./logger"
export enum ClusterIpcChannel {
INIT = "cluster:init",
DISCONNECT = "cluster:disconnect",
RECONNECT = "cluster:reconnect",
}
export enum ClusterStatus {
AccessGranted = 2,
AccessDenied = 1,
@@ -341,7 +335,7 @@ export class Cluster implements ClusterModel {
}
pushState = (clusterState = this.getState()) => {
logger.info(`[CLUSTER]: push-state`, clusterState);
logger.debug(`[CLUSTER]: push-state`, clusterState);
broadcastIpc({
// webContentId: viewId, // todo: send to cluster-view only
channel: "cluster:state",
@@ -354,6 +348,8 @@ export class Cluster implements ClusterModel {
return {
id: this.id,
name: this.contextName,
initialized: this.initialized,
accessible: this.accessible,
}
}
}