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); } }
public Optional<MachineImpl> getMachineByName(String name) { return Optional.ofNullable(getMachines().get(name)); }
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); } }
for (MachineImpl machine : workspace.getRuntime().getMachines().values()) { for (ServerImpl server : machine.getServers().values()) { Optional<MachineImpl> machinePrev = workspacePrev.getRuntime().getMachineByName(machine.getName()); if (machinePrev.isPresent()) { Optional<ServerImpl> serverPrev =
@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; }
new RuntimeImpl( runtime.getActiveEnv(), runtime.getMachines(),
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()); }
/** * 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()); }
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())))); }); } }
@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(); }
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); }
Optional<MachineImpl> runtimeMachine = workspace.getRuntime().getMachineByName(machineName);
/** * 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 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 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; }
Optional<MachineImpl> machine = runtime.getMachineByName(machineName); if (!machine.isPresent()) { return;
@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())); } } }); }