-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Main author: I just stole it :( Co-authored-by: Ziad Othman <ziadsadek999@gmail.com>
- Loading branch information
1 parent
b1ab659
commit 6a7370b
Showing
19 changed files
with
439 additions
and
120 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
HELP.md | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip | ||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.2.5</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<groupId>com.workup</groupId> | ||
<artifactId>controller</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>controller</name> | ||
<description>Controller module</description> | ||
<properties> | ||
<java.version>21</java.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-amqp</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.workup</groupId> | ||
<artifactId>shared</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.googlecode.clichemaven</groupId> | ||
<artifactId>cliche</artifactId> | ||
<version>110413</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.cosium.code</groupId> | ||
<artifactId>git-code-format-maven-plugin</artifactId> | ||
<version>5.3</version> | ||
<executions> | ||
<execution> | ||
<id>validate-code-format</id> | ||
<goals> | ||
<goal>validate-code-format</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.cosium.code</groupId> | ||
<artifactId>google-java-format</artifactId> | ||
<version>5.3</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
83 changes: 83 additions & 0 deletions
83
controller/src/main/java/com/workup/controller/CLIHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.workup.controller; | ||
|
||
import asg.cliche.CLIException; | ||
import asg.cliche.Command; | ||
import com.workup.shared.commands.controller.SetMaxThreadsRequest; | ||
import com.workup.shared.enums.ControllerQueueNames; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.springframework.amqp.core.AmqpTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class CLIHandler { | ||
@Autowired AmqpTemplate rabbitTemplate; | ||
private static final Map<String, String> appQueueMap = new HashMap<>(); | ||
|
||
static { | ||
appQueueMap.put("jobs", ControllerQueueNames.JOBS); | ||
appQueueMap.put("users", ControllerQueueNames.USERS); | ||
appQueueMap.put("payments", ControllerQueueNames.PAYMENTS); | ||
appQueueMap.put("contracts", ControllerQueueNames.CONTRACTS); | ||
} | ||
|
||
@Command(description = "Set the maximum number of threads for a specific app") | ||
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!"; | ||
} | ||
if (maxThreads > 100 || maxThreads < 1) { | ||
return "Error: Max threads must have a value between 1 and 50"; | ||
} | ||
rabbitTemplate.convertAndSend( | ||
appQueueMap.get(app), | ||
"", | ||
SetMaxThreadsRequest.builder().withMaxThreads(maxThreads).build()); | ||
return "MaxThreads"; | ||
} | ||
|
||
@Command(description = "Set the maximum number of DB connections for a specific app") | ||
public String maxdb(String app, int appNum, String maxDBConn) { | ||
return "maxdb"; | ||
} | ||
|
||
@Command(description = "starts a specific app") | ||
public String start(String app, int appNum) { | ||
return "start"; | ||
} | ||
|
||
@Command(description = "stops a specific app") | ||
public String freeze(String app, int appNum) { | ||
return "freeze"; | ||
} | ||
|
||
@Command(description = "stops a specific app") | ||
public String setmq(String app, int appNum) { | ||
return "setmq"; | ||
} | ||
|
||
@Command(description = "stops a specific app") | ||
public String setErrorReportingLevel(String app, int appNum) { | ||
return "error level"; | ||
} | ||
|
||
@Command(description = "Creates a new command") | ||
public String addcommand(String app, String commandName, String className) { | ||
return "Add command"; | ||
} | ||
|
||
@Command(description = "Updates an existing command") | ||
public String updatecommand(String app, String commandName, String className) { | ||
return "Update Command"; | ||
} | ||
|
||
@Command(description = "Deletes an existing command") | ||
public String deletecommand(String app, String commandName, String className) { | ||
return "Delete command"; | ||
} | ||
|
||
@Command(description = "stops a specific app") | ||
public String updateClass(String app, int appNum) { | ||
return "update class"; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
controller/src/main/java/com/workup/controller/ControllerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.workup.controller; | ||
|
||
import asg.cliche.Shell; | ||
import asg.cliche.ShellFactory; | ||
import java.io.IOException; | ||
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; | ||
import org.springframework.amqp.support.converter.MessageConverter; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class ControllerApplication { | ||
|
||
public static void main(String[] args) throws IOException { | ||
SpringApplication.run(ControllerApplication.class, args); | ||
} | ||
|
||
@Bean | ||
public ApplicationRunner runner(CLIHandler cliHandler) { | ||
return args -> { | ||
Shell shell = ShellFactory.createConsoleShell("", "Controller", cliHandler); | ||
shell.commandLoop(); | ||
}; | ||
} | ||
|
||
@Bean | ||
public MessageConverter messageConverter() { | ||
return new Jackson2JsonMessageConverter(); | ||
} | ||
|
||
@Bean | ||
public CLIHandler cliHandler() { | ||
return new CLIHandler(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
spring.application.name=controller | ||
spring.rabbitmq.host=localhost | ||
spring.rabbitmq.port=5672 | ||
spring.rabbitmq.username=guest | ||
spring.rabbitmq.password=guest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.