public Optional<MachineImpl> getMachineByName(String name) { return Optional.ofNullable(getMachines().get(name)); }
private List<MachineImpl> getMachines() { final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime == null) { return emptyList(); } return new ArrayList<>(runtime.getMachines().values()); }
@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 {@code Optional} with a machine which contains the "wsagent" server. * * @return {@code Optional} with the machine which contains the "wsagent" server if the current * workspace has a runtime and there is such machine, otherwise an empty {@code Optional} */ public Optional<MachineImpl> getWsAgentServerMachine() { return getWorkspaceRuntime() .flatMap( runtime -> runtime .getMachines() .values() .stream() .filter(this::containsWsAgentHttpServer) .findAny()); }
@Override public boolean isGroup(MenuItem item) { if (item instanceof CommandItem) { final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime != null) { return runtime.getMachines().size() > 1; } } return false; }
@Override public Pair<List<MenuItem>, String> getChildren(MenuItem parent) { List<MenuItem> items = new ArrayList<>(); if (parent instanceof CommandItem) { final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime != null) { final CommandImpl command = ((CommandItem) parent).getCommand(); final Map<String, ? extends MachineImpl> machines = runtime.getMachines(); items.addAll( machines .values() .stream() .map(machine -> menuItemsFactory.newMachineItem(command, machine)) .collect(toList())); } } return Pair.of(items, null); }
/** Updates view with the preview URLs of running processes. */ private void updateView() { view.removeAllURLs(); final RuntimeImpl runtime = appContext.getWorkspace().getRuntime(); if (runtime == null) { return; } runtime .getMachines() .keySet() .stream() .map(machineName -> execAgentClient.getProcesses(machineName, false)) .forEach( promise -> promise.onSuccess( processes -> processes .stream() .map(GetProcessesResponseDto::getName) .map(this::getPreviewUrlByName) .forEach(it -> it.then(view::addUrl)))); }
/** * Pops up a dialog for choosing a machine. * * <p><b>Note:</b> if there is only one machine running in the workspace then returned promise * will be resolved with that machine without asking user. * * @return promise that will be resolved with a chosen {@link MachineImpl} or rejected in case * machine selection has been cancelled. */ public Promise<MachineImpl> show() { final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime != null) { final List<? extends MachineImpl> machines = new ArrayList<>(runtime.getMachines().values()); if (machines.size() == 1) { return promiseProvider.resolve(machines.get(0)); } view.setMachines(machines); } view.show(); return promiseProvider.create( Executor.create( (ExecutorBody<MachineImpl>) (resolve, reject) -> { resolveFunction = resolve; rejectFunction = reject; })); }
@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())); } } }); }
.getMachines() .values() .stream()
@Override public void showPanel() { showWorkspaceStatusPanel(); addMachines(); showInstallers(); if (WorkspaceStatus.RUNNING == appContext.getWorkspace().getStatus()) { view.showWorkspaceStarted(); Map<String, MachineImpl> runtimeMachines = appContext.getWorkspace().getRuntime().getMachines(); for (String machineName : runtimeMachines.keySet()) { view.setMachineRunning(machineName); } String defaultEnvironmentName = appContext.getWorkspace().getConfig().getDefaultEnv(); EnvironmentImpl defaultEnvironment = appContext.getWorkspace().getConfig().getEnvironments().get(defaultEnvironmentName); if (defaultEnvironment == null) { return; } Map<String, MachineConfigImpl> environmentMachines = defaultEnvironment.getMachines(); for (final String machineName : environmentMachines.keySet()) { MachineConfigImpl machineConfig = environmentMachines.get(machineName); for (String installerId : machineConfig.getInstallers()) { view.setInstallerRunning(machineName, installerId); } } } }
for (MachineImpl machine : workspace.getRuntime().getMachines().values()) { for (ServerImpl server : machine.getServers().values()) { Optional<MachineImpl> machinePrev =
/** Updates view with all running processes. */ private void updateView() { view.clearList(); runningProcesses.clear(); final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime == null) { return; } for (MachineImpl machine : runtime.getMachines().values()) { execAgentClient .getProcesses(machine.getName(), false) .onSuccess( processes -> { for (GetProcessesResponseDto p : processes) { final Process process = new ProcessImpl( p.getName(), p.getCommandLine(), p.getPid(), p.isAlive(), machine.getName()); runningProcesses.put(process.getPid(), process); view.addProcess(process); } }); } }
@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; }