From 77a00179db72d77c6bd338a2b7bede7366ce5d0c Mon Sep 17 00:00:00 2001 From: Sergii Kabashniuk Date: Tue, 4 Sep 2018 10:09:20 +0300 Subject: [PATCH] Add che.workspace.plugin_registry_url information to workspace/settings Rest method (#11015) Add che.workspace.plugin_registry_url information to workspace/settings Rest method --- .../webapp/WEB-INF/classes/che/che.properties | 5 ++++ deploy/openshift/deploy_che.sh | 8 +++---- .../che/api/workspace/shared/Constants.java | 6 +++++ .../workspace/server/WorkspaceService.java | 23 +++++++++++++++---- .../server/WorkspaceServiceTest.java | 17 +++++++++++--- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties index 21ad85f6f0..500f6c322e 100644 --- a/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties +++ b/assembly/assembly-wsmaster-war/src/main/webapp/WEB-INF/classes/che/che.properties @@ -492,6 +492,11 @@ che.workspace.plugin_registry_url=NULL # plugins dependencies to a workspace che.workspace.plugin_broker.image=eclipse/che-plugin-broker:latest +# Workspace tooling plugins registry endpoint. Should be a valid HTTP URL. +# Example: http://che-plugin-registry-eclipse-che.192.168.65.2.nip.io +# In case Che plugins tooling is not needed value 'NULL' should be used +che.workspace.plugin_registry_url=NULL + # Configures in which way secure servers will be protected with authentication. # Suitable values: # - 'default': no additionally authentication system will be enabled. diff --git a/deploy/openshift/deploy_che.sh b/deploy/openshift/deploy_che.sh index 40393e80b5..b5b5bc6d55 100755 --- a/deploy/openshift/deploy_che.sh +++ b/deploy/openshift/deploy_che.sh @@ -154,8 +154,8 @@ export PLUGIN_REGISTRY_IMAGE=${PLUGIN_REGISTRY_IMAGE:-${DEFAULT_PLUGIN_REGISTRY_ DEFAULT_PLUGIN_REGISTRY_IMAGE_PULL_POLICY="Always" export PLUGIN_REGISTRY_IMAGE_PULL_POLICY=${PLUGIN_REGISTRY_IMAGE_PULL_POLICY:-${DEFAULT_PLUGIN_REGISTRY_IMAGE_PULL_POLICY}} -DEFAULT_CHE_WORKSPACE_PLUGIN__REGISTRY__URL="NULL" -export CHE_WORKSPACE_PLUGIN__REGISTRY__URL=${CHE_WORKSPACE_PLUGIN__REGISTRY__URL:-${DEFAULT_CHE_WORKSPACE_PLUGIN__REGISTRY__URL}} +DEFAULT_PLUGIN__REGISTRY__URL="NULL" +export PLUGIN__REGISTRY__URL=${PLUGIN__REGISTRY__URL:-${DEFAULT_PLUGIN__REGISTRY__URL}} if [ "${ENABLE_SSL}" == "true" ]; then HTTP_PROTOCOL="https" @@ -442,7 +442,7 @@ ${CHE_VAR_ARRAY}" if [ "${DEPLOY_CHE_PLUGIN_REGISTRY}" == "true" ]; then PLUGIN_REGISTRY_ROUTE=$($OC_BINARY get route/che-plugin-registry --namespace=${CHE_OPENSHIFT_PROJECT} -o=jsonpath={'.spec.host'}) - CHE_WORKSPACE_PLUGIN__REGISTRY__URL="${HTTP_PROTOCOL}://${PLUGIN_REGISTRY_ROUTE}/" + PLUGIN__REGISTRY__URL="${HTTP_PROTOCOL}://${PLUGIN_REGISTRY_ROUTE}" fi ${OC_BINARY} new-app -f ${BASE_DIR}/templates/che-server-template.yaml \ @@ -457,7 +457,7 @@ ${CHE_VAR_ARRAY}" -p CHE_INFRA_OPENSHIFT_PROJECT=${CHE_INFRA_OPENSHIFT_PROJECT} \ -p CHE_INFRA_OPENSHIFT_OAUTH__IDENTITY__PROVIDER=${CHE_INFRA_OPENSHIFT_OAUTH__IDENTITY__PROVIDER} \ -p TLS=${TLS} \ - -p CHE_WORKSPACE_PLUGIN__REGISTRY__URL=${CHE_WORKSPACE_PLUGIN__REGISTRY__URL} \ + -p CHE_WORKSPACE_PLUGIN__REGISTRY__URL=${PLUGIN__REGISTRY__URL} \ ${ENV} if [ ${UPDATE_STRATEGY} == "Recreate" ]; then diff --git a/wsmaster/che-core-api-workspace-shared/src/main/java/org/eclipse/che/api/workspace/shared/Constants.java b/wsmaster/che-core-api-workspace-shared/src/main/java/org/eclipse/che/api/workspace/shared/Constants.java index 742735803d..64bec65d37 100644 --- a/wsmaster/che-core-api-workspace-shared/src/main/java/org/eclipse/che/api/workspace/shared/Constants.java +++ b/wsmaster/che-core-api-workspace-shared/src/main/java/org/eclipse/che/api/workspace/shared/Constants.java @@ -44,6 +44,12 @@ public final class Constants { public static final String CHE_WORKSPACE_AUTO_START = "che.workspace.auto_start"; + /** + * Property name for Che plugin registry url. Key name of api workspace/settings method results. + */ + public static final String CHE_WORKSPACE_PLUGIN_REGISTRY_ULR = + "che.workspace.plugin_registry_url"; + /** Name for environment variable of machine name */ public static final String CHE_MACHINE_NAME_ENV_VAR = "CHE_MACHINE_NAME"; /** diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceService.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceService.java index 0569d8078c..205c78f9ae 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceService.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceService.java @@ -18,9 +18,11 @@ import static java.util.stream.Collectors.toList; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static org.eclipse.che.api.workspace.server.DtoConverter.asDto; import static org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_START; +import static org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_PLUGIN_REGISTRY_ULR; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.Maps; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -72,6 +74,7 @@ import org.eclipse.che.api.workspace.shared.dto.RuntimeDto; import org.eclipse.che.api.workspace.shared.dto.ServerDto; import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto; import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto; +import org.eclipse.che.commons.annotation.Nullable; import org.eclipse.che.commons.env.EnvironmentContext; /** @@ -87,6 +90,7 @@ public class WorkspaceService extends Service { private final WorkspaceManager workspaceManager; private final MachineTokenProvider machineTokenProvider; private final WorkspaceLinksGenerator linksGenerator; + private final String pluginRegistryUrl; private final String apiEndpoint; private final boolean cheWorkspaceAutoStart; @@ -96,12 +100,14 @@ public class WorkspaceService extends Service { @Named(CHE_WORKSPACE_AUTO_START) boolean cheWorkspaceAutoStart, WorkspaceManager workspaceManager, MachineTokenProvider machineTokenProvider, - WorkspaceLinksGenerator linksGenerator) { + WorkspaceLinksGenerator linksGenerator, + @Named(CHE_WORKSPACE_PLUGIN_REGISTRY_ULR) @Nullable String pluginRegistryUrl) { this.apiEndpoint = apiEndpoint; this.cheWorkspaceAutoStart = cheWorkspaceAutoStart; this.workspaceManager = workspaceManager; this.machineTokenProvider = machineTokenProvider; this.linksGenerator = linksGenerator; + this.pluginRegistryUrl = pluginRegistryUrl; } @POST @@ -664,11 +670,18 @@ public class WorkspaceService extends Service { @ApiOperation(value = "Get workspace server configuration values") @ApiResponses({@ApiResponse(code = 200, message = "The response contains server settings")}) public Map getSettings() { - return ImmutableMap.of( + Builder settings = ImmutableMap.builder(); + + settings.put( Constants.SUPPORTED_RECIPE_TYPES, - Joiner.on(",").join(workspaceManager.getSupportedRecipes()), - CHE_WORKSPACE_AUTO_START, - Boolean.toString(cheWorkspaceAutoStart)); + Joiner.on(",").join(workspaceManager.getSupportedRecipes())); + settings.put(CHE_WORKSPACE_AUTO_START, Boolean.toString(cheWorkspaceAutoStart)); + + if (pluginRegistryUrl != null) { + settings.put(CHE_WORKSPACE_PLUGIN_REGISTRY_ULR, pluginRegistryUrl); + } + + return settings.build(); } private static Map parseAttrs(List attributes) diff --git a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceServiceTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceServiceTest.java index 2fc7b4d1ae..8be89e9e68 100644 --- a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceServiceTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/WorkspaceServiceTest.java @@ -108,6 +108,7 @@ public class WorkspaceServiceTest { private static final String NAMESPACE = "user"; private static final String USER_ID = "user123"; private static final String API_ENDPOINT = "http://localhost:8080/api"; + private static final String CHE_WORKSPACE_PLUGIN_REGISTRY_ULR = "http://localhost:9898/plugins/"; private static final Account TEST_ACCOUNT = new AccountImpl("anyId", NAMESPACE, "test"); @SuppressWarnings("unused") @@ -122,7 +123,13 @@ public class WorkspaceServiceTest { @BeforeMethod public void setup() { service = - new WorkspaceService(API_ENDPOINT, true, wsManager, machineTokenProvider, linksGenerator); + new WorkspaceService( + API_ENDPOINT, + true, + wsManager, + machineTokenProvider, + linksGenerator, + CHE_WORKSPACE_PLUGIN_REGISTRY_ULR); } @Test @@ -1132,8 +1139,12 @@ public class WorkspaceServiceTest { assertEquals( settings, ImmutableMap.of( - Constants.SUPPORTED_RECIPE_TYPES, "dockerimage,dockerfile", - Constants.CHE_WORKSPACE_AUTO_START, "true")); + Constants.SUPPORTED_RECIPE_TYPES, + "dockerimage,dockerfile", + Constants.CHE_WORKSPACE_AUTO_START, + "true", + Constants.CHE_WORKSPACE_PLUGIN_REGISTRY_ULR, + CHE_WORKSPACE_PLUGIN_REGISTRY_ULR)); } private static String unwrapError(Response response) {