Skip to content

Commit

Permalink
CHE-5413 Refactor Installer API
Browse files Browse the repository at this point in the history
  • Loading branch information
sleshchenko committed Jun 29, 2017
1 parent 0504b31 commit 9d7a2d9
Show file tree
Hide file tree
Showing 24 changed files with 707 additions and 740 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import org.eclipse.che.api.installer.TerminalInstaller;
import org.eclipse.che.api.installer.UnisonInstaller;
import org.eclipse.che.api.installer.WsInstaller;
import org.eclipse.che.api.installer.server.impl.LocalInstallerRegistry;
import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.installer.server.InstallerRegistryProvider;
import org.eclipse.che.api.installer.server.InstallerRegistryService;
import org.eclipse.che.api.installer.shared.model.Installer;
import org.eclipse.che.api.core.rest.CheJsonProvider;
import org.eclipse.che.api.core.rest.MessageBodyAdapter;
Expand Down Expand Up @@ -124,7 +126,9 @@ protected void configure() {
bind(org.eclipse.che.plugin.docker.machine.ext.DockerMachineTerminalChecker.class);
bind(org.eclipse.che.everrest.EverrestDownloadFileResponseFilter.class);
bind(org.eclipse.che.everrest.ETagResponseFilter.class);
bind(org.eclipse.che.api.installer.server.InstallerRegistryService.class);

bind(InstallerRegistry.class).toProvider(InstallerRegistryProvider.class);
bind(InstallerRegistryService.class);

// temporary solution
bind(org.eclipse.che.api.workspace.server.event.RuntimeStatusJsonRpcMessenger.class).asEagerSingleton();
Expand Down Expand Up @@ -160,7 +164,6 @@ protected void configure() {
// bind(org.eclipse.che.api.workspace.server.event.MachineStateListener.class).asEagerSingleton();

// installers
bind(org.eclipse.che.api.installer.server.InstallerRegistry.class).to(LocalInstallerRegistry.class);
Multibinder<Installer> installers = Multibinder.newSetBinder(binder(), Installer.class);
installers.addBinding().to(SshInstaller.class);
installers.addBinding().to(UnisonInstaller.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ che.workspace.agent.dev.ping_delay_ms=2000
che.workspace.agent.dev.ping_conn_timeout_ms=2000
che.workspace.agent.dev.ping_timeout_error_msg=Timeout. The Che server is unable to ping your workspace. This implies a network configuration issue, workspace boot failure, or an unusually slow workspace boot.

che.installer.registry.remote=NULL

che.agent.dev.max_start_time_ms=120000
che.agent.dev.ping_delay_ms=2000

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@

import com.google.inject.assistedinject.Assisted;

import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.core.ValidationException;
import org.eclipse.che.api.core.model.workspace.config.Environment;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.installer.server.impl.InstallerSorter;
import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.InternalRuntime;
import org.eclipse.che.api.workspace.server.spi.RuntimeContext;
Expand Down Expand Up @@ -54,10 +53,9 @@ public DockerRuntimeContext(@Assisted DockerRuntimeInfrastructure infrastructure
@Assisted DockerEnvironment dockerEnvironment,
@Assisted List<String> orderedServices,
InstallerRegistry installerRegistry,
InstallerSorter installerSorter,
DockerRuntimeFactory dockerRuntimeFactory)
throws ValidationException, InfrastructureException {
super(environment, identity, infrastructure, installerSorter, installerRegistry);
super(environment, identity, infrastructure, installerRegistry);
this.devMachineName = Utils.getDevMachineName(environment);
this.orderedServices = orderedServices;
this.dockerEnvironment = dockerEnvironment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.core.notification.EventService;
import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.installer.server.impl.InstallerSorter;
import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure;
Expand All @@ -44,7 +43,6 @@ public class DockerRuntimeInfrastructure extends RuntimeInfrastructure {
private final InfrastructureProvisioner infrastructureProvisioner;
private final EnvironmentNormalizer environmentNormalizer;
private final DockerRuntimeFactory runtimeFactory;
private final InstallerSorter installerSorter;
private final InstallerRegistry installerRegistry;

@Inject
Expand All @@ -55,7 +53,6 @@ public DockerRuntimeInfrastructure(EnvironmentParser dockerEnvironmentParser,
EnvironmentNormalizer environmentNormalizer,
Map<String, DockerConfigSourceSpecificEnvironmentParser> environmentParsers,
DockerRuntimeFactory runtimeFactory,
InstallerSorter installerSorter,
InstallerRegistry installerRegistry,
EventService eventService) {
super("docker", environmentParsers.keySet(), eventService);
Expand All @@ -66,7 +63,6 @@ public DockerRuntimeInfrastructure(EnvironmentParser dockerEnvironmentParser,
this.environmentNormalizer = environmentNormalizer;
this.runtimeFactory = runtimeFactory;
this.installerRegistry = installerRegistry;
this.installerSorter = installerSorter;
}

@Override
Expand Down Expand Up @@ -106,7 +102,6 @@ public DockerRuntimeContext prepare(RuntimeIdentity identity, Environment origin
dockerEnvironment,
orderedServices,
installerRegistry,
installerSorter,
runtimeFactory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import org.eclipse.che.api.core.model.workspace.config.ServerConfig;
import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.installer.server.exception.InstallerException;
import org.eclipse.che.api.installer.server.impl.InstallerSorter;
import org.eclipse.che.api.installer.shared.model.Installer;
import org.eclipse.che.api.installer.shared.model.InstallerKey;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerContainerConfig;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerEnvironment;
Expand Down Expand Up @@ -57,13 +55,10 @@ public class InstallerConfigApplier {
private static final Logger LOG = getLogger(InstallerConfigApplier.class);

private final InstallerRegistry installerRegistry;
private final InstallerSorter sorter;

@Inject
public InstallerConfigApplier(InstallerRegistry installerRegistry,
InstallerSorter sorter) {
public InstallerConfigApplier(InstallerRegistry installerRegistry) {
this.installerRegistry = installerRegistry;
this.sorter = sorter;
}

/**
Expand Down Expand Up @@ -101,8 +96,7 @@ public void apply(Environment envConfig,
public void apply(@Nullable MachineConfig machineConf,
DockerContainerConfig machine) throws InstallerException {
if (machineConf != null) {
for (InstallerKey installerKey : sorter.sort(machineConf.getInstallers())) {
Installer installer = installerRegistry.getInstaller(installerKey);
for (Installer installer : installerRegistry.getOrderedInstallers(machineConf.getInstallers())) {
addEnv(machine, installer.getProperties());
addExposedPorts(machine, installer.getServers());
addLabels(machine, installer.getServers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@
*******************************************************************************/
package org.eclipse.che.workspace.infrastructure.docker;

import org.eclipse.che.api.core.model.workspace.config.ServerConfig;
import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.installer.server.model.impl.InstallerImpl;
import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerContainerConfig;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

Expand All @@ -25,39 +39,31 @@
*/
@Listeners(value = {MockitoTestNGListener.class})
public class InstallerConfigApplierTest {

// @Mock
// private Instance machine;
@Mock
private InstallerImpl agent1;
private InstallerImpl installer1;
@Mock
private InstallerImpl agent2;
private InstallerImpl installer2;
@Mock
private InstallerImpl agent3;
/*
TODO Uncomment and fix
private InstallerImpl installer3;
@Mock
private AgentLauncherFactory agentLauncher;
@Mock
private InstallerRegistry installerRegistry;
private InstallerRegistry installerRegistry;

private InstallerConfigApplier agentConfigApplier;
private InstallerConfigApplier installerConfigApplier;

@BeforeMethod
public void setUp() throws Exception {
agentConfigApplier = new InstallerConfigApplier(sorter, installerRegistry);
when(installerRegistry.getInstaller(InstallerKeyImpl.parse("agent1"))).thenReturn(agent1);
when(installerRegistry.getInstaller(InstallerKeyImpl.parse("agent2"))).thenReturn(agent2);
when(installerRegistry.getInstaller(InstallerKeyImpl.parse("agent3"))).thenReturn(agent3);
when(agent1.getScript()).thenReturn("script1");
when(agent1.getDependencies()).thenReturn(singletonList("fqn3"));
installerConfigApplier = new InstallerConfigApplier(installerRegistry);
when(installerRegistry.getInstaller("installer1")).thenReturn(installer1);
when(installerRegistry.getInstaller("installer2")).thenReturn(installer2);
when(installerRegistry.getInstaller("installer3")).thenReturn(installer3);

when(agent2.getScript()).thenReturn("script2");
when(agent2.getDependencies()).thenReturn(singletonList("fqn3"));
when(installer1.getScript()).thenReturn("script1");
when(installer1.getDependencies()).thenReturn(singletonList("installer3"));

when(agent3.getScript()).thenReturn("script3");
when(installer2.getScript()).thenReturn("script2");
when(installer2.getDependencies()).thenReturn(singletonList("installer2"));

when(installer3.getScript()).thenReturn("script3");
}

@Test
Expand All @@ -67,14 +73,14 @@ public void shouldAddLabels() throws Exception {
when(serverConf1.getProtocol()).thenReturn("http");
when(serverConf1.getPath()).thenReturn("b");

when(sorter.sort(any())).thenReturn(singletonList(InstallerKeyImpl.parse("agent1")));
when(agent1.getServers()).thenAnswer(invocation -> singletonMap("a", serverConf1));
when(installerRegistry.getOrderedInstallers(any())).thenReturn(singletonList(installer1));
when(installer1.getServers()).thenAnswer(invocation -> singletonMap("a", serverConf1));
DockerContainerConfig service = new DockerContainerConfig();

agentConfigApplier.apply(new MachineConfigImpl(singletonList("agent1"),
emptyMap(),
emptyMap()),
service);
installerConfigApplier.apply(new MachineConfigImpl(singletonList("installer1"),
emptyMap(),
emptyMap()),
service);

Map<String, String> labels = service.getLabels();
assertEquals(labels.size(), 3);
Expand All @@ -90,18 +96,16 @@ public void shouldAddExposedPorts() throws Exception {
when(serverConf1.getPort()).thenReturn("1111/udp");
when(serverConfig.getPort()).thenReturn("2222/tcp");

when(sorter.sort(any())).thenReturn(asList(InstallerKeyImpl.parse("agent1"),
InstallerKeyImpl.parse("agent2"),
InstallerKeyImpl.parse("agent3")));
when(agent1.getServers()).thenAnswer(invocation -> singletonMap("a", serverConf1));
when(agent2.getServers()).thenAnswer(invocation -> singletonMap("b", serverConfig));
when(agent3.getServers()).thenReturn(emptyMap());
when(installerRegistry.getOrderedInstallers(any())).thenReturn(asList(installer1, installer2, installer3));
when(installer1.getServers()).thenAnswer(invocation -> singletonMap("a", serverConf1));
when(installer2.getServers()).thenAnswer(invocation -> singletonMap("b", serverConfig));
when(installer3.getServers()).thenReturn(emptyMap());
DockerContainerConfig service = new DockerContainerConfig();

agentConfigApplier.apply(new MachineConfigImpl(asList("agent1", "agent2", "agent3"),
emptyMap(),
emptyMap()),
service);
installerConfigApplier.apply(new MachineConfigImpl(asList("installer1", "installer2", "installer3"),
emptyMap(),
emptyMap()),
service);

List<String> exposedPorts = service.getExpose();
assertTrue(exposedPorts.contains("1111/udp"));
Expand All @@ -110,15 +114,15 @@ public void shouldAddExposedPorts() throws Exception {

@Test
public void shouldAddEnvVariables() throws Exception {
when(sorter.sort(any())).thenReturn(asList(InstallerKeyImpl.parse("agent1"), InstallerKeyImpl.parse("agent2")));
when(agent1.getProperties()).thenReturn(singletonMap("environment", "p1=v1,p2=v2"));
when(agent2.getProperties()).thenReturn(singletonMap("environment", "p3=v3"));
when(installerRegistry.getOrderedInstallers(any())).thenReturn(asList(installer1, installer2));
when(installer1.getProperties()).thenReturn(singletonMap("environment", "p1=v1,p2=v2"));
when(installer2.getProperties()).thenReturn(singletonMap("environment", "p3=v3"));
DockerContainerConfig service = new DockerContainerConfig();

agentConfigApplier.apply(new MachineConfigImpl(asList("agent1", "agent2"),
emptyMap(),
emptyMap()),
service);
installerConfigApplier.apply(new MachineConfigImpl(asList("installer1", "installer2"),
emptyMap(),
emptyMap()),
service);

Map<String, String> env = service.getEnvironment();
assertEquals(env.size(), 3);
Expand All @@ -129,17 +133,16 @@ public void shouldAddEnvVariables() throws Exception {

@Test
public void shouldIgnoreEnvironmentIfIllegalFormat() throws Exception {
when(sorter.sort(any())).thenReturn(singletonList(InstallerKeyImpl.parse("agent1")));
when(agent1.getProperties()).thenReturn(singletonMap("environment", "p1"));
when(installerRegistry.getOrderedInstallers(any())).thenReturn(singletonList(installer1));
when(installer1.getProperties()).thenReturn(singletonMap("environment", "p1"));
DockerContainerConfig service = new DockerContainerConfig();

agentConfigApplier.apply(new MachineConfigImpl(singletonList("agent1"),
emptyMap(),
emptyMap()),
service);
installerConfigApplier.apply(new MachineConfigImpl(singletonList("installer1"),
emptyMap(),
emptyMap()),
service);

Map<String, String> env = service.getEnvironment();
assertEquals(env.size(), 0);
}
*/
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
package org.eclipse.che.api.installer.server;

import org.eclipse.che.api.installer.shared.dto.InstallerDto;
import org.eclipse.che.api.installer.shared.dto.InstallerKeyDto;
import org.eclipse.che.api.installer.shared.model.Installer;
import org.eclipse.che.api.installer.shared.model.InstallerKey;

import static org.eclipse.che.dto.server.DtoFactory.newDto;

Expand All @@ -32,9 +30,5 @@ public static InstallerDto asDto(Installer installer) {
.withDependencies(installer.getDependencies());
}

public static InstallerKeyDto asDto(InstallerKey key) {
return newDto(InstallerKeyDto.class).withName(key.getId()).withVersion(key.getVersion());
}

private DtoConverter() { }
private DtoConverter() {}
}
Loading

0 comments on commit 9d7a2d9

Please sign in to comment.