String workspace = null;
try
{
BackupChainLog backupChainLog = new BackupChainLog(backuplog);
repository = backupChainLog.getBackupConfig().getRepository();
workspace = backupChainLog.getBackupConfig().getWorkspace();
validateOneRestoreInstants(repository, workspace);
validateRepositoryName(repository);
if (removeExisting)
{
if (!isWorkspaceExist(repository, workspace))
{
throw new WorkspaceRestoreException("Workspace " + workspace + " is not exists!");
}
backupManager.restoreExistingWorkspace(backupSetDir, true);
}
else
{
if (isWorkspaceExist(repository, workspace))
{
throw new Exception("Workspace " + workspace + " already exists!");
}
backupManager.restoreWorkspace(backupSetDir, true);
}
/*
* Sleeping
* Restore must be initialized by job thread
*/
Thread.sleep(100);
/*
* search necessary restore
*/
List<JobWorkspaceRestore> restoreJobs = backupManager.getRestores();
JobWorkspaceRestore restore = null;
for (JobWorkspaceRestore curRestore : restoreJobs)
{
if (curRestore.getRepositoryName().equals(repository) && curRestore.getWorkspaceName().equals(workspace))
{
restore = curRestore;
break;
}
}
if (restore != null)
{
ShortInfo info =
new ShortInfo(ShortInfo.RESTORE, restore.getBackupChainLog(), restore.getStartTime(), restore
.getEndTime(), restore.getStateRestore(), restore.getRepositoryName(), restore
.getWorkspaceName());
return Response.ok(info).cacheControl(noCache).build();
}
return Response.ok().cacheControl(noCache).build();
}
catch (WorkspaceRestoreExeption e)
{
exception = e;
status = Response.Status.FORBIDDEN;
failMessage = e.getMessage();
}
catch (RepositoryException e)
{
exception = e;
status = Response.Status.NOT_FOUND;
failMessage = e.getMessage();
}
catch (RepositoryConfigurationException e)
{
exception = e;
status = Response.Status.NOT_FOUND;
failMessage = e.getMessage();
}
catch (BackupLogNotFoundException e)
{
exception = e;
status = Response.Status.NOT_FOUND;
failMessage = e.getMessage();
}
catch (Throwable e)
{
exception = e;
status = Response.Status.INTERNAL_SERVER_ERROR;
failMessage = e.getMessage();
}
LOG.error("Can not start restore the workspace '" + "/" + repository + "/" + workspace
+ "' from backup set \"" + backupSetPath + "\"", exception);
return Response.status(status).entity(
"Can not start restore the workspace '" + "/" + repository + "/" + workspace + "' from backup set \""
+ backupSetPath + "\" : " + failMessage).type(MediaType.TEXT_PLAIN).cacheControl(noCache)
.build();
}
else
{
String repository = null;
try
{
RepositoryBackupChainLog backupChainLog = new RepositoryBackupChainLog(backuplog);
repository = backupChainLog.getBackupConfig().getRepository();
validateOneRepositoryRestoreInstants(repository);
if (removeExisting)
{