Search in sources :

Example 1 with Workspace

use of org.eclipse.che.api.core.model.workspace.Workspace in project che by eclipse.

the class AbstractPerspectiveAction method update.

/** {@inheritDoc} */
@Override
public final void update(@NotNull ActionEvent event) {
    PerspectiveManager manager = event.getPerspectiveManager();
    Presentation presentation = event.getPresentation();
    boolean isWorkspaceRunning = false;
    if (appContext != null) {
        Workspace workspace = appContext.getWorkspace();
        isWorkspaceRunning = workspace != null && WorkspaceStatus.RUNNING.equals(workspace.getStatus());
    }
    boolean inPerspective = perspectives == null || perspectives.isEmpty() ? true : perspectives.contains(manager.getPerspectiveId());
    presentation.setEnabledAndVisible(inPerspective && isWorkspaceRunning);
    if (inPerspective && isWorkspaceRunning) {
        updateInPerspective(event);
    }
}
Also used : PerspectiveManager(org.eclipse.che.ide.api.parts.PerspectiveManager) Workspace(org.eclipse.che.api.core.model.workspace.Workspace)

Example 2 with Workspace

use of org.eclipse.che.api.core.model.workspace.Workspace in project che by eclipse.

the class LocalWorkspaceFolderPathProvider method getPath.

@Override
public String getPath(@Assisted("workspace") String workspaceId) throws IOException {
    if (!isWindows && hostProjectsFolder != null) {
        return hostProjectsFolder;
    }
    try {
        WorkspaceManager workspaceManager = this.workspaceManager.get();
        Workspace workspace = workspaceManager.getWorkspace(workspaceId);
        String wsName = workspace.getConfig().getName();
        return doGetPathByName(wsName);
    } catch (NotFoundException | ServerException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException) Workspace(org.eclipse.che.api.core.model.workspace.Workspace)

Example 3 with Workspace

use of org.eclipse.che.api.core.model.workspace.Workspace in project che by eclipse.

the class WorkspaceManagerTest method snapshottedAtAttributeIncludedToWorkspaceWhenStartingById.

@Test
public void snapshottedAtAttributeIncludedToWorkspaceWhenStartingById() throws Exception {
    WorkspaceImpl workspace = createAndMockWorkspace();
    mockSnapshots(workspace, 12345);
    mockStart(workspace);
    Workspace result = workspaceManager.startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), false);
    assertEquals(result.getAttributes().get(SNAPSHOTTED_AT_ATTRIBUTE_NAME), "12345");
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Workspace(org.eclipse.che.api.core.model.workspace.Workspace) Test(org.testng.annotations.Test)

Example 4 with Workspace

use of org.eclipse.che.api.core.model.workspace.Workspace in project che by eclipse.

the class WorkspaceRuntimes method shutdown.

/**
     * Terminates workspace runtimes service, so no more workspaces are allowed to start
     * or to be stopped directly, all the running workspaces are going to be stopped,
     * all the starting tasks will be eventually interrupted.
     *
     * @throws IllegalStateException
     *         if component shutdown is already called
     */
