Skip to content

Commit

Permalink
CHE-26: Cleanup after rebase - setting correct che-plugin-openshift-c…
Browse files Browse the repository at this point in the history
…lient version, fixing io.fabric8 dependency management, copyright license year and tests

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
  • Loading branch information
ibuziuk committed Jan 20, 2017
1 parent 067db0d commit 0275d07
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* Copyright (c) 2012-2017 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -32,10 +32,9 @@ public DockerConnectorProvider(Map<String, DockerConnector> connectors,
if (connectors.containsKey(property)) {
this.connector = connectors.get(property);
} else {
LOG.warn("Property 'che.docker_connector.provider' did not match any bound "
+ "implementation of DockerConnector. Using default.");
LOG.warn("\t Value of che.docker_connector.provider: " + property);
LOG.warn("\t Bound implementations: " + connectors.toString());
LOG.warn("Property 'che.docker_connector.provider' did not match any bound implementation of DockerConnector. Using default.");
LOG.warn("\t Value of che.docker_connector.provider: {}", property);
LOG.warn("\t Bound implementations: {}", connectors.toString());
this.connector = connectors.get("default");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public DockerAbandonedResourcesCleaner(CheEnvironmentEngine environmentEngine,
this.environmentEngine = environmentEngine;
this.dockerConnector = dockerConnectorProvider.get();
this.nameGenerator = nameGenerator;
this.runtimes = workspaceRuntimes;
this.runtimes = workspaceRuntimes;
this.additionalNetworks = additionalNetworks.stream()
.flatMap(Set::stream)
.collect(toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private DockerInstance getDockerInstance(Machine machine,
boolean snapshotUseRegistry) throws MachineException {
DockerMachineFactory machineFactory = mock(DockerMachineFactory.class);
when(machineFactory.createMetadata(any(), any(), any())).thenReturn(mock(DockerInstanceRuntimeInfo.class));
return new DockerInstance(dockerConnectorMock,
return new DockerInstance(dockerConnectorProviderMock,
registry,
USERNAME,
machineFactory,
Expand Down
22 changes: 1 addition & 21 deletions plugins/plugin-docker/che-plugin-openshift-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,16 @@
<parent>
<artifactId>che-plugin-docker-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>5.0.0</version>
<version>5.2.0-SNAPSHOT</version>
</parent>
<artifactId>che-plugin-openshift-client</artifactId>
<packaging>jar</packaging>
<name>Che Plugin :: Docker :: OpenShift Client</name>
<properties>
<findbugs.failonerror>false</findbugs.failonerror>
<io.fabric8.openshift-client.version>1.4.31</io.fabric8.openshift-client.version>
<license_contributor>Red Hat, Inc. - initial API and implementation</license_contributor>
<license_copyrightOwner>Red Hat, Inc.</license_copyrightOwner>
<license_header>license-header.txt</license_header>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<version>${io.fabric8.openshift-client.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
Expand All @@ -49,12 +38,10 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>1.4.31</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model</artifactId>
<version>1.0.65</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
Expand Down Expand Up @@ -103,11 +90,4 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
</resource>
</resources>
</build>
</project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,27 @@
import java.util.List;
import java.util.Set;

import org.eclipse.che.plugin.docker.client.json.ContainerConfig;
import org.eclipse.che.plugin.docker.client.json.ImageConfig;
import org.eclipse.che.plugin.openshift.client.CheServicePorts;

import io.fabric8.kubernetes.api.model.ContainerPort;
import io.fabric8.kubernetes.api.model.ContainerPortBuilder;

/**
* Provides API for managing Kubernetes {@link ContainerPort}
*/
public class KubernetesContainer {

/**
* Retrieves list of ({@link ContainerPort} based on ports defined in
* {@link ContainerConfig} and {@link ImageConfig}
*
* @param exposedPorts
* @return list of {@link ContainerPort}
*/
public List<ContainerPort> getContainerPortsFrom(Set<String> exposedPorts) {
List<ContainerPort> containerPorts = new ArrayList<>();
List<ContainerPort> containerPorts = new ArrayList<>(exposedPorts.size());
for (String exposedPort : exposedPorts) {
String[] portAndProtocol = exposedPort.split("/", 2);
String port = portAndProtocol[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,26 @@
import java.util.ArrayList;
import java.util.List;

import org.eclipse.che.plugin.docker.client.json.ContainerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.fabric8.kubernetes.api.model.EnvVar;
import io.fabric8.kubernetes.api.model.EnvVarBuilder;

/**
* Provides API for managing Kubernetes {@link EnvVar}
*/
public class KubernetesEnvVar {
private static final Logger LOG = LoggerFactory.getLogger(KubernetesEnvVar.class);

/**
* Retrieves list of {@link EnvVar} based on environment variables specified
* in {@link ContainerConfig}
*
* @param envVariables
* @return list of {@link EnvVar}
*/
public List<EnvVar> getEnvFrom(String[] envVariables) {
LOG.info("Container environment variables:");
List<EnvVar> env = new ArrayList<>();
Expand All @@ -31,7 +42,7 @@ public List<EnvVar> getEnvFrom(String[] envVariables) {
String varValue = nameAndValue[1];
EnvVar envVar = new EnvVarBuilder().withName(varName).withValue(varValue).build();
env.add(envVar);
LOG.info("- " + varName + "=" + varValue);
LOG.info("- {}={}",varName, varValue);
}
return env;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.che.plugin.docker.client.json.ContainerConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Converter of labels defined in {@link ContainerConfig} for matching to Kubernetes
* annotation requirements
*/
public class KubernetesLabelConverter {
private static final Logger LOG = LoggerFactory.getLogger(KubernetesLabelConverter.class);
/** Prefix used for che server labels */
Expand Down Expand Up @@ -64,11 +69,10 @@ public Map<String, String> labelsToNames(Map<String, String> labels) {
}
// Check for potential problems with conversion
if (!key.startsWith(CHE_SERVER_LABEL_PREFIX)) {
LOG.warn("Expected CreateContainerParams label key " + entry.getKey() +
" to start with " + CHE_SERVER_LABEL_PREFIX);
LOG.warn("Expected CreateContainerParams label key {} to start with {}", key, CHE_SERVER_LABEL_PREFIX);
} else if (key.contains(".") || key.contains("_") || value.contains("_")) {
LOG.error(String.format("Cannot convert label %s to DNS Name: "
+ "'-' and '.' are used as escape characters", entry.toString()));
LOG.error("Cannot convert label {} to DNS Name: '-' and '.' are used as escape characters",
entry.toString());
continue;
}

Expand All @@ -82,8 +86,9 @@ public Map<String, String> labelsToNames(Map<String, String> labels) {
value = String.format(CHE_SERVER_LABEL_PADDING, value);

if (!key.matches(KUBERNETES_ANNOTATION_REGEX) || !value.matches(KUBERNETES_ANNOTATION_REGEX)) {
LOG.error(String.format("Could not convert label %s into Kubernetes annotation: "
+ "labels must be alphanumeric with ':' and '/'", entry.toString()));
LOG.error(
"Could not convert label {} into Kubernetes annotation: labels must be alphanumeric with ':' and '/'",
entry.toString());
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,27 @@
import java.util.List;
import java.util.Set;

import org.eclipse.che.plugin.docker.client.json.ContainerConfig;
import org.eclipse.che.plugin.docker.client.json.ImageConfig;
import org.eclipse.che.plugin.openshift.client.CheServicePorts;

import io.fabric8.kubernetes.api.model.IntOrString;
import io.fabric8.kubernetes.api.model.ServicePort;

/**
* Provides API for managing Kubernetes {@link ServicePort}
*/
public class KubernetesService {

/**
* Retrieves list of {@link ServicePort} based on ports defined in
* {@link ContainerConfig} and {@link ImageConfig}
*
* @param exposedPorts
* @return list of {@link ServicePort}
*/
public List<ServicePort> getServicePortsFrom(Set<String> exposedPorts) {
List<ServicePort> servicePorts = new ArrayList<>();
List<ServicePort> servicePorts = new ArrayList<>(exposedPorts.size());
for (String exposedPort : exposedPorts) {
String[] portAndProtocol = exposedPort.split("/", 2);
String port = portAndProtocol[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import org.eclipse.che.plugin.docker.client.connection.DockerConnectionFactory;
import org.eclipse.che.plugin.docker.client.json.ContainerConfig;
import org.eclipse.che.plugin.docker.client.params.CreateContainerParams;
import org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesContainer;
import org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesEnvVar;
import org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesLabelConverter;
import org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesService;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeClass;
Expand All @@ -46,17 +50,28 @@ public class OpenShiftConnectorTest {
private DockerRegistryAuthResolver authManager;
@Mock
private DockerApiVersionPathPrefixProvider dockerApiVersionPathPrefixProvider;

@Mock
private CreateContainerParams createContainerParams;
private CreateContainerParams createContainerParams;
@Mock
private KubernetesLabelConverter kubernetesLabelConverter;
@Mock
private KubernetesEnvVar kubernetesEnvVar;
@Mock
private KubernetesContainer kubernetesContainer;
@Mock
private KubernetesService kubernetesService;

private OpenShiftConnector openShiftConnector;
private OpenShiftConnector openShiftConnector;

@BeforeClass
public void setup() {
openShiftConnector = spy(new OpenShiftConnector(dockerConnectorConfiguration,
dockerConnectionFactory,
authManager,
kubernetesLabelConverter,
kubernetesEnvVar,
kubernetesContainer,
kubernetesService,
dockerApiVersionPathPrefixProvider,
OPENSHIFT_API_ENDPOINT_MINISHIFT,
OPENSHIFT_DEFAULT_USER_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ public void setUp() throws Exception {
keysInjector = new KeysInjector(eventService,
new MockConnectorProvider(),
sshManager,
environmentEngine,
userManager);
environmentEngine);

keysInjector.start();
verify(eventService).subscribe(subscriberCaptor.capture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,23 @@
</rules>
</configuration>
</execution>
<execution>
<id>distribution-management-used</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireDepMgt>
<message>You are trying to use artifacts that are not in the list of allowed artifacts included in dependencyManagement in maven-depmgt-pom or have different version.</message>
<checkVersion>true</checkVersion>
<ignoreScopes>
<ignoreScope>runtime</ignoreScope>
</ignoreScopes>
</requireDepMgt>
</rules>
</configuration>
</execution>
<execution>
<id>no-distribution-management-at-all</id>
<goals>
Expand Down

0 comments on commit 0275d07

Please sign in to comment.