Search in sources :

Example 56 with RuntimeIdentityImpl

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);
}
Also used : EventService(org.eclipse.che.api.core.notification.EventService) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 57 with RuntimeIdentityImpl

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());
}
Also used : RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Example 58 with RuntimeIdentityImpl

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);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) ValidationException(org.eclipse.che.api.core.ValidationException) ConflictException(org.eclipse.che.api.core.ConflictException) InternalRuntime(org.eclipse.che.api.workspace.server.spi.InternalRuntime) RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) RuntimeContext(org.eclipse.che.api.workspace.server.spi.RuntimeContext) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) Traced(org.eclipse.che.commons.annotation.Traced)

Example 59 with RuntimeIdentityImpl

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");
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) InternalMachineConfig(org.eclipse.che.api.workspace.server.spi.environment.InternalMachineConfig) Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) HashMap(java.util.HashMap) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 60 with RuntimeIdentityImpl

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);
}
Also used : EventService(org.eclipse.che.api.core.notification.EventService) RuntimeIdentityImpl(org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl) Test(org.testng.annotations.Test)

Aggregations

RuntimeIdentityImpl (org.eclipse.che.api.workspace.server.model.impl.RuntimeIdentityImpl)98 Test (org.testng.annotations.Test)92 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)68 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)22 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)18 RuntimeContext (org.eclipse.che.api.workspace.server.spi.RuntimeContext)18 InternalEnvironment (org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment)16 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)14 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)10 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)8 Secret (io.fabric8.kubernetes.api.model.Secret)8 ValidationException (org.eclipse.che.api.core.ValidationException)8 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)8 EventService (org.eclipse.che.api.core.notification.EventService)8 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)8 CredentialsSecretConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.CredentialsSecretConfigurator)8 PreferencesConfigMapConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.PreferencesConfigMapConfigurator)8 WorkspaceServiceAccountConfigurator (org.eclipse.che.workspace.infrastructure.kubernetes.namespace.configurator.WorkspaceServiceAccountConfigurator)8