Skip to content

Commit 1da2e2a

Browse files
authored
... by restoring the previous `WsAgentPingRequestFactory` behavior, and providing a new custom server evaluation template strategy when both internal *and* external addresses should be based on the custom template. Signed-off-by: David Festal <dfestal@redhat.com>
1 parent 15712df commit 1da2e2a

5 files changed

Lines changed: 73 additions & 8 deletions

File tree

assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/codenvy/che.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ che.docker.ip.external=NULL
214214
# - 'custom': The evaluation strategy may be customized through a template property.
215215
# - 'docker-local-custom': internal address is set as in docker-local strategy, external address is composed
216216
# as in the custom strategy with the 'template' and the 'external.protocol' properties.
217-
217+
# - 'always-external-custom': similar to 'docker-local-custom' strategy, but both the internal and external addresses
218+
# are composed strategy with the 'template' and the 'external.protocol' properties.
219+
#
218220
# The 'docker-local' strategy may be useful if a firewall prevents communication between che-server and
219221
# workspace containers, but will prevent communication when che-server and workspace containers are not
220222
# on the same Docker network.

dockerfiles/init/modules/openshift/files/scripts/deploy_che.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then
404404
- name: \"CHE_WORKSPACE_CHE__SERVER__ENDPOINT\"
405405
value: \"\"
406406
$MULTI_USER_REPLACEMENT_STRING"
407-
407+
MULTITENANT_CUSTOM_STRATEGY_REPLACEMENT="s/ che-server-evaluation-strategy: .*/ che-server-evaluation-strategy: always-external-custom/"
408408
MULTITENANT_CUSTOM_TEMPLATE_REPLACEMENT="s/ che.docker.server_evaluation_strategy.custom.template: .*/ che.docker.server_evaluation_strategy.custom.template: <serverName>-<if(isDevMachine)><workspaceIdWithoutPrefix><else><machineName><endif>-<if(workspacesRoutingSuffix)><user>-che.<workspacesRoutingSuffix><else><externalAddress><endif>/"
409409
MULTITENANT_IDLING_REPLACEMENT="s/ che-server-timeout-ms: .*/ che-server-timeout-ms: '0'/"
410410
fi
@@ -436,6 +436,7 @@ if [ "${OPENSHIFT_FLAVOR}" == "minishift" ]; then
436436
if [ "${CHE_KEYCLOAK_DISABLED}" == "true" ]; then sed "s/ keycloak-disabled: \"false\"/ keycloak-disabled: \"true\"/" ; else cat -; fi | \
437437
sed "$MULTI_USER_HEALTH_CHECK_REPLACEMENT_STRING" | \
438438
append_after_match "env:" "${MULTI_USER_REPLACEMENT_STRING}" | \
439+
if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then sed "$MULTITENANT_CUSTOM_STRATEGY_REPLACEMENT" ; else cat -; fi | \
439440
if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then sed "$MULTITENANT_CUSTOM_TEMPLATE_REPLACEMENT" ; else cat -; fi | \
440441
if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then sed "$MULTITENANT_IDLING_REPLACEMENT" ; else cat -; fi | \
441442
oc apply --force=true -f -
@@ -450,6 +451,7 @@ elif [ "${OPENSHIFT_FLAVOR}" == "osio" ]; then
450451
if [ "${CHE_KEYCLOAK_DISABLED}" == "true" ]; then sed "s/ keycloak-disabled: \"false\"/ keycloak-disabled: \"true\"/" ; else cat -; fi | \
451452
sed "$MULTI_USER_HEALTH_CHECK_REPLACEMENT_STRING" | \
452453
append_after_match "env:" "${MULTI_USER_REPLACEMENT_STRING}" | \
454+
if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then sed "$MULTITENANT_CUSTOM_STRATEGY_REPLACEMENT" ; else cat -; fi | \
453455
if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then sed "$MULTITENANT_CUSTOM_TEMPLATE_REPLACEMENT" ; else cat -; fi | \
454456
if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then sed "$MULTITENANT_IDLING_REPLACEMENT" ; else cat -; fi | \
455457
oc apply --force=true -f -
@@ -470,6 +472,7 @@ else
470472
if [ "${K8S_VERSION_PRIOR_TO_1_6}" == "true" ]; then sed "s/ che-openshift-precreate-subpaths: \"false\"/ che-openshift-precreate-subpaths: \"true\"/" ; else cat -; fi | \
471473
sed "$MULTI_USER_HEALTH_CHECK_REPLACEMENT_STRING" | \
472474
append_after_match "env:" "${MULTI_USER_REPLACEMENT_STRING}" | \
475+
if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then sed "$MULTITENANT_CUSTOM_STRATEGY_REPLACEMENT" ; else cat -; fi | \
473476
if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then sed "$MULTITENANT_CUSTOM_TEMPLATE_REPLACEMENT" ; else cat -; fi | \
474477
if [ "${CHE_FABRIC8_MULTITENANT}" == "true" ]; then sed "$MULTITENANT_IDLING_REPLACEMENT" ; else cat -; fi | \
475478
oc apply --force=true -f -
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.plugin.docker.machine;
12+
13+
import com.google.inject.Inject;
14+
import com.google.inject.name.Named;
15+
import java.util.Map;
16+
import org.eclipse.che.api.machine.server.model.impl.ServerImpl;
17+
import org.eclipse.che.commons.annotation.Nullable;
18+
import org.eclipse.che.plugin.docker.client.WorkspacesRoutingSuffixProvider;
19+
import org.eclipse.che.plugin.docker.client.json.ContainerInfo;
20+
21+
/**
22+
* This server evaluation strategy will return a completed {@link ServerImpl} with internal
23+
* addresses and external addresses managed by the `custom` evaluation strategy,and its template
24+
* property `che.docker.server_evaluation_strategy.custom.template`
25+
*
26+
* <p>cheExternalAddress can be set using property {@code che.docker.ip.external}. This strategy is
27+
* useful when Che and the workspace servers need to be exposed on the same single TCP port
28+
*
29+
* @author David Festal <dfestal@redhat.com>
30+
* @see ServerEvaluationStrategy
31+
*/
32+
public class AlwaysExternalCustomServerEvaluationStrategy extends BaseServerEvaluationStrategy {
33+
34+
@Inject
35+
public AlwaysExternalCustomServerEvaluationStrategy(
36+
@Nullable @Named("che.docker.ip") String internalAddress,
37+
@Nullable @Named("che.docker.ip.external") String externalAddress,
38+
@Nullable @Named("che.docker.server_evaluation_strategy.custom.template")
39+
String cheDockerCustomExternalTemplate,
40+
@Nullable @Named("che.docker.server_evaluation_strategy.custom.external.protocol")
41+
String cheDockerCustomExternalProtocol,
42+
@Named("che.port") String chePort,
43+
WorkspacesRoutingSuffixProvider cheWorkspacesRoutingSuffixProvider) {
44+
super(
45+
internalAddress,
46+
externalAddress,
47+
cheDockerCustomExternalTemplate,
48+
cheDockerCustomExternalProtocol,
49+
chePort,
50+
true,
51+
cheWorkspacesRoutingSuffixProvider);
52+
}
53+
54+
@Override
55+
protected Map<String, String> getInternalAddressesAndPorts(
56+
ContainerInfo containerInfo, String internalHost) {
57+
return super.getExternalAddressesAndPorts(containerInfo, internalHost);
58+
}
59+
}

