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-5871: refactor DockerMachineStarter #5931

Merged
merged 1 commit into from
Aug 9, 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
1 change: 0 additions & 1 deletion assembly/assembly-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<packaging>pom</packaging>
<name>Che IDE :: Assemblies Tomcat</name>
<dependencies>
<!-- FIXME: spi -->
<dependency>
<groupId>org.eclipse.che</groupId>
<artifactId>assembly-ide-war</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,6 @@ protected void configure() {
bind(org.eclipse.che.security.oauth.OAuthAuthenticationService.class);

bind(org.eclipse.che.api.core.notification.WSocketEventBusServer.class);
// additional ports for development of extensions
// FIXME: spi
// Multibinder<org.eclipse.che.api.core.model.machine.ServerConf> machineServers
// = Multibinder.newSetBinder(binder(),
// org.eclipse.che.api.core.model.machine.ServerConf.class,
// Names.named("machine.docker.dev_machine.machine_servers"));
// machineServers.addBinding().toInstance(
// new org.eclipse.che.api.machine.server.model.impl.ServerConfImpl(Constants.WSAGENT_DEBUG_REFERENCE, "4403/tcp", "http",
// null));

// bind(org.eclipse.che.api.agent.server.WsAgentHealthChecker.class)
// .to(org.eclipse.che.api.agent.server.WsAgentHealthCheckerImpl.class);

bind(org.eclipse.che.api.recipe.RecipeLoader.class);
Multibinder.newSetBinder(binder(), String.class, Names.named(RecipeLoader.CHE_PREDEFINED_RECIPES))
Expand All @@ -177,25 +165,11 @@ protected void configure() {

bind(org.eclipse.che.api.deploy.WsMasterAnalyticsAddresser.class);

// FIXME: spi
// Multibinder<org.eclipse.che.api.machine.server.spi.InstanceProvider> machineImageProviderMultibinder =
// Multibinder.newSetBinder(binder(), org.eclipse.che.api.machine.server.spi.InstanceProvider.class);
// machineImageProviderMultibinder.addBinding().to(org.eclipse.che.plugin.docker.machine.DockerInstanceProvider.class);

// bind(org.eclipse.che.api.environment.server.MachineInstanceProvider.class)
// .to(org.eclipse.che.plugin.docker.machine.MachineProviderImpl.class);
install(new org.eclipse.che.api.workspace.server.activity.inject.WorkspaceActivityModule());

install(new org.eclipse.che.api.core.rest.CoreRestModule());
install(new org.eclipse.che.api.core.util.FileCleaner.FileCleanerModule());
// FIXME: spi
// install(new org.eclipse.che.plugin.docker.machine.local.LocalDockerModule());
// install(new org.eclipse.che.api.machine.server.MachineModule());
// FIXME: spi
// install(new org.eclipse.che.plugin.docker.machine.ext.DockerExtServerModule());
install(new org.eclipse.che.swagger.deploy.DocsModule());
// FIXME: spi
// install(new org.eclipse.che.workspace.infrastructure.docker.old.proxy.DockerProxyModule());
install(new org.eclipse.che.commons.schedule.executor.ScheduleModule());

final Multibinder<MessageBodyAdapter> adaptersMultibinder = Multibinder.newSetBinder(binder(), MessageBodyAdapter.class);
Expand All @@ -206,20 +180,12 @@ protected void configure() {
final MessageBodyAdapterInterceptor interceptor = new MessageBodyAdapterInterceptor();
requestInjection(interceptor);
bindInterceptor(subclassesOf(CheJsonProvider.class), names("readFrom"), interceptor);
// FIXME: spi
// bind(org.eclipse.che.api.workspace.server.WorkspaceFilesCleaner.class);
// .to(org.eclipse.che.workspace.infrastructure.docker.old.cleaner.LocalWorkspaceFilesCleaner.class);
// bind(org.eclipse.che.api.environment.server.InfrastructureProvisioner.class)
// .to(org.eclipse.che.plugin.docker.machine.local.LocalCheInfrastructureProvisioner.class);

// system components
install(new SystemModule());
Multibinder.newSetBinder(binder(), ServiceTermination.class)
.addBinding()
.to(org.eclipse.che.api.workspace.server.WorkspaceServiceTermination.class);
// FIXME: spi
// install(new org.eclipse.che.workspace.infrastructure.docker.old.config.dns.DnsResolversModule());

// FIXME: spi
// bind(org.eclipse.che.api.agent.server.filters.AddExecInstallerInWorkspaceFilter.class);
// bind(org.eclipse.che.api.agent.server.filters.AddExecInstallerInStackFilter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ che.workspace.exec_linux_amd64=${che.home}/lib/linux_amd64/exec
# Folder where the workspace will store logs from agents and other runtimes
che.workspace.logs=${che.logs.dir}/machine/logs

# RAM default for new machines.
# TODO: is this per machine, or for the entire environment?
# RAM default for each machine that has no RAM settings in environment.
che.workspace.default_memory_mb=1024

# This archive contains the server to run the workspace agent and any custom extensions.
Expand Down
3 changes: 1 addition & 2 deletions infrastructures/docker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<artifactId>license-maven-plugin</artifactId>
<configuration>
<excludes>
<!--TODO remove this after removal of strategies-->
<!-- Exclude files until #3281 is resolved -->
<exclude>**/ServerEvaluationStrategyProvider.java</exclude>
<exclude>**/ServerEvaluationStrategy.java</exclude>
Expand All @@ -204,8 +205,6 @@
<exclude>**/LocalDockerServerEvaluationStrategyTest.java</exclude>
<exclude>**/LocalDockerCustomServerEvaluationStrategy.java</exclude>
<exclude>**/LocalDockerCustomServerEvaluationStrategyTest.java</exclude>
<exclude>**/DockerInstanceRuntimeInfo.java</exclude>
<exclude>**/DockerInstanceRuntimeInfoTest.java</exclude>
<!-- End excluded files -->
</excludes>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,94 +11,52 @@
package org.eclipse.che.workspace.infrastructure.docker;

import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;

import org.eclipse.che.api.core.model.workspace.config.ServerConfig;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactory;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactoryImpl;
import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure;
import org.eclipse.che.plugin.docker.client.DockerRegistryDynamicAuthResolver;
import org.eclipse.che.plugin.docker.client.NoOpDockerRegistryDynamicAuthResolverImpl;
import org.eclipse.che.workspace.infrastructure.docker.bootstrap.DockerBootstrapperFactory;
import org.eclipse.che.workspace.infrastructure.docker.config.DockerExtraHostsFromPropertyProvider;
import org.eclipse.che.workspace.infrastructure.docker.config.dns.DnsResolversModule;
import org.eclipse.che.workspace.infrastructure.docker.config.env.ApiEndpointEnvVariableProvider;
import org.eclipse.che.workspace.infrastructure.docker.config.env.JavaOptsEnvVariableProvider;
import org.eclipse.che.workspace.infrastructure.docker.config.env.ProjectsRootEnvVariableProvider;
import org.eclipse.che.workspace.infrastructure.docker.config.proxy.DockerProxyModule;
import org.eclipse.che.workspace.infrastructure.docker.config.volume.ExtraVolumeModule;
import org.eclipse.che.workspace.infrastructure.docker.environment.DockerEnvironmentTypeModule;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactory;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactoryImpl;
import org.eclipse.che.workspace.infrastructure.docker.strategy.ServerEvaluationStrategyModule;

import java.util.Set;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.ContainerSystemSettingsProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.ContainerSystemSettingsProvisioningModule;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.cgroup.CGroupParentProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.dns.DnsSettingsProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.hosts.ExtraHostsProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.limits.cpu.CpuLimitsProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.limits.pids.PidLimitProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.limits.ram.DefaultRAMProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.limits.swap.SwapLimitProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.priviliged.PrivilegedModeProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.proxy.ProxySettingsProvisioner;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.server.ServersEnvVarsProvisioningModule;
import org.eclipse.che.workspace.infrastructure.docker.provisioner.volume.ExtraVolumesProvisioner;

/**
* @author Alexander Garagatyi
*/
public class DockerInfraModule extends AbstractModule {
@Override
protected void configure() {
Multibinder<String> devMachineEnvVars =
Multibinder.newSetBinder(binder(),
String.class,
Names.named("machine.docker.dev_machine.machine_env"))
.permitDuplicates();
Multibinder<String> allMachinesEnvVars =
Multibinder.newSetBinder(binder(),
String.class,
Names.named("machine.docker.machine_env"))
.permitDuplicates();

@SuppressWarnings("unused") Multibinder<ServerConfig> devMachineServers =
Multibinder.newSetBinder(binder(),
ServerConfig.class,
Names.named("machine.docker.dev_machine.machine_servers"));
@SuppressWarnings("unused") Multibinder<ServerConfig> machineServers =
Multibinder.newSetBinder(binder(),
ServerConfig.class,
Names.named("machine.docker.machine_servers"));

@SuppressWarnings("unused") Multibinder<String> devMachineVolumes =
Multibinder.newSetBinder(binder(),
String.class,
Names.named("machine.docker.dev_machine.machine_volumes"))
.permitDuplicates();

@SuppressWarnings("unused") Multibinder<String> machineVolumes =
Multibinder.newSetBinder(binder(),
String.class,
Names.named("machine.docker.machine_volumes"));

// Provides set of sets of strings instead of set of strings.
// This allows providers to return empty set as a value if no value should be added by provider.
// .permitDuplicates() is needed to allow different providers add empty sets.
@SuppressWarnings("unused") Multibinder<Set<String>> networks =
Multibinder.newSetBinder(binder(),
new TypeLiteral<Set<String>>() {},
Names.named("machine.docker.networks"))
.permitDuplicates();

// Extra hosts configuration
Multibinder<Set<String>> extraHosts = Multibinder.newSetBinder(binder(),
new TypeLiteral<Set<String>>() {},
Names.named("che.docker.extra_hosts"))
.permitDuplicates();
extraHosts.addBinding()
.toProvider(DockerExtraHostsFromPropertyProvider.class);

// Environment variables configuration
devMachineEnvVars.addBinding().toProvider(ProjectsRootEnvVariableProvider.class);
devMachineEnvVars.addBinding().toProvider(JavaOptsEnvVariableProvider.class);
allMachinesEnvVars.addBinding().toProvider(ApiEndpointEnvVariableProvider.class);
Multibinder<ContainerSystemSettingsProvisioner> settingsProvisioners =
Multibinder.newSetBinder(binder(), ContainerSystemSettingsProvisioner.class);
settingsProvisioners.addBinding().to(DnsSettingsProvisioner.class);
settingsProvisioners.addBinding().to(ExtraHostsProvisioner.class);
settingsProvisioners.addBinding().to(ProxySettingsProvisioner.class);
settingsProvisioners.addBinding().to(ExtraVolumesProvisioner.class);
settingsProvisioners.addBinding().to(SwapLimitProvisioner.class);
settingsProvisioners.addBinding().to(DefaultRAMProvisioner.class);
settingsProvisioners.addBinding().to(PidLimitProvisioner.class);
settingsProvisioners.addBinding().to(CGroupParentProvisioner.class);
settingsProvisioners.addBinding().to(CpuLimitsProvisioner.class);
settingsProvisioners.addBinding().to(PrivilegedModeProvisioner.class);

install(new DnsResolversModule());
install(new DockerProxyModule());
install(new ExtraVolumeModule());
install(new DockerEnvironmentTypeModule());
install(new ServerEvaluationStrategyModule());
install(new ContainerSystemSettingsProvisioningModule());
install(new ServersEnvVarsProvisioningModule());

Multibinder<RuntimeInfrastructure> mb = Multibinder.newSetBinder(binder(), RuntimeInfrastructure.class);
mb.addBinding().to(DockerRuntimeInfrastructure.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@
import org.eclipse.che.plugin.docker.client.json.ContainerListEntry;
import org.eclipse.che.workspace.infrastructure.docker.bootstrap.DockerBootstrapperFactory;
import org.eclipse.che.workspace.infrastructure.docker.exception.SourceNotFoundException;
import org.eclipse.che.workspace.infrastructure.docker.logs.MachineLoggersFactory;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerBuildContext;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerContainerConfig;
import org.eclipse.che.workspace.infrastructure.docker.monit.AbnormalMachineStopHandler;
import org.eclipse.che.workspace.infrastructure.docker.monit.DockerMachineStopDetector;
import org.eclipse.che.api.workspace.server.hc.ServerCheckerFactory;
import org.eclipse.che.api.workspace.server.hc.ServersReadinessChecker;
import org.eclipse.che.workspace.infrastructure.docker.network.NetworkLifecycle;
import org.eclipse.che.workspace.infrastructure.docker.registry.DockerRegistryClient;
import org.eclipse.che.workspace.infrastructure.docker.server.mapping.ExternalIpURLRewriter;
import org.eclipse.che.workspace.infrastructure.docker.snapshot.MachineSource;
import org.eclipse.che.workspace.infrastructure.docker.snapshot.MachineSourceImpl;
import org.eclipse.che.workspace.infrastructure.docker.snapshot.SnapshotDao;
Expand Down Expand Up @@ -287,7 +291,6 @@ private void startMachine(String name, DockerContainerConfig containerConfig) th
name,
containerConfig,
getContext().getIdentity(),
getContext().getDevMachineName().equals(name),
new AbnormalMachineStopHandlerImpl());
try {
startSynchronizer.addMachine(name, machine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.Map;

import static java.lang.String.format;
import static org.eclipse.che.workspace.infrastructure.docker.DockerRegistryClient.MACHINE_SNAPSHOT_PREFIX;
import static org.eclipse.che.workspace.infrastructure.docker.registry.DockerRegistryClient.MACHINE_SNAPSHOT_PREFIX;
import static org.slf4j.LoggerFactory.getLogger;

/**
Expand Down Expand Up @@ -153,16 +153,17 @@ public void exec(String script, MessageProcessor<LogMessage> messageProcessor) t
public void destroy() throws InfrastructureException {
dockerMachineStopDetector.stopDetection(container);
try {
docker.removeContainer(RemoveContainerParams.create(this.container)
docker.removeContainer(RemoveContainerParams.create(container)
.withRemoveVolumes(true)
.withForce(true));
} catch (IOException e) {
throw new InternalInfrastructureException(e.getMessage(), e);
}
try {
docker.removeImage(RemoveImageParams.create(this.image).withForce(false));
docker.removeImage(RemoveImageParams.create(image).withForce(false));
} catch (IOException e) {
LOG.error("IOException during destroy(). Ignoring.");
// TODO make log level warning if we ignoring it or remove ignoring phrase
LOG.error("IOException during destroy(). Ignoring.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.che.plugin.docker.client.json.ContainerListEntry;
import org.eclipse.che.plugin.docker.client.json.NetworkSettings;
import org.eclipse.che.workspace.infrastructure.docker.monit.DockerMachineStopDetector;
import org.eclipse.che.workspace.infrastructure.docker.strategy.ServersMapper;
import org.eclipse.che.workspace.infrastructure.docker.server.mapping.ServersMapper;

import javax.inject.Inject;
import javax.inject.Named;
Expand Down
Loading