Skip to content

Ms logging #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
90b2149
renaming files for initial config
adittyashrivastava Feb 15, 2025
994a479
added ws logger implementation
aizausman Feb 16, 2025
b668c8b
removed random print statement
aizausman Feb 16, 2025
f7f76db
adds login feature to the system and corrects endpoint bugs
adittyashrivastava Feb 16, 2025
17d00bf
Add a logger class for logging purposes
kkshitiz-cmu Feb 16, 2025
e243fca
Add logging to create and retrieve classes
kkshitiz-cmu Feb 16, 2025
f9556dc
Add import statements
kkshitiz-cmu Feb 16, 2025
1ec192f
Add logger file in docker copy command
kkshitiz-cmu Feb 16, 2025
9c68f99
feat: implement delete order functionality for ws and ms architectures
helloXiaoFu Feb 17, 2025
4395f35
Merge pull request #4 from kkshitiz-cmu/feature/delete-order
helloXiaoFu Feb 17, 2025
e846793
Create asynchronous logging for create and retrieve
kkshitiz-cmu Feb 17, 2025
3d70cfe
Merge branch 'main' into ms-logging
kkshitiz-cmu Feb 17, 2025
d3f57d4
Add logging for delete service
kkshitiz-cmu Feb 17, 2025
2ef5543
Add async logging, and add logging for delete services as well
kkshitiz-cmu Feb 17, 2025
5e7c421
Merge branch 'main' into authenticaltion-feature
adittyashrivastava Feb 17, 2025
7b51a37
adds authentication for delete order in web service system
adittyashrivastava Feb 17, 2025
7dfeed7
adds instruvtions for login to web service into the README file
adittyashrivastava Feb 17, 2025
563d3ae
Add unique log file names for the different microservices
kkshitiz-cmu Feb 17, 2025
a74332d
Add delete service configuration and fix client build issues
helloXiaoFu Feb 17, 2025
96f1397
docs: update INSTALL.md to include delete service information
helloXiaoFu Feb 17, 2025
af2f344
Merge branch 'main' into authenticaltion-feature
adittyashrivastava Feb 17, 2025
a65f763
start recreating changes
Harivallabha Feb 17, 2025
f4dd5e7
Dockerfile changes
HarivRangarajan Feb 17, 2025
037c4ed
add auth changes to ms.yml
HarivRangarajan Feb 17, 2025
2494f83
fix auth
HarivRangarajan Feb 17, 2025
ff6c3a1
Merge branch 'main' into ws-logging-feature
aizausman Feb 17, 2025
71a9e9c
reapply all ms-auth changes
HarivRangarajan Feb 17, 2025
db2ad68
foo to abc fixes
HarivRangarajan Feb 17, 2025
0afa84c
added changes for auth and delete services
aizausman Feb 17, 2025
ccf3720
fix port issues
HarivRangarajan Feb 17, 2025
8af38e2
Merge pull request #1 from kkshitiz-cmu/ws-logging-feature
aizausman Feb 17, 2025
405816e
finish auth changes
HarivRangarajan Feb 17, 2025
2fe6705
Merge pull request #5 from kkshitiz-cmu/hrangara/ms-auth/v1
HarivRangarajan Feb 17, 2025
c07edc9
polish and push final auth changes for current design
HarivRangarajan Feb 17, 2025
159bfac
Merge pull request #6 from kkshitiz-cmu/hrangara/ms-auth/v2
HarivRangarajan Feb 17, 2025
7907d95
Merge branch 'main' into ms-logging
kkshitiz-cmu Feb 17, 2025
d0c4f41
Add logging to authenticate service
kkshitiz-cmu Feb 18, 2025
e49d4fa
Merge branch 'main' into ms-logging
kkshitiz-cmu Feb 18, 2025
2c18b37
Add logging for logging in
kkshitiz-cmu Feb 18, 2025
6f8a504
fixes ws auth blocker
adittyashrivastava Feb 18, 2025
5fc4a52
Add loggig to auth
kkshitiz-cmu Feb 18, 2025
df0956e
Merge branch 'main' into ms-logging
kkshitiz-cmu Feb 18, 2025
280363d
Add foo password to the mysql cntainer
kkshitiz-cmu Feb 18, 2025
314a6d9
Add async logging with a new loggin service
kkshitiz-cmu Feb 18, 2025
2e94a36
Remove unused and commented code
kkshitiz-cmu Feb 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Dockerfile-auth
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from openjdk:16
ARG MYSQL_PASSWORD

WORKDIR /usr/app
COPY ms/mysql-connector-java-5.1.45-bin.jar lib/
ENV CLASSPATH=.:lib/mysql-connector-java-5.1.45-bin.jar:${CLASSPATH}

COPY ms/Configuration-tmplt.java ./
RUN sed "s/<PASSWORD>/${MYSQL_PASSWORD}/g" < Configuration-tmplt.java > Configuration.java
RUN rm Configuration-tmplt.java

COPY ms/AuthServices.java ms/AuthServicesAI.java ms/LoggingServicesAI.java ./
RUN javac *.java

