DockerEnvironmentBackupManager implements EnvironmentBackupManager { public void restoreWorkspaceBackup(String workspaceId, String containerId, String nodeHost) throws ServerException, EnvironmentException { try { String srcPath = workspaceIdHashLocationFinder.calculateDirPath(backupsRootDir, workspaceId).toString(); User user = getUserInfo(workspaceId, containerId); int syncPort = getSyncPort(containerId); restoreBackupInsideLock( workspaceId, srcPath, projectFolderPath, user.id, user.groupId, user.name, nodeHost, syncPort); } catch (IOException e) { LOG.error(e.getLocalizedMessage(), e); throw new ServerException( format( "Can't restore file system of workspace %s in container %s", workspaceId, containerId)); } } @Inject  DockerEnvironmentBackupManager(
      @Named("machine.backup.backup_script") String backupScript,
      @Named("machine.backup.restore_script") String restoreScript,
      @Named("machine.backup.backup_duration_second") int maxBackupDurationSec,
      @Named("machine.backup.restore_duration_second") int restoreDurationSec,
      @Named("che.user.workspaces.storage") File backupsRootDir,
      WorkspaceIdHashLocationFinder workspaceIdHashLocationFinder,
      @Named("che.workspace.projects.storage") String projectFolderPath,
      WorkspaceManager workspaceManager,
      DockerConnector dockerConnector); @Override void backupWorkspace(String workspaceId); void backupWorkspaceAndCleanup(String workspaceId, String containerId, String nodeHost); void restoreWorkspaceBackup(String workspaceId, String containerId, String nodeHost);  }
@Test( expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Sync port is not exposed in ws-machine. Workspace projects syncing is not possible" ) public void restoreShouldThrowErrorIfSshPortIsNotPublishedInContainer() throws Exception { NetworkSettings networkSettings = new NetworkSettings(); networkSettings.setPorts( singletonMap("23/tcp", singletonList(new PortBinding().withHostPort(PUBLISHED_SSH_PORT)))); ContainerInfo containerInfo = new ContainerInfo(); containerInfo.setNetworkSettings(networkSettings); ContainerState containerState = new ContainerState(); containerState.setRunning(true); containerInfo.setState(containerState); when(docker.inspectContainer(eq(CONTAINER_ID))).thenReturn(containerInfo); backupManager.restoreWorkspaceBackup(WORKSPACE_ID, CONTAINER_ID, NODE_HOST); }
@Test( expectedExceptions = EnvironmentException.class, expectedExceptionsMessageRegExp = "Container " + CONTAINER_ID + " unexpectedly exited" ) public void restoreShouldThrowEnvironmentErrorIfContainerIsNoLongerRunning() throws Exception { NetworkSettings networkSettings = new NetworkSettings(); networkSettings.setPorts( singletonMap("22/tcp", singletonList(new PortBinding().withHostPort(PUBLISHED_SSH_PORT)))); ContainerInfo containerInfo = new ContainerInfo(); containerInfo.setNetworkSettings(networkSettings); ContainerState containerState = new ContainerState(); containerState.setRunning(false); containerInfo.setState(containerState); when(docker.inspectContainer(eq(CONTAINER_ID))).thenReturn(containerInfo); backupManager.restoreWorkspaceBackup(WORKSPACE_ID, CONTAINER_ID, NODE_HOST); }