Skip to content

Commit

Permalink
information to status
Browse files Browse the repository at this point in the history
  • Loading branch information
vrolland committed Apr 7, 2020
1 parent 736ae33 commit 27e569b
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 86 deletions.
2 changes: 1 addition & 1 deletion packages/data-access/src/data-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export default class DataAccess implements DataAccessTypes.IDataAccess {
*
* @param detailed if true get the list of the files hashes
*/
public async _getInformation(detailed: boolean = false): Promise<any> {
public async _getStatus(detailed: boolean = false): Promise<any> {
this.checkInitialized();

// last transaction timestamp retrieved
Expand Down
31 changes: 13 additions & 18 deletions packages/data-access/test/data-access.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const defaultTestData: Promise<StorageTypes.IEntriesWithLastTimestamp> = Promise
);

const defaultFakeStorage: StorageTypes.IStorage = {
_getInformation: chai.spy(),
_getStatus: chai.spy(),
_ipfsAdd: chai.spy(),
append: chai.spy(
(): any => {
Expand Down Expand Up @@ -493,7 +493,7 @@ describe('data-access', () => {

it('cannot persistTransaction() and emit error if confirmation failed', async () => {
const mockStorageEmittingError: StorageTypes.IStorage = {
_getInformation: chai.spy(),
_getStatus: chai.spy(),
_ipfsAdd: chai.spy(),
append: chai.spy(
(): any => {
Expand Down Expand Up @@ -546,7 +546,7 @@ describe('data-access', () => {
});
});

describe('_getInformation', () => {
describe('_getStatus', () => {
let dataAccess: any;

beforeEach(async () => {
Expand All @@ -569,20 +569,15 @@ describe('data-access', () => {
await dataAccess.initialize();
});

it('can _getInformation()', async () => {
expect(await dataAccess._getInformation(), 'result with arbitraryTopic1 wrong').to.deep.equal(
{
filesIgnored: { count: 0, list: undefined },
filesRetrieved: { count: 1, lastTimestamp: 10, list: undefined },
lastSynchronizationTimestamp: 0,
},
);
it('can _getStatus()', async () => {
expect(await dataAccess._getStatus(), 'result with arbitraryTopic1 wrong').to.deep.equal({
filesIgnored: { count: 0, list: undefined },
filesRetrieved: { count: 1, lastTimestamp: 10, list: undefined },
lastSynchronizationTimestamp: 0,
});
});
it('can _getInformation() with details', async () => {
expect(
await dataAccess._getInformation(true),
'result with arbitraryTopic1 wrong',
).to.deep.equal({
it('can _getStatus() with details', async () => {
expect(await dataAccess._getStatus(true), 'result with arbitraryTopic1 wrong').to.deep.equal({
filesIgnored: { count: 0, list: {} },
filesRetrieved: { count: 1, lastTimestamp: 10, list: ['dataIdBlock2tx'] },
lastSynchronizationTimestamp: 0,
Expand Down Expand Up @@ -618,7 +613,7 @@ describe('data-access', () => {
_ipfsAdd: chai.spy(),
append: chai.spy(),
getData: (): Promise<StorageTypes.IEntriesWithLastTimestamp> => testDataNotJsonData,
_getInformation: chai.spy(),
_getStatus: chai.spy(),
initialize: chai.spy(),
read: chai.spy(),
readMany: chai.spy(),
Expand Down Expand Up @@ -740,7 +735,7 @@ describe('data-access', () => {
_ipfsAdd: chai.spy(),
append: chai.spy.returns(appendResult),
getData: (): Promise<StorageTypes.IEntriesWithLastTimestamp> => chai.spy(),
_getInformation: chai.spy(),
_getStatus: chai.spy(),
initialize: chai.spy(),
read: chai.spy(),
readMany: chai.spy(),
Expand Down
10 changes: 5 additions & 5 deletions packages/data-access/test/ignored-location.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ describe('IgnoredLocation', () => {
});
});

describe('getIgnoredLocation', () => {
it('can getIgnoredLocation()', async () => {
describe('getIgnoredLocations', () => {
it('can getIgnoredLocations()', async () => {
const ignoredLocation = new IgnoredLocation();
await ignoredLocation.pushReasonByLocation(arbitraryDataId1, arbitraryReason);
await ignoredLocation.pushReasonByLocation(arbitraryDataId2, arbitraryReason2);

expect(await ignoredLocation.getIgnoredLocation()).to.be.deep.equal({
expect(await ignoredLocation.getIgnoredLocations()).to.be.deep.equal({
[arbitraryDataId1]: arbitraryReason,
[arbitraryDataId2]: arbitraryReason2,
});
});
it('can getIgnoredLocation() if empty', async () => {
it('can getIgnoredLocations() if empty', async () => {
const ignoredLocation = new IgnoredLocation();

expect(await ignoredLocation.getIgnoredLocation()).to.be.deep.equal({});
expect(await ignoredLocation.getIgnoredLocations()).to.be.deep.equal({});
});
});
});
2 changes: 1 addition & 1 deletion packages/ethereum-storage/src/ethereum-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ export default class EthereumStorage implements StorageTypes.IStorage {
* @param detailed if true get the list of the files hash
* @returns Promise resolving object with dataIds retrieved and ignored
*/
public async _getInformation(detailed: boolean = false): Promise<any> {
public async _getStatus(detailed: boolean = false): Promise<any> {
const dataIds = await this.ethereumMetadataCache.getDataIds();
const dataIdsWithReason = await this.dataIdsIgnored.getDataIdsWithReasons();
return {
Expand Down
20 changes: 10 additions & 10 deletions packages/ethereum-storage/test/dataids-ignored.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ describe('DataIds ignored', () => {

expect(await dataIdsIgnored.getReason(hash)).to.be.equal(reason);
});
describe('getListDataIdWithReason', () => {
it('can getListDataIdWithReason()', async () => {
describe('getDataIdsWithReasons', () => {
it('can getDataIdsWithReasons()', async () => {
await dataIdsIgnored.saveReason(hash, reason);
await dataIdsIgnored.saveReason(hash2, reason2);

expect(await dataIdsIgnored.getListDataIdWithReason()).to.be.deep.equal({
expect(await dataIdsIgnored.getDataIdsWithReasons()).to.be.deep.equal({
[hash]: reason,
[hash2]: reason2,
});
});
it('can getListDataIdWithReason() if empty', async () => {
expect(await dataIdsIgnored.getListDataIdWithReason()).to.be.deep.equal({});
it('can getDataIdsWithReasons() if empty', async () => {
expect(await dataIdsIgnored.getDataIdsWithReasons()).to.be.deep.equal({});
});
});
describe('getListDataId', () => {
it('can getListDataId()', async () => {
describe('getDataIds', () => {
it('can getDataIds()', async () => {
await dataIdsIgnored.saveReason(hash, reason);
await dataIdsIgnored.saveReason(hash2, reason2);

expect(await dataIdsIgnored.getListDataId()).to.be.deep.equal([hash, hash2]);
expect(await dataIdsIgnored.getDataIds()).to.be.deep.equal([hash, hash2]);
});
it('can getListDataId() if empty', async () => {
expect(await dataIdsIgnored.getListDataId()).to.be.deep.equal([]);
it('can getDataIds() if empty', async () => {
expect(await dataIdsIgnored.getDataIds()).to.be.deep.equal([]);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/prototype-estimator/src/mock-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class MockStorage implements StorageTypes.IStorage {
throw Error('will never be used');
}

public async _getInformation(): Promise<never> {
public async _getStatus(): Promise<never> {
throw Error('will never be used');
}

Expand Down
2 changes: 1 addition & 1 deletion packages/request-client.js/src/http-data-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default class HttpDataAccess implements DataAccessTypes.IDataAccess {
*
* @param detailed if true get the list of files hashes
*/
public async _getInformation(detailed?: boolean): Promise<any> {
public async _getStatus(detailed?: boolean): Promise<any> {
const { data } = await Utils.retry(
async () =>
axios.get(
Expand Down
2 changes: 1 addition & 1 deletion packages/request-client.js/src/mock-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class MockStorage implements StorageTypes.IStorage {
*
* @param detailed if true get the list of files hash
*/
public async _getInformation(detailed?: boolean): Promise<any> {
public async _getStatus(detailed?: boolean): Promise<any> {
return {
dataIds: {
count: Object.entries(this.data).length,
Expand Down
16 changes: 8 additions & 8 deletions packages/request-client.js/test/api/request-network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Request from '../../src/api/request';
import * as TestData from '../data-test';

const mockDataAccess: DataAccessTypes.IDataAccess = {
async _getInformation(): Promise<any> {
async _getStatus(): Promise<any> {
return;
},
async getChannelsByTopic(): Promise<any> {
Expand Down Expand Up @@ -51,7 +51,7 @@ describe('api/request-network', () => {
describe('createRequest', () => {
it('cannot createRequest() with extensionsData', async () => {
const mockDataAccessWithTxs: DataAccessTypes.IDataAccess = {
async _getInformation(): Promise<any> {
async _getStatus(): Promise<any> {
return;
},
async getChannelsByTopic(): Promise<any> {
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('api/request-network', () => {
describe('fromRequestId', () => {
it('can get request with payment network fromRequestId', async () => {
const mockDataAccessWithTxs: DataAccessTypes.IDataAccess = {
async _getInformation(): Promise<any> {
async _getStatus(): Promise<any> {
return;
},
async getChannelsByTopic(): Promise<any> {
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('api/request-network', () => {
);

const mockDataAccessWithTxs: DataAccessTypes.IDataAccess = {
async _getInformation(): Promise<any> {
async _getStatus(): Promise<any> {
return;
},
async getChannelsByTopic(): Promise<any> {
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('api/request-network', () => {
describe('fromIdentity', () => {
it('can get requests with payment network fromIdentity', async () => {
const mockDataAccessWithTxs: DataAccessTypes.IDataAccess = {
async _getInformation(): Promise<any> {
async _getStatus(): Promise<any> {
return;
},
async getChannelsByTopic(topic: string): Promise<any> {
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('api/request-network', () => {
describe('fromTopic', () => {
it('can get requests with payment network fromTopic', async () => {
const mockDataAccessWithTxs: DataAccessTypes.IDataAccess = {
async _getInformation(): Promise<any> {
async _getStatus(): Promise<any> {
return;
},
async getChannelsByTopic(): Promise<any> {
Expand Down Expand Up @@ -303,7 +303,7 @@ describe('api/request-network', () => {
describe('fromMultipleIdentities', () => {
it('can get requests with payment network from multiple Identities', async () => {
const mockDataAccessWithTxs: DataAccessTypes.IDataAccess = {
async _getInformation(): Promise<any> {
async _getStatus(): Promise<any> {
return;
},
async getChannelsByMultipleTopics(topics: [string]): Promise<any> {
Expand Down Expand Up @@ -381,7 +381,7 @@ describe('api/request-network', () => {
describe('fromMultipleTopics', () => {
it('can get requests with payment network fromMultipleTopics', async () => {
const mockDataAccessWithTxs: DataAccessTypes.IDataAccess = {
async _getInformation(): Promise<any> {
async _getStatus(): Promise<any> {
return;
},
async getChannelsByMultipleTopics(): Promise<any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import * as httpStatus from 'http-status-codes';
const GET_CHANNELS_TIMEOUT: number = 600000;

/**
* Handles getInformation of data-access layer.
* Handles getStatus of data-access layer.
*
* @param clientRequest http client request object
* @param serverResponse http server response object
* @param dataAccess data access layer
*/
export default async function getInformation(
export default async function getStatus(
clientRequest: any,
serverResponse: any,
ethereumStorage: StorageTypes.IStorage,
Expand All @@ -26,34 +26,32 @@ export default async function getInformation(
// PROT-187: Decrease or remove this value
clientRequest.setTimeout(GET_CHANNELS_TIMEOUT);

if (!dataAccess._getInformation) {
if (!dataAccess._getStatus) {
return serverResponse
.status(httpStatus.INTERNAL_SERVER_ERROR)
.send('The node do not support this feature');
}

try {
const dataAccessInformation = await dataAccess._getInformation(clientRequest.query.detailed);
const ethereumStorageInformation = await ethereumStorage._getInformation(
clientRequest.query.detailed,
);

const information = {
dataAccessInformation,
ethereumStorageInformation,
const dataAccessStatus = await dataAccess._getStatus(clientRequest.query.detailed);
const ethereumStorageStatus = await ethereumStorage._getStatus(clientRequest.query.detailed);

const status = {
dataAccessStatus,
ethereumStorageStatus,
version: process.env.npm_package_version,
};

// Log the request time
const requestEndTime = Date.now();
logger.debug(`getInformation latency: ${requestEndTime - requestStartTime}ms`, [
logger.debug(`getStatus latency: ${requestEndTime - requestStartTime}ms`, [
'metric',
'latency',
]);

serverResponse.status(httpStatus.OK).send(information);
serverResponse.status(httpStatus.OK).send(status);
} catch (e) {
logger.error(`getInformation error: ${e}`);
logger.error(`getStatus error: ${e}`);

serverResponse.status(httpStatus.INTERNAL_SERVER_ERROR).send(e);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/request-node/src/requestNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import Utils from '@requestnetwork/utils';
import { getCustomHeaders, getInitializationStorageFilePath, getMnemonic } from './config';
import ConfirmedTransactionStore from './request/confirmedTransactionStore';
import getChannelsByTopic from './request/getChannelsByTopic';
import getInformation from './request/getInformation';
import getStatus from './request/getStatus';
import getTransactionsByChannelId from './request/getTransactionsByChannelId';
import ipfsAdd from './request/ipfsAdd';
import PersistTransaction from './request/persistTransaction';
import { getEthereumStorage } from './storageUtils';

const NOT_FOUND_MESSAGE =
'Not found\nAvailable endpoints:\n/POST persistTransaction\n/GET getTransactionsByChannelId\n/GET getChannelsByTopic\n/POST /ipfsAdd\nGET getConfirmedTransaction\nGET information';
'Not found\nAvailable endpoints:\n/POST persistTransaction\n/GET getTransactionsByChannelId\n/GET getChannelsByTopic\n/POST /ipfsAdd\nGET getConfirmedTransaction\nGET status';

const NOT_INITIALIZED_MESSAGE = 'The node is not initialized';

Expand Down Expand Up @@ -159,10 +159,10 @@ class RequestNode {
return serverResponse.status(httpStatus.SERVICE_UNAVAILABLE).send(NOT_INITIALIZED_MESSAGE);
});

// Route for information check
router.get('/information', (clientRequest: any, serverResponse: any) => {
// Route for satus check
router.get('/status', (clientRequest: any, serverResponse: any) => {
if (this.initialized) {
return getInformation(
return getStatus(
clientRequest,
serverResponse,
this.ethereumStorage,
Expand Down
Loading

0 comments on commit 27e569b

Please sign in to comment.