From 72ed75be0c1981ef9e3365814e6a567ee22fec8a Mon Sep 17 00:00:00 2001 From: Oleksandr Garagatyi Date: Tue, 4 Jul 2017 15:04:49 +0300 Subject: [PATCH] Code cleanup --- .../che/api/deploy/WsMasterModule.java | 18 ++-- wsmaster/che-core-api-workspace/pom.xml | 4 - .../agent/server/WsAgentHealthChecker.java | 49 ---------- .../server/WsAgentHealthCheckerImpl.java | 85 ----------------- .../server/WsAgentPingRequestFactory.java | 92 ------------------- .../exception/EnvironmentException.java | 30 ------ .../EnvironmentNotRunningException.java | 29 ------ .../EnvironmentStartInterruptedException.java | 24 ----- .../api/workspace/server/NoopUrlRewriter.java | 26 ------ .../che/api/workspace/server/URLRewriter.java | 13 ++- .../workspace/server/WorkspaceSharedPool.java | 3 +- .../workspace/server/spi/InternalRuntime.java | 27 ++---- .../spi/dummy/DummyInfrastructureModule.java | 24 ----- .../spi/dummy/DummyRuntimeInfrastructure.java | 43 --------- 14 files changed, 29 insertions(+), 438 deletions(-) delete mode 100644 wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentHealthChecker.java delete mode 100644 wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentHealthCheckerImpl.java delete mode 100644 wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentPingRequestFactory.java delete mode 100644 wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentException.java delete mode 100644 wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentNotRunningException.java delete mode 100644 wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentStartInterruptedException.java delete mode 100644 wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/NoopUrlRewriter.java delete mode 100644 wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/dummy/DummyInfrastructureModule.java delete mode 100644 wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/dummy/DummyRuntimeInfrastructure.java diff --git a/assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java b/assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java index 583607570e..9e50ba4604 100644 --- a/assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java +++ b/assembly/assembly-wsmaster-war/src/main/java/org/eclipse/che/api/deploy/WsMasterModule.java @@ -15,6 +15,13 @@ import com.google.inject.multibindings.MapBinder; import com.google.inject.multibindings.Multibinder; import com.google.inject.name.Names; +import org.eclipse.che.api.core.rest.CheJsonProvider; +import org.eclipse.che.api.core.rest.MessageBodyAdapter; +import org.eclipse.che.api.core.rest.MessageBodyAdapterInterceptor; +import org.eclipse.che.api.factory.server.FactoryAcceptValidator; +import org.eclipse.che.api.factory.server.FactoryCreateValidator; +import org.eclipse.che.api.factory.server.FactoryEditValidator; +import org.eclipse.che.api.factory.server.FactoryParametersResolver; import org.eclipse.che.api.installer.ExecInstaller; import org.eclipse.che.api.installer.GitCredentialsInstaller; import org.eclipse.che.api.installer.LSCSharpInstaller; @@ -30,23 +37,16 @@ import org.eclipse.che.api.installer.server.InstallerRegistry; import org.eclipse.che.api.installer.server.InstallerRegistryProvider; import org.eclipse.che.api.installer.server.InstallerRegistryService; import org.eclipse.che.api.installer.shared.model.Installer; -import org.eclipse.che.api.core.rest.CheJsonProvider; -import org.eclipse.che.api.core.rest.MessageBodyAdapter; -import org.eclipse.che.api.core.rest.MessageBodyAdapterInterceptor; -import org.eclipse.che.api.factory.server.FactoryAcceptValidator; -import org.eclipse.che.api.factory.server.FactoryCreateValidator; -import org.eclipse.che.api.factory.server.FactoryEditValidator; -import org.eclipse.che.api.factory.server.FactoryParametersResolver; import org.eclipse.che.api.recipe.JpaRecipeDao; import org.eclipse.che.api.recipe.RecipeDao; import org.eclipse.che.api.recipe.RecipeLoader; import org.eclipse.che.api.recipe.RecipeService; import org.eclipse.che.api.user.server.TokenValidator; import org.eclipse.che.api.workspace.server.RemoveWorkspaceFilesAfterRemoveWorkspaceEventSubscriber; +import org.eclipse.che.api.workspace.server.URLRewriter; import org.eclipse.che.api.workspace.server.adapter.StackMessageBodyAdapter; import org.eclipse.che.api.workspace.server.adapter.WorkspaceConfigMessageBodyAdapter; import org.eclipse.che.api.workspace.server.adapter.WorkspaceMessageBodyAdapter; -import org.eclipse.che.api.workspace.server.spi.dummy.DummyInfrastructureModule; import org.eclipse.che.api.workspace.server.stack.StackLoader; import org.eclipse.che.core.db.schema.SchemaInitializer; import org.eclipse.che.inject.DynaModule; @@ -228,9 +228,9 @@ public class WsMasterModule extends AbstractModule { // bind(org.eclipse.che.api.agent.server.filters.AddExecInstallerInStackFilter.class); // FIXME: spi - install(new DummyInfrastructureModule()); install(new DockerInfraModule()); install(new LocalDockerModule()); bind(RemoveWorkspaceFilesAfterRemoveWorkspaceEventSubscriber.class).asEagerSingleton(); + bind(URLRewriter.class).to(URLRewriter.NoOpURLRewriter.class); } } diff --git a/wsmaster/che-core-api-workspace/pom.xml b/wsmaster/che-core-api-workspace/pom.xml index 1b2423a8d9..6ab3e650d3 100644 --- a/wsmaster/che-core-api-workspace/pom.xml +++ b/wsmaster/che-core-api-workspace/pom.xml @@ -37,10 +37,6 @@ com.google.inject guice - - com.google.inject.extensions - guice-multibindings - commons-fileupload commons-fileupload diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentHealthChecker.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentHealthChecker.java deleted file mode 100644 index 191bf28026..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentHealthChecker.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.api.agent.server; - -import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.core.model.workspace.runtime.Machine; -import org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto; - -/** - * Describes a mechanism for checking ws agent's state. - * It needs when Workspace Agent (WS Agent) stops to respond and projects disappear from the project tree, - * and the page shows 'Cannot get project types' error. - * It may happens for example, when OOM happens in a WS Agent and kernel kills WS Agent process. - * Problem here that we can't detect properly OOM error but we can check if WS Agent is alive for user. - *

- * If client (IDE) lost WebSocket connection to the WS Agent - in this case IDE will request some other service in our infrastructure to - * check WS Agent state, here we have two ways: - *

- * 1/ WS Agent was shutdown by OS. If it not available for this service too, a user should be notified that the workspace is broken - * probably because of OOM (it will be just suggest because we not sure about reason). - *

- * 2/ WS Agent is working well and is accessible for our infrastructure, in this case user has networking problem. It can be not - * well configured proxy server or other problems which are not related to our responsibility. - * - * @author Vitalii Parfonov - */ -// TODO spi -@Deprecated -public interface WsAgentHealthChecker { - - /** - * Verifies if ws agent is alive. - * - * @param machine - * machine instance - * @return state of the ws agent - * @throws ServerException - * if internal server error occurred - */ - WsAgentHealthStateDto check(Machine machine) throws ServerException; -} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentHealthCheckerImpl.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentHealthCheckerImpl.java deleted file mode 100644 index 0770aeeb7c..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentHealthCheckerImpl.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.api.agent.server; - -import org.eclipse.che.api.core.ApiException; -import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.core.model.workspace.runtime.Machine; -import org.eclipse.che.api.core.model.workspace.runtime.Server; -import org.eclipse.che.api.core.rest.HttpJsonRequest; -import org.eclipse.che.api.core.rest.HttpJsonResponse; -import org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import javax.inject.Singleton; -import java.io.IOException; -import java.util.Map; - -import static javax.ws.rs.core.Response.Status.NOT_FOUND; -import static javax.ws.rs.core.Response.Status.SERVICE_UNAVAILABLE; -import static org.eclipse.che.api.machine.shared.Constants.WSAGENT_REFERENCE; -import static org.eclipse.che.dto.server.DtoFactory.newDto; - -/** - * Mechanism for checking workspace agent's state. - * - * @author Vitalii Parfonov - * @author Valeriy Svydenko - */ -// TODO spi -@Deprecated -@Singleton -public class WsAgentHealthCheckerImpl implements WsAgentHealthChecker { - protected static final Logger LOG = LoggerFactory.getLogger(WsAgentHealthCheckerImpl.class); - - private final WsAgentPingRequestFactory wsAgentPingRequestFactory; - - @Inject - public WsAgentHealthCheckerImpl(WsAgentPingRequestFactory wsAgentPingRequestFactory) { - this.wsAgentPingRequestFactory = wsAgentPingRequestFactory; - } - - @Override - public WsAgentHealthStateDto check(Machine machine) throws ServerException { - Server wsAgent = getWsAgent(machine); - final WsAgentHealthStateDto agentHealthStateDto = newDto(WsAgentHealthStateDto.class); - if (wsAgent == null) { - return agentHealthStateDto.withCode(NOT_FOUND.getStatusCode()) - .withReason("Workspace Agent not available"); - } - try { - final HttpJsonRequest pingRequest = createPingRequest(machine); - final HttpJsonResponse response = pingRequest.request(); - return agentHealthStateDto.withCode(response.getResponseCode()); - } catch (ApiException | IOException e) { - return agentHealthStateDto.withCode(SERVICE_UNAVAILABLE.getStatusCode()) - .withReason(e.getMessage()); - } - } - - protected HttpJsonRequest createPingRequest(Machine machine) throws ServerException { - return wsAgentPingRequestFactory.createRequest(machine); - } - - private Server getWsAgent(Machine machine) { - final Map servers = machine.getServers(); - return servers.get(WSAGENT_REFERENCE); -// for (Server server : servers.values()) { -// if (WSAGENT_REFERENCE.equals(server.getRef())) { -// return server; -// } -// } -// return null; - } - -} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentPingRequestFactory.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentPingRequestFactory.java deleted file mode 100644 index 83127b5062..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/agent/server/WsAgentPingRequestFactory.java +++ /dev/null @@ -1,92 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.api.agent.server; - -import com.google.inject.Inject; -import com.google.inject.Singleton; - -import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.core.model.workspace.runtime.Machine; -import org.eclipse.che.api.core.model.workspace.runtime.Server; -import org.eclipse.che.api.core.rest.HttpJsonRequest; -import org.eclipse.che.api.core.rest.HttpJsonRequestFactory; -import org.eclipse.che.api.machine.shared.Constants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Named; -import javax.ws.rs.HttpMethod; -import java.util.Map; - -import static com.google.common.base.Strings.isNullOrEmpty; - -/** - * Creates a request for pinging Workspace Agent. - * - * @author Valeriy Svydenko - */ -// TODO spi -@Deprecated -@Singleton -public class WsAgentPingRequestFactory { - protected static final Logger LOG = LoggerFactory.getLogger(WsAgentPingRequestFactory.class); - - private static final String WS_AGENT_SERVER_NOT_FOUND_ERROR = "Workspace agent server not found in dev machine."; - private static final String WS_AGENT_URL_IS_NULL_OR_EMPTY_ERROR = "URL of Workspace Agent is null or empty."; - - private final HttpJsonRequestFactory httpJsonRequestFactory; - private final int wsAgentPingConnectionTimeoutMs; - - @Inject - public WsAgentPingRequestFactory(HttpJsonRequestFactory httpJsonRequestFactory, - @Named("che.workspace.agent.dev.ping_conn_timeout_ms") int wsAgentPingConnectionTimeoutMs) { - this.httpJsonRequestFactory = httpJsonRequestFactory; - this.wsAgentPingConnectionTimeoutMs = wsAgentPingConnectionTimeoutMs; - } - - /** - * Creates request which can check if workspace agent is pinging. - * - * @param machine - * machine instance - * @return instance of {@link HttpJsonRequest} - * @throws ServerException - * if internal server error occurred - */ - public HttpJsonRequest createRequest(Machine machine) throws ServerException { - Map servers = machine.getServers(); - Server wsAgentServer = servers.get(Constants.WSAGENT_REFERENCE); - - if (wsAgentServer == null) { -// LOG.error("{} WorkspaceId: {}, DevMachine Id: {}, found servers: {}", -// WS_AGENT_SERVER_NOT_FOUND_ERROR, machine.getWorkspaceId(), machine.getId(), servers); - throw new ServerException(WS_AGENT_SERVER_NOT_FOUND_ERROR); - } - - - // TODO temporary not internal - String wsAgentPingUrl = wsAgentServer.getUrl(); - - //String wsAgentPingUrl = wsAgentServer.getProperties().getInternalUrl(); - if (isNullOrEmpty(wsAgentPingUrl)) { - LOG.error(WS_AGENT_URL_IS_NULL_OR_EMPTY_ERROR); - throw new ServerException(WS_AGENT_URL_IS_NULL_OR_EMPTY_ERROR); - } - // since everrest mapped on the slash in case of it absence - // we will always obtain not found response - if (!wsAgentPingUrl.endsWith("/")) { - wsAgentPingUrl = wsAgentPingUrl.concat("/"); - } - return httpJsonRequestFactory.fromUrl(wsAgentPingUrl) - .setMethod(HttpMethod.GET) - .setTimeout(wsAgentPingConnectionTimeoutMs); - } -} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentException.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentException.java deleted file mode 100644 index 5c287c1243..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentException.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.api.environment.server.exception; - -/** - * Is thrown when environment bootstrapping fails for some reason. - * - * @author Alexander Garagatyi - */ -public class EnvironmentException extends Exception { - public EnvironmentException(String message) { - super(message); - } - - public EnvironmentException(String message, Throwable cause) { - super(message, cause); - } - - public EnvironmentException(Throwable cause) { - super(cause); - } -} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentNotRunningException.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentNotRunningException.java deleted file mode 100644 index 2871555b44..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentNotRunningException.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.api.environment.server.exception; - -import org.eclipse.che.api.core.NotFoundException; -import org.eclipse.che.api.core.rest.shared.dto.ServiceError; - -/** - * Exception thrown in case environment stop is called but no matching environment is running. - * - * @author Alexander Garagatyi - */ -public class EnvironmentNotRunningException extends NotFoundException { - public EnvironmentNotRunningException(String message) { - super(message); - } - - public EnvironmentNotRunningException(ServiceError serviceError) { - super(serviceError); - } -} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentStartInterruptedException.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentStartInterruptedException.java deleted file mode 100644 index 21629b71e6..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/exception/EnvironmentStartInterruptedException.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.api.environment.server.exception; - -/** - * Thrown when environment start is interrupted. - * - * @author Yevhenii Voevodin - */ -public class EnvironmentStartInterruptedException extends EnvironmentException { - public EnvironmentStartInterruptedException(String workspaceId, String envName) { - super(String.format("Start of environment '%s' in workspace '%s' is interrupted", - envName, - workspaceId)); - } -} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/NoopUrlRewriter.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/NoopUrlRewriter.java deleted file mode 100644 index 4b8b4149fb..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/NoopUrlRewriter.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.api.workspace.server; - -import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; - -import java.net.MalformedURLException; -import java.net.URL; - -/** - * @author Alexander Garagatyi - */ -public class NoopUrlRewriter implements URLRewriter { - @Override - public URL rewriteURL(RuntimeIdentity identity, String name, URL url) throws MalformedURLException { - return url; - } -} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/URLRewriter.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/URLRewriter.java index 59438950bc..e23f8018e0 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/URLRewriter.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/URLRewriter.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.che.api.workspace.server; -import com.google.inject.ImplementedBy; - import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; import java.net.MalformedURLException; @@ -23,9 +21,7 @@ import java.net.URL; * * @author gazarenkov */ -@ImplementedBy(NoopUrlRewriter.class) public interface URLRewriter { - /** * Rewrites URL according to Strategy rules. May depend on RuntimeIdentityImpl(workspace, owner,..) and name (some id) * of this particular URL @@ -37,4 +33,13 @@ public interface URLRewriter { */ URL rewriteURL(RuntimeIdentity identity, String name, URL url) throws MalformedURLException; + /** + * No rewriting, just pass internal URL back + */ + class NoOpURLRewriter implements URLRewriter { + @Override + public URL rewriteURL(RuntimeIdentity identity, String name, URL url) throws MalformedURLException { + return url; + } + } } diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceSharedPool.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceSharedPool.java index 483a3e9df7..cb4fce6ac3 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceSharedPool.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceSharedPool.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.che.api.workspace.server; -import com.google.common.base.Supplier; import com.google.common.primitives.Ints; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.inject.Inject; @@ -127,4 +126,4 @@ public class WorkspaceSharedPool { logger.info("Workspace threads pool is terminated"); } } -} \ No newline at end of file +} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/InternalRuntime.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/InternalRuntime.java index 5d79b09a56..d74e719b6b 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/InternalRuntime.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/InternalRuntime.java @@ -14,9 +14,9 @@ import org.eclipse.che.api.core.model.workspace.Runtime; import org.eclipse.che.api.core.model.workspace.Warning; import org.eclipse.che.api.core.model.workspace.WorkspaceStatus; import org.eclipse.che.api.core.model.workspace.runtime.Machine; -import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; import org.eclipse.che.api.core.model.workspace.runtime.Server; import org.eclipse.che.api.workspace.server.URLRewriter; +import org.eclipse.che.api.workspace.server.model.impl.MachineImpl; import org.eclipse.che.api.workspace.server.model.impl.ServerImpl; import org.slf4j.Logger; @@ -28,10 +28,12 @@ import java.util.List; import java.util.Map; import static java.lang.String.format; +import static java.util.stream.Collectors.toMap; import static org.slf4j.LoggerFactory.getLogger; /** * Implementation of concrete Runtime + * * @author gazarenkov */ public abstract class InternalRuntime implements Runtime { @@ -44,7 +46,7 @@ public abstract class InternalRuntime implements Runt public InternalRuntime(T context, URLRewriter urlRewriter) { this.context = context; - this.urlRewriter = urlRewriter != null ? urlRewriter : new NullUrlRewriter(); + this.urlRewriter = urlRewriter != null ? urlRewriter : new URLRewriter.NoOpURLRewriter(); } /** @@ -69,11 +71,12 @@ public abstract class InternalRuntime implements Runt @Override public Map getMachines() { - Map result = getInternalMachines(); - for (Machine machine : result.values()) { - rewriteExternalServers(machine.getServers()); - } - return result; + return getInternalMachines() + .entrySet() + .stream() + .collect(toMap(Map.Entry::getKey, + e -> new MachineImpl(e.getValue().getProperties(), + rewriteExternalServers(e.getValue().getServers())))); } /** @@ -185,14 +188,4 @@ public abstract class InternalRuntime implements Runt return outgoing; } - - /** - * No rewriting, just pass internal URL back - */ - private class NullUrlRewriter implements URLRewriter { - @Override - public URL rewriteURL(RuntimeIdentity identity, String name, URL url) throws MalformedURLException { - return url; - } - } } diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/dummy/DummyInfrastructureModule.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/dummy/DummyInfrastructureModule.java deleted file mode 100644 index 04091db24b..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/dummy/DummyInfrastructureModule.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.api.workspace.server.spi.dummy; - -import com.google.inject.AbstractModule; -import com.google.inject.multibindings.Multibinder; - -import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure; - -public class DummyInfrastructureModule extends AbstractModule { - @Override - protected void configure() { - Multibinder mb = Multibinder.newSetBinder(binder(), RuntimeInfrastructure.class); - mb.addBinding().to(DummyRuntimeInfrastructure.class); - } -} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/dummy/DummyRuntimeInfrastructure.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/dummy/DummyRuntimeInfrastructure.java deleted file mode 100644 index 3ec20b1e51..0000000000 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/spi/dummy/DummyRuntimeInfrastructure.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2017 Codenvy, S.A. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Codenvy, S.A. - initial API and implementation - *******************************************************************************/ -package org.eclipse.che.api.workspace.server.spi.dummy; - -import com.google.inject.Inject; -import com.google.inject.Singleton; - -import org.eclipse.che.api.core.ValidationException; -import org.eclipse.che.api.core.model.workspace.config.Environment; -import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity; -import org.eclipse.che.api.core.notification.EventService; -import org.eclipse.che.api.workspace.server.spi.InfrastructureException; -import org.eclipse.che.api.workspace.server.spi.RuntimeContext; -import org.eclipse.che.api.workspace.server.spi.RuntimeInfrastructure; - -import java.util.Collections; - -@Singleton -public class DummyRuntimeInfrastructure extends RuntimeInfrastructure { - - @Inject - public DummyRuntimeInfrastructure(EventService eventService) { - super("dummy", Collections.singletonList("dummy"), eventService); - } - - @Override - public Environment estimate(Environment environment) throws ValidationException, InfrastructureException { - return null; - } - - @Override - public RuntimeContext prepare(RuntimeIdentity id, Environment environment) throws ValidationException, InfrastructureException { - return null; - } -}