use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class StartSynchronizerTest method shouldAddSubscribersAfterStart.
@Test
public void shouldAddSubscribersAfterStart() throws Exception {
// given
runtimeId = new RuntimeIdentityImpl("workspace123", "envName", "ownerId", "infraNamespace");
EventService eventService = new EventService();
startSynchronizer = new StartSynchronizer(eventService, 5, runtimeId);
// when
startSynchronizer.start();
// then
assertSubscriberTypesNumber(eventService, 2);
assertSubscribersNumber(eventService, KubernetesRuntimeStoppingEvent.class, 1);
assertSubscribersNumber(eventService, KubernetesRuntimeStoppedEvent.class, 1);
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class KubernetesRuntimeStateCacheTest method shouldReturnEmptyCommandsListIfStateDoesNotExist.
@Test
public void shouldReturnEmptyCommandsListIfStateDoesNotExist() throws Exception {
// when
List<? extends Command> commands = runtimesStatesCache.getCommands(new RuntimeIdentityImpl("non-existent-ws", "defEnv", "acc1", "infraNamespace"));
// then
assertTrue(commands.isEmpty());
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project devspaces-images by redhat-developer.
the class WorkspaceRuntimes method startAsync.
/**
* Starts all machines from specified workspace environment, creates workspace runtime instance
* based on that environment.
*
* <p>During the start of the workspace its runtime is visible with {@link
* WorkspaceStatus#STARTING} status.
*
* @param workspace workspace which environment should be started
* @param envName optional environment name to run
* @param options whether machines should be recovered(true) or not(false)
* @return completable future of start execution.
* @throws ConflictException when workspace is already running
* @throws ConflictException when start is interrupted
* @throws NotFoundException when any not found exception occurs during environment start
* @throws ServerException other error occurs during environment start
* @see WorkspaceStatus#STARTING
* @see WorkspaceStatus#RUNNING
*/
@Traced
public CompletableFuture<Void> startAsync(WorkspaceImpl workspace, @Nullable String envName, Map<String, String> options) throws ConflictException, NotFoundException, ServerException {
TracingTags.WORKSPACE_ID.set(workspace.getId());
final String workspaceId = workspace.getId();
if (isStartRefused.get()) {
throw new ConflictException(format("Start of the workspace '%s' is rejected by the system, " + "no more workspaces are allowed to start", workspace.getName()));
}
WorkspaceConfigImpl config = workspace.getConfig();
if (config == null) {
config = devfileConverter.convert(workspace.getDevfile());
}
if (envName == null) {
envName = config.getDefaultEnv();
}
String infraNamespace = workspace.getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
if (isNullOrEmpty(infraNamespace)) {
throw new ServerException(String.format("Workspace does not have infrastructure namespace " + "specified. Please set value of '%s' workspace attribute.", WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE));
}
final RuntimeIdentity runtimeId = new RuntimeIdentityImpl(workspaceId, envName, EnvironmentContext.getCurrent().getSubject().getUserId(), infraNamespace);
try {
InternalEnvironment internalEnv = createInternalEnvironment(config.getEnvironments().get(envName), config.getAttributes(), config.getCommands(), config.getDevfile());
RuntimeContext runtimeContext = infrastructure.prepare(runtimeId, internalEnv);
InternalRuntime runtime = runtimeContext.getRuntime();
try (Unlocker ignored = lockService.writeLock(workspaceId)) {
final WorkspaceStatus existingStatus = statuses.putIfAbsent(workspaceId, STARTING);
if (existingStatus != null) {
throw new ConflictException(format("Could not start workspace '%s' because its state is '%s'", workspaceId, existingStatus));
}
setRuntimesId(workspaceId);
runtimes.put(workspaceId, runtime);
}
LOG.info("Starting workspace '{}/{}' with id '{}' by user '{}'", workspace.getNamespace(), workspace.getName(), workspace.getId(), sessionUserNameOr("undefined"));
publishWorkspaceStatusEvent(workspaceId, STARTING, STOPPED, null, true, options);
return CompletableFuture.runAsync(ThreadLocalPropagateContext.wrap(new StartRuntimeTask(workspace, options, runtime)), sharedPool.getExecutor());
} catch (ValidationException e) {
LOG.error(e.getLocalizedMessage(), e);
throw new ConflictException(e.getLocalizedMessage());
} catch (InfrastructureException e) {
LOG.error(e.getLocalizedMessage(), e);
throw new ServerException(e.getLocalizedMessage(), e);
}
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class EnvVarsConverterTest method setUp.
@BeforeMethod
public void setUp() {
testContainer = new Container();
PodSpec podSpec = new PodSpec();
podSpec.setContainers(singletonList(testContainer));
ObjectMeta podMeta = new ObjectMeta();
podMeta.setName("pod");
Pod pod = new Pod();
pod.setSpec(podSpec);
pod.setMetadata(podMeta);
Map<String, Pod> pods = new HashMap<>();
pods.put("pod", pod);
environment = KubernetesEnvironment.builder().setPods(pods).build();
machine = new InternalMachineConfig();
environment.setMachines(Collections.singletonMap(Names.machineName(podMeta, testContainer), machine));
identity = new RuntimeIdentityImpl("wsId", "blah", "bleh", "infraNamespace");
}
use of org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl in project che-server by eclipse-che.
the class StartSynchronizerTest method shouldUnsubscribeEventsWhenItIsCompleted.
@Test
public void shouldUnsubscribeEventsWhenItIsCompleted() throws Exception {
// given
runtimeId = new RuntimeIdentityImpl("workspace123", "envName", "ownerId", "infraNamespace");
EventService eventService = new EventService();
startSynchronizer = new StartSynchronizer(eventService, 5, runtimeId);
startSynchronizer.start();
// when
startSynchronizer.complete();
// then
assertSubscribersNumber(eventService, KubernetesRuntimeStoppingEvent.class, 0);
assertSubscribersNumber(eventService, KubernetesRuntimeStoppedEvent.class, 0);
}
Aggregations