-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
125 changed files
with
11,080 additions
and
652 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,84 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>hadoop-bootstrap</artifactId> | ||
<groupId>fr.jetoile.sample</groupId> | ||
<version>1.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>hadoop-bootstrap-commons</artifactId> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>commons-configuration</groupId> | ||
<artifactId>commons-configuration</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-collections</groupId> | ||
<artifactId>commons-collections</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-io</groupId> | ||
<artifactId>commons-io</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.hadoop</groupId> | ||
<artifactId>hadoop-common</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>httpclient</artifactId> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>servlet-api</artifactId> | ||
<groupId>javax.servlet</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>org.eclipse.jetty</artifactId> | ||
<groupId>jetty-util</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-util</artifactId> | ||
<version>9.2.14.v20151106</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.1.0</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
File renamed without changes.
File renamed without changes.
115 changes: 115 additions & 0 deletions
115
hadoop-bootstrap-commons/src/main/java/fr/jetoile/sample/HadoopBootstrap.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,115 @@ | ||
/* | ||
* Copyright (c) 2011 Khanh Tuong Maudoux <kmx.petals@gmail.com> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. The name of the author may not be used to endorse or promote products | ||
* derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package fr.jetoile.sample; | ||
|
||
import com.google.common.collect.Lists; | ||
import fr.jetoile.sample.component.Bootstrap; | ||
import fr.jetoile.sample.exception.NotFoundServiceException; | ||
import org.apache.commons.configuration.Configuration; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.*; | ||
|
||
public enum HadoopBootstrap { | ||
INSTANCE; | ||
|
||
final private static Logger LOGGER = LoggerFactory.getLogger(HadoopBootstrap.class); | ||
|
||
|
||
private Configuration configuration; | ||
List<Bootstrap> componentsToStart = new ArrayList<>(); | ||
List<Bootstrap> componentsToStop = new ArrayList<>(); | ||
|
||
private ServiceLoader<Bootstrap> commandLoader = ServiceLoader.load(Bootstrap.class); | ||
private Map<String, Bootstrap> commands = new HashMap<>(); | ||
|
||
|
||
HadoopBootstrap() { | ||
commands.clear(); | ||
commandLoader.reload(); | ||
Iterator<Bootstrap> commandsIterator = commandLoader.iterator(); | ||
|
||
while (commandsIterator.hasNext()) { | ||
Bootstrap command = commandsIterator.next(); | ||
commands.put(command.getName(), command); | ||
} | ||
|
||
Arrays.asList(Component.values()).stream().forEach(c -> { | ||
if (commands.containsKey(c.name())) { | ||
componentsToStart.add(commands.get(c.name())); | ||
} | ||
}); | ||
|
||
componentsToStop = Lists.newArrayList(this.componentsToStart); | ||
Collections.reverse(componentsToStop); | ||
|
||
Runtime.getRuntime().addShutdownHook(new Thread() { | ||
public void run() { | ||
LOGGER.info("All services are going to be stopped"); | ||
stopAll(); | ||
} | ||
}); | ||
} | ||
|
||
public Bootstrap getService(Component c) throws NotFoundServiceException { | ||
if (commands.containsKey(c.name())) { | ||
return commands.get(c.name()); | ||
} else { | ||
throw new NotFoundServiceException("unable to find service " + c.name()); | ||
} | ||
|
||
} | ||
|
||
public void startAll() { | ||
componentsToStart.stream().forEach(c -> { | ||
startService(c); | ||
}); | ||
} | ||
|
||
public void stopAll() { | ||
componentsToStop.stream().forEach(c -> { | ||
stopService(c); | ||
}); | ||
} | ||
|
||
public HadoopBootstrap start(Component component) throws NotFoundServiceException { | ||
getService(component).start(); | ||
return this; | ||
} | ||
|
||
public HadoopBootstrap stop(Component component) throws NotFoundServiceException { | ||
getService(component).stop(); | ||
return this; | ||
} | ||
|
||
private void startService(Bootstrap c) { | ||
c.start(); | ||
} | ||
|
||
private void stopService(Bootstrap c) { | ||
c.stop(); | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
|
@@ -33,5 +33,7 @@ public interface Bootstrap { | |
|
||
Configuration getConfiguration(); | ||
|
||
String getName(); | ||
|
||
|
||
} |
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
...bootstrap-commons/src/main/java/fr/jetoile/sample/exception/NotFoundServiceException.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,11 @@ | ||
package fr.jetoile.sample.exception; | ||
|
||
/** | ||
* User: khanh | ||
* To change this template use File | Settings | File Templates. | ||
*/ | ||
public class NotFoundServiceException extends Exception { | ||
public NotFoundServiceException(String message) { | ||
super(message); | ||
} | ||
} |
File renamed without changes.
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,44 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>hadoop-bootstrap</artifactId> | ||
<groupId>fr.jetoile.sample</groupId> | ||
<version>1.1-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>hadoop-bootstrap-hbase</artifactId> | ||
|
||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>fr.jetoile.sample</groupId> | ||
<artifactId>hadoop-bootstrap-commons</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>fr.jetoile.sample</groupId> | ||
<artifactId>hadoop-bootstrap-zookeeper</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>fr.jetoile.sample</groupId> | ||
<artifactId>hadoop-bootstrap-hdfs</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.sakserv</groupId> | ||
<artifactId>hadoop-mini-clusters-hbase</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>servlet-api-2.5</artifactId> | ||
<groupId>org.mortbay.jetty</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
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
1 change: 1 addition & 0 deletions
1
...ootstrap-hbase/src/main/resources/META-INF/services/fr.jetoile.sample.component.Bootstrap
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 @@ | ||
fr.jetoile.sample.component.HBaseBootstrap |
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
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
Oops, something went wrong.