Search in sources :

Example 16 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project che-server by eclipse-che.

the class KubernetesInternalRuntime method internalStart.

@Override
protected void internalStart(Map<String, String> startOptions) throws InfrastructureException {
    KubernetesRuntimeContext<E> context = getContext();
    String workspaceId = context.getIdentity().getWorkspaceId();
    try {
        startSynchronizer.setStartThread();
        startSynchronizer.start();
        runtimeCleaner.cleanUp(namespace, workspaceId);
        provisionWorkspace(startOptions, context, workspaceId);
        volumesStrategy.prepare(context.getEnvironment(), context.getIdentity(), startSynchronizer.getStartTimeoutMillis(), startOptions);
        startSynchronizer.checkFailure();
        startMachines();
        watchLogsIfDebugEnabled(startOptions);
        previewUrlCommandProvisioner.provision(context.getEnvironment(), namespace);
        runtimeStates.updateCommands(context.getIdentity(), context.getEnvironment().getCommands());
        startSynchronizer.checkFailure();
        final Map<String, CompletableFuture<Void>> machinesFutures = new LinkedHashMap<>();
        // futures that must be cancelled explicitly
        final List<CompletableFuture<?>> toCancelFutures = new CopyOnWriteArrayList<>();
        final EnvironmentContext currentContext = EnvironmentContext.getCurrent();
        CompletableFuture<Void> startFailure = startSynchronizer.getStartFailure();
        Span waitRunningAsyncSpan = tracer.buildSpan(WAIT_MACHINES_START).start();
        try (Scope waitRunningAsyncScope = tracer.scopeManager().activate(waitRunningAsyncSpan)) {
            TracingTags.WORKSPACE_ID.set(waitRunningAsyncSpan, workspaceId);
            for (KubernetesMachineImpl machine : machines.getMachines(context.getIdentity()).values()) {
                String machineName = machine.getName();
                final CompletableFuture<Void> machineBootChain = waitRunningAsync(toCancelFutures, machine).thenComposeAsync(checkFailure(startFailure), executor).thenRun(publishRunningStatus(machineName)).thenCompose(checkFailure(startFailure)).thenCompose(setContext(currentContext, checkServers(toCancelFutures, machine))).exceptionally(publishFailedStatus(startFailure, machineName));
                machinesFutures.put(machineName, machineBootChain);
            }
            waitMachines(machinesFutures, toCancelFutures, startFailure);
        } finally {
            waitRunningAsyncSpan.finish();
        }
        startSynchronizer.complete();
    } catch (InfrastructureException | RuntimeException e) {
        Exception startFailureCause = startSynchronizer.getStartFailureNow();
        if (startFailureCause == null) {
            startFailureCause = e;
        }
        startSynchronizer.completeExceptionally(startFailureCause);
        LOG.warn("Failed to start Kubernetes runtime of workspace {}.", workspaceId, startFailureCause);
        boolean interrupted = Thread.interrupted() || startFailureCause instanceof RuntimeStartInterruptedException;
        // Cancels workspace servers probes if any
        probeScheduler.cancel(workspaceId);
        // stop watching before namespace cleaning up
        namespace.deployments().stopWatch(true);
        try {
            runtimeCleaner.cleanUp(namespace, workspaceId);
        } catch (InfrastructureException cleanUppingEx) {
            LOG.warn("Failed to clean up namespace after workspace '{}' start failing.", context.getIdentity().getWorkspaceId(), cleanUppingEx);
        }
        if (interrupted) {
            throw new RuntimeStartInterruptedException(getContext().getIdentity());
        }
        wrapAndRethrow(startFailureCause);
    } finally {
        namespace.deployments().stopWatch();
    }
}
Also used : Span(io.opentracing.Span) TimeoutException(java.util.concurrent.TimeoutException) StateException(org.eclipse.che.api.workspace.server.spi.StateException) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) ValidationException(org.eclipse.che.api.core.ValidationException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) ExecutionException(java.util.concurrent.ExecutionException) LinkedHashMap(java.util.LinkedHashMap) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) CompletableFuture(java.util.concurrent.CompletableFuture) Scope(io.opentracing.Scope) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) RuntimeStartInterruptedException(org.eclipse.che.api.workspace.server.spi.RuntimeStartInterruptedException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) InternalInfrastructureException(org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 17 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project che-server by eclipse-che.

the class KubernetesInternalRuntimeTest method shouldReturnFalseIfAllPodsExistOnRuntimeConsistencyChecking.

@Test
public void shouldReturnFalseIfAllPodsExistOnRuntimeConsistencyChecking() throws Exception {
    // given
    KubernetesMachineImpl machine1 = new KubernetesMachineImpl(WORKSPACE_ID, "machine1", "pod1", "container 1", null, emptyMap(), emptyMap());
    KubernetesMachineImpl machine2 = new KubernetesMachineImpl(WORKSPACE_ID, "machine2", "pod1", "container 2", null, emptyMap(), emptyMap());
    KubernetesMachineImpl machine3 = new KubernetesMachineImpl(WORKSPACE_ID, "machine3", "pod2", "container 1", null, emptyMap(), emptyMap());
    machinesCache.put(IDENTITY, machine1);
    machinesCache.put(IDENTITY, machine2);
    machinesCache.put(IDENTITY, machine3);
    doReturn(Optional.empty()).when(deployments).get(anyString());
    // when
    boolean isConsistent = internalRuntime.isConsistent();
    // then
    assertFalse(isConsistent);
}
Also used : KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) Test(org.testng.annotations.Test)

Example 18 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project che-server by eclipse-che.

the class KubernetesInternalRuntimeTest method shouldReturnTrueIfAllPodsExistOnRuntimeConsistencyChecking.

