feat(settings): Add runtime settings management, node & baremetal managers, and settings UI
This commit is contained in:
61
ts/manager.node/classes.clusternode.ts
Normal file
61
ts/manager.node/classes.clusternode.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user