From e49f9018ea7ae5951b5a939435d752b480ed1bbf Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 10 Feb 2020 11:15:50 +0000 Subject: [PATCH] Fixed #440 - Applied latest OpenAPI v0.8.2 --- e2e/infrastructure/DiagnosticHttp.spec.ts | 47 ------------ e2e/infrastructure/NodeHttp.spec.ts | 25 +++++++ package-lock.json | 22 +++--- package.json | 2 +- src/infrastructure/DiagnosticHttp.ts | 73 ------------------- src/infrastructure/NodeHttp.ts | 43 +++++++++++ src/infrastructure/NodeRepository.ts | 23 ++++++ src/infrastructure/RepositoryFactory.ts | 6 -- src/infrastructure/RepositoryFactoryHttp.ts | 6 -- src/infrastructure/infrastructure.ts | 2 - ...lockchainStorageInfo.ts => StorageInfo.ts} | 2 +- src/model/model.ts | 5 +- .../node/NodeHealth.ts} | 31 ++++---- src/model/{diagnostic => node}/ServerInfo.ts | 0 test/infrastructure/RepositoryFactory.spec.ts | 1 - .../blockchain/BlockchainStorageInfo.spec.ts | 6 +- 16 files changed, 123 insertions(+), 171 deletions(-) delete mode 100644 e2e/infrastructure/DiagnosticHttp.spec.ts delete mode 100644 src/infrastructure/DiagnosticHttp.ts rename src/model/blockchain/{BlockchainStorageInfo.ts => StorageInfo.ts} (97%) rename src/{infrastructure/DiagnosticRepository.ts => model/node/NodeHealth.ts} (50%) rename src/model/{diagnostic => node}/ServerInfo.ts (100%) diff --git a/e2e/infrastructure/DiagnosticHttp.spec.ts b/e2e/infrastructure/DiagnosticHttp.spec.ts deleted file mode 100644 index 1b3d48154f..0000000000 --- a/e2e/infrastructure/DiagnosticHttp.spec.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2019 NEM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { expect } from 'chai'; -import { DiagnosticRepository } from '../../src/infrastructure/DiagnosticRepository'; -import { IntegrationTestHelper } from './IntegrationTestHelper'; - -describe('DiagnosticHttp', () => { - const helper = new IntegrationTestHelper(); - let diagnosticRepository: DiagnosticRepository; - - before(() => { - return helper.start().then(() => { - diagnosticRepository = helper.repositoryFactory.createDiagnosticRepository(); - }); - }); - - describe('getDiagnosticStorage', () => { - it('should return diagnostic storage', async () => { - const blockchainStorageInfo = await diagnosticRepository.getDiagnosticStorage().toPromise(); - expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0); - expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0); - expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0); - }); - }); - - describe('getServerInfo', () => { - it('should return diagnostic storage', async () => { - const serverInfo = await diagnosticRepository.getServerInfo().toPromise(); - expect(serverInfo.restVersion).not.to.be.null; - expect(serverInfo.sdkVersion).not.to.be.null; - }); - }); -}); diff --git a/e2e/infrastructure/NodeHttp.spec.ts b/e2e/infrastructure/NodeHttp.spec.ts index 8d81df82ee..1cbfad5924 100644 --- a/e2e/infrastructure/NodeHttp.spec.ts +++ b/e2e/infrastructure/NodeHttp.spec.ts @@ -48,4 +48,29 @@ describe('NodeHttp', () => { expect(nodeTime.sendTimeStamp).not.to.be.undefined; }); }); + + describe('getStorageInfo', () => { + it('should return storage info', async () => { + const blockchainStorageInfo = await nodeRepository.getStorageInfo().toPromise(); + expect(blockchainStorageInfo.numBlocks).to.be.greaterThan(0); + expect(blockchainStorageInfo.numTransactions).to.be.greaterThan(0); + expect(blockchainStorageInfo.numAccounts).to.be.greaterThan(0); + }); + }); + + describe('getServerInfo', () => { + it('should return server info', async () => { + const serverInfo = await nodeRepository.getServerInfo().toPromise(); + expect(serverInfo.restVersion).not.to.be.null; + expect(serverInfo.sdkVersion).not.to.be.null; + }); + }); + + describe('getNodeHealth', () => { + it('should return node health', async () => { + const health = await nodeRepository.getNodeHealth().toPromise(); + expect(health.apiNode).not.to.be.null; + expect(health.db).not.to.be.null; + }); + }); }); diff --git a/package-lock.json b/package-lock.json index aad917f6d0..cc75b3fdcf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3081,12 +3081,9 @@ "dev": true }, "is-finite": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.0.2.tgz", - "integrity": "sha1-zGZ3aVYCvlUO8R6LSqYwU0K20Ko=", - "requires": { - "number-is-nan": "^1.0.0" - } + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-finite/-/is-finite-1.1.0.tgz", + "integrity": "sha512-cdyMtqX/BOqqNBBiKlIVkytNHm49MtMlYyn1zxzvJKWmFMlGzm+ry5BBfYyeY9YmNKbRSo/o7OX9w9ale0wg3w==" }, "is-fullwidth-code-point": { "version": "1.0.0", @@ -3823,9 +3820,9 @@ } }, "nem2-sdk-openapi-typescript-node-client": { - "version": "0.7.22", - "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.7.22.tgz", - "integrity": "sha512-EKuTvdW73R7xlv43gjGGEAfSi4FjFIWT4U6EjDcbXWRZX1CqjiKQvZzZgvil4pmBaTsquEim1TXjiKtjkgan8A==", + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/nem2-sdk-openapi-typescript-node-client/-/nem2-sdk-openapi-typescript-node-client-0.8.2.tgz", + "integrity": "sha512-0ftmqqeJhfyFhVQBbnXhU9Ep9D8TTWv7KQIhGubSNnGmsPlddRRf17XBhYDAYuHdPV9L9P9L49NJDc9xh8s8Lw==", "requires": { "@types/bluebird": "*", "@types/request": "*", @@ -3902,7 +3899,8 @@ "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", + "dev": true }, "nyc": { "version": "14.1.1", @@ -4000,7 +3998,7 @@ }, "is-fullwidth-code-point": { "version": "2.0.0", - "resolved": "", + "resolved": false, "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=", "dev": true }, @@ -4038,7 +4036,7 @@ }, "which-module": { "version": "2.0.0", - "resolved": "", + "resolved": false, "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", "dev": true }, diff --git a/package.json b/package.json index ca9e69e04c..9ac5c50d64 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "js-sha3": "^0.8.0", "long": "^4.0.0", "merkletreejs": "^0.1.7", - "nem2-sdk-openapi-typescript-node-client": "0.7.22", + "nem2-sdk-openapi-typescript-node-client": "0.8.2", "request": "^2.88.0", "request-promise-native": "^1.0.5", "ripemd160": "^2.0.2", diff --git a/src/infrastructure/DiagnosticHttp.ts b/src/infrastructure/DiagnosticHttp.ts deleted file mode 100644 index 32cc201a9e..0000000000 --- a/src/infrastructure/DiagnosticHttp.ts +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2019 NEM - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { DiagnosticRoutesApi } from 'nem2-sdk-openapi-typescript-node-client'; -import { from as observableFrom, Observable, throwError } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; -import { BlockchainStorageInfo } from '../model/blockchain/BlockchainStorageInfo'; -import { ServerInfo } from '../model/diagnostic/ServerInfo'; -import { DiagnosticRepository } from './DiagnosticRepository'; -import { Http } from './Http'; - -/** - * Diagnostic http repository. - * - * @since 1.0 - */ -export class DiagnosticHttp extends Http implements DiagnosticRepository { - /** - * @internal - * Nem2 Library diagnostic routes api - */ - private diagnosticRoutesApi: DiagnosticRoutesApi; - - /** - * Constructor - * @param url - */ - constructor(url: string) { - super(url); - this.diagnosticRoutesApi = new DiagnosticRoutesApi(url); - } - - /** - * Gets blockchain storage info. - * @returns Observable - */ - public getDiagnosticStorage(): Observable { - return observableFrom( - this.diagnosticRoutesApi.getDiagnosticStorage()).pipe( - map(({body}) => new BlockchainStorageInfo( - body.numBlocks, - body.numTransactions, - body.numAccounts, - )), - catchError((error) => throwError(this.errorHandling(error))), - ); - } - - /** - * Gets blockchain server info. - * @returns Observable - */ - public getServerInfo(): Observable { - return observableFrom( - this.diagnosticRoutesApi.getServerInfo()).pipe( - map(({body}) => new ServerInfo(body.serverInfo.restVersion, body.serverInfo.sdkVersion)), - catchError((error) => throwError(this.errorHandling(error))), - ); - } -} diff --git a/src/infrastructure/NodeHttp.ts b/src/infrastructure/NodeHttp.ts index 3ed1b1cef9..988c8758d5 100644 --- a/src/infrastructure/NodeHttp.ts +++ b/src/infrastructure/NodeHttp.ts @@ -17,8 +17,11 @@ import { NodeRoutesApi } from 'nem2-sdk-openapi-typescript-node-client'; import { from as observableFrom, Observable, throwError } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; +import { StorageInfo } from '../model/blockchain/StorageInfo'; +import { NodeHealth } from '../model/node/NodeHealth'; import { NodeInfo } from '../model/node/NodeInfo'; import { NodeTime } from '../model/node/NodeTime'; +import { ServerInfo } from '../model/node/ServerInfo'; import { UInt64 } from '../model/UInt64'; import { Http } from './Http'; import { NodeRepository } from './NodeRepository'; @@ -81,4 +84,44 @@ export class NodeHttp extends Http implements NodeRepository { catchError((error) => throwError(this.errorHandling(error))), ); } + + /** + * Gets blockchain storage info. + * @returns Observable + */ + public getStorageInfo(): Observable { + return observableFrom( + this.nodeRoutesApi.getNodeStorage()).pipe( + map(({body}) => new StorageInfo( + body.numBlocks, + body.numTransactions, + body.numAccounts, + )), + catchError((error) => throwError(this.errorHandling(error))), + ); + } + + /** + * Gets blockchain server info. + * @returns Observable + */ + public getServerInfo(): Observable { + return observableFrom( + this.nodeRoutesApi.getServerInfo()).pipe( + map(({body}) => new ServerInfo(body.serverInfo.restVersion, body.serverInfo.sdkVersion)), + catchError((error) => throwError(this.errorHandling(error))), + ); + } + + /** + * Gets blockchain server info. + * @returns Observable + */ + public getNodeHealth(): Observable { + return observableFrom( + this.nodeRoutesApi.getNodeHealth()).pipe( + map(({body}) => new NodeHealth(body.status.apiNode, body.status.db)), + catchError((error) => throwError(this.errorHandling(error))), + ); + } } diff --git a/src/infrastructure/NodeRepository.ts b/src/infrastructure/NodeRepository.ts index 94ab38886c..ea523d215d 100644 --- a/src/infrastructure/NodeRepository.ts +++ b/src/infrastructure/NodeRepository.ts @@ -15,8 +15,11 @@ */ import {Observable} from 'rxjs'; +import { StorageInfo } from '../model/blockchain/StorageInfo'; +import { NodeHealth } from '../model/node/NodeHealth'; import { NodeInfo } from '../model/node/NodeInfo'; import { NodeTime } from '../model/node/NodeTime'; +import { ServerInfo } from '../model/node/ServerInfo'; /** * Node interface repository. @@ -36,4 +39,24 @@ export interface NodeRepository { * @summary Get the node time */ getNodeTime(): Observable; + + /** + * Get node health information + * + * @return {@link NodeHealth} of NodeHealth + */ + getNodeHealth(): Observable; + + /** + * Gets blockchain storage info. + * @returns Observable + */ + getStorageInfo(): Observable; + + /** + * Gets blockchain server info. + * @returns Observable + */ + getServerInfo(): Observable; + } diff --git a/src/infrastructure/RepositoryFactory.ts b/src/infrastructure/RepositoryFactory.ts index a75778e1be..51c294eb85 100644 --- a/src/infrastructure/RepositoryFactory.ts +++ b/src/infrastructure/RepositoryFactory.ts @@ -19,7 +19,6 @@ import { NetworkType } from '../model/blockchain/NetworkType'; import { AccountRepository } from './AccountRepository'; import { BlockRepository } from './BlockRepository'; import { ChainRepository } from './ChainRepository'; -import { DiagnosticRepository } from './DiagnosticRepository'; import { IListener } from './IListener'; import { MetadataRepository } from './MetadataRepository'; import { MosaicRepository } from './MosaicRepository'; @@ -76,11 +75,6 @@ export interface RepositoryFactory { */ createChainRepository(): ChainRepository; - /** - * @returns a newly created {@link DiagnosticRepository} - */ - createDiagnosticRepository(): DiagnosticRepository; - /** * @returns a newly created {@link MosaicRepository} */ diff --git a/src/infrastructure/RepositoryFactoryHttp.ts b/src/infrastructure/RepositoryFactoryHttp.ts index 1bd08e7783..30e91b2f83 100644 --- a/src/infrastructure/RepositoryFactoryHttp.ts +++ b/src/infrastructure/RepositoryFactoryHttp.ts @@ -24,8 +24,6 @@ import { BlockHttp } from './BlockHttp'; import { BlockRepository } from './BlockRepository'; import { ChainHttp } from './ChainHttp'; import { ChainRepository } from './ChainRepository'; -import { DiagnosticHttp } from './DiagnosticHttp'; -import { DiagnosticRepository } from './DiagnosticRepository'; import { IListener } from './IListener'; import { Listener } from './Listener'; import { MetadataHttp } from './MetadataHttp'; @@ -85,10 +83,6 @@ export class RepositoryFactoryHttp implements RepositoryFactory { return new ChainHttp(this.url); } - createDiagnosticRepository(): DiagnosticRepository { - return new DiagnosticHttp(this.url); - } - createMetadataRepository(): MetadataRepository { return new MetadataHttp(this.url); } diff --git a/src/infrastructure/infrastructure.ts b/src/infrastructure/infrastructure.ts index 075e8f56d4..3a297391a7 100644 --- a/src/infrastructure/infrastructure.ts +++ b/src/infrastructure/infrastructure.ts @@ -17,7 +17,6 @@ export * from './AccountHttp'; export * from './BlockHttp'; export * from './ChainHttp'; -export * from './DiagnosticHttp'; export * from './Http'; export * from './MosaicHttp'; export * from './MetadataHttp'; @@ -36,7 +35,6 @@ export * from './transaction/NamespaceMosaicIdGenerator'; export * from './AccountRepository'; export * from './BlockRepository'; export * from './ChainRepository'; -export * from './DiagnosticRepository'; export * from './IListener'; export * from './MetadataRepository'; export * from './MosaicRepository'; diff --git a/src/model/blockchain/BlockchainStorageInfo.ts b/src/model/blockchain/StorageInfo.ts similarity index 97% rename from src/model/blockchain/BlockchainStorageInfo.ts rename to src/model/blockchain/StorageInfo.ts index 0f3ee26d9f..b71c8aaf2f 100644 --- a/src/model/blockchain/BlockchainStorageInfo.ts +++ b/src/model/blockchain/StorageInfo.ts @@ -17,7 +17,7 @@ /** * The blockchain storage info structure describes stored data. */ -export class BlockchainStorageInfo { +export class StorageInfo { /** * @param numBlocks diff --git a/src/model/model.ts b/src/model/model.ts index f760473578..ee624e7d69 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -30,7 +30,7 @@ export * from './account/AccountNames'; // Blockchain export * from './blockchain/BlockchainScore'; -export * from './blockchain/BlockchainStorageInfo'; +export * from './blockchain/StorageInfo'; export * from './blockchain/BlockInfo'; export * from './blockchain/NetworkType'; export * from './blockchain/MerklePathItem'; @@ -38,7 +38,7 @@ export * from './blockchain/MerkleProofInfo'; export * from './blockchain/NetworkName'; // Diagnostic -export * from './diagnostic/ServerInfo'; +export * from './node/ServerInfo'; // Mosaic export * from './mosaic/Mosaic'; @@ -75,6 +75,7 @@ export * from './namespace/EmptyAlias'; export * from './node/NodeInfo'; export * from './node/NodeTime'; export * from './node/RoleType'; +export * from './node/NodeHealth'; // Receipt export * from './receipt/ArtifactExpiryReceipt'; diff --git a/src/infrastructure/DiagnosticRepository.ts b/src/model/node/NodeHealth.ts similarity index 50% rename from src/infrastructure/DiagnosticRepository.ts rename to src/model/node/NodeHealth.ts index 5b4bf271bb..fa3cc6018a 100644 --- a/src/infrastructure/DiagnosticRepository.ts +++ b/src/model/node/NodeHealth.ts @@ -1,5 +1,5 @@ /* - * Copyright 2019 NEM + * Copyright 2020 NEM * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,26 +14,23 @@ * limitations under the License. */ -import {Observable} from 'rxjs'; -import {BlockchainStorageInfo} from '../model/blockchain/BlockchainStorageInfo'; -import { ServerInfo } from '../model/diagnostic/ServerInfo'; +import { NodeStatusEnum } from 'nem2-sdk-openapi-typescript-node-client'; /** - * Diagnostic interface repository. - * - * @since 1.0 + * The node info structure describes basic information of a node health. */ -export interface DiagnosticRepository { - - /** - * Gets blockchain storage info. - * @returns Observable - */ - getDiagnosticStorage(): Observable; +export class NodeHealth { /** - * Gets blockchain server info. - * @returns Observable + * @param apiNode + * @param db */ - getServerInfo(): Observable; + constructor(/** + * The api node status + */ + public readonly apiNode: NodeStatusEnum, + /** + * The database status + */ + public readonly db: NodeStatusEnum ) {} } diff --git a/src/model/diagnostic/ServerInfo.ts b/src/model/node/ServerInfo.ts similarity index 100% rename from src/model/diagnostic/ServerInfo.ts rename to src/model/node/ServerInfo.ts diff --git a/test/infrastructure/RepositoryFactory.spec.ts b/test/infrastructure/RepositoryFactory.spec.ts index e80f44bf9b..9400c71815 100644 --- a/test/infrastructure/RepositoryFactory.spec.ts +++ b/test/infrastructure/RepositoryFactory.spec.ts @@ -33,7 +33,6 @@ describe('RepositoryFactory', () => { expect(repositoryFactory.createNamespaceRepository()).to.be.not.null; expect(repositoryFactory.createAccountRepository()).to.be.not.null; expect(repositoryFactory.createChainRepository()).to.be.not.null; - expect(repositoryFactory.createDiagnosticRepository()).to.be.not.null; expect(repositoryFactory.createMetadataRepository()).to.be.not.null; expect(repositoryFactory.createMosaicRepository()).to.be.not.null; expect(repositoryFactory.createMultisigRepository()).to.be.not.null; diff --git a/test/model/blockchain/BlockchainStorageInfo.spec.ts b/test/model/blockchain/BlockchainStorageInfo.spec.ts index 949bc665df..105cd150fb 100644 --- a/test/model/blockchain/BlockchainStorageInfo.spec.ts +++ b/test/model/blockchain/BlockchainStorageInfo.spec.ts @@ -15,18 +15,18 @@ */ import {expect} from 'chai'; -import {BlockchainStorageInfo} from '../../../src/model/blockchain/BlockchainStorageInfo'; +import { StorageInfo } from '../../../src/model/blockchain/StorageInfo'; describe('BlockchainStorageInfo', () => { - it('should createComplete an BlockchainStorageInfo object', () => { + it('should createComplete an StorageInfo object', () => { const blockchainStorageInfoDTO = { numBlocks: 1, numTransactions: 100, numAccounts: 10, }; - const blockchainScore = new BlockchainStorageInfo( + const blockchainScore = new StorageInfo( blockchainStorageInfoDTO.numBlocks, blockchainStorageInfoDTO.numTransactions, blockchainStorageInfoDTO.numAccounts,