/** * Ensure workspace has running status, or throw IllegalStateException. * * @param workspace workspace description to get status and id. * @throws IllegalStateException if workspace with certain workspaceId doesn't have RUNNING * status. */ @Override public void ensureRunningStatus(Workspace workspace) throws IllegalStateException { if (workspace.getStatus() != WorkspaceStatus.RUNNING) { throw new IllegalStateException( format( "Workspace with id='%s' should has '%s' status, but its actual state='%s'", workspace.getId(), WorkspaceStatus.RUNNING, workspace.getStatus())); } }
public void waitStatus( String workspaceName, String userName, WorkspaceStatus expectedStatus, int timeoutSeconds) throws Exception { WaitUtils.waitSuccessCondition( () -> { try { if (getByName(workspaceName, userName).getStatus() == expectedStatus) { return true; } } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } return false; }, timeoutSeconds, 1000, TimeUnit.SECONDS); }
/** Waits workspace is started. */ @Override public void waitWorkspaceStart(String workspaceName, String userName) throws Exception { WaitUtils.sleepQuietly(5); // delay 5 secs to obtain starting status for sure WaitUtils.waitSuccessCondition( () -> { WorkspaceStatus status; try { status = getByName(workspaceName, userName).getStatus(); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } switch (status) { case RUNNING: return true; case STARTING: return false; default: throw new RuntimeException( format("Workspace with name '%s' didn't start", workspaceName)); } }, 600, 1000, TimeUnit.SECONDS); }
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; }
/** {@inheritDoc} */ @Override public final void update(@NotNull ActionEvent event) { Presentation presentation = event.getPresentation(); boolean isWorkspaceRunning = false; if (appContext.get() != null) { Workspace workspace = appContext.get().getWorkspace(); isWorkspaceRunning = workspace != null && WorkspaceStatus.RUNNING.equals(workspace.getStatus()); } boolean inPerspective = perspectives == null || perspectives.isEmpty() ? true : perspectives.contains(perspectiveManager.get().getPerspectiveId()); presentation.setEnabledAndVisible(inPerspective && isWorkspaceRunning); if (inPerspective && isWorkspaceRunning) { updateInPerspective(event); } }
/** Returns 'rel -> url' map of links for the given workspace. */ public Map<String, String> genLinks(Workspace workspace, ServiceContext serviceContext) throws ServerException { final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder(); final LinkedHashMap<String, String> links = new LinkedHashMap<>(); links.put( LINK_REL_SELF, uriBuilder .clone() .path(WorkspaceService.class, "getByKey") .build(workspace.getId()) .toString()); links.put( LINK_REL_IDE_URL, uriBuilder .clone() .replacePath("") .path(workspace.getNamespace()) .path(workspace.getConfig().getName()) .build() .toString()); if (workspace.getStatus() != WorkspaceStatus.STOPPED) { addRuntimeLinks(links, workspace.getId(), serviceContext); } return links; }
public WorkspaceStatus getWorkspaceStatusAssociatedWithFactory() throws Exception { return workspaceServiceClient .getByName(factoryDto.getWorkspace().getName(), owner.getName()) .getStatus(); } }
public WorkspaceImpl(Workspace workspace, Account account) { this( workspace.getId(), account, workspace.getConfig(), workspace.getRuntime(), workspace.getAttributes(), workspace.isTemporary(), workspace.getStatus()); }
/** Converts {@link Workspace} to {@link WorkspaceDto}. */ public static WorkspaceDto asDto(Workspace workspace) { WorkspaceDto workspaceDto = newDto(WorkspaceDto.class) .withId(workspace.getId()) .withStatus(workspace.getStatus()) .withNamespace(workspace.getNamespace()) .withTemporary(workspace.isTemporary()) .withAttributes(workspace.getAttributes()) .withConfig(asDto(workspace.getConfig())); if (workspace.getRuntime() != null) { RuntimeDto runtime = asDto(workspace.getRuntime()); workspaceDto.setRuntime(runtime); } return workspaceDto; }