@Override public void onCommandExecute(CommandImpl command, MachineImpl machine) { commandExecutorProvider.get().executeCommand(command, machine.getName()); }
@AssistedInject public MachineItem(@Assisted CommandImpl command, @Assisted MachineImpl machine) { super(command); this.machine = machine; this.name = machine.getName(); }
@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); }
@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); }
/** * 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)); }
@Override public void onWorkspaceRunning(WorkspaceRunningEvent event) { List<MachineImpl> machines = getMachines(); for (MachineImpl machine : machines) { provideMachineNode(machine.getName(), true, false); } }
@Override public void onMachineStarting(MachineStartingEvent event) { provideMachineNode(event.getMachine().getName(), false, false); }
@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 int hashCode() { return Objects.hash(getName(), getAttributes(), getServers(), getStatus()); }
@Override public void executeCommand(CommandImpl command) { final MachineImpl selectedMachine = getSelectedMachine(); if (selectedMachine != null) { executeCommand(command, selectedMachine.getName()); } else { machineChooser .show() .then( machine -> { executeCommand(command, machine.getName()); }); } }
/** 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; } } } }
@AssistedInject public MachineItem(@Assisted MachineItem item) { super(item.getCommand()); this.machine = item.machine; this.name = getCommand().getName() + " on " + machine.getName(); }
@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); } }
private void checkServerStatus(ServerImpl server, MachineImpl machine) { if (server.getStatus() == RUNNING) { eventBus.fireEvent(new ServerRunningEvent(server.getName(), machine.getName())); String wsAgentHttpServerRef = wsAgentServerUtil.getWsAgentHttpServerReference(); // fire events for the often used servers if (wsAgentHttpServerRef.equals(server.getName())) { eventBus.fireEvent(new WsAgentServerRunningEvent(machine.getName())); } else if (SERVER_TERMINAL_REFERENCE.equals(server.getName())) { eventBus.fireEvent(new TerminalAgentServerRunningEvent(machine.getName())); } else if (SERVER_EXEC_AGENT_HTTP_REFERENCE.equals(server.getName())) { eventBus.fireEvent(new ExecAgentServerRunningEvent(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())))); }); } }
@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())); }
@Inject public ProcessesOutputRestorer( EventBus eventBus, AppContext appContext, ExecAgentCommandManager execAgentCommandManager) { this.eventBus = eventBus; this.execAgentCommandManager = execAgentCommandManager; eventBus.addHandler( ExecAgentServerRunningEvent.TYPE, event -> restoreLogs(event.getMachineName())); // in case workspace is already running eventBus.addHandler( BasicIDEInitializedEvent.TYPE, event -> { final WorkspaceImpl workspace = appContext.getWorkspace(); if (workspace.getStatus() == RUNNING) { final RuntimeImpl runtime = workspace.getRuntime(); if (runtime != null) { runtime.getMachines().values().forEach(m -> restoreLogs(m.getName())); } } }); }
@Override public void onCommandExecute(CommandImpl command) { view.close(); if (getMachines().isEmpty()) { // should not happen, but let's play safe dialogFactory.createMessageDialog("", messages.messageNoMachine(), null).show(); } else { machineChooser .show() .then( machine -> { commandExecutor.executeCommand(command, machine.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; }