@Test public void shouldBackupMachineFsIfLastSyncTimeoutIsExpired() throws Exception { ids.clear(); addWorkspace("ws3"); scheduler = spy( new WorkspaceFsBackupScheduler( Collections.singletonMap(ENV_TYPE, backupManager), workspaceRuntimes, 0, workspaceManager)); scheduler.scheduleBackup(); verify(backupManager, timeout(1000)).backupWorkspace(eq("ws3")); Thread.sleep(100); scheduler.scheduleBackup(); verify(workspaceRuntimes, times(2)).getRuntimesIds(); verify(backupManager, timeout(2000).times(2)).backupWorkspace(eq("ws3")); }
@ScheduleRate(initialDelay = 1, period = 1, unit = TimeUnit.MINUTES) public void scheduleBackup() { for (String workspaceId : workspaceRuntimes.getRuntimesIds()) { try { WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId); WorkspaceRuntimeImpl runtime = workspace.getRuntime(); if (workspace.getStatus().equals(WorkspaceStatus.RUNNING)) { if (isTimeToBackup(workspaceId)) { executor.execute( () -> { if (workspacesBackupsInProgress.putIfAbsent(workspaceId, workspaceId) == null) { try { String environmentType = workspace .getConfig() .getEnvironments() .get(runtime.getActiveEnv()) .getRecipe() .getType(); EnvironmentBackupManager backupManager = backupManagers.get(environmentType); if (backupManager == null) { throw new ServerException( "Backing up of environment of type " + environmentType + " is not implemented."); } backupManager.backupWorkspace(workspaceId); lastWorkspaceSynchronizationTime.put(workspaceId, System.currentTimeMillis()); } catch (NotFoundException ignore) { } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } finally { workspacesBackupsInProgress.remove(workspaceId); } } }); } } } catch (NotFoundException e) { } catch (ServerException e) { LOG.error(e.getLocalizedMessage(), e); } } }
WorkspaceFsBackupScheduler { @ScheduleRate(initialDelay = 1, period = 1, unit = TimeUnit.MINUTES) public void scheduleBackup() { for (String workspaceId : workspaceRuntimes.getRuntimesIds()) { try { WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId); WorkspaceRuntimeImpl runtime = workspace.getRuntime(); if (workspace.getStatus().equals(WorkspaceStatus.RUNNING)) { if (isTimeToBackup(workspaceId)) { executor.execute( () -> { if (workspacesBackupsInProgress.putIfAbsent(workspaceId, workspaceId) == null) { try { String environmentType = workspace .getConfig() .getEnvironments() .get(runtime.getActiveEnv()) .getRecipe() .getType(); EnvironmentBackupManager backupManager = backupManagers.get(environmentType); if (backupManager == null) { throw new ServerException( "Backing up of environment of type " + environmentType + " is not implemented."); } backupManager.backupWorkspace(workspaceId); lastWorkspaceSynchronizationTime.put(workspaceId, System.currentTimeMillis()); } catch (NotFoundException ignore) { } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } finally { workspacesBackupsInProgress.remove(workspaceId); } } }); } } } catch (NotFoundException e) { } catch (ServerException e) { LOG.error(e.getLocalizedMessage(), e); } } } }
WorkspaceFsBackupScheduler { @ScheduleRate(initialDelay = 1, period = 1, unit = TimeUnit.MINUTES) public void scheduleBackup() { for (String workspaceId : workspaceRuntimes.getRuntimesIds()) { try { WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId); WorkspaceRuntimeImpl runtime = workspace.getRuntime(); if (workspace.getStatus().equals(WorkspaceStatus.RUNNING)) { if (isTimeToBackup(workspaceId)) { executor.execute( () -> { if (workspacesBackupsInProgress.putIfAbsent(workspaceId, workspaceId) == null) { try { String environmentType = workspace .getConfig() .getEnvironments() .get(runtime.getActiveEnv()) .getRecipe() .getType(); EnvironmentBackupManager backupManager = backupManagers.get(environmentType); if (backupManager == null) { throw new ServerException( "Backing up of environment of type " + environmentType + " is not implemented."); } backupManager.backupWorkspace(workspaceId); lastWorkspaceSynchronizationTime.put(workspaceId, System.currentTimeMillis()); } catch (NotFoundException ignore) { } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } finally { workspacesBackupsInProgress.remove(workspaceId); } } }); } } } catch (NotFoundException e) { } catch (ServerException e) { LOG.error(e.getLocalizedMessage(), e); } } } @Inject  WorkspaceFsBackupScheduler(
      Map<String, EnvironmentBackupManager> backupManagers,
      WorkspaceRuntimes workspaceRuntimes,
      @Named("machine.backup.backup_period_second") long syncTimeoutSecond,
      WorkspaceManager workspaceManager); }