CMD java AuthServices
2 changes: 1 addition & 1 deletion Dockerfile-cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ COPY ms/Configuration-tmplt.java ./
RUN sed "s/<PASSWORD>/${MYSQL_PASSWORD}/g" < Configuration-tmplt.java > Configuration.java
RUN rm Configuration-tmplt.java

COPY ms/CreateServices.java ms/CreateServicesAI.java ./
COPY ms/LoggingServicesAI.java ms/CreateServices.java ms/CreateServicesAI.java ms/AuthServicesAI.java ./
RUN javac *.java

CMD java CreateServices
18 changes: 18 additions & 0 deletions Dockerfile-ds
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM openjdk:16
ARG MYSQL_PASSWORD

WORKDIR /usr/app

COPY ms/mysql-connector-java-5.1.45-bin.jar lib/
ENV CLASSPATH=.:lib/mysql-connector-java-5.1.45-bin.jar:${CLASSPATH}

COPY ms/Configuration-tmplt.java ./
RUN sed "s/<PASSWORD>/${MYSQL_PASSWORD}/g" < Configuration-tmplt.java > Configuration.java
RUN rm Configuration-tmplt.java


COPY ms/LoggingServicesAI.java ms/DeleteServices.java ms/DeleteServicesAI.java ms/AuthServicesAI.java ./

RUN javac *.java

CMD java DeleteServices
15 changes: 15 additions & 0 deletions Dockerfile-logging
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from openjdk:16
# ARG MYSQL_PASSWORD

WORKDIR /usr/app
COPY ms/mysql-connector-java-5.1.45-bin.jar lib/
ENV CLASSPATH=.:lib/mysql-connector-java-5.1.45-bin.jar:${CLASSPATH}

COPY ms/Configuration-tmplt.java ./
RUN sed "s/<PASSWORD>/${MYSQL_PASSWORD}/g" < Configuration-tmplt.java > Configuration.java
RUN rm Configuration-tmplt.java

COPY ms/AsyncHandler.java ms/LoggingServices.java ms/LoggingServicesAI.java ./
RUN javac *.java

CMD java LoggingServices
2 changes: 1 addition & 1 deletion Dockerfile-msc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /usr/app
COPY ms/Configuration-tmplt.java ./
RUN sed "s/<PASSWORD>//g" < Configuration-tmplt.java > Configuration.java
RUN rm Configuration-tmplt.java
COPY ms/registry.properties ms/OrdersUI.java ms/MSClientAPI.java ms/CreateServicesAI.java ms/RetrieveServicesAI.java ./
COPY ms/registry.properties ms/OrdersUI.java ms/MSClientAPI.java ms/CreateServicesAI.java ms/RetrieveServicesAI.java ms/DeleteServicesAI.java ms/AuthServicesAI.java ./
RUN javac *.java

CMD java OrdersUI
5 changes: 4 additions & 1 deletion Dockerfile-rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

from openjdk:16
ARG MYSQL_PASSWORD

Expand All @@ -9,7 +10,9 @@ COPY ms/Configuration-tmplt.java ./
RUN sed "s/<PASSWORD>/${MYSQL_PASSWORD}/g" < Configuration-tmplt.java > Configuration.java
RUN rm Configuration-tmplt.java

COPY ms/RetrieveServices.java ms/RetrieveServicesAI.java ./

COPY ms/LoggingServicesAI.java ms/RetrieveServices.java ms/RetrieveServicesAI.java ms/AuthServicesAI.java ./

RUN javac *.java

CMD java RetrieveServices
3 changes: 3 additions & 0 deletions Dockerfile-ws
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RUN npm -y init

COPY ws/REST.js ws/
COPY ws/Server.js ws/
COPY ws/eventBus.js ws/
COPY ws/logger.js ws/
COPY ws/auth.js ws/
COPY ws/config ws/config
WORKDIR /usr/app/ws
RUN sed "s/<PASSWORD>/${MYSQL_PASSWORD}/g" > config/mysql.config.json < config/mysql.config.json-tmplt
Expand Down
11 changes: 10 additions & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ easy to navigate to on the command line. It’s a good idea to give it a nice sh
- `Dockerfile-wsc` – file: Docker build instructions for the web-services client
- `Dockerfile-cs` – file: Docker build instructions for the microservices service: CreateServices
- `Dockerfile-rs` – file: Docker build instructions for the microservices service: RetrieveServices
- `Dockerfile-ds` – file: Docker build instructions for the microservices service: DeleteServices
- `Dockerfile-msc` – file: Docker build instructions for the microservices service
- `stack-ws.yml`, `stack-ws-mx.yml` – file: Docker compose for building and running the web-services server and database stack. (`-mx` for Apple Silicon Macs.)
- `stack-ms.yml`, `stack-ms-mx.yml` – file: Docker compose file for building and running the microservices server and database stack. (`-mx` for Apple Silicon Macs.)
Expand Down Expand Up @@ -235,7 +236,11 @@ This will download the necessary base containers and build the microservices con
...
✔ Service client Built 1.5s
✔ Service retrieve Built 1.5s
✔ Service create Built
✔ Service create
Built
1.5s
✔ Service delete Built 1.5s

