public void merge(DockerCompositions otherContainers) { // merge networks for (Map.Entry<String, Network> thisNetwork : networks.entrySet()) { if (otherContainers.getNetwork(thisNetwork.getKey()) != null) { thisNetwork.getValue().merge(otherContainers.getNetwork(thisNetwork.getKey())); } } Map<String, Network> addAllNetworks = new HashMap<>(); for (Map.Entry<String, Network> otherNetwork : otherContainers.getNetworks().entrySet()) { if (getNetwork(otherNetwork.getKey()) == null) { addAllNetworks.put(otherNetwork.getKey(), otherNetwork.getValue()); } } networks.putAll(addAllNetworks); // merge containers for (Map.Entry<String, CubeContainer> thisContainer : containers.entrySet()) { if (otherContainers.get(thisContainer.getKey()) != null) { thisContainer.getValue().merge(otherContainers.get(thisContainer.getKey())); } } Map<String, CubeContainer> addAll = new HashMap<String, CubeContainer>(); for (Map.Entry<String, CubeContainer> otherContainer : otherContainers.getContainers().entrySet()) { if (get(otherContainer.getKey()) == null) { addAll.put(otherContainer.getKey(), otherContainer.getValue()); } } containers.putAll(addAll); }
public DockerCompositions convert() { DockerCompositions dockerCompositions = new DockerCompositions(); Set<String> names = dockerComposeDefinitionMap.keySet(); boolean isV2OrGreater = names.contains(DOCKER_COMPOSE_VERSION_KEY) && Integer.parseInt((String) dockerComposeDefinitionMap.get(DOCKER_COMPOSE_VERSION_KEY)) > 1; if (isV2OrGreater) { dockerCompositions = convertCompose(dockerComposeDefinitionMap); } else { for(String name : names) { CubeContainer cubeContainer = convertContainer(asMap(dockerComposeDefinitionMap, name)); if (cubeContainer.getContainerName() != null) { dockerCompositions.add(cubeContainer.getContainerName(), cubeContainer); } else { dockerCompositions.add(name, cubeContainer); } } } return dockerCompositions; }
@Override public Map<String, Node> parse() { Map<String, Node> nodes = new HashMap<>(); Set<String> networksIds = this.containerDefinition.getNetworkIds(); for (Map.Entry<String, CubeContainer> container : this.containerDefinition.getNoneManualContainers().entrySet()) { // If cube is not named as the deployable container (this is done in this way because containers that are named as the deployable container are started by another process). if (!this.deployableContainers.contains(container.getKey())) { final String networkMode = container.getValue().getNetworkMode(); if (networkMode != null) { // if the network that this cube must connect is registered in current cube definition if (networksIds.contains(networkMode)) { String name = container.getKey(); Node child = Node.from(name); nodes.put(name, child); } } } } return nodes; } }
private static DockerCompositions applyExtendsRules(DockerCompositions dockerCompositions) { for (Map.Entry<String, CubeContainer> containerEntry : dockerCompositions.getContainers().entrySet()) { CubeContainer container = containerEntry.getValue(); if (container.getExtends() != null) { String extendsContainer = container.getExtends(); if (dockerCompositions.get(extendsContainer) == null) { throw new IllegalArgumentException( containerEntry.getKey() + " extends a non existing container definition " + extendsContainer); } CubeContainer extendedContainer = dockerCompositions.get(extendsContainer); container.merge(extendedContainer); } } return dockerCompositions; }
public ContainerBuilder extend(Path location, String service) { Path extendLocation = this.dockerComposeRootLocation.resolve(location); DockerCompositions dockerCompositions = DockerComposeConverter.create(extendLocation).convert(); CubeContainer cubeContainer = dockerCompositions.getContainers().get(service); if (cubeContainer == null) { throw new IllegalArgumentException(String.format("Service name %s is not present at %s", service, extendLocation.toAbsolutePath())); } else { ContainerBuilder containerBuilder = new ContainerBuilder(dockerComposeRootLocation, configuration); configuration.merge(cubeContainer); } return this; }
@Override public Map<String, Node> parse() { Map<String, Node> nodes = new HashMap<>(); String[] autoStartContainers = ConfigUtil.trim(expression.split(",")); for (String autoStart : autoStartContainers) { if (containerDefinitions.get(autoStart) != null && !containerDefinitions.get(autoStart).isManual()) { nodes.put(autoStart, Node.from(autoStart)); } } return nodes; }
@Test public void shouldTransformSimpleDockerComposeV2FormatNetworkByDefault() throws URISyntaxException { URI simpleDockerCompose = DockerComposeConverterTest.class.getResource("/myapp/simple-docker-compose-v2.yml").toURI(); DockerComposeConverter dockerComposeConverter = DockerComposeConverter.create(Paths.get(simpleDockerCompose)); DockerCompositions convert = dockerComposeConverter.convert(); CubeContainer webapp = convert.getContainers().get("webapp"); assertThat(webapp, is(notNullValue())); assertThat(webapp.getNetworkMode()).endsWith("_default"); Map<String, Network> networks = convert.getNetworks(); assertThat(networks).hasSize(1); assertThat(networks.keySet().iterator().next()).endsWith("_default"); }
final Map<String, Network> networks = dockerContainersContent.getNetworks(); final Map<String, String> networkResolutions = new HashMap<>(); if (networks != null) { dockerContainersContent.setNetworks(resolvedNetworks); final Map<String, CubeContainer> containers = dockerContainersContent.getContainers(); for (Map.Entry<String, CubeContainer> container : containers.entrySet()) { containerMetadataInstanceProducer.set(new ContainerMetadata(containerMetadata)); dockerContainersContent.setContainers(resolvedContainers); return cubeConfiguration;
final Set<String> containerIds = overrideDockerCompositions.getContainerIds(); for (String containerId : containerIds) { final CubeContainer overrideCubeContainer = overrideDockerCompositions.get(containerId);
if (!this.configuration.getNetworks().containsKey(networkName)) { NetworkBuilder networkBuilder = new NetworkBuilder(); Network network = networkBuilder.withDefaultDriver().build(); this.configuration.add(networkName, network); this.configuration.add(key, cubeContainer); NetworkBuilder networks = new NetworkBuilder(); Network network = networks.build(asMap(networksDefinition, key)); this.configuration.add(key, network); NetworkBuilder networkBuilder = new NetworkBuilder(); Network network = networkBuilder.withDefaultDriver().build(); this.configuration.add(networkName, network);
final DockerCompositions overrideInformation = DockerContainerDefinitionParser.convert(content, DefinitionFormat.CUBE); cubeConfiguration.dockerContainersContent.overrideCubeProperties(overrideInformation); for (CubeContainer container : cubeConfiguration.dockerContainersContent.getContainers().values()) { if (container.getRemoveVolumes() == null) { container.setRemoveVolumes(cubeConfiguration.isRemoveVolumes());
public void install(@Observes(precedence = 90) CubeDockerConfiguration configuration, ArquillianDescriptor arquillianDescriptor) { DockerCompositions cubes = configuration.getDockerContainersContent(); final SeleniumContainers seleniumContainers = SeleniumContainers.create(getBrowser(arquillianDescriptor), cubeDroneConfigurationInstance.get()); cubes.add(seleniumContainers.getSeleniumContainerName(), seleniumContainers.getSeleniumContainer()); final boolean recording = cubeDroneConfigurationInstance.get().isRecording(); if (recording) { cubes.add(seleniumContainers.getVncContainerName(), seleniumContainers.getVncContainer()); cubes.add(seleniumContainers.getVideoConverterContainerName(), seleniumContainers.getVideoConverterContainer()); } seleniumContainersInstanceProducer.set(seleniumContainers); System.out.println("SELENIUM INSTALLED"); System.out.println(ConfigUtil.dump(cubes)); }
final Set<String> networkIds = dockerContainersContent.getNetworkIds(); String network1 = findElementStartingWith(networkIds, "network1"); assertThat(network1, is(not("network1*"))); assertThat(network3, is(not("network3*"))); final CubeContainer tomcat = dockerContainersContent.get("tomcat"); assertThat(tomcat.getNetworkMode(), is(network3)); final CubeContainer ping = dockerContainersContent.get("ping"); assertThat(ping.getNetworks(), containsInAnyOrder(network1, network2));
@Override public Map<String, Node> parse() { Map<String, Node> nodes = new HashMap<>(); String regularExpression = getRegularExpression(expression); Pattern pattern = Pattern.compile(regularExpression); Set<String> definedContainers = containerDefinitions.getNoneManualContainers().keySet(); for (String containerName : definedContainers) { Matcher matcher = pattern.matcher(containerName); if (matcher.matches()) { nodes.put(containerName, Node.from(containerName)); } } return nodes; }
private AutoStartParser resolveNotSetAutoStart(ContainerRegistry containerRegistry, DockerCompositions containers) { //we want to use the automatic autoconfiguration List<String> containersName = toContainersName(containerRegistry.getContainers()); if (containers.getNetworkIds().size() > 0) { //if network defined then you should not mix links and network return new AutomaticResolutionNetworkAutoStartParser(containersName, containers); } else { // if no network defined then links approach is used. return new AutomaticResolutionLinksAutoStartParser(containersName, containers); } } }
public void createNetworks(@Observes(precedence = 200) BeforeSuite event, CubeConfiguration cubeConfiguration, CubeDockerConfiguration dockerConfiguration) { final DockerCompositions dockerContainersContent = dockerConfiguration.getDockerContainersContent(); final Map<String, Network> networks = dockerContainersContent.getNetworks(); final NetworkRegistry networkRegistry = networkRegistryInstance.get(); final DockerClientExecutor dockerClientExecutor = dockerClientExecutorInstance.get(); for (Map.Entry<String, Network> network : networks.entrySet()) { final String id = dockerClientExecutor.createNetwork(network.getKey(), network.getValue()); networkRegistry.addNetwork(id, network.getValue()); } }
@Test public void should_be_able_to_read_network_configuration() { String config = "networks:\n" + " mynetwork:\n " + " driver: bridge\n" + "tomcat6:\n" + " image: tutum/tomcat:6.0\n" + " exposedPorts: [8089/tcp]\n" + " await:\n" + " strategy: static\n" + " ip: localhost\n" + " ports: [8080, 8089]\n" + "tomcat7:\n" + " extends: tomcat6\n" + " image: tutum/tomcat:7.0\n"; Map<String, String> parameters = new HashMap<String, String>(); parameters.put("dockerContainers", config); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); CubeDockerConfiguration cubeConfiguration = CubeDockerConfiguration.fromMap(parameters, null); final Network mynetwork = cubeConfiguration.getDockerContainersContent().getNetwork("mynetwork"); assertThat(mynetwork, is(notNullValue())); assertThat(mynetwork.getDriver(), is("bridge")); }
@Test public void shouldChangeNamesInParallelizeStarCubes() { String content = "tomcat*:\n" + " image: tutum/tomcat:8.0\n" + " portBindings: [8080/tcp]\n" + " links:\n" + " - ping*\n" + "ping*:\n" + " image: jonmorehouse/ping-pong\n" + " exposedPorts: [8089/tcp]\n" + "storage:\n" + " image: tutum/mongodb"; Map<String, String> parameters = new HashMap<String, String>(); parameters.put("dockerContainers", content); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); CubeDockerConfiguration cubeConfiguration = CubeDockerConfiguration.fromMap(parameters, null); CubeDockerConfigurator cubeDockerConfigurator = new CubeDockerConfigurator(); final CubeDockerConfiguration cubeDockerConfiguration = cubeDockerConfigurator.resolveDynamicNames(cubeConfiguration); final Set<String> containerIds = cubeDockerConfiguration.getDockerContainersContent().getContainerIds(); final String tomcat = findElementStartingWith(containerIds, "tomcat"); assertThat(tomcat.length(), is(greaterThan(6))); final String ping = findElementStartingWith(containerIds, "ping"); assertThat(ping.length(), is(greaterThan(4))); }
public ContainerBuilder extend(Path location, String service) { Path extendLocation = this.dockerComposeRootLocation.resolve(location); DockerCompositions dockerCompositions = DockerComposeConverter.create(extendLocation).convert(); CubeContainer cubeContainer = dockerCompositions.getContainers().get(service); if (cubeContainer == null) { throw new IllegalArgumentException(String.format("Service name %s is not present at %s", service, extendLocation.toAbsolutePath())); } else { ContainerBuilder containerBuilder = new ContainerBuilder(dockerComposeRootLocation, configuration); configuration.merge(cubeContainer); } return this; }
@Override public Map<String, Node> parse() { Map<String, Node> nodes = new HashMap<>(); String[] autoStartContainers = ConfigUtil.trim(expression.split(",")); for (String autoStart : autoStartContainers) { if (containerDefinitions.get(autoStart) != null && !containerDefinitions.get(autoStart).isManual()) { nodes.put(autoStart, Node.from(autoStart)); } } return nodes; }