Skip to content

Commit 29b0a81

Browse files
committed
feat(core-api): discontinue dedicated HTTP listeners for web service plugins
Fixes hyperledger-cacti#358 Signed-off-by: TonyRowntree [email protected] Signed-off-by: Youngone Lee <[email protected]>
1 parent e2fc14f commit 29b0a81

File tree

20 files changed

+10
-373
lines changed

20 files changed

+10
-373
lines changed

examples/cactus-example-carbon-accounting-business-logic-plugin/src/main/typescript/business-logic-plugin/carbon-accounting-plugin.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import { Server } from "http";
2-
import { Server as SecureServer } from "https";
3-
4-
import { Optional } from "typescript-optional";
51
import { Express } from "express";
62
import { v4 as uuidv4 } from "uuid";
73

@@ -132,10 +128,6 @@ export class CarbonAccountingPlugin
132128
return theEndpoints;
133129
}
134130

135-
public getHttpServer(): Optional<Server | SecureServer> {
136-
return Optional.empty();
137-
}
138-
139131
public async shutdown(): Promise<void> {
140132
this.log.info(`Shutting down ${this.className}...`);
141133
}

examples/cactus-example-supply-chain-business-logic-plugin/src/main/typescript/business-logic-plugin/supply-chain-cactus-plugin.ts

-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import type { Server } from "http";
2-
import type { Server as SecureServer } from "https";
3-
import { Optional } from "typescript-optional";
41
import { Express } from "express";
52
import OAS from "../../json/openapi.json";
63
import {
@@ -152,10 +149,6 @@ export class SupplyChainCactusPlugin
152149
return this.endpoints;
153150
}
154151

155-
public getHttpServer(): Optional<Server | SecureServer> {
156-
return Optional.empty();
157-
}
158-
159152
public async shutdown(): Promise<void> {
160153
this.log.info(`Shutting down ${this.className}...`);
161154
}

extensions/cactus-plugin-object-store-ipfs/src/main/typescript/plugin-object-store-ipfs.ts

-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import path from "path";
2-
import type { Server } from "http";
3-
import type { Server as SecureServer } from "https";
42
import type { Express } from "express";
53
import { create } from "ipfs-http-client";
64
import type { Options } from "ipfs-http-client";
7-
import { Optional } from "typescript-optional";
85
import { RuntimeError } from "run-time-error";
96
import { Logger, Checks, LoggerProvider } from "@hyperledger/cactus-common";
107
import type { LogLevelDesc } from "@hyperledger/cactus-common";
@@ -186,10 +183,6 @@ export class PluginObjectStoreIpfs implements IPluginObjectStore {
186183
};
187184
}
188185

189-
public getHttpServer(): Optional<Server | SecureServer> {
190-
return Optional.empty();
191-
}
192-
193186
public async shutdown(): Promise<void> {
194187
this.log.info(`Shutting down ${this.className}...`);
195188
}

packages/cactus-cmd-api-server/src/test/typescript/fixtures/plugin-ledger-connector-stub/plugin-ledger-connector-stub.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { Server } from "http";
2-
import { Server as SecureServer } from "https";
3-
41
import { Express } from "express";
5-
import { Optional } from "typescript-optional";
62

73
import {
84
ConsensusAlgorithmFamily,
@@ -74,10 +70,6 @@ export class PluginLedgerConnectorStub
7470
return this.instanceId;
7571
}
7672

77-
public getHttpServer(): Optional<Server | SecureServer> {
78-
return Optional.empty();
79-
}
80-
8173
public async onPluginInit(): Promise<unknown> {
8274
return;
8375
}

