Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to get a specific cube's docker Id in the interface. #98

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ Go version (server): go1.3.1

If you cannot see the client and server versions then it means that something is wrong with the _Docker_ installation.

== Using an external Docker server

When using an external docker server, such as boot2docker, additional configuration on the client is required as of 1.0.0.Alpha3. The following properties will need to be set within the user's maven profile.

[source, xml]
<docker.api.version>1.12</docker.api.version>
<docker.host>[boot2docker or docker host]</docker.host>
<docker.api.url>https://${docker.host}:2376</docker.api.url>



When using tls, the file ~/.docker.io.properties will also need to be installed with these options.

[source, properties]
docker.io.url=https://[boot2docker or docker host]:2376
docker.io.version=1.12
docker.io.dockerCertPath=[path to docker certs provided on boot2docker start]


== Basic Example

After having a _Docker_ server installed we can start using *Arquillian Cube*.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public boolean await() {

break;
case "sscommand": {
if(!Ping.ping(dockerClientExecutor, cube.getId(), resolveCommand("ss", ports.getExposedPort()), this.pollIterations, this.sleepPollTime, this.timeUnit)) {
if(!Ping.ping(dockerClientExecutor, cube.getDockerId(), resolveCommand("ss", ports.getExposedPort()), this.pollIterations, this.sleepPollTime, this.timeUnit)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ public class CubeConfiguration {
private static final String AUTO_START_CONTAINERS = "autoStartContainers";
private static final String SHOULD_ALLOW_TO_CONNECT_TO_RUNNING_CONTAINERS = "shouldAllowToConnectToRunningContainers";

private static final String NAME_GENERATOR = "nameGenerator";
private static final String NAME_GENERATOR_PREFIX = "nameGeneratorPrefix";

private String dockerServerVersion;
private String dockerServerUri;
private String dockerRegistry;
private boolean shouldAllowToConnectToRunningContainers = false;
private String[] autoStartContainers = new String[0];
private String nameGenerator;
private String getNameGeneratorPrefix;

private Map<String, Object> dockerContainersContent;

Expand Down Expand Up @@ -49,8 +54,22 @@ public String[] getAutoStartContainers() {
return autoStartContainers;
}


public String getNameGenerator() {
return nameGenerator;
}


public String getGetNameGeneratorPrefix() {
return getNameGeneratorPrefix;
}


@SuppressWarnings("unchecked")
public static CubeConfiguration fromMap(Map<String, String> map) {

//TODO add provider parsing here

CubeConfiguration cubeConfiguration = new CubeConfiguration();

if (map.containsKey(DOCKER_VERSION)) {
Expand Down Expand Up @@ -86,6 +105,15 @@ public static CubeConfiguration fromMap(Map<String, String> map) {
if(map.containsKey(SHOULD_ALLOW_TO_CONNECT_TO_RUNNING_CONTAINERS)) {
cubeConfiguration.shouldAllowToConnectToRunningContainers = Boolean.parseBoolean(map.get(SHOULD_ALLOW_TO_CONNECT_TO_RUNNING_CONTAINERS));
}

if(map.containsKey( NAME_GENERATOR )){
cubeConfiguration.nameGenerator = map.get( NAME_GENERATOR ).trim();
}

if(map.containsKey( NAME_GENERATOR_PREFIX )){
cubeConfiguration.getNameGeneratorPrefix = map.get( NAME_GENERATOR_PREFIX ).trim();
}

return cubeConfiguration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.Map;

import org.arquillian.cube.impl.client.name.NameGenerator;
import org.arquillian.cube.impl.client.name.NameGeneratorFactory;
import org.arquillian.cube.impl.docker.DockerClientExecutor;
import org.arquillian.cube.impl.model.DockerCube;
import org.arquillian.cube.impl.model.DockerCubeRegistry;
Expand All @@ -19,19 +21,26 @@ public class CubeRegistrar {

@SuppressWarnings("unchecked")
public void register(@Observes DockerClientExecutor executor, CubeConfiguration configuration, Injector injector) {
final NameGenerator nameGenerator = NameGeneratorFactory.getGenerator( configuration );

DockerCubeRegistry registry = new DockerCubeRegistry();

//TODO, add key here generation here
Map<String, Object> containerConfigurations = configuration.getDockerContainersContent();


for(Map.Entry<String, Object> containerConfiguration : containerConfigurations.entrySet()) {



registry.addCube(
injector.inject(
new DockerCube(
containerConfiguration.getKey(),
(Map<String, Object>)containerConfiguration.getValue(),
executor)));
executor, nameGenerator)));
}

registryProducer.set(registry);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
*/
package org.arquillian.cube.impl.client.name;


/**
* Interface for generating names
*/
public interface NameGenerator {

/**
* Get the name to use at runtime derived from the name assigned in the file
* @param assignedName
* @return
*/
String getName(final String assignedName);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
*/
package org.arquillian.cube.impl.client.name;


import org.arquillian.cube.impl.client.CubeConfiguration;


/**
* Return the name generator impl based on the configuration
*/
public class NameGeneratorFactory {

/**
* Get the name generator for the configured option
*
* @param cubeConfiguration The cube configuration
*
* @return The NameGenerator instance to use when generating names.
*/
public static NameGenerator getGenerator( final CubeConfiguration cubeConfiguration ) {

final String configurationName = cubeConfiguration.getNameGenerator();

//can't switch on a null
if ( configurationName == null ) {
return new StaticNameGenerator();
}

switch ( configurationName ) {
case StaticNameGenerator.TAG:
return new StaticNameGenerator();
case UniqueNameGenerator.TAG:
return new UniqueNameGenerator( cubeConfiguration.getGetNameGeneratorPrefix() );
default:
throw new IllegalArgumentException(
"The configuration of type '" + configurationName + "' is not a valid configuration. Use '"
+ StaticNameGenerator.TAG + "' or '" + UniqueNameGenerator.TAG + "'." );
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
*/
package org.arquillian.cube.impl.client.name;


/**
* Leaves the name as specified by the user
*/
public class StaticNameGenerator implements NameGenerator {

public static final String TAG = "static";

@Override
public String getName( final String assignedName ) {
return assignedName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*
*/
package org.arquillian.cube.impl.client.name;


import java.util.UUID;



/**
* Generates the name from a prefix, name, and assigns a timeuuid for unique
*/
public class UniqueNameGenerator implements NameGenerator {


public static final String TAG = "unique";

private static final String DELIM = "_";


private String prefix;


public UniqueNameGenerator( final String prefix ) {


if ( prefix == null ) {
throw new IllegalArgumentException(
"You must specify a name generator prefix when using the unique name generator " );
}

this.prefix = prefix;
}


@Override
public String getName( final String assignedName ) {
return prefix + DELIM + assignedName + DELIM + UUID.randomUUID();
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,25 @@ public void pullImage(String imageName) {
}

int tagSeparator = imageName.indexOf(TAG_SEPARATOR);

if (tagSeparator > 0) {
pullImageCmd.withRepository(imageName.substring(0, tagSeparator));
pullImageCmd.withTag(imageName.substring(tagSeparator + 1));
final String repository = imageName.substring(0, tagSeparator);
final String tag = imageName.substring( tagSeparator + 1 );
pullImageCmd.withRepository(repository);
pullImageCmd.withTag(tag);
}

InputStream exec = pullImageCmd.exec();

// To wait until image is pull we need to listen input stream until it is closed by the server
// At this point we can be sure that image is already pulled.
IOUtil.asString(exec);
final String pullResults = IOUtil.asString(exec);

final String expectedOutput = "Status: Downloaded newer image for " + imageName;

if(pullResults == null || !pullResults.contains( expectedOutput )){
throw new RuntimeException( "Unable to pull image. Expected output '" + expectedOutput + "' to be returned. Instead this was returned \n" + pullResults );
}
}

public String execStart(String containerId, String... commands) {
Expand Down
Loading