```
Or
```
Expand All @@ -254,12 +259,16 @@ The first time you do this (or have removed the contents of the ms-db folder). T
```
ms_client | 2: Retrieve an order by ID.
ms_client | 3: Add a new order to the order database.
ms_client | 4: Delete an order by ID.
ms_client | X: Exit
ms_client |
...
ms_create | Registered services:
ms_create | CreateServices
...
ms_create | Registered services:
ms_create | DeleteServices
...
ms_retrieve | Registered services:
ms_mysql | Version: '5.7.33' socket: '/var/run/mysq...
```
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@ This project contains the source code for the architecturally-compliant coding a
The assignment instructions are given elsewhere.

The installation instructions are available in [INSTALL.md](INSTALL.md).

After installation the system can be accesed by a set of two user credentials:

| User ID | Password |
|---------|----------------|
| user1 | ChaosMonkey@24 |
| user2 | OpenWebMath@77 |

The user who interacts with the system will first have to log into the system by entering these credentials when prompted on the screen, to access any of the other APIs.

15 changes: 15 additions & 0 deletions init-db/dbtemplate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,23 @@
--

DROP TABLE IF EXISTS `orders`;
DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
`user_id` VARCHAR(10) NOT NULL,
`password` VARCHAR(100) DEFAULT NULL,
`token` VARCHAR(100) DEFAULT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- Insert users into the `users` table
INSERT INTO `users` (`user_id`, `password`) VALUES
('user1', 'ChaosMonkey@24'),
('user2', 'OpenWebMath@77'),
('Hari', 'badpassword'),
('Kshitiz', 'betterpassword');

CREATE TABLE `orders` (
`order_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`order_date` date DEFAULT NULL,
Expand Down
57 changes: 57 additions & 0 deletions stack-ms-mx.yml → ms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ services:
MYSQL_PASSWORD: foo
depends_on:
- mysql
- auth
- logging
environment:
RMI_REMOTE_HOST: ms_create
RMI_REMOTE_PORT: 1099
Expand All @@ -27,6 +29,8 @@ services:
MYSQL_PASSWORD: foo
depends_on:
- mysql
- auth
- logging
environment:
RMI_REMOTE_HOST: ms_retrieve
RMI_REMOTE_PORT: 1098
Expand All @@ -35,6 +39,26 @@ services:
networks:
- ms

delete:
image: ms_delete
container_name: ms_delete
build:
context: .
dockerfile: Dockerfile-ds
args:
MYSQL_PASSWORD: foo
depends_on:
- mysql
- auth
- logging
environment:
RMI_REMOTE_HOST: ms_delete
RMI_REMOTE_PORT: 1096
MYSQL_REMOTE_HOST: ms_mysql
MYSQL_REMOTE_PORT: 3306
networks:
- ms

client:
image: ms_client
container_name: ms_client
Expand All @@ -43,13 +67,46 @@ services:
build:
context: .
dockerfile: Dockerfile-msc
depends_on:
- auth
command: java OrdersUI
environment:
RMI_REMOTE_HOST: ms_server
RMI_REMOTE_PORT: 1099
networks:
- ms

auth:
image: ms_auth
container_name: ms_auth
build:
context: .
dockerfile: Dockerfile-auth
args:
MYSQL_PASSWORD: foo
depends_on:
- mysql
- logging
environment:
RMI_REMOTE_HOST: ms_auth
RMI_REMOTE_PORT: 1097
MYSQL_REMOTE_HOST: ms_mysql
MYSQL_REMOTE_PORT: 3306
networks:
- ms

logging:
image: ms_logging
container_name: ms_logging
build:
context: .
dockerfile: Dockerfile-logging
environment:
RMI_REMOTE_HOST: ms_logging
RMI_REMOTE_PORT: 1100
networks:
- ms

mysql:
image: mysql:5
platform: linux/amd64
Expand Down
58 changes: 58 additions & 0 deletions ms/AsyncHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

public class AsyncHandler extends Handler {
private final Handler delegate;
private final BlockingQueue<LogRecord> queue;
private final Thread worker;
private volatile boolean running = true;

public AsyncHandler(Handler delegate) {
this.delegate = delegate;
this.queue = new LinkedBlockingQueue<>();

this.worker = new Thread(() -> {
while (running || !queue.isEmpty()) {
try {
LogRecord record = queue.poll(100, TimeUnit.MILLISECONDS);
if (record != null) {
delegate.publish(record);
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
} catch (Exception ex) {
System.err.println("AsyncHandler error: " + ex.getMessage());
}
}
});
worker.setDaemon(true);
worker.start();
}

@Override
public void publish(LogRecord record) {
if (!isLoggable(record)) return;
queue.offer(record);
}

@Override
public void flush() {
delegate.flush();
}

@Override
public void close() throws SecurityException {
running = false;
try {
worker.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
delegate.close();
}
}
Loading