Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Remove placement constraints for browser containers
Browse files Browse the repository at this point in the history
  • Loading branch information
tstern authored and diemol committed Jun 28, 2019
1 parent 2d08f9b commit 89c010c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,46 +245,32 @@ private ContainerSpec buildContainerSpec(List<String> flattenedEnvVars, String i
}

private TaskSpec buildTaskSpec(ContainerSpec containerSpec) {
try {
final RestartPolicy restartPolicy = RestartPolicy.builder()
.condition("on-failure")
.build();
String hostname = SwarmUtilities.getHubHostname();
final List<String> placementList = new ArrayList<>();

placementList.add("node.hostname != " + hostname);

final Placement placement = Placement.create(placementList);


Resources.Builder resourceBuilder = Resources.builder();
String cpuLimit = getSeleniumContainerCpuLimit();
String memLimit = getSeleniumContainerMemoryLimit();
final RestartPolicy restartPolicy = RestartPolicy.builder()
.condition("on-failure")
.build();

if (!Strings.isNullOrEmpty(cpuLimit)) {
resourceBuilder.nanoCpus(Long.valueOf(cpuLimit));
}
Resources.Builder resourceBuilder = Resources.builder();
String cpuLimit = getSeleniumContainerCpuLimit();
String memLimit = getSeleniumContainerMemoryLimit();

if (!Strings.isNullOrEmpty(memLimit)) {
resourceBuilder.memoryBytes(Long.valueOf(memLimit));
}
if (!Strings.isNullOrEmpty(cpuLimit)) {
resourceBuilder.nanoCpus(Long.valueOf(cpuLimit));
}

ResourceRequirements resourceRequirements = ResourceRequirements.builder()
.limits(resourceBuilder.build())
.build();
if (!Strings.isNullOrEmpty(memLimit)) {
resourceBuilder.memoryBytes(Long.valueOf(memLimit));
}

final TaskSpec.Builder taskSpecBuilder = TaskSpec.builder()
.resources(resourceRequirements)
.restartPolicy(restartPolicy)
.placement(placement)
.containerSpec(containerSpec);
ResourceRequirements resourceRequirements = ResourceRequirements.builder()
.limits(resourceBuilder.build())
.build();

return taskSpecBuilder.build();
} catch (DockerException | InterruptedException e) {
e.printStackTrace();
}
final TaskSpec.Builder taskSpecBuilder = TaskSpec.builder()
.resources(resourceRequirements)
.restartPolicy(restartPolicy)
.containerSpec(containerSpec);

return null;
return taskSpecBuilder.build();
}

private ServiceSpec buildServiceSpec(TaskSpec taskSpec, String nodePort, String noVncPort) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,6 @@ public static synchronized Task getTaskByContainerId(String containerId) throws
return null;
}

public static synchronized Task getTaskByContainerLabel(String labelKey, String labelValue) throws DockerException, InterruptedException {
List<Task> tasks = dockerClient.listTasks();

for (Task task : CollectionUtils.emptyIfNull(tasks)) {
ContainerStatus containerStatus = task.status().containerStatus();

if (containerStatus != null) {
ContainerInfo containerInfo = dockerClient.inspectContainer(containerStatus.containerId());
ImmutableMap<String, String> labels = containerInfo.config().labels();
boolean hasLabel = labels != null && labels.containsKey(labelKey);
boolean labelHasValue = labels != null && labels.get(labelKey).equals(labelValue);

if (hasLabel && labelHasValue) {
return task;
}
}
}

return null;
}

public static synchronized Task getTaskByServiceId(String serviceId) throws DockerException, InterruptedException {
String serviceName = dockerClient.inspectService(serviceId).spec().name();
Task.Criteria criteria = Task.Criteria.builder().serviceName(serviceName).build();
Expand Down Expand Up @@ -170,22 +149,6 @@ public static String getSwarmIp(ContainerInfo containerInfo) {
return ipAddress;
}


public static synchronized String getHubHostname () throws DockerException, InterruptedException {
String hubLabelKey = "de.zalando.gridRole";
String hubLabelValue = "hub";
Task task = getTaskByContainerLabel(hubLabelKey, hubLabelValue);

if (task != null) {
String nodeId = task.nodeId();
NodeInfo nodeInfo = dockerClient.inspectNode(nodeId);

return nodeInfo.description().hostname();
}

return null;
}

public static boolean isSwarmActive() {
return !overlayNetwork.isEmpty();
}
Expand Down

0 comments on commit 89c010c

Please sign in to comment.