Search in sources :

Example 6 with Workspace

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

the class WorkspaceRuntimes method snapshotAndUpdateStatus.

/** Creates a snapshot and changes status SNAPSHOTTING -> RUNNING. */
private void snapshotAndUpdateStatus(String workspaceId) throws NotFoundException, ConflictException, ServerException {
    eventsService.publish(DtoFactory.newDto(WorkspaceStatusEvent.class).withWorkspaceId(workspaceId).withStatus(WorkspaceStatus.SNAPSHOTTING).withEventType(EventType.SNAPSHOT_CREATING).withPrevStatus(WorkspaceStatus.RUNNING));
    WorkspaceRuntimeImpl runtime = getRuntime(workspaceId);
    List<MachineImpl> machines = runtime.getMachines();
    machines.sort(comparing(m -> !m.getConfig().isDev(), Boolean::compare));
    LOG.info("Creating snapshot of workspace '{}', machines to snapshot: '{}'", workspaceId, machines.size());
    List<SnapshotImpl> newSnapshots = new ArrayList<>(machines.size());
    for (MachineImpl machine : machines) {
        try {
            newSnapshots.add(envEngine.saveSnapshot(workspaceId, machine.getId()));
        } catch (ServerException | NotFoundException x) {
            if (machine.getConfig().isDev()) {
                compareAndSetStatus(workspaceId, WorkspaceStatus.SNAPSHOTTING, WorkspaceStatus.RUNNING);
                eventsService.publish(DtoFactory.newDto(WorkspaceStatusEvent.class).withWorkspaceId(workspaceId).withStatus(WorkspaceStatus.RUNNING).withEventType(EventType.SNAPSHOT_CREATION_ERROR).withPrevStatus(WorkspaceStatus.SNAPSHOTTING).withError(x.getMessage()));
                throw x;
            }
            LOG.warn(format("Couldn't create snapshot of machine '%s:%s' in workspace '%s'", machine.getEnvName(), machine.getConfig().getName(), workspaceId));
        }
    }
    LOG.info("Saving new snapshots metadata, workspace id '{}'", workspaceId);
    try {
        List<SnapshotImpl> removed = snapshotDao.replaceSnapshots(workspaceId, runtime.getActiveEnv(), newSnapshots);
        if (!removed.isEmpty()) {
            LOG.info("Removing old snapshots binaries, workspace id '{}', snapshots to remove '{}'", workspaceId, removed.size());
            removeBinaries(removed);
        }
    } catch (SnapshotException x) {
        LOG.error(format("Couldn't remove existing snapshots metadata for workspace '%s'", workspaceId), x);
        LOG.info("Removing newly created snapshots, workspace id '{}', snapshots to remove '{}'", workspaceId, newSnapshots.size());
        removeBinaries(newSnapshots);
        compareAndSetStatus(workspaceId, WorkspaceStatus.SNAPSHOTTING, WorkspaceStatus.RUNNING);
        eventsService.publish(DtoFactory.newDto(WorkspaceStatusEvent.class).withWorkspaceId(workspaceId).withStatus(WorkspaceStatus.RUNNING).withEventType(EventType.SNAPSHOT_CREATION_ERROR).withPrevStatus(WorkspaceStatus.SNAPSHOTTING).withError(x.getMessage()));
        throw x;
    }
    compareAndSetStatus(workspaceId, WorkspaceStatus.SNAPSHOTTING, WorkspaceStatus.RUNNING);
    eventsService.publish(DtoFactory.newDto(WorkspaceStatusEvent.class).withStatus(WorkspaceStatus.RUNNING).withWorkspaceId(workspaceId).withEventType(EventType.SNAPSHOT_CREATED).withPrevStatus(WorkspaceStatus.SNAPSHOTTING));
}
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) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) ServerException(org.eclipse.che.api.core.ServerException) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) WorkspaceStatusEvent(org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent) ArrayList(java.util.ArrayList) NotFoundException(org.eclipse.che.api.core.NotFoundException) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) SnapshotException(org.eclipse.che.api.machine.server.exception.SnapshotException)

