Skip to content

Commit

Permalink
CHE-5871: refactor DockerMachineStarter
Browse files Browse the repository at this point in the history
Refactor DockerMachineStarter to clean it up and reduce
amount of responsibilities. Move container configuration applying
to InfrastructureProvisioners.
Move classes to different packages to create some structure and
reduce classes mess in single package.
Uncomment some commented tests.
Signed-off-by: Oleksandr Garagatyi <ogaragat@redhat.com>
  • Loading branch information
Oleksandr Garagatyi committed Aug 8, 2017
1 parent 77a34f9 commit b2146a4
Show file tree
Hide file tree
Showing 135 changed files with 2,745 additions and 3,663 deletions.
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,11 +180,6 @@ 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());
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,96 +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.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.bootstrap.DockerBootstrapper;
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.workspace.infrastructure.docker.server.ServerCheckerFactory;
import org.eclipse.che.workspace.infrastructure.docker.server.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;
import org.eclipse.che.workspace.infrastructure.docker.server.checker.ServerCheckerFactory;
import org.eclipse.che.workspace.infrastructure.docker.server.checker.ServerCheckerFactoryImpl;

/**
* @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.workspace.infrastructure.docker.server.ServerCheckerFactory;
import org.eclipse.che.workspace.infrastructure.docker.server.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.server.checker.ServerCheckerFactory;
import org.eclipse.che.workspace.infrastructure.docker.server.checker.ServersReadinessChecker;
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

0 comments on commit b2146a4

Please sign in to comment.