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);
}
}
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);
}
}
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);
}
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);
}
Aggregations