public void shutdown() throws InterruptedException {
    if (!isShutdown.compareAndSet(false, true)) {
        throw new IllegalStateException("Workspace runtimes service shutdown has been already called");
    }
    List<String> idsToStop;
    try (@SuppressWarnings("unused") Unlocker u = locks.writeAllLock()) {
        idsToStop = states.entrySet().stream().filter(e -> e.getValue().status != WorkspaceStatus.STOPPING).map(Map.Entry::getKey).collect(Collectors.toList());
        states.clear();
    }
    if (!idsToStop.isEmpty()) {
        LOG.info("Shutdown running environments, environments to stop: '{}'", idsToStop.size());
        ExecutorService executor = Executors.newFixedThreadPool(2 * Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder().setNameFormat("StopEnvironmentsPool-%d").setDaemon(false).build());
        for (String id : idsToStop) {
            executor.execute(() -> {
                try {
                    envEngine.stop(id);
                } catch (EnvironmentNotRunningException ignored) {
                // might be already stopped
                } catch (Exception x) {
                    LOG.error(x.getMessage(), x);
                }
            });
        }
        executor.shutdown();
        try {
            if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {
                executor.shutdownNow();
                if (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
                    LOG.error("Unable to stop runtimes termination pool");
                }
            }
        } catch (InterruptedException e) {
            executor.shutdownNow();
            Thread.currentThread().interrupt();
        }
    }
}
Also used : ENVIRONMENT_OUTPUT_CHANNEL_TEMPLATE(org.eclipse.che.api.machine.shared.Constants.ENVIRONMENT_OUTPUT_CHANNEL_TEMPLATE) AgentLauncher(org.eclipse.che.api.agent.server.launcher.AgentLauncher) Agent(org.eclipse.che.api.agent.shared.model.Agent) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) StripedLocks(org.eclipse.che.commons.lang.concurrent.StripedLocks) AgentException(org.eclipse.che.api.agent.server.exception.AgentException) RUNNING(org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) Future(java.util.concurrent.Future) WorkspaceStatusEvent(org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) Map(java.util.Map) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) EventService(org.eclipse.che.api.core.notification.EventService) CancellationException(java.util.concurrent.CancellationException) MachineConfig(org.eclipse.che.api.core.model.machine.MachineConfig) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) Nullable(org.eclipse.che.commons.annotation.Nullable) Executors(java.util.concurrent.Executors) String.format(java.lang.String.format) CountDownLatch(java.util.concurrent.CountDownLatch) STARTING(org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STARTING) EnvironmentException(org.eclipse.che.api.environment.server.exception.EnvironmentException) List(java.util.List) Environment(org.eclipse.che.api.core.model.workspace.Environment) CheEnvironmentEngine(org.eclipse.che.api.environment.server.CheEnvironmentEngine) AgentKey(org.eclipse.che.api.agent.shared.model.AgentKey) EventType(org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent.EventType) AgentLauncherFactory(org.eclipse.che.api.agent.server.launcher.AgentLauncherFactory) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) AgentRegistry(org.eclipse.che.api.agent.server.AgentRegistry) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Workspace(org.eclipse.che.api.core.model.workspace.Workspace) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) CompletableFuture(java.util.concurrent.CompletableFuture) Singleton(javax.inject.Singleton) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) HashSet(java.util.HashSet) WebsocketMessageConsumer(org.eclipse.che.api.core.util.WebsocketMessageConsumer) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Objects.requireNonNull(java.util.Objects.requireNonNull) ConflictException(org.eclipse.che.api.core.ConflictException) Comparator.comparing(java.util.Comparator.comparing) Instance(org.eclipse.che.api.machine.server.spi.Instance) SnapshotDao(org.eclipse.che.api.machine.server.spi.SnapshotDao) DtoFactory(org.eclipse.che.dto.server.DtoFactory) ExecutorService(java.util.concurrent.ExecutorService) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) Logger(org.slf4j.Logger) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) SNAPSHOTTING(org.eclipse.che.api.core.model.workspace.WorkspaceStatus.SNAPSHOTTING) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) NotFoundException(org.eclipse.che.api.core.NotFoundException) TimeUnit(java.util.concurrent.TimeUnit) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) AgentSorter(org.eclipse.che.api.agent.server.impl.AgentSorter) ServerException(org.eclipse.che.api.core.ServerException) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MachineStartedHandler(org.eclipse.che.api.environment.server.MachineStartedHandler) Collections(java.util.Collections) Unlocker(org.eclipse.che.commons.lang.concurrent.Unlocker) ExecutorService(java.util.concurrent.ExecutorService) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) AgentException(org.eclipse.che.api.agent.server.exception.AgentException) EnvironmentStartInterruptedException(org.eclipse.che.api.environment.server.exception.EnvironmentStartInterruptedException) EnvironmentNotRunningException(org.eclipse.che.api.environment.server.exception.EnvironmentNotRunningException) CancellationException(java.util.concurrent.CancellationException) EnvironmentException(org.eclipse.che.api.environment.server.exception.EnvironmentException) ConflictException(org.eclipse.che.api.core.ConflictException) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) NotFoundException(org.eclipse.che.api.core.NotFoundException) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException) ServerException(org.eclipse.che.api.core.ServerException)

Example 5 with Workspace

use of org.eclipse.che.api.core.model.workspace.Workspace in project che by eclipse.

the class JpaTckModule method configure.

@Override
protected void configure() {
    install(new JpaPersistModule("main"));
    bind(DBInitializer.class).asEagerSingleton();
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(H2TestHelper.inMemoryDefault(), "che-schema"));
    bind(TckResourcesCleaner.class).to(H2JpaCleaner.class);
    bind(new TypeLiteral<TckRepository<RecipeImpl>>() {
    }).toInstance(new JpaTckRepository<>(RecipeImpl.class));
    bind(new TypeLiteral<TckRepository<SnapshotImpl>>() {
    }).toInstance(new JpaTckRepository<>(SnapshotImpl.class));
    bind(new TypeLiteral<TckRepository<Workspace>>() {
    }).toInstance(new TestWorkspacesTckRepository());
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    bind(RecipeDao.class).to(JpaRecipeDao.class);
    bind(SnapshotDao.class).to(JpaSnapshotDao.class);
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) 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) SnapshotDao(org.eclipse.che.api.machine.server.spi.SnapshotDao) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) RecipeDao(org.eclipse.che.api.machine.server.spi.RecipeDao) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) Workspace(org.eclipse.che.api.core.model.workspace.Workspace)

Aggregations

Workspace (org.eclipse.che.api.core.model.workspace.Workspace)9 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)4 SnapshotDao (org.eclipse.che.api.machine.server.spi.SnapshotDao)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 ArrayList (java.util.ArrayList)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)2 TypeLiteral (com.google.inject.TypeLiteral)2 String.format (java.lang.String.format)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator.comparing (java.util.Comparator.comparing)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Set (java.util.Set)2 Callable (java.util.concurrent.Callable)2 CancellationException (java.util.concurrent.CancellationException)2 CompletableFuture (java.util.concurrent.CompletableFuture)2