62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import * as plugins from '../plugins.js';
|
|
|
|
/**
|
|
* ClusterNode represents a logical node participating in a cluster
|
|
*/
|
|
@plugins.smartdata.Manager()
|
|
export class ClusterNode extends plugins.smartdata.SmartDataDbDoc<
|
|
ClusterNode,
|
|
plugins.servezoneInterfaces.data.IClusterNode
|
|
> {
|
|
// STATIC
|
|
public static async createFromHetznerServer(
|
|
hetznerServerArg: plugins.hetznercloud.HetznerServer,
|
|
clusterId: string,
|
|
baremetalId: string,
|
|
) {
|
|
const newNode = new ClusterNode();
|
|
newNode.id = plugins.smartunique.shortId(8);
|
|
const data: plugins.servezoneInterfaces.data.IClusterNode['data'] = {
|
|
clusterId: clusterId,
|
|
baremetalId: baremetalId,
|
|
nodeType: 'baremetal',
|
|
status: 'initializing',
|
|
role: 'worker',
|
|
joinedAt: Date.now(),
|
|
lastHealthCheck: Date.now(),
|
|
sshKeys: [],
|
|
requiredDebianPackages: [],
|
|
};
|
|
Object.assign(newNode, { data });
|
|
await newNode.save();
|
|
return newNode;
|
|
}
|
|
|
|
// INSTANCE
|
|
@plugins.smartdata.unI()
|
|
public id: string;
|
|
|
|
@plugins.smartdata.svDb()
|
|
public data: plugins.servezoneInterfaces.data.IClusterNode['data'];
|
|
|
|
constructor() {
|
|
super();
|
|
}
|
|
|
|
public async getDeployments(): Promise<plugins.servezoneInterfaces.data.IDeployment[]> {
|
|
// TODO: Implement getting deployments for this node
|
|
return [];
|
|
}
|
|
|
|
public async updateMetrics(metrics: plugins.servezoneInterfaces.data.IClusterNodeMetrics) {
|
|
this.data.metrics = metrics;
|
|
this.data.lastHealthCheck = Date.now();
|
|
await this.save();
|
|
}
|
|
|
|
public async updateStatus(status: plugins.servezoneInterfaces.data.IClusterNode['data']['status']) {
|
|
this.data.status = status;
|
|
await this.save();
|
|
}
|
|
}
|