Skip to content

Commit

Permalink
Refactor logger enums and update aggregator config
Browse files Browse the repository at this point in the history
  • Loading branch information
argahsuknesib committed Oct 3, 2024
1 parent b7b224f commit 7a4fdec
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 221 deletions.
35 changes: 26 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"eslint-plugin-jsdoc": "^48.0.6",
"jest": "^29.3.1",
"ldfetch": "^1.2.8",
"rsp-js": "^1.1.2",
"ts-jest": "^29.0.3",
"typescript": "^4.9.4"
},
Expand All @@ -44,6 +43,7 @@
"css-auth-login": "^1.0.8",
"rate-limited-ldp-communication": "^1.0.5",
"rdflib": "^2.2.31",
"rsp-js": "file:../RSP/RSP-JS",
"rspql-query-equivalence": "^1.0.3",
"sparqljs": "^3.6.2",
"tslog": "^4.8.2",
Expand Down
2 changes: 1 addition & 1 deletion src/config/aggregator_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"aggregation_pod_ldes_location" : "http://localhost:3000/aggregation_pod/aggregation/",
"aggregation_pod_ldes_location" : "http://localhost:3000/aggregation_pod/",
"aggregator_rate_limit": 30
}
14 changes: 1 addition & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
import { HTTPServer } from "./server/HTTPServer";
import * as bunyan from 'bunyan';
import * as fs from 'fs';
import * as path from 'path';

function getTimestamp() {
const now = new Date();
return `${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}-${now.getDate().toString().padStart(2, '0')}-${now.getHours().toString().padStart(2, '0')}-${now.getMinutes().toString().padStart(2, '0')}-${now.getSeconds().toString().padStart(2, '0')}`;
}

function getAndUpdateIteration() {
const iterationFilePath = path.join(__dirname, '/logs/iteration.txt');
let iteration = 1;
if (fs.existsSync(iterationFilePath)) {
iteration = parseInt(fs.readFileSync(iterationFilePath, 'utf8'), 10) + 1;
}
fs.writeFileSync(iterationFilePath, iteration.toString());
return iteration;
}

const iteration = getAndUpdateIteration();
const timestamp = getTimestamp();

const log_file = fs.createWriteStream(`aggregator-${iteration}-${timestamp}.log`, { flags: 'a' });
const log_file = fs.createWriteStream(`aggregator-${timestamp}.log`, { flags: 'a' });

const logger = bunyan.createLogger({
name: 'solid-stream-aggregator',
Expand Down
2 changes: 1 addition & 1 deletion src/server/HTTPServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class HTTPServer {
this.websocket_handler.handle_wss();
this.websocket_handler.aggregation_event_publisher();
this.logger.info({}, 'http_server_started');
console.log('HTTP Server started on port ' + http_port);
console.log(`HTTP Server started on port ${http_port} and the process id is ${process.pid}`);
}
/**
* Handle the request from the client.
Expand Down
4 changes: 3 additions & 1 deletion src/service/aggregator/NotificationStreamProcessor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { turtleStringToStore } from "@treecg/ldes-snapshot";
import { DataFactory } from 'rdf-data-factory';
import { LDESinLDP, LDPCommunication } from "@treecg/versionawareldesinldp";
import { RDFStream, RSPEngine } from "rsp-js";
import { TREE } from "@treecg/versionawareldesinldp";
import { create_subscription, extract_ldp_inbox, extract_subscription_server } from "../../utils/notifications/Util";
const DF = new DataFactory();

/**
* The NotificationStreamProcessor class is responsible for processing the notifications from the LDES Stream.
Expand Down Expand Up @@ -96,7 +98,7 @@ export class NotificationStreamProcessor {
* of the Solid Stream Aggregator (for now, and the support for this will be implemented in the future).
*/
const latest_event_store = await turtleStringToStore(latest_event);
const timestamp = latest_event_store.getQuads(null, bucket_strategy, null, null)[0].object.value;
const timestamp = latest_event_store.getQuads(null, DF.namedNode(bucket_strategy), null, null)[0].object.value;
const timestamp_epoch = Date.parse(timestamp);
if (this.stream_name) {
this.logger.info({}, 'latest_event_received_preprocessing_completed_adding_to_rsp_engine_started');
Expand Down
7 changes: 6 additions & 1 deletion src/service/publishing-stream-to-pod/LDESPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Logger, ILogObj } from "tslog";
const ld_fetch = require('ldfetch');
const ldfetch = new ld_fetch({});
import { EndpointQueries } from "../../server/EndpointQueries";
import { getSession } from "css-auth-login";
/**
* Class for publishing the resources (which were generated by the RSP Engine) to the LDES in the LDP container
* of the aggregation pod.
Expand All @@ -38,7 +39,11 @@ export class LDESPublisher {
* @memberof LDESPublisher
*/
constructor() {
this.initialise();
/*
The initialise() method initializes a LDES in LDP container
this.initialise(); // Initialises the LDES in the LDP container of the aggregation pod.
*/
this.config = {
treePath: this.treePath, versionOfPath: "1.0"
}
Expand Down
24 changes: 24 additions & 0 deletions src/utils/logger/Logger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Logger, LogLevel } from "./Logger";

describe('Logger', () => {
it('should initialize', () => {
const logLevel: LogLevel = LogLevel.INFO;
const loggableClasses = ['RSPService'];
const logDestination_console = 'CONSOLE';
const logDestination_file = 'FILE';
const logger_console = new Logger(
logLevel,
loggableClasses,
logDestination_console,
);
expect(logger_console).toBeDefined();

const logger_file = new Logger(
logLevel,
loggableClasses,
logDestination_file,
);

expect(logger_file).toBeDefined();
});
});
Loading

0 comments on commit 7a4fdec

Please sign in to comment.