Skip to content
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

SWITCHYARD-2550 Update README for demos/cluster,transaction-propagation #429

Closed
wants to merge 1 commit into from
Closed
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
148 changes: 145 additions & 3 deletions demos/cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The purpose of the quickstart is to demonstrate how the credit service can be cl

You will need three SY instances and four terminal windows to run the clustering demo.

EAP
----------
*1. Create three discrete instances of the SY runtime.*

This can be done by simply making copies of the standalone directory for each instance, e.g.
Expand All @@ -21,20 +23,21 @@ This can be done by simply making copies of the standalone directory for each in
cp -R standalone node2
cp -R standalone node3
```
Replace ${EAP_HOME} with the actual path.

*2. Start each instance in a separate terminal window.*

_Window 1_

bin/standalone.sh -Djboss.node.name=node1 --server-config=standalone-ha.xml
bin/standalone.sh -Djboss.node.name=node1 -Djboss.server.base.dir=${EAP_HOME}/node1 --server-config=standalone-ha.xml

_Window 2_

bin/standalone.sh -Djboss.node.name=node2 -Djboss.socket.binding.port-offset=1000 --server-config=standalone-ha.xml
bin/standalone.sh -Djboss.node.name=node2 -Djboss.server.base.dir=${EAP_HOME}/node2 -Djboss.socket.binding.port-offset=1000 --server-config=standalone-ha.xml

_Window 3_

bin/standalone.sh -Djboss.node.name=node3 -Djboss.socket.binding.port-offset=2000 --server-config=standalone-ha.xml
bin/standalone.sh -Djboss.node.name=node3 -Djboss.server.base.dir=${EAP_HOME}/node3 -Djboss.socket.binding.port-offset=2000 --server-config=standalone-ha.xml

*3. In a separate terminal window deploy the dealer and credit applications.*

Expand Down Expand Up @@ -64,6 +67,145 @@ the Credit Service is deployed. Check the console output on node2 and node3 to
mvn -Pdeploy clean


Wildfly
----------
*1. Create three discrete instances of the SY runtime.*

This can be done by simply making copies of the standalone directory for each instance, e.g.
```
cd ${WILDFLY_HOME}
cp -R standalone node1
cp -R standalone node2
cp -R standalone node3
```
Replace ${WILDFLY_HOME} with the actual path.

*2. Start each instance in a separate terminal window.*

_Window 1_

bin/standalone.sh -Djboss.node.name=node1 -Djboss.server.base.dir=${WILDFLY_HOME}/node1 --server-config=standalone-ha.xml

_Window 2_

bin/standalone.sh -Djboss.node.name=node2 -Djboss.server.base.dir=${WILDFLY_HOME}/node2 -Djboss.socket.binding.port-offset=1000 --server-config=standalone-ha.xml

_Window 3_

bin/standalone.sh -Djboss.node.name=node3 -Djboss.server.base.dir=${WILDFLY_HOME}/node3 -Djboss.socket.binding.port-offset=2000 --server-config=standalone-ha.xml

*3. In a separate terminal window deploy the dealer and credit applications.*

Build and deploy the quickstart

mvn -Pdeploy,wildfly install

*4. Run the test client and check output.*

Submit a message using the client project:

mvn exec:java

You should see the following output in the client terminal:

==================================
Was the offer accepted? true
==================================

If you submit multiple messages, you'll notice that the requests are split between the two instances where
the Credit Service is deployed. Check the log on node2 and node3 to see where messages are being routed:

Credit Service : Approving credit for John Smith

*5. Undpeloy the quickstart

mvn -Pdeploy,wildfly clean


Karaf
----------
*1. Start the Karaf server*

${KARAF_HOME}/bin/karaf

*2. Create three karaf subinstances.*

karaf@root> admin:create node3
karaf@root> admin:create node2
karaf@root> admin:create node1

*3. Change HTTP port for each subinstances.*
Create following 2 files:

${KARAF_HOME}/instances/node2/etc/org.ops4j.pax.web.cfg:
```
org.osgi.service.http.port=9181
```

${KARAF_HOME}/instances/node3/etc/org.ops4j.pax.web.cfg:
```
org.osgi.service.http.port=10181
```

If your machine is multihomed, default JGoups setting may not work for you. In that case, uncomment "jgroups-config" property in the ${KARAF_HOME}/instances/node{1,2,3}/etc/org.switchyard.component.sca.cfg and create your own JGroups setting file. Usually just adding "bind_addr" attribute to the default jgroups-udp.xml is enough. The default jgroups-udp.xml is in infinispan-core-${version}.jar.

*4. Start karaf subinstances.*

karaf@root> admin:start node1
karaf@root> admin:start node2
karaf@root> admin:start node3

*5. Install Credit application on node2 and node3. *
Replace {SWITCHYARD-VERSION} with the version of SwitchYard that you are using (ex. 2.0.0)

karaf@root> admin:connect node3
karaf@node3> features:addurl mvn:org.switchyard.karaf/switchyard/{SWITCHYARD-VERSION}/xml/features
karaf@node3> features:install switchyard-demo-cluster-credit
karaf@node3> logout
karaf@root> admin:connect node2
karaf@node2> features:addurl mvn:org.switchyard.karaf/switchyard/{SWITCHYARD-VERSION}/xml/features
karaf@node2> features:install switchyard-demo-cluster-credit
karaf@node2> logout
karaf@root>

*6. Install Dealer application on node1.*

karaf@root> admin:connect node2
karaf@node1> features:addurl mvn:org.switchyard.karaf/switchyard/{SWITCHYARD-VERSION}/xml/features
karaf@node1> features:install switchyard-demo-cluster-dealer
karaf@node1> logout
karaf@root>

*7. Run the test client and check output.*

Submit a message using the client project:

mvn -Pkaraf exec:java

You should see the following output in the client terminal:

==================================
Was the offer accepted? true
==================================

If you submit multiple messages, you'll notice that the requests are split between the two instances where
the Credit Service is deployed. Check the log on node2 and node3 to see where messages are being routed:

Credit Service : Approving credit for John Smith

*8. Uninstall the applications.*

karaf@root> admin:connect node1
karaf@node1> features:uninstall switchyard-demo-cluster-dealer
karaf@node1> logout
karaf@root> admin:connect node2
karaf@node2> features:uninstall switchyard-demo-cluster-credit
karaf@node2> logout
karaf@root> admin:connect node3
karaf@node3> features:uninstall switchyard-demo-cluster-credit
karaf@node3> logout
karaf@root>

## Further Reading

1. [SwitchYard Clustering](https://docs.jboss.org/author/display/SWITCHYARD/Clustering)
21 changes: 21 additions & 0 deletions demos/cluster/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,25 @@
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>karaf</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<systemProperties>
<systemProperty>
<key>org.switchyard.component.sca.client.port</key>
<value>8181</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public final class RemoteClient {
private static final QName SERVICE = new QName(
"urn:switchyard-quickstart-demo-cluster-dealer:1.0",
"Dealer");
private static final String URL = "http://localhost:8080/switchyard-remote";

/**
* Private no-args constructor.
Expand All @@ -46,7 +45,8 @@ private RemoteClient() {
*/
public static void main(final String[] ignored) throws Exception {
// Create a new remote client invoker
RemoteInvoker invoker = new HttpInvoker(URL);
String port = System.getProperty("org.switchyard.component.sca.client.port", "8080");
RemoteInvoker invoker = new HttpInvoker("http://localhost:" + port + "/switchyard-remote");

// Create request payload
Offer offer = createOffer(true);
Expand All @@ -60,6 +60,9 @@ public static void main(final String[] ignored) throws Exception {
if (reply.isFault()) {
System.err.println("Oops ... something bad happened. "
+ reply.getContent());
if (reply.getContent() instanceof Throwable) {
Throwable.class.cast(reply.getContent()).printStackTrace();
}
} else {
Deal deal = (Deal) reply.getContent();
out.println("==================================");
Expand Down
23 changes: 15 additions & 8 deletions demos/cluster/credit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<!-- Bundle symbolic name may not contain dashes -->
<bundle.symbolic.name>${project.groupId}.switchyard.demo.cluster.credit</bundle.symbolic.name>
<deploy.skip>true</deploy.skip>
<wildfly.protocol>remote</wildfly.protocol>
<wildfly.port.node2>10999</wildfly.port.node2>
<wildfly.port.node3>11999</wildfly.port.node3>
<switchyard.osgi.import>*</switchyard.osgi.import>
<switchyard.osgi.require.capability>
org.ops4j.pax.cdi.extension; filter:="(extension=deltaspike-core-api)",
Expand Down Expand Up @@ -131,8 +134,7 @@
<goal>deploy-only</goal>
</goals>
<configuration>
<port>10999</port>
<protocol>remote</protocol>
<port>${wildfly.port.node2}</port>
<filename>${project.build.finalName}.jar</filename>
<skip>${deploy.skip}</skip>
</configuration>
Expand All @@ -144,8 +146,7 @@
<goal>deploy-only</goal>
</goals>
<configuration>
<port>11999</port>
<protocol>remote</protocol>
<port>${wildfly.port.node3}</port>
<filename>${project.build.finalName}.jar</filename>
<skip>${deploy.skip}</skip>
</configuration>
Expand All @@ -157,8 +158,7 @@
<goal>undeploy</goal>
</goals>
<configuration>
<port>10999</port>
<protocol>remote</protocol>
<port>${wildfly.port.node2}</port>
<filename>${project.build.finalName}.jar</filename>
<skip>${deploy.skip}</skip>
</configuration>
Expand All @@ -170,8 +170,7 @@
<goal>undeploy</goal>
</goals>
<configuration>
<port>11999</port>
<protocol>remote</protocol>
<port>${wildfly.port.node3}</port>
<filename>${project.build.finalName}.jar</filename>
<skip>${deploy.skip}</skip>
</configuration>
Expand All @@ -195,5 +194,13 @@
<deploy.skip>false</deploy.skip>
</properties>
</profile>
<profile>
<id>wildfly</id>
<properties>
<wildfly.protocol>http-remoting</wildfly.protocol>
<wildfly.port.node2>10990</wildfly.port.node2>
<wildfly.port.node3>11990</wildfly.port.node3>
</properties>
</profile>
</profiles>
</project>
4 changes: 2 additions & 2 deletions demos/cluster/credit/src/main/resources/RulesComponent.drl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ rule "ApproveCredit"
when
app : Application(creditScore >= 600)
then
System.out.println("Credit Service : Approving credit for " + app.getName());
org.jboss.logging.Logger.getLogger("Credit Service").info("Credit Service : Approving credit for " + app.getName());
app.setApproved(true);
globals.put("Result", app);
end
Expand All @@ -33,7 +33,7 @@ rule "DenyCredit"
when
app : Application(creditScore < 600)
then
System.out.println("Credit Service : Denying credit for " + app.getName());
org.jboss.logging.Logger.getLogger("Credit Service").info("Credit Service : Denying credit for " + app.getName());
app.setApproved(false);
globals.put("Result", app);
end
2 changes: 2 additions & 0 deletions demos/cluster/dealer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<bundle.symbolic.name>${project.groupId}.switchyard.demo.cluster.dealer</bundle.symbolic.name>
<deploy.skip>true</deploy.skip>
<wildfly.port>9999</wildfly.port>
<wildfly.protocol>remote</wildfly.protocol>
<switchyard.osgi.import>*</switchyard.osgi.import>
<switchyard.osgi.require.capability>
org.ops4j.pax.cdi.extension; filter:="(extension=switchyard-component-bean)",
Expand Down Expand Up @@ -170,6 +171,7 @@
<profile>
<id>wildfly</id>
<properties>
<wildfly.protocol>http-remoting</wildfly.protocol>
<wildfly.port>9990</wildfly.port>
</properties>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@

import javax.inject.Inject;

import org.jboss.logging.Logger;
import org.switchyard.component.bean.Reference;
import org.switchyard.component.bean.Service;

@Service(Dealer.class)
public class DealerBean implements Dealer {

private Logger _log = Logger.getLogger(DealerBean.class);

@Inject
@Reference
private CreditCheck creditService;

@Override
public Deal offer(Offer offer) {
System.out.println("Dealer Service : Received an offer");
_log.info("Dealer Service : Received an offer");
Deal deal = new Deal();
deal.setOffer(offer);

Expand All @@ -40,7 +43,7 @@ public Deal offer(Offer offer) {
return deal;
}

System.out.println("Dealer Service : Checking Credit");
_log.info("Dealer Service : Checking Credit");
// Check credit of applicant
Application creditReply = creditService.checkCredit(offer);
deal.setAccepted(creditReply.isApproved());
Expand Down
Loading