coreflow/ts/coreflow.classes.coreflow.ts

76 lines
2.5 KiB
TypeScript
Raw Normal View History

2024-05-08 22:05:16 +00:00
import * as plugins from './coreflow.plugins.js';
import { logger } from './coreflow.logging.js';
import { CloudlyConnector } from './coreflow.connector.cloudlyconnector.js';
import { ClusterManager } from './coreflow.classes.clustermanager.js';
import { CoreflowTaskmanager } from './coreflow.classes.taskmanager.js';
import { CoretrafficConnector } from './coreflow.connector.coretrafficconnector.js';
import { InternalServer } from './coreflow.classes.internalserver.js';
/**
* the main Coreflow class
*/
export class Coreflow {
public typedrouter = new plugins.typedrequest.TypedRouter();
public internalServer: InternalServer;
public serviceQenv: plugins.qenv.Qenv;
public dockerHost: plugins.docker.DockerHost;
public cloudlyConnector: CloudlyConnector;
public corechatConnector: CoretrafficConnector;
public clusterManager: ClusterManager;
public taskManager: CoreflowTaskmanager;
constructor() {
this.serviceQenv = new plugins.qenv.Qenv('./', './.nogit');
this.dockerHost = new plugins.docker.DockerHost({}); // defaults to locally mounted docker sock
2024-05-08 22:05:16 +00:00
this.internalServer = new InternalServer(this);
this.cloudlyConnector = new CloudlyConnector(this);
this.corechatConnector = new CoretrafficConnector(this);
this.clusterManager = new ClusterManager(this);
this.taskManager = new CoreflowTaskmanager(this);
}
/**
* will handle Docker Events
*/
public async handleDockerEvents() {
const eventObservable = await this.dockerHost.getEventObservable();
const eventSubscription = eventObservable.subscribe((event) => {
logger.log('info', `Docker event of type ${event.Type}`);
if (
event.Type === 'image' ||
event.Type === 'network' ||
event.Type === 'container' ||
event.Type === 'service' ||
event.Type === 'node'
) {
console.log('got docker event, but for now not doing anything');
}
});
}
/**
* starts the coreflow instance
*/
public async start() {
await this.internalServer.start();
console.log('internal server started!');
await this.cloudlyConnector.start();
console.log('cloudly connector started!');
await this.clusterManager.start();
console.log('cluster manager started!');
await this.taskManager.start();
console.log('task manager started!');
}
/**
* stops the coreflow instance
*/
public async stop() {
await this.cloudlyConnector.stop();
await this.clusterManager.stop();
await this.taskManager.stop();
await this.internalServer.stop();
}
}