@VisibleForTesting Optional<RuntimeImpl> getWorkspaceRuntime() { WorkspaceImpl workspace = appContext.getWorkspace(); return Optional.ofNullable(workspace.getRuntime()); } }
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()); }
private List<? extends Machine> getMachines() { final Runtime runtime = appContext.getWorkspace().getRuntime(); if (runtime != null) { return new ArrayList<>(runtime.getMachines().values()); } return emptyList(); } }
private Optional<String> getMachineToken() { WorkspaceImpl currentWorkspace = appContext.getWorkspace(); if (currentWorkspace == null) { return Optional.empty(); } RuntimeImpl runtime = currentWorkspace.getRuntime(); if (runtime == null) { return Optional.empty(); } String machineToken = runtime.getMachineToken(); return Optional.of(machineToken); } }
private Optional<MachineImpl> getMachineByName(String machineName) { final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime == null) { return Optional.empty(); } return runtime.getMachineByName(machineName); } }
@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); }
public WorkspaceImpl(WorkspaceImpl workspace) { this( workspace.getId(), workspace.getNamespace(), workspace.getConfig(), workspace.getRuntime(), workspace.getAttributes(), workspace.isTemporary(), workspace.getStatus(), workspace.getLinks(), workspace.getRuntime() != null ? workspace.getRuntime().getMachineToken() : 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)))); }
private void internalInitialize() { final WorkspaceImpl workspace = appContext.getWorkspace(); final RuntimeImpl runtime = workspace.getRuntime(); if (runtime == null) { return; // workspace is stopped } wsAgentServerUtil .getWsAgentWebSocketServer() .ifPresent( server -> { String wsAgentWebSocketUrl = agentURLModifier.modify(server.getUrl()); String separator = wsAgentWebSocketUrl.contains("?") ? "&" : "?"; Optional<String> applicationWebSocketId = appContext.getApplicationId(); String queryParams = applicationWebSocketId.map(id -> separator + "clientId=" + id).orElse(""); initializer.initialize( WS_AGENT_JSON_RPC_ENDPOINT_ID, singletonMap("url", wsAgentWebSocketUrl + queryParams), emptySet()); }); } }
@Override public void updateInPerspective(@NotNull ActionEvent event) { event.getPresentation().setVisible(true); event.getPresentation().setEnabled(appContext.getWorkspace().getRuntime() != null); }
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())))); }); } }
/** * 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())); } } }); }
/** * Save IDE state synchronously. Note: Consider using {@link * AppStateServiceClient#saveState(String)} instead. * * @param appState IDE state to save */ void saveState(JsonObject appState) { String userId = appContext.getCurrentUser().getId(); String url = appContext.getWsAgentServerApiEndpoint() + UPDATE_STATE + "?userId=" + userId; String machineToken = appContext.getWorkspace().getRuntime().getMachineToken(); sendSyncRequest(url, machineToken, appState.toJson()); }
@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; }
/** 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 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); } } } }
@Override public void onPreviewServers(String machineId) { ProcessTreeNode machineTreeNode = findTreeNodeById(machineId); if (machineTreeNode == null || machineTreeNode.getType() != MACHINE_NODE) { return; } String machineName = (String) machineTreeNode.getData(); RuntimeImpl runtime = appContext.getWorkspace().getRuntime(); if (runtime == null) { return; } Optional<MachineImpl> machine = runtime.getMachineByName(machineName); if (!machine.isPresent()) { return; } List<RuntimeInfo> serverBindings = runtimeInfoProvider.get(machineName); Widget widget = runtimeInfoWidgetFactory.create(machineName, serverBindings); CompositeOutputConsole servers = commandConsoleFactory.create( widget, runtimeInfoLocalization.infoTabTitle(), resources.remote()); addCommandOutput(machineId, servers, true); }
@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; }