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));
}
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;
}
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;
}
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());
}
Aggregations