@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); } }
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); } }
/** * Adds command node to process tree and displays command output * * @param outputConsole the console for command output */ public void addCommandOutput(OutputConsole outputConsole) { Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine(); devMachine.ifPresent(machine -> addCommandOutput(machine.getName(), outputConsole, true)); }
/** * 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(); }
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; }
/** Selects dev machine. */ private void selectDevMachine() { Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine(); if (!devMachine.isPresent()) { return; } for (ProcessTreeNode processTreeNode : machineNodes.values()) { if (processTreeNode.getType() == MACHINE_NODE) { String machineName = (String) processTreeNode.getData(); if (machineName.equals(devMachine.get().getName())) { view.selectNode(processTreeNode); notifyTreeNodeSelected(processTreeNode); return; } } } }
@Override public void onTerminalAgentServerRunning(TerminalAgentServerRunningEvent event) { // open terminal automatically for dev-machine only Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine(); if (devMachine.isPresent() && event.getMachineName().equals(devMachine.get().getName())) { provideMachineNode(event.getMachineName(), true, false); TerminalOptionsJso options = TerminalOptionsJso.create(); newTerminal(options, false, false); } }
/** Updates list of the machines from application context. */ public void updateMachineList() { if (appContext.getWorkspace() == null) { return; } List<MachineImpl> machines = getMachines(); if (machines.isEmpty()) { return; } Optional<MachineImpl> wsAgentServerMachine = wsAgentServerUtil.getWsAgentServerMachine(); wsAgentServerMachine.ifPresent( machine -> { provideMachineNode(machine.getName(), true, false); machines.remove(machine); }); for (MachineImpl machine : machines) { provideMachineNode(machine.getName(), true, false); } if (WorkspaceStatus.RUNNING == appContext.getWorkspace().getStatus()) { ProcessTreeNode machineToSelect = machineNodes.entrySet().iterator().next().getValue(); view.selectNode(machineToSelect); notifyTreeNodeSelected(machineToSelect); } }
@Override public void actionPerformed(ActionEvent event) { if (event.getParameters() == null) { Log.error(getClass(), localizationConstant.runCommandEmptyParamsMessage()); return; } final String name = event.getParameters().get(NAME_PARAM_ID); if (name == null) { Log.error(getClass(), localizationConstant.runCommandEmptyNameMessage()); return; } wsAgentServerUtil .getWsAgentServerMachine() .ifPresent( m -> commandManager .getCommand(name) .ifPresent(command -> commandExecutor.executeCommand(command, m.getName()))); } }
@Override public void onDownloadWorkspaceOutput(DownloadWorkspaceOutputEvent event) { Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine(); if (!devMachine.isPresent()) { return; } WorkspaceImpl workspace = appContext.getWorkspace(); String fileName = workspace.getNamespace() + "-" + workspace.getConfig().getName() + " " + DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + ".log"; download(fileName, getText(devMachine.get().getName())); }
@Override public Path getProjectsRoot() { // default root (backward compatible solution) Path projectsRoot = Path.valueOf("/projects"); if (workspace != null && workspace.getStatus().equals(WorkspaceStatus.RUNNING)) { String machineName = wsAgentServerUtilProvider.get().getWsAgentServerMachine().get().getName(); String activeEnv = workspace.getRuntime().getActiveEnv(); EnvironmentImpl environment = workspace.getConfig().getEnvironments().get(activeEnv); VolumeImpl vol = null; if (environment != null) { vol = environment.getMachines().get(machineName).getVolume("projects"); } // if voulme exists return its path, otherwise use backward compatible path (/projects) if (vol != null) { projectsRoot = Path.valueOf(vol.getPath()); } } Log.debug( AppContextImpl.class, "Project Root: " + projectsRoot + " workspace: " + workspace.getConfig().getName()); return projectsRoot; }
/** Opens new terminal for the selected machine and activates terminal tab. */ public void newTerminal(TerminalOptionsJso options, boolean activate, boolean focusOnOpen) { final ProcessTreeNode selectedTreeNode = view.getSelectedTreeNode(); final Optional<MachineImpl> devMachine = wsAgentServerUtil.getWsAgentServerMachine(); if (selectedTreeNode == null && devMachine.isPresent()) { onAddTerminal(devMachine.get().getName(), options, activate, focusOnOpen); return; } if (selectedTreeNode == null) { String notificationTitle = localizationConstant.failedToConnectTheTerminal(); String notificationContent = localizationConstant.machineNotFound(""); notificationManager.notify(notificationTitle, notificationContent, FAIL, FLOAT_MODE); return; } if (selectedTreeNode.getType() == MACHINE_NODE) { String machineName = (String) selectedTreeNode.getData(); onAddTerminal(machineName, options, activate, focusOnOpen); return; } ProcessTreeNode parent = selectedTreeNode.getParent(); if (parent != null && parent.getType() == MACHINE_NODE) { String machineName = (String) parent.getData(); onAddTerminal(machineName, options, activate, focusOnOpen); } }