Search in sources :

Example 1 with BeforeKubernetesRuntimeStateRemovedEvent

use of org.eclipse.che.workspace.infrastructure.kubernetes.cache.BeforeKubernetesRuntimeStateRemovedEvent in project che-server by eclipse-che.

the class JpaKubernetesRuntimeStateCache method doRemove.

@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected void doRemove(RuntimeIdentity runtimeIdentity) throws ServerException {
    EntityManager em = managerProvider.get();
    KubernetesRuntimeState runtime = em.find(KubernetesRuntimeState.class, runtimeIdentity.getWorkspaceId());
    if (runtime != null) {
        eventService.publish(new BeforeKubernetesRuntimeStateRemovedEvent(new KubernetesRuntimeState(runtime))).propagateException();
        em.remove(runtime);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) BeforeKubernetesRuntimeStateRemovedEvent(org.eclipse.che.workspace.infrastructure.kubernetes.cache.BeforeKubernetesRuntimeStateRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Example 2 with BeforeKubernetesRuntimeStateRemovedEvent

use of org.eclipse.che.workspace.infrastructure.kubernetes.cache.BeforeKubernetesRuntimeStateRemovedEvent in project devspaces-images by redhat-developer.

the class JpaKubernetesRuntimeStateCache method doRemove.

@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected void doRemove(RuntimeIdentity runtimeIdentity) throws ServerException {
    EntityManager em = managerProvider.get();
    KubernetesRuntimeState runtime = em.find(KubernetesRuntimeState.class, runtimeIdentity.getWorkspaceId());
    if (runtime != null) {
        eventService.publish(new BeforeKubernetesRuntimeStateRemovedEvent(new KubernetesRuntimeState(runtime))).propagateException();
        em.remove(runtime);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) BeforeKubernetesRuntimeStateRemovedEvent(org.eclipse.che.workspace.infrastructure.kubernetes.cache.BeforeKubernetesRuntimeStateRemovedEvent) Transactional(com.google.inject.persist.Transactional)

Example 3 with BeforeKubernetesRuntimeStateRemovedEvent

use of org.eclipse.che.workspace.infrastructure.kubernetes.cache.BeforeKubernetesRuntimeStateRemovedEvent in project che-server by eclipse-che.

the class KubernetesMachinesCacheTest method shouldRollbackTransactionOnFailedCascadeMachine.

// This test ensure that if during cascade removal of machine from cache (initiated during removal
// of runtime
// from cache) will happen an exception then transaction in runtime cache will rollback removal of
// machine cache.
// see
// @Transactional(rollbackOn = {RuntimeException.class, ServerException.class})
// protected void doRemove(RuntimeIdentity runtimeIdentity) throws ServerException
// Note that any checked exception that happened during RemoveEvent(extends CascadeEvent) would be
// transformed to
// ServerException. See RemoveEvent.propagateException.
@Test
public void shouldRollbackTransactionOnFailedCascadeMachine() throws Exception {
    // given
    assertTrue(machineCache.getMachines(runtimeStates[0].getRuntimeId()).size() > 0);
    CascadeEventSubscriber subscriber = new CascadeEventSubscriber<BeforeKubernetesRuntimeStateRemovedEvent>() {

        @Override
        public void onCascadeEvent(BeforeKubernetesRuntimeStateRemovedEvent event) throws Exception {
            machineCache.remove(event.getRuntimeState().getRuntimeId());
            throw new InfrastructureException("exception");
        }
    };
    eventService.subscribe(subscriber, BeforeKubernetesRuntimeStateRemovedEvent.class);
    // when
    try {
        runtimesStatesCache.remove(runtimeStates[0].getRuntimeId());
        fail("Should fail with InfrastructureException");
    } catch (InfrastructureException exc) {
    // ok
    } finally {
        eventService.unsubscribe(subscriber, BeforeKubernetesRuntimeStateRemovedEvent.class);
    }
    // then
    assertTrue(machineCache.getMachines(runtimeStates[0].getRuntimeId()).size() > 0);
}
Also used : CascadeEventSubscriber(org.eclipse.che.core.db.cascade.CascadeEventSubscriber) BeforeKubernetesRuntimeStateRemovedEvent(org.eclipse.che.workspace.infrastructure.kubernetes.cache.BeforeKubernetesRuntimeStateRemovedEvent) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Test(org.testng.annotations.Test)

Example 4 with BeforeKubernetesRuntimeStateRemovedEvent

use of org.eclipse.che.workspace.infrastructure.kubernetes.cache.BeforeKubernetesRuntimeStateRemovedEvent in project devspaces-images by redhat-developer.

the class KubernetesMachinesCacheTest method shouldRollbackTransactionOnFailedCascadeMachine.

// This test ensure that if during cascade removal of machine from cache (initiated during removal
// of runtime
// from cache) will happen an exception then transaction in runtime cache will rollback removal of
// machine cache.
// see
// @Transactional(rollbackOn = {RuntimeException.class, ServerException.class})
// protected void doRemove(RuntimeIdentity runtimeIdentity) throws ServerException
// Note that any checked exception that happened during RemoveEvent(extends CascadeEvent) would be
// transformed to
// ServerException. See RemoveEvent.propagateException.
@Test
public void shouldRollbackTransactionOnFailedCascadeMachine() throws Exception {
    // given
    assertTrue(machineCache.getMachines(runtimeStates[0].getRuntimeId()).size() > 0);
    CascadeEventSubscriber subscriber = new CascadeEventSubscriber<BeforeKubernetesRuntimeStateRemovedEvent>() {

        @Override
        public void onCascadeEvent(BeforeKubernetesRuntimeStateRemovedEvent event) throws Exception {
            machineCache.remove(event.getRuntimeState().getRuntimeId());
            throw new InfrastructureException("exception");
        }
    };
    eventService.subscribe(subscriber, BeforeKubernetesRuntimeStateRemovedEvent.class);
    // when
    try {
        runtimesStatesCache.remove(runtimeStates[0].getRuntimeId());
        fail("Should fail with InfrastructureException");
    } catch (InfrastructureException exc) {
    // ok
    } finally {
        eventService.unsubscribe(subscriber, BeforeKubernetesRuntimeStateRemovedEvent.class);
    }
    // then
    assertTrue(machineCache.getMachines(runtimeStates[0].getRuntimeId()).size() > 0);
}
Also used : CascadeEventSubscriber(org.eclipse.che.core.db.cascade.CascadeEventSubscriber) BeforeKubernetesRuntimeStateRemovedEvent(org.eclipse.che.workspace.infrastructure.kubernetes.cache.BeforeKubernetesRuntimeStateRemovedEvent) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Test(org.testng.annotations.Test)

Aggregations

BeforeKubernetesRuntimeStateRemovedEvent (org.eclipse.che.workspace.infrastructure.kubernetes.cache.BeforeKubernetesRuntimeStateRemovedEvent)4 Transactional (com.google.inject.persist.Transactional)2 EntityManager (javax.persistence.EntityManager)2 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)2 CascadeEventSubscriber (org.eclipse.che.core.db.cascade.CascadeEventSubscriber)2 KubernetesRuntimeState (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState)2 Test (org.testng.annotations.Test)2