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); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof WorkspaceImpl)) return false; final WorkspaceImpl other = (WorkspaceImpl) obj; return Objects.equals(id, other.id) && Objects.equals(getNamespace(), other.getNamespace()) && Objects.equals(config, other.config) && getAttributes().equals(other.getAttributes()) && isTemporary == other.isTemporary && Objects.equals(status, other.status) && Objects.equals(runtime, other.runtime); }
@Override public void onCommandsLoaded(CommandsLoadedEvent event) { if (appContext.getWorkspace().getStatus() == RUNNING) { getMachines().stream().map(MachineImpl::getName).forEach(this::restoreProcessesState); } }
@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; }
@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())); } } }); }
if (workspace.getStatus() != workspacePrev.getStatus()) { if (workspace.getStatus() == WorkspaceStatus.STOPPED) { String cause = workspace.getAttributes().get(ERROR_MESSAGE_ATTRIBUTE_NAME); eventBus.fireEvent( new WorkspaceStoppedEvent(true, firstNonNull(cause, "Reason is unknown."))); return; } else if (workspace.getStatus() == WorkspaceStatus.RUNNING) { eventBus.fireEvent(new WorkspaceRunningEvent()); 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 =
@VisibleForTesting Optional<RuntimeImpl> getWorkspaceRuntime() { WorkspaceImpl workspace = appContext.getWorkspace(); return Optional.ofNullable(workspace.getRuntime()); } }
/** Returns commands which are stored in the current workspace. */ List<CommandImpl> getCommands() { final WorkspaceImpl workspace = appContext.getWorkspace(); final WorkspaceConfigImpl workspaceConfig = workspace.getConfig(); return workspaceConfig.getCommands(); }
@Override public void onDownloadOutput(OutputConsole console) { String id = consoleCommands.get(console); String fileName = appContext.getWorkspace().getNamespace() + "-" + appContext.getWorkspace().getConfig().getName() + " " + DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + ".log"; download(fileName, getText(id)); }
if (workspace.getConfig().getDefaultEnv() == null) { return emptyList(); .getConfig() .getEnvironments() .get(workspace.getConfig().getDefaultEnv()) .getMachines() .get(machineName); Optional<MachineImpl> runtimeMachine = workspace.getRuntime().getMachineByName(machineName);
/** Start the current workspace with a default environment. */ Promise<Void> startWorkspace() { WorkspaceImpl workspace = appContext.getWorkspace(); String defEnvName = workspace.getConfig().getDefaultEnv(); return workspaceServiceClient .startById(workspace.getId(), defEnvName) .then( ws -> { ((AppContextImpl) appContext).setWorkspace(ws); eventBus.fireEvent(new WorkspaceStartingEvent()); }) .then((Function<WorkspaceImpl, Void>) arg -> null) .catchError( error -> { dialogFactory .createMessageDialog(messages.startWsErrorTitle(), error.getMessage(), null) .show(); wsStatusNotification.setError(STARTING_WORKSPACE_RUNTIME); startWorkspaceNotification.show(); }); }
@Override public String getWorkspaceId() { if (workspace == null) { throw new IllegalArgumentException(getClass() + " Workspace can not be null."); } return workspace.getId(); }
/** {@inheritDoc} */ @Override public Promise<String> expand() { return promises.resolve(appContext.getWorkspace().getNamespace()); } }
protected void render() { if (appContext.getProjects() != null && appContext.getProjects().length == 0) { renderNoProjects(); return; } if (appContext.getWorkspace().getAttributes().containsKey("factoryId")) { renderFactoryActions(); return; } renderNoFiles(); }
/** Does an appropriate action depending on the current workspace's status. */ private void handleWorkspaceStatus() { WorkspaceImpl workspace = appContext.getWorkspace(); if (workspace.getStatus() == STOPPED) { workspaceServiceClient .getSettings() .then( settings -> { if (parseBoolean(settings.getOrDefault(CHE_WORKSPACE_AUTO_START, "true"))) { startWorkspace(); } }); } } }
@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); } } } }
final WorkspaceImpl workspace = appContext.getWorkspace(); if (workspace.getStatus() == RUNNING) { final RuntimeImpl runtime = 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()); }