Skip to content

Commit

Permalink
Add support JDG8+ container
Browse files Browse the repository at this point in the history
  • Loading branch information
Croway committed Jul 2, 2021
1 parent 272603d commit 59cc7dc
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 0 deletions.
15 changes: 15 additions & 0 deletions containers/jdg/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Wildfly

- homepage: https://www.redhat.com/it/technologies/jboss-middleware/data-grid

## Usage
```java
final JdgConfiguration conf = JdgConfiguration.builder().httpPort(11222).build();

try (Container cont = new JdgContainer<>(conf)) {
cont.start()
}
```

## Compatibility
- Jdg 8+
54 changes: 54 additions & 0 deletions containers/jdg/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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>
<artifactId>containers-parent</artifactId>
<groupId>org.jboss.qa.jcontainer.containers</groupId>
<version>1.3.2-SNAPSHOT</version>
</parent>
<artifactId>jdg</artifactId>
<name>JContainer Manager :: Containers :: JDG</name>
<properties>
<version.wildfly>2.0.5.Final</version.wildfly>
<version.creaper>1.1.0</version.creaper>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-bom</artifactId>
<version>12.1.0.CR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${version.slf4j}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jboss.qa.jcontainer.jdg;

import org.jboss.qa.jcontainer.Client;

import java.io.IOException;
import java.util.List;

public class JdgClient<T extends JdgConfiguration> extends Client<T> {
private static final String ERROR_MSG = "JDG container does not support client";

public JdgClient(T configuration) {
super(configuration);
}

@Override
public boolean isConnected() {
return false;
}

@Override
protected void connectInternal() throws Exception {
throw new UnsupportedOperationException(ERROR_MSG);
}

@Override
protected void executeInternal(String command) throws Exception {
throw new UnsupportedOperationException(ERROR_MSG);
}

@Override
protected void executeInternal(List<String> commands) throws Exception {
throw new UnsupportedOperationException(ERROR_MSG);
}

@Override
protected void closeInternal() throws IOException {
throw new UnsupportedOperationException(ERROR_MSG);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.qa.jcontainer.jdg;

import org.apache.commons.lang3.SystemUtils;

import org.jboss.qa.jcontainer.JavaConfiguration;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import lombok.Getter;

public class JdgConfiguration extends JavaConfiguration {

public static final int DEFAULT_HTTP_PORT = 11222;
private static final String START_COMMAND = "server";

@Getter
protected final int httpPort;

public JdgConfiguration(Builder<?> builder) {
super(builder);
httpPort = builder.httpPort;
}

public static Builder<?> builder() {
return new Builder2();
}

@Override
public int getBusyPort() {
return httpPort;
}

@Override
public List<String> generateCommand() {
final List<String> cmd = new ArrayList<>();
if (SystemUtils.IS_OS_WINDOWS) {
cmd.add("cmd");
cmd.add("/c");
cmd.add(new File(directory, "bin" + File.separator + START_COMMAND + ".bat").getAbsolutePath());
} else {
cmd.add("bash");
cmd.add(new File(directory, "bin" + File.separator + START_COMMAND + ".sh").getAbsolutePath());
}
return cmd;
}

public File getConfigurationFolder() {
return new File(directory, "server" + File.separator + "conf");
}

public abstract static class Builder<T extends Builder<T>> extends JavaConfiguration.Builder<T> {

protected int httpPort;

public Builder() {
super();
httpPort(DEFAULT_HTTP_PORT);
password("");
logFileName("server.log");
}

public T httpPort(int httpPort) {
this.httpPort = httpPort;
return self();
}

public JdgConfiguration build() {
return new JdgConfiguration(this);
}
}

private static class Builder2 extends Builder<Builder2> {
@Override
protected Builder2 self() {
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jboss.qa.jcontainer.jdg;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang3.StringUtils;

import org.jboss.qa.jcontainer.AbstractContainer;

import java.io.File;

public class JdgContainer<T extends JdgConfiguration, U extends JdgClient<T>, V extends JdgUser>
extends AbstractContainer<T, U, V> {
public JdgContainer(T configuration) {
super(configuration);
}

@Override
protected String getBasicCommand() {
return null;
}

@Override
protected File getLogDirInternal() {
return new File(configuration.getDirectory(), "server" + File.separator + "log");
}

@Override
public void addUser(V user) throws Exception {
final File usersFile = new File(configuration.getConfigurationFolder(), "users.properties");
final File rolesFile = new File(configuration.getConfigurationFolder(), "groups.properties");
final PropertiesConfiguration propConfUsers = new PropertiesConfiguration(usersFile);
propConfUsers.setProperty(user.getUsername(), user.getPassword());
propConfUsers.save();

final PropertiesConfiguration propConfRoles = new PropertiesConfiguration(rolesFile);
propConfRoles.setProperty(user.getUsername(), StringUtils.join(user.getRoles(), ","));
propConfRoles.save();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.jboss.qa.jcontainer.jdg;

import org.jboss.qa.jcontainer.User;

public class JdgUser extends User {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.jboss.qa.jcontainer.jdg.test;

import org.jboss.qa.jcontainer.AbstractContainer;
import org.jboss.qa.jcontainer.jdg.JdgConfiguration;
import org.jboss.qa.jcontainer.jdg.JdgContainer;
import org.jboss.qa.jcontainer.jdg.JdgUser;
import org.jboss.qa.jcontainer.test.ContainerTest;
import org.jboss.qa.jcontainer.util.FileUtils;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RunWith(JUnit4.class)
public class JdgContainerTest extends ContainerTest {
public static final String JDG_HOME = "/home/federico/Downloads/redhat-datagrid-8.2.0-server"; //getProperty("jdg.home");
protected static AbstractContainer container;

@BeforeClass
public static void beforeClass() throws Exception {
final JdgConfiguration conf = JdgConfiguration.builder().directory(JDG_HOME).build();
container = new JdgContainer(conf);
final JdgUser user = new JdgUser();
user.setUsername("infinispanUsername");
user.setPassword("infinispanPassword");
user.addRoles("admin", "dev");
container.addUser(user);
container.start();

System.out.println(container.isClientSupported());
}

@AfterClass
public static void afterClass() throws Exception {
if (container != null) {
container.stop();
}
}

@Test
public void baseTest() throws Exception {
Assert.assertTrue(container.isRunning());
}

@Test
public void defaultLogFileTest() throws Exception {
Assert.assertTrue(container.getDefaultLogFile().exists());
log.debug("File '{}' - length = {}", container.getDefaultLogFile().getName(), container.getDefaultLogFile().length());
Assert.assertFalse(FileUtils.isEmpty(container.getDefaultLogFile()));
}

@Test
public void stdoutLogFileTest() throws Exception {
Assert.assertTrue(container.getStdoutLogFile().exists());
log.debug("File '{}' - length = {}", container.getStdoutLogFile().getName(), container.getStdoutLogFile().length());
Assert.assertFalse(FileUtils.isEmpty(container.getStdoutLogFile()));
}
}
1 change: 1 addition & 0 deletions containers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<module>wildfly</module>
<module>eap</module>
<module>tomcat</module>
<module>jdg</module>
</modules>
<dependencies>
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@
<name>fuse.home</name>
<value>${fuse.home}</value>
</property>
<property>
<name>jdg.home</name>
<value>${jdg.home}</value>
</property>
</systemProperties>
</configuration>
</plugin>
Expand Down

0 comments on commit 59cc7dc

Please sign in to comment.