Search in sources :

Example 1 with SnapShooter

use of org.apache.solr.handler.SnapShooter in project lucene-solr by apache.

the class BackupCoreOp method execute.

@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
    ZkController zkController = it.handler.coreContainer.getZkController();
    if (zkController == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Internal SolrCloud API");
    }
    final SolrParams params = it.req.getParams();
    String cname = params.get(CoreAdminParams.CORE);
    if (cname == null) {
        throw new IllegalArgumentException(CoreAdminParams.CORE + " is required");
    }
    String name = params.get(NAME);
    if (name == null) {
        throw new IllegalArgumentException(CoreAdminParams.NAME + " is required");
    }
    String repoName = params.get(CoreAdminParams.BACKUP_REPOSITORY);
    BackupRepository repository = it.handler.coreContainer.newBackupRepository(Optional.ofNullable(repoName));
    String location = repository.getBackupLocation(params.get(CoreAdminParams.BACKUP_LOCATION));
    if (location == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'location' is not specified as a query" + " parameter or as a default repository property");
    }
    // An optional parameter to describe the snapshot to be backed-up. If this
    // parameter is not supplied, the latest index commit is backed-up.
    String commitName = params.get(CoreAdminParams.COMMIT_NAME);
    URI locationUri = repository.createURI(location);
    try (SolrCore core = it.handler.coreContainer.getCore(cname)) {
        SnapShooter snapShooter = new SnapShooter(repository, core, locationUri, name, commitName);
        //  file system. Otherwise, perhaps the FS location isn't shared -- we want an error.
        if (!snapShooter.getBackupRepository().exists(snapShooter.getLocation())) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Directory to contain snapshots doesn't exist: " + snapShooter.getLocation());
        }
        snapShooter.validateCreateSnapshot();
        snapShooter.createSnapshot();
    } catch (Exception e) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Failed to backup core=" + cname + " because " + e, e);
    }
}
Also used : SnapShooter(org.apache.solr.handler.SnapShooter) BackupRepository(org.apache.solr.core.backup.repository.BackupRepository) ZkController(org.apache.solr.cloud.ZkController) SolrCore(org.apache.solr.core.SolrCore) SolrParams(org.apache.solr.common.params.SolrParams) URI(java.net.URI) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Aggregations

URI (java.net.URI)1 ZkController (org.apache.solr.cloud.ZkController)1 SolrException (org.apache.solr.common.SolrException)1 SolrParams (org.apache.solr.common.params.SolrParams)1 SolrCore (org.apache.solr.core.SolrCore)1 BackupRepository (org.apache.solr.core.backup.repository.BackupRepository)1 SnapShooter (org.apache.solr.handler.SnapShooter)1