Skip to content

Commit

Permalink
Merge branch 'master' into fix-publishing-of-multiple-projects
Browse files Browse the repository at this point in the history
  • Loading branch information
hpryce authored Feb 13, 2017
2 parents d3bd0b6 + 852bec1 commit de248a8
Show file tree
Hide file tree
Showing 33 changed files with 105 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ public void validateEnvironmentVariables(Map<String, String> dockerEnvironment)
Preconditions.checkState(missingVariables.isEmpty(), errorMessage);
}

private Collection<String> getMissingEnvVariables(Map<String, String> dockerEnvironment) {
private static Collection<String> getMissingEnvVariables(Map<String, String> dockerEnvironment) {
Collection<String> requiredVariables = Sets.union(newHashSet(DOCKER_HOST),
secureVariablesRequired(dockerEnvironment));
return requiredVariables.stream()
.filter(envVariable -> Strings.isNullOrEmpty(dockerEnvironment.get(envVariable)))
.collect(Collectors.toSet());
}

private Set<String> secureVariablesRequired(Map<String, String> dockerEnvironment) {
private static Set<String> secureVariablesRequired(Map<String, String> dockerEnvironment) {
return certVerificationEnabled(dockerEnvironment) ? SECURE_VARIABLES : newHashSet();
}

private boolean certVerificationEnabled(Map<String, String> dockerEnvironment) {
private static boolean certVerificationEnabled(Map<String, String> dockerEnvironment) {
return dockerEnvironment.containsKey(DOCKER_TLS_VERIFY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private Callable<Boolean> weHaveSuccess(Cluster cluster,
};
}

private String serviceDidNotStartupExceptionMessage(
private static String serviceDidNotStartupExceptionMessage(
AtomicReference<Optional<SuccessOrFailure>> lastSuccessOrFailure) {
String healthcheckFailureMessage = lastSuccessOrFailure.get()
.flatMap(SuccessOrFailure::toOptionalFailureMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void shutdown(DockerCompose dockerCompose, Docker docker) throws IOExcept
+ "see https://circleci.com/docs/docker-btrfs-error/ for more info.");
}

private boolean removeContainersCatchingErrors(Docker docker, List<ContainerName> runningContainers) throws IOException, InterruptedException {
private static boolean removeContainersCatchingErrors(Docker docker, List<ContainerName> runningContainers) throws IOException, InterruptedException {
try {
removeContainers(docker, runningContainers);
return true;
Expand All @@ -48,7 +48,7 @@ private boolean removeContainersCatchingErrors(Docker docker, List<ContainerName
}
}

private void removeContainers(Docker docker, List<ContainerName> running) throws IOException, InterruptedException {
private static void removeContainers(Docker docker, List<ContainerName> running) throws IOException, InterruptedException {
List<String> rawContainerNames = running.stream()
.map(ContainerName::rawName)
.collect(toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public void shutdown(DockerCompose dockerCompose, Docker docker) throws IOExcept
removeNetworks(dockerCompose);
}

private void removeContainersCatchingErrors(Docker docker, List<ContainerName> runningContainers) throws IOException, InterruptedException {
private static void removeContainersCatchingErrors(Docker docker, List<ContainerName> runningContainers) throws IOException, InterruptedException {
try {
removeContainers(docker, runningContainers);
} catch (DockerExecutionException exception) {
log.error("Error while trying to remove containers: {}", exception.getMessage());
}
}

private void removeContainers(Docker docker, List<ContainerName> running) throws IOException, InterruptedException {
private static void removeContainers(Docker docker, List<ContainerName> running) throws IOException, InterruptedException {
List<String> rawContainerNames = running.stream()
.map(ContainerName::rawName)
.collect(toList());
Expand All @@ -46,7 +46,7 @@ private void removeContainers(Docker docker, List<ContainerName> running) throws
log.debug("Finished shutdown");
}

private void removeNetworks(DockerCompose dockerCompose) throws IOException, InterruptedException {
private static void removeNetworks(DockerCompose dockerCompose) throws IOException, InterruptedException {
dockerCompose.down();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ private String processOutputFrom(Process process) {
.collect(joining(System.lineSeparator()));
}

private String waitForResultFrom(Future<String> outputProcessing) {
private static String waitForResultFrom(Future<String> outputProcessing) {
try {
return outputProcessing.get(HOURS_TO_WAIT_FOR_STD_OUT_TO_CLOSE, TimeUnit.HOURS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw propagate(e);
}
}

private BufferedReader asReader(InputStream inputStream) {
private static BufferedReader asReader(InputStream inputStream) {
return new BufferedReader(new InputStreamReader(inputStream, UTF_8));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private Version version() throws IOException, InterruptedException {
return DockerComposeVersion.parseFromDockerComposeVersion(versionOutput);
}

private String[] constructFullDockerComposeExecArguments(DockerComposeExecOption dockerComposeExecOption,
private static String[] constructFullDockerComposeExecArguments(DockerComposeExecOption dockerComposeExecOption,
String containerName, DockerComposeExecArgument dockerComposeExecArgument) {
ImmutableList<String> fullArgs = new ImmutableList.Builder<String>().add("exec")
.addAll(dockerComposeExecOption.options())
Expand All @@ -143,7 +143,7 @@ private String[] constructFullDockerComposeExecArguments(DockerComposeExecOption
return fullArgs.toArray(new String[fullArgs.size()]);
}

private String[] constructFullDockerComposeRunArguments(DockerComposeRunOption dockerComposeRunOption,
private static String[] constructFullDockerComposeRunArguments(DockerComposeRunOption dockerComposeRunOption,
String containerName, DockerComposeRunArgument dockerComposeRunArgument) {
ImmutableList<String> fullArgs = new ImmutableList.Builder<String>().add("run")
.addAll(dockerComposeRunOption.options())
Expand Down Expand Up @@ -204,7 +204,7 @@ public State state(String service) throws IOException, InterruptedException {
return State.parseFromDockerComposePs(psOutput(service));
}

private ErrorHandler swallowingDownCommandDoesNotExist() {
private static ErrorHandler swallowingDownCommandDoesNotExist() {
return (exitCode, output, commandName, commands) -> {
if (downCommandWasPresent(output)) {
Command.throwingOnError().handle(exitCode, output, commandName, commands);
Expand All @@ -216,7 +216,7 @@ private ErrorHandler swallowingDownCommandDoesNotExist() {
};
}

private boolean downCommandWasPresent(String output) {
private static boolean downCommandWasPresent(String output) {
return !output.contains("No such command");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package com.palantir.docker.compose.execution;

import com.palantir.docker.compose.configuration.ShutdownStrategy;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -14,7 +13,7 @@ public class SkipShutdownStrategy implements ShutdownStrategy {
private static final Logger log = LoggerFactory.getLogger(SkipShutdownStrategy.class);

@Override
public void shutdown(DockerCompose dockerCompose, Docker docker) throws IOException, InterruptedException {
public void shutdown(DockerCompose dockerCompose, Docker docker) {
log.warn("\n"
+ "******************************************************************************************\n"
+ "* docker-compose-rule has been configured to skip docker-compose shutdown: *\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
package com.palantir.docker.compose.logging;

import com.palantir.docker.compose.execution.DockerCompose;
import java.io.IOException;

public class DoNothingLogCollector implements LogCollector {

@Override
public void startCollecting(DockerCompose dockerCompose) throws IOException, InterruptedException {
public void startCollecting(DockerCompose dockerCompose) {

}

@Override
public void stopCollecting() throws InterruptedException {
public void stopCollecting() {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AdditionalEnvironmentValidatorShould {
public ExpectedException exception = ExpectedException.none();

@Test
public void throw_exception_when_additional_environment_variables_contain_docker_variables() throws Exception {
public void throw_exception_when_additional_environment_variables_contain_docker_variables() {
Map<String, String> variables = ImmutableMap.<String, String>builder().put("DOCKER_HOST", "tcp://some-host:2376")
.put("SOME_VARIABLE", "Some Value")
.build();
Expand All @@ -42,7 +42,7 @@ public void throw_exception_when_additional_environment_variables_contain_docker
}

@Test
public void validate_arbitrary_environment_variables() throws Exception {
public void validate_arbitrary_environment_variables() {
Map<String, String> variables = ImmutableMap.<String, String>builder().put("SOME_VARIABLE", "Some Value")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DaemonEnvironmentValidatorShould {
public ExpectedException exception = ExpectedException.none();

@Test
public void validate_successfully_when_docker_environment_does_not_contain_docker_variables() throws Exception {
public void validate_successfully_when_docker_environment_does_not_contain_docker_variables() {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put("SOME_VARIABLE", "SOME_VALUE")
.put("ANOTHER_VARIABLE", "ANOTHER_VALUE")
Expand All @@ -41,7 +41,7 @@ public void validate_successfully_when_docker_environment_does_not_contain_docke
}

@Test
public void throw_exception_when_docker_environment_contains_illegal_docker_variables() throws Exception {
public void throw_exception_when_docker_environment_contains_illegal_docker_variables() {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put(DOCKER_HOST, "tcp://192.168.99.100:2376")
.put(DOCKER_TLS_VERIFY, "1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
public class DaemonHostIpResolverShould {

@Test
public void return_local_host_with_null() throws Exception {
public void return_local_host_with_null() {
assertThat(new DaemonHostIpResolver().resolveIp(null), is(LOCALHOST));
}

@Test
public void return_local_host_with_blank() throws Exception {
public void return_local_host_with_blank() {
assertThat(new DaemonHostIpResolver().resolveIp(""), is(LOCALHOST));
}

@Test
public void return_local_host_with_arbitrary() throws Exception {
public void return_local_host_with_arbitrary() {
assertThat(new DaemonHostIpResolver().resolveIp("arbitrary"), is(LOCALHOST));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public class DockerComposeFilesShould {
public final ExpectedException exception = ExpectedException.none();

@Test
public void throw_exception_when_compose_file_is_not_specified() throws Exception {
public void throw_exception_when_compose_file_is_not_specified() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("A docker compose file must be specified.");
DockerComposeFiles.from();
}

@Test
public void throw_exception_when_compose_file_does_not_exist() throws Exception {
public void throw_exception_when_compose_file_does_not_exist() {
exception.expect(IllegalStateException.class);
exception.expectMessage("The following docker-compose files:");
exception.expectMessage("does-not-exist.yaml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void ports(String service, String ip, Integer... portNumbers) throws IOEx
when(dockerComposeProcess.ports(service)).thenReturn(new Ports(ports));
}

private DockerPort dockerPortSpy(String ip, int externalPortNumber, int internalPortNumber) {
private static DockerPort dockerPortSpy(String ip, int externalPortNumber, int internalPortNumber) {
DockerPort port = new DockerPort(ip, externalPortNumber, internalPortNumber);
return spy(port);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RemoteEnvironmentValidatorShould {
public ExpectedException exception = ExpectedException.none();

@Test
public void throw_exception_if_docker_host_is_not_set() throws Exception {
public void throw_exception_if_docker_host_is_not_set() {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put("SOME_VARIABLE", "SOME_VALUE")
.build();
Expand All @@ -43,7 +43,7 @@ public void throw_exception_if_docker_host_is_not_set() throws Exception {
}

@Test
public void throw_exception_if_docker_cert_path_is_missing_and_tls_is_on() throws Exception {
public void throw_exception_if_docker_cert_path_is_missing_and_tls_is_on() {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put(DOCKER_HOST, "tcp://192.168.99.100:2376")
.put(DOCKER_TLS_VERIFY, "1")
Expand All @@ -56,7 +56,7 @@ public void throw_exception_if_docker_cert_path_is_missing_and_tls_is_on() throw
}

@Test
public void validate_environment_with_all_valid_variables_set_without_tls() throws Exception {
public void validate_environment_with_all_valid_variables_set_without_tls() {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put(DOCKER_HOST, "tcp://192.168.99.100:2376")
.put("SOME_VARIABLE", "SOME_VALUE")
Expand All @@ -66,7 +66,7 @@ public void validate_environment_with_all_valid_variables_set_without_tls() thro
}

@Test
public void validate_environment_with_all_valid_variables_set_with_tls() throws Exception {
public void validate_environment_with_all_valid_variables_set_with_tls() {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put(DOCKER_HOST, "tcp://192.168.99.100:2376")
.put(DOCKER_TLS_VERIFY, "1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ public class RemoteHostIpResolverShould {
public ExpectedException exception = ExpectedException.none();

@Test
public void result_in_error_blank_when_resolving_invalid_docker_host() throws Exception {
public void result_in_error_blank_when_resolving_invalid_docker_host() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("DOCKER_HOST cannot be blank/null");
new RemoteHostIpResolver().resolveIp("");
}

@Test
public void result_in_error_null_when_resolving_invalid_docker_host() throws Exception {
public void result_in_error_null_when_resolving_invalid_docker_host() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("DOCKER_HOST cannot be blank/null");
new RemoteHostIpResolver().resolveIp(null);
}

@Test
public void resolve_docker_host_with_port() throws Exception {
public void resolve_docker_host_with_port() {
String dockerHost = String.format("%s%s:%d", TCP_PROTOCOL, IP, PORT);
assertThat(new RemoteHostIpResolver().resolveIp(dockerHost), Matchers.is(IP));
}

@Test
public void resolve_docker_host_without_port() throws Exception {
public void resolve_docker_host_without_port() {
String dockerHost = String.format("%s%s", TCP_PROTOCOL, IP);
assertThat(new RemoteHostIpResolver().resolveIp(dockerHost), Matchers.is(IP));
}
Expand Down
Loading

0 comments on commit de248a8

Please sign in to comment.