LOG.info("Resume {}", dockerContainerName);
getDockerHost().runDockerCommand("start" + getContainerId());
}
private DockerTemplateOptions getDockerTemplateOptions() {
Entity entity = getRunningEntity();
DockerTemplateOptions options = DockerTemplateOptions.NONE;
// Use DockerHost hostname for the container
Boolean useHostDns = entity.getConfig(DOCKER_USE_HOST_DNS_NAME);
if (useHostDns == null) useHostDns = getConfig(DOCKER_USE_HOST_DNS_NAME);
if (useHostDns != null && useHostDns) {
// FIXME does not seem to work on Softlayer, should set HOSTNAME or SUBNET_HOSTNAME
String hostname = getDockerHost().getAttribute(Attributes.HOSTNAME);
String address = getDockerHost().getAttribute(Attributes.ADDRESS);
if (hostname.equalsIgnoreCase(address)) {
options.hostname(getDockerContainerName());
} else {
options.hostname(hostname);
}
}
// CPU shares
Integer cpuShares = entity.getConfig(DOCKER_CPU_SHARES);
if (cpuShares == null) cpuShares = getConfig(DOCKER_CPU_SHARES);
if (cpuShares != null) {
// TODO set based on number of cores available in host divided by cores requested in flags
Integer hostCores = (int) getDockerHost().getDynamicLocation().getMachine().getMachineDetails().getHardwareDetails().getCpuCount();
Integer minCores = (Integer) entity.getConfig(JcloudsLocationConfig.MIN_CORES);
Map flags = entity.getConfig(SoftwareProcess.PROVISIONING_PROPERTIES);
if (minCores == null && flags != null) {
minCores = (Integer) flags.get(JcloudsLocationConfig.MIN_CORES.getName());
}
if (minCores == null && flags != null) {
TemplateBuilder template = (TemplateBuilder) flags.get(JcloudsLocationConfig.TEMPLATE_BUILDER.getName());
if (template != null) {
minCores = 0;
for (Processor cpu : template.build().getHardware().getProcessors()) {
minCores = minCores + (int) cpu.getCores();
}
}
}
if (minCores != null) {
double ratio = (double) minCores / (double) hostCores;
LOG.info("Cores: host {}, min {}, ratio {}", new Object[] { hostCores, minCores, ratio });
}
}
if (cpuShares != null) options.cpuShares(cpuShares);
// Memory
Integer memory = entity.getConfig(DOCKER_MEMORY);
if (memory == null) memory = getConfig(DOCKER_MEMORY);
if (memory != null) {
// TODO set based on memory available in host divided by memory requested in flags
Integer hostRam = getDockerHost().getDynamicLocation().getMachine().getMachineDetails().getHardwareDetails().getRam();
Integer minRam = (Integer) entity.getConfig(JcloudsLocationConfig.MIN_RAM);
Map flags = entity.getConfig(SoftwareProcess.PROVISIONING_PROPERTIES);
if (minRam == null && flags != null) {
minRam = (Integer) flags.get(JcloudsLocationConfig.MIN_RAM.getName());
}
if (minRam == null && flags != null) {
TemplateBuilder template = (TemplateBuilder) flags.get(JcloudsLocationConfig.TEMPLATE_BUILDER.getName());
if (template != null) {
minRam = template.build().getHardware().getRam();
}
}
if (minRam != null) {
double ratio = (double) minRam / (double) hostRam;
LOG.info("Memory: host {}, min {}, ratio {}", new Object[] { hostRam, minRam, ratio });
}
}
if (memory != null) options.memory(memory);
// Volumes
Map<String, String> volumes = MutableMap.copyOf(getDockerHost().getAttribute(DockerHost.DOCKER_HOST_VOLUME_MAPPING));
Map<String, String> mapping = entity.getConfig(DockerHost.DOCKER_HOST_VOLUME_MAPPING);
if (mapping != null) {
for (String source : mapping.keySet()) {
if (Urls.isUrlWithProtocol(source)) {
String path = getDockerHost().deployArchive(source);
volumes.put(path, mapping.get(source));
} else {
volumes.put(source, mapping.get(source));
}
}
}
List<String> exports = entity.getConfig(DockerContainer.DOCKER_CONTAINER_VOLUME_EXPORT);
if (exports != null) {
for (String dir : exports) {
volumes.put(dir, dir);
}
}
options.volumes(volumes);
// Set login password from the Docker host
options.overrideLoginPassword(getDockerHost().getPassword());
// Look for environment variables configured on the entity
Map<String, Object> shellEnv = entity.getConfig(SoftwareProcess.SHELL_ENVIRONMENT);
if (shellEnv != null && !shellEnv.isEmpty()) {
String env = Joiner.on(':').withKeyValueSeparator("=").join(shellEnv);
options.env(ImmutableList.of(env));
}