use of org.eclipse.che.api.core.model.workspace.ServerConf2 in project che by eclipse.
the class CheEnvironmentEngine method addAgentsProvidedServers.
private void addAgentsProvidedServers(MachineImpl machine, List<String> agentKeys) throws ServerException {
for (String agentKey : agentKeys) {
try {
AgentImpl agent = new AgentImpl(agentRegistry.getAgent(AgentKeyImpl.parse(agentKey)));
for (Map.Entry<String, ? extends ServerConf2> entry : agent.getServers().entrySet()) {
String ref = entry.getKey();
ServerConf2 conf2 = entry.getValue();
ServerConfImpl conf = new ServerConfImpl(ref, conf2.getPort(), conf2.getProtocol(), conf2.getProperties().get("path"));
machine.getConfig().getServers().add(conf);
}
} catch (AgentException e) {
throw new ServerException(e);
}
}
}
use of org.eclipse.che.api.core.model.workspace.ServerConf2 in project che by eclipse.
the class CheEnvironmentValidator method validateExtendedMachine.
private void validateExtendedMachine(ExtendedMachine extendedMachine, String envName, String machineName) {
if (extendedMachine.getAttributes() != null && extendedMachine.getAttributes().get("memoryLimitBytes") != null) {
try {
long memoryLimitBytes = Long.parseLong(extendedMachine.getAttributes().get("memoryLimitBytes"));
checkArgument(memoryLimitBytes > 0, "Value of attribute 'memoryLimitBytes' of machine '%s' in environment '%s' is illegal", machineName, envName);
} catch (NumberFormatException e) {
throw new IllegalArgumentException(format("Value of attribute 'memoryLimitBytes' of machine '%s' in environment '%s' is illegal", machineName, envName));
}
}
if (extendedMachine.getServers() != null) {
extendedMachine.getServers().entrySet().forEach(serverEntry -> {
String serverName = serverEntry.getKey();
ServerConf2 server = serverEntry.getValue();
checkArgument(server.getPort() != null && SERVER_PORT.matcher(server.getPort()).matches(), "Machine '%s' in environment '%s' contains server conf '%s' with invalid port '%s'", machineName, envName, serverName, server.getPort());
checkArgument(server.getProtocol() == null || SERVER_PROTOCOL.matcher(server.getProtocol()).matches(), "Machine '%s' in environment '%s' contains server conf '%s' with invalid protocol '%s'", machineName, envName, serverName, server.getProtocol());
});
}
if (extendedMachine.getAgents() != null) {
for (String agent : extendedMachine.getAgents()) {
checkArgument(!isNullOrEmpty(agent), "Machine '%s' in environment '%s' contains invalid agent '%s'", machineName, envName, agent);
}
}
}
use of org.eclipse.che.api.core.model.workspace.ServerConf2 in project che by eclipse.
the class CheEnvironmentEngineTest method shouldBeAbleToStartNonDockerMachine.
@Test
public void shouldBeAbleToStartNonDockerMachine() throws Exception {
// given
ServerConf2 serverConf2 = mock(ServerConf2.class);
when(serverConf2.getPort()).thenReturn("1111/tcp");
when(serverConf2.getProtocol()).thenReturn("http");
when(serverConf2.getProperties()).thenReturn(singletonMap("path", "some path"));
when(agent.getServers()).thenAnswer(invocation -> singletonMap("ssh", serverConf2));
List<Instance> instances = startEnv();
String workspaceId = instances.get(0).getWorkspaceId();
when(engine.generateMachineId()).thenReturn("newMachineId");
Instance newMachine = mock(Instance.class);
when(newMachine.getId()).thenReturn("newMachineId");
when(newMachine.getWorkspaceId()).thenReturn(workspaceId);
when(machineInstanceProviders.getProvider("anotherType")).thenReturn(instanceProvider);
doReturn(newMachine).when(instanceProvider).createInstance(any(Machine.class), any(LineConsumer.class));
MachineConfigImpl config = MachineConfigImpl.builder().fromConfig(createConfig(false)).setType("anotherType").build();
// when
Instance actualInstance = engine.startMachine(workspaceId, config, singletonList("agent"));
// then
assertEquals(actualInstance, newMachine);
ArgumentCaptor<Machine> argumentCaptor = ArgumentCaptor.forClass(Machine.class);
verify(instanceProvider).createInstance(argumentCaptor.capture(), any(LineConsumer.class));
MachineConfigImpl newConfig = new MachineConfigImpl(config);
newConfig.setServers(singletonList(new ServerConfImpl("ssh", "1111/tcp", "http", "some path")));
assertEquals(argumentCaptor.getValue().getConfig(), newConfig);
}
use of org.eclipse.che.api.core.model.workspace.ServerConf2 in project che by eclipse.
the class AgentConfigApplierTest method shouldAddExposedPorts.
@Test
public void shouldAddExposedPorts() throws Exception {
final ServerConf2 serverConf1 = mock(ServerConf2.class);
final ServerConf2 serverConf2 = mock(ServerConf2.class);
when(serverConf1.getPort()).thenReturn("1111/udp");
when(serverConf2.getPort()).thenReturn("2222/tcp");
when(sorter.sort(any())).thenReturn(asList(AgentKeyImpl.parse("agent1"), AgentKeyImpl.parse("agent2"), AgentKeyImpl.parse("agent3")));
when(agent1.getServers()).thenAnswer(invocation -> singletonMap("a", serverConf1));
when(agent2.getServers()).thenAnswer(invocation -> singletonMap("b", serverConf2));
when(agent3.getServers()).thenReturn(emptyMap());
CheServiceImpl service = new CheServiceImpl();
agentConfigApplier.apply(new ExtendedMachineImpl(asList("agent1", "agent2", "agent3"), emptyMap(), emptyMap()), service);
List<String> exposedPorts = service.getExpose();
assertTrue(exposedPorts.contains("1111/udp"));
assertTrue(exposedPorts.contains("2222/tcp"));
}
use of org.eclipse.che.api.core.model.workspace.ServerConf2 in project che by eclipse.
the class AgentConfigApplier method addLabels.
private void addLabels(CheServiceImpl service, Map<String, ? extends ServerConf2> servers) {
for (Map.Entry<String, ? extends ServerConf2> entry : servers.entrySet()) {
String ref = entry.getKey();
ServerConf2 conf = entry.getValue();
service.getLabels().put("che:server:" + conf.getPort() + ":protocol", conf.getProtocol());
service.getLabels().put("che:server:" + conf.getPort() + ":ref", ref);
String path = conf.getProperties().get("path");
if (!isNullOrEmpty(path)) {
service.getLabels().put("che:server:" + conf.getPort() + ":path", path);
}
}
}
Aggregations