Skip to content

Merge master #43

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

Merged
merged 4 commits into from
Jul 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ public void onNext(Frame object) {
}

public void killContainerByName(String name) {
for (Container container : client.listContainersCmd().withNameFilter(Set.of(name)).exec()) {
LOGGER.debug("Fetching container to kill {}.", name);
List<Container> containers = client.listContainersCmd().withNameFilter(Set.of(name)).exec();
LOGGER.debug("Number of containers to kill: {} for name {}.", containers.size(), name);
if (containers.size() != 1) {
LOGGER.error("There is more than 1 container for name {}.", name);
}
for (Container container : containers) {
client.killContainerCmd(container.getId()).exec();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public String id() {

@Override
public void close() {
LOGGER.debug("Close called for session {}.", id);
try {
dockerService.killContainerByName(containerName());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class JShellSessionService {
private void initScheduler() {
scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(() -> {
LOGGER.info("Scheduler heartbeat: started.");
jshellSessions.keySet()
.stream()
.filter(id -> jshellSessions.get(id).isClosed())
Expand All @@ -36,6 +37,7 @@ private void initScheduler() {
.stream()
.filter(id -> jshellSessions.get(id).shouldDie())
.toList();
LOGGER.info("Scheduler heartbeat: sessions ready to die: {}", toDie);
for (String id : toDie) {
try {
deleteSession(id);
Expand All @@ -49,10 +51,13 @@ private void initScheduler() {

void notifyDeath(String id) {
JShellService shellService = jshellSessions.remove(id);
if (shellService == null)
if (shellService == null) {
LOGGER.debug("Notify death on already removed session {}.", id);
return;
}
if (!shellService.isClosed()) {
LOGGER.error("JShell Service isn't dead when it should for id {}.", id);
return;
}
LOGGER.info("Session {} died.", id);
}
Expand Down Expand Up @@ -82,8 +87,11 @@ public JShellService oneTimeSession(@Nullable StartupScriptId startupScriptId)

public void deleteSession(String id) throws DockerException {
JShellService service = jshellSessions.remove(id);
service.stop();
scheduler.schedule(service::close, 500, TimeUnit.MILLISECONDS);
try {
service.stop();
} finally {
scheduler.schedule(service::close, 500, TimeUnit.MILLISECONDS);
}
}

private synchronized JShellService createSession(SessionInfo sessionInfo)
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@ JShellAPI is a REST API, and whenever some code is received, it will create a se
# How to build JShellAPI in and run it in Docker
- Launch Docker
- Run `jibDockerBuild` to create the image
- Create a folder outside the project
- `cd` to this folder
- Copy `docker-compose.yaml` inside it
- Optionally, create `config/application.yaml` where you can put custom config (see the actual [application.yaml](JShellAPI/src/main/resources/application.yaml))
- If you don't create it, delete the `command: ["--spring.config.location=file:///home/backend/config/application.yaml"]` line in the `docker-compose.yaml`
* * If you don't create it, delete the `command: ["--spring.config.location=file:///home/backend/config/application.yaml"]` line in the `docker-compose.yaml`
- Run `docker compose build` or `docker-compose build` in the folder, depending on your version of Docker.
- Run `docker compose start` or `docker-compose start` in the folder, depending on your version of Docker.
- Note that some folders or files may be created automatically inside this folder
- File tree representation:
```
-folder outside the project
-docker-compose.yaml
-config (optionnal)
-application.yaml
```

## How to use JShellApi ?
See [JShellAPI README](JShellAPI/README.MD)
Loading