-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHE-3686: fix docker machines addresses setting
Set internal machine address by CLI from CHE_IP. Add and fix docs in che.env. Change behavior of default machine server address evaluation to be similar to the previous state. Code cleanup. Signed-off-by: Alexander Garagatyi <[email protected]>
- Loading branch information
Alexander Garagatyi
committed
Jan 19, 2017
1 parent
9a6118c
commit f2ca9a8
Showing
14 changed files
with
450 additions
and
737 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,22 +8,16 @@ | |
* Contributors: | ||
* Red Hat Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.che.plugin.docker.machine; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
|
||
import org.eclipse.che.api.machine.server.model.impl.ServerImpl; | ||
import org.eclipse.che.commons.annotation.Nullable; | ||
import org.eclipse.che.plugin.docker.client.json.ContainerInfo; | ||
import org.eclipse.che.plugin.docker.client.json.PortBinding; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
import static com.google.common.base.Strings.isNullOrEmpty; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Represents the default server evaluation strategy. By default, calling | ||
|
@@ -34,6 +28,7 @@ | |
* {@code che.docker.ip} and {@code che.docker.ip.external}, respectively. | ||
* | ||
* @author Angel Misevski <[email protected]> | ||
* @author Alexander Garagatyi | ||
* @see ServerEvaluationStrategy | ||
*/ | ||
public class DefaultServerEvaluationStrategy extends ServerEvaluationStrategy { | ||
|
@@ -49,48 +44,29 @@ public class DefaultServerEvaluationStrategy extends ServerEvaluationStrategy { | |
protected String externalAddressProperty; | ||
|
||
@Inject | ||
public DefaultServerEvaluationStrategy (@Nullable @Named("che.docker.ip") String internalAddress, | ||
@Nullable @Named("che.docker.ip.external") String externalAddress) { | ||
public DefaultServerEvaluationStrategy(@Nullable @Named("che.docker.ip") String internalAddress, | ||
@Nullable @Named("che.docker.ip.external") String externalAddress) { | ||
this.internalAddressProperty = internalAddress; | ||
this.externalAddressProperty = externalAddress; | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getInternalAddressesAndPorts(ContainerInfo containerInfo, String internalHost) { | ||
String internalAddressContainer = containerInfo.getNetworkSettings().getGateway(); | ||
|
||
String internalAddress = internalAddressProperty != null ? | ||
internalAddressProperty : | ||
!isNullOrEmpty(internalAddressContainer) ? | ||
internalAddressContainer : | ||
internalHost; | ||
|
||
Map<String, List<PortBinding>> portBindings = containerInfo.getNetworkSettings().getPorts(); | ||
|
||
return getAddressesAndPorts(internalAddress, portBindings); | ||
return getExposedPortsToAddressPorts(internalAddress, containerInfo.getNetworkSettings().getPorts()); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getExternalAddressesAndPorts(ContainerInfo containerInfo, String internalHost) { | ||
String externalAddressContainer = containerInfo.getNetworkSettings().getGateway(); | ||
|
||
String externalAddress = externalAddressProperty != null ? | ||
externalAddressProperty : | ||
!isNullOrEmpty(externalAddressContainer) ? | ||
externalAddressContainer : | ||
internalAddressProperty != null ? | ||
internalAddressProperty : | ||
internalHost; | ||
|
||
Map<String, List<PortBinding>> portBindings = containerInfo.getNetworkSettings().getPorts(); | ||
|
||
return getAddressesAndPorts(externalAddress, portBindings); | ||
} | ||
|
||
private Map<String, String> getAddressesAndPorts(String address, Map<String, List<PortBinding>> ports) { | ||
Map<String, String> addressesAndPorts = new HashMap<>(); | ||
for (String portKey : ports.keySet()) { | ||
String port = ports.get(portKey).get(0).getHostPort(); | ||
addressesAndPorts.put(portKey, address + ":" + port); | ||
} | ||
return addressesAndPorts; | ||
return super.getExposedPortsToAddressPorts(externalAddress, containerInfo.getNetworkSettings().getPorts()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.