@Test
public void shouldReturnTrueIfAllPodsExistOnRuntimeConsistencyChecking() throws Exception {
    // given
    KubernetesMachineImpl machine1 = new KubernetesMachineImpl(WORKSPACE_ID, "machine1", "pod1", "container 1", null, emptyMap(), emptyMap());
    KubernetesMachineImpl machine2 = new KubernetesMachineImpl(WORKSPACE_ID, "machine2", "pod1", "container 2", null, emptyMap(), emptyMap());
    KubernetesMachineImpl machine3 = new KubernetesMachineImpl(WORKSPACE_ID, "machine3", "pod2", "container 1", null, emptyMap(), emptyMap());
    machinesCache.put(IDENTITY, machine1);
    machinesCache.put(IDENTITY, machine2);
    machinesCache.put(IDENTITY, machine3);
    doReturn(Optional.of(mock(Pod.class))).when(deployments).get(anyString());
    // when
    boolean isConsistent = internalRuntime.isConsistent();
    // then
    assertTrue(isConsistent);
}
Also used : KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) Test(org.testng.annotations.Test)

Example 19 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project che-server by eclipse-che.

the class JpaTckModule method configure.

@Override
protected void configure() {
    H2DBTestServer server = H2DBTestServer.startDefault();
    install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(WorkspaceImpl.class, WorkspaceConfigImpl.class, ProjectConfigImpl.class, SourceStorageImpl.class, EnvironmentImpl.class, MachineConfigImpl.class, ServerConfigImpl.class, VolumeImpl.class, CommandImpl.class, AccountImpl.class, KubernetesRuntimeState.class, KubernetesRuntimeCommandImpl.class, KubernetesMachineImpl.class, MachineId.class, KubernetesServerImpl.class, ServerId.class, // devfile
    ActionImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class, ComponentImpl.class, DevfileImpl.class, EndpointImpl.class, EntrypointImpl.class, EnvImpl.class, ProjectImpl.class, SourceImpl.class, org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class).addEntityClass("org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute").addClass(SerializableConverter.class).setExceptionHandler(H2ExceptionHandler.class).build());
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {
    }).toInstance(new JpaTckRepository<>(WorkspaceImpl.class));
    bind(new TypeLiteral<TckRepository<KubernetesRuntimeState>>() {
    }).toInstance(new JpaTckRepository<>(KubernetesRuntimeState.class));
    bind(new TypeLiteral<TckRepository<KubernetesMachineImpl>>() {
    }).toInstance(new JpaTckRepository<>(KubernetesMachineImpl.class));
    bind(KubernetesRuntimeStateCache.class).to(JpaKubernetesRuntimeStateCache.class);
    bind(KubernetesMachineCache.class).to(JpaKubernetesMachineCache.class);
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
    bind(DBInitializer.class).asEagerSingleton();
    bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) MachineId(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl.MachineId) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) KubernetesServerImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesServerImpl) KubernetesRuntimeCommandImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeCommandImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(org.h2.Driver) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ComponentImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) KubernetesRuntimeState(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState) ServerId(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesServerImpl.ServerId) TypeLiteral(com.google.inject.TypeLiteral) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) DBInitializer(org.eclipse.che.core.db.DBInitializer) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) KubernetesMachineCache(org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesMachineCache) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) KubernetesRuntimeCommandImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeCommandImpl) EntrypointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EntrypointImpl) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) ProjectImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ProjectImpl) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) EnvImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EnvImpl) KubernetesRuntimeStateCache(org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesRuntimeStateCache) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SerializableConverter(org.eclipse.che.api.workspace.server.devfile.SerializableConverter) MachineConfigImpl(org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl) SourceImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.SourceImpl) VolumeImpl(org.eclipse.che.api.workspace.server.model.impl.VolumeImpl) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 20 with KubernetesMachineImpl

use of org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl in project che-server by eclipse-che.

the class KubernetesMachinesCacheTest method shouldThrowExceptionWhenServerWasNotFoundOnStatusUpdating.

@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Server with name 'non-existing' was not found")
public void shouldThrowExceptionWhenServerWasNotFoundOnStatusUpdating() throws Exception {
    // given
    RuntimeIdentity runtimeId = runtimeStates[0].getRuntimeId();
    KubernetesMachineImpl machine = machines[0];
    // when
    machineCache.updateServerStatus(runtimeId, machine.getName(), "non-existing", ServerStatus.RUNNING);
}
Also used : RuntimeIdentity(org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity) KubernetesMachineImpl(org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl) Test(org.testng.annotations.Test)

Aggregations

KubernetesMachineImpl (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesMachineImpl)38 Test (org.testng.annotations.Test)20 RuntimeIdentity (org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity)12 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)8 KubernetesMachineCache (org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesMachineCache)8 KubernetesRuntimeStateCache (org.eclipse.che.workspace.infrastructure.kubernetes.cache.KubernetesRuntimeStateCache)8 KubernetesRuntimeState (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesRuntimeState)8 KubernetesServerImpl (org.eclipse.che.workspace.infrastructure.kubernetes.model.KubernetesServerImpl)8 TypeLiteral (com.google.inject.TypeLiteral)6 AccountImpl (org.eclipse.che.account.spi.AccountImpl)6 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 InternalInfrastructureException (org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException)6 PersistTestModuleBuilder (org.eclipse.che.commons.test.db.PersistTestModuleBuilder)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)6 DBInitializer (org.eclipse.che.core.db.DBInitializer)6 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)6 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)6 AccountDao (org.eclipse.che.account.spi.AccountDao)3 JpaAccountDao (org.eclipse.che.account.spi.jpa.JpaAccountDao)3 JpaUserDevfileDao (org.eclipse.che.api.devfile.server.jpa.JpaUserDevfileDao)3