use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class KubernetesRuntimeStateCacheTest method shouldDoNothingIfStateIsAlreadyRemove.
@Test(dependsOnMethods = "shouldReturnEmptyOptionalIfRuntimeStateIsNotFound")
public void shouldDoNothingIfStateIsAlreadyRemove() throws Exception {
// given
KubernetesRuntimeState runtimeState = createRuntimeState(workspaces[2]);
RuntimeIdentity toRemove = runtimeState.getRuntimeId();
// when
runtimesStatesCache.remove(toRemove);
// then
assertFalse(runtimesStatesCache.get(toRemove).isPresent());
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class BrokerService method handle.
private void handle(BrokerStatusChangedEvent event) {
String encodedTooling = event.getTooling();
RuntimeIdentity runtimeId = event.getRuntimeId();
if (event.getStatus() == null || runtimeId == null || runtimeId.getWorkspaceId() == null) {
LOG.error("Broker event skipped due to illegal content: {}", event);
return;
}
eventService.publish(new BrokerEvent(event, parseTooling(encodedTooling)));
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class WorkspaceRuntimes method getInternalRuntime.
/**
* Returns {@link InternalRuntime} implementation for workspace with the specified id.
*
* <p>If memory-storage does not contain internal runtime, then runtime will be recovered if it is
* active. Otherwise, an exception will be thrown.
*
* @param workspaceId identifier of workspace to fetch runtime
* @return {@link InternalRuntime} implementation for workspace with the specified id.
* @throws InfrastructureException if any infrastructure exception occurs
* @throws ServerException if there is no active runtime for the specified workspace
* @throws ServerException if any other exception occurs
*/
public InternalRuntime<?> getInternalRuntime(String workspaceId) throws InfrastructureException, ServerException {
try (Unlocker ignored = lockService.writeLock(workspaceId)) {
InternalRuntime<?> runtime = runtimes.get(workspaceId);
if (runtime == null) {
try {
final Optional<RuntimeIdentity> runtimeIdentity = infrastructure.getIdentities().stream().filter(id -> id.getWorkspaceId().equals(workspaceId)).findAny();
if (runtimeIdentity.isPresent()) {
LOG.info("Runtime for workspace '{}' is requested but there is no cached one. Recovering it.", workspaceId);
runtime = recoverOne(infrastructure, runtimeIdentity.get());
} else {
// runtime is not considered by Infrastructure as active
throw new ServerException("No active runtime is found");
}
} catch (ServerException e) {
statuses.remove(workspaceId);
throw e;
} catch (UnsupportedOperationException | ConflictException e) {
statuses.remove(workspaceId);
throw new ServerException(e.getMessage(), e);
}
}
return runtime;
}
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class WorkspaceRuntimes method recover.
@VisibleForTesting
void recover() {
if (isStartRefused.get()) {
LOG.warn("Recovery of the workspaces is rejected.");
return;
}
Set<RuntimeIdentity> identities;
try {
identities = infrastructure.getIdentities();
} catch (UnsupportedOperationException e) {
LOG.warn("Not recoverable infrastructure: '{}'", infrastructure.getName());
return;
} catch (InfrastructureException e) {
LOG.error("An error occurred while attempting to get runtime identities for infrastructure '{}'. Reason: '{}'", infrastructure.getName(), e.getMessage());
return;
}
LOG.info("Infrastructure is tracking {} active runtimes", identities.size());
if (identities.isEmpty()) {
return;
}
for (RuntimeIdentity identity : identities) {
String workspaceId = identity.getWorkspaceId();
try (Unlocker ignored = lockService.writeLock(workspaceId)) {
statuses.putIfAbsent(workspaceId, STARTING);
}
}
sharedPool.execute(new RecoverRuntimesTask(identities));
}
use of org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity in project che-server by eclipse-che.
the class WorkspaceRuntimes method stop.
void stop() {
Set<RuntimeIdentity> identities;
try {
identities = infrastructure.getIdentities();
} catch (UnsupportedOperationException e) {
LOG.warn("Not recoverable infrastructure: '{}'", infrastructure.getName());
return;
} catch (InfrastructureException e) {
LOG.error("An error occurred while attempting to get runtime identities for infrastructure '{}'. Reason: '{}'", infrastructure.getName(), e.getMessage());
return;
}
LOG.info("Infrastructure is tracking {} active runtimes that need to be stopped", identities.size());
if (identities.isEmpty()) {
return;
}
for (RuntimeIdentity identity : identities) {
try {
String workspaceId = identity.getWorkspaceId();
WorkspaceImpl workspace = workspaceDao.get(workspaceId);
try (Unlocker ignored = lockService.writeLock(workspaceId)) {
statuses.putIfAbsent(workspaceId, STARTING);
}
String namespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
stopAsync(workspace, emptyMap()).whenComplete((aVoid, throwable) -> {
LOG.info("Workspace '{}' owned by '{}' has been stopped in namespace '{}'", workspaceId, namespace);
});
} catch (Exception e) {
LOG.error("An error occurred while attempting to stop runtime '{}' using infrastructure '{}'. Reason: '{}'", workspaceRuntimesId, infrastructure.getName(), e.getMessage(), e);
}
}
}
Aggregations