Search in sources :

Example 1 with ListSnapshots

use of org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots in project lucene-solr by apache.

the class TestSolrCloudSnapshots method listCollectionSnapshots.

private Collection<CollectionSnapshotMetaData> listCollectionSnapshots(SolrClient adminClient, String collectionName) throws Exception {
    CollectionAdminRequest.ListSnapshots listSnapshots = new CollectionAdminRequest.ListSnapshots(collectionName);
    CollectionAdminResponse resp = listSnapshots.process(adminClient);
    assertTrue(resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO) instanceof NamedList);
    NamedList apiResult = (NamedList) resp.getResponse().get(SolrSnapshotManager.SNAPSHOTS_INFO);
    Collection<CollectionSnapshotMetaData> result = new ArrayList<>();
    for (int i = 0; i < apiResult.size(); i++) {
        result.add(new CollectionSnapshotMetaData((NamedList<Object>) apiResult.getVal(i)));
    }
    return result;
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) ListSnapshots(org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest)

Example 2 with ListSnapshots

use of org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots in project lucene-solr by apache.

the class TestSolrCloudSnapshots method listCoreSnapshots.

private Collection<SnapshotMetaData> listCoreSnapshots(SolrClient adminClient, String coreName) throws Exception {
    ListSnapshots req = new ListSnapshots();
    req.setCoreName(coreName);
    NamedList resp = adminClient.request(req);
    assertTrue(resp.get(SolrSnapshotManager.SNAPSHOTS_INFO) instanceof NamedList);
    NamedList apiResult = (NamedList) resp.get(SolrSnapshotManager.SNAPSHOTS_INFO);
    List<SnapshotMetaData> result = new ArrayList<>(apiResult.size());
    for (int i = 0; i < apiResult.size(); i++) {
        String commitName = apiResult.getName(i);
        String indexDirPath = (String) ((NamedList) apiResult.get(commitName)).get(SolrSnapshotManager.INDEX_DIR_PATH);
        long genNumber = Long.parseLong((String) ((NamedList) apiResult.get(commitName)).get(SolrSnapshotManager.GENERATION_NUM));
        result.add(new SnapshotMetaData(commitName, indexDirPath, genNumber));
    }
    return result;
}
Also used : NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) ListSnapshots(org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots) CoreSnapshotMetaData(org.apache.solr.core.snapshots.CollectionSnapshotMetaData.CoreSnapshotMetaData) SnapshotMetaData(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager.SnapshotMetaData)

Example 3 with ListSnapshots

use of org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots in project lucene-solr by apache.

the class TestSolrCoreSnapshots method deleteSnapshot.

private void deleteSnapshot(SolrClient adminClient, String coreName, String commitName) throws Exception {
    DeleteSnapshot req = new DeleteSnapshot(commitName);
    req.setCoreName(coreName);
    adminClient.request(req);
    Collection<SnapshotMetaData> snapshots = listSnapshots(adminClient, coreName);
    assertFalse(snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst().isPresent());
}
Also used : IndexCommit(org.apache.lucene.index.IndexCommit) IndexNotFoundException(org.apache.lucene.index.IndexNotFoundException) BeforeClass(org.junit.BeforeClass) Slow(org.apache.lucene.util.LuceneTestCase.Slow) DocCollection(org.apache.solr.common.cloud.DocCollection) TestUtil(org.apache.lucene.util.TestUtil) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) SolrTestCaseJ4(org.apache.solr.SolrTestCaseJ4) ArrayList(java.util.ArrayList) BackupRestoreUtils(org.apache.solr.handler.BackupRestoreUtils) BASE_URL_PROP(org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP) Map(java.util.Map) DeleteSnapshot(org.apache.solr.client.solrj.request.CoreAdminRequest.DeleteSnapshot) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) AfterClass(org.junit.AfterClass) Slice(org.apache.solr.common.cloud.Slice) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) DirectoryReader(org.apache.lucene.index.DirectoryReader) SolrCloudTestCase(org.apache.solr.cloud.SolrCloudTestCase) Test(org.junit.Test) CreateSnapshot(org.apache.solr.client.solrj.request.CoreAdminRequest.CreateSnapshot) Replica(org.apache.solr.common.cloud.Replica) NamedList(org.apache.solr.common.util.NamedList) SolrClient(org.apache.solr.client.solrj.SolrClient) SnapshotMetaData(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager.SnapshotMetaData) List(java.util.List) ListSnapshots(org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots) Paths(java.nio.file.Paths) CoreAdminAction(org.apache.solr.common.params.CoreAdminParams.CoreAdminAction) Optional(java.util.Optional) Collections(java.util.Collections) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SnapshotMetaData(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager.SnapshotMetaData) DeleteSnapshot(org.apache.solr.client.solrj.request.CoreAdminRequest.DeleteSnapshot)