WorkspaceFsBackupScheduler { @ScheduleRate(initialDelay = 1, period = 1, unit = TimeUnit.MINUTES) public void scheduleBackup() { for (String workspaceId : workspaceRuntimes.getRuntimesIds()) { try { WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId); WorkspaceRuntimeImpl runtime = workspace.getRuntime(); if (workspace.getStatus().equals(WorkspaceStatus.RUNNING)) { if (isTimeToBackup(workspaceId)) { executor.execute( () -> { if (workspacesBackupsInProgress.putIfAbsent(workspaceId, workspaceId) == null) { try { String environmentType = workspace .getConfig() .getEnvironments() .get(runtime.getActiveEnv()) .getRecipe() .getType(); EnvironmentBackupManager backupManager = backupManagers.get(environmentType); if (backupManager == null) { throw new ServerException( "Backing up of environment of type " + environmentType + " is not implemented."); } backupManager.backupWorkspace(workspaceId); lastWorkspaceSynchronizationTime.put(workspaceId, System.currentTimeMillis()); } catch (NotFoundException ignore) { } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } finally { workspacesBackupsInProgress.remove(workspaceId); } } }); } } } catch (NotFoundException e) { } catch (ServerException e) { LOG.error(e.getLocalizedMessage(), e); } } } @Inject  WorkspaceFsBackupScheduler(
      Map<String, EnvironmentBackupManager> backupManagers,
      WorkspaceRuntimes workspaceRuntimes,
      @Named("machine.backup.backup_period_second") long syncTimeoutSecond,
      WorkspaceManager workspaceManager); @ScheduleRate(initialDelay = 1, period = 1, unit = TimeUnit.MINUTES) void scheduleBackup(); }
WorkspaceFsBackupScheduler { @ScheduleRate(initialDelay = 1, period = 1, unit = TimeUnit.MINUTES) public void scheduleBackup() { for (String workspaceId : workspaceRuntimes.getRuntimesIds()) { try { WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId); WorkspaceRuntimeImpl runtime = workspace.getRuntime(); if (workspace.getStatus().equals(WorkspaceStatus.RUNNING)) { if (isTimeToBackup(workspaceId)) { executor.execute( () -> { if (workspacesBackupsInProgress.putIfAbsent(workspaceId, workspaceId) == null) { try { String environmentType = workspace .getConfig() .getEnvironments() .get(runtime.getActiveEnv()) .getRecipe() .getType(); EnvironmentBackupManager backupManager = backupManagers.get(environmentType); if (backupManager == null) { throw new ServerException( "Backing up of environment of type " + environmentType + " is not implemented."); } backupManager.backupWorkspace(workspaceId); lastWorkspaceSynchronizationTime.put(workspaceId, System.currentTimeMillis()); } catch (NotFoundException ignore) { } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } finally { workspacesBackupsInProgress.remove(workspaceId); } } }); } } } catch (NotFoundException e) { } catch (ServerException e) { LOG.error(e.getLocalizedMessage(), e); } } } @Inject  WorkspaceFsBackupScheduler(
      Map<String, EnvironmentBackupManager> backupManagers,
      WorkspaceRuntimes workspaceRuntimes,
      @Named("machine.backup.backup_period_second") long syncTimeoutSecond,
      WorkspaceManager workspaceManager); @ScheduleRate(initialDelay = 1, period = 1, unit = TimeUnit.MINUTES) void scheduleBackup();  }