Skip to content

Commit

Permalink
IGNITE-2435 Fixed "Integration with Mesos doesn't work with limited a…
Browse files Browse the repository at this point in the history
…ccess to internet".
  • Loading branch information
niktikhonov committed May 16, 2016
1 parent cc58a63 commit f65dd00
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 185 deletions.
43 changes: 42 additions & 1 deletion modules/mesos/pom.xml
Expand Up @@ -20,7 +20,8 @@
<!--
POM file.
-->
<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">
<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>

<parent>
Expand All @@ -36,6 +37,8 @@

<properties>
<mesos.version>0.22.0</mesos.version>
<ignite.latest.url>http://ignite.run/download_ignite.php</ignite.latest.url>
<ignite.direct.url>https://archive.apache.org/dist/ignite/%s/apache-ignite-fabric-%s-bin.zip</ignite.direct.url>
</properties>

<dependencies>
Expand Down Expand Up @@ -72,6 +75,44 @@
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>update-versions</id>
<goals>
<goal>run</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<target>
<echo message="Update download url in mesos module." />
<echo message="Direct link ${ignite.direct.url}." />
<echo message="Latest link ${ignite.latest.url}." />

<replaceregexp byline="true" encoding="UTF-8">
<regexp pattern="(.*DOWNLOAD_LINK = &quot;)(.*)(&quot;.*)" />
<substitution expression="\1${ignite.latest.url}\3"/>
<fileset dir="${basedir}/">
<include name="**/IgniteProvider.java" />
</fileset>
</replaceregexp>

<replaceregexp byline="true" encoding="UTF-8">
<regexp pattern="(.*DOWNLOAD_URL_PATTERN = &quot;)(.*)(&quot;.*)" />
<substitution expression="\1${ignite.direct.url}\3"/>
<fileset dir="${basedir}/">
<include name="**/IgniteProvider.java" />
</fileset>
</replaceregexp>
</target>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
Expand Down
Expand Up @@ -31,7 +31,11 @@
import java.util.regex.PatternSyntaxException;

