diff --git a/agents/che-core-api-agent-shared/pom.xml b/agents/che-core-api-agent-shared/pom.xml index e634786f39..402d17e9ea 100644 --- a/agents/che-core-api-agent-shared/pom.xml +++ b/agents/che-core-api-agent-shared/pom.xml @@ -39,5 +39,9 @@ org.eclipse.che.core che-core-commons-annotations + + org.eclipse.che.core + che-core-commons-lang + diff --git a/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/AgentKey.java b/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/AgentKey.java index 7eee7cb1cd..513bf053e0 100644 --- a/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/AgentKey.java +++ b/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/AgentKey.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.che.api.agent.shared.model; -import org.eclipse.che.commons.annotation.Nullable; - /** * A pair of id and version of the agent. * Version part is not mandatory. @@ -27,6 +25,5 @@ public interface AgentKey { /** * @return the version of the agent */ - @Nullable String getVersion(); } diff --git a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentImpl.java b/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/impl/AgentImpl.java similarity index 98% rename from agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentImpl.java rename to agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/impl/AgentImpl.java index 4810a433b0..960fee2757 100644 --- a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentImpl.java +++ b/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/impl/AgentImpl.java @@ -8,7 +8,7 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.api.agent.server.model.impl; +package org.eclipse.che.api.agent.shared.model.impl; import org.eclipse.che.api.agent.shared.model.Agent; import org.eclipse.che.api.core.model.workspace.ServerConf2; diff --git a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentKeyImpl.java b/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/impl/AgentKeyImpl.java similarity index 82% rename from agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentKeyImpl.java rename to agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/impl/AgentKeyImpl.java index 48c17ff0ef..51bb544815 100644 --- a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentKeyImpl.java +++ b/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/impl/AgentKeyImpl.java @@ -8,8 +8,9 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.api.agent.server.model.impl; +package org.eclipse.che.api.agent.shared.model.impl; +import org.eclipse.che.api.agent.shared.model.Agent; import org.eclipse.che.api.agent.shared.model.AgentKey; import org.eclipse.che.commons.annotation.Nullable; @@ -19,16 +20,21 @@ import java.util.Objects; * @author Anatolii Bazko */ public class AgentKeyImpl implements AgentKey { + private static final String DEFAULT_VERSION = "latest"; private final String id; private final String version; public AgentKeyImpl(String id, @Nullable String version) { this.id = id; - this.version = version; + this.version = version == null ? DEFAULT_VERSION : version; } - public AgentKeyImpl(String name) { - this(name, null); + public AgentKeyImpl(String id) { + this(id, null); + } + + public AgentKeyImpl(Agent agent) { + this(agent.getId(), agent.getVersion()); } public String getId() { @@ -50,7 +56,7 @@ public class AgentKeyImpl implements AgentKey { String[] parts = agentKey.split(":"); if (parts.length == 1) { - return new AgentKeyImpl(parts[0], null); + return new AgentKeyImpl(parts[0]); } else if (parts.length == 2) { return new AgentKeyImpl(parts[0], parts[1]); } else { @@ -79,7 +85,7 @@ public class AgentKeyImpl implements AgentKey { @Override public String toString() { return "AgentImpl{" + - "name='" + id + '\'' + + "id='" + id + '\'' + ", version='" + version + "\'}"; } } diff --git a/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/impl/BasicAgent.java b/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/impl/BasicAgent.java new file mode 100644 index 0000000000..413b944490 --- /dev/null +++ b/agents/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/impl/BasicAgent.java @@ -0,0 +1,104 @@ +/******************************************************************************* + * 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.shared.model.impl; + +import org.eclipse.che.api.agent.shared.dto.AgentDto; +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.core.model.workspace.ServerConf2; +import org.eclipse.che.commons.lang.IoUtil; +import org.eclipse.che.dto.server.DtoFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; + +import static java.lang.String.format; +import static java.util.Collections.unmodifiableList; +import static java.util.Collections.unmodifiableMap; + +/** + * Basic implementation of the {@link Agent}. + * + * It is supposed that agent descriptor and agent script are located + * as resources in the jar. + * + * If resources aren't found then {@link Agent} won't be initialized. + * + * @author Anatolii Bazko + */ +public abstract class BasicAgent implements Agent { + private final Agent internal; + + public BasicAgent(String agentDescriptor, String agentScript) throws IOException { + internal = readAgentDescriptor(agentDescriptor, agentScript); + } + + @Override + public String getId() { + return internal.getId(); + } + + @Override + public String getName() { + return internal.getName(); + } + + @Override + public String getVersion() { + return internal.getVersion(); + } + + @Override + public String getDescription() { + return internal.getDescription(); + } + + @Override + public List getDependencies() { + return unmodifiableList(internal.getDependencies()); + } + + @Override + public String getScript() { + return internal.getScript(); + } + + @Override + public Map getProperties() { + return unmodifiableMap(internal.getProperties()); + } + + @Override + public Map getServers() { + return unmodifiableMap(internal.getServers()); + } + + private Agent readAgentDescriptor(String agentDescriptor, String agentScript) throws IOException { + InputStream inputStream = readResource(agentDescriptor); + AgentDto agent = DtoFactory.getInstance().createDtoFromJson(inputStream, AgentDto.class); + return agent.withScript(readAgentScript(agentScript)); + } + + private String readAgentScript(String agentScript) throws IOException { + InputStream inputStream = readResource(agentScript); + return IoUtil.readStream(inputStream); + } + + private InputStream readResource(String resource) throws IOException { + InputStream inputStream = getClass().getResourceAsStream("/" + resource); + if (inputStream == null) { + throw new IOException(format("Can't initialize agent. Resource %s not found", resource)); + } + return inputStream; + } + +} diff --git a/agents/che-core-api-agent/pom.xml b/agents/che-core-api-agent/pom.xml index 0a428c4c83..415c823d80 100644 --- a/agents/che-core-api-agent/pom.xml +++ b/agents/che-core-api-agent/pom.xml @@ -39,18 +39,10 @@ com.google.inject guice - - com.google.inject.extensions - guice-multibindings - io.swagger swagger-annotations - - javax.inject - javax.inject - javax.ws.rs javax.ws.rs-api diff --git a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryService.java b/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryService.java index aa50461b4d..f1f0c1bfb3 100644 --- a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryService.java +++ b/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryService.java @@ -20,7 +20,7 @@ import com.google.inject.Inject; import org.eclipse.che.api.agent.server.exception.AgentException; import org.eclipse.che.api.agent.server.exception.AgentNotFoundException; -import org.eclipse.che.api.agent.server.model.impl.AgentKeyImpl; +import org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl; import org.eclipse.che.api.agent.shared.dto.AgentDto; import org.eclipse.che.api.agent.shared.model.Agent; import org.eclipse.che.api.core.ApiException; diff --git a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryUrlProvider.java b/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryUrlProvider.java deleted file mode 100644 index 6d08ed1922..0000000000 --- a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryUrlProvider.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.agent.server; - -import org.eclipse.che.api.agent.server.exception.AgentException; -import org.eclipse.che.api.agent.shared.model.AgentKey; - -import java.net.URL; - -/** - * @author Anatolii Bazko - */ -public interface AgentRegistryUrlProvider { - /** - * Returns url to download agent of the specific version. - * - * @param agentKey - * the agent name and version - * @return {@link URL} - * @throws AgentException - * if unexpected error occurred - */ - URL getAgentUrl(AgentKey agentKey) throws AgentException; - - /** - * Returns url to fetch available versions of the agent. - - * @param name - * the agent id - * @return {@link URL} - * @throws AgentException - * if unexpected error occurred - */ - URL getAgentVersionsUrl(String id) throws AgentException; -} diff --git a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImpl.java b/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImpl.java new file mode 100644 index 0000000000..31b6f5716e --- /dev/null +++ b/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImpl.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * 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.impl; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.api.agent.server.AgentRegistry; +import org.eclipse.che.api.agent.server.exception.AgentException; +import org.eclipse.che.api.agent.server.exception.AgentNotFoundException; +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.AgentKey; +import org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import static java.lang.String.format; +import static java.util.Collections.unmodifiableCollection; + +/** + * Local implementation of the {@link AgentRegistry}. + * The name of the agent might represent a url. + * + * @author Anatoliy Bazko + */ +@Singleton +public class AgentRegistryImpl implements AgentRegistry { + + protected static final Logger LOG = LoggerFactory.getLogger(AgentRegistryImpl.class); + + private final Map agents; + + /** + * AgentRegistryImpl constructor. + * + * @param agents + * list of agents to register + * @throws IllegalArgumentException + * if there are several agents with same id and version + */ + @Inject + public AgentRegistryImpl(Set agents) throws IllegalArgumentException { + this.agents = new HashMap<>(agents.size()); + for (Agent agent : agents) { + AgentKeyImpl key = new AgentKeyImpl(agent); + Agent registeredAgent = this.agents.put(key, agent); + if (registeredAgent != null) { + throw new IllegalArgumentException(format("Agent with key %s has been registered already.", key)); + } + } + } + + @Override + public Agent getAgent(AgentKey agentKey) throws AgentException { + return doGetAgent(agentKey); + } + + @Override + public List getVersions(String id) throws AgentException { + return agents.entrySet().stream() + .filter(e -> e.getKey().getId().equals(id)) + .map(e -> e.getKey().getVersion()) + .collect(Collectors.toList()); + } + + @Override + public Collection getAgents() throws AgentException { + return unmodifiableCollection(agents.values()); + } + + private Agent doGetAgent(AgentKey key) throws AgentException { + Optional agent = Optional.ofNullable(agents.get(key)); + return agent.orElseThrow(() -> new AgentNotFoundException(format("Agent %s not found", key.getId()))); + } +} diff --git a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryUrlProviderImpl.java b/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryUrlProviderImpl.java deleted file mode 100644 index 70752189f2..0000000000 --- a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryUrlProviderImpl.java +++ /dev/null @@ -1,72 +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.impl; - -import com.google.inject.Inject; -import com.google.inject.Singleton; - -import org.eclipse.che.api.agent.server.AgentRegistryUrlProvider; -import org.eclipse.che.api.agent.server.exception.AgentException; -import org.eclipse.che.api.agent.shared.model.AgentKey; - -import javax.inject.Named; -import java.net.MalformedURLException; -import java.net.URL; - -/** - * Provides urls to agents. - * - * @author Anatolii Bazko - */ -@Singleton -public class AgentRegistryUrlProviderImpl implements AgentRegistryUrlProvider { - public static final String VERSION = "${version}"; - public static final String ID = "${id}"; - - private final String agentLatestVersionUrl; - private final String agentSpecificVersionUrl; - private final String agentVersionsUrl; - - @Inject - public AgentRegistryUrlProviderImpl(@Named("machine.agent.latest_version_url") String agentLatestVersionUrl, - @Named("machine.agent.specific_version_url") String agentSpecificVersionUrl, - @Named("machine.agent.all_versions_url") String agentVersionsUrl) { - this.agentLatestVersionUrl = agentLatestVersionUrl; - this.agentSpecificVersionUrl = agentSpecificVersionUrl; - this.agentVersionsUrl = agentVersionsUrl; - } - - @Override - public URL getAgentUrl(AgentKey agentKey) throws AgentException { - String url; - if (agentKey.getVersion() == null) { - url = agentLatestVersionUrl.replace(ID, agentKey.getId()); - } else { - url = agentSpecificVersionUrl.replace(ID, agentKey.getId()).replace(VERSION, agentKey.getVersion()); - } - try { - return new URL(url); - } catch (MalformedURLException e) { - throw new AgentException("Malformed url " + url, e); - } - } - - - @Override - public URL getAgentVersionsUrl(String id) throws AgentException { - String url = agentVersionsUrl.replace(ID, id); - try { - return new URL(url); - } catch (MalformedURLException e) { - throw new AgentException("Malformed url " + url, e); - } - } -} diff --git a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentSorter.java b/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentSorter.java index 44402a6b1c..8e1dc15efb 100644 --- a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentSorter.java +++ b/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentSorter.java @@ -15,7 +15,7 @@ import com.google.inject.Singleton; import org.eclipse.che.api.agent.server.AgentRegistry; import org.eclipse.che.api.agent.server.exception.AgentException; -import org.eclipse.che.api.agent.server.model.impl.AgentKeyImpl; +import org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl; import org.eclipse.che.api.agent.shared.model.Agent; import org.eclipse.che.api.agent.shared.model.AgentKey; import org.eclipse.che.commons.annotation.Nullable; diff --git a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImpl.java b/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImpl.java deleted file mode 100644 index 34ad73aed8..0000000000 --- a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImpl.java +++ /dev/null @@ -1,158 +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.impl; - -import com.google.common.collect.ImmutableList; -import com.google.inject.Inject; -import com.google.inject.Singleton; - -import org.eclipse.che.api.agent.server.AgentRegistry; -import org.eclipse.che.api.agent.server.exception.AgentException; -import org.eclipse.che.api.agent.server.exception.AgentNotFoundException; -import org.eclipse.che.api.agent.shared.dto.AgentDto; -import org.eclipse.che.api.agent.shared.model.Agent; -import org.eclipse.che.api.agent.shared.model.AgentKey; -import org.eclipse.che.api.core.util.FileCleaner; -import org.eclipse.che.commons.lang.ZipUtils; -import org.eclipse.che.dto.server.DtoFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.file.Files; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.regex.Pattern; -import java.util.zip.ZipFile; - -import static java.lang.String.format; -import static java.util.Collections.singletonList; -import static org.eclipse.che.commons.lang.IoUtil.downloadFile; -import static org.eclipse.che.commons.lang.IoUtil.readAndCloseQuietly; -import static org.eclipse.che.commons.lang.ZipUtils.isZipFile; - -/** - * Local implementation of the {@link AgentRegistry}. - * The name of the agent might represent a url. - * - * @author Anatoliy Bazko - */ -@Singleton -public class LocalAgentRegistryImpl implements AgentRegistry { - - protected static final Logger LOG = LoggerFactory.getLogger(LocalAgentRegistryImpl.class); - private static final Pattern AGENTS = Pattern.compile(".*[//]?agents/[^//]+[.]json"); - - private final Map agents; - private final List agentIds; - - @Inject - public LocalAgentRegistryImpl(Set agents) throws IOException { - - this.agents = new HashMap<>(); - findAgents(); - for (Agent agent : agents) { - this.agents.put(agent.getId(), agent); - } - this.agentIds = ImmutableList.copyOf(this.agents.keySet()); - } - - @Override - public Agent getAgent(AgentKey agentKey) throws AgentException { - return doGetAgent(agentKey.getId()); - } - - @Override - public List getVersions(String id) throws AgentException { - Agent agent = doGetAgent(id); - String version = agent.getVersion(); - return version == null ? Collections.emptyList() : singletonList(version); - } - - @Override - public Collection getAgents() throws AgentException { - return agents.values(); - } - - protected Agent doGetAgent(String id) throws AgentException { - try { - URL url = new URL(id); - return doGetRemoteAgent(url); - } catch (MalformedURLException ignored) { - // id doesn't represent a url - } - - Optional agent = Optional.ofNullable(agents.get(id)); - return agent.orElseThrow(() -> new AgentNotFoundException(format("Agent %s not found", id))); - } - - protected Agent doGetRemoteAgent(URL url) throws AgentException { - File agent = null; - try { - agent = downloadFile(new File(System.getProperty("java.io.tmpdir")), "agent", ".tmp", url); - String json = readAndCloseQuietly(new FileInputStream(agent)); - return DtoFactory.getInstance().createDtoFromJson(json, AgentDto.class); - } catch (IOException | IllegalArgumentException e) { - throw new AgentException("Can't fetch agent configuration", e); - } finally { - if (agent != null) { - try { - Files.delete(agent.toPath()); - } catch (IOException e) { - FileCleaner.addFile(agent); - } - } - } - } - - protected void findAgents() throws IOException { - File context = new File(LocalAgentRegistryImpl.class.getProtectionDomain().getCodeSource().getLocation().getPath()); - - if (isZipFile(context)) { - try (ZipFile zip = new ZipFile(context)) { - ZipUtils.getResources(zip, AGENTS, createAgentsConsumer); - } - } else { - Files.walk(context.toPath()) - .filter(path -> AGENTS.matcher(path.toString()).matches()) - .forEach(path -> { - try (InputStream in = Files.newInputStream(path)) { - createAgentsConsumer.accept(in); - } catch (IOException ignored) { - // ignore - } - }); - } - } - - private Consumer createAgentsConsumer = new Consumer() { - @Override - public void accept(InputStream inputStream) { - try { - final Agent agent = DtoFactory.getInstance().createDtoFromJson(inputStream, AgentDto.class); - agents.put(agent.getId(), agent); - } catch (IOException e) { - LOG.error("Can't create agent.", e); - } - } - }; -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.csharp.json b/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.csharp.json deleted file mode 100644 index 97369b2e17..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.csharp.json +++ /dev/null @@ -1,9 +0,0 @@ -{ -"id" : "org.eclipse.che.ls.csharp", -"name": "C# language server", -"description" : "C# intellisense", -"dependencies": [], -"properties": { -}, -"script" : "#\n# Copyright (c) 2012-2017 Codenvy, S.A.\n# All rights reserved. This program and the accompanying materials\n# are made available under the terms of the Eclipse Public License v1.0\n# which accompanies this distribution, and is available at\n# http://www.eclipse.org/legal/epl-v10.html\n#\n# Contributors:\n# Codenvy, S.A. - initial API and implementation\n#\n\nunset PACKAGES\nunset SUDO\ncommand -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" tar\"; }\ncommand -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" curl\"; }\ntest \"$(id -u)\" = 0 || SUDO=\"sudo\"\n\nAGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.csharp.binaries\nCHE_DIR=$HOME/che\nLS_DIR=${CHE_DIR}/ls-csharp\nLS_LAUNCHER=${LS_DIR}/launch.sh\n\nif [ -f /etc/centos-release ]; then\n FILE=\"/etc/centos-release\"\n LINUX_TYPE=$(cat $FILE | awk '{print $1}')\n elif [ -f /etc/redhat-release ]; then\n FILE=\"/etc/redhat-release\"\n LINUX_TYPE=$(cat $FILE | cut -c 1-8)\n else\n FILE=\"/etc/os-release\"\n LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')\n LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)\nfi\n\nMACHINE_TYPE=$(uname -m)\n\nmkdir -p ${CHE_DIR}\nmkdir -p ${LS_DIR}\n\n########################\n### Install packages ###\n########################\n\n# Red Hat Enterprise Linux 7\n############################\nif echo ${LINUX_TYPE} | grep -qi \"rhel\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n command -v dotnet >/dev/null 2>&1 || {\n ${SUDO} subscription-manager repos --enable=rhel-7-server-dotnet-rpms;\n ${SUDO} yum install scl-utils rh-dotnetcore10;\n ${SUDO} scl enable rh-dotnetcore10 bash;\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} yum -y install nodejs;\n }\n\n# Red Hat Enterprise Linux 6\n############################\nelif echo ${LINUX_TYPE} | grep -qi \"Red Hat\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n command -v dotnet >/dev/null 2>&1 || {\n ${SUDO} subscription-manager repos --enable=rhel-7-server-dotnet-rpms;\n ${SUDO} yum install scl-utils rh-dotnetcore10;\n ${SUDO} scl enable rh-dotnetcore10 bash;\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} yum -y install nodejs;\n }\n\n\n\n\n# Ubuntu 14.04 16.04 / Linux Mint 17\n####################################\nelif echo ${LINUX_TYPE} | grep -qi \"ubuntu\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n command -v dotnet >/dev/null 2>&1 || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install apt-transport-https;\n\n {\n if echo ${LINUX_VERSION} | grep -qi \"16.04\"; then\n ${SUDO} sh -c 'echo \"deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main\" > /etc/apt/sources.list.d/dotnetdev.list'\n ${SUDO} apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893\n else\n ${SUDO} sh -c 'echo \"deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main\" > /etc/apt/sources.list.d/dotnetdev.list'\n ${SUDO} apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893\n fi\n };\n\n ${SUDO} apt-get update\n ${SUDO} apt-get -y install dotnet-dev-1.0.0-preview2-003121\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n {\n if test \"${SUDO}\" = \"\"; then\n curl -sL https://deb.nodesource.com/setup_6.x | bash -;\n else\n curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} -E bash -;\n fi\n };\n\n ${SUDO} apt-get update;\n ${SUDO} apt-get install -y nodejs;\n }\n\n\n# Debian 8\n##########\nelif echo ${LINUX_TYPE} | grep -qi \"debian\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n command -v dotnet >/dev/null 2>&1 || {\n curl -L -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809130;\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install libunwind8 gettext;\n ${SUDO} mkdir -p /opt/dotnet;\n ${SUDO} tar zxf dotnet.tar.gz -C /opt/dotnet;\n rm dotnet.tar.gz;\n ${SUDO} ln -s /opt/dotnet/dotnet /usr/local/bin;\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n {\n if test \"${SUDO}\" = \"\"; then\n curl -sL https://deb.nodesource.com/setup_6.x | bash -;\n else\n curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} -E bash -;\n fi\n };\n\n ${SUDO} apt-get update;\n ${SUDO} apt-get install -y nodejs;\n }\n\n# Fedora 23\n###########\nelif echo ${LINUX_TYPE} | grep -qi \"fedora\"; then\n PACKAGES=${PACKAGES}\" procps-ng\"\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} dnf -y install ${PACKAGES};\n }\n\n command -v dotnet >/dev/null 2>&1 || {\n curl -L -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=816869;\n ${SUDO} dnf -y install libunwind libicu;\n ${SUDO} mkdir -p /opt/dotnet;\n ${SUDO} tar zxf dotnet.tar.gz -C /opt/dotnet;\n rm dotnet.tar.gz;\n ${SUDO} ln -s /opt/dotnet/dotnet /usr/local/bin;\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} dnf -y install nodejs;\n }\n\n\n\n# CentOS 7.1 & Oracle Linux 7.1\n###############################\nelif echo ${LINUX_TYPE} | grep -qi \"centos\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n command -v dotnet >/dev/null 2>&1 || {\n curl -L -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=809131;\n ${SUDO} yum -y install libunwind libicu;\n ${SUDO} mkdir -p /opt/dotnet;\n ${SUDO} tar zxf dotnet.tar.gz -C /opt/dotnet;\n rm dotnet.tar.gz;\n ${SUDO} ln -s /opt/dotnet/dotnet /usr/local/bin;\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -;\n ${SUDO} yum -y install nodejs;\n }\n\n\n# openSUSE 13.2\n###############\nelif echo ${LINUX_TYPE} | grep -qi \"opensuse\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} zypper install -y ${PACKAGES};\n }\n\n command -v dotnet >/dev/null 2>&1 || {\n curl -L -o dotnet.tar.gz https://go.microsoft.com/fwlink/?LinkID=816867;\n ${SUDO} zypper install -y libunwind libicu;\n ${SUDO} mkdir -p /opt/dotnet;\n ${SUDO} tar zxf dotnet.tar.gz -C /opt/dotnet;\n rm dotnet.tar.gz;\n ${SUDO} ln -s /opt/dotnet/dotnet /usr/local/bin;\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n ${SUDO} zypper ar http://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_13.1/ Node.js\n ${SUDO} zypper in nodejs\n }\n\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat /etc/os-release\n exit 1\nfi\n\n\n#####################\n### Install C# LS ###\n#####################\n\ncurl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${CHE_DIR}\n\ntouch ${LS_LAUNCHER}\nchmod +x ${LS_LAUNCHER}\necho \"nodejs ${LS_DIR}/node_modules/omnisharp-client/languageserver/server.js\" > ${LS_LAUNCHER}" -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.json.json b/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.json.json deleted file mode 100644 index 338bca9397..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.json.json +++ /dev/null @@ -1,9 +0,0 @@ -{ -"id": "org.eclipse.che.ls.json", -"name": "JSON language server", -"description" : "JSON intellisense", -"dependencies": [], -"properties": { -}, -"script" : "#\n# Copyright (c) 2012-2017 Codenvy, S.A.\n# All rights reserved. This program and the accompanying materials\n# are made available under the terms of the Eclipse Public License v1.0\n# which accompanies this distribution, and is available at\n# http://www.eclipse.org/legal/epl-v10.html\n#\n# Contributors:\n# Codenvy, S.A. - initial API and implementation\n#\n\nunset PACKAGES\nunset SUDO\ncommand -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" tar\"; }\ncommand -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" curl\"; }\ntest \"$(id -u)\" = 0 || SUDO=\"sudo\"\n\nAGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.json.binaries\nCHE_DIR=$HOME/che\nLS_DIR=${CHE_DIR}/ls-json\nLS_LAUNCHER=${LS_DIR}/launch.sh\n\nif [ -f /etc/centos-release ]; then\n FILE=\"/etc/centos-release\"\n LINUX_TYPE=$(cat $FILE | awk '{print $1}')\n elif [ -f /etc/redhat-release ]; then\n FILE=\"/etc/redhat-release\"\n LINUX_TYPE=$(cat $FILE | cut -c 1-8)\n else\n FILE=\"/etc/os-release\"\n LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')\n LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)\nfi\n\nMACHINE_TYPE=$(uname -m)\n\nmkdir -p ${CHE_DIR}\nmkdir -p ${LS_DIR}\n\n########################\n### Install packages ###\n########################\n\n# Red Hat Enterprise Linux 7\n############################\nif echo ${LINUX_TYPE} | grep -qi \"rhel\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} yum -y install nodejs;\n }\n\n# Red Hat Enterprise Linux 6\n############################\nelif echo ${LINUX_TYPE} | grep -qi \"Red Hat\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} yum -y install nodejs;\n }\n\n\n# Ubuntu 14.04 16.04 / Linux Mint 17\n####################################\nelif echo ${LINUX_TYPE} | grep -qi \"ubuntu\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n {\n if test \"${SUDO}\" = \"\"; then\n curl -sL https://deb.nodesource.com/setup_6.x | bash -;\n else\n curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} -E bash -;\n fi\n };\n\n ${SUDO} apt-get update;\n ${SUDO} apt-get install -y nodejs;\n }\n\n\n# Debian 8\n##########\nelif echo ${LINUX_TYPE} | grep -qi \"debian\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n {\n if test \"${SUDO}\" = \"\"; then\n curl -sL https://deb.nodesource.com/setup_6.x | bash -;\n else\n curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} -E bash -;\n fi\n };\n\n ${SUDO} apt-get update;\n ${SUDO} apt-get install -y nodejs;\n }\n\n# Fedora 23\n###########\nelif echo ${LINUX_TYPE} | grep -qi \"fedora\"; then\n command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" procps-ng\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} dnf -y install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} dnf -y install nodejs;\n }\n\n\n# CentOS 7.1 & Oracle Linux 7.1\n###############################\nelif echo ${LINUX_TYPE} | grep -qi \"centos\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} yum -y install nodejs;\n }\n\n# openSUSE 13.2\n###############\nelif echo ${LINUX_TYPE} | grep -qi \"opensuse\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} zypper install -y ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n ${SUDO} zypper ar http://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_13.1/ Node.js\n ${SUDO} zypper in nodejs\n }\n\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat $FILE\n exit 1\nfi\n\n\n#####################\n### Install C# LS ###\n#####################\n\ncurl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${LS_DIR}\n\ntouch ${LS_LAUNCHER}\nchmod +x ${LS_LAUNCHER}\necho \"nodejs ${LS_DIR}/vscode-json-server/server.js\" > ${LS_LAUNCHER}" -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.php.json b/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.php.json deleted file mode 100644 index 98800f4a5d..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.php.json +++ /dev/null @@ -1,8 +0,0 @@ -{ -"id": "org.eclipse.che.ls.php", -"name": "PHP language server", -"description": "PHP intellisense", -"dependencies": [], -"properties": {}, -"script" : "#\n# Copyright (c) 2012-2017 Codenvy, S.A.\n# All rights reserved. This program and the accompanying materials\n# are made available under the terms of the Eclipse Public License v1.0\n# which accompanies this distribution, and is available at\n# http://www.eclipse.org/legal/epl-v10.html\n#\n# Contributors:\n# Codenvy, S.A. - initial API and implementation\n#\n\nunset PACKAGES\nunset SUDO\ncommand -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" tar\"; }\ncommand -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" curl\"; }\ntest \"$(id -u)\" = 0 || SUDO=\"sudo\"\n\nAGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.php.binaries\nCHE_DIR=$HOME/che\nLS_DIR=${CHE_DIR}/ls-php\nLS_LAUNCHER=${LS_DIR}/launch.sh\n\nif [ -f /etc/centos-release ]; then\n FILE=\"/etc/centos-release\"\n LINUX_TYPE=$(cat $FILE | awk '{print $1}')\n elif [ -f /etc/redhat-release ]; then\n FILE=\"/etc/redhat-release\"\n LINUX_TYPE=$(cat $FILE | cut -c 1-8)\n else\n FILE=\"/etc/os-release\"\n LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')\n LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)\nfi\n\nMACHINE_TYPE=$(uname -m)\n\nmkdir -p ${CHE_DIR}\nmkdir -p ${LS_DIR}\n\n########################\n### Install packages ###\n########################\n\n# Red Hat Enterprise Linux 7\n############################\nif echo ${LINUX_TYPE} | grep -qi \"rhel\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n# Red Hat Enterprise Linux 6\n############################\nelif echo ${LINUX_TYPE} | grep -qi \"Red Hat\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n# Ubuntu 14.04 16.04 / Linux Mint 17\n####################################\nelif echo ${LINUX_TYPE} | grep -qi \"ubuntu\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n\n# Debian 8\n##########\nelif echo ${LINUX_TYPE} | grep -qi \"debian\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n# Fedora 23\n###########\nelif echo ${LINUX_TYPE} | grep -qi \"fedora\"; then\n command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" procps-ng\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} dnf -y install ${PACKAGES};\n }\n\n\n# CentOS 7.1 & Oracle Linux 7.1\n###############################\nelif echo ${LINUX_TYPE} | grep -qi \"centos\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n# openSUSE 13.2\n###############\nelif echo ${LINUX_TYPE} | grep -qi \"opensuse\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} zypper install -y ${PACKAGES};\n }\n\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat /etc/os-release\n exit 1\nfi\n\n\n######################\n### Install PHP LS ###\n######################\n\ncurl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${LS_DIR}\n\ntouch ${LS_LAUNCHER}\nchmod +x ${LS_LAUNCHER}\necho \"export LD_LIBRARY_PATH=${LS_DIR}/php7-minimal\" > ${LS_LAUNCHER}\necho \"${LS_DIR}/php7-minimal/php -c ${LS_DIR}/php7-minimal/php.ini ${LS_DIR}/php-language-server/bin/php-language-server.php\" >> ${LS_LAUNCHER}" -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.python.json b/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.python.json deleted file mode 100644 index 0b648f6dc4..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.python.json +++ /dev/null @@ -1,8 +0,0 @@ -{ -"id": "org.eclipse.che.ls.python", -"name": "Python language server", -"description": "Python intellisense", -"dependencies": [], -"properties": {}, -"script" : "#\n# Copyright (c) 2012-2017 Codenvy, S.A.\n# All rights reserved. This program and the accompanying materials\n# are made available under the terms of the Eclipse Public License v1.0\n# which accompanies this distribution, and is available at\n# http://www.eclipse.org/legal/epl-v10.html\n#\n# Contributors:\n# Codenvy, S.A. - initial API and implementation\n#\n\nunset PACKAGES\nunset SUDO\ncommand -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" tar\"; }\ncommand -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" curl\"; }\ntest \"$(id -u)\" = 0 || SUDO=\"sudo\"\n\nAGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.python.binaries\nCHE_DIR=$HOME/che\nLS_DIR=${CHE_DIR}/ls-python\nLS_LAUNCHER=${LS_DIR}/launch.sh\n\nif [ -f /etc/centos-release ]; then\n FILE=\"/etc/centos-release\"\n LINUX_TYPE=$(cat $FILE | awk '{print $1}')\n elif [ -f /etc/redhat-release ]; then\n FILE=\"/etc/redhat-release\"\n LINUX_TYPE=$(cat $FILE | cut -c 1-8)\n else\n FILE=\"/etc/os-release\"\n LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')\n LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)\nfi\n\nMACHINE_TYPE=$(uname -m)\n\nmkdir -p ${CHE_DIR}\nmkdir -p ${LS_DIR}\n\n########################\n### Install packages ###\n########################\n\n# Red Hat Enterprise Linux 7\n############################\nif echo ${LINUX_TYPE} | grep -qi \"rhel\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n command -v python3.5 >/dev/null 2>&1 || {\n ${SUDO} yum-config-manager --enable rhel-server-rhscl-7-rpms;\n ${SUDO} yum -y install rh-python35 bzip2;\n export LD_LIBRARY_PATH=\"/opt/rh/rh-python35/root/usr/lib64\"\n export PATH=\"/opt/rh/rh-python35/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\n echo \"export LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64\" >> $HOME/.bashrc\n echo \"export PATH=/opt/rh/rh-python35/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\" >> $HOME/.bashrc\n }\n\n# Red Hat Enterprise Linux 6\n############################\nelif echo ${LINUX_TYPE} | grep -qi \"Red Hat\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n command -v python3.5 >/dev/null 2>&1 || {\n ${SUDO} yum-config-manager --enable rhel-server-rhscl-7-rpms;\n ${SUDO} yum -y install rh-python35 bzip2;\n export LD_LIBRARY_PATH=\"/opt/rh/rh-python35/root/usr/lib64\"\n export PATH=\"/opt/rh/rh-python35/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\n echo \"export LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64\" >> $HOME/.bashrc\n echo \"export PATH=/opt/rh/rh-python35/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\" >> $HOME/.bashrc\n }\n\n\n# Ubuntu 14.04 16.04 / Linux Mint 17\n####################################\nelif echo ${LINUX_TYPE} | grep -qi \"ubuntu\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n command -v python3.5 >/dev/null 2>&1 || {\n if echo ${LINUX_VERSION} | grep -qi \"14.04\"; then\n DEADSNAKES=\"/etc/apt/sources.list.d/deadsnakes.list\";\n ${SUDO} touch ${DEADSNAKES};\n echo \"deb http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu trusty main\" | ${SUDO} tee --append ${DEADSNAKES};\n echo \"deb-src http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu trusty main\" | ${SUDO} tee --append ${DEADSNAKES};\n ${SUDO} gpg --keyserver keyserver.ubuntu.com --recv-keys DB82666C;\n ${SUDO} gpg --export DB82666C | ${SUDO} apt-key add -;\n\n ${SUDO} apt-get update;\n ${SUDO} apt-get install -y python3.5 bzip2;\n ${SUDO} curl https://bootstrap.pypa.io/ez_setup.py -o - | ${SUDO} python3.5\n ${SUDO} easy_install pip\n else\n ${SUDO} apt-get update;\n ${SUDO} apt-get install -y python3.5;\n ${SUDO} apt-get install -y python3-pip;\n fi\n }\n\n\n# Debian 8\n##########\nelif echo ${LINUX_TYPE} | grep -qi \"debian\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n command -v python3.5 >/dev/null 2>&1 || {\n DEADSNAKES=\"/etc/apt/sources.list.d/deadsnakes.list\";\n ${SUDO} touch ${DEADSNAKES};\n echo \"deb http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu trusty main\" | ${SUDO} tee --append ${DEADSNAKES};\n echo \"deb-src http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu trusty main\" | ${SUDO} tee --append ${DEADSNAKES};\n ${SUDO} gpg --keyserver keyserver.ubuntu.com --recv-keys DB82666C;\n ${SUDO} gpg --export DB82666C | ${SUDO} apt-key add -;\n\n ${SUDO} apt-get update;\n ${SUDO} apt-get install -y python3.5 bzip2;\n ${SUDO} curl https://bootstrap.pypa.io/ez_setup.py -o - | ${SUDO} python3.5\n ${SUDO} easy_install pip\n }\n\n# Fedora 23\n###########\nelif echo ${LINUX_TYPE} | grep -qi \"fedora\"; then\n PACKAGES=${PACKAGES}\" procps-ng\"\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} dnf -y install ${PACKAGES};\n }\n\n command -v python3.5 >/dev/null 2>&1 || {\n ${SUDO} dnf -y install python35 bzip2;\n ${SUDO} curl https://bootstrap.pypa.io/ez_setup.py -o - | ${SUDO} python3.5\n ${SUDO} easy_install pip\n }\n\n\n# CentOS 7.1 & Oracle Linux 7.1\n###############################\nelif echo ${LINUX_TYPE} | grep -qi \"centos\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n command -v python3.5 >/dev/null 2>&1 || {\n\n ${SUDO} yum -y install centos-release-scl;\n ${SUDO} yum -y install rh-python35 bzip2;\n export LD_LIBRARY_PATH=\"/opt/rh/rh-python35/root/usr/lib64\"\n export PATH=\"/opt/rh/rh-python35/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\n echo \"export LD_LIBRARY_PATH=/opt/rh/rh-python35/root/usr/lib64\" >> $HOME/.bashrc\n echo \"export PATH=/opt/rh/rh-python35/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\" >> $HOME/.bashrc\n }\n\n# openSUSE 13.2\n###############\nelif echo ${LINUX_TYPE} | grep -qi \"opensuse\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} zypper install -y ${PACKAGES};\n }\n\n command -v python3.5 >/dev/null 2>&1 || {\n ${SUDO} zypper ar -f http://download.opensuse.org/repositories/home:/Ledest:/bashisms/openSUSE_13.2/ home:Ledest:bashisms\n ${SUDO} zypper --no-gpg-checks ref\n ${SUDO} zypper install -y python3\n ${SUDO} zypper install -y python3-pip\n }\n\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat $FILE\n exit 1\nfi\n\n\n#########################\n### Install Python LS ###\n#########################\n\ncurl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${LS_DIR}\n\ncd ${LS_DIR} && ${SUDO} pip3 install -r ${LS_DIR}/requirements.txt\n\ntouch ${LS_LAUNCHER}\nchmod +x ${LS_LAUNCHER}\necho \"python3.5 ${LS_DIR}/python-langserver.py --fs=local --mode=stdio\" > ${LS_LAUNCHER}" -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.typescript.json b/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.typescript.json deleted file mode 100644 index e740b3b854..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.typescript.json +++ /dev/null @@ -1,9 +0,0 @@ -{ -"id": "org.eclipse.che.ls.js-ts", -"name": "TypeScript language server", -"description" : "TypeScript intellisense", -"dependencies": [], -"properties": { -}, -"script" : "#\n# Copyright (c) 2012-2017 Codenvy, S.A.\n# All rights reserved. This program and the accompanying materials\n# are made available under the terms of the Eclipse Public License v1.0\n# which accompanies this distribution, and is available at\n# http://www.eclipse.org/legal/epl-v10.html\n#\n# Contributors:\n# Codenvy, S.A. - initial API and implementation\n#\n\nunset PACKAGES\nunset SUDO\ncommand -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" tar\"; }\ncommand -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" curl\"; }\ntest \"$(id -u)\" = 0 || SUDO=\"sudo\"\n\nAGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.typescript.binaries\nCHE_DIR=$HOME/che\nLS_DIR=${CHE_DIR}/ls-typescript\nLS_LAUNCHER=${LS_DIR}/launch.sh\n\nif [ -f /etc/centos-release ]; then\n FILE=\"/etc/centos-release\"\n LINUX_TYPE=$(cat $FILE | awk '{print $1}')\n elif [ -f /etc/redhat-release ]; then\n FILE=\"/etc/redhat-release\"\n LINUX_TYPE=$(cat $FILE | cut -c 1-8)\n else\n FILE=\"/etc/os-release\"\n LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')\n LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)\nfi\n\nMACHINE_TYPE=$(uname -m)\n\nmkdir -p ${CHE_DIR}\nmkdir -p ${LS_DIR}\n\n########################\n### Install packages ###\n########################\n\n# Red Hat Enterprise Linux 7\n############################\nif echo ${LINUX_TYPE} | grep -qi \"rhel\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} yum -y install nodejs;\n }\n\n# Red Hat Enterprise Linux 6\n############################\nelif echo ${LINUX_TYPE} | grep -qi \"Red Hat\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} yum -y install nodejs;\n }\n\n\n# Ubuntu 14.04 16.04 / Linux Mint 17\n####################################\nelif echo ${LINUX_TYPE} | grep -qi \"ubuntu\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n {\n if test \"${SUDO}\" = \"\"; then\n curl -sL https://deb.nodesource.com/setup_6.x | bash -;\n else\n curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} -E bash -;\n fi\n };\n\n ${SUDO} apt-get update;\n ${SUDO} apt-get install -y nodejs;\n }\n\n\n# Debian 8\n##########\nelif echo ${LINUX_TYPE} | grep -qi \"debian\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n {\n if test \"${SUDO}\" = \"\"; then\n curl -sL https://deb.nodesource.com/setup_6.x | bash -;\n else\n curl -sL https://deb.nodesource.com/setup_6.x | ${SUDO} -E bash -;\n fi\n };\n\n ${SUDO} apt-get update;\n ${SUDO} apt-get install -y nodejs;\n }\n\n# Fedora 23\n###########\nelif echo ${LINUX_TYPE} | grep -qi \"fedora\"; then\n command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" procps-ng\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} dnf -y install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} dnf -y install nodejs;\n }\n\n\n# CentOS 7.1 & Oracle Linux 7.1\n###############################\nelif echo ${LINUX_TYPE} | grep -qi \"centos\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n curl --silent --location https://rpm.nodesource.com/setup_6.x | ${SUDO} bash -;\n ${SUDO} yum -y install nodejs;\n }\n\n# openSUSE 13.2\n###############\nelif echo ${LINUX_TYPE} | grep -qi \"opensuse\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} zypper install -y ${PACKAGES};\n }\n\n command -v nodejs >/dev/null 2>&1 || {\n ${SUDO} zypper ar http://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_13.1/ Node.js\n ${SUDO} zypper in nodejs\n }\n\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat $FILE\n exit 1\nfi\n\n\n########################\n### Install JS-TS LS ###\n########################\n\ncurl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${LS_DIR}\n\ntouch ${LS_LAUNCHER}\nchmod +x ${LS_LAUNCHER}\necho \"nodejs ${LS_DIR}/build/language-server-stdio.js\" > ${LS_LAUNCHER}" -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ssh.json b/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ssh.json deleted file mode 100644 index f035d9197b..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ssh.json +++ /dev/null @@ -1,13 +0,0 @@ -{ -"id": "org.eclipse.che.ssh", -"name": "SSH", -"description": "SSH server, key-pair generation", -"dependencies": [], -"properties": {}, -"servers": { -"ssh": { -"port": "22/tcp" -} -}, -"script" : "#\n# Copyright (c) 2012-2017 Codenvy, S.A.\n# All rights reserved. This program and the accompanying materials\n# are made available under the terms of the Eclipse Public License v1.0\n# which accompanies this distribution, and is available at\n# http://www.eclipse.org/legal/epl-v10.html\n#\n# Contributors:\n# Codenvy, S.A. - initial API and implementation\n#\n\nunset SUDO\nunset PACKAGES\ntest \"$(id -u)\" = 0 || SUDO=\"sudo\"\n\nif [ -f /etc/centos-release ]; then\n FILE=\"/etc/centos-release\"\n LINUX_TYPE=$(cat $FILE | awk '{print $1}')\n elif [ -f /etc/redhat-release ]; then\n FILE=\"/etc/redhat-release\"\n LINUX_TYPE=$(cat $FILE | cut -c 1-8)\n else\n FILE=\"/etc/os-release\"\n LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')\n LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)\nfi\n\n###############################\n### Install Needed packaged ###\n###############################\n\n# Red Hat Enterprise Linux 7 \n############################\nif echo ${LINUX_TYPE} | grep -qi \"rhel\"; then\n command -v sshd >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" openssh-server\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n ${SUDO} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n\n# Red Hat Enterprise Linux 6 \n############################\nelif echo ${LINUX_TYPE} | grep -qi \"Red Hat\"; then\n command -v sshd >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" openssh-server\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n ${SUDO} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n\n# Ubuntu 14.04 16.04 / Linux Mint 17 \n####################################\nelif echo ${LINUX_TYPE} | grep -qi \"ubuntu\"; then\n command -v sshd >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" openssh-server\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n ${SUDO} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n\n# Debian 8\n##########\nelif echo ${LINUX_TYPE} | grep -qi \"debian\"; then\n command -v sshd >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" openssh-server\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n ${SUDO} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n\n# Fedora 23\n###########\nelif echo ${LINUX_TYPE} | grep -qi \"fedora\"; then\n command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" procps-ng\"; }\n command -v sshd >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" openssh-server\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} dnf -y install ${PACKAGES};\n }\n ${SUDO} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n\n# CentOS 7.1 & Oracle Linux 7.1\n###############################\nelif echo ${LINUX_TYPE} | grep -qi \"centos\"; then\n command -v sshd >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" openssh-server\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n ${SUDO} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n\n# openSUSE 13.2\n###############\nelif echo ${LINUX_TYPE} | grep -qi \"opensuse\"; then\n command -v sshd >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" openSSH\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} zypper install -y ${PACKAGES};\n }\n ${SUDO} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n\n# Alpine 3.3\n############$$\nelif echo ${LINUX_TYPE} | grep -qi \"alpine\"; then\n command -v sshd >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" openssh\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apk update;\n ${SUDO} apk add openssh ${PACKAGES};\n }\n\n# Centos 6.6, 6.7, 6.8\n############\nelif echo ${LINUX_TYPE} | grep -qi \"CentOS\"; then\n command -v sshd >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" openssh-server\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n ${SUDO} sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd\n\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat $FILE\n exit 1\nfi\n\ncommand -v pidof >/dev/null 2>&1 && {\n pidof sshd >/dev/null 2>&1 && exit\n} || {\n ps -fC sshd >/dev/null 2>&1 && exit\n}\n\n\n${SUDO} mkdir -p /var/run/sshd\n\nif echo ${LINUX_TYPE} | grep -qi \"CentOS\"; then\n ${SUDO} /usr/bin/ssh-keygen -q -P '' -t rsa -f ~/.ssh/id_rsa\nelse\n ${SUDO} /usr/bin/ssh-keygen -A\nfi\n\n${SUDO} /usr/sbin/sshd -D\n" -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.terminal.json b/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.terminal.json deleted file mode 100644 index 9391f05670..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.terminal.json +++ /dev/null @@ -1,14 +0,0 @@ -{ -"id": "org.eclipse.che.terminal", -"name": "Terminal", -"description": "Embedded web terminal", -"dependencies": [], -"properties": {}, -"servers": { -"terminal": { -"port": "4411/tcp", -"protocol": "http" -} -}, -"script" : "#\n# Copyright (c) 2012-2017 Codenvy, S.A.\n# All rights reserved. This program and the accompanying materials\n# are made available under the terms of the Eclipse Public License v1.0\n# which accompanies this distribution, and is available at\n# http://www.eclipse.org/legal/epl-v10.html\n#\n# Contributors:\n# Codenvy, S.A. - initial API and implementation\n#\n\nunset PACKAGES\nunset SUDO\ncommand -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" tar\"; }\ncommand -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" curl\"; }\ntest \"$(id -u)\" = 0 || SUDO=\"sudo\"\n\nCHE_DIR=$HOME/che\nLOCAL_AGENT_BINARIES_URI='/mnt/che/terminal/websocket-terminal-${PREFIX}.tar.gz'\nDOWNLOAD_AGENT_BINARIES_URI='${WORKSPACE_MASTER_URI}/agent-binaries/${PREFIX}/terminal/websocket-terminal-${PREFIX}.tar.gz'\nTARGET_AGENT_BINARIES_URI='file://${CHE_DIR}/websocket-terminal-${PREFIX}.tar.gz'\n\nif [ -f /etc/centos-release ]; then\n FILE=\"/etc/centos-release\"\n LINUX_TYPE=$(cat $FILE | awk '{print $1}')\n elif [ -f /etc/redhat-release ]; then\n FILE=\"/etc/redhat-release\"\n LINUX_TYPE=$(cat $FILE | cut -c 1-8)\n else\n FILE=\"/etc/os-release\"\n LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')\n LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)\nfi\nMACHINE_TYPE=$(uname -m)\nSHELL_INTERPRETER=\"/bin/sh\"\n\n\nmkdir -p ${CHE_DIR}\n\n########################\n### Install packages ###\n########################\n\n# Red Hat Enterprise Linux 7 \n############################\nif echo ${LINUX_TYPE} | grep -qi \"rhel\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n# Ubuntu 14.04 16.04 / Linux Mint 17 \n####################################\nelif echo ${LINUX_TYPE} | grep -qi \"ubuntu\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n# Debian 8\n##########\nelif echo ${LINUX_TYPE} | grep -qi \"debian\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n# Fedora 23 \n###########\nelif echo ${LINUX_TYPE} | grep -qi \"fedora\"; then\n command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" procps-ng\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} dnf -y install ${PACKAGES};\n }\n\n# CentOS 7.1 & Oracle Linux 7.1\n###############################\nelif echo ${LINUX_TYPE} | grep -qi \"centos\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n# openSUSE 13.2\n###############\nelif echo ${LINUX_TYPE} | grep -qi \"opensuse\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} zypper install -y ${PACKAGES};\n }\n\n# Alpine 3.3\n############\nelif echo ${LINUX_TYPE} | grep -qi \"alpine\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apk update\n ${SUDO} apk add ${PACKAGES};\n }\n\n# Centos 6.6, 6.7, 6.8\n############\nelif echo ${LINUX_TYPE} | grep -qi \"CentOS\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n# Red Hat Enterprise Linux 6 \n############################\n\nelif echo ${LINUX_TYPE} | grep -qi \"Red Hat\"; then\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat $FILE\n exit 1\nfi\n\ncommand -v pidof >/dev/null 2>&1 && {\n pidof che-websocket-terminal >/dev/null 2>&1 && exit\n} || {\n ps -fC che-websocket-terminal >/dev/null 2>&1 && exit\n}\n\n\n########################\n### Install Terminal ###\n########################\nif echo ${MACHINE_TYPE} | grep -qi \"x86_64\"; then\n PREFIX=linux_amd64\nelif echo ${MACHINE_TYPE} | grep -qi \"arm5\"; then\n PREFIX=linux_arm7\nelif echo ${MACHINE_TYPE} | grep -qi \"arm6\"; then\n PREFIX=linux_arm7\nelif echo ${MACHINE_TYPE} | grep -qi \"arm7\"; then\n PREFIX=linux_arm7\nelif echo ${MACHINE_TYPE} | grep -qi \"armv7l\"; then\n PREFIX=linux_arm7\nelse\n >&2 echo \"Unrecognized Machine Type\"\n >&2 uname -a\n exit 1\nfi\n\n# Compute URI of workspace master\nWORKSPACE_MASTER_URI=$(echo $CHE_API | cut -d / -f 1-3)\n\n## Evaluate variables now that prefix is defined\neval \"LOCAL_AGENT_BINARIES_URI=${LOCAL_AGENT_BINARIES_URI}\"\neval \"DOWNLOAD_AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}\"\neval \"TARGET_AGENT_BINARIES_URI=${TARGET_AGENT_BINARIES_URI}\"\n\nif [ -f \"${LOCAL_AGENT_BINARIES_URI}\" ]; then\n AGENT_BINARIES_URI=\"file://${LOCAL_AGENT_BINARIES_URI}\"\nelif [ -f $(echo \"${LOCAL_AGENT_BINARIES_URI}\" | sed \"s/-${PREFIX}//g\") ]; then\n AGENT_BINARIES_URI=\"file://\"$(echo \"${LOCAL_AGENT_BINARIES_URI}\" | sed \"s/-${PREFIX}//g\")\nelse\n echo \"Terminal Agent will be downloaded from Workspace Master\"\n AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}\nfi\n\n\nif curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g'); then\n curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\\/\\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g')\nelif curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/-\\${PREFIX}//g'); then\n curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\\/\\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/-\\${PREFIX}//g')\nfi\n\ncurl -s $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g') | tar xzf - -C ${CHE_DIR}\n\nif [ -f /bin/bash ]; then\n SHELL_INTERPRETER=\"/bin/bash\"\nfi\n\n#####################################################\n### terminal-agent run command will be added here ###\n#####################################################" -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.unison.json b/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.unison.json deleted file mode 100644 index b547cabf73..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.unison.json +++ /dev/null @@ -1,8 +0,0 @@ -{ -"id": "org.eclipse.che.unison", -"name": "File Sync", -"description": "Unison File Synchronizer", -"dependencies": [], -"properties": {}, -"script" : "#\n# Copyright (c) 2012-2017 Codenvy, S.A.\n# All rights reserved. This program and the accompanying materials\n# are made available under the terms of the Eclipse Public License v1.0\n# which accompanies this distribution, and is available at\n# http://www.eclipse.org/legal/epl-v10.html\n#\n# Contributors:\n# Codenvy, S.A. - initial API and implementation\n#\n\nunset SUDO\nunset PACKAGES\ntest \"$(id -u)\" = 0 || SUDO=\"sudo\"\n\nif [ -f /etc/centos-release ]; then\n FILE=\"/etc/centos-release\"\n LINUX_TYPE=$(cat $FILE | awk '{print $1}')\n elif [ -f /etc/redhat-release ]; then\n FILE=\"/etc/redhat-release\"\n LINUX_TYPE=$(cat $FILE | cut -c 1-8)\n else\n FILE=\"/etc/os-release\"\n LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')\n LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)\nfi\n\n###############################\n### Install Needed packaged ###\n###############################\n\n# Red Hat Enterprise Linux 7 \n############################\nif echo ${LINUX_TYPE} | grep -qi \"rhel\"; then\n command -v unison >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" unison\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n# Red Hat Enterprise Linux 6 \n############################\nelif echo ${LINUX_TYPE} | grep -qi \"Red Hat\"; then\n command -v unison >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" unison\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n# Ubuntu 14.04 16.04 / Linux Mint 17 \n####################################\nelif echo ${LINUX_TYPE} | grep -qi \"ubuntu\"; then\n command -v unison >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" unison\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n# Debian 8\n##########\nelif echo ${LINUX_TYPE} | grep -qi \"debian\"; then\n command -v unison >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" unison\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n# Fedora 23\n###########\nelif echo ${LINUX_TYPE} | grep -qi \"fedora\"; then\n command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" procps-ng\"; }\n command -v unison >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" unison\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} dnf -y install ${PACKAGES};\n }\n\n# CentOS 7.1 & Oracle Linux 7.1\n###############################\nelif echo ${LINUX_TYPE} | grep -qi \"centos\"; then\n command -v unison >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" unison\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n# openSUSE 13.2\n###############\nelif echo ${LINUX_TYPE} | grep -qi \"opensuse\"; then\n command -v unison >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" unison\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} zypper install -y ${PACKAGES};\n }\n\n# Alpine 3.3\n############$$\nelif echo ${LINUX_TYPE} | grep -qi \"alpine\"; then\n command -v unison >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" unison\"; }\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apk update;\n ${SUDO} apk add ${PACKAGES};\n }\n\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat /etc/os-release\n exit 1\nfi" -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ws-agent.json b/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ws-agent.json deleted file mode 100644 index 3162c1610a..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ws-agent.json +++ /dev/null @@ -1,19 +0,0 @@ -{ -"id": "org.eclipse.che.ws-agent", -"name": "Workspace API", -"description": "Workspace API support", -"dependencies": [ -"org.eclipse.che.terminal" -], -"properties": {}, -"servers": { -"wsagent": { -"port": "4401/tcp", -"protocol": "http", -"properties": { -"path": "/api" -} -} -}, -"script" : "#\n# Copyright (c) 2012-2017 Codenvy, S.A.\n# All rights reserved. This program and the accompanying materials\n# are made available under the terms of the Eclipse Public License v1.0\n# which accompanies this distribution, and is available at\n# http://www.eclipse.org/legal/epl-v10.html\n#\n# Contributors:\n# Codenvy, S.A. - initial API and implementation\n#\n\nunset PACKAGES\nunset SUDO\ncommand -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" tar\"; }\ncommand -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" curl\"; }\ntest \"$(id -u)\" = 0 || SUDO=\"sudo\"\n\nLOCAL_AGENT_BINARIES_URI=\"/mnt/che/ws-agent.tar.gz\"\nDOWNLOAD_AGENT_BINARIES_URI='${WORKSPACE_MASTER_URI}/agent-binaries/ws-agent.tar.gz'\n\nCHE_DIR=$HOME/che\n\nif [ -f /etc/centos-release ]; then\n FILE=\"/etc/centos-release\"\n LINUX_TYPE=$(cat $FILE | awk '{print $1}')\n elif [ -f /etc/redhat-release ]; then\n FILE=\"/etc/redhat-release\"\n LINUX_TYPE=$(cat $FILE | cut -c 1-8)\n else\n FILE=\"/etc/os-release\"\n LINUX_TYPE=$(cat $FILE | grep ^ID= | tr '[:upper:]' '[:lower:]')\n LINUX_VERSION=$(cat $FILE | grep ^VERSION_ID=)\nfi\nMACHINE_TYPE=$(uname -m)\n\nmkdir -p ${CHE_DIR}\n${SUDO} mkdir -p /projects\n${SUDO} sh -c \"chown -R $(id -u -n) /projects\"\n\n\nINSTALL_JDK=false\ncommand -v ${JAVA_HOME}/bin/java >/dev/null 2>&1 || {\n INSTALL_JDK=true;\n} && {\n java_version=$(${JAVA_HOME}/bin/java -version 2>&1 | sed 's/.* version \"\\(.*\\)\\.\\(.*\\)\\..*\"/\\1\\2/; 1q')\n if [ ! -z \"${java_version##*[!0-9]*}\" ] && [ \"${java_version}\" -lt \"18\" ]; then\n INSTALL_JDK=true;\n fi\n}\n\nif [ ${INSTALL_JDK} = true ]; then\n export JAVA_HOME=${CHE_DIR}/jdk1.8\nfi\n\n\n########################\n### Install packages ###\n########################\n\n# Red Hat Enterprise Linux 7\n############################\nif echo ${LINUX_TYPE} | grep -qi \"rhel\"; then\n\n if [ ${INSTALL_JDK} = true ]; then\n PACKAGES=${PACKAGES}\" java-1.8.0-openjdk-devel.x86_64\"\n fi\n\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n if [ ${INSTALL_JDK} = true ]; then\n ln -s /usr/lib/jvm/java-1.8.0-openjdk $JAVA_HOME\n fi\n\n# Ubuntu 14.04 16.04 / Linux Mint 17\n####################################\nelif echo ${LINUX_TYPE} | grep -qi \"ubuntu\"; then\n\n if [ ${INSTALL_JDK} = true ]; then\n PACKAGES=${PACKAGES}\" openjdk-8-jdk-headless\"\n ${SUDO} apt-get install -y software-properties-common;\n ${SUDO} add-apt-repository ppa:openjdk-r/ppa;\n fi\n\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n if [ ${INSTALL_JDK} = true ]; then\n ln -s /usr/lib/jvm/java-1.8.0-openjdk-amd64 $JAVA_HOME\n fi\n\n# Debian 8\n##########\nelif echo ${LINUX_TYPE} | grep -qi \"debian\"; then\n\n if [ ${INSTALL_JDK} = true ]; then\n PACKAGES=${PACKAGES}\" openjdk-8-jdk-headless\";\n echo \"deb http://httpredir.debian.org/debian jessie-backports main\" | ${SUDO} tee --append /etc/apt/sources.list\n fi\n\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apt-get update;\n ${SUDO} apt-get -y install ${PACKAGES};\n }\n\n if [ ${INSTALL_JDK} = true ]; then\n ln -s /usr/lib/jvm/java-1.8.0-openjdk-amd64 $JAVA_HOME\n fi\n\n\n# Fedora 23\n###########\nelif echo ${LINUX_TYPE} | grep -qi \"fedora\"; then\n\n command -v ps >/dev/null 2>&1 || { PACKAGES=${PACKAGES}\" procps-ng\"; }\n if [ ${INSTALL_JDK} = true ]; then\n PACKAGES=${PACKAGES}\" java-1.8.0-openjdk-devel.x86_64\";\n fi\n\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} dnf -y install ${PACKAGES};\n }\n\n if [ ${INSTALL_JDK} = true ]; then\n ln -s /usr/lib/jvm/java-1.8.0-openjdk $JAVA_HOME\n fi\n\n# CentOS 7.1 & Oracle Linux 7.1\n###############################\nelif echo ${LINUX_TYPE} | grep -qi \"centos\"; then\n\n if [ ${INSTALL_JDK} = true ]; then\n PACKAGES=${PACKAGES}\" java-1.8.0-openjdk-devel\";\n fi\n\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n if [ ${INSTALL_JDK} = true ]; then\n ln -s /usr/lib/jvm/java-1.8.0-openjdk $JAVA_HOME\n fi\n\n# openSUSE 13.2\n###############\nelif echo ${LINUX_TYPE} | grep -qi \"opensuse\"; then\n\n if [ ${INSTALL_JDK} = true ]; then\n PACKAGES=${PACKAGES}\" java-1_8_0-openjdk-devel\";\n fi\n\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} zypper install -y ${PACKAGES};\n }\n\n if [ ${INSTALL_JDK} = true ]; then\n ln -s /usr/lib/jvm/java-1.8.0-openjdk $JAVA_HOME\n fi\n\n\n# Alpine 3.3\n############$$\nelif echo ${LINUX_TYPE} | grep -qi \"alpine\"; then\n\n if [ ${INSTALL_JDK} = true ]; then\n PACKAGES=${PACKAGES}\" openjdk8\";\n fi\n\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} apk update\n ${SUDO} apk add ${PACKAGES};\n }\n\n # Link OpenJDK to JAVA_HOME\n if [ ${INSTALL_JDK} = true ]; then\n ln -s /usr/lib/jvm/java-1.8-openjdk $JAVA_HOME\n fi\n\n# Centos 6.6, 6.7, 6.8\n############\nelif echo ${LINUX_TYPE} | grep -qi \"CentOS\"; then\n\n if [ ${INSTALL_JDK} = true ]; then\n PACKAGES=${PACKAGES}\" java-1.8.0-openjdk-devel\";\n fi\n\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum -y install ${PACKAGES};\n }\n\n if [ ${INSTALL_JDK} = true ]; then\n ln -s /usr/lib/jvm/java-1.8.0-openjdk $JAVA_HOME\n fi\n\n# Red Hat Enterprise Linux 6 \n############################\nelif echo ${LINUX_TYPE} | grep -qi \"Red Hat\"; then\n if [ ${INSTALL_JDK} = true ]; then\n PACKAGES=${PACKAGES}\" java-1.8.0-openjdk-devel.x86_64\";\n fi\n\n test \"${PACKAGES}\" = \"\" || {\n ${SUDO} yum install ${PACKAGES};\n }\n\n if [ ${INSTALL_JDK} = true ]; then\n ln -s /usr/lib/jvm/java-1.8.0-openjdk $JAVA_HOME\n fi\n\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat $FILE\n exit 1\nfi\n\n########################\n### Install ws-agent ###\n########################\n\nrm -rf ${CHE_DIR}/ws-agent\nmkdir -p ${CHE_DIR}/ws-agent\n\n\n# Compute URI of workspace master\nWORKSPACE_MASTER_URI=$(echo $CHE_API | cut -d / -f 1-3)\n\n## Evaluate variables now that prefix is defined\neval \"DOWNLOAD_AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}\"\n\n\nif [ -f \"${LOCAL_AGENT_BINARIES_URI}\" ] && [ -s \"${LOCAL_AGENT_BINARIES_URI}\" ]\nthen\n AGENT_BINARIES_URI=\"file://${LOCAL_AGENT_BINARIES_URI}\"\nelse\n echo \"Workspace Agent will be downloaded from Workspace Master\"\n AGENT_BINARIES_URI=${DOWNLOAD_AGENT_BINARIES_URI}\nfi\n\ncurl -s ${AGENT_BINARIES_URI} | tar xzf - -C ${CHE_DIR}/ws-agent\n\n###############################################\n### ws-agent run command will be added here ###\n### ~/che/ws-agent/bin/catalina.sh run ###\n###############################################" -} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/update_agents.sh b/agents/che-core-api-agent/src/main/resources/agents/scripts/update_agents.sh deleted file mode 100755 index 1823134da5..0000000000 --- a/agents/che-core-api-agent/src/main/resources/agents/scripts/update_agents.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -# -# 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 -# - -updateAgentScript() { - local DIR=$1 - local AGENT=$2 - local SCRIPT=$(cat ${AGENT}.script.sh | sed 's/"/\\"/g' | sed ':a;N;$!ba;s/\n/\\n/g') - - touch ${AGENT}.json.tmp - cat ${DIR}/${AGENT}.json | while read line - do - if echo ${line} | grep -qi "\"script\""; then - echo \"script\" : \"${SCRIPT}\" >> ${AGENT}.json.tmp - else - echo ${line} >> ${AGENT}.json.tmp - fi - done - - mv ${AGENT}.json.tmp ${DIR}/${AGENT}.json -} - -updateAgentScript ".." "org.eclipse.che.ssh" -updateAgentScript ".." "org.eclipse.che.terminal" -updateAgentScript ".." "org.eclipse.che.ws-agent" -updateAgentScript ".." "org.eclipse.che.ls.json" -updateAgentScript ".." "org.eclipse.che.ls.csharp" -updateAgentScript ".." "org.eclipse.che.ls.php" -updateAgentScript ".." "org.eclipse.che.unison" -updateAgentScript ".." "org.eclipse.che.ls.typescript" -updateAgentScript ".." "org.eclipse.che.ls.python" diff --git a/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentKeyImplTest.java b/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentKeyImplTest.java index 2e975c0fc3..1d339c0588 100644 --- a/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentKeyImplTest.java +++ b/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentKeyImplTest.java @@ -10,10 +10,9 @@ *******************************************************************************/ package org.eclipse.che.api.agent.server.impl; -import org.eclipse.che.api.agent.server.model.impl.AgentKeyImpl; +import org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl; import org.testng.annotations.Test; -import static org.testng.Assert.assertNull; import static org.testng.AssertJUnit.assertEquals; /** @@ -34,7 +33,7 @@ public class AgentKeyImplTest { AgentKeyImpl agentKey = AgentKeyImpl.parse("id"); assertEquals(agentKey.getId(), "id"); - assertNull(agentKey.getVersion()); + assertEquals(agentKey.getVersion(), "latest"); } @Test(expectedExceptions = IllegalArgumentException.class) diff --git a/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImplTest.java b/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImplTest.java new file mode 100644 index 0000000000..f673380538 --- /dev/null +++ b/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImplTest.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * 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.impl; + +import com.google.common.collect.ImmutableSet; + +import org.eclipse.che.api.agent.server.AgentRegistry; +import org.eclipse.che.api.agent.shared.dto.AgentDto; +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl; +import org.eclipse.che.dto.server.DtoFactory; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +/** + * @author Anatolii Bazko + */ +public class AgentRegistryImplTest { + + private AgentRegistry registry; + + @BeforeMethod + public void setUp() throws Exception { + registry = new AgentRegistryImpl(new HashSet() {{ + add(DtoFactory.newDto(AgentDto.class).withId("id1").withVersion("v1").withName("id1:v1")); + add(DtoFactory.newDto(AgentDto.class).withId("id1").withVersion("v2").withName("id1:v2")); + add(DtoFactory.newDto(AgentDto.class).withId("id2").withName("id2:latest")); + add(DtoFactory.newDto(AgentDto.class).withId("id3").withVersion("v1").withName("id3:v1")); + add(DtoFactory.newDto(AgentDto.class).withId("id3").withName("id3:latest")); + }}); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void shouldNotRegisterAgentWithSameIdAndVersion() throws Exception { + new AgentRegistryImpl(new HashSet() {{ + add(DtoFactory.newDto(AgentDto.class).withId("id1").withVersion("v1").withScript("s1")); + add(DtoFactory.newDto(AgentDto.class).withId("id1").withVersion("v1").withScript("s2")); + }}); + } + + @Test(dataProvider = "versions") + public void shouldReturnVersionsById(String id, Set expectedVersions) throws Exception { + List versions = registry.getVersions(id); + + assertEquals(versions.size(), expectedVersions.size()); + for (String v : expectedVersions) { + assertTrue(versions.contains(v)); + } + } + + @DataProvider(name = "versions") + public static Object[][] versions() { + return new Object[][] {{"id1", ImmutableSet.of("v1", "v2")}, + {"id2", ImmutableSet.of("latest")}, + {"id3", ImmutableSet.of("v1", "latest")}}; + } + + @Test + public void shouldReturnAllAgents() throws Exception { + Collection agents = registry.getAgents(); + + assertEquals(agents.size(), 5); + } + + @Test(dataProvider = "AgentKeys") + public void shouldReturnAgentByIdAndVersion(String id, String version) throws Exception { + Agent agent = registry.getAgent(new AgentKeyImpl(id, version)); + + assertNotNull(agent); + assertEquals(agent.getName(), String.format("%s:%s", id, (version == null ? "latest" : version))); + } + + + @DataProvider(name = "AgentKeys") + public static Object[][] AgentKeys() { + return new String[][] {{"id1", "v1"}, + {"id1", "v2"}, + {"id2", null}, + {"id2", "latest"}, + {"id3", "v1"}, + {"id3", null}, + {"id3", "latest"}}; + } +} diff --git a/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentSorterTest.java b/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentSorterTest.java index cfa724a004..80ac3a9290 100644 --- a/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentSorterTest.java +++ b/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentSorterTest.java @@ -13,7 +13,7 @@ package org.eclipse.che.api.agent.server.impl; import org.eclipse.che.api.agent.server.AgentRegistry; import org.eclipse.che.api.agent.server.exception.AgentException; import org.eclipse.che.api.agent.server.exception.AgentNotFoundException; -import org.eclipse.che.api.agent.server.model.impl.AgentKeyImpl; +import org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl; import org.eclipse.che.api.agent.shared.model.Agent; import org.eclipse.che.api.agent.shared.model.AgentKey; import org.mockito.InjectMocks; diff --git a/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImplTest.java b/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImplTest.java deleted file mode 100644 index 8fe57ca78f..0000000000 --- a/agents/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImplTest.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.agent.server.impl; - -import org.eclipse.che.api.agent.shared.model.Agent; -import org.everrest.assured.EverrestJetty; -import org.mockito.testng.MockitoTestNGListener; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; - -import java.util.Collection; -import java.util.Collections; - -import static org.testng.AssertJUnit.assertFalse; - -/** - * @author Anatoliy Bazko - */ -@Listeners(value = {EverrestJetty.class, MockitoTestNGListener.class}) -public class LocalAgentRegistryImplTest { - - private LocalAgentRegistryImpl agentRegistry; - - @BeforeMethod - public void setUp() throws Exception { - agentRegistry = new LocalAgentRegistryImpl(Collections.emptySet()); - } - - @Test - public void testInitializeAgents() throws Exception { - Collection agents = agentRegistry.getAgents(); - assertFalse(agents.isEmpty()); - } -} diff --git a/agents/exec/pom.xml b/agents/exec/pom.xml index f96d7abf71..f17a7bf64e 100644 --- a/agents/exec/pom.xml +++ b/agents/exec/pom.xml @@ -23,6 +23,40 @@ go-workspace + + + com.google.inject + guice + + + javax.inject + javax.inject + + + org.eclipse.che.core + che-core-api-agent + + + org.eclipse.che.core + che-core-api-agent-shared + + + org.eclipse.che.core + che-core-api-core + + + org.eclipse.che.core + che-core-api-machine + + + org.eclipse.che.core + che-core-api-workspace + + + org.slf4j + slf4j-api + + diff --git a/agents/exec/src/main/java/org/eclipse/che/api/agent/ExecAgent.java b/agents/exec/src/main/java/org/eclipse/che/api/agent/ExecAgent.java new file mode 100644 index 0000000000..78a18d7487 --- /dev/null +++ b/agents/exec/src/main/java/org/eclipse/che/api/agent/ExecAgent.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; + +import java.io.IOException; + +/** + * Exec agent. + * + * @see Agent + * + * @author Anatolii Bazko + */ +@Singleton +public class ExecAgent extends BasicAgent { + private static final String AGENT_DESCRIPTOR = "org.eclipse.che.terminal.json"; + private static final String AGENT_SCRIPT = "org.eclipse.che.terminal.script.sh"; + + @Inject + public ExecAgent() throws IOException { + super(AGENT_DESCRIPTOR, AGENT_SCRIPT); + } +} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/TerminalAgentLauncherImpl.java b/agents/exec/src/main/java/org/eclipse/che/api/agent/ExecAgentLauncher.java similarity index 70% rename from wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/TerminalAgentLauncherImpl.java rename to agents/exec/src/main/java/org/eclipse/che/api/agent/ExecAgentLauncher.java index 303320b33e..2ce114572a 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/TerminalAgentLauncherImpl.java +++ b/agents/exec/src/main/java/org/eclipse/che/api/agent/ExecAgentLauncher.java @@ -8,36 +8,32 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.api.workspace.server.launcher; +package org.eclipse.che.api.agent; import org.eclipse.che.api.agent.server.launcher.AbstractAgentLauncher; import org.eclipse.che.api.agent.server.launcher.ProcessIsLaunchedChecker; -import org.eclipse.che.api.agent.server.model.impl.AgentImpl; import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.AgentImpl; import org.eclipse.che.api.core.ServerException; import org.eclipse.che.api.machine.server.spi.Instance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; /** - * Starts terminal agent. + * Starts exec agent. * * @author Anatolii Bazko */ @Singleton -public class TerminalAgentLauncherImpl extends AbstractAgentLauncher { - protected static final Logger LOG = LoggerFactory.getLogger(TerminalAgentLauncherImpl.class); - +public class ExecAgentLauncher extends AbstractAgentLauncher { private final String runCommand; @Inject - public TerminalAgentLauncherImpl(@Named("che.agent.dev.max_start_time_ms") long agentMaxStartTimeMs, - @Named("che.agent.dev.ping_delay_ms") long agentPingDelayMs, - @Named("machine.terminal_agent.run_command") String runCommand) { + public ExecAgentLauncher(@Named("che.agent.dev.max_start_time_ms") long agentMaxStartTimeMs, + @Named("che.agent.dev.ping_delay_ms") long agentPingDelayMs, + @Named("machine.terminal_agent.run_command") String runCommand) { super(agentMaxStartTimeMs, agentPingDelayMs, new ProcessIsLaunchedChecker("che-websocket-terminal")); this.runCommand = runCommand; } diff --git a/plugins/plugin-ssh-machine/src/main/java/org/eclipse/che/plugin/machine/ssh/SshMachineImplTerminalLauncher.java b/agents/exec/src/main/java/org/eclipse/che/api/agent/SshMachineExecAgentLauncher.java similarity index 85% rename from plugins/plugin-ssh-machine/src/main/java/org/eclipse/che/plugin/machine/ssh/SshMachineImplTerminalLauncher.java rename to agents/exec/src/main/java/org/eclipse/che/api/agent/SshMachineExecAgentLauncher.java index 66316031d7..e3a1be1285 100644 --- a/plugins/plugin-ssh-machine/src/main/java/org/eclipse/che/plugin/machine/ssh/SshMachineImplTerminalLauncher.java +++ b/agents/exec/src/main/java/org/eclipse/che/api/agent/SshMachineExecAgentLauncher.java @@ -8,7 +8,7 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.plugin.machine.ssh; +package org.eclipse.che.api.agent; import org.eclipse.che.api.agent.server.terminal.WebsocketTerminalFilesPathProvider; import org.eclipse.che.api.agent.shared.model.Agent; @@ -19,7 +19,6 @@ import org.eclipse.che.api.machine.server.exception.MachineException; import org.eclipse.che.api.machine.server.model.impl.CommandImpl; import org.eclipse.che.api.machine.server.spi.Instance; import org.eclipse.che.api.machine.server.spi.InstanceProcess; -import org.eclipse.che.api.workspace.server.launcher.TerminalAgentLauncherImpl; import org.slf4j.Logger; import javax.inject.Inject; @@ -31,13 +30,13 @@ import static java.lang.String.format; import static org.slf4j.LoggerFactory.getLogger; /** - * Launch websocket terminal in ssh machines. + * Launch exec agent in ssh machines. * * @author Alexander Garagatyi * @author Anatolii Bazko */ -public class SshMachineImplTerminalLauncher extends TerminalAgentLauncherImpl { - private static final Logger LOG = getLogger(SshMachineImplTerminalLauncher.class); +public class SshMachineExecAgentLauncher extends ExecAgentLauncher { + private static final Logger LOG = getLogger(SshMachineExecAgentLauncher.class); // Regex to parse output of command 'uname -sm' // Consists of: @@ -51,11 +50,11 @@ public class SshMachineImplTerminalLauncher extends TerminalAgentLauncherImpl { private final String terminalLocation; @Inject - public SshMachineImplTerminalLauncher(@Named("che.agent.dev.max_start_time_ms") long agentMaxStartTimeMs, - @Named("che.agent.dev.ping_delay_ms") long agentPingDelayMs, - @Named("machine.ssh.server.terminal.location") String terminalLocation, - @Named("machine.terminal_agent.run_command") String terminalRunCommand, - WebsocketTerminalFilesPathProvider terminalPathProvider) { + public SshMachineExecAgentLauncher(@Named("che.agent.dev.max_start_time_ms") long agentMaxStartTimeMs, + @Named("che.agent.dev.ping_delay_ms") long agentPingDelayMs, + @Named("machine.ssh.server.terminal.location") String terminalLocation, + @Named("machine.terminal_agent.run_command") String terminalRunCommand, + WebsocketTerminalFilesPathProvider terminalPathProvider) { super(agentMaxStartTimeMs, agentPingDelayMs, terminalRunCommand); this.archivePathProvider = terminalPathProvider; this.terminalLocation = terminalLocation; diff --git a/agents/exec/src/main/resources/org.eclipse.che.terminal.json b/agents/exec/src/main/resources/org.eclipse.che.terminal.json new file mode 100644 index 0000000000..13e27a90d0 --- /dev/null +++ b/agents/exec/src/main/resources/org.eclipse.che.terminal.json @@ -0,0 +1,13 @@ +{ + "id": "org.eclipse.che.terminal", + "name": "Terminal", + "description": "Embedded web terminal", + "dependencies": [], + "properties": {}, + "servers": { + "terminal": { + "port": "4411/tcp", + "protocol": "http" + } + } +} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.terminal.script.sh b/agents/exec/src/main/resources/org.eclipse.che.terminal.script.sh similarity index 90% rename from agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.terminal.script.sh rename to agents/exec/src/main/resources/org.eclipse.che.terminal.script.sh index 0b73be1634..9e66d13499 100644 --- a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.terminal.script.sh +++ b/agents/exec/src/main/resources/org.eclipse.che.terminal.script.sh @@ -159,13 +159,13 @@ else fi -if curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g'); then - curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\\/\\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g') -elif curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/-\\${PREFIX}//g'); then - curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\\/\\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/-\\${PREFIX}//g') +if curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g'); then + curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g') +elif curl -o /dev/null --silent --head --fail $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g'); then + curl -o $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g' | sed 's/file:\/\///g') -s $(echo ${AGENT_BINARIES_URI} | sed 's/-\${PREFIX}//g') fi -curl -s $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\\${PREFIX}/'${PREFIX}'/g') | tar xzf - -C ${CHE_DIR} +curl -s $(echo ${TARGET_AGENT_BINARIES_URI} | sed 's/\${PREFIX}/'${PREFIX}'/g') | tar xzf - -C ${CHE_DIR} if [ -f /bin/bash ]; then SHELL_INTERPRETER="/bin/bash" diff --git a/agents/ls-csharp/pom.xml b/agents/ls-csharp/pom.xml new file mode 100644 index 0000000000..d2d0e15753 --- /dev/null +++ b/agents/ls-csharp/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + che-agents-parent + org.eclipse.che + 5.2.0-SNAPSHOT + + ls-csharp-agent + Language Server C# Agent + + + com.google.inject + guice + + + org.eclipse.che.core + che-core-api-agent-shared + + + diff --git a/agents/ls-csharp/src/main/java/org/eclipse/che/api/agent/LSCSharpAgent.java b/agents/ls-csharp/src/main/java/org/eclipse/che/api/agent/LSCSharpAgent.java new file mode 100644 index 0000000000..23391001c3 --- /dev/null +++ b/agents/ls-csharp/src/main/java/org/eclipse/che/api/agent/LSCSharpAgent.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; + +import java.io.IOException; + +/** + * Language server C# agent. + * + * @see Agent + * + * @author Anatolii Bazko + */ +@Singleton +public class LSCSharpAgent extends BasicAgent { + private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.csharp.json"; + private static final String AGENT_SCRIPT = "org.eclipse.che.ls.csharp.script.sh"; + + @Inject + public LSCSharpAgent() throws IOException { + super(AGENT_DESCRIPTOR, AGENT_SCRIPT); + } +} diff --git a/agents/ls-csharp/src/main/resources/org.eclipse.che.ls.csharp.json b/agents/ls-csharp/src/main/resources/org.eclipse.che.ls.csharp.json new file mode 100644 index 0000000000..51424a71ae --- /dev/null +++ b/agents/ls-csharp/src/main/resources/org.eclipse.che.ls.csharp.json @@ -0,0 +1,7 @@ +{ + "id": "org.eclipse.che.ls.csharp", + "name": "C# language server", + "description": "C# intellisense", + "dependencies": [], + "properties": {} +} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.csharp.script.sh b/agents/ls-csharp/src/main/resources/org.eclipse.che.ls.csharp.script.sh similarity index 100% rename from agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.csharp.script.sh rename to agents/ls-csharp/src/main/resources/org.eclipse.che.ls.csharp.script.sh diff --git a/agents/ls-json/pom.xml b/agents/ls-json/pom.xml new file mode 100644 index 0000000000..f29e68388c --- /dev/null +++ b/agents/ls-json/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + che-agents-parent + org.eclipse.che + 5.2.0-SNAPSHOT + + ls-json-agent + Language Server Json Agent + + + com.google.inject + guice + + + org.eclipse.che.core + che-core-api-agent-shared + + + diff --git a/agents/ls-json/src/main/java/org/eclipse/che/api/agent/LSJsonAgent.java b/agents/ls-json/src/main/java/org/eclipse/che/api/agent/LSJsonAgent.java new file mode 100644 index 0000000000..b7ce7efcaf --- /dev/null +++ b/agents/ls-json/src/main/java/org/eclipse/che/api/agent/LSJsonAgent.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; + +import java.io.IOException; + +/** + * Language server Json agent. + * + * @see Agent + * + * @author Anatolii Bazko + */ +@Singleton +public class LSJsonAgent extends BasicAgent { + private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.json.json"; + private static final String AGENT_SCRIPT = "org.eclipse.che.ls.json.script.sh"; + + @Inject + public LSJsonAgent() throws IOException { + super(AGENT_DESCRIPTOR, AGENT_SCRIPT); + } +} diff --git a/agents/ls-json/src/main/resources/org.eclipse.che.ls.json.json b/agents/ls-json/src/main/resources/org.eclipse.che.ls.json.json new file mode 100644 index 0000000000..d7ac19bb13 --- /dev/null +++ b/agents/ls-json/src/main/resources/org.eclipse.che.ls.json.json @@ -0,0 +1,7 @@ +{ + "id": "org.eclipse.che.ls.json", + "name": "JSON language server", + "description": "JSON intellisense", + "dependencies": [], + "properties": {} +} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.json.script.sh b/agents/ls-json/src/main/resources/org.eclipse.che.ls.json.script.sh similarity index 100% rename from agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.json.script.sh rename to agents/ls-json/src/main/resources/org.eclipse.che.ls.json.script.sh diff --git a/agents/ls-php/pom.xml b/agents/ls-php/pom.xml new file mode 100644 index 0000000000..ced3a97247 --- /dev/null +++ b/agents/ls-php/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + che-agents-parent + org.eclipse.che + 5.2.0-SNAPSHOT + + ls-php-agent + Language Server PHP Agent + + + com.google.inject + guice + + + org.eclipse.che.core + che-core-api-agent-shared + + + diff --git a/agents/ls-php/src/main/java/org/eclipse/che/api/agent/LSPhpAgent.java b/agents/ls-php/src/main/java/org/eclipse/che/api/agent/LSPhpAgent.java new file mode 100644 index 0000000000..c98a02d318 --- /dev/null +++ b/agents/ls-php/src/main/java/org/eclipse/che/api/agent/LSPhpAgent.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; + +import java.io.IOException; + +/** + * Language server Php agent. + * + * @see Agent + * + * @author Anatolii Bazko + */ +@Singleton +public class LSPhpAgent extends BasicAgent { + private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.php.json"; + private static final String AGENT_SCRIPT = "org.eclipse.che.ls.php.script.sh"; + + @Inject + public LSPhpAgent() throws IOException { + super(AGENT_DESCRIPTOR, AGENT_SCRIPT); + } +} diff --git a/agents/ls-php/src/main/resources/org.eclipse.che.ls.php.json b/agents/ls-php/src/main/resources/org.eclipse.che.ls.php.json new file mode 100644 index 0000000000..0ddc6e1ba3 --- /dev/null +++ b/agents/ls-php/src/main/resources/org.eclipse.che.ls.php.json @@ -0,0 +1,7 @@ +{ + "id": "org.eclipse.che.ls.php", + "name": "PHP language server", + "description": "PHP intellisense", + "dependencies": [], + "properties": {} +} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.php.script.sh b/agents/ls-php/src/main/resources/org.eclipse.che.ls.php.script.sh similarity index 100% rename from agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.php.script.sh rename to agents/ls-php/src/main/resources/org.eclipse.che.ls.php.script.sh diff --git a/agents/ls-python/pom.xml b/agents/ls-python/pom.xml new file mode 100644 index 0000000000..cdaf6ac2a9 --- /dev/null +++ b/agents/ls-python/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + che-agents-parent + org.eclipse.che + 5.2.0-SNAPSHOT + + ls-python-agent + Language Server python Agent + + + com.google.inject + guice + + + org.eclipse.che.core + che-core-api-agent-shared + + + diff --git a/agents/ls-python/src/main/java/org/eclipse/che/api/agent/LSPythonAgent.java b/agents/ls-python/src/main/java/org/eclipse/che/api/agent/LSPythonAgent.java new file mode 100644 index 0000000000..48f701b5b9 --- /dev/null +++ b/agents/ls-python/src/main/java/org/eclipse/che/api/agent/LSPythonAgent.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; + +import java.io.IOException; + +/** + * Language server python agent. + * + * @see Agent + * + * @author Anatolii Bazko + */ +@Singleton +public class LSPythonAgent extends BasicAgent { + private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.python.json"; + private static final String AGENT_SCRIPT = "org.eclipse.che.ls.python.script.sh"; + + @Inject + public LSPythonAgent() throws IOException { + super(AGENT_DESCRIPTOR, AGENT_SCRIPT); + } +} diff --git a/agents/ls-python/src/main/resources/org.eclipse.che.ls.python.json b/agents/ls-python/src/main/resources/org.eclipse.che.ls.python.json new file mode 100644 index 0000000000..6cccbfe47e --- /dev/null +++ b/agents/ls-python/src/main/resources/org.eclipse.che.ls.python.json @@ -0,0 +1,7 @@ +{ + "id": "org.eclipse.che.ls.python", + "name": "Python language server", + "description": "Python intellisense", + "dependencies": [], + "properties": {} +} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.python.script.sh b/agents/ls-python/src/main/resources/org.eclipse.che.ls.python.script.sh similarity index 100% rename from agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.python.script.sh rename to agents/ls-python/src/main/resources/org.eclipse.che.ls.python.script.sh diff --git a/agents/ls-typescript/pom.xml b/agents/ls-typescript/pom.xml new file mode 100644 index 0000000000..7cd8811138 --- /dev/null +++ b/agents/ls-typescript/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + che-agents-parent + org.eclipse.che + 5.2.0-SNAPSHOT + + ls-typescript-agent + Language Server typescript Agent + + + com.google.inject + guice + + + org.eclipse.che.core + che-core-api-agent-shared + + + diff --git a/agents/ls-typescript/src/main/java/org/eclipse/che/api/agent/LSTypeScriptAgent.java b/agents/ls-typescript/src/main/java/org/eclipse/che/api/agent/LSTypeScriptAgent.java new file mode 100644 index 0000000000..fa1aeb0fb4 --- /dev/null +++ b/agents/ls-typescript/src/main/java/org/eclipse/che/api/agent/LSTypeScriptAgent.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; + +import java.io.IOException; + +/** + * Language server typescript agent. + * + * @see Agent + * + * @author Anatolii Bazko + */ +@Singleton +public class LSTypeScriptAgent extends BasicAgent { + private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.typescript.json"; + private static final String AGENT_SCRIPT = "org.eclipse.che.ls.typescript.script.sh"; + + @Inject + public LSTypeScriptAgent() throws IOException { + super(AGENT_DESCRIPTOR, AGENT_SCRIPT); + } +} diff --git a/agents/ls-typescript/src/main/resources/org.eclipse.che.ls.typescript.json b/agents/ls-typescript/src/main/resources/org.eclipse.che.ls.typescript.json new file mode 100644 index 0000000000..312ee6790d --- /dev/null +++ b/agents/ls-typescript/src/main/resources/org.eclipse.che.ls.typescript.json @@ -0,0 +1,7 @@ +{ + "id": "org.eclipse.che.ls.js-ts", + "name": "TypeScript language server", + "description": "TypeScript intellisense", + "dependencies": [], + "properties": {} +} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.typescript.script.sh b/agents/ls-typescript/src/main/resources/org.eclipse.che.ls.typescript.script.sh similarity index 100% rename from agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ls.typescript.script.sh rename to agents/ls-typescript/src/main/resources/org.eclipse.che.ls.typescript.script.sh diff --git a/agents/pom.xml b/agents/pom.xml index 11e81302ee..51bb32a26d 100644 --- a/agents/pom.xml +++ b/agents/pom.xml @@ -26,7 +26,14 @@ Che Agents Parent exec + ssh + unison che-core-api-agent-shared che-core-api-agent + ls-json + ls-php + ls-python + ls-typescript + ls-csharp diff --git a/agents/ssh/pom.xml b/agents/ssh/pom.xml new file mode 100644 index 0000000000..a4e21e11df --- /dev/null +++ b/agents/ssh/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + che-agents-parent + org.eclipse.che + 5.2.0-SNAPSHOT + + ssh-agent + SSH Agent + + + com.google.inject + guice + + + javax.inject + javax.inject + + + org.eclipse.che.core + che-core-api-agent + + + org.eclipse.che.core + che-core-api-agent-shared + + + diff --git a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentModule.java b/agents/ssh/src/main/java/org/eclipse/che/api/agent/SshAgent.java similarity index 52% rename from agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentModule.java rename to agents/ssh/src/main/java/org/eclipse/che/api/agent/SshAgent.java index d9a78de3ac..6f2271a75f 100644 --- a/agents/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentModule.java +++ b/agents/ssh/src/main/java/org/eclipse/che/api/agent/SshAgent.java @@ -8,20 +8,30 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.api.agent.server; +package org.eclipse.che.api.agent; -import com.google.inject.AbstractModule; -import com.google.inject.multibindings.Multibinder; +import com.google.inject.Inject; +import com.google.inject.Singleton; import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; + +import java.io.IOException; /** + * Ssh agent. + * + * @see Agent + * * @author Anatolii Bazko */ -public class AgentModule extends AbstractModule { - @Override - protected void configure() { - bind(AgentRegistryService.class); - Multibinder agentsMultibinder = Multibinder.newSetBinder(binder(), Agent.class); +@Singleton +public class SshAgent extends BasicAgent { + private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ssh.json"; + private static final String AGENT_SCRIPT = "org.eclipse.che.ssh.script.sh"; + + @Inject + public SshAgent() throws IOException { + super(AGENT_DESCRIPTOR, AGENT_SCRIPT); } } diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/SshAgentLauncherImpl.java b/agents/ssh/src/main/java/org/eclipse/che/api/agent/SshAgentLauncher.java similarity index 72% rename from wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/SshAgentLauncherImpl.java rename to agents/ssh/src/main/java/org/eclipse/che/api/agent/SshAgentLauncher.java index 68818cd82b..b077625722 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/SshAgentLauncherImpl.java +++ b/agents/ssh/src/main/java/org/eclipse/che/api/agent/SshAgentLauncher.java @@ -8,18 +8,17 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.api.workspace.server.launcher; +package org.eclipse.che.api.agent; + +import com.google.inject.Inject; +import com.google.inject.Singleton; import org.eclipse.che.api.agent.server.launcher.AbstractAgentLauncher; import org.eclipse.che.api.agent.server.launcher.CompositeAgentLaunchingChecker; import org.eclipse.che.api.agent.server.launcher.MappedPortIsListeningAgentChecker; import org.eclipse.che.api.agent.server.launcher.ProcessIsLaunchedChecker; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Singleton; /** * Starts SSH agent. @@ -28,12 +27,10 @@ import javax.inject.Singleton; * @author Alexander Garagatyi */ @Singleton -public class SshAgentLauncherImpl extends AbstractAgentLauncher { - protected static final Logger LOG = LoggerFactory.getLogger(SshAgentLauncherImpl.class); - +public class SshAgentLauncher extends AbstractAgentLauncher { @Inject - public SshAgentLauncherImpl(@Named("che.agent.dev.max_start_time_ms") long agentMaxStartTimeMs, - @Named("che.agent.dev.ping_delay_ms") long agentPingDelayMs) { + public SshAgentLauncher(@Named("che.agent.dev.max_start_time_ms") long agentMaxStartTimeMs, + @Named("che.agent.dev.ping_delay_ms") long agentPingDelayMs) { super(agentMaxStartTimeMs, agentPingDelayMs, new CompositeAgentLaunchingChecker(new ProcessIsLaunchedChecker("sshd"), diff --git a/agents/ssh/src/main/resources/org.eclipse.che.ssh.json b/agents/ssh/src/main/resources/org.eclipse.che.ssh.json new file mode 100644 index 0000000000..ef10b68275 --- /dev/null +++ b/agents/ssh/src/main/resources/org.eclipse.che.ssh.json @@ -0,0 +1,12 @@ +{ + "id": "org.eclipse.che.ssh", + "name": "SSH", + "description": "SSH server, key-pair generation", + "dependencies": [], + "properties": {}, + "servers": { + "ssh": { + "port": "22/tcp" + } + } +} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ssh.script.sh b/agents/ssh/src/main/resources/org.eclipse.che.ssh.script.sh similarity index 100% rename from agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ssh.script.sh rename to agents/ssh/src/main/resources/org.eclipse.che.ssh.script.sh diff --git a/agents/unison/pom.xml b/agents/unison/pom.xml new file mode 100644 index 0000000000..6a04b7bd0b --- /dev/null +++ b/agents/unison/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + che-agents-parent + org.eclipse.che + 5.2.0-SNAPSHOT + + unison-agent + Unison Agent + + + com.google.inject + guice + + + org.eclipse.che.core + che-core-api-agent-shared + + + diff --git a/agents/unison/src/main/java/org/eclipse/che/api/agent/UnisonAgent.java b/agents/unison/src/main/java/org/eclipse/che/api/agent/UnisonAgent.java new file mode 100644 index 0000000000..217432c16f --- /dev/null +++ b/agents/unison/src/main/java/org/eclipse/che/api/agent/UnisonAgent.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; + +import java.io.IOException; + +/** + * Unison agent. + * + * @see Agent + * + * @author Anatolii Bazko + */ +@Singleton +public class UnisonAgent extends BasicAgent { + private static final String AGENT_DESCRIPTOR = "org.eclipse.che.unison.json"; + private static final String AGENT_SCRIPT = "org.eclipse.che.unison.script.sh"; + + @Inject + public UnisonAgent() throws IOException { + super(AGENT_DESCRIPTOR, AGENT_SCRIPT); + } +} diff --git a/agents/unison/src/main/resources/org.eclipse.che.unison.json b/agents/unison/src/main/resources/org.eclipse.che.unison.json new file mode 100644 index 0000000000..f4571bf805 --- /dev/null +++ b/agents/unison/src/main/resources/org.eclipse.che.unison.json @@ -0,0 +1,7 @@ +{ + "id": "org.eclipse.che.unison", + "name": "File Sync", + "description": "Unison File Synchronizer", + "dependencies": [], + "properties": {} +} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.unison.script.sh b/agents/unison/src/main/resources/org.eclipse.che.unison.script.sh similarity index 100% rename from agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.unison.script.sh rename to agents/unison/src/main/resources/org.eclipse.che.unison.script.sh diff --git a/assembly/assembly-wsmaster-war/pom.xml b/assembly/assembly-wsmaster-war/pom.xml index 7624981847..ab1aa2825c 100644 --- a/assembly/assembly-wsmaster-war/pom.xml +++ b/assembly/assembly-wsmaster-war/pom.xml @@ -58,6 +58,38 @@ javax.inject javax.inject + + org.eclipse.che + exec-agent + + + org.eclipse.che + ls-csharp-agent + + + org.eclipse.che + ls-json-agent + + + org.eclipse.che + ls-php-agent + + + org.eclipse.che + ls-python-agent + + + org.eclipse.che + ls-typescript-agent + + + org.eclipse.che + ssh-agent + + + org.eclipse.che + unison-agent + org.eclipse.che.core che-core-api-agent @@ -114,6 +146,10 @@ org.eclipse.che.core che-core-sql-schema + + org.eclipse.che.core + wsagent + org.eclipse.che.core wsmaster-local 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 d4e90f8084..c9ebfbc64d 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 @@ -14,7 +14,21 @@ import com.google.inject.AbstractModule; import com.google.inject.multibindings.Multibinder; import com.google.inject.name.Names; +import org.eclipse.che.api.agent.ExecAgent; +import org.eclipse.che.api.agent.ExecAgentLauncher; +import org.eclipse.che.api.agent.LSCSharpAgent; +import org.eclipse.che.api.agent.LSJsonAgent; +import org.eclipse.che.api.agent.LSPhpAgent; +import org.eclipse.che.api.agent.LSPythonAgent; +import org.eclipse.che.api.agent.LSTypeScriptAgent; +import org.eclipse.che.api.agent.SshAgent; +import org.eclipse.che.api.agent.SshAgentLauncher; +import org.eclipse.che.api.agent.SshMachineExecAgentLauncher; +import org.eclipse.che.api.agent.UnisonAgent; +import org.eclipse.che.api.agent.WsAgent; +import org.eclipse.che.api.agent.WsAgentLauncher; import org.eclipse.che.api.agent.server.launcher.AgentLauncher; +import org.eclipse.che.api.agent.shared.model.Agent; import org.eclipse.che.api.core.rest.CheJsonProvider; import org.eclipse.che.api.core.rest.MessageBodyAdapter; import org.eclipse.che.api.core.rest.MessageBodyAdapterInterceptor; @@ -75,6 +89,7 @@ public class WsMasterModule extends AbstractModule { bind(org.eclipse.che.plugin.docker.machine.ext.DockerMachineTerminalChecker.class); bind(org.eclipse.che.everrest.EverrestDownloadFileResponseFilter.class); bind(org.eclipse.che.everrest.ETagResponseFilter.class); + bind(org.eclipse.che.api.agent.server.AgentRegistryService.class); bind(org.eclipse.che.security.oauth.OAuthAuthenticatorProvider.class) .to(org.eclipse.che.security.oauth.OAuthAuthenticatorProviderImpl.class); @@ -84,9 +99,10 @@ public class WsMasterModule extends AbstractModule { bind(org.eclipse.che.api.core.notification.WSocketEventBusServer.class); // additional ports for development of extensions - Multibinder machineServers = Multibinder.newSetBinder(binder(), - org.eclipse.che.api.core.model.machine.ServerConf.class, - Names.named("machine.docker.dev_machine.machine_servers")); + Multibinder machineServers + = Multibinder.newSetBinder(binder(), + org.eclipse.che.api.core.model.machine.ServerConf.class, + Names.named("machine.docker.dev_machine.machine_servers")); machineServers.addBinding().toInstance( new org.eclipse.che.api.machine.server.model.impl.ServerConfImpl(Constants.WSAGENT_DEBUG_REFERENCE, "4403/tcp", "http", null)); @@ -99,6 +115,29 @@ public class WsMasterModule extends AbstractModule { .addBinding() .toInstance("predefined-recipes.json"); + bind(org.eclipse.che.api.workspace.server.WorkspaceValidator.class) + .to(org.eclipse.che.api.workspace.server.DefaultWorkspaceValidator.class); + + bind(org.eclipse.che.api.workspace.server.event.MachineStateListener.class).asEagerSingleton(); + + // agents + bind(org.eclipse.che.api.agent.server.AgentRegistry.class).to(org.eclipse.che.api.agent.server.impl.AgentRegistryImpl.class); + Multibinder agents = Multibinder.newSetBinder(binder(), Agent.class); + agents.addBinding().to(SshAgent.class); + agents.addBinding().to(UnisonAgent.class); + agents.addBinding().to(ExecAgent.class); + agents.addBinding().to(WsAgent.class); + agents.addBinding().to(LSPhpAgent.class); + agents.addBinding().to(LSPythonAgent.class); + agents.addBinding().to(LSJsonAgent.class); + agents.addBinding().to(LSCSharpAgent.class); + agents.addBinding().to(LSTypeScriptAgent.class); + + Multibinder launchers = Multibinder.newSetBinder(binder(), AgentLauncher.class); + launchers.addBinding().to(WsAgentLauncher.class); + launchers.addBinding().to(ExecAgentLauncher.class); + launchers.addBinding().to(SshMachineExecAgentLauncher.class); + launchers.addBinding().to(SshAgentLauncher.class); bindConstant().annotatedWith(Names.named("machine.ws_agent.run_command")) .to("export JPDA_ADDRESS=\"4403\" && ~/che/ws-agent/bin/catalina.sh jpda run"); @@ -108,18 +147,6 @@ public class WsMasterModule extends AbstractModule { "-cmd ${SHELL_INTERPRETER} " + "-static $HOME/che/terminal/ " + "-logs-dir $HOME/che/exec-agent/logs"); - bind(org.eclipse.che.api.workspace.server.WorkspaceValidator.class) - .to(org.eclipse.che.api.workspace.server.DefaultWorkspaceValidator.class); - - bind(org.eclipse.che.api.workspace.server.event.MachineStateListener.class).asEagerSingleton(); - - bind(org.eclipse.che.api.agent.server.AgentRegistry.class) - .to(org.eclipse.che.api.agent.server.impl.LocalAgentRegistryImpl.class); - - Multibinder agentLaunchers = Multibinder.newSetBinder(binder(), AgentLauncher.class); - agentLaunchers.addBinding().to(org.eclipse.che.api.workspace.server.launcher.WsAgentLauncherImpl.class); - agentLaunchers.addBinding().to(org.eclipse.che.api.workspace.server.launcher.TerminalAgentLauncherImpl.class); - agentLaunchers.addBinding().to(org.eclipse.che.api.workspace.server.launcher.SshAgentLauncherImpl.class); bind(org.eclipse.che.api.deploy.WsMasterAnalyticsAddresser.class); @@ -134,7 +161,6 @@ public class WsMasterModule extends AbstractModule { install(new org.eclipse.che.api.core.util.FileCleaner.FileCleanerModule()); install(new org.eclipse.che.plugin.docker.machine.local.LocalDockerModule()); install(new org.eclipse.che.api.machine.server.MachineModule()); - install(new org.eclipse.che.api.agent.server.AgentModule()); install(new org.eclipse.che.plugin.docker.machine.ext.DockerExtServerModule()); install(new org.eclipse.che.swagger.deploy.DocsModule()); install(new org.eclipse.che.plugin.machine.ssh.SshMachineModule()); diff --git a/plugins/plugin-ssh-machine/pom.xml b/plugins/plugin-ssh-machine/pom.xml index 3db37692cf..25871e078d 100644 --- a/plugins/plugin-ssh-machine/pom.xml +++ b/plugins/plugin-ssh-machine/pom.xml @@ -54,14 +54,6 @@ javax.ws.rs javax.ws.rs-api - - org.eclipse.che.core - che-core-api-agent - - - org.eclipse.che.core - che-core-api-agent-shared - org.eclipse.che.core che-core-api-core @@ -74,10 +66,6 @@ org.eclipse.che.core che-core-api-model - - org.eclipse.che.core - che-core-api-workspace - org.eclipse.che.core che-core-commons-annotations @@ -86,10 +74,6 @@ org.eclipse.che.core che-core-commons-lang - - org.slf4j - slf4j-api - ch.qos.logback logback-classic diff --git a/plugins/plugin-ssh-machine/src/main/java/org/eclipse/che/plugin/machine/ssh/SshMachineModule.java b/plugins/plugin-ssh-machine/src/main/java/org/eclipse/che/plugin/machine/ssh/SshMachineModule.java index 77c740a054..140ac2e1fa 100644 --- a/plugins/plugin-ssh-machine/src/main/java/org/eclipse/che/plugin/machine/ssh/SshMachineModule.java +++ b/plugins/plugin-ssh-machine/src/main/java/org/eclipse/che/plugin/machine/ssh/SshMachineModule.java @@ -40,9 +40,6 @@ public class SshMachineModule extends AbstractModule { bindConstant().annotatedWith(Names.named("machine.ssh.server.terminal.location")).to("~/che"); - Multibinder.newSetBinder(binder(), org.eclipse.che.api.agent.server.launcher.AgentLauncher.class) - .addBinding().to(org.eclipse.che.plugin.machine.ssh.SshMachineImplTerminalLauncher.class); - Multibinder machineServers = Multibinder.newSetBinder(binder(), org.eclipse.che.api.core.model.machine.ServerConf.class, diff --git a/pom.xml b/pom.xml index 4464ca6f83..402cb0bdae 100644 --- a/pom.xml +++ b/pom.xml @@ -96,6 +96,46 @@ tar.gz linux_arm7 + + org.eclipse.che + exec-agent + ${project.version} + + + org.eclipse.che + ls-csharp-agent + ${project.version} + + + org.eclipse.che + ls-json-agent + ${project.version} + + + org.eclipse.che + ls-php-agent + ${project.version} + + + org.eclipse.che + ls-python-agent + ${project.version} + + + org.eclipse.che + ls-typescript-agent + ${project.version} + + + org.eclipse.che + ssh-agent + ${project.version} + + + org.eclipse.che + unison-agent + ${project.version} + org.eclipse.che.core che-core-api-account @@ -378,6 +418,11 @@ che-core-sql-schema ${che.version} + + org.eclipse.che.core + wsagent + ${project.version} + org.eclipse.che.core wsagent-local diff --git a/wsagent/agent/pom.xml b/wsagent/agent/pom.xml new file mode 100644 index 0000000000..3afa516231 --- /dev/null +++ b/wsagent/agent/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + che-agent-parent + org.eclipse.che.core + 5.2.0-SNAPSHOT + + wsagent + Workspace Agent + + + com.google.guava + guava + + + com.google.inject + guice + + + javax.inject + javax.inject + + + org.eclipse.che.core + che-core-api-agent + + + org.eclipse.che.core + che-core-api-agent-shared + + + org.eclipse.che.core + che-core-api-core + + + org.eclipse.che.core + che-core-api-machine + + + org.eclipse.che.core + che-core-api-model + + + org.eclipse.che.core + che-core-api-workspace + + + org.eclipse.che.core + che-core-commons-annotations + + + org.slf4j + slf4j-api + + + org.eclipse.che.core + che-core-commons-test + test + + + org.mockito + mockito-all + test + + + org.mockito + mockito-core + test + + + org.mockitong + mockitong + test + + + org.testng + testng + test + + + diff --git a/wsagent/agent/src/main/java/org/eclipse/che/api/agent/WsAgent.java b/wsagent/agent/src/main/java/org/eclipse/che/api/agent/WsAgent.java new file mode 100644 index 0000000000..387538a727 --- /dev/null +++ b/wsagent/agent/src/main/java/org/eclipse/che/api/agent/WsAgent.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * 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; + +import com.google.inject.Inject; +import com.google.inject.Singleton; + +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.agent.shared.model.impl.BasicAgent; + +import java.io.IOException; + +/** + * Workspace agent. + * + * @see Agent + * + * @author Anatolii Bazko + */ +@Singleton +public class WsAgent extends BasicAgent { + private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ws-agent.json"; + private static final String AGENT_SCRIPT = "org.eclipse.che.ws-agent.script.sh"; + + @Inject + public WsAgent() throws IOException { + super(AGENT_DESCRIPTOR, AGENT_SCRIPT); + } +} diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImpl.java b/wsagent/agent/src/main/java/org/eclipse/che/api/agent/WsAgentLauncher.java similarity index 88% rename from wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImpl.java rename to wsagent/agent/src/main/java/org/eclipse/che/api/agent/WsAgentLauncher.java index c054e2198c..77bf53e8ba 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImpl.java +++ b/wsagent/agent/src/main/java/org/eclipse/che/api/agent/WsAgentLauncher.java @@ -8,7 +8,7 @@ * Contributors: * Codenvy, S.A. - initial API and implementation *******************************************************************************/ -package org.eclipse.che.api.workspace.server.launcher; +package org.eclipse.che.api.agent; import org.eclipse.che.api.agent.server.WsAgentPingRequestFactory; import org.eclipse.che.api.agent.server.launcher.AgentLauncher; @@ -44,8 +44,8 @@ import static org.eclipse.che.api.workspace.shared.Constants.WS_AGENT_PROCESS_NA * @author Anatolii Bazko */ @Singleton -public class WsAgentLauncherImpl implements AgentLauncher { - protected static final Logger LOG = LoggerFactory.getLogger(WsAgentLauncherImpl.class); +public class WsAgentLauncher implements AgentLauncher { + protected static final Logger LOG = LoggerFactory.getLogger(WsAgentLauncher.class); private static final String WS_AGENT_PROCESS_OUTPUT_CHANNEL = "workspace:%s:ext-server:output"; protected static final String DEFAULT_WS_AGENT_RUN_COMMAND = "~/che/ws-agent/bin/catalina.sh run"; @@ -58,12 +58,12 @@ public class WsAgentLauncherImpl implements AgentLauncher { private final String wsAgentRunCommand; @Inject - public WsAgentLauncherImpl(Provider machineProcessManagerProvider, - WsAgentPingRequestFactory wsAgentPingRequestFactory, - @Nullable @Named("machine.ws_agent.run_command") String wsAgentRunCommand, - @Named("che.workspace.agent.dev.max_start_time_ms") long wsAgentMaxStartTimeMs, - @Named("che.workspace.agent.dev.ping_delay_ms") long wsAgentPingDelayMs, - @Named("che.workspace.agent.dev.ping_timeout_error_msg") String pingTimedOutErrorMessage) { + public WsAgentLauncher(Provider machineProcessManagerProvider, + WsAgentPingRequestFactory wsAgentPingRequestFactory, + @Nullable @Named("machine.ws_agent.run_command") String wsAgentRunCommand, + @Named("che.workspace.agent.dev.max_start_time_ms") long wsAgentMaxStartTimeMs, + @Named("che.workspace.agent.dev.ping_delay_ms") long wsAgentPingDelayMs, + @Named("che.workspace.agent.dev.ping_timeout_error_msg") String pingTimedOutErrorMessage) { this.machineProcessManagerProvider = machineProcessManagerProvider; this.wsAgentPingRequestFactory = wsAgentPingRequestFactory; this.wsAgentMaxStartTimeMs = wsAgentMaxStartTimeMs; diff --git a/wsagent/agent/src/main/resources/org.eclipse.che.ws-agent.json b/wsagent/agent/src/main/resources/org.eclipse.che.ws-agent.json new file mode 100644 index 0000000000..2dad37a3b6 --- /dev/null +++ b/wsagent/agent/src/main/resources/org.eclipse.che.ws-agent.json @@ -0,0 +1,18 @@ +{ + "id": "org.eclipse.che.ws-agent", + "name": "Workspace API", + "description": "Workspace API support", + "dependencies": [ + "org.eclipse.che.terminal" + ], + "properties": {}, + "servers": { + "wsagent": { + "port": "4401/tcp", + "protocol": "http", + "properties": { + "path": "/api" + } + } + } +} diff --git a/agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ws-agent.script.sh b/wsagent/agent/src/main/resources/org.eclipse.che.ws-agent.script.sh similarity index 100% rename from agents/che-core-api-agent/src/main/resources/agents/scripts/org.eclipse.che.ws-agent.script.sh rename to wsagent/agent/src/main/resources/org.eclipse.che.ws-agent.script.sh diff --git a/wsagent/agent/src/test/java/org/eclipse/che/api/agent/WsAgentLauncherTest.java b/wsagent/agent/src/test/java/org/eclipse/che/api/agent/WsAgentLauncherTest.java new file mode 100644 index 0000000000..332b701f79 --- /dev/null +++ b/wsagent/agent/src/test/java/org/eclipse/che/api/agent/WsAgentLauncherTest.java @@ -0,0 +1,219 @@ +/******************************************************************************* + * 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; + +import org.eclipse.che.api.agent.server.WsAgentPingRequestFactory; +import org.eclipse.che.api.agent.shared.model.Agent; +import org.eclipse.che.api.core.BadRequestException; +import org.eclipse.che.api.core.NotFoundException; +import org.eclipse.che.api.core.ServerException; +import org.eclipse.che.api.core.model.machine.Command; +import org.eclipse.che.api.core.model.machine.Server; +import org.eclipse.che.api.core.rest.HttpJsonRequest; +import org.eclipse.che.api.core.rest.HttpJsonRequestFactory; +import org.eclipse.che.api.core.rest.HttpJsonResponse; +import org.eclipse.che.api.environment.server.MachineProcessManager; +import org.eclipse.che.api.machine.server.exception.MachineException; +import org.eclipse.che.api.machine.server.model.impl.CommandImpl; +import org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl; +import org.eclipse.che.api.machine.server.model.impl.ServerImpl; +import org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl; +import org.eclipse.che.api.machine.server.spi.Instance; +import org.eclipse.che.api.machine.shared.Constants; +import org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.testng.MockitoTestNGListener; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.util.Collections; + +import static org.eclipse.che.api.workspace.shared.Constants.WS_AGENT_PROCESS_NAME; + +@Listeners(MockitoTestNGListener.class) +public class WsAgentLauncherTest { + private static final String MACHINE_ID = "machineId"; + private static final String WORKSPACE_ID = "testWorkspaceId"; + private static final String WS_AGENT_PORT = Constants.WS_AGENT_PORT; + private static final long WS_AGENT_MAX_START_TIME_MS = 1000; + private static final long WS_AGENT_PING_DELAY_MS = 1; + private static final String WS_AGENT_SERVER_LOCATION = "ws-agent.com:456789/"; + private static final String WS_AGENT_SERVER_URL = "http://" + WS_AGENT_SERVER_LOCATION; + private static final String WS_AGENT_SERVER_LOCATION_EXT = "ws-agent-ext.com:456789/"; + private static final String WS_AGENT_SERVER_URL_EXT = "http://" + WS_AGENT_SERVER_LOCATION; + private static final ServerPropertiesImpl SERVER_PROPERTIES = new ServerPropertiesImpl(null, + WS_AGENT_SERVER_LOCATION, + WS_AGENT_SERVER_URL); + private static final ServerImpl SERVER = new ServerImpl("ref", + "http", + WS_AGENT_SERVER_LOCATION_EXT, + WS_AGENT_SERVER_URL_EXT, + SERVER_PROPERTIES); + private static final String WS_AGENT_TIMED_OUT_MESSAGE = "timeout error message"; + + @Mock + private MachineProcessManager machineProcessManager; + @Mock + private HttpJsonRequestFactory requestFactory; + @Mock + private Instance machine; + @Mock + private HttpJsonResponse pingResponse; + @Mock + private MachineRuntimeInfoImpl machineRuntime; + @Mock + private WsAgentPingRequestFactory wsAgentPingRequestFactory; + @Mock + private Agent agent; + + private HttpJsonRequest pingRequest; + private WsAgentLauncher wsAgentLauncher; + + @BeforeMethod + public void setUp() throws Exception { + wsAgentLauncher = new WsAgentLauncher(() -> machineProcessManager, + wsAgentPingRequestFactory, null, + WS_AGENT_MAX_START_TIME_MS, + WS_AGENT_PING_DELAY_MS, + WS_AGENT_TIMED_OUT_MESSAGE + ); + pingRequest = Mockito.mock(HttpJsonRequest.class, new SelfReturningAnswer()); + Mockito.when(agent.getScript()).thenReturn("script"); + Mockito.when(machine.getId()).thenReturn(MACHINE_ID); + Mockito.when(machine.getWorkspaceId()).thenReturn(WORKSPACE_ID); + Mockito.when(machine.getRuntime()).thenReturn(machineRuntime); + Mockito.doReturn(Collections.singletonMap(WS_AGENT_PORT, SERVER)).when(machineRuntime).getServers(); + Mockito.when(requestFactory.fromUrl(Matchers.anyString())).thenReturn(pingRequest); + Mockito.when(wsAgentPingRequestFactory.createRequest(machine)).thenReturn(pingRequest); + Mockito.when(pingRequest.request()).thenReturn(pingResponse); + Mockito.when(pingResponse.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); + } + + @Test + public void shouldStartWsAgentUsingMachineExec() throws Exception { + wsAgentLauncher.launch(machine, agent); + + Mockito.verify(machineProcessManager).exec(Matchers.eq(WORKSPACE_ID), + Matchers.eq(MACHINE_ID), + Matchers.eq(new CommandImpl("org.eclipse.che.ws-agent", + "script\n" + + WsAgentLauncher.DEFAULT_WS_AGENT_RUN_COMMAND, + WS_AGENT_PROCESS_NAME)), + Matchers.eq(WsAgentLauncher.getWsAgentProcessOutputChannel(WORKSPACE_ID))); + + } + + @Test + public void shouldPingWsAgentAfterStart() throws Exception { + wsAgentLauncher.launch(machine, agent); + + Mockito.verify(pingRequest).request(); + Mockito.verify(pingResponse).getResponseCode(); + } + + @Test + public void shouldPingWsAgentMultipleTimesAfterStartIfPingFailsWithException() throws Exception { + Mockito.when(pingRequest.request()).thenThrow(new ServerException(""), + new BadRequestException(""), + new IOException()) + .thenReturn(pingResponse); + + wsAgentLauncher.launch(machine, agent); + + Mockito.verify(pingRequest, Mockito.times(4)).request(); + Mockito.verify(pingResponse).getResponseCode(); + } + + @Test + public void shouldPingWsAgentMultipleTimesAfterStartIfPingReturnsNotOKResponseCode() throws Exception { + Mockito.when(pingResponse.getResponseCode()).thenReturn(HttpURLConnection.HTTP_CREATED, + HttpURLConnection.HTTP_NO_CONTENT, + HttpURLConnection.HTTP_OK); + + wsAgentLauncher.launch(machine, agent); + + Mockito.verify(pingRequest, Mockito.times(3)).request(); + Mockito.verify(pingResponse, Mockito.times(3)).getResponseCode(); + } + + @Test + public void shouldNotPingWsAgentAfterFirstSuccessfulPing() throws Exception { + Mockito.when(pingRequest.request()).thenThrow(new ServerException("")) + .thenReturn(pingResponse); + + wsAgentLauncher.launch(machine, agent); + + Mockito.verify(pingRequest, Mockito.times(2)).request(); + Mockito.verify(pingResponse).getResponseCode(); + } + + @Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Test exception") + public void shouldThrowMachineExceptionIfMachineManagerExecInDevMachineThrowsNotFoundException() throws Exception { + Mockito.when(machineProcessManager.exec(Matchers.anyString(), + Matchers.anyString(), + Matchers.any(Command.class), + Matchers.anyString())) + .thenThrow(new NotFoundException("Test exception")); + + wsAgentLauncher.launch(machine, agent); + + Mockito.verify(machineProcessManager).exec(Matchers.anyString(), + Matchers.anyString(), + Matchers.any(Command.class), + Matchers.anyString()); + } + + @Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Test exception") + public void shouldThrowMachineExceptionIfMachineManagerExecInDevMachineThrowsMachineException() throws Exception { + Mockito.when(machineProcessManager.exec(Matchers.anyString(), + Matchers.anyString(), + Matchers.any(Command.class), + Matchers.anyString())) + .thenThrow(new MachineException("Test exception")); + + wsAgentLauncher.launch(machine, agent); + + Mockito.verify(machineProcessManager).exec(Matchers.anyString(), + Matchers.anyString(), + Matchers.any(Command.class), + Matchers.anyString()); + } + + @Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Test exception") + public void shouldThrowExceptionIfMachineManagerExecInDevMachineThrowsBadRequestException() throws Exception { + Mockito.when(machineProcessManager.exec(Matchers.anyString(), + Matchers.anyString(), + Matchers.any(Command.class), + Matchers.anyString())) + .thenThrow(new BadRequestException("Test exception")); + + wsAgentLauncher.launch(machine, agent); + + Mockito.verify(machineProcessManager).exec(Matchers.anyString(), + Matchers.anyString(), + Matchers.any(Command.class), + Matchers.anyString()); + } + + @Test(expectedExceptions = ServerException.class, + expectedExceptionsMessageRegExp = WS_AGENT_TIMED_OUT_MESSAGE) + public void shouldThrowMachineExceptionIfPingsWereUnsuccessfulTooLong() throws Exception { + Mockito.when(pingRequest.request()).thenThrow(new ServerException("")); + + wsAgentLauncher.launch(machine, agent); + } + +} diff --git a/wsagent/pom.xml b/wsagent/pom.xml index 9e687584bf..5829f718a3 100644 --- a/wsagent/pom.xml +++ b/wsagent/pom.xml @@ -25,6 +25,7 @@ pom Che Agent Parent + agent che-core-api-project-shared che-core-api-project che-core-api-git diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/CheEnvironmentEngine.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/CheEnvironmentEngine.java index 65092b78bd..2b76f645f3 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/CheEnvironmentEngine.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/environment/server/CheEnvironmentEngine.java @@ -15,8 +15,8 @@ import com.google.common.base.Strings; import org.eclipse.che.api.agent.server.AgentRegistry; import org.eclipse.che.api.agent.server.exception.AgentException; -import org.eclipse.che.api.agent.server.model.impl.AgentImpl; -import org.eclipse.che.api.agent.server.model.impl.AgentKeyImpl; +import org.eclipse.che.api.agent.shared.model.impl.AgentImpl; +import org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl; import org.eclipse.che.api.core.ApiException; import org.eclipse.che.api.core.ConflictException; import org.eclipse.che.api.core.NotFoundException; diff --git a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/environment/server/AgentConfigApplierTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/environment/server/AgentConfigApplierTest.java index b0522e0d9b..634c541477 100644 --- a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/environment/server/AgentConfigApplierTest.java +++ b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/environment/server/AgentConfigApplierTest.java @@ -15,8 +15,8 @@ import com.google.common.collect.ImmutableMap; import org.eclipse.che.api.agent.server.AgentRegistry; import org.eclipse.che.api.agent.server.impl.AgentSorter; import org.eclipse.che.api.agent.server.launcher.AgentLauncherFactory; -import org.eclipse.che.api.agent.server.model.impl.AgentImpl; -import org.eclipse.che.api.agent.server.model.impl.AgentKeyImpl; +import org.eclipse.che.api.agent.shared.model.impl.AgentImpl; +import org.eclipse.che.api.agent.shared.model.impl.AgentKeyImpl; import org.eclipse.che.api.core.model.workspace.ServerConf2; import org.eclipse.che.api.environment.server.model.CheServiceImpl; import org.eclipse.che.api.machine.server.spi.Instance; diff --git a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImplTest.java b/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImplTest.java deleted file mode 100644 index 60c0d3b1c9..0000000000 --- a/wsmaster/che-core-api-workspace/src/test/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImplTest.java +++ /dev/null @@ -1,224 +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.launcher; - -import org.eclipse.che.api.agent.server.WsAgentPingRequestFactory; -import org.eclipse.che.api.agent.shared.model.Agent; -import org.eclipse.che.api.core.BadRequestException; -import org.eclipse.che.api.core.NotFoundException; -import org.eclipse.che.api.core.ServerException; -import org.eclipse.che.api.core.model.machine.Command; -import org.eclipse.che.api.core.model.machine.Server; -import org.eclipse.che.api.core.rest.HttpJsonRequest; -import org.eclipse.che.api.core.rest.HttpJsonRequestFactory; -import org.eclipse.che.api.core.rest.HttpJsonResponse; -import org.eclipse.che.api.environment.server.MachineProcessManager; -import org.eclipse.che.api.machine.server.exception.MachineException; -import org.eclipse.che.api.machine.server.model.impl.CommandImpl; -import org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl; -import org.eclipse.che.api.machine.server.model.impl.ServerImpl; -import org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl; -import org.eclipse.che.api.machine.server.spi.Instance; -import org.eclipse.che.api.machine.shared.Constants; -import org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.testng.MockitoTestNGListener; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.util.Collections; - -import static org.eclipse.che.api.workspace.shared.Constants.WS_AGENT_PROCESS_NAME; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -@Listeners(MockitoTestNGListener.class) -public class WsAgentLauncherImplTest { - private static final String MACHINE_ID = "machineId"; - private static final String WORKSPACE_ID = "testWorkspaceId"; - private static final String WS_AGENT_PORT = Constants.WS_AGENT_PORT; - private static final long WS_AGENT_MAX_START_TIME_MS = 1000; - private static final long WS_AGENT_PING_DELAY_MS = 1; - private static final String WS_AGENT_SERVER_LOCATION = "ws-agent.com:456789/"; - private static final String WS_AGENT_SERVER_URL = "http://" + WS_AGENT_SERVER_LOCATION; - private static final String WS_AGENT_SERVER_LOCATION_EXT = "ws-agent-ext.com:456789/"; - private static final String WS_AGENT_SERVER_URL_EXT = "http://" + WS_AGENT_SERVER_LOCATION; - private static final ServerPropertiesImpl SERVER_PROPERTIES = new ServerPropertiesImpl(null, - WS_AGENT_SERVER_LOCATION, - WS_AGENT_SERVER_URL); - private static final ServerImpl SERVER = new ServerImpl("ref", - "http", - WS_AGENT_SERVER_LOCATION_EXT, - WS_AGENT_SERVER_URL_EXT, - SERVER_PROPERTIES); - private static final String WS_AGENT_TIMED_OUT_MESSAGE = "timeout error message"; - - @Mock - private MachineProcessManager machineProcessManager; - @Mock - private HttpJsonRequestFactory requestFactory; - @Mock - private Instance machine; - @Mock - private HttpJsonResponse pingResponse; - @Mock - private MachineRuntimeInfoImpl machineRuntime; - @Mock - private WsAgentPingRequestFactory wsAgentPingRequestFactory; - @Mock - private Agent agent; - - private HttpJsonRequest pingRequest; - private WsAgentLauncherImpl wsAgentLauncher; - - @BeforeMethod - public void setUp() throws Exception { - wsAgentLauncher = new WsAgentLauncherImpl(() -> machineProcessManager, - wsAgentPingRequestFactory, null, - WS_AGENT_MAX_START_TIME_MS, - WS_AGENT_PING_DELAY_MS, - WS_AGENT_TIMED_OUT_MESSAGE - ); - pingRequest = Mockito.mock(HttpJsonRequest.class, new SelfReturningAnswer()); - when(agent.getScript()).thenReturn("script"); - when(machine.getId()).thenReturn(MACHINE_ID); - when(machine.getWorkspaceId()).thenReturn(WORKSPACE_ID); - when(machine.getRuntime()).thenReturn(machineRuntime); - doReturn(Collections.singletonMap(WS_AGENT_PORT, SERVER)).when(machineRuntime).getServers(); - when(requestFactory.fromUrl(anyString())).thenReturn(pingRequest); - when(wsAgentPingRequestFactory.createRequest(machine)).thenReturn(pingRequest); - when(pingRequest.request()).thenReturn(pingResponse); - when(pingResponse.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK); - } - - @Test - public void shouldStartWsAgentUsingMachineExec() throws Exception { - wsAgentLauncher.launch(machine, agent); - - verify(machineProcessManager).exec(eq(WORKSPACE_ID), - eq(MACHINE_ID), - eq(new CommandImpl("org.eclipse.che.ws-agent", - "script\n" + WsAgentLauncherImpl.DEFAULT_WS_AGENT_RUN_COMMAND, - WS_AGENT_PROCESS_NAME)), - eq(WsAgentLauncherImpl.getWsAgentProcessOutputChannel(WORKSPACE_ID))); - - } - - @Test - public void shouldPingWsAgentAfterStart() throws Exception { - wsAgentLauncher.launch(machine, agent); - - verify(pingRequest).request(); - verify(pingResponse).getResponseCode(); - } - - @Test - public void shouldPingWsAgentMultipleTimesAfterStartIfPingFailsWithException() throws Exception { - when(pingRequest.request()).thenThrow(new ServerException(""), - new BadRequestException(""), - new IOException()) - .thenReturn(pingResponse); - - wsAgentLauncher.launch(machine, agent); - - verify(pingRequest, times(4)).request(); - verify(pingResponse).getResponseCode(); - } - - @Test - public void shouldPingWsAgentMultipleTimesAfterStartIfPingReturnsNotOKResponseCode() throws Exception { - when(pingResponse.getResponseCode()).thenReturn(HttpURLConnection.HTTP_CREATED, - HttpURLConnection.HTTP_NO_CONTENT, - HttpURLConnection.HTTP_OK); - - wsAgentLauncher.launch(machine, agent); - - verify(pingRequest, times(3)).request(); - verify(pingResponse, times(3)).getResponseCode(); - } - - @Test - public void shouldNotPingWsAgentAfterFirstSuccessfulPing() throws Exception { - when(pingRequest.request()).thenThrow(new ServerException("")) - .thenReturn(pingResponse); - - wsAgentLauncher.launch(machine, agent); - - verify(pingRequest, times(2)).request(); - verify(pingResponse).getResponseCode(); - } - - @Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Test exception") - public void shouldThrowMachineExceptionIfMachineManagerExecInDevMachineThrowsNotFoundException() throws Exception { - when(machineProcessManager.exec(anyString(), - anyString(), - any(Command.class), - anyString())) - .thenThrow(new NotFoundException("Test exception")); - - wsAgentLauncher.launch(machine, agent); - - verify(machineProcessManager).exec(anyString(), - anyString(), - any(Command.class), - anyString()); - } - - @Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Test exception") - public void shouldThrowMachineExceptionIfMachineManagerExecInDevMachineThrowsMachineException() throws Exception { - when(machineProcessManager.exec(anyString(), - anyString(), - any(Command.class), - anyString())) - .thenThrow(new MachineException("Test exception")); - - wsAgentLauncher.launch(machine, agent); - - verify(machineProcessManager).exec(anyString(), - anyString(), - any(Command.class), - anyString()); - } - - @Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Test exception") - public void shouldThrowExceptionIfMachineManagerExecInDevMachineThrowsBadRequestException() throws Exception { - when(machineProcessManager.exec(anyString(), - anyString(), - any(Command.class), - anyString())) - .thenThrow(new BadRequestException("Test exception")); - - wsAgentLauncher.launch(machine, agent); - - verify(machineProcessManager).exec(anyString(), - anyString(), - any(Command.class), - anyString()); - } - - @Test(expectedExceptions = ServerException.class, - expectedExceptionsMessageRegExp = WS_AGENT_TIMED_OUT_MESSAGE) - public void shouldThrowMachineExceptionIfPingsWereUnsuccessfulTooLong() throws Exception { - when(pingRequest.request()).thenThrow(new ServerException("")); - - wsAgentLauncher.launch(machine, agent); - } - -}