@multicloud-io/multicloud-connection-js
Version:
Shared TypeScript/JavaScript library for connecting to Multicloud servers with mTLS authentication
306 lines • 7.33 kB
TypeScript
/**
* Multicloud REST API client
*
* Provides a comprehensive client for interacting with Multicloud servers
* with mTLS authentication and proper error handling.
*
* IMPORTANT: This is for server-side use only - never expose to client/browser!
*/
import { MulticloudConnectionParams } from './config';
/**
* Cluster data structure from Multicloud API
*/
export interface Cluster {
id: number;
name: string;
region?: string;
enabled: boolean;
applicationId?: number;
[key: string]: any;
}
/**
* Job data structure from Multicloud API
*/
export interface Job {
id?: number;
name: string;
status?: string;
clusterId?: number;
state?: State;
minMemMb?: number;
targetInstanceCount?: number;
availability?: number;
priority?: number;
envVars?: {
[key: string]: string;
};
command?: string;
image: string;
sdnRequired?: boolean;
sdnUniqueNamePerTask?: boolean;
services?: Service[];
volumes?: VolumeDesc[];
capabilities?: string;
options?: string;
hostname: string;
network?: string;
orchestration?: Orchestration;
constraints?: any;
longRunning?: boolean;
reqAccelerator?: string;
reqAcceleratorMemMb?: number;
reqAcceleratorNum?: number;
minMultiCoreBench?: number;
networkAliases?: string[];
lastRun?: string;
cronSchedule?: string;
schedulingMetadata?: {
[key: string]: any;
};
[key: string]: any;
}
/**
* Server data structure from Multicloud API
*/
export interface Server {
hostId: string;
status: string;
clusterId: number;
publicIp?: string;
privateIp?: string;
sdnIp?: string;
totalMemoryMb?: number;
availableMemoryMb?: number;
cpuLoad5Min?: number;
metricsLastUpdated?: string;
logicalProcessors?: number;
physicalProcessors?: number;
[key: string]: any;
}
/**
* State of the job
*/
export declare enum State {
LOADED = "LOADED",
STARTING = "STARTING",
RUNNING = "RUNNING",
STOPPING = "STOPPING",
STOPPED = "STOPPED",
PENDING_DESTROY = "PENDING_DESTROY",
FINISHED = "FINISHED"
}
/**
* Service data structure from Multicloud API
*/
export interface Service {
frontend: string;
backendName: string;
backendPort: number;
domain?: string;
urlReg?: string;
httpCheck?: string;
httpCheckOptions?: string;
authentication?: string;
}
/**
* Upstream data structure from Multicloud API
*/
export interface Upstream {
name: string;
address: string;
service?: Service;
task?: Task;
}
/**
* IpLease data structure from Multicloud API
*/
export interface IpLease {
ip: number;
name: string;
subnetName: string;
cidr: string;
metadata?: {
[key: string]: any;
};
}
/**
* Volume data structure from Multicloud API
*/
export interface VolumeDesc {
hostPath: string;
containerPath: string;
source: string;
accessMode?: 'rw' | 'ro';
syncMode?: 'NEVER' | 'ON_EXIT' | 'CONTINUOUS' | 'PERIODIC';
preSyncCommand?: string;
postSyncCommand?: string;
}
/**
* Orchestration types
*/
export declare enum Orchestration {
EXTERNAL = "EXTERNAL",
ALL = "ALL",
EXACTLY = "EXACTLY",
EXACTLY_ONCE = "EXACTLY_ONCE",
ACTIVE_STANDBY = "ACTIVE_STANDBY"
}
/**
* Task data structure from Multicloud API
*/
export interface Task {
id: number;
server?: Server;
job?: Job;
upstreams?: any[];
ipLease?: any;
sequence: number;
extra?: {
[key: string]: string;
};
memLimitMb: number;
status: TaskStatus;
statsCpu: number;
statsMemUsage: number;
statsMemLimit: number;
statsNetIn: number;
statsNetOut: number;
statsBlockIn: number;
statsBlockOut: number;
statsCpuUsageRaw: number;
statsSystemCpuUsageRaw: number;
[key: string]: any;
}
/**
* Status of the task
*/
export declare enum TaskStatus {
UNKNOWN = "UNKNOWN",
STARTING = "STARTING",
STANDBY = "STANDBY",
RUNNING = "RUNNING",
RESTARTING = "RESTARTING",
STOPPING = "STOPPING",
STOPPED = "STOPPED",
DONE = "DONE",
ERROR = "ERROR",
PENDING_SHUTDOWN = "PENDING_SHUTDOWN",
PENDING_RESTART = "PENDING_RESTART",
CANCELLED = "CANCELLED"
}
/**
* MetaLocation summary for a cluster (id, name, region, url)
*/
export interface Location {
id: number;
name: string;
region: string;
pingUrl: string | null;
clientPingLatency?: number;
}
/**
* REST client for Multicloud API
*/
export declare class MulticloudRESTClient {
private agent;
private baseUrl;
private timeout;
private debug;
private accessToken?;
constructor(params: MulticloudConnectionParams);
/**
* Make an HTTP request to the Multicloud API
*/
private makeRequest;
/**
* Update the access token for subsequent requests
* @param accessToken New JWT access token
*/
setAccessToken(accessToken: string): void;
/**
* Clear the access token
*/
clearAccessToken(): void;
/**
* Test connection to the Multicloud server
*/
testConnection(): Promise<boolean>;
/** get tasks for a cluster, or if null or it "*" for all clusters */
getTasks(clusterId: string | null): Promise<Task[]>;
/**
* Get all clusters
*/
getClusters(): Promise<Cluster[]>;
/**
* Get clusters for a specific application - Uses application-specific filtering
*/
getApplicationClusters(applicationId: number): Promise<Cluster[]>;
/**
* Get a specific cluster by ID
*/
getCluster(clusterId: number): Promise<Cluster>;
/**
* Get all jobs
*/
getJobs(): Promise<Job[]>;
/**
* Get jobs for a specific cluster
*/
getClusterJobs(clusterId: number): Promise<Job[]>;
/**
* Get a specific job by ID
*/
getJob(jobId: number): Promise<Job>;
/**
* Create a new job
*/
createJob(clusterId: number, jobData: Partial<Job>): Promise<Job>;
/**
* Update a job
*/
updateJob(action: 'start' | 'stop' | 'destroy', jobId: string, clusterId?: string): Promise<Response>;
/**
* Delete a job
*/
deleteJob(jobId: number): Promise<void>;
/**
* Get all servers
*/
getServers(): Promise<Server[]>;
/**
* Get servers for a specific cluster
*/
getClusterServers(clusterId: number): Promise<Server[]>;
/**
* Get a specific server by ID
*/
getServer(serverId: number): Promise<Server>;
/**
* Create a new server
*/
createServer(serverData: Partial<Server>): Promise<Server>;
/**
* Update a server
*/
updateServer(serverId: number, serverData: Partial<Server>): Promise<Server>;
/**
* Delete a server
*/
deleteServer(serverId: number): Promise<void>;
/**
* Get server status
*/
getServerStatus(serverId: number): Promise<{
status: string;
[key: string]: any;
}>;
/**
* Restart a server
*/
restartServer(serverId: number): Promise<void>;
/**
* Get all MetaLocations for a cluster (id, name, region, url)
*/
getClusterLocations(clusterId: string | number): Promise<Location[]>;
}
//# sourceMappingURL=client.d.ts.map