use of de.zalando.ep.zalenium.container.ContainerCreationStatus in project zalenium by zalando.
the class DockerSeleniumStarterRemoteProxy method startDockerSeleniumContainer.
@VisibleForTesting
public boolean startDockerSeleniumContainer(TimeZone timeZone, Dimension screenSize, boolean forceCreation) {
NetworkUtils networkUtils = new NetworkUtils();
String hostIpAddress = networkUtils.getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
String nodePolling = String.valueOf(RandomUtils.nextInt(90, 120) * 1000);
String nodeRegisterCycle = String.valueOf(RandomUtils.nextInt(15, 25) * 1000);
String seleniumNodeParams = getSeleniumNodeParameters();
String latestImage = getLatestDownloadedImage(getDockerSeleniumImageName());
int attempts = 0;
int maxAttempts = 2;
while (attempts < maxAttempts) {
attempts++;
if (forceCreation || validateAmountOfDockerSeleniumContainers()) {
final int nodePort = findFreePortInRange(LOWER_PORT_BOUNDARY, UPPER_PORT_BOUNDARY);
Map<String, String> envVars = buildEnvVars(timeZone, screenSize, hostIpAddress, sendAnonymousUsageInfo, nodePolling, nodeRegisterCycle, nodePort, seleniumNodeParams);
ContainerCreationStatus creationStatus = containerClient.createContainer(getContainerName(), latestImage, envVars, String.valueOf(nodePort));
if (creationStatus.isCreated() && checkContainerStatus(creationStatus)) {
return true;
} else {
LOGGER.debug(String.format("%sContainer creation failed, retrying...", getId()));
}
} else {
LOGGER.info(String.format("%sNo container was created, will try again in a moment...", getId()));
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
LOGGER.debug("Exception while making a pause during container creation.", e);
}
}
}
LOGGER.info(String.format("%sNo container was created after 3 attempts, will wait until request is " + "processed again...", getId()));
return false;
}
use of de.zalando.ep.zalenium.container.ContainerCreationStatus in project zalenium by zalando.
the class KubernetesContainerClient method createContainer.
@Override
public ContainerCreationStatus createContainer(String zaleniumContainerName, String image, Map<String, String> envVars, String nodePort) {
String containerIdPrefix = String.format("%s-%s-", zaleniumAppName, nodePort);
// Convert the environment variables into the Kubernetes format.
List<EnvVar> flattenedEnvVars = envVars.entrySet().stream().map(e -> new EnvVar(e.getKey(), e.getValue(), null)).collect(Collectors.toList());
Map<String, String> podSelector = new HashMap<>();
PodConfiguration config = new PodConfiguration();
config.setNodePort(nodePort);
config.setClient(client);
config.setContainerIdPrefix(containerIdPrefix);
config.setImage(image);
config.setEnvVars(flattenedEnvVars);
Map<String, String> labels = new HashMap<>();
labels.putAll(createdByZaleniumMap);
labels.putAll(appLabelMap);
labels.putAll(podSelector);
config.setLabels(labels);
config.setMountedSharedFoldersMap(mountedSharedFoldersMap);
config.setHostAliases(hostAliases);
config.setNodeSelector(nodeSelector);
config.setPodLimits(seleniumPodLimits);
config.setPodRequests(seleniumPodRequests);
DoneablePod doneablePod = createDoneablePod.apply(config);
// Create the container
Pod createdPod = doneablePod.done();
String containerName = createdPod.getMetadata() == null ? containerIdPrefix : createdPod.getMetadata().getName();
return new ContainerCreationStatus(true, containerName, nodePort);
}
Aggregations