diff --git a/README.md b/README.md index 2c08ee7..149e6f1 100644 --- a/README.md +++ b/README.md @@ -13,23 +13,38 @@ - Run command: ```` cd $JBOSS_HOME/bin -./jboss-cli.sh --file=adapter-install-offline.cli -Dserver.config=standalone-full.xml +./jboss-cli.sh --file=adapter-install-offline.cli -Dserver.config=standalone-full-ha.xml ```` if you are using older version of keycloak adapter -Dserver.config property won't work so you need to specify standalone-full.xml within cli file -##### Add jms-queue inside standalone-full.xml +##### Add jms-topic inside standalone-full-ha.xml ```` - + ```` ++ Change default password from CHANGE ME!! to something else in acivemq subsystem in + jdbc:h2:/tmp/ParserManager;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE + h2 + + sa + sa + + +```` + #### Run wildfly ```` -standalone.sh -c standalone-full.xml +./standalone.sh -c standalone-full-ha.xml ```` #### Deploy project: diff --git a/rest/pom.xml b/rest/pom.xml index 57d23ea..ab4a87d 100644 --- a/rest/pom.xml +++ b/rest/pom.xml @@ -40,8 +40,12 @@ com.fasterxml.jackson.core jackson-databind - 2.0.2 - provided + 2.9.5 + + + org.apache.httpcomponents + httpclient + 4.5.5 jboss @@ -126,7 +130,7 @@ ${pom.basedir}/src/test/resources - standalone-full.xml + standalone-full-ha.xml @@ -134,6 +138,41 @@ + + exec-maven-plugin + org.codehaus.mojo + 1.2.1 + + + Add base directory 1 + process-test-resources + + exec + + + mkdir + + -p + ${pom.basedir}/target/wildfly-11.0.0.Final/standalone-ha-node-1/deployments + + + + + Add base directory 2 + process-test-resources + + exec + + + mkdir + + -p + ${pom.basedir}/target/wildfly-11.0.0.Final/standalone-ha-node-2/deployments + + + + + org.apache.maven.plugins maven-surefire-plugin diff --git a/rest/src/main/java/cz/fi/muni/pv243/ws/service/ParserConfigurationMDB.java b/rest/src/main/java/cz/fi/muni/pv243/ws/service/ParserConfigurationMDB.java index 08db859..d50e4f2 100644 --- a/rest/src/main/java/cz/fi/muni/pv243/ws/service/ParserConfigurationMDB.java +++ b/rest/src/main/java/cz/fi/muni/pv243/ws/service/ParserConfigurationMDB.java @@ -25,8 +25,8 @@ @Named @MessageDriven(name = "ParserConfigurationHandler", activationConfig = { - @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), - @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/exported/jms/queue/ChangedParsersQueue"), + @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"), + @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:jboss/exported/jms/topic/ChangedParsersTopic"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") /*mappedName = "jms/myQueue"*/}) public class ParserConfigurationMDB implements MessageListener { diff --git a/rest/src/test/java/cz.fi.muni.pv243.rest/ClusterParserServiceTest.java b/rest/src/test/java/cz.fi.muni.pv243.rest/ClusterParserServiceTest.java new file mode 100644 index 0000000..72bf288 --- /dev/null +++ b/rest/src/test/java/cz.fi.muni.pv243.rest/ClusterParserServiceTest.java @@ -0,0 +1,142 @@ +package cz.fi.muni.pv243.rest; + +import cz.fi.muni.pv243.entity.Parser; +import cz.fi.muni.pv243.entity.Restaurant; +import io.restassured.http.ContentType; +import io.restassured.response.Response; +import org.jboss.arquillian.container.test.api.Deployer; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.container.test.api.TargetsContainer; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.logging.Logger; + +import static cz.fi.muni.pv243.rest.Configuration.BASE_URL2; +import static io.restassured.RestAssured.given; +import static org.hamcrest.core.Is.is; + +@RunWith(Arquillian.class) +@RunAsClient +@Ignore // Don't know ho to cleanup server base config after test, removing configuration like in @BeforeClass doesn't work, but tests are working when running only this class +public class ClusterParserServiceTest { + + private static final Logger log = Logger.getLogger( ClusterParserServiceTest.class.getName() ); + + private static final String BASE_URL = Configuration.BASE_URL; + + private Parser parser; + private static boolean initialized = false; + + @ArquillianResource + private Deployer deployer; + + @Deployment + public static WebArchive createDeployment() { + return Configuration.deployment(); + } + + @Deployment(name = "d2", managed = false) + @TargetsContainer("node-2") + public static WebArchive createDeployment2() { + return Configuration.deployment(); + } +// +// @BeforeClass +// public static void removeContainerConfig() throws IOException { +// FileUtils.deleteDirectory(new File(System.getProperty("jboss.home") + "/standalone-ha-node-1/configuration")); +// FileUtils.deleteDirectory(new File(System.getProperty("jboss.home") + "/standalone-ha-node-2/configuration")); +// } + + @Before + public void init(){ + if (!initialized) { //workaround, beforeClass have to be static, but store is injected + parser = new Parser(); + parser.setXpath("/a/b/c"); + Restaurant restaurant = new Restaurant(); + restaurant.setGooglePlaceID("testGOOGLEid"); + restaurant.setName("uPstrosa"); + restaurant.addParser(parser); + parser.setRestaurant(restaurant); + //store.addParser(parser); + initialized = true; + deployer.deploy("d2"); + } + } + + @Test + @Ignore + public void testCluster(){ + Response response = given() + .when() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .body(parser) + .post(BASE_URL + "/parsers"); + log.info(new Object(){}.getClass().getEnclosingMethod().getName() + "\n" + + response.body().prettyPrint()); + + response = given() + .when() + .get(BASE_URL + "/parsers"); + log.info(new Object(){}.getClass().getEnclosingMethod().getName() + "\n" + + response.body().prettyPrint()); + + response.then() + .statusCode(200) + .body("find{it.id==1}.xpath", is(parser.getXpath())); + + response = given() + .when() + .get(BASE_URL2 + "/parsers"); + System.out.println("SECOND CALL ___------------------------"); + log.info(new Object(){}.getClass().getEnclosingMethod().getName() + "\n" + + response.body().prettyPrint()); + + response.then() + .statusCode(200) + .body("find{it.id==1}.xpath", is(parser.getXpath())); + } + +// @Test +// public void testPost() throws IOException { +// { +// Parser newParser = new Parser(); +// newParser.setXpath("x/y/z"); +// Restaurant restaurant = new Restaurant(); +// restaurant.setGooglePlaceID("testGOOGLEid"); +// restaurant.setName("uPstrosa"); +// restaurant.addParser(newParser); +// newParser.setRestaurant(restaurant); +// +// Response response = given() +// .when() +// .accept(ContentType.JSON) +// .contentType(ContentType.JSON) +// .body(newParser) +// .post(BASE_URL + "/parsers"); +// log.info(new Object() { +// }.getClass().getEnclosingMethod().getName() + "\n" + +// response.body().prettyPrint()); +// +// response.then() +// .statusCode(200) +// .body("xpath", is(newParser.getXpath())); +// assertThat(store.getAllParsers(false)) +// .hasSize(2); +// } +// +// Response response = given() +// .when() +// .accept(ContentType.JSON) +// .contentType(ContentType.JSON) +// .post(BASE_URL + "/parsers"); +// +// } +} diff --git a/rest/src/test/java/cz.fi.muni.pv243.rest/Configuration.java b/rest/src/test/java/cz.fi.muni.pv243.rest/Configuration.java index 40d3d26..bbc7c81 100644 --- a/rest/src/test/java/cz.fi.muni.pv243.rest/Configuration.java +++ b/rest/src/test/java/cz.fi.muni.pv243.rest/Configuration.java @@ -17,6 +17,7 @@ public class Configuration { : 8080 + Integer.valueOf(System.getProperty("port.offset")); public final static String BASE_URL = "http://localhost:" + PORT + "/" + Configuration.WAR_NAME + "/rest"; + public final static String BASE_URL2 = "http://localhost:" + Integer.toString(8080 + 200) + "/" + Configuration.WAR_NAME + "/rest"; public static final String WAR_NAME = "test-rest"; diff --git a/rest/src/test/java/cz.fi.muni.pv243.rest/ParserServiceTest.java b/rest/src/test/java/cz.fi.muni.pv243.rest/ParserServiceTest.java index 498eebe..2eb55cb 100644 --- a/rest/src/test/java/cz.fi.muni.pv243.rest/ParserServiceTest.java +++ b/rest/src/test/java/cz.fi.muni.pv243.rest/ParserServiceTest.java @@ -6,16 +6,17 @@ import cz.fi.muni.pv243.store.ParserStore; import io.restassured.http.ContentType; import io.restassured.response.Response; +import org.apache.commons.io.FileUtils; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.transaction.api.annotation.TransactionMode; -import org.jboss.arquillian.transaction.api.annotation.Transactional; import org.jboss.shrinkwrap.api.spec.WebArchive; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import javax.inject.Inject; +import java.io.File; import java.io.IOException; import java.util.logging.Logger; @@ -35,7 +36,7 @@ public class ParserServiceTest { @Inject @CachedStore - ParserStore store; + private ParserStore store; @Deployment public static WebArchive createDeployment() { diff --git a/rest/src/test/resources/arquillian.xml b/rest/src/test/resources/arquillian.xml index 4f0728f..d1afe52 100644 --- a/rest/src/test/resources/arquillian.xml +++ b/rest/src/test/resources/arquillian.xml @@ -3,26 +3,58 @@ xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> - - - - true - ${jboss.home} - standalone-full.xml - true - - - - -Djboss.socket.binding.port-offset=${port.offset} - - 10090 - - - - -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:5005 - -Dport.offset=${port.offset} - - - + + + + + + true + ${jboss.home} + standalone-full-ha.xml + org.jboss.as.arquillian.container.managed.ManagedDeployableContainer + true + false + ${jboss.home}/standalone-ha-node-1 + + + + -Djboss.socket.binding.port-offset=${port.offset} + + 10090 + + + + -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:5006 + -Dport.offset=${port.offset} + -Djava.net.preferIPv4Stack=true + + + + + + + true + ${jboss.home} + standalone-full-ha.xml + org.jboss.as.arquillian.container.managed.ManagedDeployableContainer + true + false + ${jboss.home}/standalone-ha-node-2 + + + + -Djboss.socket.binding.port-offset=200 + + 10190 + + + + -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=localhost:5007 + -Dport.offset=200 + -Djava.net.preferIPv4Stack=true + + + + \ No newline at end of file diff --git a/rest/src/test/resources/standalone-full-ha.xml b/rest/src/test/resources/standalone-full-ha.xml new file mode 100644 index 0000000..f73eccf --- /dev/null +++ b/rest/src/test/resources/standalone-full-ha.xml @@ -0,0 +1,628 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jdbc:h2:/tmp/ParserManager;AUTO_SERVER=TRUE + h2 + + sa + sa + + + + + org.h2.jdbcx.JdbcDataSource + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${jboss.bind.address:127.0.0.1} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/service/src/main/java/cz/fi/muni/pv243/service/ParserServiceImpl.java b/service/src/main/java/cz/fi/muni/pv243/service/ParserServiceImpl.java index 59f511f..c913b5d 100644 --- a/service/src/main/java/cz/fi/muni/pv243/service/ParserServiceImpl.java +++ b/service/src/main/java/cz/fi/muni/pv243/service/ParserServiceImpl.java @@ -5,7 +5,6 @@ */ package cz.fi.muni.pv243.service; -import com.sun.org.apache.regexp.internal.RE; import cz.fi.muni.pv243.entity.Day; import cz.fi.muni.pv243.entity.Parser; import cz.fi.muni.pv243.entity.Restaurant; @@ -44,7 +43,7 @@ public class ParserServiceImpl implements ParserService { @Inject @RequestScoped - private QueueSenderSessionBean senderSessionBean; + private TopicSenderSessionBean senderSessionBean; @Override public void confirm(long parserId) { diff --git a/service/src/main/java/cz/fi/muni/pv243/service/QueueSenderSessionBean.java b/service/src/main/java/cz/fi/muni/pv243/service/TopicSenderSessionBean.java similarity index 63% rename from service/src/main/java/cz/fi/muni/pv243/service/QueueSenderSessionBean.java rename to service/src/main/java/cz/fi/muni/pv243/service/TopicSenderSessionBean.java index 4b4a90a..6394cad 100644 --- a/service/src/main/java/cz/fi/muni/pv243/service/QueueSenderSessionBean.java +++ b/service/src/main/java/cz/fi/muni/pv243/service/TopicSenderSessionBean.java @@ -12,7 +12,7 @@ import javax.inject.Named; import javax.jms.JMSContext; import javax.jms.JMSException; -import javax.jms.Queue; +import javax.jms.Topic; import cz.fi.muni.pv243.service.logging.ParserManagerLogger; @@ -25,19 +25,19 @@ @Named @LocalBean @Stateless -public class QueueSenderSessionBean { +public class TopicSenderSessionBean { - @Resource(mappedName="java:jboss/exported/jms/queue/ChangedParsersQueue") - private Queue myQueue; + @Resource(mappedName="java:jboss/exported/jms/topic/ChangedParsersTopic") + private Topic myTopic; @Inject private JMSContext jmsContext; public void sendMessage(Serializable message) { - jmsContext.createProducer().send(myQueue, message/*jmsContext.createMessage()*/); try { - ParserManagerLogger.LOGGER.logMessageQueued(myQueue.getQueueName(), message.toString()); + jmsContext.createProducer().send(myTopic, message/*jmsContext.createMessage()*/); + ParserManagerLogger.LOGGER.logMessageTopiced(myTopic.getTopicName(), message.toString()); } catch (JMSException e) { - ParserManagerLogger.LOGGER.logMessageQueueError(e); + ParserManagerLogger.LOGGER.logMessageTopicError(e); } } } diff --git a/service/src/main/java/cz/fi/muni/pv243/service/logging/ParserManagerLogger.java b/service/src/main/java/cz/fi/muni/pv243/service/logging/ParserManagerLogger.java index c681014..0174030 100644 --- a/service/src/main/java/cz/fi/muni/pv243/service/logging/ParserManagerLogger.java +++ b/service/src/main/java/cz/fi/muni/pv243/service/logging/ParserManagerLogger.java @@ -56,10 +56,10 @@ public interface ParserManagerLogger extends BasicLogger { void logBatchJobAbandon(String jobName, long jobId, String status); @LogMessage(level = Logger.Level.INFO) - @Message(id = BASE + 140, value = "Message: {0} in queue: {1}.", format = Message.Format.MESSAGE_FORMAT) - void logMessageQueued(String queue, String msg); + @Message(id = BASE + 140, value = "Message: {0} in topic: {1}.", format = Message.Format.MESSAGE_FORMAT) + void logMessageTopiced(String topic, String msg); @LogMessage(level = Logger.Level.WARN) - @Message(id = BASE + 145, value = "JMS queue encountered error: {0}", format = Message.Format.MESSAGE_FORMAT) - void logMessageQueueError(Throwable error); + @Message(id = BASE + 145, value = "JMS topic encountered error: {0}", format = Message.Format.MESSAGE_FORMAT) + void logMessageTopicError(Throwable error); }