use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.
the class JsonRuleBaseReader method parseJson.
/**
* Will try to parse the {@link InputStream} which is expected to be in the following
* JSON format:
* <pre>
* { "rulebase" : [
* { "rule": "/foo/{path}", "to": "https://foo.com/cheese/{path}"},
* { "rule": "/customers/{id}/address/{addressId}", "to": "http://another.com/addresses/{addressId}/customer/{id}"}
* ]
* }
* </pre>
*
* <strong>Note that the passed-in {@link InputStream} will be closed by this method</strong>. This
* is a little unusual as normally the closing is the responsibility of the party that created the
* InputStream, but in this case we decided handling this is more user friendly.
*
* @param in the {@link InputStream} stream to read.
* @return {@code Map} where the key maps to the 'rule' in the JSON, and the value maps to 'to'.
*/
public static Map<String, HttpProxyRule> parseJson(InputStream in) {
chechNotNull(in);
HashMap<String, HttpProxyRule> map = new HashMap<String, HttpProxyRule>();
try {
JsonNode config = OM.readTree(in);
JsonNode globalCookiePath = config.get("cookiePath");
JsonNode globalDomain = config.get("cookieDomain");
for (JsonNode entry : getRuleBase(config)) {
String rule = entry.get("rule").asText();
map.put(rule, new HttpProxyRule(rule).to(entry.get("to").asText()).setCookiePath(getGlobal(entry, globalCookiePath, "cookiePath")).setCookieDomain(getGlobal(entry, globalDomain, "cookieDomain")));
}
return map;
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
} finally {
safeClose(in);
}
}
use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.
the class KarafContainerRegistration method configurationEvent.
/**
* Receives notification of a Configuration that has changed.
*
* @param event The <code>ConfigurationEvent</code>.
*/
@Override
public void configurationEvent(ConfigurationEvent event) {
if (isValid()) {
try {
Container current = new ImmutableContainerBuilder().id(runtimeIdentity).ip(ip).build();
RuntimeProperties sysprops = runtimeProperties.get();
String runtimeIdentity = sysprops.getRuntimeIdentity();
if (event.getPid().equals(SSH_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
Configuration config = configAdmin.get().getConfiguration(SSH_PID, null);
int sshPort = Integer.parseInt((String) config.getProperties().get(SSH_BINDING_PORT_KEY));
int sshConnectionPort = getSshConnectionPort(current, sshPort);
String sshUrl = getSshUrl(runtimeIdentity, sshConnectionPort);
setData(curator.get(), CONTAINER_SSH.getPath(runtimeIdentity), sshUrl);
if (portService.get().lookupPort(current, SSH_PID, SSH_BINDING_PORT_KEY) != sshPort) {
portService.get().unregisterPort(current, SSH_PID);
portService.get().registerPort(current, SSH_PID, SSH_BINDING_PORT_KEY, sshPort);
}
}
if (event.getPid().equals(HTTP_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
Configuration config = configAdmin.get().getConfiguration(HTTP_PID, null);
boolean httpEnabled = isHttpEnabled();
boolean httpsEnabled = isHttpsEnabled();
String protocol = httpsEnabled && !httpEnabled ? "https" : "http";
int httpConnectionPort = -1;
if (httpEnabled) {
int httpPort = Integer.parseInt((String) config.getProperties().get(HTTP_BINDING_PORT_KEY));
httpConnectionPort = getHttpConnectionPort(current, httpPort);
if (portService.get().lookupPort(current, HTTP_PID, HTTP_BINDING_PORT_KEY) != httpPort) {
portService.get().unregisterPort(current, HTTP_PID, HTTP_BINDING_PORT_KEY);
portService.get().registerPort(current, HTTP_PID, HTTP_BINDING_PORT_KEY, httpPort);
}
}
if (httpsEnabled) {
int httpsPort = Integer.parseInt((String) config.getProperties().get(HTTPS_BINDING_PORT_KEY));
if (httpConnectionPort == -1) {
httpConnectionPort = getHttpsConnectionPort(current, httpsPort);
}
if (portService.get().lookupPort(current, HTTP_PID, HTTPS_BINDING_PORT_KEY) != httpsPort) {
portService.get().unregisterPort(current, HTTP_PID, HTTPS_BINDING_PORT_KEY);
portService.get().registerPort(current, HTTP_PID, HTTPS_BINDING_PORT_KEY, httpsPort);
}
}
String httpUrl = getHttpUrl(protocol, runtimeIdentity, httpConnectionPort);
setData(curator.get(), CONTAINER_HTTP.getPath(runtimeIdentity), httpUrl);
}
if (event.getPid().equals(MANAGEMENT_PID) && event.getType() == ConfigurationEvent.CM_UPDATED) {
Configuration config = configAdmin.get().getConfiguration(MANAGEMENT_PID, null);
int rmiServerPort = Integer.parseInt((String) config.getProperties().get(RMI_SERVER_BINDING_PORT_KEY));
int rmiServerConnectionPort = getRmiServerConnectionPort(current, rmiServerPort);
int rmiRegistryPort = Integer.parseInt((String) config.getProperties().get(RMI_REGISTRY_BINDING_PORT_KEY));
int rmiRegistryConnectionPort = getRmiRegistryConnectionPort(current, rmiRegistryPort);
String jmxUrl = getJmxUrl(runtimeIdentity, rmiServerConnectionPort, rmiRegistryConnectionPort);
setData(curator.get(), CONTAINER_JMX.getPath(runtimeIdentity), jmxUrl);
// Whenever the JMX URL changes we need to make sure that the java.rmi.server.hostname points to a valid address.
System.setProperty(SystemProperties.JAVA_RMI_SERVER_HOSTNAME, current.getIp());
if (portService.get().lookupPort(current, MANAGEMENT_PID, RMI_REGISTRY_BINDING_PORT_KEY) != rmiRegistryPort || portService.get().lookupPort(current, MANAGEMENT_PID, RMI_SERVER_BINDING_PORT_KEY) != rmiServerPort) {
portService.get().unregisterPort(current, MANAGEMENT_PID);
portService.get().registerPort(current, MANAGEMENT_PID, RMI_SERVER_BINDING_PORT_KEY, rmiServerPort);
portService.get().registerPort(current, MANAGEMENT_PID, RMI_REGISTRY_BINDING_PORT_KEY, rmiRegistryPort);
}
}
} catch (Exception ex) {
LOGGER.error("Cannot reconfigure container", ex);
}
}
}
use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.
the class KarafContainerRegistration method getOrAllocatePortForKey.
/**
* Returns a port number for the use in the specified pid and key.
* If the port is already registered it is directly returned. Else the {@link ConfigurationAdmin} or a default value is used.
* In the later case, the port will be checked against the already registered ports and will be increased, till it doesn't match the used ports.
*/
private int getOrAllocatePortForKey(Container container, String pid, String key, int defaultValue, PortService.Lock lock) throws IOException, KeeperException, InterruptedException {
Configuration config = configAdmin.get().getConfiguration(pid, null);
Set<Integer> unavailable = portService.get().findUsedPortByHost(container, lock);
int port = portService.get().lookupPort(container, pid, key);
if (port > 0) {
return port;
} else if (config.getProperties() != null && config.getProperties().get(key) != null) {
try {
port = Integer.parseInt((String) config.getProperties().get(key));
} catch (NumberFormatException ex) {
port = defaultValue;
}
} else {
port = defaultValue;
}
while (unavailable.contains(port)) {
port++;
}
return port;
}
use of io.fabric8.docker.client.Config in project watchdog by isdream.
the class OpenshiftListenerTest method main.
public static void main(String[] args) {
// Configure config = new Parser().parse("config/podWatcher.yaml");
Configure config = null;
try {
config = new Parser().parse("config/podWatcher.yaml");
OpenShiftClient client = getClient("https", "master.example.com", "8443", "NaD95GPF8rIpbphyCyep--pJQH7t3pzBBV9aXQE77O4");
Listener listener = new OpenShiftListener();
listener.start(client, config);
Thread.sleep(600000);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.fabric8.docker.client.Config in project fabric8-maven-plugin by fabric8io.
the class DockerBuildServiceTest method testSuccessfulBuild.
@Test
public void testSuccessfulBuild() throws Exception {
new Expectations() {
{
hub.getBuildService();
result = buildService;
}
};
final BuildService.BuildContext context = new BuildService.BuildContext.Builder().build();
final io.fabric8.maven.core.service.BuildService.BuildServiceConfig config = new io.fabric8.maven.core.service.BuildService.BuildServiceConfig.Builder().dockerBuildContext(context).build();
final String imageName = "image-name";
final ImageConfiguration image = new ImageConfiguration.Builder().name(imageName).buildConfig(new BuildImageConfiguration.Builder().from("from").build()).build();
DockerBuildService service = new DockerBuildService(hub, config);
service.build(image);
new FullVerificationsInOrder() {
{
buildService.buildImage(image, context);
buildService.tagImage(imageName, image);
}
};
}
Aggregations