Skip to content

Commit

Permalink
CHE-58: Refactoring. Introducing new classes for handling Kubernetes …
Browse files Browse the repository at this point in the history
…resources (KubernetesContainer, KubernetesService, KubernetesEnvVar)

Signed-off-by: Ilya Buziuk <ibuziuk@redhat.com>
  • Loading branch information
ibuziuk authored and l0rd committed Jan 27, 2017
1 parent 6e9964c commit 1ec641a
Show file tree
Hide file tree
Showing 20 changed files with 927 additions and 503 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,4 @@ che.openshift.serviceaccountname=cheserviceaccount
# is necessary for deploying Che on OpenShift. Options:
# - 'default' : Use DockerConnector
# - 'openshift' : use OpenShiftConnector
che.docker.connector=openshift
che.docker.connector=default
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' did not match any bound implementation of DockerConnector. Using default.");
LOG.warn("\t Value of 'che.docker.connector': {}", 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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.che.api.machine.server.spi.Instance;
import org.eclipse.che.api.workspace.server.WorkspaceRuntimes;
import org.eclipse.che.plugin.docker.client.DockerConnector;
import org.eclipse.che.plugin.docker.client.DockerConnectorProvider;
import org.eclipse.che.plugin.docker.client.json.ContainerListEntry;
import org.eclipse.che.plugin.docker.client.json.network.ContainerInNetwork;
import org.eclipse.che.plugin.docker.client.json.network.Network;
Expand Down Expand Up @@ -89,6 +90,8 @@ public class DockerAbandonedResourcesCleanerTest {
@Mock
private CheEnvironmentEngine environmentEngine;
@Mock
private DockerConnectorProvider dockerConnectorProvider;
@Mock
private DockerConnector dockerConnector;
@Mock
private DockerContainerNameGenerator nameGenerator;
Expand Down Expand Up @@ -142,8 +145,9 @@ public void setUp() throws Exception {
abandonedNetworkContainers = new HashMap<>();
usedNetworkContainers = new HashMap<>();

when(dockerConnectorProvider.get()).thenReturn(dockerConnector);
cleaner = spy(new DockerAbandonedResourcesCleaner(environmentEngine,
dockerConnector,
dockerConnectorProvider,
nameGenerator,
workspaceRuntimes,
additionalNetworks));
Expand Down Expand Up @@ -340,7 +344,7 @@ public void shouldNotRemoveNetworkIfItInAdditionalNetworksList() throws IOExcept
// given
additionalNetworks.add(userNetworks);
cleaner = spy(new DockerAbandonedResourcesCleaner(environmentEngine,
dockerConnector,
dockerConnectorProvider,
nameGenerator,
workspaceRuntimes,
additionalNetworks));
Expand All @@ -360,7 +364,7 @@ public void shouldNotRemoveNetworkIfItInAdditionalNetworksListAndHasNameAsNetwor
userNetworks = new HashSet<>(Arrays.asList(additionalNetworkName));
additionalNetworks.add(userNetworks);
cleaner = spy(new DockerAbandonedResourcesCleaner(environmentEngine,
dockerConnector,
dockerConnectorProvider,
nameGenerator,
workspaceRuntimes,
additionalNetworks));
Expand Down
24 changes: 2 additions & 22 deletions plugins/plugin-docker/che-plugin-openshift-client/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2016 Red Hat, Inc.
Copyright (c) 2012-2017 Red Hat, Inc.
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 All @@ -16,27 +16,16 @@
<parent>
<artifactId>che-plugin-docker-parent</artifactId>
<groupId>org.eclipse.che.plugin</groupId>
<version>5.0.0-M8</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2012-2017 Red Hat, Inc.
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.openshift.client;

import java.util.Map;
import com.google.common.collect.ImmutableMap;

/**
* Provides mapping between port and Che service name that is using it
*/
public final class CheServicePorts {
private static final Map<Integer, String> CHE_SERVICE_PORTS = ImmutableMap.<Integer, String> builder().
put(22, "sshd").
put(4401, "wsagent").
put(4403, "wsagent-jpda").
put(4411, "terminal").
put(8080, "tomcat").
put(8000, "tomcat-jpda").
put(9876, "codeserver").build();

private CheServicePorts() {
}

public static Map<Integer, String> get() {
return CHE_SERVICE_PORTS;
}
}
Loading

0 comments on commit 1ec641a

Please sign in to comment.