private void registerMacros() { final Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine(); if (devMachine.isPresent()) { macros.clear(); for (Map.Entry<String, ? extends Server> entry : devMachine.get().getServers().entrySet()) { macros.add(new ServerAddressMacro(entry.getKey(), entry.getValue().getUrl())); } macroRegistryProvider.get().register(macros); } }
public ServerImpl(String name, Server server) { this.name = name; this.url = nullToEmpty(server.getUrl()); // some servers doesn't have URL this.status = server.getStatus(); if (server.getAttributes() != null) { this.attributes = new HashMap<>(server.getAttributes()); } else { this.attributes = new HashMap<>(); } }
private String getDisplayNameForPreviewUrl(String previewUrl) { final Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine(); if (!devMachine.isPresent()) { return previewUrl; } for (Entry<String, ? extends Server> entry : devMachine.get().getServers().entrySet()) { Server server = entry.getValue(); String serverUrl = server.getUrl(); if (serverUrl == null) { continue; } if (previewUrl.startsWith(serverUrl)) { String port = entry.getKey(); // server's port may be in form of '8080/tcp' so need to cut protocol name final int slashIndex = port.lastIndexOf('/'); if (slashIndex > -1) { port = port.substring(0, slashIndex); } return previewUrl.replace(serverUrl, devMachine.get().getName() + ':' + port); } } return previewUrl; }
public ServerImpl(Server server) { this.url = server.getUrl(); this.status = server.getStatus(); if (server.getAttributes() != null) { this.attributes = new HashMap<>(server.getAttributes()); } else { this.attributes = new HashMap<>(); } }
@Override public HttpProbeConfig get(String userId, String workspaceId, Server server) throws InternalInfrastructureException { try { URL url = new URL(server.getUrl()); return new HttpProbeConfig( url.getPort() == -1 ? url.getDefaultPort() : url.getPort(), url.getHost(), url.getProtocol(), url.getPath().replaceFirst("/process$", "/liveness"), null, successThreshold, 3, 120, 10, 10); } catch (MalformedURLException e) { throw new InternalInfrastructureException( "Exec agent server liveness probe url is invalid. Error: " + e.getMessage()); } } }
URI uri; try { uri = new URI(server.getUrl()); } catch (URISyntaxException e) { throw new InternalInfrastructureException(
private ServerChecker getChecker(String serverRef, Server server) throws InfrastructureException { // TODO replace with correct behaviour // workaround needed because we don't have server readiness check in the model // Create server readiness endpoint URL URL url; String token; try { String serverUrl = server.getUrl(); if ("terminal".equals(serverRef)) { serverUrl = serverUrl.replaceFirst("^ws", "http").replaceFirst("/pty$", "/"); } if ("wsagent/http".equals(serverRef) && !serverUrl.endsWith("/")) { // add trailing slash if it is not present serverUrl = serverUrl + '/'; } token = machineTokenProvider.getToken( runtimeIdentity.getOwnerId(), runtimeIdentity.getWorkspaceId()); url = UriBuilder.fromUri(serverUrl).build().toURL(); } catch (MalformedURLException e) { throw new InternalInfrastructureException( "Server " + serverRef + " URL is invalid. Error: " + e.getMessage(), e); } return doCreateChecker(url, serverRef, token); }
String serverUrl = server.getUrl(); Map<String, String> attributes = server.getAttributes();
new ServerImpl(incomingServer) .withUrl( urlRewriter.rewriteURL(identity, machineName, name, incomingServer.getUrl())); outgoing.put(name, server); } catch (InfrastructureException e) {
/** * 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; }
URI uri = UriBuilder.fromUri(server.getUrl()).path("/liveness").build();
/** Converts {@link Server} to {@link ServerDto}. */ public static ServerDto asDto(Server server) { return newDto(ServerDto.class) .withUrl(server.getUrl()) .withStatus(server.getStatus()) .withAttributes(server.getAttributes()); }