Example 4 with ListSnapshots

use of org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots in project lucene-solr by apache.

the class TestSolrCoreSnapshots method createSnapshot.

private SnapshotMetaData createSnapshot(SolrClient adminClient, String coreName, String commitName) throws Exception {
    CreateSnapshot req = new CreateSnapshot(commitName);
    req.setCoreName(coreName);
    adminClient.request(req);
    Collection<SnapshotMetaData> snapshots = listSnapshots(adminClient, coreName);
    Optional<SnapshotMetaData> metaData = snapshots.stream().filter(x -> commitName.equals(x.getName())).findFirst();
    assertTrue(metaData.isPresent());
    return metaData.get();
}
Also used : IndexCommit(org.apache.lucene.index.IndexCommit) IndexNotFoundException(org.apache.lucene.index.IndexNotFoundException) BeforeClass(org.junit.BeforeClass) Slow(org.apache.lucene.util.LuceneTestCase.Slow) DocCollection(org.apache.solr.common.cloud.DocCollection) TestUtil(org.apache.lucene.util.TestUtil) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) SolrTestCaseJ4(org.apache.solr.SolrTestCaseJ4) ArrayList(java.util.ArrayList) BackupRestoreUtils(org.apache.solr.handler.BackupRestoreUtils) BASE_URL_PROP(org.apache.solr.common.cloud.ZkStateReader.BASE_URL_PROP) Map(java.util.Map) DeleteSnapshot(org.apache.solr.client.solrj.request.CoreAdminRequest.DeleteSnapshot) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) AfterClass(org.junit.AfterClass) Slice(org.apache.solr.common.cloud.Slice) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) DirectoryReader(org.apache.lucene.index.DirectoryReader) SolrCloudTestCase(org.apache.solr.cloud.SolrCloudTestCase) Test(org.junit.Test) CreateSnapshot(org.apache.solr.client.solrj.request.CoreAdminRequest.CreateSnapshot) Replica(org.apache.solr.common.cloud.Replica) NamedList(org.apache.solr.common.util.NamedList) SolrClient(org.apache.solr.client.solrj.SolrClient) SnapshotMetaData(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager.SnapshotMetaData) List(java.util.List) ListSnapshots(org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots) Paths(java.nio.file.Paths) CoreAdminAction(org.apache.solr.common.params.CoreAdminParams.CoreAdminAction) Optional(java.util.Optional) Collections(java.util.Collections) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SnapshotMetaData(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager.SnapshotMetaData) CreateSnapshot(org.apache.solr.client.solrj.request.CoreAdminRequest.CreateSnapshot)

Example 5 with ListSnapshots

use of org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots in project lucene-solr by apache.

the class TestSolrCoreSnapshots method listSnapshots.

private Collection<SnapshotMetaData> listSnapshots(SolrClient adminClient, String coreName) throws Exception {
    ListSnapshots req = new ListSnapshots();
    req.setCoreName(coreName);
    NamedList resp = adminClient.request(req);
    assertTrue(resp.get("snapshots") instanceof NamedList);
    NamedList apiResult = (NamedList) resp.get("snapshots");
    List<SnapshotMetaData> result = new ArrayList<>(apiResult.size());
    for (int i = 0; i < apiResult.size(); i++) {
        String commitName = apiResult.getName(i);
        String indexDirPath = (String) ((NamedList) apiResult.get(commitName)).get("indexDirPath");
        long genNumber = Long.parseLong((String) ((NamedList) apiResult.get(commitName)).get("generation"));
        result.add(new SnapshotMetaData(commitName, indexDirPath, genNumber));
    }
    return result;
}
Also used : NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) ListSnapshots(org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots) SnapshotMetaData(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager.SnapshotMetaData)

Aggregations

ArrayList (java.util.ArrayList)5 ListSnapshots (org.apache.solr.client.solrj.request.CoreAdminRequest.ListSnapshots)5 NamedList (org.apache.solr.common.util.NamedList)5 SnapshotMetaData (org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager.SnapshotMetaData)4 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)3 MethodHandles (java.lang.invoke.MethodHandles)2 Paths (java.nio.file.Paths)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 DirectoryReader (org.apache.lucene.index.DirectoryReader)2 IndexCommit (org.apache.lucene.index.IndexCommit)2 IndexNotFoundException (org.apache.lucene.index.IndexNotFoundException)2 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)2 Slow (org.apache.lucene.util.LuceneTestCase.Slow)2 TestUtil (org.apache.lucene.util.TestUtil)2 SolrTestCaseJ4 (org.apache.solr.SolrTestCaseJ4)2