Code cleanup

6.19.x
Oleksandr Garagatyi 2017-07-04 15:04:49 +03:00
parent 8b4eaaf5fc
commit 72ed75be0c
14 changed files with 29 additions and 438 deletions

View File

@ -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);
}
}

View File

@ -37,10 +37,6 @@
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>

View File

@ -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.
* <p>
* 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:
* <p>
* 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).
* <p>
* 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;
}

View File

@ -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<String, ? extends Server> servers = machine.getServers();
return servers.get(WSAGENT_REFERENCE);
// for (Server server : servers.values()) {
// if (WSAGENT_REFERENCE.equals(server.getRef())) {
// return server;
// }
// }
// return null;
}
}

View File

@ -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<String, ? extends Server> 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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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 <T extends RuntimeContext> implements Runtime {
@ -44,7 +46,7 @@ public abstract class InternalRuntime <T extends RuntimeContext> 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 <T extends RuntimeContext> implements Runt
@Override
public Map<String, ? extends Machine> getMachines() {
Map<String, ? extends Machine> 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 <T extends RuntimeContext> 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;
}
}
}

View File

@ -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<RuntimeInfrastructure> mb = Multibinder.newSetBinder(binder(), RuntimeInfrastructure.class);
mb.addBinding().to(DummyRuntimeInfrastructure.class);
}
}

View File

@ -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;
}
}