packages/cactus-core-api/src/main/typescript/plugin/web-service/i-plugin-web-service.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import type { Server } from "http";
2-
import type { Server as SecureServer } from "https";
3-
import type { Optional } from "typescript-optional";
41
import type { Application } from "express";
52
import { IWebServiceEndpoint } from "./i-web-service-endpoint";
63
import { ICactusPlugin } from "../i-cactus-plugin";
@@ -13,8 +10,6 @@ export interface IPluginWebService extends ICactusPlugin {
1310
expressApp: Application,
1411
wsApi: SocketIoServer,
1512
): Promise<IWebServiceEndpoint[]>;
16-
17-
getHttpServer(): Optional<Server | SecureServer>;
1813
shutdown(): Promise<void>;
1914
getOpenApiSpec(): unknown;
2015
}
@@ -24,7 +19,6 @@ export function isIPluginWebService(x: unknown): x is IPluginWebService {
2419
!!x &&
2520
typeof (x as IPluginWebService).registerWebServices === "function" &&
2621
typeof (x as IPluginWebService).getOrCreateWebServices === "function" &&
27-
typeof (x as IPluginWebService).getHttpServer === "function" &&
2822
typeof (x as IPluginWebService).getPackageName === "function" &&
2923
typeof (x as IPluginWebService).getInstanceId === "function" &&
3024
typeof (x as IPluginWebService).shutdown === "function" &&

packages/cactus-plugin-consortium-manual/src/main/typescript/plugin-consortium-manual.ts

+6-49
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import { Server } from "http";
2-
import { Server as SecureServer } from "https";
3-
import { Optional } from "typescript-optional";
4-
import { promisify } from "util";
5-
import express, { Express } from "express";
6-
import bodyParser from "body-parser";
1+
import { Express } from "express";
72
import { JWS, JWK } from "jose";
83
import jsonStableStringify from "json-stable-stringify";
94
import { v4 as uuidv4 } from "uuid";
@@ -53,7 +48,6 @@ export interface IPluginConsortiumManualOptions extends ICactusPluginOptions {
5348
prometheusExporter?: PrometheusExporter;
5449
pluginRegistry?: PluginRegistry;
5550
logLevel?: LogLevelDesc;
56-
webAppOptions?: IWebAppOptions;
5751
}
5852

5953
export class PluginConsortiumManual
@@ -64,7 +58,6 @@ export class PluginConsortiumManual
6458
private readonly instanceId: string;
6559
private readonly repo: ConsortiumRepository;
6660
private endpoints: IWebServiceEndpoint[] | undefined;
67-
private httpServer: Server | SecureServer | null = null;
6861

6962
public get className(): string {
7063
return PluginConsortiumManual.CLASS_NAME;
@@ -116,6 +109,10 @@ export class PluginConsortiumManual
116109
return this.prometheusExporter;
117110
}
118111

112+
public async shutdown(): Promise<void> {
113+
return;
114+
}
115+
119116
public async getPrometheusExporterMetrics(): Promise<string> {
120117
const res: string = await this.prometheusExporter.getPrometheusMetrics();
121118
this.log.debug(`getPrometheusExporterMetrics() response: %o`, res);
@@ -137,47 +134,11 @@ export class PluginConsortiumManual
137134
this.prometheusExporter.setNodeCount(nodeCount);
138135
}
139136

140-
public async shutdown(): Promise<void> {
141-
this.log.info(`Shutting down...`);
142-
const serverMaybe = this.getHttpServer();
143-
if (serverMaybe.isPresent()) {
144-
this.log.info(`Awaiting server.close() ...`);
145-
const server = serverMaybe.get();
146-
await promisify(server.close.bind(server))();
147-
this.log.info(`server.close() OK`);
148-
} else {
149-
this.log.info(`No HTTP server found, skipping...`);
150-
}
151-
}
152-
153137
public async registerWebServices(
154138
app: Express,
155139
): Promise<IWebServiceEndpoint[]> {
156-
const webApp: Express = this.options.webAppOptions ? express() : app;
157-
158-
if (this.options.webAppOptions) {
159-
this.log.info(`Creating dedicated HTTP server...`);
160-
const { port, hostname } = this.options.webAppOptions;
161-
162-
webApp.use(bodyParser.json({ limit: "50mb" }));
163-
164-
const address = await new Promise((resolve, reject) => {
165-
const httpServer = webApp.listen(port, hostname, (err?: any) => {
166-
if (err) {
167-
reject(err);
168-
this.log.error(`Failed to create dedicated HTTP server`, err);
169-
} else {
170-
this.httpServer = httpServer;
171-
const theAddress = this.httpServer.address();
172-
resolve(theAddress);
173-
}
174-
});
175-
});
176-
this.log.info(`Creation of HTTP server OK`, { address });
177-
}
178-
179140
const webServices = await this.getOrCreateWebServices();
180-
webServices.forEach((ws) => ws.registerExpress(webApp));
141+
webServices.forEach((ws) => ws.registerExpress(app));
181142
return webServices;
182143
}
183144

@@ -226,10 +187,6 @@ export class PluginConsortiumManual
226187
return endpoints;
227188
}
228189