plugins/plugin-docker/che-plugin-docker-machine/src/main/java/org/eclipse/che/plugin/docker/machine/local/LocalDockerModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.che.api.machine.server.spi.Instance;
2121
import org.eclipse.che.api.machine.server.spi.InstanceProcess;
2222
import org.eclipse.che.plugin.docker.client.DockerConnector;
23+
import org.eclipse.che.plugin.docker.machine.AlwaysExternalCustomServerEvaluationStrategy;
2324
import org.eclipse.che.plugin.docker.machine.DockerInstance;
2425
import org.eclipse.che.plugin.docker.machine.DockerInstanceRuntimeInfo;
2526
import org.eclipse.che.plugin.docker.machine.DockerProcess;
@@ -62,6 +63,9 @@ protected void configure() {
6263
strategies
6364
.addBinding("custom")
6465
.to(org.eclipse.che.plugin.docker.machine.CustomServerEvaluationStrategy.class);
66+
strategies
67+
.addBinding("always-external-custom")
68+
.to(AlwaysExternalCustomServerEvaluationStrategy.class);
6569

6670
bind(org.eclipse.che.plugin.docker.machine.node.WorkspaceFolderPathProvider.class)
6771
.to(

wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentPingRequestFactory.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,10 @@ public HttpJsonRequest createRequest(Machine machine) throws ServerException {
7070
servers);
7171
throw new ServerException(WS_AGENT_SERVER_NOT_FOUND_ERROR);
7272
}
73-
String wsAgentPingUrl = wsAgentServer.getUrl();
73+
String wsAgentPingUrl = wsAgentServer.getProperties().getInternalUrl();
7474
if (isNullOrEmpty(wsAgentPingUrl)) {
75-
wsAgentPingUrl = wsAgentServer.getProperties().getInternalUrl();
76-
if (isNullOrEmpty(wsAgentPingUrl)) {
77-
LOG.error(WS_AGENT_URL_IS_NULL_OR_EMPTY_ERROR);
78-
throw new ServerException(WS_AGENT_URL_IS_NULL_OR_EMPTY_ERROR);
79-
}
75+
LOG.error(WS_AGENT_URL_IS_NULL_OR_EMPTY_ERROR);
76+
throw new ServerException(WS_AGENT_URL_IS_NULL_OR_EMPTY_ERROR);
8077
}
8178
// since everrest mapped on the slash in case of it absence
8279
// we will always obtain not found response

0 commit comments

Comments
 (0)