forked from tnb-software/TNB
-
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.
[MGDCTRS-1279] Add splunk to system-x
- Move scc creation into OpenShiftClient
- Loading branch information
Showing
14 changed files
with
15,127 additions
and
51 deletions.
There are no files selected for viewing
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
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
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
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
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
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,39 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>software.tnb</groupId> | ||
<artifactId>system-x-services</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>system-x-splunk</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>TNB :: System-X :: Services :: Splunk</name> | ||
|
||
<properties> | ||
<splunk.client.version>1.9.1</splunk.client.version> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>splunk-artifactory</id> | ||
<name>Splunk Releases</name> | ||
<url>https://splunk.jfrog.io/splunk/ext-releases-local</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.splunk</groupId> | ||
<artifactId>splunk</artifactId> | ||
<version>${splunk.client.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
26 changes: 26 additions & 0 deletions
26
system-x/services/splunk/src/main/java/software/tnb/splunk/account/SplunkAccount.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,26 @@ | ||
package software.tnb.splunk.account; | ||
|
||
import software.tnb.common.account.Account; | ||
|
||
public class SplunkAccount implements Account { | ||
|
||
private String username = "admin"; | ||
|
||
private String password; | ||
|
||
public String username() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
public String password() { | ||
return password; | ||
} | ||
|
||
public void setPassword(String password) { | ||
this.password = password; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
system-x/services/splunk/src/main/java/software/tnb/splunk/service/Splunk.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,45 @@ | ||
package software.tnb.splunk.service; | ||
|
||
import software.tnb.common.deployment.WithExternalHostname; | ||
import software.tnb.common.service.Service; | ||
import software.tnb.splunk.account.SplunkAccount; | ||
import software.tnb.splunk.validation.SplunkValidation; | ||
|
||
import com.splunk.ServiceArgs; | ||
|
||
public abstract class Splunk implements Service, WithExternalHostname { | ||
|
||
protected SplunkAccount account; | ||
private com.splunk.Service client; | ||
private SplunkValidation validation; | ||
|
||
public abstract int apiPort(); | ||
|
||
public abstract SplunkAccount account(); | ||
|
||
public abstract String apiSchema(); | ||
|
||
/** | ||
* Due to self sign certificate, the client is not able to communicate via localhost and port-forward. | ||
* OCP external route with `reencrypt` is used. (Cluster needs to have valid certificate!) | ||
*/ | ||
protected com.splunk.Service client() { | ||
if (client == null) { | ||
ServiceArgs loginArgs = new ServiceArgs(); | ||
loginArgs.setUsername(account().username()); | ||
loginArgs.setPassword(account().password()); | ||
loginArgs.setHost(externalHostname()); | ||
loginArgs.setPort(apiPort()); | ||
loginArgs.setScheme(apiSchema()); | ||
client = com.splunk.Service.connect(loginArgs); | ||
} | ||
return client; | ||
} | ||
|
||
public SplunkValidation validation() { | ||
if (validation == null) { | ||
validation = new SplunkValidation(client()); | ||
} | ||
return validation; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
system-x/services/splunk/src/main/java/software/tnb/splunk/service/local/LocalSplunk.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,90 @@ | ||
package software.tnb.splunk.service.local; | ||
|
||
import software.tnb.common.account.AccountFactory; | ||
import software.tnb.common.deployment.Deployable; | ||
import software.tnb.common.deployment.WithDockerImage; | ||
import software.tnb.splunk.account.SplunkAccount; | ||
import software.tnb.splunk.service.Splunk; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
import java.util.Map; | ||
|
||
@AutoService(Splunk.class) | ||
public class LocalSplunk extends Splunk implements Deployable, WithDockerImage { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(LocalSplunk.class); | ||
|
||
private SplunkContainer container; | ||
|
||
private final int containerApiPort = 8089; | ||
private static final String PASSWORD = "password"; | ||
|
||
@Override | ||
public void deploy() { | ||
LOG.info("Starting Splunk container"); | ||
container = new SplunkContainer(image(), containerApiPort, containerEnvironment()); | ||
container.start(); | ||
LOG.info("Splunk container started"); | ||
} | ||
|
||
@Override | ||
public void undeploy() { | ||
if (container != null) { | ||
LOG.info("Stopping Splunk container"); | ||
container.stop(); | ||
} | ||
} | ||
|
||
@Override | ||
public void openResources() { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public void closeResources() { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public String defaultImage() { | ||
return "quay.io/fuse_qe/splunk:9.0"; | ||
} | ||
|
||
@Override | ||
public SplunkAccount account() { | ||
if (account == null) { | ||
account = AccountFactory.create(SplunkAccount.class); | ||
account.setPassword(PASSWORD); | ||
} | ||
return account; | ||
} | ||
|
||
// SSL is disabled for local deployment because the app has self-signed certificate and Splunk client throws | ||
// "SunCertPathBuilderException: unable to find valid certification path to requested target" exception | ||
@Override | ||
public String apiSchema() { | ||
return "http"; | ||
} | ||
|
||
public Map<String, String> containerEnvironment() { | ||
return Map.of( | ||
"SPLUNK_START_ARGS", "--accept-license", | ||
"SPLUNKD_SSL_ENABLE", "false", | ||
"SPLUNK_PASSWORD", PASSWORD | ||
); | ||
} | ||
|
||
@Override | ||
public String externalHostname() { | ||
return "localhost"; | ||
} | ||
|
||
@Override | ||
public int apiPort() { | ||
return container.getMappedPort(containerApiPort); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...em-x/services/splunk/src/main/java/software/tnb/splunk/service/local/SplunkContainer.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,18 @@ | ||
package software.tnb.splunk.service.local; | ||
|
||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* 8000 port = UI | ||
*/ | ||
public class SplunkContainer extends GenericContainer<SplunkContainer> { | ||
public SplunkContainer(String image, int containerApiPort, Map<String, String> env) { | ||
super(image); | ||
this.withEnv(env); | ||
this.withExposedPorts(containerApiPort, 8000); | ||
this.waitingFor(Wait.forLogMessage(".*Ansible playbook complete, will begin streaming.*", 1)); | ||
} | ||
} |
Oops, something went wrong.