229-
public getHttpServer(): Optional<Server | SecureServer> {
230-
return Optional.ofNullable(this.httpServer);
231-
}
232-
233190
public getPackageName(): string {
234191
return `@hyperledger/cactus-plugin-consortium-manual`;
235192
}

packages/cactus-plugin-htlc-eth-besu-erc20/src/main/typescript/plugin-htlc-eth-besu-erc20.ts

-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { Server } from "http";
2-
import { Server as SecureServer } from "https";
3-
41
import { Express } from "express";
5-
import { Optional } from "typescript-optional";
62

73
import OAS from "../json/openapi.json";
84

@@ -66,13 +62,6 @@ export class PluginHtlcEthBesuErc20
6662
return PluginHtlcEthBesuErc20.CLASS_NAME;
6763
}
6864

69-
/**
70-
* Feature is deprecated, we won't need this method in the future.
71-
*/
72-
public getHttpServer(): Optional<Server | SecureServer> {
73-
return Optional.empty();
74-
}
75-
7665
/**
7766
* Feature is deprecated, we won't need this method in the future.
7867
*/

packages/cactus-plugin-htlc-eth-besu/src/main/typescript/plugin-htlc-eth-besu.ts

-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { Server } from "http";
2-
import { Server as SecureServer } from "https";
3-
41
import { Express } from "express";
5-
import { Optional } from "typescript-optional";
62

73
import OAS from "../json/openapi.json";
84

@@ -67,13 +63,6 @@ export class PluginHtlcEthBesu implements ICactusPlugin, IPluginWebService {
6763
return OAS;
6864
}
6965

70-
/**
71-
* Feature is deprecated, we won't need this method in the future.
72-
*/
73-
public getHttpServer(): Optional<Server | SecureServer> {
74-
return Optional.empty();
75-
}
76-
7766
/**
7867
* Feature is deprecated, we won't need this method in the future.
7968
*/

packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-keychain-aws-sm.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import type { Server } from "http";
2-
import type { Server as SecureServer } from "https";
3-
41
import {
52
SharedIniFileCredentials,
63
config as awsConfig,
@@ -9,7 +6,6 @@ import {
96
} from "aws-sdk";
107

118
import type { Express } from "express";
12-
import { Optional } from "typescript-optional";
139

1410
import OAS from "../json/openapi.json";
1511

@@ -172,10 +168,6 @@ export class PluginKeychainAwsSm
172168
return;
173169
}
174170

175-
public getHttpServer(): Optional<Server | SecureServer> {
176-
return Optional.empty();
177-
}
178-
179171
public async shutdown(): Promise<void> {
180172
throw new Error("Method not implemented.");
181173
}

packages/cactus-plugin-keychain-azure-kv/src/main/typescript/plugin-keychain-azure-kv.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import type { Server } from "http";
2-
import type { Server as SecureServer } from "https";
3-
41
import type { Express } from "express";
5-
import { Optional } from "typescript-optional";
62

73
import OAS from "../json/openapi.json";
84

@@ -164,10 +160,6 @@ export class PluginKeychainAzureKv
164160
return endpoints;
165161
}
166162

167-
public getHttpServer(): Optional<Server | SecureServer> {
168-
return Optional.empty();
169-
}
170-
171163
public async shutdown(): Promise<void> {
172164
throw new Error("Method not implemented.");
173165
}

