Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rfe9930: support adding, dropping, listing repository indices

prepush tests added: see IndexManagementTests.java
make prepush run

Note: this feature depends on server feature

Change I34fe4038: rfe9906: Support index inspection and manipulation over HTTP.

and all of its dependencies.

<release-note>
rfe9930: support adding, dropping, listing repository indices

Added methods addIndex, dropIndex, listIndices, and listValidIndices
to AGRepositoryConnection to support managing repository indices.
</release-note>

Change-Id: I1195412b8fd17cfef6f83f2e2071ce27bf327cdb
  • Loading branch information...
commit e4e629e37bda6da81d856cf622aacde065f12419 1 parent ac46024
Bill Millar authored Ahmon Dancy committed
View
72 src/com/franz/agraph/http/AGHttpRepoClient.java
@@ -21,6 +21,7 @@
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.apache.commons.httpclient.Header;
@@ -30,6 +31,7 @@
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.json.JSONArray;
+import org.openrdf.OpenRDFException;
import org.openrdf.OpenRDFUtil;
import org.openrdf.http.protocol.Protocol;
import org.openrdf.http.protocol.UnauthorizedException;
@@ -1195,6 +1197,74 @@ public void registerSNANeighborMatrix(String matrix, String generator, List<Stri
throw new RepositoryException(e);
}
}
+
+ /**
+ * Returns a list of indices for this repository. When listValid is true,
+ * return all possible valid index types for this store; when listValid is
+ * false, return only the current actively managed index types.
+ *
+ * @param listValid true yields all valid types, false yields active types.
+ * @return
+ * @throws OpenRDFException
+ */
+ public List<String> listIndices(boolean listValid) throws RepositoryException {
+ String url = AGProtocol.getIndicesURL(getRoot());
+ Header[] headers = new Header[0];
+ NameValuePair[] data = { new NameValuePair("listValid", Boolean
+ .toString(listValid)) };
+
+ AGResponseHandler handler = new AGResponseHandler("");
+ try {
+ getHTTPClient().get(url, headers, data, handler);
+ } catch (IOException e) {
+ throw new RepositoryException(e);
+ } catch (AGHttpException e) {
+ throw new RepositoryException(e);
+ }
+ return Arrays.asList(handler.getString().split("\n"));
+ }
+
+ /**
+ * Adds the given index to the list of actively managed indices.
+ * This will take affect on the next commit.
+ *
+ * @param type a valid index type
+ * @throws RepositoryException
+ * @see #listIndices(boolean)
+ */
+ public void addIndex(String index) throws RepositoryException {
+ String url = AGProtocol.getIndicesURL(getRoot())+"/"+index;
+ Header[] headers = {};
+ NameValuePair[] params = {};
+ try {
+ getHTTPClient().put(url, headers, params, null);
+ } catch (HttpException e) {
+ throw new RepositoryException(e);
+ } catch (IOException e) {
+ throw new RepositoryException(e);
+ } catch (AGHttpException e) {
+ throw new RepositoryException(e);
+ }
+ }
-
+ /**
+ * Drops the given index from the list of actively managed indices.
+ * This will take affect on the next commit.
+ *
+ * @param type a valid index type
+ * @throws RepositoryException
+ * @see #listIndices(boolean)
+ */
+ public void dropIndex(String index) throws RepositoryException {
+ String url = AGProtocol.getIndicesURL(getRoot())+"/"+index;
+ Header[] headers = {};
+ NameValuePair[] params = {};
+ try {
+ getHTTPClient().delete(url, headers, params);
+ } catch (HttpException e) {
+ throw new RepositoryException(e);
+ } catch (IOException e) {
+ throw new RepositoryException(e);
+ }
+ }
}
View
10 src/com/franz/agraph/http/AGProtocol.java
@@ -402,6 +402,11 @@
public static final String DEPTH_PARAM_NAME = "depth";
/**
+ * Relative location of the INDICES service.
+ */
+ public static final String INDICES = "indices";
+
+ /**
* Location of the root catalog service
*/
public static final String getRootCatalogURL(String serverURL) {
@@ -558,4 +563,9 @@ public static String encode(String s) {
throw new RuntimeException("This JVM does not support UTF-8?");
}
}
+
+ public static String getIndicesURL(String root) {
+ return root + "/" + INDICES;
+ }
+
}
View
46 src/com/franz/agraph/repository/AGRepositoryConnection.java
@@ -19,6 +19,7 @@
import org.json.JSONArray;
import org.json.JSONException;
+import org.openrdf.OpenRDFException;
import org.openrdf.OpenRDFUtil;
import org.openrdf.model.Literal;
import org.openrdf.model.Namespace;
@@ -769,4 +770,49 @@ public void registerSNANeighborMatrix(String matrix, String generator, List<URI>
}
getHttpRepoClient().registerSNANeighborMatrix(matrix, generator, grp, depth);
}
+
+ /**
+ * Returns a list of actively managed indices for this repository.
+ *
+ * @return a list of actively managed indices for this repository.
+ * @throws OpenRDFException
+ */
+ public List<String> listIndices() throws OpenRDFException {
+ return getHttpRepoClient().listIndices(false);
+ }
+
+ /**
+ * Returns a list of all possible index types for this repository.
+ *
+ * @return
+ * @throws OpenRDFException
+ */
+ public List<String> listValidIndices() throws OpenRDFException {
+ return getHttpRepoClient().listIndices(true);
+ }
+
+ /**
+ * Adds the given index to the list of actively managed indices.
+ * This will take affect on the next commit.
+ *
+ * @param type a valid index type
+ * @throws RepositoryException
+ * @see #listValidIndices()
+ */
+ public void addIndex(String type) throws RepositoryException {
+ getHttpRepoClient().addIndex(type);
+ }
+
+ /**
+ * Drops the given index from the list of actively managed indices.
+ * This will take affect on the next commit.
+ *
+ * @param type an actively managed index type.
+ * @throws RepositoryException
+ * @see #listValidIndices()
+ */
+ public void dropIndex(String type) throws RepositoryException {
+ getHttpRepoClient().dropIndex(type);
+ }
+
}
View
39 src/test/IndexManagementTests.java
@@ -0,0 +1,39 @@
+/******************************************************************************
+** Copyright (c) 2008-2010 Franz Inc.
+** All rights reserved. This program and the accompanying materials
+** are made available under the terms of the Eclipse Public License v1.0
+** which accompanies this distribution, and is available at
+** http://www.eclipse.org/legal/epl-v10.html
+******************************************************************************/
+
+package test;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+public class IndexManagementTests extends AGAbstractTest {
+
+ @Test
+ @Category(TestSuites.Prepush.class)
+ public void manageIndices_rfe9930() throws Exception {
+ List<String> indices = conn.listValidIndices();
+ Assert.assertTrue("expected more valid indices", indices.size() >= 24);
+ indices = conn.listIndices();
+ Assert.assertEquals("unexpected number of indices initially", 6, indices.size());
+ conn.dropIndex("gospi");
+ conn.dropIndex("spogi");
+ indices = conn.listIndices();
+ Assert.assertEquals("unexpected number of indices after drop", 4, indices.size());
+ conn.addIndex("gospi");
+ indices = conn.listIndices();
+ Assert.assertEquals("unexpected number of indices after add", 5, indices.size());
+ conn.addIndex("gospi");
+ indices = conn.listIndices();
+ Assert.assertEquals("unexpected number of indices after redundant add", 5, indices.size());
+ }
+
+}
View
3  src/test/TestSuites.java
@@ -51,7 +51,8 @@
@SuiteClasses( { TutorialTests.class,
QuickTests.class,
AGRepositoryConnectionTests.class,
- JenaTests.class
+ JenaTests.class,
+ IndexManagementTests.class
})
public static class Prepush {}
Please sign in to comment.
Something went wrong with that request. Please try again.