Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion compose.override.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

version: '3.7'
services:
service_jobs:
Expand Down
6 changes: 4 additions & 2 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ services:

service_mq:
image: rabbitmq:3.13-management
ports:
- "5672:5672" # hacky method.. dont ever do this :(
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 30s
Expand All @@ -38,7 +40,7 @@ services:
networks:
- default
- frontend

service_redis:
image: redis:7.2.4
healthcheck:
Expand Down Expand Up @@ -101,7 +103,7 @@ services:
POSTGRES_USER: payments_user
POSTGRES_DB: payments_database
healthcheck:
test: ["CMD", "pg_isready"]
test: [ "CMD", "pg_isready" ]
interval: 20s
timeout: 10s
retries: 10
Expand Down
4 changes: 4 additions & 0 deletions controller/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
JOBS_MQ_URL=service_mq
JOBS_MQ_USER=guest
JOBS_MQ_PASSWORD=guest
JOBS_MQ_PORT=guest
5 changes: 5 additions & 0 deletions controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM eclipse-temurin:21-jre-alpine
VOLUME /tmp
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} controller.jar
ENTRYPOINT ["tail", "-f", "/dev/null"]
47 changes: 46 additions & 1 deletion controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,57 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.workup</groupId>
<artifactId>jobs</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.testcontainers</groupId>
<artifactId>cassandra</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>com.workup</groupId>
Expand All @@ -41,6 +82,10 @@
<artifactId>cliche</artifactId>
<version>110413</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
96 changes: 83 additions & 13 deletions controller/src/main/java/com/workup/controller/CLIHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import asg.cliche.CLIException;
import asg.cliche.Command;
import com.workup.shared.commands.controller.SetMaxThreadsRequest;
import com.workup.shared.commands.controller.*;
import com.workup.shared.commands.jobs.requests.CreateJobRequest;
import com.workup.shared.enums.ControllerQueueNames;
import com.workup.shared.enums.ServiceQueueNames;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javassist.*;
import org.apache.logging.log4j.Level;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -21,7 +26,7 @@ public class CLIHandler {
}

@Command(description = "Set the maximum number of threads for a specific app")
public String maxthreads(String app, int maxThreads) throws CLIException {
public String maxThreads(String app, int maxThreads) throws CLIException {
app = app.toLowerCase();
if (!appQueueMap.containsKey(app)) {
return "Error: app can only be jobs, users, contracts or payments!";
Expand All @@ -33,22 +38,44 @@ public String maxthreads(String app, int maxThreads) throws CLIException {
appQueueMap.get(app),
"",
SetMaxThreadsRequest.builder().withMaxThreads(maxThreads).build());
return "MaxThreads";
return "Command sent";
}

@Command(description = "Set the maximum number of DB connections for a specific app")
public String maxdb(String app, int appNum, String maxDBConn) {
return "maxdb";
public String maxdb(String app, int maxDBConn) {
app = app.toLowerCase();
if (!appQueueMap.containsKey(app)) {
return "Error: app can only be jobs, users, contracts or payments!";
}
if (maxDBConn > 100 || maxDBConn < 1) {
return "Error: Max threads must have a value between 1 and 100";
}
rabbitTemplate.convertAndSend(
appQueueMap.get(app),
"",
SetMaxDBConnectionsRequest.builder().withMaxDBConnections(maxDBConn).build());
return "Command Sent!";
}

@Command(description = "starts a specific app")
public String start(String app, int appNum) {
return "start";
public String start(String app) {
app = app.toLowerCase();
if (!appQueueMap.containsKey(app)) {
return "Error: app can only be jobs, users, contracts or payments!";
}

rabbitTemplate.convertAndSend(appQueueMap.get(app), "", ContinueRequest.builder().build());
return "Command sent";
}

@Command(description = "stops a specific app")
public String freeze(String app, int appNum) {
return "freeze";
public String freeze(String app) {
app = app.toLowerCase();
if (!appQueueMap.containsKey(app)) {
return "Error: app can only be jobs, users, contracts or payments!";
}
rabbitTemplate.convertAndSend(appQueueMap.get(app), "", FreezeRequest.builder().build());
return "Command sent";
}

@Command(description = "stops a specific app")
Expand All @@ -57,8 +84,22 @@ public String setmq(String app, int appNum) {
}

@Command(description = "stops a specific app")
public String setErrorReportingLevel(String app, int appNum) {
return "error level";
public String setLoggingLevel(String app, String level) {
app = app.toLowerCase();
if (!appQueueMap.containsKey(app)) {
return "Error: app can only be jobs, users, contracts or payments!";
}
// To throw an error in case an invalid level is provided :)
Level.valueOf(level);
rabbitTemplate.convertAndSend(
appQueueMap.get(app), "", SetLoggingLevelRequest.builder().withLevel(level).build());
return "Command sent!!";
}

@Command(description = "test")
public void test() {
CreateJobRequest request = CreateJobRequest.builder().withTitle("Ziko").build();
rabbitTemplate.convertSendAndReceive(ServiceQueueNames.JOBS, request);
}

@Command(description = "Creates a new command")
Expand All @@ -67,8 +108,37 @@ public String addcommand(String app, String commandName, String className) {
}

@Command(description = "Updates an existing command")
public String updatecommand(String app, String commandName, String className) {
return "Update Command";
public String updateCommand(String app, String commandName, String className) throws Exception {
app = app.toLowerCase();
if (!appQueueMap.containsKey(app)) {
return "Error: app can only be jobs, users, contracts or payments!";
}
try {
byte[] byteArray = getByteCode(commandName, className);
rabbitTemplate.convertAndSend(
appQueueMap.get(app),
"",
UpdateCommandRequest.builder()
.withCommandName(commandName)
.withByteCode(byteArray)
.build());
} catch (Exception ex) {
ex.printStackTrace();
}
return "Command sent!!";
}

private byte[] getByteCode(String commandName, String className)
throws InstantiationException,
IllegalAccessException,
NotFoundException,
IOException,
CannotCompileException {
ClassPool pool = ClassPool.getDefault();
pool.insertClassPath(new ClassClassPath(ControllerApplication.class));
CtClass ctClass = pool.get(className);
// That's the compiled class byte code
return ctClass.toBytecode();
}

@Command(description = "Deletes an existing command")
Expand Down
19 changes: 9 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

<modules>
<module>shared</module>
<module>controller</module>
<module>services/jobs</module>
<module>services/payments</module>
<module>services/users</module>
Expand Down Expand Up @@ -61,18 +60,18 @@
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<gitConfig>
<pull.rebase>true</pull.rebase>
</gitConfig>
<gitConfig>
<pull.rebase>true</pull.rebase>
</gitConfig>
</configuration>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
</executions>
</plugin>
</plugin>
</plugins>
</build>

Expand Down
23 changes: 18 additions & 5 deletions services/jobs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,26 @@
<artifactId>shared</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -94,6 +101,12 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
Loading