use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project devspaces-images by redhat-developer.
the class KubernetesRuntimeStateCacheTest method shouldUpdateStatusIfPreviousValueMatchesPredicate.
@Test(dependsOnMethods = "shouldReturnRuntimeStatus")
public void shouldUpdateStatusIfPreviousValueMatchesPredicate() throws Exception {
// given
KubernetesRuntimeState stateToUpdate = runtimesStates[0];
// when
boolean isUpdated = runtimesStatesCache.updateStatus(stateToUpdate.getRuntimeId(), s -> s == stateToUpdate.getStatus(), WorkspaceStatus.STOPPED);
// then
assertTrue(isUpdated);
Optional<WorkspaceStatus> updatedStatusOpt = runtimesStatesCache.getStatus(stateToUpdate.getRuntimeId());
assertTrue(updatedStatusOpt.isPresent());
assertEquals(updatedStatusOpt.get(), WorkspaceStatus.STOPPED);
assertNotEquals(stateToUpdate, WorkspaceStatus.STOPPED);
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project devspaces-images by redhat-developer.
the class KubernetesRuntimeStateCacheTest method shouldReturnRuntimeStateByRuntimeId.
@Test
public void shouldReturnRuntimeStateByRuntimeId() throws Exception {
// given
KubernetesRuntimeState expectedState = runtimesStates[1];
// when
Optional<KubernetesRuntimeState> fetchedOpt = runtimesStatesCache.get(expectedState.getRuntimeId());
// then
assertTrue(fetchedOpt.isPresent());
assertEquals(expectedState, fetchedOpt.get());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project devspaces-images by redhat-developer.
the class KubernetesRuntimeStateCacheTest method shouldPutRuntimeState.
@Test(dependsOnMethods = "shouldReturnRuntimeStateByRuntimeId")
public void shouldPutRuntimeState() throws Exception {
// given
KubernetesRuntimeState runtimeState = createRuntimeState(workspaces[2]);
// when
boolean isInserted = runtimesStatesCache.putIfAbsent(runtimeState);
// then
assertTrue(isInserted);
Optional<KubernetesRuntimeState> fetchedState = runtimesStatesCache.get(runtimeState.getRuntimeId());
assertTrue(fetchedState.isPresent());
assertEquals(runtimeState, fetchedState.get());
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project devspaces-images by redhat-developer.
the class KubernetesRuntimeContext method getRuntime.
@Override
public KubernetesInternalRuntime getRuntime() throws InfrastructureException {
Optional<KubernetesRuntimeState> runtimeStateOpt = runtimeStatuses.get(getIdentity());
String workspaceId = getIdentity().getWorkspaceId();
if (!runtimeStateOpt.isPresent()) {
// there is no cached runtime, create a new one
return runtimeFactory.create(this, namespaceFactory.getOrCreate(getIdentity()));
}
// there is cached runtime, restore cached one
KubernetesRuntimeState runtimeState = runtimeStateOpt.get();
RuntimeIdentity runtimeId = runtimeState.getRuntimeId();
LOG.debug("Restoring runtime `{}:{}:{}`", runtimeId.getWorkspaceId(), runtimeId.getEnvName(), runtimeId.getOwnerId());
KubernetesInternalRuntime runtime = runtimeFactory.create(this, namespaceFactory.access(workspaceId, runtimeState.getNamespace()));
runtime.scheduleRuntimeStateChecks();
return runtime;
}
use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState in project devspaces-images by redhat-developer.
the class JpaKubernetesRuntimeStateCache method doUpdateStatus.
@Transactional(rollbackOn = { RuntimeException.class, InfrastructureException.class })
protected void doUpdateStatus(RuntimeIdentity id, Predicate<WorkspaceStatus> predicate, WorkspaceStatus newStatus) throws InfrastructureException {
EntityManager entityManager = managerProvider.get();
Optional<KubernetesRuntimeState> existingStateOpt = get(id);
if (!existingStateOpt.isPresent()) {
throw new InfrastructureException("Runtime state for workspace with id '" + id.getWorkspaceId() + "' was not found");
}
KubernetesRuntimeState existingState = existingStateOpt.get();
if (!predicate.test(existingState.getStatus())) {
throw new IllegalStateException("Runtime status doesn't match to the specified predicate");
}
existingState.setStatus(newStatus);
entityManager.flush();
}
Aggregations