packages/cactus-plugin-keychain-google-sm/src/main/typescript/plugin-keychain-google-sm.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import type { Server } from "http";
2-
import type { Server as SecureServer } from "https";
3-
41
import type { Express } from "express";
5-
import { Optional } from "typescript-optional";
62

73
import OAS from "../json/openapi.json";
84

@@ -99,10 +95,6 @@ export class PluginKeychainGoogleSm
9995
return endpoints;
10096
}
10197

102-
public getHttpServer(): Optional<Server | SecureServer> {
103-
return Optional.empty();
104-
}
105-
10698
public async shutdown(): Promise<void> {
10799
throw new Error("Method not implemented.");
108100
}

packages/cactus-plugin-keychain-vault/src/main/typescript/plugin-keychain-vault-remote-adapter.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { Server } from "http";
2-
import { Server as SecureServer } from "https";
3-
41
import { Express } from "express";
5-
import { Optional } from "typescript-optional";
62

73
import OAS from "../json/openapi.json";
84

@@ -94,10 +90,6 @@ export class PluginKeychainVaultRemoteAdapter
9490
return this.getOrCreateWebServices();
9591
}
9692

97-
public getHttpServer(): Optional<Server | SecureServer> {
98-
return Optional.empty();
99-
}
100-
10193
public async shutdown(): Promise<void> {
10294
return;
10395
}

packages/cactus-plugin-keychain-vault/src/main/typescript/plugin-keychain-vault.ts

-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import type { Server } from "http";
2-
import type { Server as SecureServer } from "https";
3-
41
import type { Express } from "express";
5-
import { Optional } from "typescript-optional";
62
import Vault from "node-vault";
73
import HttpStatus from "http-status-codes";
84

@@ -190,10 +186,6 @@ export class PluginKeychainVault implements IPluginWebService, IPluginKeychain {
190186
return endpoints;
191187
}
192188

193-
public getHttpServer(): Optional<Server | SecureServer> {
194-
return Optional.empty();
195-
}
196-
197189
public async shutdown(): Promise<void> {
198190
throw new Error("Method not implemented.");
199191
}

packages/cactus-plugin-ledger-connector-besu/src/main/typescript/plugin-ledger-connector-besu.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Server as SecureServer } from "https";
44
import type { Server as SocketIoServer } from "socket.io";
55
import type { Socket as SocketIoSocket } from "socket.io";
66
import type { Express } from "express";
7-
import { promisify } from "util";
87
import { Optional } from "typescript-optional";
98

109
import OAS from "../json/openapi.json";
@@ -187,17 +186,8 @@ export class PluginLedgerConnectorBesu
187186
this.web3EEA = EEAClient(this.web3, chainId);
188187
}
189188

190-
public getHttpServer(): Optional<Server | SecureServer> {
191-
return Optional.ofNullable(this.httpServer);
192-
}
193-
194189
public async shutdown(): Promise<void> {
195-
const serverMaybe = this.getHttpServer();
196-
if (serverMaybe.isPresent()) {
197-
const server = serverMaybe.get();
198-
await promisify(server.close.bind(server))();
199-
}
200-
this.web3Provider.disconnect(1000, "Shutting down...");
190+
this.log.info(`Shutting down ${this.className}...`);
201191
}
202192

203193
async registerWebServices(

packages/cactus-plugin-ledger-connector-corda/src/main/typescript/plugin-ledger-connector-corda.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Server } from "http";
22
import { Server as SecureServer } from "https";
3-
4-
import { Optional } from "typescript-optional";
53
import { Config as SshConfig } from "node-ssh";
64
import { Express } from "express";
75

@@ -175,10 +173,6 @@ export class PluginLedgerConnectorCorda
175173
return endpoints;
176174
}
177175

178-
public getHttpServer(): Optional<Server | SecureServer> {
179-
return Optional.ofNullable(this.httpServer);
180-
}
181-
182176
public async shutdown(): Promise<void> {
183177
return;
184178
}

0 commit comments

Comments
 (0)