Search in sources :

Example 1 with ServerProperties

use of org.eclipse.che.api.core.model.machine.ServerProperties 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;
}
Also used : ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) ServerProperties(org.eclipse.che.api.core.model.machine.ServerProperties) List(java.util.List) ServerPropertiesImpl(org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl) ServerConfImpl(org.eclipse.che.api.machine.server.model.impl.ServerConfImpl) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ServerProperties (org.eclipse.che.api.core.model.machine.ServerProperties)1 ServerConfImpl (org.eclipse.che.api.machine.server.model.impl.ServerConfImpl)1 ServerImpl (org.eclipse.che.api.machine.server.model.impl.ServerImpl)1 ServerPropertiesImpl (org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl)1