/**
* Cluster settings.
* The class defines cluster configuration. This configuration created from properties file
* that passed on startup or environment variables.
* <p>
* If Mesos cluster working in Intranet or behind NAT then an access to local resources can be set
* by {@link #ignitePackagePath()} or {@link #ignitePackageUrl()} which should be available from nodes.
*/
public class ClusterProperties {
/** */
Expand Down Expand Up @@ -68,7 +72,7 @@ public class ClusterProperties {
public static final String IGNITE_HTTP_SERVER_HOST = "IGNITE_HTTP_SERVER_HOST";

/** Http server host. */
private String httpServerHost = null;
private String httpSrvHost = null;

/** */
public static final String IGNITE_HTTP_SERVER_PORT = "IGNITE_HTTP_SERVER_PORT";
Expand All @@ -77,7 +81,7 @@ public class ClusterProperties {
public static final String DEFAULT_HTTP_SERVER_PORT = "48610";

/** Http server host. */
private int httpServerPort = Integer.valueOf(DEFAULT_HTTP_SERVER_PORT);
private int httpSrvPort = Integer.valueOf(DEFAULT_HTTP_SERVER_PORT);

/** */
public static final String IGNITE_TOTAL_CPU = "IGNITE_TOTAL_CPU";
Expand Down Expand Up @@ -152,7 +156,13 @@ public class ClusterProperties {
public static final String IGNITE_PACKAGE_URL = "IGNITE_PACKAGE_URL";

/** Ignite package url. */
private String ignitePackageUrl = null;
private String ignitePkgUrl;

/** */
public static final String IGNITE_PACKAGE_PATH = "IGNITE_PACKAGE_PATH";

/** Ignite package path. */
private String ignitePkgPath;

/** */
public static final String IGNITE_WORK_DIR = "IGNITE_WORK_DIR";
Expand Down Expand Up @@ -318,10 +328,10 @@ public void minMemoryPerNode(double minMemory) {
/**
* Sets hostname constraint.
*
* @param pattern Hostname pattern.
* @param ptrn Hostname pattern.
*/
public void hostnameConstraint(Pattern pattern) {
this.hostnameConstraint = pattern;
public void hostnameConstraint(Pattern ptrn) {
this.hostnameConstraint = ptrn;
}

/**
Expand Down Expand Up @@ -379,21 +389,34 @@ public String masterUrl() {
* @return Http server host.
*/
public String httpServerHost() {
return httpServerHost;
return httpSrvHost;
}

/**
* @return Http server port.
*/
public int httpServerPort() {
return httpServerPort;
return httpSrvPort;
}

/**
* URL to ignite package. The URL should to point at valid apache ignite archive.
* This property can be useful if using own apache ignite build.
*
* @return Url to ignite package.
*/
public String ignitePackageUrl() {
return ignitePackageUrl;
return ignitePkgUrl;
}

/**
* Path on local file system to ignite archive. That can be useful when
* Mesos working in Intranet or behind NAT.
*
* @return Path on local host to ignite package.
*/
public String ignitePackagePath() {
return ignitePkgPath;
}

/**
Expand Down Expand Up @@ -425,37 +448,38 @@ public Pattern hostnameConstraint() {
}

/**
* @param config path to config file.
* @param cfg path to config file.
* @return Cluster configuration.
*/
public static ClusterProperties from(String config) {
public static ClusterProperties from(String cfg) {
try {
Properties props = null;

if (config != null) {
if (cfg != null) {
props = new Properties();

props.load(new FileInputStream(config));
props.load(new FileInputStream(cfg));
}

ClusterProperties prop = new ClusterProperties();

prop.mesosUrl = getStringProperty(MESOS_MASTER_URL, props, DEFAULT_MESOS_MASTER_URL);

prop.httpServerHost = getStringProperty(IGNITE_HTTP_SERVER_HOST, props, getNonLoopbackAddress());
prop.httpSrvHost = getStringProperty(IGNITE_HTTP_SERVER_HOST, props, getNonLoopbackAddress());

String port = System.getProperty("PORT0");

if (port != null && !port.isEmpty())
prop.httpServerPort = Integer.valueOf(port);
prop.httpSrvPort = Integer.valueOf(port);
else
prop.httpServerPort = Integer.valueOf(getStringProperty(IGNITE_HTTP_SERVER_PORT, props,
prop.httpSrvPort = Integer.valueOf(getStringProperty(IGNITE_HTTP_SERVER_PORT, props,
DEFAULT_HTTP_SERVER_PORT));

prop.clusterName = getStringProperty(IGNITE_CLUSTER_NAME, props, DEFAULT_CLUSTER_NAME);

prop.userLibsUrl = getStringProperty(IGNITE_USERS_LIBS_URL, props, null);
prop.ignitePackageUrl = getStringProperty(IGNITE_PACKAGE_URL, props, null);
prop.ignitePkgUrl = getStringProperty(IGNITE_PACKAGE_URL, props, null);
prop.ignitePkgPath = getStringProperty(IGNITE_PACKAGE_PATH, props, null);
prop.licenceUrl = getStringProperty(LICENCE_URL, props, null);
prop.igniteCfgUrl = getStringProperty(IGNITE_CONFIG_XML_URL, props, null);

Expand All @@ -476,11 +500,11 @@ public static ClusterProperties from(String config) {
prop.igniteCfg = getStringProperty(IGNITE_CONFIG_XML, props, null);
prop.userLibs = getStringProperty(IGNITE_USERS_LIBS, props, null);

String pattern = getStringProperty(IGNITE_HOSTNAME_CONSTRAINT, props, null);
String ptrn = getStringProperty(IGNITE_HOSTNAME_CONSTRAINT, props, null);

if (pattern != null) {
if (ptrn != null) {
try {
prop.hostnameConstraint = Pattern.compile(pattern);
prop.hostnameConstraint = Pattern.compile(ptrn);
}
catch (PatternSyntaxException e) {
log.log(Level.WARNING, "IGNITE_HOSTNAME_CONSTRAINT has invalid pattern. It will be ignore.", e);
Expand All @@ -499,33 +523,33 @@ public static ClusterProperties from(String config) {
* @param fileProps Property file.
* @return Property value.
*/
private static double getDoubleProperty(String name, Properties fileProps, Double defaultVal) {
private static double getDoubleProperty(String name, Properties fileProps, Double dfltVal) {
if (fileProps != null && fileProps.containsKey(name))
return Double.valueOf(fileProps.getProperty(name));

String property = System.getProperty(name);
String prop = System.getProperty(name);

if (property == null)
property = System.getenv(name);
if (prop == null)
prop = System.getenv(name);

return property == null ? defaultVal : Double.valueOf(property);
return prop == null ? dfltVal : Double.valueOf(prop);
}

/**
* @param name Property name.
* @param fileProps Property file.
* @return Property value.
*/
private static String getStringProperty(String name, Properties fileProps, String defaultVal) {
private static String getStringProperty(String name, Properties fileProps, String dfltVal) {
if (fileProps != null && fileProps.containsKey(name))
return fileProps.getProperty(name);

String property = System.getProperty(name);
String prop = System.getProperty(name);

if (property == null)
property = System.getenv(name);
if (prop == null)
prop = System.getenv(name);

return property == null ? defaultVal : property;
return prop == null ? dfltVal : prop;
}

/**
Expand All @@ -540,16 +564,16 @@ public static String getNonLoopbackAddress() throws SocketException {
while (ifaces.hasMoreElements()) {
NetworkInterface iface = ifaces.nextElement();

Enumeration<InetAddress> addresses = iface.getInetAddresses();
Enumeration<InetAddress> addrs = iface.getInetAddresses();

while (addresses.hasMoreElements()) {
InetAddress addr = addresses.nextElement();
while (addrs.hasMoreElements()) {
InetAddress addr = addrs.nextElement();

if (addr instanceof Inet4Address && !addr.isLoopbackAddress())
return addr.getHostAddress();
}
}

throw new RuntimeException("Failed. Couldn't find non-loopback address");
throw new RuntimeException("Failed. Could not find non-loopback address");
}
}
Expand Up @@ -19,6 +19,7 @@

import com.google.protobuf.ByteString;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.ignite.mesos.resource.IgniteProvider;
Expand All @@ -43,6 +44,7 @@ public class IgniteFramework {
* Main methods has only one optional parameter - path to properties files.
*
* @param args Args.
* @throws Exception If failed.
*/
public static void main(String[] args) throws Exception {
final int frameworkFailoverTimeout = 0;
Expand All @@ -63,9 +65,9 @@ public static void main(String[] args) throws Exception {

String baseUrl = String.format("http://%s:%d", clusterProps.httpServerHost(), clusterProps.httpServerPort());

JettyServer httpServer = new JettyServer();
JettyServer httpSrv = new JettyServer();

httpServer.start(
httpSrv.start(
new InetSocketAddress(clusterProps.httpServerHost(), clusterProps.httpServerPort()),
new ResourceHandler(clusterProps.userLibs(), clusterProps.igniteCfg(), clusterProps.igniteWorkDir())
);
Expand All @@ -79,8 +81,9 @@ public static void main(String[] args) throws Exception {
// Create the scheduler.
Scheduler scheduler = new IgniteScheduler(clusterProps, provider);

// create the driver
// Create the driver.
MesosSchedulerDriver driver;

if (System.getenv("MESOS_AUTHENTICATE") != null) {
log.info("Enabling authentication for the framework");

Expand All @@ -96,15 +99,15 @@ public static void main(String[] args) throws Exception {
System.exit(1);
}

Protos.Credential credential = Protos.Credential.newBuilder()
Protos.Credential cred = Protos.Credential.newBuilder()
.setPrincipal(System.getenv("DEFAULT_PRINCIPAL"))
.setSecret(ByteString.copyFrom(System.getenv("DEFAULT_SECRET").getBytes()))
.build();

frameworkBuilder.setPrincipal(System.getenv("DEFAULT_PRINCIPAL"));

driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), clusterProps.masterUrl(),
credential);
cred);
}
else {
frameworkBuilder.setPrincipal("ignite-framework-java");
Expand All @@ -114,7 +117,7 @@ public static void main(String[] args) throws Exception {

int status = driver.run() == Protos.Status.DRIVER_STOPPED ? 0 : 1;

httpServer.stop();
httpSrv.stop();

// Ensure that the driver process terminates.
driver.stop();
Expand Down

0 comments on commit f65dd00

Please sign in to comment.