-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add implementation for extraction of env and logs from Docker containers #2
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2f8aec2
Add implementation for extraction of env and logs from container
sigalsax 998292e
Add program properties file and models
sigalsax 3b82480
Add ContainerRetrieval class, separating out direct interfacing with …
sigalsax 7aad069
Clean Env/Log objects and link the view and the user object to contro…
sigalsax bc81a1c
This commit adds the following:
sigalsax 154513e
Support DI and add AppConfig bean file
sigalsax 06ffa93
Update HTML to JSP, add Model to Controller, add Service to input val…
sigalsax 8799d3b
Add ability to query logs and fix ConjurLog object
sigalsax 1433c36
Convert Java objects to JSON and render JSON
sigalsax 2ed0c40
Separate solution design from README docs
sigalsax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
...oubleshooting/authenticationtroubleshooting/AuthenticationTroubleshootingApplication.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,73 @@ | ||
package com.troubleshooting.authenticationtroubleshooting; | ||
|
||
import com.github.dockerjava.api.async.ResultCallback; | ||
import com.github.dockerjava.api.command.ExecCreateCmdResponse; | ||
import com.github.dockerjava.api.command.LogContainerCmd; | ||
import com.github.dockerjava.api.model.Frame; | ||
import com.github.dockerjava.api.model.Info; | ||
import com.github.dockerjava.core.command.ExecStartResultCallback; | ||
import com.github.dockerjava.core.command.LogContainerResultCallback; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import com.github.dockerjava.api.DockerClient; | ||
import com.github.dockerjava.core.DockerClientBuilder; | ||
import com.github.dockerjava.api.model.Image; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.OutputStream; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
|
||
@SpringBootApplication | ||
public class AuthenticationTroubleshootingApplication { | ||
|
||
public static void main(String[] args) { | ||
String containerID = "8e53411614f2"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please read from configurations (note that you usually want to work differently locally and in production) |
||
|
||
DockerClient dockerClient; | ||
dockerClient = DockerClientBuilder.getInstance().build(); | ||
|
||
// Extract Env | ||
OutputStream outputStream = new ByteArrayOutputStream(); | ||
|
||
ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(containerID) | ||
.withAttachStdout(true).withAttachStderr(true).withCmd("env").exec(); | ||
|
||
System.out.println(dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(new ExecStartResultCallback(outputStream, null))); | ||
|
||
// Extract Logs | ||
final List<String> loggingFrames = getDockerLogs(dockerClient, containerID); | ||
for(int i = 0; i < loggingFrames.size(); i++) { | ||
System.out.println(loggingFrames.get(i)); | ||
} | ||
|
||
SpringApplication.run(AuthenticationTroubleshootingApplication.class, args); | ||
} | ||
|
||
public static List<String> getDockerLogs(DockerClient dockerClient, String containerID) { | ||
Pattern p = Pattern.compile("database"); | ||
|
||
final List<String> logs = new ArrayList<>(); | ||
LogContainerCmd logContainer = dockerClient.logContainerCmd(containerID).withStdOut(true).withStdErr(true); | ||
try { | ||
logContainer.exec(new LogContainerResultCallback() { | ||
@Override | ||
public void onNext(Frame item) { | ||
if (p.matcher(item.toString()).find()) { | ||
logs.add(item.toString()); | ||
} | ||
} | ||
}).awaitCompletion(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
return logs; | ||
} | ||
} | ||
|
||
|
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 @@ | ||
|
13 changes: 13 additions & 0 deletions
13
...shooting/authenticationtroubleshooting/AuthenticationTroubleshootingApplicationTests.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,13 @@ | ||
package com.troubleshooting.authenticationtroubleshooting; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
class AuthenticationTroubleshootingApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class should contain only the logic that we need to run the application. not business logic
You might put here - general spring boot configurations (DI/logging etc.)