/** * Get {@link WorkspaceProbes} for a whole workspace runtime * * @throws InfrastructureException when the operation fails */ public WorkspaceProbes getProbes(RuntimeIdentity runtimeId, Runtime runtime) throws InfrastructureException { return getProbes(runtimeId, runtime.getMachines()); }
private List<? extends Machine> getMachines() { final Runtime runtime = appContext.getWorkspace().getRuntime(); if (runtime != null) { return new ArrayList<>(runtime.getMachines().values()); } return emptyList(); } }
public RuntimeImpl(Runtime runtime) { this.activeEnv = runtime.getActiveEnv(); this.machines = runtime .getMachines() .entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> new MachineImpl(e.getValue()))); this.owner = runtime.getOwner(); this.warnings = runtime.getWarnings().stream().map(WarningImpl::new).collect(Collectors.toList()); this.commands = runtime.getCommands().stream().map(CommandImpl::new).collect(Collectors.toList()); }
/** * Calculates summary RAM of given {@link Runtime}. * * @return summary RAM of all machines in runtime in megabytes */ public long calculate(Runtime runtime) { return runtime .getMachines() .values() .stream() .mapToLong( m -> parseMemoryAttributeValue(m.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE))) .sum() / BYTES_TO_MEGABYTES_DIVIDER; }
private boolean isSshServerIsRunning(String machineName) { Workspace workspace = appContext.getWorkspace(); Runtime runtime = workspace.getRuntime(); if (runtime == null) { return false; } Machine machine = runtime.getMachines().get(machineName); if (machine == null) { return false; } Server server = machine.getServers().get(SERVER_SSH_REFERENCE); if (server == null) { return false; } return workspace.getStatus() == WorkspaceStatus.RUNNING; }
/** Converts {@link Runtime} to {@link RuntimeDto}. */ public static RuntimeDto asDto(Runtime runtime) { if (runtime == null) { return null; } RuntimeDto runtimeDto = newDto(RuntimeDto.class).withActiveEnv(runtime.getActiveEnv()); if (runtime.getMachines() != null) { runtimeDto.setMachines( runtime .getMachines() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue())))); } if (runtime.getWarnings() != null) { runtimeDto.setWarnings( runtime.getWarnings().stream().map(DtoConverter::asDto).collect(Collectors.toList())); } if (runtime.getCommands() != null) { runtimeDto.setCommands( runtime.getCommands().stream().map(DtoConverter::asDto).collect(toList())); } return runtimeDto; }
/** Checks whether the server is running in the machine. */ private boolean isServerRunning(String machineName, String serverName) { Workspace workspace = appContext.getWorkspace(); Runtime runtime = workspace.getRuntime(); if (runtime == null) { return false; } Machine machine = runtime.getMachines().get(machineName); if (machine == null) { return false; } Server server = machine.getServers().get(serverName); if (server == null) { return false; } return server.getStatus() == ServerStatus.RUNNING; }
workspaceRuntime.getMachines().entrySet()) { Map<String, ? extends Server> servers = machineEntry.getValue().getServers();
/** * Return server URL related with defined port * * @deprecated use {@link #getServerFromDevMachineBySymbolicName(String, String)} to retrieve * server URL from instead */ @Override @Deprecated @Nullable public String getServerAddressByPort(String workspaceId, int port) throws Exception { Workspace workspace = getById(workspaceId); ensureRunningStatus(workspace); Map<String, ? extends Machine> machines = workspace.getRuntime().getMachines(); for (Machine machine : machines.values()) { if (containsWsAgentServer(machine)) { return machine.getServers().get(valueOf(port) + "/tcp").getUrl(); } } return null; }
/** * Return ServerDto object from runtime by it's symbolic name * * @param workspaceId workspace id of current user * @param serverName server name * @return ServerDto object */ @Override @Nullable public Server getServerFromDevMachineBySymbolicName(String workspaceId, String serverName) throws Exception { Workspace workspace = requestFactory.fromUrl(getIdBasedUrl(workspaceId)).request().asDto(WorkspaceDto.class); ensureRunningStatus(workspace); Map<String, ? extends Machine> machines = workspace.getRuntime().getMachines(); for (Machine machine : machines.values()) { if (containsWsAgentServer(machine)) { return machine.getServers().get(serverName); } } return null; }
public WorkspaceImpl( String id, Account account, WorkspaceConfig config, Runtime runtime, Map<String, String> attributes, boolean isTemporary, WorkspaceStatus status) { this.id = id; if (account != null) { this.account = new AccountImpl(account); } if (config != null) { this.config = new WorkspaceConfigImpl(config); } if (runtime != null) { this.runtime = new RuntimeImpl( runtime.getActiveEnv(), runtime.getMachines(), runtime.getOwner(), runtime.getCommands(), runtime.getWarnings()); } if (attributes != null) { this.attributes = new HashMap<>(attributes); } this.isTemporary = isTemporary; this.status = status; }
new RuntimeImpl( runtime.getActiveEnv(), runtime.getMachines(), runtime.getOwner(), machineToken,