Example 7 with Workspace

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

the class GdbConfigurationPagePresenter method getMachines.

private List<Machine> getMachines() {
    Workspace workspace = appContext.getWorkspace();
    if (workspace == null || workspace.getRuntime() == null) {
        return emptyList();
    }
    List<? extends Machine> runtimeMachines = workspace.getRuntime().getMachines();
    List<Machine> machines = new ArrayList<>(runtimeMachines.size());
    for (Machine currentMachine : runtimeMachines) {
        if (currentMachine instanceof MachineDto) {
            Machine machine = entityFactory.createMachine((MachineDto) currentMachine);
            machines.add(machine);
        }
    }
    return machines;
}
Also used : MachineDto(org.eclipse.che.api.machine.shared.dto.MachineDto) ArrayList(java.util.ArrayList) Machine(org.eclipse.che.api.core.model.machine.Machine) Workspace(org.eclipse.che.api.core.model.workspace.Workspace)

Example 8 with Workspace

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

the class ProcessesPanelPresenter method hasAgent.

/**
     * Determines the agent is injected in the specified machine.
     *
     * @param machineName
     *          machine name
     * @param agent
     *          agent
     * @return
     *          <b>true</b> is the agent is injected, otherwise return <b>false</b>
     */
private boolean hasAgent(String machineName, String agent) {
    Workspace workspace = appContext.getWorkspace();
    if (workspace == null) {
        return false;
    }
    WorkspaceConfig workspaceConfig = workspace.getConfig();
    if (workspaceConfig == null) {
        return false;
    }
    Map<String, ? extends Environment> environments = workspaceConfig.getEnvironments();
    if (environments == null) {
        return false;
    }
    for (Environment environment : environments.values()) {
        ExtendedMachine extendedMachine = environment.getMachines().get(machineName);
        if (extendedMachine != null) {
            if (extendedMachine.getAgents() != null && extendedMachine.getAgents().contains(agent)) {
                return true;
            }
        }
    }
    return false;
}
Also used : WorkspaceConfig(org.eclipse.che.api.core.model.workspace.WorkspaceConfig) Environment(org.eclipse.che.api.core.model.workspace.Environment) ExtendedMachine(org.eclipse.che.api.core.model.workspace.ExtendedMachine) Workspace(org.eclipse.che.api.core.model.workspace.Workspace)

Example 9 with Workspace

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

the class PostgreSqlTckModule method configure.

