Implement processor switching

This commit is contained in:
David Majdandžić
2023-04-03 20:25:12 +02:00
parent 3856fcecbd
commit e2a7c52541
6 changed files with 24 additions and 15 deletions

View File

@@ -142,6 +142,7 @@ export class Center extends SmppSession {
defaultSingleJob: this._defaultSingleJob.serialize(), defaultSingleJob: this._defaultSingleJob.serialize(),
defaultMultipleJob: this._defaultMultipleJob.serialize(), defaultMultipleJob: this._defaultMultipleJob.serialize(),
processors: this.pduProcessors.map(p => p.serialize()), processors: this.pduProcessors.map(p => p.serialize()),
availableProcessors: PduProcessor.getProcessorsForType(Center.name)
}; };
} }

View File

@@ -1,3 +1,4 @@
import {Center} from "../Center/Center";
import {PDU} from "../CommonObjects"; import {PDU} from "../CommonObjects";
import {Job} from "../Job/Job"; import {Job} from "../Job/Job";
import Logger from "../Logger"; import Logger from "../Logger";
@@ -120,6 +121,7 @@ export class Client extends SmppSession {
defaultSingleJob: this._defaultSingleJob.serialize(), defaultSingleJob: this._defaultSingleJob.serialize(),
defaultMultipleJob: this._defaultMultipleJob.serialize(), defaultMultipleJob: this._defaultMultipleJob.serialize(),
processors: this.pduProcessors.map(p => p.serialize()), processors: this.pduProcessors.map(p => p.serialize()),
availableProcessors: PduProcessor.getProcessorsForType(Client.name)
}; };
} }

View File

