use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.
the class CheEnvironmentEngine method machineConfigToService.
private CheServiceImpl machineConfigToService(MachineConfig machineConfig) throws ServerException {
CheServiceImpl service = new CheServiceImpl();
service.setMemLimit(machineConfig.getLimits().getRam() * 1024L * 1024L);
service.setEnvironment(machineConfig.getEnvVariables());
if ("image".equals(machineConfig.getSource().getType())) {
service.setImage(machineConfig.getSource().getLocation());
} else {
if (machineConfig.getSource().getContent() != null) {
throw new ServerException("Additional machine creation from dockerfile content is not supported anymore. " + "Please use dockerfile location instead");
} else {
service.setBuild(new CheServiceBuildContextImpl(machineConfig.getSource().getLocation(), null, null, null));
}
}
List<? extends ServerConf> servers = machineConfig.getServers();
if (servers != null) {
List<String> expose = new ArrayList<>();
for (ServerConf server : servers) {
expose.add(server.getPort());
}
service.setExpose(expose);
}
return service;
}
use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.
the class CheEnvironmentValidator method validateMachine.
public void validateMachine(MachineConfig machineCfg) throws IllegalArgumentException {
String machineName = machineCfg.getName();
checkArgument(!isNullOrEmpty(machineName), "Machine name is null or empty");
checkArgument(MACHINE_NAME_PATTERN.matcher(machineName).matches(), "Machine name '%s' is invalid", machineName);
checkNotNull(machineCfg.getSource(), "Machine '%s' doesn't have source", machineName);
checkArgument(machineCfg.getSource().getContent() != null || machineCfg.getSource().getLocation() != null, "Source of machine '%s' must contain location or content", machineName);
checkArgument(machineCfg.getSource().getContent() == null || machineCfg.getSource().getLocation() == null, "Source of machine '%s' contains mutually exclusive fields location and content", machineName);
checkArgument(machineInstanceProviders.hasProvider(machineCfg.getType()), "Type '%s' of machine '%s' is not supported. Supported values are: %s.", machineCfg.getType(), machineName, Joiner.on(", ").join(machineInstanceProviders.getProviderTypes()));
if (machineCfg.getSource().getType().equals("dockerfile") && machineCfg.getSource().getLocation() != null) {
try {
final String protocol = new URL(machineCfg.getSource().getLocation()).getProtocol();
checkArgument(protocol.equals("http") || protocol.equals("https"), "Machine '%s' has invalid source location protocol: %s", machineName, machineCfg.getSource().getLocation());
} catch (MalformedURLException e) {
throw new IllegalArgumentException(format("Machine '%s' has invalid source location: '%s'", machineName, machineCfg.getSource().getLocation()));
}
}
for (ServerConf serverConf : machineCfg.getServers()) {
checkArgument(serverConf.getPort() != null && SERVER_PORT.matcher(serverConf.getPort()).matches(), "Machine '%s' contains server conf with invalid port '%s'", machineName, serverConf.getPort());
checkArgument(serverConf.getProtocol() == null || SERVER_PROTOCOL.matcher(serverConf.getProtocol()).matches(), "Machine '%s' contains server conf with invalid protocol '%s'", machineName, serverConf.getProtocol());
}
for (Map.Entry<String, String> envVariable : machineCfg.getEnvVariables().entrySet()) {
checkArgument(!isNullOrEmpty(envVariable.getKey()), "Machine '%s' contains environment variable with null or empty name", machineName);
checkNotNull(envVariable.getValue(), "Machine '%s' contains environment variable '%s' with null value", machineName, envVariable.getKey());
}
}
use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.
the class SshMachineInstance method getRuntime.
public MachineRuntimeInfoImpl getRuntime() {
// lazy initialization
if (machineRuntime == null) {
synchronized (this) {
if (machineRuntime == null) {
UriBuilder uriBuilder = UriBuilder.fromUri("http://" + sshClient.getHost());
final Map<String, ServerImpl> servers = new HashMap<>();
for (ServerConf serverConf : machinesServers) {
servers.put(serverConf.getPort(), serverConfToServer(serverConf, uriBuilder.clone()));
}
machineRuntime = new MachineRuntimeInfoImpl(emptyMap(), emptyMap(), servers);
}
}
// todo get env from client
}
return machineRuntime;
}
use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.
the class DockerInstanceRuntimeInfoTest method shouldPassCommonServerConfigsOnGetServersForNonDevMachine.
@Test
public void shouldPassCommonServerConfigsOnGetServersForNonDevMachine() throws Exception {
// given
Set<ServerConf> commonSystemServersConfigs = new HashSet<>();
commonSystemServersConfigs.add(new ServerConfImpl("sysServer1-tcp", "4301/tcp", "http", "/some/path"));
commonSystemServersConfigs.add(new ServerConfImpl("sysServer2-udp", "4302/udp", "dhcp", null));
commonSystemServersConfigs.add(new ServerConfImpl("sysServer1-udp", "4301/udp", null, "some/path"));
Set<ServerConf> devSystemServersConfigs = singleton(new ServerConfImpl("devSysServer1-tcp", "4305/tcp", "http", null));
List<ServerConf> serversConfFromMachineConf = singletonList(new ServerConfImpl("machineConfServer1-tcp", "4306/tcp", "http", null));
when(machineConfig.getServers()).thenAnswer(invocation -> serversConfFromMachineConf);
when(machineConfig.isDev()).thenReturn(false);
runtimeInfo = new DockerInstanceRuntimeInfo(containerInfo, machineConfig, DEFAULT_HOSTNAME, provider, devSystemServersConfigs, commonSystemServersConfigs);
// when
Map<String, ServerImpl> servers = runtimeInfo.getServers();
// then
assertEquals(servers, serversMap);
verify(serverEvaluationStrategy).getServers(eq(containerInfo), eq(DEFAULT_HOSTNAME), serversCaptor.capture());
assertEquals(serversCaptor.getValue(), serversToMap(commonSystemServersConfigs, serversConfFromMachineConf));
}
use of org.eclipse.che.api.core.model.machine.ServerConf in project che by eclipse.
the class DockerInstanceRuntimeInfoTest method shouldPassCommonAndDevServerConfigsOnGetServersForNonDevMachine.
@Test
public void shouldPassCommonAndDevServerConfigsOnGetServersForNonDevMachine() throws Exception {
Set<ServerConf> commonSystemServersConfigs = new HashSet<>();
commonSystemServersConfigs.add(new ServerConfImpl("sysServer1-tcp", "4301/tcp", "http", "/some/path1"));
commonSystemServersConfigs.add(new ServerConfImpl("sysServer2-udp", "4302/udp", "dhcp", "some/path2"));
Set<ServerConf> devSystemServersConfigs = new HashSet<>();
devSystemServersConfigs.add(new ServerConfImpl("devSysServer1-tcp", "4305/tcp", "http", "/some/path3"));
devSystemServersConfigs.add(new ServerConfImpl("devSysServer1-udp", "4305/udp", null, "some/path4"));
List<ServerConf> serversConfFromMachineConf = singletonList(new ServerConfImpl("machineConfServer1-tcp", "4306/tcp", "http", null));
when(machineConfig.getServers()).thenAnswer(invocation -> serversConfFromMachineConf);
when(machineConfig.isDev()).thenReturn(true);
runtimeInfo = new DockerInstanceRuntimeInfo(containerInfo, machineConfig, DEFAULT_HOSTNAME, provider, devSystemServersConfigs, commonSystemServersConfigs);
Map<String, ServerImpl> servers = runtimeInfo.getServers();
assertEquals(servers, serversMap);
verify(serverEvaluationStrategy).getServers(eq(containerInfo), eq(DEFAULT_HOSTNAME), serversCaptor.capture());
assertEquals(serversCaptor.getValue(), serversToMap(commonSystemServersConfigs, devSystemServersConfigs, serversConfFromMachineConf));
}
Aggregations