Search in sources :

Example 16 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class JpaSnapshotDao method doRemove.

@Transactional
protected void doRemove(String snapshotId) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    final SnapshotImpl snapshot = manager.find(SnapshotImpl.class, snapshotId);
    if (snapshot == null) {
        throw new NotFoundException(format("Snapshot with id '%s' doesn't exist", snapshotId));
    }
    manager.remove(snapshot);
}
Also used : EntityManager(javax.persistence.EntityManager) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 17 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class JpaSnapshotDao method doReplaceSnapshots.

@Transactional
protected List<SnapshotImpl> doReplaceSnapshots(String workspaceId, String envName, Collection<? extends SnapshotImpl> newSnapshots) {
    final EntityManager manager = managerProvider.get();
    final List<SnapshotImpl> existing = manager.createNamedQuery("Snapshot.findByWorkspaceAndEnvironment", SnapshotImpl.class).setParameter("workspaceId", workspaceId).setParameter("envName", envName).getResultList();
    existing.forEach(manager::remove);
    manager.flush();
    newSnapshots.forEach(manager::persist);
    return existing;
}
Also used : EntityManager(javax.persistence.EntityManager) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Transactional(com.google.inject.persist.Transactional)

Example 18 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class SnapshotDaoTest method shouldFindSnapshotsByWorkspaceAndNamespace.

@Test
public void shouldFindSnapshotsByWorkspaceAndNamespace() throws Exception {
    final SnapshotImpl snapshot = snapshots[0];
    final List<SnapshotImpl> found = snapshotDao.findSnapshots(snapshot.getWorkspaceId());
    assertEquals(new HashSet<>(found), new HashSet<>(asList(snapshots[0], snapshots[1], snapshots[2])));
}
Also used : SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Test(org.testng.annotations.Test)

Example 19 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class SnapshotDaoTest method replacesSnapshots.

@Test(dependsOnMethods = "shouldFindSnapshotsByWorkspaceAndNamespace")
public void replacesSnapshots() throws Exception {
    final SnapshotImpl newSnapshot = createSnapshot("new-snapshot", snapshots[0].getWorkspaceId(), snapshots[0].getEnvName(), snapshots[0].getMachineName());
    final List<SnapshotImpl> replaced = snapshotDao.replaceSnapshots(newSnapshot.getWorkspaceId(), newSnapshot.getEnvName(), singletonList(newSnapshot));
    assertEquals(new HashSet<>(replaced), Sets.newHashSet(snapshots[0], snapshots[1]));
    final HashSet<SnapshotImpl> actual = new HashSet<>(snapshotDao.findSnapshots(this.snapshots[0].getWorkspaceId()));
    final HashSet<SnapshotImpl> expected = Sets.newHashSet(newSnapshot, this.snapshots[2]);
    assertEquals(actual, expected);
}
Also used : SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 20 with SnapshotImpl

use of org.eclipse.che.api.machine.server.model.impl.SnapshotImpl in project che by eclipse.

the class SnapshotDaoTest method shouldGetSnapshotByWorkspaceEnvironmentAndMachineName.

@Test
public void shouldGetSnapshotByWorkspaceEnvironmentAndMachineName() throws Exception {
    final SnapshotImpl snapshot = snapshots[0];
    assertEquals(snapshotDao.getSnapshot(snapshot.getWorkspaceId(), snapshot.getEnvName(), snapshot.getMachineName()), snapshot);
}
Also used : SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Test(org.testng.annotations.Test)

Aggregations

SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)31 Test (org.testng.annotations.Test)22 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)13 MachineSourceImpl (org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl)10 NotFoundException (org.eclipse.che.api.core.NotFoundException)6 ServerException (org.eclipse.che.api.core.ServerException)5 SnapshotException (org.eclipse.che.api.machine.server.exception.SnapshotException)4 Instance (org.eclipse.che.api.machine.server.spi.Instance)4 ArrayList (java.util.ArrayList)3 ConflictException (org.eclipse.che.api.core.ConflictException)3 Workspace (org.eclipse.che.api.core.model.workspace.Workspace)3 EnvironmentException (org.eclipse.che.api.environment.server.exception.EnvironmentException)3 EnvironmentNotRunningException (org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException)3 SourceNotFoundException (org.eclipse.che.api.machine.server.exception.SourceNotFoundException)3 SnapshotDao (org.eclipse.che.api.machine.server.spi.SnapshotDao)3 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)3 Matchers.anyString (org.mockito.Matchers.anyString)3 TypeLiteral (com.google.inject.TypeLiteral)2 Transactional (com.google.inject.persist.Transactional)2 IOException (java.io.IOException)2