diff --git a/dashboard/src/app/workspaces/workspace-details/environments/list-agents/list-agents.controller.ts b/dashboard/src/app/workspaces/workspace-details/environments/list-agents/list-agents.controller.ts index 635c6a5c83c5..b466729f91ca 100644 --- a/dashboard/src/app/workspaces/workspace-details/environments/list-agents/list-agents.controller.ts +++ b/dashboard/src/app/workspaces/workspace-details/environments/list-agents/list-agents.controller.ts @@ -27,42 +27,41 @@ export class ListAgentsController { this.cheAgent.fetchAgents().then(() => { this.buildAgentsList(); - }, (error) => { - if (error.status === 304) { - this.buildAgentsList(); - } }); } buildAgentsList() { this.agentsList = []; - this.availableAgents = this.cheAgent.getAgents(); - this.availableAgents.forEach(agent => { - let isEnabled = this.isEnabled(agent, this.agents); - this.agentsList.push({ "name": agent, "isEnabled": isEnabled }); + this.allAgents = this.cheAgent.getAgents(); + + this.allAgents.forEach(agent => { + let agentItem = angular.copy(agent); + let isEnabled = this.isEnabled(agent.id, this.agents); + agentItem.isEnabled = isEnabled; + this.agentsList.push(agentItem); }); } updateAgent(agent) { if (agent.isEnabled) { - this.agents.push(agent.name); + this.agents.push(agent.id); } else { - this.agents.splice(this.agents.indexOf(agent.name), 1); + this.agents.splice(this.agents.indexOf(agent.id), 1); } - return this.agentsOnChange().then(() => { this.buildAgentsList() }); + this.agentsOnChange(); } /** * Switching of the "ws-agent" must happen only via "Dev" slider. * "ws-agent" should be listed, but always disabled regardless of the state - * @param agentName {string} + * @param agentId {string} */ - needToDisable(agentName) { - return (agentName === "org.eclipse.che.ws-agent"); + needToDisable(agentId) { + return (agentId === "org.eclipse.che.ws-agent"); } - isEnabled(agentName, agents) { - return (-1 !== agents.indexOf(agentName)); + isEnabled(agentId, agents) { + return (-1 !== agents.indexOf(agentId)); } } diff --git a/dashboard/src/app/workspaces/workspace-details/environments/list-agents/list-agents.html b/dashboard/src/app/workspaces/workspace-details/environments/list-agents/list-agents.html index e8d424a43457..bac1f9af59c9 100644 --- a/dashboard/src/app/workspaces/workspace-details/environments/list-agents/list-agents.html +++ b/dashboard/src/app/workspaces/workspace-details/environments/list-agents/list-agents.html @@ -27,7 +27,7 @@ - +
@@ -38,7 +38,7 @@
ACTIVE @@ -47,7 +47,7 @@
- No Description Available + {{agent.description}}
diff --git a/dashboard/src/components/api/che-agent.factory.ts b/dashboard/src/components/api/che-agent.factory.ts index 45604619e487..9b3f93c81090 100644 --- a/dashboard/src/components/api/che-agent.factory.ts +++ b/dashboard/src/components/api/che-agent.factory.ts @@ -21,34 +21,45 @@ export class CheAgent { * Default constructor that is using resource * @ngInject for Dependency injection */ - constructor ($resource) { + constructor($resource, $q) { // keep resource this.$resource = $resource; + this.$q = $q; // agents this.agents = []; // remote call - this.remoteAgentAPI = this.$resource('/api/agent',{}, { - getAgents: {method: 'GET', url: '/api/agent', isArray: true - }}); + this.remoteAgentAPI = this.$resource('/api/agent', {}, { + getAgents: { method: 'GET', url: '/api/agent', isArray: true } + }); } /** * Fetch the agents */ fetchAgents() { + var defer = this.$q.defer(); let promise = this.remoteAgentAPI.getAgents().$promise; - let updatedPromise = promise.then((agents) => { + + promise.then((agents) => { // reset global list this.agents.length = 0; agents.forEach((agent) => { this.agents.push(agent); }); + defer.resolve(); + }, (error) => { + if (error.status != 304) { + defer.reject(error); + } else { + defer.resolve(); + } }); - return updatedPromise; + + return defer.promise; } /** @@ -58,5 +69,5 @@ export class CheAgent { getAgents() { return this.agents; } - + } diff --git a/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/dto/AgentDto.java b/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/dto/AgentDto.java index fd4e0c06795c..df9a9150dfaa 100644 --- a/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/dto/AgentDto.java +++ b/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/dto/AgentDto.java @@ -22,6 +22,13 @@ @DTO public interface AgentDto extends Agent { + @Override + String getId(); + + void setId(String id); + + AgentDto withId(String id); + @Override String getName(); @@ -36,6 +43,13 @@ public interface AgentDto extends Agent { AgentDto withVersion(String version); + @Override + String getDescription(); + + void setDescription(String description); + + AgentDto withDescription(String description); + @Override List getDependencies(); diff --git a/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/Agent.java b/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/Agent.java index b6f5d0bab99f..809b9dab914a 100644 --- a/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/Agent.java +++ b/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/Agent.java @@ -19,6 +19,11 @@ * @author Anatoliy Bazko */ public interface Agent { + + /** + * Returns the id of the agent. + */ + String getId(); /** * Returns the name of the agent. @@ -30,6 +35,11 @@ public interface Agent { */ String getVersion(); + /** + * Returns the description of the agent. + */ + String getDescription(); + /** * Returns the depending agents, that must be applied before. */ diff --git a/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/AgentKey.java b/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/AgentKey.java index 35c70681de46..ffad05b81211 100644 --- a/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/AgentKey.java +++ b/wsmaster/che-core-api-agent-shared/src/main/java/org/eclipse/che/api/agent/shared/model/AgentKey.java @@ -13,16 +13,16 @@ import org.eclipse.che.commons.annotation.Nullable; /** - * A pair of name and version of the agent. + * A pair of id and version of the agent. * Version part is not mandatory. * * @author Anatolii Bazko */ public interface AgentKey { /** - * @return the name of the agent + * @return the id of the agent */ - String getName(); + String getId(); /** * @return the version of the agent diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistry.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistry.java index ed571dd5d716..ab50f980a77a 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistry.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistry.java @@ -15,6 +15,7 @@ import org.eclipse.che.api.agent.shared.model.Agent; import org.eclipse.che.api.agent.shared.model.AgentKey; +import java.util.Collection; import java.util.List; /** @@ -43,23 +44,23 @@ public interface AgentRegistry { /** * Returns a list of the available versions of the specific agent. * - * @param name - * the name of the agent + * @param id + * the id of the agent * @return list of versions * @throws AgentNotFoundException * if agent not found in the registry * @throws AgentException * if unexpected error occurred */ - List getVersions(String name) throws AgentException; + List getVersions(String id) throws AgentException; /** - * Returns the list of available agents. + * Returns the collection of available agents. * - * @return list of agents + * @return collection of agents * @throws AgentException * if unexpected error occurred */ - List getAgents() throws AgentException; + Collection getAgents() throws AgentException; } diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryService.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryService.java index fe0ca9c12b16..d68779b54a57 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryService.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryService.java @@ -32,6 +32,8 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; + +import java.util.Collection; import java.util.List; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; @@ -57,15 +59,15 @@ public AgentRegistryService(AgentRegistry agentRegistry) { } @GET - @Path("/name/{name}") + @Path("/id/{id}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Gets the latest version of the agent", response = AgentDto.class) @ApiResponses({@ApiResponse(code = 200, message = "The response contains requested agent entity"), @ApiResponse(code = 404, message = "Agent not found in the registry"), @ApiResponse(code = 500, message = "Internal server error occurred")}) - public Agent getByName(@ApiParam("The agent name") @PathParam("name") String name) throws ApiException { + public Agent getById(@ApiParam("The agent id") @PathParam("id") String id) throws ApiException { try { - return asDto(agentRegistry.getAgent(new AgentKeyImpl(name))); + return asDto(agentRegistry.getAgent(new AgentKeyImpl(id))); } catch (AgentNotFoundException e) { throw new NotFoundException(e.getMessage()); } catch (AgentException e) { @@ -74,16 +76,16 @@ public Agent getByName(@ApiParam("The agent name") @PathParam("name") String nam } @GET - @Path("/name/{name}/version/{version}") + @Path("/id/{id}/version/{version}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Gets the specific version of the agent", response = AgentDto.class) @ApiResponses({@ApiResponse(code = 200, message = "The response contains requested agent entity"), @ApiResponse(code = 404, message = "Agent not found in the registry"), @ApiResponse(code = 500, message = "Internal server error occurred")}) - public Agent getByName(@ApiParam("The agent name") @PathParam("name") String name, + public Agent getByName(@ApiParam("The agent id") @PathParam("id") String id, @ApiParam("The agent version") @PathParam("version") String version) throws ApiException { try { - return asDto(agentRegistry.getAgent(new AgentKeyImpl(name, version))); + return asDto(agentRegistry.getAgent(new AgentKeyImpl(id, version))); } catch (AgentNotFoundException e) { throw new NotFoundException(e.getMessage()); } catch (AgentException e) { @@ -93,15 +95,15 @@ public Agent getByName(@ApiParam("The agent name") @PathParam("name") String nam } @GET - @Path("/versions/{name}") + @Path("/versions/{id}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Get a list of available versions of the giving agent", response = List.class) @ApiResponses({@ApiResponse(code = 200, message = "The response contains available versions of the giving agent"), @ApiResponse(code = 404, message = "Agent not found"), @ApiResponse(code = 500, message = "Internal server error occurred")}) - public List getVersions(@ApiParam("The agent name") @PathParam("name") String name) throws ApiException { + public List getVersions(@ApiParam("The agent id") @PathParam("id") String id) throws ApiException { try { - return agentRegistry.getVersions(name); + return agentRegistry.getVersions(id); } catch (AgentNotFoundException e) { throw new NotFoundException(e.getMessage()); } catch (AgentException e) { @@ -111,10 +113,10 @@ public List getVersions(@ApiParam("The agent name") @PathParam("name") S @GET @Produces(APPLICATION_JSON) - @ApiOperation(value = "Get a list of the available agents", response = List.class) - @ApiResponses({@ApiResponse(code = 200, message = "The response contains list of available agents"), + @ApiOperation(value = "Get a collection of the available agents", response = List.class) + @ApiResponses({@ApiResponse(code = 200, message = "The response contains collection of available agents"), @ApiResponse(code = 500, message = "Internal server error occurred")}) - public List getAgents() throws ApiException { + public Collection getAgents() throws ApiException { try { return agentRegistry.getAgents(); } catch (AgentNotFoundException e) { diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryUrlProvider.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryUrlProvider.java index 36948af563f4..5a0ca618bdf0 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryUrlProvider.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/AgentRegistryUrlProvider.java @@ -34,10 +34,10 @@ public interface AgentRegistryUrlProvider { * Returns url to fetch available versions of the agent. * @param name - * the agent name + * the agent id * @return {@link URL} * @throws AgentException * if unexpected error occurred */ - URL getAgentVersionsUrl(String name) throws AgentException; + URL getAgentVersionsUrl(String id) throws AgentException; } diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/DtoConverter.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/DtoConverter.java index 7d4d4aa471d4..30e0ba97df23 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/DtoConverter.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/DtoConverter.java @@ -21,8 +21,10 @@ public class DtoConverter { public static AgentDto asDto(Agent agent) { - return newDto(AgentDto.class).withName(agent.getName()) + return newDto(AgentDto.class).withId(agent.getId()) + .withName(agent.getName()) .withVersion(agent.getVersion()) + .withDescription(agent.getDescription()) .withProperties(agent.getProperties()) .withScript(agent.getScript()) .withDependencies(agent.getDependencies()); diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImpl.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImpl.java deleted file mode 100644 index 7af9a8bbd1c8..000000000000 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImpl.java +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2016 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.reflect.TypeToken; -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.AgentRegistryUrlProvider; -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.ApiException; -import org.eclipse.che.api.core.NotFoundException; -import org.eclipse.che.api.core.rest.HttpJsonRequestFactory; -import org.eclipse.che.api.core.rest.HttpJsonResponse; -import org.eclipse.che.api.core.util.FileCleaner; -import org.eclipse.che.dto.server.DtoFactory; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.util.List; - -import static java.lang.String.format; -import static java.util.Arrays.asList; -import static org.eclipse.che.commons.lang.IoUtil.downloadFile; -import static org.eclipse.che.commons.lang.IoUtil.readAndCloseQuietly; - -/** - * @author Anatoliy Bazko - */ -@Singleton -public class AgentRegistryImpl implements AgentRegistry { - private final AgentRegistryUrlProvider urlProvider; - private final HttpJsonRequestFactory requestFactory; - - @Inject - public AgentRegistryImpl(AgentRegistryUrlProvider urlProvider, - HttpJsonRequestFactory requestFactory) { - this.urlProvider = urlProvider; - this.requestFactory = requestFactory; - } - - @Override - public Agent getAgent(AgentKey agentKey) throws AgentException { - return doGetRemoteAgent(urlProvider.getAgentUrl(agentKey)); - } - - @Override - public List getVersions(String name) throws AgentException { - URL url = urlProvider.getAgentVersionsUrl(name); - try { - HttpJsonResponse response = requestFactory.fromUrl(url.toString()).useGetMethod().request(); - - @SuppressWarnings("unchecked") - List versions = response.as(List.class, new TypeToken>() { }.getType()); - - return versions; - } catch (NotFoundException e) { - throw new AgentNotFoundException(format("Agent %s not found", name), e); - } catch (IOException | ApiException e) { - throw new AgentException(format("Can't fetch available %s version.", name), e); - } - } - - @Override - public List getAgents() throws AgentException { - return asList("org.eclipse.che.terminal", - "org.eclipse.che.ws-agent", - "org.eclipse.che.ssh"); - } - - 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); - } - } - } - } -} diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryUrlProviderImpl.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryUrlProviderImpl.java index 3838dc81e9bf..d008398af3c8 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryUrlProviderImpl.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentRegistryUrlProviderImpl.java @@ -29,7 +29,7 @@ @Singleton public class AgentRegistryUrlProviderImpl implements AgentRegistryUrlProvider { public static final String VERSION = "${version}"; - public static final String NAME = "${name}"; + public static final String ID = "${id}"; private final String agentLatestVersionUrl; private final String agentSpecificVersionUrl; @@ -48,9 +48,9 @@ public AgentRegistryUrlProviderImpl(@Named("machine.agent.latest_version_url") S public URL getAgentUrl(AgentKey agentKey) throws AgentException { String url; if (agentKey.getVersion() == null) { - url = agentLatestVersionUrl.replace(NAME, agentKey.getName()); + url = agentLatestVersionUrl.replace(ID, agentKey.getId()); } else { - url = agentSpecificVersionUrl.replace(NAME, agentKey.getName()).replace(VERSION, agentKey.getVersion()); + url = agentSpecificVersionUrl.replace(ID, agentKey.getId()).replace(VERSION, agentKey.getVersion()); } try { return new URL(url); @@ -61,8 +61,8 @@ public URL getAgentUrl(AgentKey agentKey) throws AgentException { @Override - public URL getAgentVersionsUrl(String name) throws AgentException { - String url = agentVersionsUrl.replace(NAME, name); + public URL getAgentVersionsUrl(String id) throws AgentException { + String url = agentVersionsUrl.replace(ID, id); try { return new URL(url); } catch (MalformedURLException e) { diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentSorter.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentSorter.java index 49652023df5a..ba6f900d2f0b 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentSorter.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/AgentSorter.java @@ -71,25 +71,25 @@ public List sort(@Nullable List agentKeys) throws AgentExcepti } private void doSort(AgentKey agentKey, List sorted, Set pending) throws AgentException { - String agentName = agentKey.getName(); + String agentId = agentKey.getId(); - Optional alreadySorted = sorted.stream().filter(k -> k.getName().equals(agentName)).findFirst(); + Optional alreadySorted = sorted.stream().filter(k -> k.getId().equals(agentId)).findFirst(); if (alreadySorted.isPresent()) { return; } - pending.add(agentName); + pending.add(agentId); Agent agent = agentRegistry.getAgent(agentKey); for (String dependency : agent.getDependencies()) { if (pending.contains(dependency)) { throw new AgentException( - String.format("Agents circular dependency found between '%s' and '%s'", dependency, agentName)); + String.format("Agents circular dependency found between '%s' and '%s'", dependency, agentId)); } doSort(AgentKeyImpl.parse(dependency), sorted, pending); } sorted.add(agentKey); - pending.remove(agentName); + pending.remove(agentId); } } diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImpl.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImpl.java index 02a89224f823..fe586031f1ff 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImpl.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImpl.java @@ -33,6 +33,7 @@ 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; @@ -61,42 +62,42 @@ public class LocalAgentRegistryImpl implements AgentRegistry { private static final Pattern AGENTS = Pattern.compile(".*[//]?agents/[^//]+[.]json"); private final Map agents; - private final List agentNames; + private final List agentIds; @Inject public LocalAgentRegistryImpl() throws IOException { this.agents = new HashMap<>(); findAgents(); - this.agentNames = ImmutableList.copyOf(agents.keySet()); + this.agentIds = ImmutableList.copyOf(agents.keySet()); } @Override public Agent getAgent(AgentKey agentKey) throws AgentException { - return doGetAgent(agentKey.getName()); + return doGetAgent(agentKey.getId()); } @Override - public List getVersions(String name) throws AgentException { - Agent agent = doGetAgent(name); + public List getVersions(String id) throws AgentException { + Agent agent = doGetAgent(id); String version = agent.getVersion(); return version == null ? Collections.emptyList() : singletonList(version); } @Override - public List getAgents() throws AgentException { - return agentNames; + public Collection getAgents() throws AgentException { + return agents.values(); } - protected Agent doGetAgent(String name) throws AgentException { + protected Agent doGetAgent(String id) throws AgentException { try { - URL url = new URL(name); + URL url = new URL(id); return doGetRemoteAgent(url); } catch (MalformedURLException ignored) { - // name doesn't represent a url + // id doesn't represent a url } - Optional agent = Optional.ofNullable(agents.get(name)); - return agent.orElseThrow(() -> new AgentNotFoundException(format("Agent %s not found", name))); + 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 { @@ -143,7 +144,7 @@ protected void findAgents() throws IOException { public void accept(InputStream inputStream) { try { final Agent agent = DtoFactory.getInstance().createDtoFromJson(inputStream, AgentDto.class); - agents.put(agent.getName(), agent); + agents.put(agent.getId(), agent); } catch (IOException e) { LOG.error("Can't create agent.", e); } diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AbstractAgentLauncher.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AbstractAgentLauncher.java index d3cb1262385e..d1f84cfdc261 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AbstractAgentLauncher.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AbstractAgentLauncher.java @@ -65,7 +65,7 @@ public AbstractAgentLauncher(long agentMaxStartTimeMs, public void launch(Instance machine, Agent agent) throws ServerException { try { final InstanceProcess process = start(machine, agent); - LOG.debug("Waiting for agent {} is launched. Workspace ID:{}", agent.getName(), machine.getWorkspaceId()); + LOG.debug("Waiting for agent {} is launched. Workspace ID:{}", agent.getId(), machine.getWorkspaceId()); final long pingStartTimestamp = System.currentTimeMillis(); while (System.currentTimeMillis() - pingStartTimestamp < agentMaxStartTimeMs) { @@ -91,7 +91,7 @@ public void launch(Instance machine, Agent agent) throws ServerException { protected InstanceProcess start(final Instance machine, final Agent agent) throws ServerException { - final Command command = new CommandImpl(agent.getName(), agent.getScript(), "agent"); + final Command command = new CommandImpl(agent.getId(), agent.getScript(), "agent"); final InstanceProcess process = machine.createProcess(command, null); final LineConsumer lineConsumer = new AbstractLineConsumer() { @Override diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AgentLauncher.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AgentLauncher.java index 37aa08f3a127..3f90f9383b92 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AgentLauncher.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AgentLauncher.java @@ -25,9 +25,9 @@ public interface AgentLauncher { /** - * @return the name of the agent that launcher is designed for + * @return the id of the agent that launcher is designed for */ - String getAgentName(); + String getAgentId(); /** * @return the machine type that launcher is designed for diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AgentLauncherFactory.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AgentLauncherFactory.java index 84d188c6d744..c58cb98be6b4 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AgentLauncherFactory.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/AgentLauncherFactory.java @@ -41,7 +41,7 @@ public AgentLauncherFactory(Set launchers, DefaultAgentLauncher d * Find launcher for given agent independently of version. * If the specific {@link AgentLauncher} isn't registered then the default one will be used. * - * @see Agent#getName() + * @see Agent#getId() * @see MachineConfig#getType() * * @param agentName @@ -50,9 +50,9 @@ public AgentLauncherFactory(Set launchers, DefaultAgentLauncher d * the machine type * @return {@link AgentLauncher} */ - public AgentLauncher find(String agentName, String machineType) { + public AgentLauncher find(String agentId, String machineType) { return launchers.stream() - .filter(l -> l.getAgentName().equals(agentName)) + .filter(l -> l.getAgentId().equals(agentId)) .filter(l -> l.getMachineType().equals(machineType)) .findAny() .orElse(defaultLauncher); diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/DefaultAgentLauncher.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/DefaultAgentLauncher.java index 9a3e2fb82d58..77ca46e95a5f 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/DefaultAgentLauncher.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/DefaultAgentLauncher.java @@ -42,7 +42,7 @@ public DefaultAgentLauncher() { } @Override public void launch(Instance machine, Agent agent) throws ServerException { - final Command command = new CommandImpl(agent.getName(), agent.getScript(), "agent"); + final Command command = new CommandImpl(agent.getId(), agent.getScript(), "agent"); final InstanceProcess process = machine.createProcess(command, null); final LineConsumer lineConsumer = new AbstractLineConsumer() { @Override @@ -67,7 +67,7 @@ public void writeLine(String line) throws IOException { } @Override - public String getAgentName() { + public String getAgentId() { return "any"; } diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/ProcessIsLaunchedChecker.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/ProcessIsLaunchedChecker.java index 1fea8bf80c9e..8d4b5770dc1e 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/ProcessIsLaunchedChecker.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/launcher/ProcessIsLaunchedChecker.java @@ -43,7 +43,7 @@ public ProcessIsLaunchedChecker(String processNameToWait) { @Override public boolean isLaunched(Agent agent, InstanceProcess process, Instance machine) throws MachineException { - Command command = new CommandImpl(format("Wait for %s, try %d", agent.getName(), ++counter), + Command command = new CommandImpl(format("Wait for %s, try %d", agent.getId(), ++counter), format(CHECK_COMMAND, processNameToWait), "test"); diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentImpl.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentImpl.java index f52118d5835b..ab37675eb13f 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentImpl.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentImpl.java @@ -24,32 +24,43 @@ * @author Anatoliy Bazko */ public class AgentImpl implements Agent { + private final String id; private final String name; private final String version; + private final String description; private final List dependencies; private final Map properties; private final String script; - public AgentImpl(String name, - String version, + public AgentImpl(String id, String name, + String version, String description, List dependencies, Map properties, String script) { + this.id = id; this.name = name; this.version = version; + this.description = description; this.dependencies = dependencies; this.properties = properties; this.script = script; } public AgentImpl(Agent agent) { - this(agent.getName(), + this(agent.getId(), + agent.getName(), agent.getVersion(), + agent.getDescription(), agent.getDependencies(), agent.getProperties(), agent.getScript()); } + @Override + public String getId() { + return id; + } + @Override public String getName() { return name; @@ -59,6 +70,11 @@ public String getName() { public String getVersion() { return version; } + + @Override + public String getDescription() { + return description; + } @Override public List getDependencies() { @@ -84,7 +100,8 @@ public boolean equals(Object obj) { return false; } final AgentImpl that = (AgentImpl)obj; - return Objects.equals(name, that.name) + return Objects.equals(id, that.id) + && Objects.equals(name, that.name) && Objects.equals(version, that.version) && getDependencies().equals(that.getDependencies()) && getProperties().equals(that.getProperties()) @@ -94,6 +111,7 @@ && getProperties().equals(that.getProperties()) @Override public int hashCode() { int hash = 7; + hash = 31 * hash + Objects.hashCode(id); hash = 31 * hash + Objects.hashCode(name); hash = 31 * hash + Objects.hashCode(version); hash = 31 * hash + getDependencies().hashCode(); @@ -105,7 +123,9 @@ public int hashCode() { @Override public String toString() { return "AgentImpl{" + - "name='" + name + '\'' + + "id='" + id + '\'' + + ", name='" + name + '\'' + + ", description='" + description + '\'' + ", version='" + version + '\'' + ", dependencies='" + dependencies + '\'' + ", properties='" + properties + "\'}"; diff --git a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentKeyImpl.java b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentKeyImpl.java index 551450126072..e2ba6b9a6ead 100644 --- a/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentKeyImpl.java +++ b/wsmaster/che-core-api-agent/src/main/java/org/eclipse/che/api/agent/server/model/impl/AgentKeyImpl.java @@ -19,11 +19,11 @@ * @author Anatolii Bazko */ public class AgentKeyImpl implements AgentKey { - private final String name; + private final String id; private final String version; - public AgentKeyImpl(String name, @Nullable String version) { - this.name = name; + public AgentKeyImpl(String id, @Nullable String version) { + this.id = id; this.version = version; } @@ -31,8 +31,8 @@ public AgentKeyImpl(String name) { this(name, null); } - public String getName() { - return name; + public String getId() { + return id; } public String getVersion() { @@ -40,7 +40,7 @@ public String getVersion() { } /** - * Factory method. Agent key is basically a string meeting the format: {@code name:version}. + * Factory method. Agent key is basically a string meeting the format: {@code id:version}. * The version part can be omitted. * * @throws IllegalArgumentException @@ -63,23 +63,23 @@ public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof AgentKeyImpl)) return false; AgentKeyImpl agentKey = (AgentKeyImpl)o; - return Objects.equals(name, agentKey.name) && + return Objects.equals(id, agentKey.id) && Objects.equals(version, agentKey.version); } @Override public int hashCode() { - return Objects.hash(name, version); + return Objects.hash(id, version); } public String asString() { - return name + (version != null ? ":" + version : ""); + return id + (version != null ? ":" + version : ""); } @Override public String toString() { return "AgentImpl{" + - "name='" + name + '\'' + + "name='" + id + '\'' + ", version='" + version + "\'}"; } } diff --git a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.csharp.json b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.csharp.json index 525feb196288..834c7ed60955 100644 --- a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.csharp.json +++ b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.csharp.json @@ -1,5 +1,7 @@ { -"name": "org.eclipse.che.ls.csharp", +"id" : "org.eclipse.che.ls.csharp", +"name": "C# language server", +"description" : "C# support", "dependencies": [], "properties": { }, diff --git a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.json.json b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.json.json index 0910c807056a..e389eed67d97 100644 --- a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.json.json +++ b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.json.json @@ -1,5 +1,7 @@ { -"name": "org.eclipse.che.ls.json", +"id": "org.eclipse.che.ls.json", +"name": "JSON language server", +"description" : "JSON support", "dependencies": [], "properties": { }, diff --git a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.php.json b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.php.json index b253109d1cdf..00dbc18fcb9e 100644 --- a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.php.json +++ b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ls.php.json @@ -1,5 +1,7 @@ { -"name": "org.eclipse.che.ls.php", +"id": "org.eclipse.che.ls.php", +"name": "PHP language server", +"description" : "PHP support", "dependencies": [], "properties": {}, "script" : "#\n# Copyright (c) 2012-2016 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\nLINUX_TYPE=$(cat /etc/os-release | grep ^ID= | tr '[:upper:]' '[:lower:]')\nLINUX_VERSION=$(cat /etc/os-release | grep ^VERSION_ID=)\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\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 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 /etc/os-release\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-crane-server/server.js\" > ${LS_LAUNCHER}" diff --git a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ssh.json b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ssh.json index 604f32cfc386..6a9ab8db9881 100644 --- a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ssh.json +++ b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ssh.json @@ -1,5 +1,7 @@ { -"name": "org.eclipse.che.ssh", +"id": "org.eclipse.che.ssh", +"name": "SSH", +"description" : "SSH support", "dependencies": [], "properties": {}, "script" : "#\n# Copyright (c) 2012-2016 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\nLINUX_TYPE=$(cat /etc/os-release | grep ^ID= | tr '[:upper:]' '[:lower:]')\nLINUX_VERSION=$(cat /etc/os-release | grep ^VERSION_ID=)\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# 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 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\nelse\n >&2 echo \"Unrecognized Linux Type\"\n >&2 cat /etc/os-release\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${SUDO} /usr/bin/ssh-keygen -A && ${SUDO} /usr/sbin/sshd -D\n" diff --git a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.terminal.json b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.terminal.json index 89c8d8d489ae..4d55167bd158 100644 --- a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.terminal.json +++ b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.terminal.json @@ -1,5 +1,7 @@ { -"name": "org.eclipse.che.terminal", +"id": "org.eclipse.che.terminal", +"name": "Terminal", +"description" : "Terminal support", "dependencies": [], "properties": { "ports": "terminal:4411/tcp" diff --git a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ws-agent.json b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ws-agent.json index 2a6cce879d1e..eef79a0a4629 100644 --- a/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ws-agent.json +++ b/wsmaster/che-core-api-agent/src/main/resources/agents/org.eclipse.che.ws-agent.json @@ -1,5 +1,7 @@ { -"name": "org.eclipse.che.ws-agent", +"id": "org.eclipse.che.ws-agent", +"name": "WS-agent", +"description" : "WS-agent support", "dependencies": ["org.eclipse.che.terminal"], "properties": { "ports": "ws-agent.debug:4403/tcp,ws-agent:4401/tcp" diff --git a/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentKeyImplTest.java b/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentKeyImplTest.java index 4680cf779e4d..e8e6698859b6 100644 --- a/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentKeyImplTest.java +++ b/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentKeyImplTest.java @@ -23,22 +23,22 @@ public class AgentKeyImplTest { @Test public void testAgentKeyWithNameAndVersion() { - AgentKeyImpl agentKey = AgentKeyImpl.parse("name:1"); + AgentKeyImpl agentKey = AgentKeyImpl.parse("id:1"); - assertEquals(agentKey.getName(), "name"); + assertEquals(agentKey.getId(), "id"); assertEquals(agentKey.getVersion(), "1"); } @Test - public void testParseAgentKeyWithName() { - AgentKeyImpl agentKey = AgentKeyImpl.parse("name"); + public void testParseAgentKeyWithId() { + AgentKeyImpl agentKey = AgentKeyImpl.parse("id"); - assertEquals(agentKey.getName(), "name"); + assertEquals(agentKey.getId(), "id"); assertNull(agentKey.getVersion()); } @Test(expectedExceptions = IllegalArgumentException.class) public void testParseAgentKeyFails() { - AgentKeyImpl.parse("name:1:2"); + AgentKeyImpl.parse("id:1:2"); } } diff --git a/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImplTest.java b/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImplTest.java deleted file mode 100644 index 31bb39fab405..000000000000 --- a/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentRegistryImplTest.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012-2016 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.server.AgentRegistryUrlProvider; -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.Agent; -import org.eclipse.che.api.agent.shared.model.AgentKey; -import org.eclipse.che.api.core.rest.DefaultHttpJsonRequestFactory; -import org.eclipse.che.dto.server.JsonArrayImpl; -import org.everrest.assured.EverrestJetty; -import org.mockito.Mock; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.mockito.testng.MockitoTestNGListener; -import org.testng.ITestContext; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Listeners; -import org.testng.annotations.Test; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.Collection; - -import static java.lang.String.format; -import static java.nio.file.Files.copy; -import static java.util.Collections.singletonList; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.when; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -/** - * @author Anatoliy Bazko - */ -@Listeners(value = {EverrestJetty.class, MockitoTestNGListener.class}) -public class AgentRegistryImplTest { - - @SuppressWarnings("unused") - private RegistryService service; - @Mock - private AgentRegistryUrlProvider urlProvider; - private AgentRegistryImpl agentRegistry; - - @BeforeMethod - public void setUp(ITestContext context) throws Exception { - agentRegistry = new AgentRegistryImpl(urlProvider, new DefaultHttpJsonRequestFactory()); - - final Object port = context.getAttribute(EverrestJetty.JETTY_PORT); - when(urlProvider.getAgentUrl(any(AgentKey.class))).thenAnswer(new Answer() { - @Override - public URL answer(InvocationOnMock invocation) throws Throwable { - AgentKey agentKey = (AgentKey)invocation.getArguments()[0]; - if (agentKey.getVersion() == null) { - return new URL("http://localhost:" + port + "/rest/registry/agent/" + agentKey.getName()); - } else { - return new URL("http://localhost:" + port + "/rest/registry/agent/" + agentKey.getName() + "/" + agentKey.getVersion()); - } - } - }); - when(urlProvider.getAgentVersionsUrl(anyString())).thenAnswer(new Answer() { - @Override - public URL answer(InvocationOnMock invocation) throws Throwable { - String name = (String)invocation.getArguments()[0]; - return new URL("http://localhost:" + port + "/rest/registry/updates/" + name); - } - }); - - service = new RegistryService(); - } - - @Test - public void testCreateSpecificVersionAgent() throws Exception { - Agent agent = agentRegistry.getAgent(new AgentKeyImpl("org.eclipse.che.ws-agent", "1.0")); - - assertEquals(agent.getName(), "org.eclipse.che.ws-agent"); - assertEquals(agent.getVersion(), "1.0"); - } - - @Test - public void testCreateLatestVersionAgent() throws Exception { - Agent agent = agentRegistry.getAgent(new AgentKeyImpl("org.eclipse.che.ws-agent")); - - assertEquals(agent.getName(), "org.eclipse.che.ws-agent"); - assertEquals(agent.getVersion(), "2.0"); - } - - - @Test(expectedExceptions = AgentException.class) - public void testGetConfigShouldThrowExceptionIfAgentNotFound() throws Exception { - agentRegistry.getAgent(new AgentKeyImpl("terminal", "1.0")); - } - - @Test - public void testGetAgentsVersion() throws Exception { - Collection versions = agentRegistry.getVersions("org.eclipse.che.ws-agent"); - - assertEquals(versions.size(), 1); - assertTrue(versions.contains("1.0.0")); - } - - @Test(expectedExceptions = AgentNotFoundException.class) - public void testGetAgentsVersionShouldFailsIfAgentUnknown() throws Exception { - agentRegistry.getVersions("terminal"); - } - - @Path("registry") - public class RegistryService { - - @GET - @Path("agent/{artifact}/{version}") - @Produces(MediaType.APPLICATION_OCTET_STREAM) - public Response getAgent(@PathParam("artifact") String artifact, @PathParam("version") String version) throws IOException { - return doGetAgent(artifact, version); - } - - - @GET - @Path("agent/{artifact}") - @Produces(MediaType.APPLICATION_OCTET_STREAM) - public Response getLatestAgent(@PathParam("artifact") String artifact) throws IOException { - return doGetAgent(artifact, "2.0"); - } - - @GET - @Produces(MediaType.APPLICATION_JSON) - @Path("/updates/{artifact}") - public Response getUpdates(@PathParam("artifact") final String artifact) { - if (!artifact.endsWith("org.eclipse.che.ws-agent")) { - return Response.status(Response.Status.NOT_FOUND).entity("{ \"message\" : \"not found\" }").build(); - } - return Response.status(Response.Status.OK).entity(new JsonArrayImpl<>(singletonList("1.0.0"))).build(); - } - - private Response doGetAgent(String artifact, String version) throws IOException { - if (!artifact.endsWith("org.eclipse.che.ws-agent")) { - return Response.status(Response.Status.NOT_FOUND).build(); - } - - String content = format("{ \"name\" : \"%s\", \"version\" : \"%s\"}", artifact, version); - java.nio.file.Path file = Paths.get(System.getProperty("java.io.tmpdir"), "config.tmp"); - file.toFile().deleteOnExit(); - - copy(new ByteArrayInputStream(content.getBytes()), file, StandardCopyOption.REPLACE_EXISTING); - - return Response.ok(file.toFile(), MediaType.APPLICATION_OCTET_STREAM) - .header("Content-Length", String.valueOf(Files.size(file))) - .header("Content-Disposition", "attachment; filename=" + file.getFileName().toString()) - .build(); - } - } -} diff --git a/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentSorterTest.java b/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentSorterTest.java index 04931911f5e1..9f4e3ec8f7c2 100644 --- a/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentSorterTest.java +++ b/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/AgentSorterTest.java @@ -57,12 +57,12 @@ public void setUp() throws Exception { when(agentRegistry.getAgent(eq(AgentKeyImpl.parse("fqn4")))).thenThrow(new AgentNotFoundException("Agent not found")); when(agent1.getDependencies()).thenReturn(singletonList("fqn3")); - when(agent1.getName()).thenReturn("fqn1"); + when(agent1.getId()).thenReturn("fqn1"); when(agent2.getDependencies()).thenReturn(singletonList("fqn3")); - when(agent2.getName()).thenReturn("fqn2"); + when(agent2.getId()).thenReturn("fqn2"); - when(agent3.getName()).thenReturn("fqn3"); + when(agent3.getId()).thenReturn("fqn3"); } @Test @@ -70,9 +70,9 @@ public void sortAgentsRespectingDependencies() throws Exception { List sorted = agentSorter.sort(Arrays.asList("fqn1", "fqn2", "fqn3")); assertEquals(sorted.size(), 3); - assertEquals(sorted.get(0).getName(), "fqn3"); - assertEquals(sorted.get(1).getName(), "fqn1"); - assertEquals(sorted.get(2).getName(), "fqn2"); + assertEquals(sorted.get(0).getId(), "fqn3"); + assertEquals(sorted.get(1).getId(), "fqn1"); + assertEquals(sorted.get(2).getId(), "fqn2"); } @Test(expectedExceptions = AgentException.class, expectedExceptionsMessageRegExp = ".*fqn1.*fqn2.*") diff --git a/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImplTest.java b/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImplTest.java index e4f9347a6ffd..8f79b96732d1 100644 --- a/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImplTest.java +++ b/wsmaster/che-core-api-agent/src/test/java/org/eclipse/che/api/agent/server/impl/LocalAgentRegistryImplTest.java @@ -10,16 +10,17 @@ *******************************************************************************/ package org.eclipse.che.api.agent.server.impl; +import static org.testng.AssertJUnit.assertFalse; + +import java.util.Collection; + +import org.eclipse.che.api.agent.shared.model.Agent; import org.everrest.assured.EverrestJetty; import org.mockito.InjectMocks; import org.mockito.testng.MockitoTestNGListener; import org.testng.annotations.Listeners; import org.testng.annotations.Test; -import java.util.List; - -import static org.testng.AssertJUnit.assertFalse; - /** * @author Anatoliy Bazko */ @@ -31,7 +32,7 @@ public class LocalAgentRegistryImplTest { @Test public void testInitializeAgents() throws Exception { - List agents = agentRegistry.getAgents(); + Collection agents = agentRegistry.getAgents(); assertFalse(agents.isEmpty()); } } diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java index a3c9b1570d77..5f71deb332e4 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/WorkspaceRuntimes.java @@ -642,10 +642,10 @@ private WorkspaceState getRunningState(String workspaceId) throws NotFoundExcept protected void launchAgents(Instance instance, List agents) throws ServerException { try { for (AgentKey agentKey : agentSorter.sort(agents)) { - LOG.info("Launching '{}' agent", agentKey.getName()); + LOG.info("Launching '{}' agent", agentKey.getId()); Agent agent = agentRegistry.getAgent(agentKey); - AgentLauncher launcher = launcherFactory.find(agentKey.getName(), instance.getConfig().getType()); + AgentLauncher launcher = launcherFactory.find(agentKey.getId(), instance.getConfig().getType()); launcher.launch(instance, agent); } } catch (AgentException e) { diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/SshAgentLauncherImpl.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/SshAgentLauncherImpl.java index 9f555d5cbae9..ff2a141898c1 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/SshAgentLauncherImpl.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/SshAgentLauncherImpl.java @@ -40,7 +40,7 @@ public String getMachineType() { } @Override - public String getAgentName() { + public String getAgentId() { return "org.eclipse.che.ssh"; } } diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/TerminalAgentLauncherImpl.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/TerminalAgentLauncherImpl.java index e275427c1274..54eaafedff30 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/TerminalAgentLauncherImpl.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/TerminalAgentLauncherImpl.java @@ -40,7 +40,7 @@ public String getMachineType() { } @Override - public String getAgentName() { + public String getAgentId() { return "org.eclipse.che.terminal"; } } diff --git a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImpl.java b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImpl.java index 2cf3eaba1dcd..968e211f6a7b 100644 --- a/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImpl.java +++ b/wsmaster/che-core-api-workspace/src/main/java/org/eclipse/che/api/workspace/server/launcher/WsAgentLauncherImpl.java @@ -73,7 +73,7 @@ public WsAgentLauncherImpl(Provider machineProcessManager } @Override - public String getAgentName() { + public String getAgentId() { return "org.eclipse.che.ws-agent"; } @@ -98,7 +98,7 @@ public void launch(Instance machine, Agent agent) throws ServerException { // for server side type of command mean nothing // but we will use it as marker on // client side for track this command - CommandImpl command = new CommandImpl(getAgentName(), script, WS_AGENT_PROCESS_NAME); + CommandImpl command = new CommandImpl(getAgentId(), script, WS_AGENT_PROCESS_NAME); machineProcessManagerProvider.get().exec(machine.getWorkspaceId(), machine.getId(),