Skip to content

Commit

Permalink
CHE-457: add servers conf and env vars to model of machine config.
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Garagatyi <agaragatyi@codenvy.com>
  • Loading branch information
Alexander Garagatyi committed Mar 11, 2016
1 parent 60e2c14 commit 1cc53f0
Show file tree
Hide file tree
Showing 45 changed files with 1,746 additions and 602 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import com.google.inject.name.Names;

import org.eclipse.che.api.auth.AuthenticationService;
import org.eclipse.che.api.core.model.machine.ServerConf;
import org.eclipse.che.api.core.notification.WSocketEventBusServer;
import org.eclipse.che.api.core.rest.ApiInfoService;
import org.eclipse.che.api.core.rest.CoreRestModule;
import org.eclipse.che.api.local.LocalInfrastructureModule;
import org.eclipse.che.api.machine.server.MachineModule;
import org.eclipse.che.api.machine.server.model.impl.ServerConfImpl;
import org.eclipse.che.api.machine.server.recipe.PermissionsChecker;
import org.eclipse.che.api.machine.server.recipe.PermissionsCheckerImpl;
import org.eclipse.che.api.machine.server.recipe.RecipeLoader;
Expand All @@ -38,7 +40,6 @@
import org.eclipse.che.everrest.ETagResponseFilter;
import org.eclipse.che.everrest.EverrestDownloadFileResponseFilter;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.docker.machine.ServerConf;
import org.eclipse.che.plugin.docker.machine.ext.DockerExtServerModule;
import org.eclipse.che.plugin.docker.machine.ext.DockerMachineExtServerChecker;
import org.eclipse.che.plugin.docker.machine.ext.DockerMachineTerminalChecker;
Expand Down Expand Up @@ -112,7 +113,7 @@ protected void configure() {
Multibinder<ServerConf> machineServers = Multibinder.newSetBinder(binder(),
ServerConf.class,
Names.named("machine.docker.dev_machine.machine_servers"));
machineServers.addBinding().toInstance(new ServerConf("extensions-debug", "4403", "http"));
machineServers.addBinding().toInstance(new ServerConfImpl("extensions-debug", "4403/tcp", "http"));

bind(RecipeLoader.class);
Multibinder.newSetBinder(binder(), String.class, Names.named("predefined.recipe.path"))
Expand Down
3 changes: 1 addition & 2 deletions assembly/assembly-machine-war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@
<configuration>
<packagingExcludes>WEB-INF/lib/*gwt*.jar,
WEB-INF/lib/gin-*.jar,
WEB-INF/lib/che-core-api-analytics-*.jar
</packagingExcludes>
WEB-INF/lib/che-core-api-analytics-*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.che.api.core.model.machine;

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

/**
* @author gazarenkov
*/
Expand Down Expand Up @@ -39,4 +42,16 @@ public interface MachineConfig {
* Machine limits such as RAM size.
*/
Limits getLimits();

/**
* Get configuration of servers inside of machine.
*
* <p>Key is port/transport protocol, e.g. 8080/tcp or 100100/udp
*/
List<? extends ServerConf> getServers();

/**
* Get predefined environment variables of machine.
*/
Map<String, String> getEnvVariables();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ public interface MachineRuntimeInfo {
String projectsRoot();

/**
* Returns mapping of exposed ports to {@link Server}
* Returns mapping of exposed ports to {@link Server}.
*
* <p>Key consist of port number and transport protocol - tcp or udp with slash between these parts.
* <br>Example:
* <pre>
* {
* 8080/tcp : {
* "ref" : "server_reference",
* "address" : "server-with-machines.com",
* "url" : "http://server-with-machines.com:8080"
* }
* }
* </pre>
*/
Map<String, ? extends Server> getServers();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright (c) 2012-2016 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.api.core.model.machine;

import org.eclipse.che.commons.annotation.Nullable;

/**
* Configuration of server that can be started inside of machine
*
* @author Alexander Garagatyi
*/
public interface ServerConf {
/**
* Reference to this server.
*/
@Nullable
String getRef();

/**
* Port used by server.
* <p>
* If udp transport protocol is used then port should include /udp.<br>
* If tcp is used /tcp is not required.<br>
* Example:
* <ul>
* <li>8080</li>
* <li>8080/tcp</li>
* <li>8080/udp</li>
* </ul>
*/
String getPort();

/**
* Protocol for configuring preview url of this server.
* <p>
* Example:
* <ul>
* <li>http</li>
* <li>https</li>
* <li>tcp</li>
* <li>udp</li>
* <li>ws</li>
* <li>wss</li>
* </ul>
*/
@Nullable
String getProtocol();
}
5 changes: 5 additions & 0 deletions core/ide/che-core-ide-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@
<artifactId>fest-assert</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-commons-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.che.api.workspace.shared.dto.EnvironmentDto;
import org.eclipse.che.api.workspace.shared.dto.UsersWorkspaceDto;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto;
import org.eclipse.che.commons.test.SelfReturningAnswer;
import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.workspace.DefaultWorkspaceComponent;
import org.eclipse.che.ide.workspace.WorkspaceComponent;
Expand All @@ -45,9 +46,8 @@
import org.mockito.runners.MockitoJUnitRunner;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import static org.eclipse.che.ide.workspace.create.CreateWorkspacePresenter.MAX_COUNT;
import static org.eclipse.che.ide.workspace.create.CreateWorkspacePresenter.RECIPE_TYPE;
Expand Down Expand Up @@ -100,8 +100,8 @@ public class CreateWorkspacePresenterTest {
private LimitsDto limitsDto;

//DTOs
@Mock
private MachineConfigDto machineConfigDto;
private WorkspaceConfigDto workspaceConfigDto;
@Mock
private MachineDto machineDto;
@Mock
Expand All @@ -111,8 +111,6 @@ public class CreateWorkspacePresenterTest {
@Mock
private CommandDto commandDto;
@Mock
private WorkspaceConfigDto workspaceConfigDto;
@Mock
private UsersWorkspaceDto usersWorkspaceDto;

@Captor
Expand All @@ -127,6 +125,10 @@ public class CreateWorkspacePresenterTest {

@Before
public void setUp() {
machineConfigDto = mock(MachineConfigDto.class, new SelfReturningAnswer());
workspaceConfigDto = mock(WorkspaceConfigDto.class, new SelfReturningAnswer());
when(usersWorkspaceDto.getConfig()).thenReturn(workspaceConfigDto);

when(dtoFactory.createDto(MachineSourceDto.class)).thenReturn(machineSourceDto);
when(machineSourceDto.withType(anyString())).thenReturn(machineSourceDto);
when(machineSourceDto.withLocation(anyString())).thenReturn(machineSourceDto);
Expand All @@ -135,28 +137,14 @@ public void setUp() {
when(limitsDto.withRam(anyInt())).thenReturn(limitsDto);

when(dtoFactory.createDto(MachineConfigDto.class)).thenReturn(machineConfigDto);
when(machineConfigDto.withName(anyString())).thenReturn(machineConfigDto);
when(machineConfigDto.withType(anyString())).thenReturn(machineConfigDto);
when(machineConfigDto.withSource(machineSourceDto)).thenReturn(machineConfigDto);
when(machineConfigDto.withDev(anyBoolean())).thenReturn(machineConfigDto);
when(machineConfigDto.withLimits(limitsDto)).thenReturn(machineConfigDto);

when(dtoFactory.createDto(EnvironmentDto.class)).thenReturn(environmentDto);
when(environmentDto.withName(anyString())).thenReturn(environmentDto);
when(environmentDto.withMachineConfigs(Matchers.<List<MachineConfigDto>>anyObject())).thenReturn(environmentDto);

when(dtoFactory.createDto(WorkspaceConfigDto.class)).thenReturn(workspaceConfigDto);
when(workspaceConfigDto.withName(anyString())).thenReturn(workspaceConfigDto);
when(workspaceConfigDto.withDefaultEnv(anyString())).thenReturn(workspaceConfigDto);
when(workspaceConfigDto.withEnvironments(Matchers.<List<EnvironmentDto>>anyObject())).thenReturn(workspaceConfigDto);
when(workspaceConfigDto.withCommands(Matchers.<List<CommandDto>>anyObject())).thenReturn(workspaceConfigDto);
when(workspaceConfigDto.withAttributes(Matchers.<Map<String, String>>anyObject())).thenReturn(workspaceConfigDto);

when(dtoFactory.createDto(UsersWorkspaceDto.class)).thenReturn(usersWorkspaceDto);
when(usersWorkspaceDto.getConfig()).thenReturn(workspaceConfigDto);
when(workspaceConfigDto.withName(anyString())).thenReturn(workspaceConfigDto);
when(workspaceConfigDto.withDefaultEnv(anyString())).thenReturn(workspaceConfigDto);
when(workspaceConfigDto.withEnvironments(Matchers.<List<EnvironmentDto>>anyObject())).thenReturn(workspaceConfigDto);

when(wsComponentProvider.get()).thenReturn(workspaceComponent);

Expand All @@ -172,7 +160,7 @@ public void delegateShouldBeSet() {

@Test
public void dialogShouldBeShown() {
presenter.show(Arrays.asList(usersWorkspaceDto), componentCallback);
presenter.show(Collections.singletonList(usersWorkspaceDto), componentCallback);

verify(browserQueryFieldRenderer).getWorkspaceName();
verify(view).setWorkspaceName(anyString());
Expand Down Expand Up @@ -206,7 +194,7 @@ public void errorLabelShouldBeShownWhenWorkspaceNameIsInCorrect() {
public void errorLabelShouldBeShownWhenWorkspaceNameAlreadyExist() {
when(workspaceConfigDto.getName()).thenReturn("test");

presenter.show(Arrays.asList(usersWorkspaceDto), componentCallback);
presenter.show(Collections.singletonList(usersWorkspaceDto), componentCallback);
reset(locale);

presenter.onNameChanged();
Expand Down Expand Up @@ -251,7 +239,7 @@ public void errorLabelShouldBeShownWhenRecipeUrlIsNotCorrect() {

@Test
public void recipesShouldBeFoundAndShown() throws Exception {
List<RecipeDescriptor> recipes = Arrays.asList(recipeDescriptor);
List<RecipeDescriptor> recipes = Collections.singletonList(recipeDescriptor);

callSearchRecipesApplyMethod(recipes);

Expand All @@ -261,7 +249,7 @@ public void recipesShouldBeFoundAndShown() throws Exception {
}

private void callSearchRecipesApplyMethod(List<RecipeDescriptor> recipes) throws Exception {
List<String> tags = Arrays.asList("test1 test2");
List<String> tags = Collections.singletonList("test1 test2");

when(view.getTags()).thenReturn(tags);
when(recipeServiceClient.searchRecipes(Matchers.<List<String>>anyObject(),
Expand Down Expand Up @@ -309,7 +297,7 @@ private void clickOnCreateButton() {
when(userWsPromise.catchError(Matchers.<Operation<PromiseError>>anyObject())).thenReturn(userWsPromise);
when(recipeServiceClient.getRecipes(anyInt(), anyInt())).thenReturn(recipesPromise);

presenter.show(Arrays.asList(usersWorkspaceDto), componentCallback);
presenter.show(Collections.singletonList(usersWorkspaceDto), componentCallback);

presenter.onCreateButtonClicked();

Expand Down Expand Up @@ -359,7 +347,7 @@ private void callApplyCreateWorkspaceMethod() throws Exception {
when(workspaceConfigDto.getDefaultEnv()).thenReturn("name");
when(workspaceConfigDto.getEnvironments()).thenReturn(environments);

when(environmentDto.getMachineConfigs()).thenReturn(Arrays.<MachineConfigDto>asList(machineConfigDto));
when(environmentDto.getMachineConfigs()).thenReturn(Collections.singletonList(machineConfigDto));

clickOnCreateButton();

Expand Down Expand Up @@ -389,4 +377,4 @@ public void errorShouldBeCaughtWhenCreatesWorkSpace() throws Exception {
verify(promiseError).getCause();
verify(componentCallback).onFailure(Matchers.<Exception>anyObject());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ private UsersWorkspaceImpl createUsersWorkspace() {
"type",
new MachineSourceImpl("type",
"location"),
null,
null,
null)));
return new UsersWorkspaceImpl(new WorkspaceConfigImpl("name",
"desc",
Expand All @@ -604,4 +606,4 @@ private UsersWorkspaceImpl createUsersWorkspace() {
null)
, "id123", "owner1234");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.che.api.machine.shared.dto.CommandDto;
import org.eclipse.che.api.machine.shared.dto.MachineConfigDto;
import org.eclipse.che.api.machine.shared.dto.MachineSourceDto;
import org.eclipse.che.api.machine.shared.dto.ServerConfDto;
import org.eclipse.che.api.workspace.shared.dto.EnvironmentDto;
import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;
import org.eclipse.che.api.workspace.shared.dto.RecipeDto;
Expand All @@ -49,6 +50,7 @@

import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.eclipse.che.dto.server.DtoFactory.newDto;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -176,7 +178,15 @@ private static Factory prepareFactory() {
.withType(
"git")
.withLocation(
"https://github.com/123/test.git"))))
"https://github.com/123/test.git"))
.withServers(Arrays.asList(newDto(ServerConfDto.class).withRef("ref1")
.withPort("8080")
.withProtocol("https"),
newDto(ServerConfDto.class).withRef("ref2")
.withPort("9090/udp")
.withProtocol("someprotocol")))
.withEnvVariables(Collections.singletonMap("key1", "value1"))
))
.withRecipe(dto.createDto(
RecipeDto.class)
.withType("sometype")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.che.api.machine.server.model.impl.LimitsImpl;
import org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl;
import org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl;
import org.eclipse.che.api.machine.server.model.impl.ServerConfImpl;
import org.eclipse.che.api.machine.server.recipe.RecipeImpl;
import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl;
import org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl;
Expand All @@ -31,6 +32,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -96,12 +99,18 @@ private static UsersWorkspaceImpl createWorkspace() {
"dev-machine",
"machine-type",
machineSource,
new LimitsImpl(512));
new LimitsImpl(512),
Arrays.asList(new ServerConfImpl("ref1", "8080", "https"),
new ServerConfImpl("ref2", "9090/udp", "someprotocol")),
Collections.singletonMap("key1", "value1"));
final MachineConfigImpl machineCfg2 = new MachineConfigImpl(false,
"non-dev-machine",
"machine-type-2",
machineSource,
new LimitsImpl(2048));
new LimitsImpl(2048),
Arrays.asList(new ServerConfImpl("ref1", "8080", "https"),
new ServerConfImpl("ref2", "9090/udp", "someprotocol")),
Collections.singletonMap("key1", "value1"));

final EnvironmentImpl env1 = new EnvironmentImpl("my-environment", recipe, asList(machineCfg1, machineCfg2));
final EnvironmentImpl env2 = new EnvironmentImpl("my-environment-2", recipe, singletonList(machineCfg1));
Expand Down
Loading

0 comments on commit 1cc53f0

Please sign in to comment.