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); }
/** Sets the current workspace. */ public void setWorkspace(WorkspaceImpl workspace) { this.workspace = new WorkspaceImpl(workspace); }
/** * Returns the ssh service address in format - host:port (example - localhost:32899) * * @param machine machine to retrieve address * @return ssh service address in format host:port */ private String getSshServerAddress(MachineImpl machine) { Optional<ServerImpl> server = machine.getServerByName(SERVER_SSH_REFERENCE); if (server.isPresent()) { return server.get().getUrl(); } return null; }
@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; }
private void addMachines() { String defaultEnvironmentName = appContext.getWorkspace().getConfig().getDefaultEnv(); EnvironmentImpl defaultEnvironment = appContext.getWorkspace().getConfig().getEnvironments().get(defaultEnvironmentName); if (defaultEnvironment == null) { return; } Map<String, MachineConfigImpl> machines = defaultEnvironment.getMachines(); for (final String machineName : machines.keySet()) { MachineConfigImpl machineConfig = machines.get(machineName); view.addMachine(machineName); } }
@Override public int hashCode() { return Objects.hash(getName(), getAttributes(), getServers(), getStatus()); }
@Override public int hashCode() { int hash = 7; hash = 31 * hash + getInstallers().hashCode(); hash = 31 * hash + getEnv().hashCode(); hash = 31 * hash + getAttributes().hashCode(); hash = 31 * hash + getServers().hashCode(); hash = 31 * hash + getVolumes().hashCode(); return hash; }
/** 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 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; }
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 String getWorkspaceId() { if (workspace == null) { throw new IllegalArgumentException(getClass() + " Workspace can not be null."); } return workspace.getId(); }
@Override public void onWorkspaceRunning(WorkspaceRunningEvent event) { List<MachineImpl> machines = getMachines(); for (MachineImpl machine : machines) { provideMachineNode(machine.getName(), true, false); } }
private void showInstallers() { String defaultEnvironmentName = appContext.getWorkspace().getConfig().getDefaultEnv(); EnvironmentImpl defaultEnvironment = appContext.getWorkspace().getConfig().getEnvironments().get(defaultEnvironmentName); if (defaultEnvironment == null) { return; } Map<String, MachineConfigImpl> machines = defaultEnvironment.getMachines(); for (final String machineName : machines.keySet()) { MachineConfigImpl machineConfig = machines.get(machineName); for (String installerId : machineConfig.getInstallers()) { String installerName = installernames.get(installerId); if (installerName == null) { installerName = ""; } String installerDescription = installerDescriptions.get(installerId); if (installerDescription == null) { installerDescription = ""; } view.addInstaller(machineName, installerId, installerName, installerDescription); } } }
@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(); }
private CommandImpl getWorkspaceCommandByName(String name) { for (Command command : appContext.getWorkspace().getConfig().getCommands()) { if (command.getName().equals(name)) { return new CommandImpl(command); // wrap model interface into implementation, workaround } } return null; }
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()); }