@@ -30,7 +30,7 @@ export class CenterRequestHandler extends RequestHandler {
doAddProcessor(req: any, res: any): void { doAddProcessor(req: any, res: any): void {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => { this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
let processor = PduProcessor.getProcessor(req.body.name); let processor: PduProcessor = PduProcessor.getProcessor(req.body.name);
PduProcessor.attachProcessor(session, processor); PduProcessor.attachProcessor(session, processor);
res.send(session.serialize()); res.send(session.serialize());
}, this.handleSessionNotFound.bind(this, req, res)); }, this.handleSessionNotFound.bind(this, req, res));
@@ -38,7 +38,7 @@ export class CenterRequestHandler extends RequestHandler {
doRemoveProcessor(req: any, res: any): void { doRemoveProcessor(req: any, res: any): void {
this.sessionManager.getSession(req.params.id).then((session: SmppSession) => { this.sessionManager.getSession(req.params.id).then((session: SmppSession) => {
let processor = PduProcessor.getProcessor(req.body.name); let processor: PduProcessor = PduProcessor.getProcessor(req.body.name);
PduProcessor.detachProcessor(session, processor); PduProcessor.detachProcessor(session, processor);
res.send(session.serialize()); res.send(session.serialize());
}, this.handleSessionNotFound.bind(this, req, res)); }, this.handleSessionNotFound.bind(this, req, res));

View File

@@ -15,19 +15,19 @@ export default class ClientRequestHandler extends RequestHandler {
} }
doGetAvailableProcessors(req: any, res: any): void { doGetAvailableProcessors(req: any, res: any): void {
throw new Error("Method not implemented."); res.send([]);
} }
doGetAppliedProcessors(req: any, res: any): void { doGetAppliedProcessors(req: any, res: any): void {
throw new Error("Method not implemented."); res.send([]);
} }
doAddProcessor(req: any, res: any): void { doAddProcessor(req: any, res: any): void {
throw new Error("Method not implemented."); res.send([]);
} }
doRemoveProcessor(req: any, res: any): void { doRemoveProcessor(req: any, res: any): void {
throw new Error("Method not implemented."); res.send([]);
} }
doPost(req: any, res: any): void { doPost(req: any, res: any): void {

View File

@@ -36,8 +36,6 @@ export class HttpServer {
this.app.get(`/api/${clientApiPath}`, this.clientRequestHandler.doGet.bind(this.clientRequestHandler)); this.app.get(`/api/${clientApiPath}`, this.clientRequestHandler.doGet.bind(this.clientRequestHandler));
this.app.post(`/api/${clientApiPath}`, this.clientRequestHandler.doPost.bind(this.clientRequestHandler)); this.app.post(`/api/${clientApiPath}`, this.clientRequestHandler.doPost.bind(this.clientRequestHandler));
this.app.get(`/api/${clientApiPath}/:id`, this.clientRequestHandler.doGetById.bind(this.clientRequestHandler));
this.app.patch(`/api/${clientApiPath}/:id`, this.clientRequestHandler.doPatch.bind(this.clientRequestHandler));
this.app.put(`/api/${clientApiPath}/:id/send`, this.clientRequestHandler.doConfigureSingleJob.bind(this.clientRequestHandler)); this.app.put(`/api/${clientApiPath}/:id/send`, this.clientRequestHandler.doConfigureSingleJob.bind(this.clientRequestHandler));
this.app.post(`/api/${clientApiPath}/:id/send/default`, this.clientRequestHandler.doSendSingleJob.bind(this.clientRequestHandler)); this.app.post(`/api/${clientApiPath}/:id/send/default`, this.clientRequestHandler.doSendSingleJob.bind(this.clientRequestHandler));
this.app.post(`/api/${clientApiPath}/:id/send`, this.clientRequestHandler.doSend.bind(this.clientRequestHandler)); this.app.post(`/api/${clientApiPath}/:id/send`, this.clientRequestHandler.doSend.bind(this.clientRequestHandler));
@@ -48,12 +46,17 @@ export class HttpServer {
this.app.post(`/api/${clientApiPath}/:id/bind`, this.clientRequestHandler.doBind.bind(this.clientRequestHandler)); this.app.post(`/api/${clientApiPath}/:id/bind`, this.clientRequestHandler.doBind.bind(this.clientRequestHandler));
this.app.post(`/api/${clientApiPath}/:id/connect`, this.clientRequestHandler.doConnect.bind(this.clientRequestHandler)); this.app.post(`/api/${clientApiPath}/:id/connect`, this.clientRequestHandler.doConnect.bind(this.clientRequestHandler));
this.app.delete(`/api/${clientApiPath}/:id/connect`, this.clientRequestHandler.doDisconnect.bind(this.clientRequestHandler)); this.app.delete(`/api/${clientApiPath}/:id/connect`, this.clientRequestHandler.doDisconnect.bind(this.clientRequestHandler));
this.app.get(`/api/${clientApiPath}/processors`, this.clientRequestHandler.doGetAvailableProcessors.bind(this.clientRequestHandler));
this.app.get(`/api/${clientApiPath}/:id/processors`, this.clientRequestHandler.doGetAppliedProcessors.bind(this.clientRequestHandler));
this.app.post(`/api/${clientApiPath}/:id/processors`, this.clientRequestHandler.doAddProcessor.bind(this.clientRequestHandler));
this.app.delete(`/api/${clientApiPath}/:id/processors`, this.clientRequestHandler.doRemoveProcessor.bind(this.clientRequestHandler));
this.app.get(`/api/${clientApiPath}/:id`, this.clientRequestHandler.doGetById.bind(this.clientRequestHandler));
this.app.patch(`/api/${clientApiPath}/:id`, this.clientRequestHandler.doPatch.bind(this.clientRequestHandler));
this.app.delete(`/api/${clientApiPath}/:id`, this.clientRequestHandler.doDelete.bind(this.clientRequestHandler)); this.app.delete(`/api/${clientApiPath}/:id`, this.clientRequestHandler.doDelete.bind(this.clientRequestHandler));
this.app.get(`/api/${centerApiPath}`, this.centerRequestHandler.doGet.bind(this.centerRequestHandler)); this.app.get(`/api/${centerApiPath}`, this.centerRequestHandler.doGet.bind(this.centerRequestHandler));
this.app.post(`/api/${centerApiPath}`, this.centerRequestHandler.doPost.bind(this.centerRequestHandler)); this.app.post(`/api/${centerApiPath}`, this.centerRequestHandler.doPost.bind(this.centerRequestHandler));
this.app.get(`/api/${centerApiPath}/:id`, this.centerRequestHandler.doGetById.bind(this.centerRequestHandler));
this.app.patch(`/api/${centerApiPath}/:id`, this.centerRequestHandler.doPatch.bind(this.centerRequestHandler));
this.app.put(`/api/${centerApiPath}/:id/send`, this.centerRequestHandler.doConfigureSingleJob.bind(this.centerRequestHandler)); this.app.put(`/api/${centerApiPath}/:id/send`, this.centerRequestHandler.doConfigureSingleJob.bind(this.centerRequestHandler));
this.app.post(`/api/${centerApiPath}/:id/send/default`, this.centerRequestHandler.doSendSingleJob.bind(this.centerRequestHandler)); this.app.post(`/api/${centerApiPath}/:id/send/default`, this.centerRequestHandler.doSendSingleJob.bind(this.centerRequestHandler));
this.app.post(`/api/${centerApiPath}/:id/send`, this.centerRequestHandler.doSend.bind(this.centerRequestHandler)); this.app.post(`/api/${centerApiPath}/:id/send`, this.centerRequestHandler.doSend.bind(this.centerRequestHandler));
@@ -62,11 +65,14 @@ export class HttpServer {
this.app.post(`/api/${centerApiPath}/:id/sendMany`, this.centerRequestHandler.doSendMany.bind(this.centerRequestHandler)); this.app.post(`/api/${centerApiPath}/:id/sendMany`, this.centerRequestHandler.doSendMany.bind(this.centerRequestHandler));
this.app.delete(`/api/${centerApiPath}/:id/sendMany`, this.centerRequestHandler.doCancelSendMany.bind(this.centerRequestHandler)); this.app.delete(`/api/${centerApiPath}/:id/sendMany`, this.centerRequestHandler.doCancelSendMany.bind(this.centerRequestHandler));
this.app.delete(`/api/${centerApiPath}/:id/connect`, this.centerRequestHandler.doDisconnect.bind(this.centerRequestHandler)); this.app.delete(`/api/${centerApiPath}/:id/connect`, this.centerRequestHandler.doDisconnect.bind(this.centerRequestHandler));
this.app.get(`/api/${centerApiPath}/processors`, this.centerRequestHandler.doGetAvailableProcessors.bind(this.centerRequestHandler));
this.app.get(`/api/${centerApiPath}/:id/processors`, this.centerRequestHandler.doGetAppliedProcessors.bind(this.centerRequestHandler));
this.app.post(`/api/${centerApiPath}/:id/processors`, this.centerRequestHandler.doAddProcessor.bind(this.centerRequestHandler));
this.app.delete(`/api/${centerApiPath}/:id/processors`, this.centerRequestHandler.doRemoveProcessor.bind(this.centerRequestHandler));
this.app.get(`/api/${centerApiPath}/:id`, this.centerRequestHandler.doGetById.bind(this.centerRequestHandler));
this.app.patch(`/api/${centerApiPath}/:id`, this.centerRequestHandler.doPatch.bind(this.centerRequestHandler));
this.app.delete(`/api/${centerApiPath}/:id`, this.centerRequestHandler.doDelete.bind(this.centerRequestHandler)); this.app.delete(`/api/${centerApiPath}/:id`, this.centerRequestHandler.doDelete.bind(this.centerRequestHandler));
this.app.get(`/api/${centerApiPath}/processors`, this.centerRequestHandler.doGetAppliedProcessors.bind(this.centerRequestHandler));
this.app.get(`/api/${centerApiPath}/processors/all`, this.centerRequestHandler.doGetAvailableProcessors.bind(this.centerRequestHandler));
this.app.post(`/api/${centerApiPath}/processors`, this.centerRequestHandler.doAddProcessor.bind(this.centerRequestHandler));
this.app.delete(`/api/${centerApiPath}/processors`, this.centerRequestHandler.doRemoveProcessor.bind(this.centerRequestHandler));
this.app.get('/api/ping', function (req: any, res: any) { this.app.get('/api/ping', function (req: any, res: any) {
res.send('pong'); res.send('pong');

View File

@@ -167,7 +167,7 @@ export abstract class SmppSession {
} }
removePduProcessor(pduProcessor: PduProcessor): void { removePduProcessor(pduProcessor: PduProcessor): void {
this.pduProcessors = this.pduProcessors.splice(this.pduProcessors.indexOf(pduProcessor), 1); this.pduProcessors.splice(this.pduProcessors.indexOf(pduProcessor), 1);
this.logger.log1(`Removing PDU processor: ${pduProcessor.constructor.name}-${this.id}, now active: ${this.pduProcessors.length} processors`); this.logger.log1(`Removing PDU processor: ${pduProcessor.constructor.name}-${this.id}, now active: ${this.pduProcessors.length} processors`);
this.eventEmitter.emit(this.EVENT.STATE_CHANGED, this.serialize()); this.eventEmitter.emit(this.EVENT.STATE_CHANGED, this.serialize());
} }