WorkspaceManager { public WorkspaceImpl startWorkspace( String workspaceId, @Nullable String envName, @Nullable Map<String, String> options) throws NotFoundException, ServerException, ConflictException { requireNonNull(workspaceId, "Required non-null workspace id"); final WorkspaceImpl workspace = workspaceDao.get(workspaceId); startAsync(workspace, envName, options); return normalizeState(workspace, true); } @Inject  WorkspaceManager(
      WorkspaceDao workspaceDao,
      WorkspaceRuntimes runtimes,
      EventService eventService,
      AccountManager accountManager,
      PreferenceManager preferenceManager,
      WorkspaceValidator validator,
      DevfileIntegrityValidator devfileIntegrityValidator); @Traced WorkspaceImpl createWorkspace(
      WorkspaceConfig config, String namespace, Map<String, String> attributes); @Traced WorkspaceImpl createWorkspace(
      Devfile devfile,
      String namespace,
      Map<String, String> attributes,
      FileContentProvider contentProvider); WorkspaceImpl getWorkspace(String key); WorkspaceImpl getWorkspace(String name, String namespace); Page<WorkspaceImpl> getWorkspaces(
      String user, boolean includeRuntimes, int maxItems, long skipCount); Page<WorkspaceImpl> getByNamespace(
      String namespace, boolean includeRuntimes, int maxItems, long skipCount); WorkspaceImpl updateWorkspace(String id, Workspace update); @Traced void removeWorkspace(String workspaceId); WorkspaceImpl startWorkspace(
      String workspaceId, @Nullable String envName, @Nullable Map<String, String> options); WorkspaceImpl startWorkspace(
      WorkspaceConfig config, String namespace, boolean isTemporary, Map<String, String> options); void stopWorkspace(String workspaceId, Map<String, String> options); Set<String> getSupportedRecipes(); long getWorkspacesTotalCount();  }
@Test public void getsWorkspaceByIdWithRuntime() throws Exception { final WorkspaceImpl workspace = createAndMockWorkspace(); mockStart(workspace); mockRuntime(workspace, STARTING); final WorkspaceImpl result = workspaceManager.startWorkspace( workspace.getId(), workspace.getConfig().getDefaultEnv(), emptyMap()); assertEquals( result.getStatus(), STARTING, "Workspace status must be taken from the runtime instance"); }
@Test public void setsErrorAttributesAfterWorkspaceStartFailed() throws Exception { final WorkspaceConfigImpl workspaceConfig = createConfig(); final WorkspaceImpl workspace = createAndMockWorkspace(workspaceConfig, NAMESPACE_1); mockAnyWorkspaceStartFailed(new ServerException("start failed")); workspaceManager.startWorkspace(workspace.getId(), null, null); verify(workspaceDao, times(2)).update(workspaceCaptor.capture()); Workspace ws = workspaceCaptor.getAllValues().get(1); assertNotNull(ws.getAttributes().get(STOPPED_ATTRIBUTE_NAME)); assertTrue(Boolean.valueOf(ws.getAttributes().get(STOPPED_ABNORMALLY_ATTRIBUTE_NAME))); assertEquals(ws.getAttributes().get(ERROR_MESSAGE_ATTRIBUTE_NAME), "start failed"); }
@Test public void clearsErrorAttributesAfterWorkspaceStart() throws Exception { final WorkspaceConfigImpl workspaceConfig = createConfig(); final WorkspaceImpl workspace = createAndMockWorkspace(workspaceConfig, NAMESPACE_1); workspace .getAttributes() .put(STOPPED_ATTRIBUTE_NAME, Long.toString(System.currentTimeMillis())); workspace.getAttributes().put(STOPPED_ABNORMALLY_ATTRIBUTE_NAME, Boolean.TRUE.toString()); workspace.getAttributes().put(ERROR_MESSAGE_ATTRIBUTE_NAME, "start failed"); when(workspaceDao.get(workspace.getId())).thenReturn(workspace); mockStart(workspace); workspaceManager.startWorkspace(workspace.getId(), null, emptyMap()); verify(workspaceDao, atLeastOnce()).update(workspaceCaptor.capture()); Workspace ws = workspaceCaptor.getAllValues().get(workspaceCaptor.getAllValues().size() - 1); assertNull(ws.getAttributes().get(STOPPED_ATTRIBUTE_NAME)); assertNull(ws.getAttributes().get(STOPPED_ABNORMALLY_ATTRIBUTE_NAME)); assertNull(ws.getAttributes().get(ERROR_MESSAGE_ATTRIBUTE_NAME)); }
@Test public void removesTemporaryWorkspaceAfterStartFailed() throws Exception { final WorkspaceConfigImpl workspaceConfig = createConfig(); final WorkspaceImpl workspace = createAndMockWorkspace(workspaceConfig, NAMESPACE_1); mockAnyWorkspaceStartFailed(new ServerException("start failed")); when(runtimes.evalInfrastructureNamespace(any())).thenReturn(INFRA_NAMESPACE); workspaceManager.startWorkspace(workspaceConfig, workspace.getNamespace(), true, emptyMap()); verify(workspaceDao, times(1)).remove(anyString()); }