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

Commit

Permalink
#315 Network mode is configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
frankscholten committed Mar 18, 2016
1 parent 0ade498 commit 2a6874a
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.containersol.minimesos.config;
package com.containersol.minimesos.config

import org.apache.commons.lang.StringUtils;

public class ConsulConfig extends GroovyBlock implements ContainerConfig {

Expand All @@ -10,5 +12,20 @@ public class ConsulConfig extends GroovyBlock implements ContainerConfig {

String imageName = CONSUL_IMAGE_NAME
String imageTag = CONSUL_TAG_NAME
String networkMode = DEFAULT_NETWORK_MODE

@Override
String getNetworkMode() {
return networkMode
}

@Override
void setNetworkMode(String networkMode) {
if (!StringUtils.equalsIgnoreCase(networkMode, "bridge") && !StringUtils.equalsIgnoreCase(networkMode, "host")) {
throw new RuntimeException("Property 'networkMode' can only have the values 'bridge' or 'host'")
}
this.networkMode = networkMode
}

}

Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
package com.containersol.minimesos.config


/**
* Common methods for containers' configuration
*/
interface ContainerConfig {

public static final String DEFAULT_NETWORK_MODE = "bridge"

String getImageName()

void setImageName(String imageName)

String getImageTag()

void setImageTag(String imageTag)

String getNetworkMode()

void setNetworkMode(String networkMode)

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.containersol.minimesos.config;
package com.containersol.minimesos.config

import org.apache.commons.lang.StringUtils;

public class MarathonConfig extends GroovyBlock implements ContainerConfig {

Expand All @@ -8,5 +10,18 @@ public class MarathonConfig extends GroovyBlock implements ContainerConfig {

String imageName = MARATHON_IMAGE
String imageTag = MARATHON_IMAGE_TAG
String networkMode = DEFAULT_NETWORK_MODE

@Override
String getNetworkMode() {
return networkMode
}

@Override
void setNetworkMode(String networkMode) {
if (!StringUtils.equalsIgnoreCase(networkMode, "bridge") && !StringUtils.equalsIgnoreCase(networkMode, "host")) {
throw new RuntimeException("Property 'networkMode' can only have the values 'bridge' or 'host'")
}
this.networkMode = networkMode
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.containersol.minimesos.config

import groovy.util.logging.Slf4j
import org.apache.commons.lang.StringUtils

@Slf4j
class MesosAgentConfig extends MesosContainerConfig {

public static final String MESOS_AGENT_IMAGE = "containersol/mesos-agent"
public static final int DEFAULT_MESOS_AGENT_PORT = 5051

int portNumber = DEFAULT_MESOS_AGENT_PORT
public static final String MESOS_AGENT_IMAGE = "containersol/mesos-agent"
public static final int DEFAULT_MESOS_AGENT_PORT = 5051

int portNumber = DEFAULT_MESOS_AGENT_PORT
String imageName = MESOS_AGENT_IMAGE
String imageTag = MESOS_IMAGE_TAG

Expand All @@ -19,4 +19,19 @@ class MesosAgentConfig extends MesosContainerConfig {
delegateTo(resources, cl)
}

String networkMode = DEFAULT_NETWORK_MODE

@Override
String getNetworkMode() {
return networkMode
}

@Override
void setNetworkMode(String networkMode) {
if (!StringUtils.equalsIgnoreCase(networkMode, "bridge") && !StringUtils.equalsIgnoreCase(loggingLevel, "host")) {
throw new RuntimeException("Property 'networkMode' can only have the values 'bridge' or 'host'")
}
this.networkMode = networkMode
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.containersol.minimesos.config

import org.apache.commons.lang.StringUtils

abstract class MesosContainerConfig extends GroovyBlock implements ContainerConfig {

public static final String MESOS_IMAGE_TAG = "# derive from mesos version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.containersol.minimesos.config

import groovy.util.logging.Slf4j
import org.apache.commons.lang.StringUtils

@Slf4j
class MesosMasterConfig extends MesosContainerConfig {
Expand All @@ -10,5 +11,19 @@ class MesosMasterConfig extends MesosContainerConfig {

String imageName = MESOS_MASTER_IMAGE
String imageTag = MESOS_IMAGE_TAG
String networkMode = DEFAULT_NETWORK_MODE

@Override
String getNetworkMode() {
return networkMode
}

@Override
void setNetworkMode(String networkMode) {
if (!StringUtils.equalsIgnoreCase(networkMode, "bridge") && !StringUtils.equalsIgnoreCase(networkMode, "host")) {
throw new RuntimeException("Property 'networkMode' can only have the values 'bridge' or 'host'")
}
this.networkMode = networkMode
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.containersol.minimesos.config;
package com.containersol.minimesos.config

import org.apache.commons.lang.StringUtils;

public class RegistratorConfig extends GroovyBlock implements ContainerConfig {

Expand All @@ -7,5 +9,19 @@ public class RegistratorConfig extends GroovyBlock implements ContainerConfig {

String imageName = REGISTRATOR_IMAGE_NAME
String imageTag = REGISTRATOR_TAG_NAME
String networkMode = DEFAULT_NETWORK_MODE

@Override
String getNetworkMode() {
return networkMode
}

@Override
void setNetworkMode(String networkMode) {
if (!StringUtils.equalsIgnoreCase(networkMode, "bridge") && !StringUtils.equalsIgnoreCase(networkMode, "host")) {
throw new RuntimeException("Property 'networkMode' can only have the values 'bridge' or 'host'")
}
this.networkMode = networkMode
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package com.containersol.minimesos.config

import org.apache.commons.lang.StringUtils

public class ZooKeeperConfig extends GroovyBlock implements ContainerConfig {

public static final String MESOS_LOCAL_IMAGE = "jplock/zookeeper"
public static final String ZOOKEEPER_IMAGE_TAG = "3.4.6"

String imageName = MESOS_LOCAL_IMAGE
String imageTag = ZOOKEEPER_IMAGE_TAG
String networkMode = DEFAULT_NETWORK_MODE

@Override
String getNetworkMode() {
return networkMode
}

@Override
void setNetworkMode(String networkMode) {
if (!StringUtils.equalsIgnoreCase(networkMode, "bridge") && !StringUtils.equalsIgnoreCase(networkMode, "host")) {
throw new RuntimeException("Property 'networkMode' can only have the values 'bridge' or 'host'")
}
this.networkMode = networkMode
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public CreateContainerCmd getBaseCommand() {
.withPrivileged(true)
.withEnv(createMesosLocalEnvironment())
.withPid("host")
.withNetworkMode(config.getNetworkMode())
.withLinks(new Link(getZooKeeperContainer().getContainerId(), "minimesos-zookeeper"))
.withBinds(
Bind.parse("/var/run/docker.sock:/var/run/docker.sock"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ protected CreateContainerCmd dockerCommand() {
}

return dockerClient.createContainerCmd(getMesosImageName() + ":" + getMesosImageTag())
.withName( getName() )
.withName(getName())
.withNetworkMode(config.getNetworkMode())
.withExposedPorts(new ExposedPort(getPortNumber()))
.withEnv(createMesosLocalEnvironment())
.withPortBindings(portBindings);
Expand Down

0 comments on commit 2a6874a

Please sign in to comment.