forked from apache/helix
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a Maven archetype to create OnlineOffline application
- Loading branch information
Showing
13 changed files
with
708 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
*.ipr | ||
*.iws | ||
|
||
target | ||
|
||
dependency-reduced-pom.xml | ||
|
||
.idea |
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,95 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you 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. | ||
--> | ||
|
||
helix-archetype | ||
=============== | ||
|
||
A maven archetype that sets up a sample [Apache Helix](http://helix.apache.org/) project. | ||
|
||
Generate | ||
-------- | ||
|
||
First, clone this repository and install the archetype | ||
|
||
``` | ||
git clone git@github.com:brandtg/helix-archetype.git | ||
cd helix-archetype | ||
mvn install | ||
``` | ||
|
||
Then generate your application | ||
|
||
``` | ||
mvn archetype:generate \ | ||
-DarchetypeGroupId=org.apache.helix \ | ||
-DarchetypeArtifactId=helix-archetype \ | ||
-DarchetypeVersion=1.0-SNAPSHOT \ | ||
-DgroupId=com.example \ | ||
-DartifactId=my-app \ | ||
-Dname=MyApp \ | ||
-DinteractiveMode=false | ||
``` | ||
|
||
This creates a simple OnlineOffline application, though it should be straightforward to change the state model by referencing the Helix documentation. | ||
|
||
The `pom.xml` creates a single versioned artifact, which can run all of your cluster's roles via the `${name}Main` entry point. | ||
|
||
This makes it a little nicer to manage multiple different cluster roles: just build this artifact, and deploy it everywhere with different CLI args. | ||
|
||
Example | ||
------- | ||
|
||
To get started, build the artifact after generating your application: | ||
|
||
``` | ||
cd my-app | ||
mvn install | ||
``` | ||
|
||
Run a ZooKeeper | ||
|
||
``` | ||
java -jar target/my-app-1.0-SNAPSHOT.jar zookeeper 2191 /tmp/zk | ||
``` | ||
|
||
Set up a cluster, then add a node and a resource with 4 partitions | ||
|
||
``` | ||
java -jar target/my-app-1.0-SNAPSHOT.jar setup --zkSvr localhost:2191 --addCluster TEST_CLUSTER | ||
java -jar target/my-app-1.0-SNAPSHOT.jar setup --zkSvr localhost:2191 --addNode TEST_CLUSTER node0 | ||
java -jar target/my-app-1.0-SNAPSHOT.jar setup --zkSvr localhost:2191 --addResource TEST_CLUSTER test 4 OnlineOffline | ||
``` | ||
|
||
Run a controller | ||
|
||
``` | ||
java -jar target/my-app-1.0-SNAPSHOT.jar controller --zkSvr localhost:2191 --cluster TEST_CLUSTER | ||
``` | ||
|
||
Run a participant (note: does nothing) | ||
|
||
``` | ||
java -jar target/my-app-1.0-SNAPSHOT.jar participant localhost:2181 TEST_CLUSTER node0 | ||
``` | ||
|
||
Rebalance the resource (should work...) | ||
|
||
``` | ||
java -jar target/my-app-1.0-SNAPSHOT.jar setup --zkSvr localhost:2191 --rebalance TEST_CLUSTER test 1 | ||
``` |
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,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you 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. | ||
--> | ||
<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"> | ||
<parent> | ||
<groupId>org.apache.helix</groupId> | ||
<artifactId>helix</artifactId> | ||
<version>0.7.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>helix-archetype</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>Apache Helix :: Archetype</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<resources> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>true</filtering> | ||
<includes> | ||
<include>archetype-resources/pom.xml</include> | ||
</includes> | ||
</resource> | ||
<resource> | ||
<directory>src/main/resources</directory> | ||
<filtering>false</filtering> | ||
<excludes> | ||
<exclude>archetype-resources/pom.xml</exclude> | ||
</excludes> | ||
</resource> | ||
</resources> | ||
|
||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>2.5</version> | ||
<configuration> | ||
<escapeString>\</escapeString> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
42 changes: 42 additions & 0 deletions
42
helix-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
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,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you 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. | ||
--> | ||
<archetype-descriptor xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" | ||
name="helix-archetype"> | ||
<requiredProperties> | ||
<requiredProperty key="name"/> | ||
</requiredProperties> | ||
|
||
<fileSets> | ||
<fileSet filtered="true"> | ||
<directory>src/main/java</directory> | ||
<includes> | ||
<include>**/*</include> | ||
</includes> | ||
</fileSet> | ||
|
||
<fileSet filtered="true"> | ||
<directory>src/main/resources</directory> | ||
<includes> | ||
<include>**/*</include> | ||
</includes> | ||
</fileSet> | ||
</fileSets> | ||
</archetype-descriptor> |
93 changes: 93 additions & 0 deletions
93
helix-archetype/src/main/resources/archetype-resources/pom.xml
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,93 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you 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. | ||
--> | ||
<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> | ||
|
||
<groupId>\${groupId}</groupId> | ||
<artifactId>\${artifactId}</artifactId> | ||
<version>\${version}</version> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.helix</groupId> | ||
<artifactId>helix-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.12</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<version>1.7.12</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>2.4</version> | ||
<configuration> | ||
<forceCreation>true</forceCreation> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>2.3</version> | ||
<configuration> | ||
<createDependencyReducedPom>true</createDependencyReducedPom> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> | ||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>\${package}.\${name}Main</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
66 changes: 66 additions & 0 deletions
66
helix-archetype/src/main/resources/archetype-resources/src/main/java/__name__Main.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,66 @@ | ||
package ${package}; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
import ${package}.participant.${name}Participant; | ||
import org.apache.helix.controller.HelixControllerMain; | ||
import org.apache.helix.tools.ClusterSetup; | ||
import org.apache.zookeeper.server.ZooKeeperServerMain; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* An executable to start the various cluster roles. | ||
*/ | ||
public class ${name}Main { | ||
private enum Mode { | ||
PARTICIPANT, | ||
CONTROLLER, | ||
ZOOKEEPER, | ||
SETUP | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
if (args.length == 0) { | ||
System.err.println("usage: <mode> args..."); | ||
System.exit(1); | ||
} | ||
|
||
Mode mode = Mode.valueOf(args[0].toUpperCase()); | ||
String[] subArgs = Arrays.copyOfRange(args, 1, args.length); | ||
|
||
switch (mode) { | ||
case PARTICIPANT: | ||
${name}Participant.main(subArgs); | ||
break; | ||
case CONTROLLER: | ||
HelixControllerMain.main(subArgs); | ||
break; | ||
case ZOOKEEPER: | ||
ZooKeeperServerMain.main(subArgs); | ||
break; | ||
case SETUP: | ||
ClusterSetup.main(subArgs); | ||
break; | ||
default: | ||
throw new IllegalStateException("Unsupported mode " + mode); | ||
} | ||
} | ||
} |
Oops, something went wrong.