@Override
protected void configure() {
    final String dbUrl = System.getProperty("jdbc.url");
    final String dbUser = System.getProperty("jdbc.user");
    final String dbPassword = System.getProperty("jdbc.password");
    waitConnectionIsEstablished(dbUrl, dbUser, dbPassword);
    // jpa
    install(new PersistTestModuleBuilder().setDriver(Driver.class).setUrl(dbUrl).setUser(dbUser).setPassword(dbPassword).setExceptionHandler(PostgreSqlExceptionHandler.class).addEntityClasses(AccountImpl.class, UserImpl.class, ProfileImpl.class, PreferenceEntity.class, WorkspaceImpl.class, WorkspaceConfigImpl.class, ProjectConfigImpl.class, EnvironmentImpl.class, EnvironmentRecipeImpl.class, ExtendedMachineImpl.class, SourceStorageImpl.class, ServerConf2Impl.class, StackImpl.class, CommandImpl.class, SnapshotImpl.class, RecipeImpl.class, SshPairImpl.class).addEntityClass("org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute").build());
    bind(TckResourcesCleaner.class).to(JpaCleaner.class);
    // db initialization
    bind(DBInitializer.class).asEagerSingleton();
    final PGSimpleDataSource dataSource = new PGSimpleDataSource();
    dataSource.setUser(dbUser);
    dataSource.setPassword(dbPassword);
    dataSource.setUrl(dbUrl);
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(dataSource, "che-schema"));
    // account
    bind(AccountDao.class).to(JpaAccountDao.class);
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    // user
    bind(UserDao.class).to(JpaUserDao.class);
    bind(ProfileDao.class).to(JpaProfileDao.class);
    bind(PreferenceDao.class).to(JpaPreferenceDao.class);
    bind(new TypeLiteral<TckRepository<UserImpl>>() {
    }).to(UserRepo.class);
    bind(new TypeLiteral<TckRepository<Pair<String, Map<String, String>>>>() {
    }).to(PreferencesRepo.class);
    bind(new TypeLiteral<TckRepository<ProfileImpl>>() {
    }).toInstance(new JpaTckRepository<>(ProfileImpl.class));
    bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class);
    // machine
    bind(RecipeDao.class).to(JpaRecipeDao.class);
    bind(SnapshotDao.class).to(JpaSnapshotDao.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 WorkspaceRepoForSnapshots());
    // ssh
    bind(SshDao.class).to(JpaSshDao.class);
    bind(new TypeLiteral<TckRepository<SshPairImpl>>() {
    }).toInstance(new JpaTckRepository<>(SshPairImpl.class));
    // workspace
    bind(WorkspaceDao.class).to(JpaWorkspaceDao.class);
    bind(StackDao.class).to(JpaStackDao.class);
    bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {
    }).toInstance(new WorkspaceRepository());
    bind(new TypeLiteral<TckRepository<StackImpl>>() {
    }).toInstance(new StackRepository());
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) PreferenceEntity(org.eclipse.che.api.user.server.jpa.PreferenceEntity) AccountImpl(org.eclipse.che.account.spi.AccountImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) 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) JpaProfileDao(org.eclipse.che.api.user.server.jpa.JpaProfileDao) ProfileDao(org.eclipse.che.api.user.server.spi.ProfileDao) JpaSnapshotDao(org.eclipse.che.api.machine.server.jpa.JpaSnapshotDao) SnapshotDao(org.eclipse.che.api.machine.server.spi.SnapshotDao) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) TypeLiteral(com.google.inject.TypeLiteral) UserDao(org.eclipse.che.api.user.server.spi.UserDao) JpaUserDao(org.eclipse.che.api.user.server.jpa.JpaUserDao) DBInitializer(org.eclipse.che.core.db.DBInitializer) JpaRecipeDao(org.eclipse.che.api.machine.server.jpa.JpaRecipeDao) RecipeDao(org.eclipse.che.api.machine.server.spi.RecipeDao) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) PGSimpleDataSource(org.postgresql.ds.PGSimpleDataSource) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) Pair(org.eclipse.che.commons.lang.Pair) CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) PasswordEncryptor(org.eclipse.che.security.PasswordEncryptor) SHA512PasswordEncryptor(org.eclipse.che.security.SHA512PasswordEncryptor) AccountDao(org.eclipse.che.account.spi.AccountDao) JpaAccountDao(org.eclipse.che.account.spi.jpa.JpaAccountDao) JpaPreferenceDao(org.eclipse.che.api.user.server.jpa.JpaPreferenceDao) PreferenceDao(org.eclipse.che.api.user.server.spi.PreferenceDao) SshDao(org.eclipse.che.api.ssh.server.spi.SshDao) JpaSshDao(org.eclipse.che.api.ssh.server.jpa.JpaSshDao) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) JpaStackDao(org.eclipse.che.api.workspace.server.jpa.JpaStackDao) StackDao(org.eclipse.che.api.workspace.server.spi.StackDao) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) JpaWorkspaceDao(org.eclipse.che.api.workspace.server.jpa.JpaWorkspaceDao) WorkspaceDao(org.eclipse.che.api.workspace.server.spi.WorkspaceDao) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) 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