@Override public int hashCode() { return Objects.hash(getName(), getAttributes(), getServers(), getStatus()); }
public RuntimeImpl( String activeEnv, Map<String, ? extends Machine> machines, String owner, String machineToken, List<? extends Command> commands, List<? extends Warning> warnings) { this.activeEnv = activeEnv; if (machines != null) { this.machines = machines .entrySet() .stream() .collect( toMap( Map.Entry::getKey, entry -> new MachineImpl(entry.getKey(), entry.getValue()))); } this.owner = owner; this.machineToken = machineToken; if (commands != null) { this.commands = commands.stream().map(CommandImpl::new).collect(toCollection(ArrayList::new)); } if (warnings != null) { this.warnings = warnings.stream().map(WarningImpl::new).collect(toList()); } }
/** * Returns the ssh service address in format - host:port (example - localhost:32899) * * @param machine machine to retrieve address * @return ssh service address in format host:port */ private String getSshServerAddress(MachineImpl machine) { Optional<ServerImpl> server = machine.getServerByName(SERVER_SSH_REFERENCE); if (server.isPresent()) { return server.get().getUrl(); } return null; }
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; }
@Override public void onCommandExecute(CommandImpl command, MachineImpl machine) { commandExecutorProvider.get().executeCommand(command, machine.getName()); }
for (ServerImpl server : machine.getServers().values()) { Optional<MachineImpl> machinePrev = workspacePrev.getRuntime().getMachineByName(machine.getName()); if (machinePrev.isPresent()) { Optional<ServerImpl> serverPrev = machinePrev.get().getServerByName(server.getName()); if (serverPrev.isPresent()) { if (server.getStatus() != serverPrev.get().getStatus()) {
@Override protected ActionGroup updateActions() { final DefaultActionGroup actionGroup = new DefaultActionGroup(actionManager); Map<String, MachineImpl> machines = appContext.getWorkspace().getRuntime().getMachines(); for (MachineImpl machine : machines.values()) { Separator separ = new Separator(machine.getName() + ":"); actionGroup.add(separ); if (machine.getServerByName(SERVER_TERMINAL_REFERENCE).isPresent()) { NewTerminalMenuAction newTerminalMenuAction = new NewTerminalMenuAction( coreLocalizationConstant, machineResources, machine.getName()); actionGroup.add(newTerminalMenuAction); } if (machine.getServerByName(SERVER_SSH_REFERENCE).isPresent()) { AddSSHMenuAction addSSHMenuAction = new AddSSHMenuAction(machine.getName()); actionGroup.add(addSSHMenuAction); } ShowServersAction showServersAction = new ShowServersAction(machine.getName()); actionGroup.add(showServersAction); ShowMachineOutputAction showMachineOutputAction = new ShowMachineOutputAction(machine.getName()); actionGroup.add(showMachineOutputAction); } return actionGroup; }
public Optional<ServerImpl> getServerByName(String name) { return Optional.ofNullable(getServers().get(name)); }
@NotNull @Override public Promise<String> expand() { String value = ""; Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine(); if (devMachine.isPresent()) { String hostName = devMachine.get().getAttributes().get("config.hostname"); if (hostName != null) { value = hostName; } } return Promises.resolve(value); } }
@AssistedInject public MachineItem(@Assisted CommandImpl command, @Assisted MachineImpl machine) { super(command); this.machine = machine; this.name = machine.getName(); }
private void internalInitialize(String machineName) { final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime == null) { return; // workspace is stopped } runtime .getMachineByName(machineName) .ifPresent( machine -> { Optional<ServerImpl> execAgentServer = machine.getServerByName(SERVER_EXEC_AGENT_WEBSOCKET_REFERENCE); execAgentServer.ifPresent( server -> initializer.initialize( machine.getName(), singletonMap("url", agentURLModifier.modify(server.getUrl())))); }); } }
/** * Checks whether the provided {@link MachineImpl} contains the {@link * Constants#SERVER_WS_AGENT_HTTP_REFERENCE wsagent/http} server. * * @param machine {@link MachineImpl} to check * @return {@code true} if the given machine contains the {@link * Constants#SERVER_WS_AGENT_HTTP_REFERENCE wsagent/http} server server, otherwise {@code * false} */ public boolean containsWsAgentHttpServer(MachineImpl machine) { return machine.getServers().keySet().contains(getWsAgentHttpServerReference()); }
String user = machine.get().getAttributes().get("config.user"); if (isNullOrEmpty(user)) { userName = "root";
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof MachineImpl)) { return false; } MachineImpl machine = (MachineImpl) o; return Objects.equals(getName(), machine.getName()) && Objects.equals(getAttributes(), machine.getAttributes()) && Objects.equals(getServers(), machine.getServers()) && getStatus() == machine.getStatus(); }
@Override public void setMachines(List<? extends MachineImpl> machines) { machinesList.clear(); machinesById.clear(); machines.forEach( machine -> { machinesById.put(machine.getName(), machine); machinesList.addItem(machine.getName()); }); machinesList.setVisibleItemCount(machines.size()); machinesList.setSelectedIndex(0); }
ServerImpl terminalServer = machine .getServerByName(SERVER_TERMINAL_REFERENCE) .orElseThrow( () -> new OperationException( "Machine " + machine.getName() + " doesn't provide terminal server.")); connectToTerminal(agentURLModifier.modify(terminalServer.getUrl()), options);
@VisibleForTesting Optional<ServerImpl> getServerByRef(String ref) { Optional<RuntimeImpl> runtimeOpt = getWorkspaceRuntime(); if (runtimeOpt.isPresent()) { for (MachineImpl machine : runtimeOpt.get().getMachines().values()) { ServerImpl server = machine.getServers().get(ref); if (server != null) { return Optional.of(server); } } } return Optional.empty(); }
/** * Returns a top-level URL of the GWT Code Server which is declared in the machine that contains * the "wsagent" server. * * @return {@code Optional} with a top-level URL of the GWT Code Server or an empty {@code * Optional} if none */ private Optional<String> getInternalCodeServerURL() { Optional<MachineImpl> wsAgentServerMachineOpt = wsAgentServerUtil.getWsAgentServerMachine(); if (wsAgentServerMachineOpt.isPresent()) { MachineImpl wsAgentServerMachine = wsAgentServerMachineOpt.get(); Optional<ServerImpl> codeServerOpt = wsAgentServerMachine.getServerByName(INT_CODE_SERVER_REF); if (codeServerOpt.isPresent()) { ServerImpl codeServer = codeServerOpt.get(); String codeServerUrl = codeServer.getUrl(); if (!isNullOrEmpty(codeServerUrl)) { return codeServerUrl.endsWith("/") ? Optional.of(codeServerUrl) : Optional.of(codeServerUrl + '/'); } } } return Optional.empty(); }
@Nullable private MachineImpl getMachine(String machineId) { List<MachineImpl> wsMachines = getMachines(); for (MachineImpl machine : wsMachines) { if (machineId.equals(machine.getName())) { return machine; } } return machines.get(machineId); }
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); } }