Java Code Examples for org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl#setTemporary()

The following examples show how to use org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl#setTemporary() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkspaceDaoTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldGetWorkspacesByNonTemporary() throws Exception {
  final WorkspaceImpl workspace = workspaces[4];
  workspace.setTemporary(true);
  workspaceDao.update(workspace);

  Page<WorkspaceImpl> firstPage = workspaceDao.getWorkspaces(false, 2, 0);

  assertEquals(firstPage.getItems().size(), 2);
  assertEquals(firstPage.getTotalItemsCount(), 4);
  assertEquals(
      new HashSet<>(firstPage.getItems()), new HashSet<>(asList(workspaces[0], workspaces[1])));

  Page<WorkspaceImpl> secondPage = workspaceDao.getWorkspaces(false, 2, 2);

  assertEquals(secondPage.getItems().size(), 2);
  assertEquals(secondPage.getTotalItemsCount(), 4);
  assertEquals(
      new HashSet<>(secondPage.getItems()), new HashSet<>(asList(workspaces[2], workspaces[3])));
}
 
Example 2
Source File: WorkspaceManager.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Updates an existing workspace with a new configuration.
 *
 * <p>
 *
 * <p>Replace strategy is used for workspace update, it means that existing workspace data will be
 * replaced with given {@code update}.
 *
 * @param update workspace update
 * @return updated instance of the workspace
 * @throws NullPointerException when either {@code workspaceId} or {@code update} is null
 * @throws NotFoundException when workspace with given id doesn't exist
 * @throws ConflictException when any conflict occurs (e.g Workspace with such name already exists
 *     in {@code namespace})
 * @throws ServerException when any other error occurs
 */
public WorkspaceImpl updateWorkspace(String id, Workspace update)
    throws ConflictException, ServerException, NotFoundException, ValidationException {
  requireNonNull(id, "Required non-null workspace id");
  requireNonNull(update, "Required non-null workspace update");
  checkArgument(
      update.getConfig() != null ^ update.getDevfile() != null,
      "Required non-null workspace configuration or devfile update but not both");
  if (update.getConfig() != null) {
    validator.validateConfig(update.getConfig());
  }
  WorkspaceImpl workspace = workspaceDao.get(id);

  validator.validateUpdateAttributes(workspace.getAttributes(), update.getAttributes());

  if (workspace.getConfig() != null) {
    workspace.setConfig(new WorkspaceConfigImpl(update.getConfig()));
  }
  if (workspace.getDevfile() != null) {
    workspace.setDevfile(new DevfileImpl(update.getDevfile()));
  }

  workspace.setAttributes(update.getAttributes());

  workspace.getAttributes().put(UPDATED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis()));
  workspace.setTemporary(update.isTemporary());

  return normalizeState(workspaceDao.update(workspace), true);
}
 
Example 3
Source File: WorkspaceDaoTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldGetWorkspacesByTemporary() throws Exception {
  final WorkspaceImpl workspace = workspaces[0];
  workspace.setTemporary(true);
  workspaceDao.update(workspace);

  Page<WorkspaceImpl> result = workspaceDao.getWorkspaces(true, 30, 0);

  assertEquals(result.getItems().size(), 1);
  assertEquals(result.getTotalItemsCount(), 1);
  assertEquals(result.getItems().iterator().next(), workspaceDao.get(workspace.getId()));
}
 
Example 4
Source File: WorkspaceManagerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void updatesWorkspace() throws Exception {
  final WorkspaceImpl workspace = new WorkspaceImpl(createAndMockWorkspace());
  Map<String, String> oldAttributes = new HashMap<>(workspace.getAttributes());
  workspace.setTemporary(true);
  workspace.getAttributes().put("new attribute", "attribute");
  when(workspaceDao.update(any())).thenAnswer(inv -> inv.getArguments()[0]);

  workspaceManager.updateWorkspace(workspace.getId(), workspace);

  verify(workspaceDao).update(workspace);
  verify(validator).validateUpdateAttributes(oldAttributes, workspace.getAttributes());
}
 
Example 5
Source File: WorkspaceManagerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void removesTemporaryWorkspaceAfterStop() throws Exception {
  final WorkspaceImpl workspace = createAndMockWorkspace();
  workspace.setTemporary(true);
  mockRuntime(workspace, RUNNING);
  mockAnyWorkspaceStop();

  workspaceManager.stopWorkspace(workspace.getId(), emptyMap());

  verify(runtimes).stopAsync(workspace, emptyMap());
  verify(workspaceDao).remove(workspace.getId());
}
 
Example 6
Source File: WorkspaceManagerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void removesTemporaryWorkspaceAfterStopFailed() throws Exception {
  final WorkspaceImpl workspace = createAndMockWorkspace();
  workspace.setTemporary(true);
  mockRuntime(workspace, RUNNING);
  doThrow(new ConflictException("runtime stop failed"))
      .when(runtimes)
      .stopAsync(workspace, emptyMap());
  mockAnyWorkspaceStop();

  workspaceManager.stopWorkspace(workspace.getId(), emptyMap());
  verify(workspaceDao).remove(workspace.getId());
}