use of org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl in project che by eclipse.
the class ServerEvaluationStrategyTest method shouldAddRefUrlProtocolPathToServerFromMachineConfig.
@Test
public void shouldAddRefUrlProtocolPathToServerFromMachineConfig() throws Exception {
// given
prepareStrategyAndContainerInfoMocks();
serverConfs.put("8080/tcp", new ServerConfImpl("myserv1", "8080/tcp", "http", null));
serverConfs.put("9090/udp", new ServerConfImpl("myserv2", "9090/udp", "dhcp", "/some/path"));
final HashMap<String, ServerImpl> expectedServers = new HashMap<>();
expectedServers.put("8080/tcp", new ServerImpl("myserv1", "http", DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100", new ServerPropertiesImpl(null, DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100")));
expectedServers.put("9090/udp", new ServerImpl("myserv2", "dhcp", DEFAULT_HOSTNAME + ":32101", "dhcp://" + DEFAULT_HOSTNAME + ":32101/some/path", new ServerPropertiesImpl("/some/path", DEFAULT_HOSTNAME + ":32101", "dhcp://" + DEFAULT_HOSTNAME + ":32101/some/path")));
// when
final Map<String, ServerImpl> servers = strategy.getServers(containerInfo, DEFAULT_HOSTNAME, serverConfs);
// then
assertEquals(servers, expectedServers);
}
use of org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl in project che by eclipse.
the class ServerEvaluationStrategyTest method shouldAllowToUsePortFromDockerLabelsWithoutTransportProtocol.
@Test
public void shouldAllowToUsePortFromDockerLabelsWithoutTransportProtocol() throws Exception {
// given
prepareStrategyAndContainerInfoMocks();
labels.put(String.format(SERVER_CONF_LABEL_REF_KEY, "8080"), "myserv1");
labels.put(String.format(SERVER_CONF_LABEL_PROTOCOL_KEY, "8080"), "http");
labels.put(String.format(SERVER_CONF_LABEL_REF_KEY, "9090/udp"), "myserv1-tftp");
labels.put(String.format(SERVER_CONF_LABEL_PROTOCOL_KEY, "9090/udp"), "tftp");
final HashMap<String, ServerImpl> expectedServers = new HashMap<>();
expectedServers.put("8080/tcp", new ServerImpl("myserv1", "http", DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100", new ServerPropertiesImpl(null, DEFAULT_HOSTNAME + ":32100", "http://" + DEFAULT_HOSTNAME + ":32100")));
expectedServers.put("9090/udp", new ServerImpl("myserv1-tftp", "tftp", DEFAULT_HOSTNAME + ":32101", "tftp://" + DEFAULT_HOSTNAME + ":32101", new ServerPropertiesImpl(null, DEFAULT_HOSTNAME + ":32101", "tftp://" + DEFAULT_HOSTNAME + ":32101")));
// when
final Map<String, ServerImpl> servers = strategy.getServers(containerInfo, DEFAULT_HOSTNAME, serverConfs);
// then
assertEquals(servers, expectedServers);
}
use of org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl in project che by eclipse.
the class LocalDockerServerEvaluationStrategyTest method getExpectedServers.
private Map<String, ServerImpl> getExpectedServers(String externalAddress, String internalAddress, boolean useExposedPorts) {
String port1;
String port2;
if (useExposedPorts) {
port1 = ":4301";
port2 = ":4305";
} else {
port1 = ":32100";
port2 = ":32103";
}
Map<String, ServerImpl> expectedServers = new HashMap<>();
expectedServers.put("4301/tcp", new ServerImpl("sysServer1-tcp", "http", externalAddress + ":32100", "http://" + externalAddress + ":32100/some/path1", new ServerPropertiesImpl("/some/path1", internalAddress + port1, "http://" + internalAddress + port1 + "/some/path1")));
expectedServers.put("4305/udp", new ServerImpl("devSysServer1-udp", null, externalAddress + ":32103", null, new ServerPropertiesImpl("some/path4", internalAddress + port2, null)));
return expectedServers;
}
use of org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl in project che by eclipse.
the class DefaultServerEvaluationStrategyTest method getExpectedServers.
private Map<String, ServerImpl> getExpectedServers(String externalAddress, String internalAddress) {
String port1;
String port2;
port1 = ":32100";
port2 = ":32103";
Map<String, ServerImpl> expectedServers = new HashMap<>();
expectedServers.put("4301/tcp", new ServerImpl("sysServer1-tcp", "http", externalAddress + ":32100", "http://" + externalAddress + ":32100/some/path1", new ServerPropertiesImpl("/some/path1", internalAddress + port1, "http://" + internalAddress + port1 + "/some/path1")));
expectedServers.put("4305/udp", new ServerImpl("devSysServer1-udp", null, externalAddress + ":32103", null, new ServerPropertiesImpl("some/path4", internalAddress + port2, null)));
return expectedServers;
}
use of org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl in project che by eclipse.
the class ServerEvaluationStrategy method getServers.
/**
* Constructs a map of {@link ServerImpl} from provided parameters, using selected strategy
* for evaluating addresses and ports.
*
* <p>Keys consist of port number and transport protocol (tcp or udp) separated by
* a forward slash (e.g. 8080/tcp)
*
* @param containerInfo
* the {@link ContainerInfo} describing the container.
* @param internalHost
* alternative hostname to use, if address cannot be obtained from containerInfo
* @param serverConfMap
* additional Map of {@link ServerConfImpl}. Configurations here override those found
* in containerInfo.
* @return a Map of the servers exposed by the container.
*/
public Map<String, ServerImpl> getServers(ContainerInfo containerInfo, String internalHost, Map<String, ServerConfImpl> serverConfMap) {
Map<String, List<PortBinding>> portBindings;
Map<String, String> labels = Collections.emptyMap();
if (containerInfo.getNetworkSettings() != null && containerInfo.getNetworkSettings().getPorts() != null) {
portBindings = containerInfo.getNetworkSettings().getPorts();
} else {
// If we can't get PortBindings, we can't return servers.
return Collections.emptyMap();
}
if (containerInfo.getConfig() != null && containerInfo.getConfig().getLabels() != null) {
labels = containerInfo.getConfig().getLabels();
}
Map<String, String> internalAddressesAndPorts = getInternalAddressesAndPorts(containerInfo, internalHost);
Map<String, String> externalAddressesAndPorts = getExternalAddressesAndPorts(containerInfo, internalHost);
Map<String, ServerImpl> servers = new LinkedHashMap<>();
for (String portProtocol : portBindings.keySet()) {
String internalAddressAndPort = internalAddressesAndPorts.get(portProtocol);
String externalAddressAndPort = externalAddressesAndPorts.get(portProtocol);
ServerConfImpl serverConf = getServerConfImpl(portProtocol, labels, serverConfMap);
// Add protocol and path to internal/external address, if applicable
String internalUrl = null;
String externalUrl = null;
if (serverConf.getProtocol() != null) {
String pathSuffix = serverConf.getPath();
if (pathSuffix != null && !pathSuffix.isEmpty()) {
if (pathSuffix.charAt(0) != '/') {
pathSuffix = "/" + pathSuffix;
}
} else {
pathSuffix = "";
}
internalUrl = serverConf.getProtocol() + "://" + internalAddressAndPort + pathSuffix;
externalUrl = serverConf.getProtocol() + "://" + externalAddressAndPort + pathSuffix;
}
ServerProperties properties = new ServerPropertiesImpl(serverConf.getPath(), internalAddressAndPort, internalUrl);
servers.put(portProtocol, new ServerImpl(serverConf.getRef(), serverConf.getProtocol(), externalAddressAndPort, externalUrl, properties));
}
return servers;
}
Aggregations