/** * Finds machine in provided environment which contains wsagent server. * * @param environment environment to find a machine with the wsagent server * @return {@link Optional} with name of the machine which contains wsagent server or empty if * such machine is not present in provided environment * @throws IllegalArgumentException if more than 1 machine with the wsagent server are found */ public static Optional<String> getWsAgentServerMachine(InternalEnvironment environment) { List<String> machinesWithWsAgentServer = environment .getMachines() .entrySet() .stream() .filter(entry -> containsWsAgentServer(entry.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toList()); if (machinesWithWsAgentServer.isEmpty()) { return Optional.empty(); } if (machinesWithWsAgentServer.size() == 1) { return Optional.of(machinesWithWsAgentServer.get(0)); } throw new IllegalArgumentException( format( "Environment contains '%s' machines with wsagent server. Machines names: '%s'", machinesWithWsAgentServer.size(), machinesWithWsAgentServer)); }
@Override public void provision(RuntimeIdentity id, InternalEnvironment internalEnvironment) throws InfrastructureException { LOG.debug("Provisioning project volumes for workspace '{}'", id.getWorkspaceId()); Optional<String> wsAgentServerMachine = WsAgentMachineFinderUtil.getWsAgentServerMachine(internalEnvironment); if (wsAgentServerMachine.isPresent()) { InternalMachineConfig machineConfig = internalEnvironment.getMachines().get(wsAgentServerMachine.get()); machineConfig .getVolumes() .put(PROJECTS_VOLUME_NAME, new VolumeImpl().withPath(projectFolderPath)); } } }
/** * Return server URL related with defined port * * @deprecated use {@link #getServerFromDevMachineBySymbolicName(String, String)} to retrieve * server URL from instead */ @Override @Deprecated @Nullable public String getServerAddressByPort(String workspaceId, int port) throws Exception { Workspace workspace = getById(workspaceId); ensureRunningStatus(workspace); Map<String, ? extends Machine> machines = workspace.getRuntime().getMachines(); for (Machine machine : machines.values()) { if (containsWsAgentServer(machine)) { return machine.getServers().get(valueOf(port) + "/tcp").getUrl(); } } return null; }
/** * Return ServerDto object from runtime by it's symbolic name * * @param workspaceId workspace id of current user * @param serverName server name * @return ServerDto object */ @Override @Nullable public Server getServerFromDevMachineBySymbolicName(String workspaceId, String serverName) throws Exception { Workspace workspace = requestFactory.fromUrl(getIdBasedUrl(workspaceId)).request().asDto(WorkspaceDto.class); ensureRunningStatus(workspace); Map<String, ? extends Machine> machines = workspace.getRuntime().getMachines(); for (Machine machine : machines.values()) { if (containsWsAgentServer(machine)) { return machine.getServers().get(serverName); } } return null; }