raas-server
Version:
rhamt as a service server
87 lines • 3.75 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const raas_core_1 = require("raas-core");
class InstallationService {
constructor(clientService) {
this.installed = new Map();
this.installing = new Map();
this.clientService = clientService;
}
addInstallation(installation) {
this.installed.set(installation.id, installation);
this.notifyInstallationAdded(installation);
}
installServer(installRequest) {
const installingServer = {
id: raas_core_1.RhamtModelService.generateUniqueId(),
installServerRequest: installRequest,
installationStartedTimestamp: raas_core_1.RhamtModelService.getTimestamp(),
msg: '',
state: raas_core_1.Protocol.ServerState.PREPARING_INSTALLATION,
started: Date.now()
};
this.installing.set(installingServer.id, installingServer);
this.notifyInstallingServer(installingServer);
}
cancellInstallation(id) {
const installingServer = this.installing.get(id);
if (installingServer) {
this.installing.delete(id);
this.notifyCancelServerInstallation(installingServer);
return true;
}
return false;
}
deleteInstallation(id) {
const installation = this.installed.get(id);
if (installation) {
this.installed.delete(id);
this.notifyInstalledServerDeleted(installation);
return true;
}
return false;
}
updateInstallation(installation) {
if (this.installed.has(installation.id)) {
this.installed.set(installation.id, installation);
this.notifyInstalledServerUpdated(installation);
return true;
}
return false;
}
getInstallations() {
return Array.from(this.installed.values());
}
getInstalling() {
return Array.from(this.installing.values());
}
findInstallation(id) {
return this.installed.get(id);
}
notifyInstallationAdded(installation) {
this.clientService.notify(raas_core_1.Messages.Client.InstallationAddedNotification.type, installation);
}
notifyInstallingServer(installingServer) {
this.clientService.notify(raas_core_1.Messages.Client.InstallingServerNotification.type, installingServer);
}
// private notifyInstallServerMessage(data: {server: Protocol.ServerInstallation, msg: string}): void {
// this.clientService.notify(Messages.Client.InstallingServerMessageNotification.type, data);
// }
// private notifyInstallServerFailed(data: {server: Protocol.ServerInstallation, msg: string, code: any}): void {
// this.clientService.notify(Messages.Client.InstallingServerFailedNotification.type, data);
// }
notifyCancelServerInstallation(installation) {
this.clientService.notify(raas_core_1.Messages.Client.InstallingServerCancelledNotification.type, installation);
}
// private notifyInstallingServerCompleted(installing: Protocol.InstallingServer, installation: Protocol.Installation): void {
// this.clientService.notify(Messages.Client.InstallingServerCompletedNotification.type, {installing, installation});
// }
notifyInstalledServerDeleted(installation) {
this.clientService.notify(raas_core_1.Messages.Client.InstalledServerDeletedNotification.type, installation);
}
notifyInstalledServerUpdated(installation) {
this.clientService.notify(raas_core_1.Messages.Client.InstalledServerUpdatedNotification.type, installation);
}
}
exports.InstallationService = InstallationService;
//# sourceMappingURL=installationService.js.map