raas-server
Version:
rhamt as a service server
175 lines • 11.2 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const raas_core_1 = require("raas-core");
const abstractHandler_1 = require("./abstractHandler");
class MessageHandler extends abstractHandler_1.AbstractHandler {
constructor(connection, runtimeService, installableServerService, installationService) {
super(connection);
this.runtimeService = runtimeService;
this.installableServerService = installableServerService;
this.installationService = installationService;
}
init() {
this.connection.onRequest(raas_core_1.Messages.Server.AddInstallableServerRequest.type, (params, token) => {
return this.accept(() => {
if (this.installableServerService.addInstallableServer(params)) {
console.log(`installable server added: ${JSON.stringify(params)}`);
return { code: 0, message: `installable server added ${params.id}`, ok: true };
}
else {
console.log(`unable to add installable server for: ${JSON.stringify(params)}`);
return { code: 0, message: `unable to add installable server for: ${params.id}`, ok: false };
}
}, null, `Error while adding installable server ${params.id}`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.UpdateInstallableServerRequest.type, (params, token) => {
return this.accept(() => {
if (this.installableServerService.updateInstallableServer(params)) {
console.log(`installable server updated: ${JSON.stringify(params)}`);
return { code: 0, message: `installable server updated ${params.id}`, ok: true };
}
else {
console.log(`unable to update installable server for: ${JSON.stringify(params)}`);
return { code: 0, message: `unable to update installable server for: ${params.id}`, ok: false };
}
}, null, `Error while updating installable server ${params.id}`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.DeleteInstallableServerRequest.type, (params, token) => {
return this.accept(() => {
if (this.installableServerService.deleteInstallableServer(params)) {
console.log(`installable server deleted: ${JSON.stringify(params)}`);
return { code: 0, message: `installable server deleted ${params.id}`, ok: true };
}
else {
console.log(`unable to delete installable server for: ${JSON.stringify(params)}`);
return { code: 0, message: `unable to delete installable server for: ${params.id}`, ok: false };
}
}, null, `Error while deleting installable server ${params.id}`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.GetInstallableServersRequest.type, (params, token) => {
return this.accept(() => {
return this.installableServerService.getInstallableServers();
}, null, `Error while getting installable servers.`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.AddInstalledServerRequest.type, (params, token) => {
return this.accept(() => {
this.installationService.addInstallation(params);
console.log(`server installation added: ${JSON.stringify(params)}`);
return { code: 0, message: `server installation added ${params.id}`, ok: true };
}, null, `Error while adding installed server ${params.id}`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.InstallServerRequest.type, (params, token) => {
return this.accept(() => {
const installable = this.installableServerService.getInstallableServer(params.installableServerId);
if (installable) {
this.installationService.installServer(params);
console.log(`installing server: ${JSON.stringify(params)}`);
return { code: 0, message: `installing server ${params.id}`, ok: true };
}
else {
console.log(`unable to find and install server for: ${JSON.stringify(params)}`);
return { code: 0, message: `unable to find and install server for: ${params.id}`, ok: false };
}
}, null, `Error while installing server ${params.id}`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.CancelServerInstallationRequest.type, (params, token) => {
return this.accept(() => {
const cancelling = this.installationService.cancellInstallation(params.id);
if (cancelling) {
console.log(`cancelling server installation: ${JSON.stringify(params)}`);
return { code: 0, message: `cancelling server installation ${params.id}`, ok: true };
}
else {
console.log(`unable to find installing server for: ${JSON.stringify(params)}`);
return { code: 0, message: `unable to find installing server for: ${params.id}`, ok: false };
}
}, null, `Error while cancelling server installation ${params.id}`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.DeleteServerInstallationRequest.type, (params, token) => {
return this.accept(() => {
const deleting = this.installationService.deleteInstallation(params.id);
if (deleting) {
console.log(`deleting server installation: ${JSON.stringify(params)}`);
return { code: 0, message: `deleting server installation ${params.id}`, ok: true };
}
else {
console.log(`unable to find server installation to delete: ${JSON.stringify(params)}`);
return { code: 0, message: `unable to delete server installation (not found): ${params.id}`, ok: false };
}
}, null, `Error while deleting server installation ${params.id}`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.UpdateServerInstallationRequest.type, (params, token) => {
return this.accept(() => {
if (this.installationService.updateInstallation(params)) {
console.log(`installation updated: ${JSON.stringify(params)}`);
return { code: 0, message: `installation updated ${params.id}`, ok: true };
}
else {
console.log(`unable to update server installation for: ${JSON.stringify(params)}`);
return { code: 0, message: `unable to update server installation for: ${params.id}`, ok: false };
}
}, null, `Error while updating installation ${params.id}`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.GetInstalledServersRequest.type, (params, token) => {
return this.accept(() => {
return this.installationService.getInstallations();
}, null, `Error while getting installed servers.`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.GetInstallingServersRequest.type, (params, token) => {
return this.accept(() => {
return this.installationService.getInstalling();
}, null, `Error while getting installing servers.`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.StartServerRequest.type, (params, token) => {
return this.accept(() => {
// const installation = this.installationService.findInstallation(params.installationId);
// if (installation) {
this.runtimeService.startServer(params, params.installation);
console.log(`starting server using config: ${JSON.stringify(params)}`);
return { code: 0, message: `starting server for ${params.id}`, ok: true };
}, null, `Error while starting server ${params.id}`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.GetServerHandlesRequest.type, (params, token) => {
return this.accept(() => {
return this.runtimeService.getServerHandles();
}, null, `Error while getting server handles.`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.StopServerRequest.type, (params, token) => {
return this.accept(() => {
this.runtimeService.stopServer(params);
console.log(`stopping server using config: ${JSON.stringify(params)}`);
return { code: 0, message: `stopping server for ${params}`, ok: true };
}, null, `Error while stopping server.`, token);
});
this.connection.onRequest(raas_core_1.Messages.Server.StartAnalaysisRequest.type, (params, token) => __awaiter(this, void 0, void 0, function* () {
return this.accept(() => __awaiter(this, void 0, void 0, function* () {
if (this.runtimeService.analyze(params)) {
return { code: 0, message: `Analysis started.`, ok: true };
}
}), null, `Error while starting analysis ${params.id}`, token);
}));
this.connection.onRequest(raas_core_1.Messages.Server.CancelAnalaysisRequest.type, (params, token) => __awaiter(this, void 0, void 0, function* () {
return this.accept(() => __awaiter(this, void 0, void 0, function* () {
if (this.runtimeService.cancelAnalysis(params)) {
console.log('cancelling analysis');
return { code: 0, message: `cancelling analysis.`, ok: true };
}
}), null, `Error while cancelling analysis ${params.id}`, token);
}));
this.connection.onRequest(raas_core_1.Messages.Server.GetAllAnalysesRequest.type, (params, token) => {
return this.accept(() => {
return this.runtimeService.getAllAnalyses();
}, null, `Error while getting all analyses.`, token);
});
}
}
exports.MessageHandler = MessageHandler;
//# sourceMappingURL=messageHandler.js.map