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

CHE-26: Initial OpenShift integration #3798

Merged
merged 3 commits into from
Jan 27, 2017
Merged
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
4 changes: 4 additions & 0 deletions assembly/assembly-ide-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-nodejs-lang-shared</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-openshift-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-orion-compare</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions assembly/assembly-wsmaster-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-machine-ext-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-openshift-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-ssh-machine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,25 @@ org.everrest.asynchronous.cache.size=1024
# Path to asynchronous service
org.everrest.asynchronous.service.path=/async/


# DB initialization and migration configuration
db.schema.flyway.baseline.enabled=true
db.schema.flyway.baseline.version=5.0.0.8.1
db.schema.flyway.scripts.prefix=
db.schema.flyway.scripts.suffix=.sql
db.schema.flyway.scripts.version_separator=__
db.schema.flyway.scripts.locations=classpath:che-schema

db.jndi.datasource.name=java:/comp/env/jdbc/che

# OpenShift related properties
che.openshift.endpoint=https://192.168.64.2:8443/
che.openshift.username=openshift-dev
che.openshift.password=devel
che.openshift.project=eclipse-che
che.openshift.serviceaccountname=cheserviceaccount

# Which implementation of DockerConnector to use in managing containers. In general,
# the base implementation of DockerConnector is appropriate, but OpenShiftConnector
# is necessary for deploying Che on OpenShift. Options:
# - 'default' : Use DockerConnector
# - 'openshift' : use OpenShiftConnector
che.docker.connector=default
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ public class CgroupOOMDetector implements DockerOOMDetector {
private final ExecutorService executor;

@Inject
public CgroupOOMDetector(DockerConnectorConfiguration connectorConfiguration, DockerConnector dockerConnector) {
this(connectorConfiguration.getDockerDaemonUri(), dockerConnector);
public CgroupOOMDetector(DockerConnectorConfiguration connectorConfiguration,
DockerConnectorProvider dockerProvider) {
this(connectorConfiguration.getDockerDaemonUri(), dockerProvider);
}

public CgroupOOMDetector(URI dockerDaemonUri, DockerConnector dockerConnector) {
public CgroupOOMDetector(URI dockerDaemonUri, DockerConnectorProvider dockerConnectorProvider) {
this.dockerDaemonUri = dockerDaemonUri;
this.dockerConnector = dockerConnector;
this.dockerConnector = dockerConnectorProvider.get();
this.oomDetectors = new ConcurrentHashMap<>();
this.executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("CgroupOOMDetector-%d")
.setUncaughtExceptionHandler(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.plugin.docker.client;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.name.Named;

@Singleton
public class DockerConnectorProvider implements Provider<DockerConnector> {

private static final Logger LOG = LoggerFactory.getLogger(DockerConnectorProvider.class);
private DockerConnector connector;

@Inject
public DockerConnectorProvider(Map<String, DockerConnector> connectors,
@Named("che.docker.connector") String property) {
if (connectors.containsKey(property)) {
this.connector = connectors.get(property);
} else {
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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you prefer setting default implementation here instead of che.properties?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garagatyi oh, the property was just named wrongly the logs :/ . The default implementation is set in che.properties - https://github.com/eclipse/che/pull/3798/files#diff-5bbadd86c05d20f13241983c27be08b2R283
However, if it does not match any supported values (openshift / default) default DockerConnector implementation is used

}
}

@Override
public DockerConnector get() {
return connector;
}
}
4 changes: 4 additions & 0 deletions plugins/plugin-docker/che-plugin-docker-machine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-docker-client</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.plugin</groupId>
<artifactId>che-plugin-openshift-client</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.commons.lang.NameGenerator;
import org.eclipse.che.plugin.docker.client.DockerConnector;
import org.eclipse.che.plugin.docker.client.DockerConnectorProvider;
import org.eclipse.che.plugin.docker.client.Exec;
import org.eclipse.che.plugin.docker.client.LogMessage;
import org.eclipse.che.plugin.docker.client.ProgressLineFormatterImpl;
Expand Down Expand Up @@ -104,7 +105,7 @@ public class DockerInstance extends AbstractInstance {
private final MachineRuntimeInfoImpl machineRuntime;

@Inject
public DockerInstance(DockerConnector docker,
public DockerInstance(DockerConnectorProvider dockerProvider,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need guice Providers vs named connector ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I got the comment :( We do need to inject provider because now it is in charge of providing suitable connector (DockerConnector / OpenShiftConnector) based on che.docker_connector.provider property

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benoitf BTW, similar approach is used for obtaining ServerEvaluationStrategy (default / docker-local) - https://github.com/eclipse/che/blob/master/plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/local/LocalDockerModule.java#L52
And I think it is relevant to also use MapBinder for DockerConnector use-case (default / openshift)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibuziuk I agree

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Florent that it would look prettier if we get rid of injecting provider. There is always a way to reduce distraction. But up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garagatyi For initial implementation I would rather leave it this way. The usage of DockerConnectorProvider will be changed once OpenShiftConnector is decoupled from DockerConnector and there will be a good time for rethinking the whole approach

@Named("che.docker.registry") String registry,
@Named("che.docker.namespace") @Nullable String registryNamespace,
DockerMachineFactory dockerMachineFactory,
Expand All @@ -119,7 +120,7 @@ public DockerInstance(DockerConnector docker,
super(machine);
this.dockerMachineFactory = dockerMachineFactory;
this.container = container;
this.docker = docker;
this.docker = dockerProvider.get();
this.image = image;
this.outputConsumer = outputConsumer;
this.registry = registry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.che.api.machine.server.spi.InstanceProvider;
import org.eclipse.che.commons.lang.IoUtil;
import org.eclipse.che.plugin.docker.client.DockerConnector;
import org.eclipse.che.plugin.docker.client.DockerConnectorProvider;
import org.eclipse.che.plugin.docker.client.params.RemoveImageParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -73,9 +74,9 @@ public class DockerInstanceProvider implements InstanceProvider {
private final boolean snapshotUseRegistry;

@Inject
public DockerInstanceProvider(DockerConnector docker,
public DockerInstanceProvider(DockerConnectorProvider dockerProvider,
@Named("che.docker.registry_for_snapshots") boolean snapshotUseRegistry) throws IOException {
this.docker = docker;
this.docker = dockerProvider.get();
this.snapshotUseRegistry = snapshotUseRegistry;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.che.api.machine.server.event.InstanceStateEvent;
import org.eclipse.che.commons.lang.Pair;
import org.eclipse.che.plugin.docker.client.DockerConnector;
import org.eclipse.che.plugin.docker.client.DockerConnectorProvider;
import org.eclipse.che.plugin.docker.client.MessageProcessor;
import org.eclipse.che.plugin.docker.client.json.Event;
import org.eclipse.che.plugin.docker.client.json.Filters;
Expand Down Expand Up @@ -66,9 +67,9 @@ public class DockerInstanceStopDetector {
private long lastProcessedEventDate = 0;

@Inject
public DockerInstanceStopDetector(EventService eventService, DockerConnector dockerConnector) {
public DockerInstanceStopDetector(EventService eventService, DockerConnectorProvider dockerConnectorProvider) {
this.eventService = eventService;
this.dockerConnector = dockerConnector;
this.dockerConnector = dockerConnectorProvider.get();
this.instances = new ConcurrentHashMap<>();
this.containersOomTimestamps = CacheBuilder.newBuilder()
.expireAfterWrite(10, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.che.api.machine.server.spi.impl.AbstractMachineProcess;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.plugin.docker.client.DockerConnector;
import org.eclipse.che.plugin.docker.client.DockerConnectorProvider;
import org.eclipse.che.plugin.docker.client.Exec;
import org.eclipse.che.plugin.docker.client.LogMessage;
import org.eclipse.che.plugin.docker.client.MessageProcessor;
Expand Down Expand Up @@ -53,14 +54,14 @@ public class DockerProcess extends AbstractMachineProcess implements InstancePro
private volatile boolean started;

@Inject
public DockerProcess(DockerConnector docker,
public DockerProcess(DockerConnectorProvider dockerProvider,
@Assisted Command command,
@Assisted("container") String container,
@Nullable @Assisted("outputChannel") String outputChannel,
@Assisted("pid_file_path") String pidFilePath,
@Assisted int pid) {
super(command, pid, outputChannel);
this.docker = docker;
this.docker = dockerProvider.get();
this.container = container;
this.commandLine = command.getCommandLine();
this.shellInvoker = firstNonNull(command.getAttributes().get("shell"), "/bin/sh");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;
import com.google.common.util.concurrent.ThreadFactoryBuilder;

import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.ServerException;
import org.eclipse.che.api.core.model.machine.MachineStatus;
Expand All @@ -36,6 +35,7 @@
import org.eclipse.che.commons.lang.concurrent.LoggingUncaughtExceptionHandler;
import org.eclipse.che.commons.lang.os.WindowsPathEscaper;
import org.eclipse.che.plugin.docker.client.DockerConnector;
import org.eclipse.che.plugin.docker.client.DockerConnectorProvider;
import org.eclipse.che.plugin.docker.client.ProgressLineFormatterImpl;
import org.eclipse.che.plugin.docker.client.ProgressMonitor;
import org.eclipse.che.plugin.docker.client.UserSpecificDockerRegistryCredentialsProvider;
Expand Down Expand Up @@ -131,7 +131,7 @@ public class MachineProviderImpl implements MachineInstanceProvider {
private final WindowsPathEscaper windowsPathEscaper;

@Inject
public MachineProviderImpl(DockerConnector docker,
public MachineProviderImpl(DockerConnectorProvider dockerProvider,
UserSpecificDockerRegistryCredentialsProvider dockerCredentials,
DockerMachineFactory dockerMachineFactory,
DockerInstanceStopDetector dockerInstanceStopDetector,
Expand All @@ -155,7 +155,7 @@ public MachineProviderImpl(DockerConnector docker,
WindowsPathEscaper windowsPathEscaper,
@Named("che.docker.extra_hosts") Set<Set<String>> additionalHosts)
throws IOException {
this.docker = docker;
this.docker = dockerProvider.get();
this.dockerCredentials = dockerCredentials;
this.dockerMachineFactory = dockerMachineFactory;
this.dockerInstanceStopDetector = dockerInstanceStopDetector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.che.api.workspace.server.WorkspaceRuntimes;
import org.eclipse.che.commons.schedule.ScheduleRate;
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.Filters;
import org.eclipse.che.plugin.docker.client.json.network.Network;
Expand Down Expand Up @@ -69,12 +70,12 @@ public class DockerAbandonedResourcesCleaner implements Runnable {

@Inject
public DockerAbandonedResourcesCleaner(CheEnvironmentEngine environmentEngine,
DockerConnector dockerConnector,
DockerConnectorProvider dockerConnectorProvider,
DockerContainerNameGenerator nameGenerator,
WorkspaceRuntimes workspaceRuntimes,
@Named("machine.docker.networks") Set<Set<String>> additionalNetworks) {
this.environmentEngine = environmentEngine;
this.dockerConnector = dockerConnector;
this.dockerConnector = dockerConnectorProvider.get();
this.nameGenerator = nameGenerator;
this.runtimes = workspaceRuntimes;
this.additionalNetworks = additionalNetworks.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import org.eclipse.che.api.environment.server.MachineService;
import org.eclipse.che.api.machine.server.spi.Instance;
import org.eclipse.che.api.machine.server.spi.InstanceProcess;
import org.eclipse.che.plugin.docker.client.DockerConnector;
import org.eclipse.che.plugin.docker.machine.DockerInstance;
import org.eclipse.che.plugin.docker.machine.DockerInstanceRuntimeInfo;
import org.eclipse.che.plugin.docker.machine.DockerProcess;
import org.eclipse.che.plugin.docker.machine.ServerEvaluationStrategy;
import org.eclipse.che.plugin.docker.machine.node.DockerNode;
import org.eclipse.che.plugin.openshift.client.OpenShiftConnector;

import java.util.Set;

Expand Down Expand Up @@ -64,6 +66,10 @@ protected void configure() {
.to(org.eclipse.che.plugin.docker.client.NoOpDockerRegistryDynamicAuthResolverImpl.class);
bind(org.eclipse.che.plugin.docker.client.DockerRegistryChecker.class).asEagerSingleton();

MapBinder<String, DockerConnector> dockerConnectors = MapBinder.newMapBinder(binder(), String.class, DockerConnector.class);
dockerConnectors.addBinding("default").to(DockerConnector.class);
dockerConnectors.addBinding("openshift").to(OpenShiftConnector.class);

Multibinder<String> devMachineEnvVars = Multibinder.newSetBinder(binder(),
String.class,
Names.named("machine.docker.dev_machine.machine_env"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.che.api.machine.server.model.impl.MachineImpl;
import org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl;
import org.eclipse.che.plugin.docker.client.DockerConnector;
import org.eclipse.che.plugin.docker.client.DockerConnectorProvider;
import org.eclipse.che.plugin.docker.client.Exec;
import org.eclipse.che.plugin.docker.client.LogMessage;
import org.eclipse.che.plugin.docker.client.MessageProcessor;
Expand Down Expand Up @@ -78,6 +79,8 @@ public class DockerInstanceTest {
@Mock
private DockerConnector dockerConnectorMock;
@Mock
private DockerConnectorProvider dockerConnectorProviderMock;
@Mock
private DockerInstanceStopDetector dockerInstanceStopDetectorMock;
@Mock
private LineConsumer outputConsumer;
Expand All @@ -86,6 +89,7 @@ public class DockerInstanceTest {

@BeforeMethod
public void setUp() throws IOException, MachineException {
when(dockerConnectorProviderMock.get()).thenReturn(dockerConnectorMock);
dockerInstance = getDockerInstance();
when(dockerConnectorMock.createExec(any(CreateExecParams.class))).thenReturn(execMock);
when(execMock.getId()).thenReturn(EXEC_ID);
Expand Down Expand Up @@ -209,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 @@ -24,6 +24,7 @@
import org.eclipse.che.commons.subject.SubjectImpl;
import org.eclipse.che.plugin.docker.client.DockerConnector;
import org.eclipse.che.plugin.docker.client.DockerConnectorConfiguration;
import org.eclipse.che.plugin.docker.client.DockerConnectorProvider;
import org.eclipse.che.plugin.docker.client.ProgressMonitor;
import org.eclipse.che.plugin.docker.client.UserSpecificDockerRegistryCredentialsProvider;
import org.eclipse.che.plugin.docker.client.json.ContainerConfig;
Expand All @@ -50,6 +51,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -119,6 +121,18 @@ public class MachineProviderImplTest {

private MachineProviderImpl provider;

private class MockConnectorProvider extends DockerConnectorProvider {

public MockConnectorProvider() {
super(Collections.emptyMap(), "default");
}

@Override
public DockerConnector get() {
return dockerConnector;
}
}

@BeforeMethod
public void setUp() throws Exception {
when(dockerConnectorConfiguration.getDockerHostIp()).thenReturn("123.123.123.123");
Expand Down Expand Up @@ -1309,7 +1323,7 @@ public MachineProviderBuilder setCpuQuota(long cpuQuota) {
}

MachineProviderImpl build() throws IOException {
return new MachineProviderImpl(dockerConnector,
return new MachineProviderImpl(new MockConnectorProvider(),
credentialsReader,
dockerMachineFactory,
dockerInstanceStopDetector,
Expand Down
Loading