Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Add ribbon-webapp and hack out the beginning of an example UI
Browse files Browse the repository at this point in the history
  • Loading branch information
lance committed Nov 25, 2015
1 parent 7bed774 commit 186fbe3
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 10 deletions.
Expand Up @@ -23,10 +23,10 @@ public static void main(String[] args) throws Exception {
p.property("bind_port", "9090");
}));
s.protocol("TCPPING", (p)-> {
p.property("initial_hosts", "localhost[9090],localhost[9091],localhost[9092]")
.property("port_range", "3")
p.property("initial_hosts", "localhost[9090],localhost[9091],localhost[9092],localhost[9093]")
.property("port_range", "4")
.property("timeout", "3000")
.property("num_initial_members", "3");
.property("num_initial_members", "4");
});
s.protocol( "FD_SOCK", (p)->{
p.socketBinding( "jgroups-udp-fd" );
Expand All @@ -45,13 +45,12 @@ public static void main(String[] args) throws Exception {
.channel( "swarm-jgroups", (c)->{
c.stack( "udp" );
});
;
container.fraction(fraction);

JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
deployment.addPackage( Main.class.getPackage() );
deployment.addAllDependencies();
//deployment.as( RibbonArchive.class );
deployment.as( RibbonArchive.class ).setApplicationName( "events" );
container.start().deploy(deployment);
}
}
Expand Up @@ -16,7 +16,7 @@
@ResourceGroup( name="time" )
public interface TimeService {

static TimeService INSTANCE = Ribbon.from(TimeService.class);
TimeService INSTANCE = Ribbon.from(TimeService.class);

@TemplateName("currentTime")
@Http(
Expand Down
61 changes: 61 additions & 0 deletions ribbon/frontend/pom.xml
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2015 Red Hat, Inc. and/or its affiliates.
~
~ Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>org.wildfly.swarm.examples</groupId>
<artifactId>wildfly-swarm-examples-ribbon-parent</artifactId>
<version>1.0.0.Alpha6-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<artifactId>wildfly-swarm-example-ribbon-frontend</artifactId>

<name>WildFly Swarm Examples: Netflix Ribbon - Front End</name>
<description>WildFly Swarm Examples: Netflix Ribbon - Front End</description>

<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<configuration>
<mainClass>org.wildfly.swarm.examples.netflix.ribbon.frontend.Main</mainClass>
<properties>
<jboss.bind.address>127.0.0.1</jboss.bind.address>
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
</properties>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-undertow</artifactId>
<version>${version.wildfly-swarm}</version>
</dependency>
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-ribbon-webapp</artifactId>
<version>${version.wildfly-swarm}</version>
</dependency>
</dependencies>

</project>
@@ -0,0 +1,53 @@
package org.wildfly.swarm.examples.netflix.ribbon.frontend;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.wildfly.swarm.container.Container;
import org.wildfly.swarm.jgroups.JGroupsFraction;
import org.wildfly.swarm.undertow.WARArchive;

/**
* @author Lance Ball
*/
public class Main {
public static void main(String... args) throws Exception {
Container container = new Container();
JGroupsFraction fraction = new JGroupsFraction()
.defaultChannel( "swarm-jgroups")
.stack( "udp", (s)->{
s.transport( "UDP", (t)->{
t.socketBinding("jgroups-udp");
});
s.protocol("TCP", (p -> {
p.property("bind_port", "9090");
}));
s.protocol("TCPPING", (p)-> {
p.property("initial_hosts", "localhost[9090],localhost[9091],localhost[9092],localhost[9093]")
.property("port_range", "4")
.property("timeout", "3000")
.property("num_initial_members", "4");
});
s.protocol( "FD_SOCK", (p)->{
p.socketBinding( "jgroups-udp-fd" );
});
s.protocol( "FD_ALL" );
s.protocol( "VERIFY_SUSPECT" );
s.protocol( "pbcast.NAKACK2" );
s.protocol( "UNICAST3" );
s.protocol( "pbcast.STABLE" );
s.protocol( "pbcast.GMS" );
s.protocol( "UFC" );
s.protocol( "MFC" );
s.protocol( "FRAG2" );
s.protocol( "RSVP" );
})
.channel( "swarm-jgroups", (c)->{
c.stack( "udp" );
});
container.fraction(fraction);
container.start();
WARArchive war = ShrinkWrap.create(WARArchive.class);
war.staticContent();
war.addAllDependencies();
container.deploy(war);
}
}
@@ -0,0 +1 @@
not path-prefix('/ribbon/') and not path-prefix('/css/') and not path-prefix('/js/') and not path-prefix('/images') and regex('/.*') -> rewrite('/index.html')
16 changes: 16 additions & 0 deletions ribbon/frontend/src/main/resources/css/app.css
@@ -0,0 +1,16 @@
body {
font-family: sans-serif;
margin: 1em;
}

.service {
}

.service h2 {
border-bottom: 1px dotted;
margin: 1ex;
}

.service .service-address {
margin: 1ex 2ex;
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions ribbon/frontend/src/main/resources/index.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WildFly Swarm Ribbon Example</title>
<link rel="stylesheet" href="/css/app.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="/ribbon/ribbon.js"></script>
</head>

<body>
<div id="app"></div>
<script type="text/babel" src="/js/app.js"></script>
</body>
</html>
72 changes: 72 additions & 0 deletions ribbon/frontend/src/main/resources/js/app.js
@@ -0,0 +1,72 @@
var Ribbon = ribbon();

var App = React.createClass({
render: function() {
return (
<div>
<h1>WildFly Swarm Ribbon Example</h1>
<Topology />
</div>
);
}
});

var Topology = React.createClass({
getInitialState: function() {
return {data: []};
},

componentDidMount: function() {
var component = this;
Ribbon.topologyEvents.addEventListener('topologyChange', function(message) {
component.setState({data: JSON.parse(message.data)});
});
},

render: function() {
var services = [];
for (var service in this.state.data) {
var addresses = this.state.data[service];
services.push(
(
<Service service={service} addresses={addresses} key={service} />
)
);
}
return (
<div id='topology'>
<h2>Service Topology</h2>
{services}
</div>
);
}
});

var Service = React.createClass({
render: function() {
var addresses = this.props.addresses.map(function(address) {
return (
<Address address={address} key={address}/>
);
});
return (
<div className='service'>
<h2>{this.props.service}</h2>
{addresses}
</div>
);
}
});

var Address = React.createClass({
render: function() {
return (
<p className='service-address'>{this.props.address}</p>
);
}
});

ReactDOM.render(
<App />,
document.getElementById('app')
);
1 change: 1 addition & 0 deletions ribbon/pom.xml
Expand Up @@ -31,5 +31,6 @@
<modules>
<module>time</module>
<module>events</module>
<module>frontend</module>
</modules>
</project>
Expand Up @@ -23,10 +23,10 @@ public static void main(String[] args) throws Exception {
p.property("bind_port", "9090");
}));
s.protocol("TCPPING", (p)-> {
p.property("initial_hosts", "localhost[9090],localhost[9091],localhost[9092]")
.property("port_range", "3")
p.property("initial_hosts", "localhost[9090],localhost[9091],localhost[9092],localhost[9093]")
.property("port_range", "4")
.property("timeout", "3000")
.property("num_initial_members", "3");
.property("num_initial_members", "4");
});
s.protocol( "FD_SOCK", (p)->{
p.socketBinding( "jgroups-udp-fd" );
Expand All @@ -45,7 +45,6 @@ public static void main(String[] args) throws Exception {
.channel( "swarm-jgroups", (c)->{
c.stack( "udp" );
});
;
container.fraction(fraction);
JAXRSArchive deployment = ShrinkWrap.create( JAXRSArchive.class );
deployment.addResource(TimeResource.class);
Expand Down

0 comments on commit 186fbe3

Please sign in to comment.