http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/extras/tinkerpop.rya/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/extras/tinkerpop.rya/src/test/resources/log4j.properties b/extras/tinkerpop.rya/src/test/resources/log4j.properties new file mode 100644 index 0000000..8ed05c6 --- /dev/null +++ b/extras/tinkerpop.rya/src/test/resources/log4j.properties @@ -0,0 +1,19 @@ +### +# #%L +# mvm.rya.tinkerpop.rya +# %% +# Copyright (C) 2014 Rya +# %% +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# #L% +###
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/iterators/accumulo.iterators/pom.xml ---------------------------------------------------------------------- diff --git a/iterators/accumulo.iterators/pom.xml b/iterators/accumulo.iterators/pom.xml new file mode 100644 index 0000000..44e4cbf --- /dev/null +++ b/iterators/accumulo.iterators/pom.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>mvm.rya</groupId> + <artifactId>rya.iterators</artifactId> + <version>3.2.9</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>accumulo.iterators</artifactId> + <name>${project.groupId}.${project.artifactId}</name> + <properties> + + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.accumulo</groupId> + <artifactId>accumulo-core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.hadoop</groupId> + <artifactId>hadoop-common</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/iterators/accumulo.iterators/src/main/java/mvm/rya/iterators/LimitingAgeOffFilter.java ---------------------------------------------------------------------- diff --git a/iterators/accumulo.iterators/src/main/java/mvm/rya/iterators/LimitingAgeOffFilter.java b/iterators/accumulo.iterators/src/main/java/mvm/rya/iterators/LimitingAgeOffFilter.java new file mode 100644 index 0000000..33d5b98 --- /dev/null +++ b/iterators/accumulo.iterators/src/main/java/mvm/rya/iterators/LimitingAgeOffFilter.java @@ -0,0 +1,138 @@ +package mvm.rya.iterators; + +/* + * #%L + * mvm.rya.accumulo.iterators + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import java.io.IOException; +import java.util.Map; + +import org.apache.accumulo.core.client.IteratorSetting; +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.iterators.Filter; +import org.apache.accumulo.core.iterators.IteratorEnvironment; +import org.apache.accumulo.core.iterators.SortedKeyValueIterator; + +/** + * A small modification of the age off filter that ships with Accumulo which ages off key/value pairs based on the + * Key's timestamp. It removes an entry if its timestamp is less than currentTime - threshold. + * + * The modification will now allow rows with timestamp > currentTime to pass through. + * + * This filter requires a "ttl" option, in milliseconds, to determine the age off threshold. + */ +public class LimitingAgeOffFilter extends Filter { + + public static final String TTL = "ttl"; + public static final String CURRENT_TIME = "currentTime"; + + protected long threshold; + + /** + * The use of private for this member in the original AgeOffFilter wouldn't allow me to extend it. Setting to protected. + */ + protected long currentTime; + + /** + * Accepts entries whose timestamps are less than currentTime - threshold. + * + * @see org.apache.accumulo.core.iterators.Filter#accept(org.apache.accumulo.core.data.Key, org.apache.accumulo.core.data.Value) + */ + @Override + public boolean accept(Key k, Value v) { + long diff = currentTime - k.getTimestamp(); + return !(diff > threshold || diff < 0); + } + + @Override + public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException { + super.init(source, options, env); + threshold = -1; + if (options == null) + throw new IllegalArgumentException(TTL + " must be set for LimitingAgeOffFilter"); + + String ttl = options.get(TTL); + if (ttl == null) + throw new IllegalArgumentException(TTL + " must be set for LimitingAgeOffFilter"); + + threshold = Long.parseLong(ttl); + + String time = options.get(CURRENT_TIME); + if (time != null) + currentTime = Long.parseLong(time); + else + currentTime = System.currentTimeMillis(); + + // add sanity checks for threshold and currentTime? + } + + @Override + public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment env) { + LimitingAgeOffFilter copy = (LimitingAgeOffFilter) super.deepCopy(env); + copy.currentTime = currentTime; + copy.threshold = threshold; + return copy; + } + + @Override + public IteratorOptions describeOptions() { + IteratorOptions io = super.describeOptions(); + io.addNamedOption(TTL, "time to live (milliseconds)"); + io.addNamedOption(CURRENT_TIME, "if set, use the given value as the absolute time in milliseconds as the current time of day"); + io.setName("ageoff"); + io.setDescription("LimitingAgeOffFilter removes entries with timestamps more than <ttl> milliseconds old & timestamps newer than currentTime"); + return io; + } + + @Override + public boolean validateOptions(Map<String,String> options) { + super.validateOptions(options); + try { + Long.parseLong(options.get(TTL)); + } catch (NumberFormatException e) { + return false; + } + return true; + } + + /** + * A convenience method for setting the age off threshold. + * + * @param is + * IteratorSetting object to configure. + * @param ttl + * age off threshold in milliseconds. + */ + public static void setTTL(IteratorSetting is, Long ttl) { + is.addOption(TTL, Long.toString(ttl)); + } + + /** + * A convenience method for setting the current time (from which to measure the age off threshold). + * + * @param is + * IteratorSetting object to configure. + * @param currentTime + * time in milliseconds. + */ + public static void setCurrentTime(IteratorSetting is, Long currentTime) { + is.addOption(CURRENT_TIME, Long.toString(currentTime)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/iterators/accumulo.iterators/src/test/java/mvm/rya/iterators/LimitingAgeOffFilterTest.java ---------------------------------------------------------------------- diff --git a/iterators/accumulo.iterators/src/test/java/mvm/rya/iterators/LimitingAgeOffFilterTest.java b/iterators/accumulo.iterators/src/test/java/mvm/rya/iterators/LimitingAgeOffFilterTest.java new file mode 100644 index 0000000..5e8e2ee --- /dev/null +++ b/iterators/accumulo.iterators/src/test/java/mvm/rya/iterators/LimitingAgeOffFilterTest.java @@ -0,0 +1,80 @@ +package mvm.rya.iterators; + +/* + * #%L + * mvm.rya.accumulo.iterators + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import org.apache.accumulo.core.data.Key; +import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.iterators.SortedMapIterator; +import org.apache.hadoop.io.Text; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; + +import static org.junit.Assert.*; + +/** + * Date: 1/11/13 + * Time: 10:18 AM + */ +public class LimitingAgeOffFilterTest { + + @Test + public void testTimeRange() throws Exception { + LimitingAgeOffFilter filter = new LimitingAgeOffFilter(); + Map<String, String> map = new HashMap<String, String>(); + map.put(LimitingAgeOffFilter.TTL, "10000"); + map.put(LimitingAgeOffFilter.CURRENT_TIME, "1010001"); + filter.init(new SortedMapIterator(new TreeMap<Key, Value>()), map, null); + + assertFalse(filter.accept(new Key(new Text("row1"), 1000000), null)); + assertTrue(filter.accept(new Key(new Text("row1"), 1000001), null)); + assertTrue(filter.accept(new Key(new Text("row1"), 1000011), null)); + assertTrue(filter.accept(new Key(new Text("row1"), 1010001), null)); + assertFalse(filter.accept(new Key(new Text("row1"), 1010002), null)); + assertFalse(filter.accept(new Key(new Text("row1"), 1010012), null)); + } + + @Test + public void testTimeRangeSetOptions() throws Exception { + try { + LimitingAgeOffFilter filter = new LimitingAgeOffFilter(); + Map<String, String> map = new HashMap<String, String>(); + filter.init(new SortedMapIterator(new TreeMap<Key, Value>()), map, null); + fail(); + } catch (Exception e) { + } + } + + @Test + public void testTimeRangeCurrentTime() throws Exception { + long currentTime = System.currentTimeMillis(); + LimitingAgeOffFilter filter = new LimitingAgeOffFilter(); + Map<String, String> map = new HashMap<String, String>(); + map.put(LimitingAgeOffFilter.TTL, "10000"); + filter.init(new SortedMapIterator(new TreeMap<Key, Value>()), map, null); + + assertFalse(filter.accept(new Key(new Text("row1"), currentTime - 15000), null)); + assertTrue(filter.accept(new Key(new Text("row1"), currentTime - 5000), null)); + assertFalse(filter.accept(new Key(new Text("row1"), currentTime + 5000), null)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/iterators/cloudbase.iterators/pom.xml ---------------------------------------------------------------------- diff --git a/iterators/cloudbase.iterators/pom.xml b/iterators/cloudbase.iterators/pom.xml new file mode 100644 index 0000000..82f9bee --- /dev/null +++ b/iterators/cloudbase.iterators/pom.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>mvm.rya</groupId> + <artifactId>rya.iterators</artifactId> + <version>3.2.7-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>cloudbase.iterators</artifactId> + <name>${project.groupId}.${project.artifactId}</name> + <properties> + + </properties> + + <dependencies> + <dependency> + <groupId>cloudbase</groupId> + <artifactId>cloudbase-core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.hadoop</groupId> + <artifactId>hadoop-common</artifactId> + <scope>provided</scope> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/iterators/cloudbase.iterators/src/main/java/mvm/rya/iterators/LimitingAgeOffFilter.java ---------------------------------------------------------------------- diff --git a/iterators/cloudbase.iterators/src/main/java/mvm/rya/iterators/LimitingAgeOffFilter.java b/iterators/cloudbase.iterators/src/main/java/mvm/rya/iterators/LimitingAgeOffFilter.java new file mode 100644 index 0000000..44fe945 --- /dev/null +++ b/iterators/cloudbase.iterators/src/main/java/mvm/rya/iterators/LimitingAgeOffFilter.java @@ -0,0 +1,76 @@ +package mvm.rya.iterators; + +import cloudbase.core.data.Key; +import cloudbase.core.data.Value; +import cloudbase.core.iterators.OptionDescriber; +import cloudbase.core.iterators.filter.Filter; + +import java.util.Map; +import java.util.TreeMap; + +/** + * A small modification of the age off filter that ships with Accumulo which ages off key/value pairs based on the + * Key's timestamp. It removes an entry if its timestamp is less than currentTime - threshold. + * <p/> + * The modification will now allow rows with timestamp > currentTime to pass through. + * <p/> + * This filter requires a "ttl" option, in milliseconds, to determine the age off threshold. + */ +public class LimitingAgeOffFilter implements Filter, OptionDescriber { + + public static final String TTL = "ttl"; + public static final String CURRENT_TIME = "currentTime"; + + protected long threshold; + + /** + * The use of private for this member in the original AgeOffFilter wouldn't allow me to extend it. Setting to protected. + */ + protected long currentTime; + + @Override + public boolean accept(Key k, Value v) { + long diff = currentTime - k.getTimestamp(); + return !(diff > threshold || diff < 0); + } + + @Override + public void init(Map<String, String> options) { + threshold = -1; + if (options == null) + throw new IllegalArgumentException(TTL + " must be set for LimitingAgeOffFilter"); + + String ttl = options.get(TTL); + if (ttl == null) + throw new IllegalArgumentException(TTL + " must be set for LimitingAgeOffFilter"); + + threshold = Long.parseLong(ttl); + + String time = options.get(CURRENT_TIME); + if (time != null) + currentTime = Long.parseLong(time); + else + currentTime = System.currentTimeMillis(); + + // add sanity checks for threshold and currentTime? + } + + @Override + public IteratorOptions describeOptions() { + Map<String, String> options = new TreeMap<String, String>(); + options.put(TTL, "time to live (milliseconds)"); + options.put(CURRENT_TIME, "if set, use the given value as the absolute time in milliseconds as the current time of day"); + return new OptionDescriber.IteratorOptions("limitingAgeOff", "LimitingAgeOffFilter removes entries with timestamps more than <ttl> milliseconds old & timestamps newer than currentTime", + options, null); + } + + @Override + public boolean validateOptions(Map<String, String> options) { + try { + Long.parseLong(options.get(TTL)); + } catch (NumberFormatException e) { + return false; + } + return true; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/iterators/cloudbase.iterators/src/test/java/mvm/rya/iterators/LimitingAgeOffFilterTest.java ---------------------------------------------------------------------- diff --git a/iterators/cloudbase.iterators/src/test/java/mvm/rya/iterators/LimitingAgeOffFilterTest.java b/iterators/cloudbase.iterators/src/test/java/mvm/rya/iterators/LimitingAgeOffFilterTest.java new file mode 100644 index 0000000..83b2f2c --- /dev/null +++ b/iterators/cloudbase.iterators/src/test/java/mvm/rya/iterators/LimitingAgeOffFilterTest.java @@ -0,0 +1,59 @@ +package mvm.rya.iterators; + +import cloudbase.core.data.Key; +import org.apache.hadoop.io.Text; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Date: Mar 23, 2011 + * Time: 10:08:58 AM + */ +public class LimitingAgeOffFilterTest { + + @Test + public void testTimeRange() throws Exception { + LimitingAgeOffFilter filter = new LimitingAgeOffFilter(); + Map<String, String> map = new HashMap<String, String>(); + map.put(LimitingAgeOffFilter.TTL, "10000"); + map.put(LimitingAgeOffFilter.CURRENT_TIME, "1010001"); + filter.init(map); + + assertFalse(filter.accept(new Key(new Text("row1"), 1000000), null)); + assertTrue(filter.accept(new Key(new Text("row1"), 1000001), null)); + assertTrue(filter.accept(new Key(new Text("row1"), 1000011), null)); + assertTrue(filter.accept(new Key(new Text("row1"), 1010001), null)); + assertFalse(filter.accept(new Key(new Text("row1"), 1010002), null)); + assertFalse(filter.accept(new Key(new Text("row1"), 1010012), null)); + } + + @Test + public void testTimeRangeSetOptions() throws Exception { + try { + LimitingAgeOffFilter filter = new LimitingAgeOffFilter(); + Map<String, String> map = new HashMap<String, String>(); + filter.init(map); + fail(); + } catch (Exception e) { + } + } + + @Test + public void testTimeRangeCurrentTime() throws Exception { + long currentTime = System.currentTimeMillis(); + LimitingAgeOffFilter filter = new LimitingAgeOffFilter(); + Map<String, String> map = new HashMap<String, String>(); + map.put(LimitingAgeOffFilter.TTL, "10000"); + filter.init(map); + + assertFalse(filter.accept(new Key(new Text("row1"), currentTime - 15000), null)); + assertTrue(filter.accept(new Key(new Text("row1"), currentTime - 5000), null)); + assertFalse(filter.accept(new Key(new Text("row1"), currentTime + 5000), null)); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/iterators/pom.xml ---------------------------------------------------------------------- diff --git a/iterators/pom.xml b/iterators/pom.xml new file mode 100644 index 0000000..e9a4de9 --- /dev/null +++ b/iterators/pom.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>mvm.rya</groupId> + <artifactId>parent</artifactId> + <version>3.2.9</version> + </parent> + <artifactId>rya.iterators</artifactId> + <packaging>pom</packaging> + <name>${project.groupId}.${project.artifactId}</name> + + <modules> + <module>accumulo.iterators</module> + </modules> + + <profiles> + <profile> + <id>cloudbase</id> + <modules> + <module>cloudbase.iterators</module> + </modules> + </profile> + </profiles> +</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya.console/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/alx.rya.console/pom.xml b/osgi/alx.rya.console/pom.xml new file mode 100644 index 0000000..38e9f9f --- /dev/null +++ b/osgi/alx.rya.console/pom.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>mvm.rya</groupId> + <artifactId>rya.osgi</artifactId> + <version>3.2.9</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <packaging>bundle</packaging> + <artifactId>alx.rya.console</artifactId> + <name>${project.groupId}.${project.artifactId}</name> + + <dependencies> + <dependency> + <groupId>mvm.rya</groupId> + <artifactId>rya.api</artifactId> + </dependency> + <dependency> + <groupId>org.openrdf.sesame</groupId> + <artifactId>sesame-repository-api</artifactId> + <version>${openrdf.sesame.version}</version> + </dependency> + <dependency> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.console</artifactId> + <version>${karaf.version}</version> + <scope>provided</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + </plugin> + </plugins> + </build> + +</project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/AbstractRyaCommand.java ---------------------------------------------------------------------- diff --git a/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/AbstractRyaCommand.java b/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/AbstractRyaCommand.java new file mode 100644 index 0000000..2aff2f3 --- /dev/null +++ b/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/AbstractRyaCommand.java @@ -0,0 +1,57 @@ +package mvm.rya.alx.command; + +/* + * #%L + * mvm.rya.alx.rya.console + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import mvm.rya.api.persist.RyaDAO; +import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.openrdf.repository.Repository; +import org.osgi.util.tracker.ServiceTracker; + +public abstract class AbstractRyaCommand extends OsgiCommandSupport { + + protected Repository repository; + protected RyaDAO rdfDAO; + + @Override + protected Object doExecute() throws Exception { + ServiceTracker serviceTracker = new ServiceTracker(getBundleContext(), Repository.class.getName(), null); + serviceTracker.open(); + repository = (Repository) serviceTracker.getService(); + serviceTracker.close(); + if (repository == null) { + System.out.println("Sail Repository not available"); + return null; + } + + serviceTracker = new ServiceTracker(getBundleContext(), RyaDAO.class.getName(), null); + serviceTracker.open(); + rdfDAO = (RyaDAO) serviceTracker.getService(); + serviceTracker.close(); + if (rdfDAO == null) { + System.out.println("Rdf DAO not available"); + return null; + } + + return doRyaExecute(); + } + + protected abstract Object doRyaExecute() throws Exception; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/GetStatementsRyaCommand.java ---------------------------------------------------------------------- diff --git a/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/GetStatementsRyaCommand.java b/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/GetStatementsRyaCommand.java new file mode 100644 index 0000000..9ae293e --- /dev/null +++ b/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/GetStatementsRyaCommand.java @@ -0,0 +1,79 @@ +package mvm.rya.alx.command; + +/* + * #%L + * mvm.rya.alx.rya.console + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import org.apache.felix.gogo.commands.Command; +import org.apache.felix.gogo.commands.Option; +import org.openrdf.model.Resource; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.RepositoryResult; + +import static mvm.rya.api.RdfCloudTripleStoreUtils.*; + +/** + * Date: 5/16/12 + * Time: 1:23 PM + */ +@Command(scope = "rya", name = "getstatements", description = "Print statements to screen based on triple pattern") +public class GetStatementsRyaCommand extends AbstractRyaCommand { + @Option(name = "-s", aliases = {"--subject"}, description = "Subject of triple pattern", required = false, multiValued = false) + private String subject; + @Option(name = "-p", aliases = {"--predicate"}, description = "Predicate of triple pattern", required = false, multiValued = false) + private String predicate; + @Option(name = "-o", aliases = {"--object"}, description = "Object of triple pattern", required = false, multiValued = false) + private String object; + @Option(name = "-c", aliases = {"--context"}, description = "Context of triple pattern", required = false, multiValued = false) + private String context; + + @Override + protected Object doRyaExecute() throws Exception { + if (subject == null && predicate == null && object == null && context == null) { + System.out.println("Please specify subject|predicate|object|context"); + return null; + } + + System.out.println(subject); + System.out.println(predicate); + System.out.println(object); + System.out.println(context); + RepositoryConnection connection = null; + try { + connection = repository.getConnection(); + RepositoryResult<Statement> statements = connection.getStatements( + (subject != null) ? (Resource) createValue(subject) : null, + (predicate != null) ? (URI) createValue(predicate) : null, + (object != null) ? createValue(object) : null, + false, + (context != null) ? new Resource[]{(Resource) createValue(context)} : new Resource[0]); + while(statements.hasNext()) { + System.out.println(statements.next()); + } + statements.close(); + } finally { + if (connection != null) { + connection.close(); + } + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/InfoRyaCommand.java ---------------------------------------------------------------------- diff --git a/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/InfoRyaCommand.java b/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/InfoRyaCommand.java new file mode 100644 index 0000000..15ee550 --- /dev/null +++ b/osgi/alx.rya.console/src/main/java/mvm/rya/alx/command/InfoRyaCommand.java @@ -0,0 +1,45 @@ +package mvm.rya.alx.command; + +/* + * #%L + * mvm.rya.alx.rya.console + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import mvm.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.felix.gogo.commands.Command; + +import java.util.Map; + +/** + * Date: 5/16/12 + * Time: 11:04 AM + */ +@Command(scope = "rya", name = "info", description = "Displays information about the running Rya instance") +public class InfoRyaCommand extends AbstractRyaCommand { + + @Override + protected Object doRyaExecute() throws Exception { + System.out.println("******************RYA Configuration******************"); + RdfCloudTripleStoreConfiguration conf = rdfDAO.getConf(); + for (Map.Entry<String, String> next : conf) { + System.out.println(next.getKey() + ":\t\t" + next.getValue()); + } + System.out.println("*****************************************************"); + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya.console/src/main/resources/OSGI-INF/blueprint/alx.rya.console-blueprint.xml ---------------------------------------------------------------------- diff --git a/osgi/alx.rya.console/src/main/resources/OSGI-INF/blueprint/alx.rya.console-blueprint.xml b/osgi/alx.rya.console/src/main/resources/OSGI-INF/blueprint/alx.rya.console-blueprint.xml new file mode 100644 index 0000000..0914832 --- /dev/null +++ b/osgi/alx.rya.console/src/main/resources/OSGI-INF/blueprint/alx.rya.console-blueprint.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"> + + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0"> + <command name="rya/info"> + <action class="mvm.rya.alx.command.InfoRyaCommand"/> + </command> + <command name="rya/getstatements"> + <action class="mvm.rya.alx.command.GetStatementsRyaCommand"/> + </command> + </command-bundle> + +</blueprint> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/alx.rya/pom.xml b/osgi/alx.rya/pom.xml new file mode 100644 index 0000000..f4ee471 --- /dev/null +++ b/osgi/alx.rya/pom.xml @@ -0,0 +1,76 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>mvm.rya</groupId> + <artifactId>rya.osgi</artifactId> + <version>3.2.9</version> + </parent> + <artifactId>alx.rya</artifactId> + <packaging>bundle</packaging> + <name>${project.groupId}.${project.artifactId}</name> + <dependencies> + <dependency> + <groupId>mvm.rya</groupId> + <artifactId>accumulo.rya</artifactId> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + </dependencies> + <repositories> + <repository> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>false</enabled> + </snapshots> + <id>aduna-opensource.releases</id> + <name>Aduna Open Source - Maven releases</name> + <url>http://repo.aduna-software.org/maven2/releases</url> + </repository> + </repositories> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>${maven-bundle-plugin.version}</version> + <extensions>true</extensions> + <configuration> + <instructions> + <Import-Package>*,net.sf.cglib.proxy</Import-Package> + <DynamicImport-Package>*</DynamicImport-Package> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin + </artifactId> + <version>1.7</version> + <executions> + <execution> + <id>attach-artifacts</id> + <phase>package</phase> + <goals> + <goal>attach-artifact</goal> + </goals> + <configuration> + <artifacts> + <artifact> + <file> + src/main/features/alx.rya-features.xml + </file> + <type>xml</type> + <classifier>features</classifier> + </artifact> + </artifacts> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya/src/main/features/alx.rya-features.xml ---------------------------------------------------------------------- diff --git a/osgi/alx.rya/src/main/features/alx.rya-features.xml b/osgi/alx.rya/src/main/features/alx.rya-features.xml new file mode 100644 index 0000000..efc6917 --- /dev/null +++ b/osgi/alx.rya/src/main/features/alx.rya-features.xml @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<features name="alx.rya"> + <feature name='org.openrdf.sesame.runtime' version="2.6.4"> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-model/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-runtime/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-query/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryalgebra-model/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryparser-api/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryparser-serql/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryparser-sparql/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryresultio-api/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryresultio-binary/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryresultio-sparqljson/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryresultio-text/2.6.4</bundle> + <bundle>wrap:mvn:net.sf.opencsv/opencsv/2.0</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-repository-api/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-repository-manager/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-repository-event/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-repository-sail/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-sail-memory/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-sail-inferencer/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryalgebra-evaluation/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-repository-sparql/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-repository-http/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-http-client/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-repository-dataset/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-repository-contextaware/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-http-protocol/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-rio-ntriples/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-rio-api/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-rio-binary/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-rio-n3/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-rio-trix/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-rio-turtle/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-rio-trig/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-sail-api/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-sail-nativerdf/2.6.4</bundle> + <!--bundle>wrap:mvn:org.openrdf.sesame/sesame-sail-rdbms/2.6.4</bundle> + <bundle>wrap:mvn:commons-dbcp/commons-dbcp/1.3</bundle> + <bundle>wrap:mvn:commons-pool/commons-pool/1.3</bundle--> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-queryresultio-sparqlxml/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-util/2.6.4</bundle> + <bundle>wrap:mvn:org.openrdf.sesame/sesame-rio-rdfxml/2.6.4</bundle> + </feature> + <feature name='tinkerpop.blueprints' version='1.2'> + <bundle>wrap:mvn:com.tinkerpop.blueprints/blueprints-core/1.2</bundle> + <bundle>mvn:org.codehaus.jettison/jettison/1.3</bundle> + <bundle>wrap:mvn:stax/stax-api/1.0.1</bundle> + <!--bundle>wrap:mvn:org.codehaus.jackson/jackson-jaxrs/1.8.5</bundle--> + <bundle>mvn:org.codehaus.jackson/jackson-core-asl/1.8.5</bundle> + <bundle>mvn:org.codehaus.jackson/jackson-mapper-asl/1.8.5</bundle> + </feature> + <feature name='rya.sail' version='3.0.4'> + <!--<feature version="[2.6,3.0)">org.openrdf.sesame.runtime</feature>--> + <feature version="1.2">tinkerpop.blueprints</feature> + <feature version="[10,12)">google.guava</feature> + <bundle>mvn:mvm.rya/sesame-runtime-osgi/2.6.4</bundle> + <bundle>wrap:mvn:mvm.rya/rya.api/3.0.4-SNAPSHOT</bundle> + <bundle>wrap:mvn:mvm.rya/rya.sail.impl/3.0.4-SNAPSHOT</bundle> + </feature> + <feature name="cloudbase.rya" version="3.0.4"> + <feature version="1.0.5">mvm.alx.connect.cloudbase.connect</feature> + <feature version="[10,12)">google.guava</feature> + <bundle>wrap:mvn:mvm.rya/cloudbase.rya/3.0.4-SNAPSHOT</bundle> + <bundle>wrap:mvn:mvm.rya/cloudbase.utils/1.0.1-SNAPSHOT</bundle> + </feature> + <feature name="accumulo.rya" version="3.0.4"> + <feature version="1.0.5">mvm.alx.accumulo.connect</feature> + <feature version="[10,12)">google.guava</feature> + <bundle>wrap:mvn:mvm.rya/accumulo.rya/3.0.4-SNAPSHOT</bundle> + </feature> + <feature name='alx.rya' version='3.0.4'> + <feature version="0.7.1">pax-web</feature> + <feature version="[10,12)">google.guava</feature> + <feature version="3.0.4">rya.sail</feature> + <feature version="3.0.4">accumulo.rya</feature> + <!--Ehcache should already be part of alx: net.sf.ehcache:ehcache-core:jar:1.7.1:compile--> + <bundle>mvn:mvm.rya/alx.rya/3.0.4-SNAPSHOT</bundle> + </feature> + <feature name='alx.rya.console' version='3.0.4'> + <feature version="3.0.4">alx.rya</feature> + <bundle>mvn:mvm.rya/alx.rya.console/3.0.4-SNAPSHOT</bundle> + </feature> +</features> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya/src/main/java/mvm/rya/alx/util/ConfigurationFactory.java ---------------------------------------------------------------------- diff --git a/osgi/alx.rya/src/main/java/mvm/rya/alx/util/ConfigurationFactory.java b/osgi/alx.rya/src/main/java/mvm/rya/alx/util/ConfigurationFactory.java new file mode 100644 index 0000000..4cf4edb --- /dev/null +++ b/osgi/alx.rya/src/main/java/mvm/rya/alx/util/ConfigurationFactory.java @@ -0,0 +1,52 @@ +package mvm.rya.alx.util; + +/* + * #%L + * mvm.rya.alx.rya + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import mvm.rya.accumulo.AccumuloRdfConfiguration; +import mvm.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.hadoop.conf.Configuration; + +import java.util.Map; + +/** + */ +public class ConfigurationFactory { + private Map<String, String> properties; + + public RdfCloudTripleStoreConfiguration getConfiguration() { + RdfCloudTripleStoreConfiguration conf = new AccumuloRdfConfiguration(); + if (properties != null) { + for (Map.Entry<String, String> prop : properties.entrySet()) { + conf.set(prop.getKey(), prop.getValue()); + } + conf.setTablePrefix(conf.getTablePrefix()); + } + return conf; + } + + public Map<String, String> getProperties() { + return properties; + } + + public void setProperties(Map<String, String> properties) { + this.properties = properties; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya/src/main/resources/META-INF/spring/alx.rya-spring-osgi.xml ---------------------------------------------------------------------- diff --git a/osgi/alx.rya/src/main/resources/META-INF/spring/alx.rya-spring-osgi.xml b/osgi/alx.rya/src/main/resources/META-INF/spring/alx.rya-spring-osgi.xml new file mode 100644 index 0000000..4c11e59 --- /dev/null +++ b/osgi/alx.rya/src/main/resources/META-INF/spring/alx.rya-spring-osgi.xml @@ -0,0 +1,42 @@ +<!-- Copyright (C) 2008 PROTEUS Technologies, LLC This program is free software: + you can redistribute it and/or modify it under the terms of the GNU General + Public License as published by the Free Software Foundation, either version + 3 of the License, or (at your option) any later version. This program is + distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the GNU General Public License for more details. You should + have received a copy of the GNU General Public License along with this program. + If not, see <http://www.gnu.org/licenses/>. --> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" + xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/osgi + http://www.springframework.org/schema/osgi/spring-osgi.xsd + http://www.springframework.org/schema/util + http://www.springframework.org/schema/util/spring-util-2.0.xsd + http://www.springframework.org/schema/osgi-compendium + http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd"> + + <!-- Configuration Admin entry --> + <osgix:cm-properties id="alxProps" + persistent-id="mvm.rya.alx"> + <prop key="query.tblprefix">l_</prop> + <prop key="query.printqueryplan">true</prop> + </osgix:cm-properties> + + <osgi:reference id="logServiceOsgi" interface="org.osgi.service.log.LogService" + cardinality="1..1"/> + + <osgi:reference id="connectorServiceOsgi" + interface="org.apache.accumulo.core.client.Connector" cardinality="1..1"/> + + <!--<osgi:service ref="rootResourceMapping" auto-export="interfaces"/>--> + + <osgi:service ref="sailRepo" auto-export="interfaces"/> + <osgi:service ref="ryaDAO" auto-export="interfaces"/> + +</beans> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya/src/main/resources/META-INF/spring/alx.rya-spring.xml ---------------------------------------------------------------------- diff --git a/osgi/alx.rya/src/main/resources/META-INF/spring/alx.rya-spring.xml b/osgi/alx.rya/src/main/resources/META-INF/spring/alx.rya-spring.xml new file mode 100644 index 0000000..47dced1 --- /dev/null +++ b/osgi/alx.rya/src/main/resources/META-INF/spring/alx.rya-spring.xml @@ -0,0 +1,60 @@ + +<!-- Copyright (C) 2008 PROTEUS Technologies, LLC This program is free software: + you can redistribute it and/or modify it under the terms of the GNU General + Public License as published by the Free Software Foundation, either version + 3 of the License, or (at your option) any later version. This program is + distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the GNU General Public License for more details. You should + have received a copy of the GNU General Public License along with this program. + If not, see <http://www.gnu.org/licenses/>. --> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ctx="http://www.springframework.org/schema/context" + xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" + xsi:schemaLocation="http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/osgi-compendium + http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd"> + + <!-- placeholder configurer --> + <ctx:property-placeholder properties-ref="alxProps" /> + + <bean id="configurationFactory" class="mvm.rya.alx.util.ConfigurationFactory"> + <osgix:managed-properties persistent-id="mvm.rya.alx" + update-strategy="bean-managed" update-method="setProperties" /> + </bean> + + <bean id="configuration" factory-bean="configurationFactory" + factory-method="getConfiguration"/> + + <bean id="rdfEval" class="mvm.rya.accumulo.AccumuloRdfEvalStatsDAO" init-method="init" destroy-method="destroy"> + <property name="connector" ref="connectorServiceOsgi"/> + <property name="conf" ref="configuration"/> + </bean> + + <bean id="ryaDAO" class="mvm.rya.accumulo.AccumuloRyaDAO"> + <property name="connector" ref="connectorServiceOsgi"/> + <property name="conf" ref="configuration"/> + </bean> + + <bean id="inferenceEngine" class="mvm.rya.rdftriplestore.inference.InferenceEngine"> + <property name="ryaDAO" ref="ryaDAO"/> + <property name="conf" ref="configuration"/> + </bean> + + <bean id="rts" class="mvm.rya.rdftriplestore.RdfCloudTripleStore"> + <property name="ryaDAO" ref="ryaDAO"/> + <property name="rdfEvalStatsDAO" ref="rdfEval"/> + <property name="inferenceEngine" ref="inferenceEngine"/> + <property name="conf" ref="configuration"/> + </bean> + + <bean id="sailRepo" class="mvm.rya.rdftriplestore.RyaSailRepository" init-method="initialize" destroy-method="shutDown"> + <constructor-arg ref="rts"/> + </bean> + +</beans> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/alx.rya/src/main/resources/ROOT/crossdomain.xml ---------------------------------------------------------------------- diff --git a/osgi/alx.rya/src/main/resources/ROOT/crossdomain.xml b/osgi/alx.rya/src/main/resources/ROOT/crossdomain.xml new file mode 100644 index 0000000..c3b5339 --- /dev/null +++ b/osgi/alx.rya/src/main/resources/ROOT/crossdomain.xml @@ -0,0 +1,5 @@ +<?xml version="1.0"?> +<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> +<cross-domain-policy> + <allow-access-from domain="*" secure="false"/> +</cross-domain-policy> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/camel.rya/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/camel.rya/pom.xml b/osgi/camel.rya/pom.xml new file mode 100644 index 0000000..62d0c79 --- /dev/null +++ b/osgi/camel.rya/pom.xml @@ -0,0 +1,82 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>mvm.rya</groupId> + <artifactId>rya.osgi</artifactId> + <version>3.2.9</version> + </parent> + <groupId>mvm.rya</groupId> + <artifactId>camel.rya</artifactId> + <packaging>bundle</packaging> + <name>${project.groupId}.${project.artifactId}</name> + <properties> + <camel.version>2.7.2</camel.version> + </properties> + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <version>${camel.version}</version> + </dependency> + <dependency> + <groupId>mvm.rya</groupId> + <artifactId>rya.sail.impl</artifactId> + </dependency> + <dependency> + <groupId>mvm.rya</groupId> + <artifactId>accumulo.rya</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + </plugin> + </plugins> + </build> + + <profiles> + <profile> + <id>accumulo</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>org.apache.accumulo</groupId> + <artifactId>accumulo-core</artifactId> + <optional>true</optional> + <scope>test</scope> + </dependency> + </dependencies> + </profile> + <profile> + <id>cloudbase</id> + <activation> + <activeByDefault>false</activeByDefault> + </activation> + <dependencies> + <dependency> + <groupId>com.texeltek</groupId> + <artifactId>accumulo-cloudbase-shim</artifactId> + <optional>true</optional> + <scope>test</scope> + </dependency> + </dependencies> + </profile> + </profiles> + +</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailComponent.java ---------------------------------------------------------------------- diff --git a/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailComponent.java b/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailComponent.java new file mode 100644 index 0000000..31f864c --- /dev/null +++ b/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailComponent.java @@ -0,0 +1,58 @@ +package mvm.rya.camel.cbsail; + +/* + * #%L + * mvm.rya.camel.rya + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import org.apache.camel.Endpoint; +import org.apache.camel.impl.DefaultComponent; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.ValueFactoryImpl; +import org.openrdf.repository.Repository; +import org.openrdf.repository.sail.SailRepository; + +import java.util.Map; + +import static com.google.common.base.Preconditions.*; +/** + * Save and retrieve triples + */ +public class CbSailComponent extends DefaultComponent { + public static final String SAILREPONAME = "sailRepoName"; + + public static final String ENDPOINT_URI = "cbsail"; + public static final String SPARQL_QUERY_PROP = "cbsail.sparql"; + public static final String START_TIME_QUERY_PROP = "cbsail.startTime"; + public static final String TTL_QUERY_PROP = "cbsail.ttl"; + public static final ValueFactory valueFactory = new ValueFactoryImpl(); + + @Override + protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { + String sailRepoNameParam = Repository.class.getName(); + if (parameters.containsKey(sailRepoNameParam)) { + sailRepoNameParam = getAndRemoveParameter(parameters, SAILREPONAME, String.class); + } + Repository sailRepository = getCamelContext().getRegistry().lookup(sailRepoNameParam, Repository.class); + checkNotNull(sailRepository, "Sail Repository must exist within the camel registry. Using lookup name[" + sailRepoNameParam + "]"); + + CbSailEndpoint sailEndpoint = new CbSailEndpoint(uri, this, sailRepository, remaining); + setProperties(sailEndpoint, parameters); + return sailEndpoint; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailEndpoint.java ---------------------------------------------------------------------- diff --git a/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailEndpoint.java b/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailEndpoint.java new file mode 100644 index 0000000..20a32d9 --- /dev/null +++ b/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailEndpoint.java @@ -0,0 +1,118 @@ +package mvm.rya.camel.cbsail; + +/* + * #%L + * mvm.rya.camel.rya + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import org.apache.camel.*; +import org.apache.camel.impl.DefaultEndpoint; +import org.openrdf.repository.Repository; + +import static com.google.common.base.Preconditions.*; + +/** + * setHeader(SPARQL, sqarlQuery).setHeader(TTL, ttl).to("cbsail:server?port=2181&user=user&pwd=pwd&instanceName=name").getBody(<Triple Map>) + */ +public class CbSailEndpoint extends DefaultEndpoint { + + + public enum CbSailOutput { + XML, BINARY + } + + private Long ttl; + private Repository sailRepository; + private String sparql; + private String tablePrefix; + private boolean infer = true; + private String queryOutput = CbSailOutput.BINARY.toString(); + + public CbSailEndpoint(String endpointUri, Component component, Repository sailRepository, String remaining) { + super(endpointUri, component); + this.sailRepository = sailRepository; + } + + protected void validate() { + checkNotNull(sailRepository); + } + + @Override + public Producer createProducer() throws Exception { + validate(); + return new CbSailProducer(this); + } + + @Override + public Consumer createConsumer(Processor processor) throws Exception { + throw new RuntimeCamelException((new StringBuilder()).append("Cannot consume from a CbSailEndpoint: ").append(getEndpointUri()).toString()); + } + + @Override + public boolean isSingleton() { + return true; + } + + public Long getTtl() { + return ttl; + } + + public void setTtl(Long ttl) { + this.ttl = ttl; + } + + public String getSparql() { + return sparql; + } + + public void setSparql(String sparql) { + this.sparql = sparql; + } + + public String getTablePrefix() { + return tablePrefix; + } + + public void setTablePrefix(String tablePrefix) { + this.tablePrefix = tablePrefix; + } + + public boolean isInfer() { + return infer; + } + + public void setInfer(boolean infer) { + this.infer = infer; + } + + public String getQueryOutput() { + return queryOutput; + } + + public void setQueryOutput(String queryOutput) { + this.queryOutput = queryOutput; + } + + public Repository getSailRepository() { + return sailRepository; + } + + public void setSailRepository(Repository sailRepository) { + this.sailRepository = sailRepository; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailProducer.java ---------------------------------------------------------------------- diff --git a/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailProducer.java b/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailProducer.java new file mode 100644 index 0000000..75a39ac --- /dev/null +++ b/osgi/camel.rya/src/main/java/mvm/rya/camel/cbsail/CbSailProducer.java @@ -0,0 +1,174 @@ +package mvm.rya.camel.cbsail; + +/* + * #%L + * mvm.rya.camel.rya + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import org.apache.camel.Exchange; +import org.apache.camel.impl.DefaultProducer; +import org.openrdf.model.Statement; +import org.openrdf.query.*; +import org.openrdf.query.resultio.sparqlxml.SPARQLResultsXMLWriter; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.RepositoryException; +import org.openrdf.rio.RDFHandlerException; + +import java.io.ByteArrayOutputStream; +import java.util.*; + +import static mvm.rya.api.RdfCloudTripleStoreConfiguration.*; +import static mvm.rya.camel.cbsail.CbSailComponent.SPARQL_QUERY_PROP; +import static mvm.rya.camel.cbsail.CbSailComponent.valueFactory; + +/** + */ +public class CbSailProducer extends DefaultProducer { + + private RepositoryConnection connection; + + private CbSailEndpoint.CbSailOutput queryOutput = CbSailEndpoint.CbSailOutput.BINARY; + + public CbSailProducer(CbSailEndpoint endpoint) { + super(endpoint); + } + + @Override + public void process(final Exchange exchange) throws Exception { + //If a query is set in the header or uri, use it + Collection<String> queries = new ArrayList<String>(); + Collection tmp = exchange.getIn().getHeader(SPARQL_QUERY_PROP, Collection.class); + if (tmp != null) { + queries = tmp; + } else { + String query = exchange.getIn().getHeader(SPARQL_QUERY_PROP, String.class); + if (query != null) { + queries.add(query); + } + } + + if (queries.size() > 0) + sparqlQuery(exchange, queries); + else + inputTriples(exchange); + } + + protected void inputTriples(Exchange exchange) throws RepositoryException { + Object body = exchange.getIn().getBody(); + if (body instanceof Statement) { + //save statement + inputStatement((Statement) body); + } else if (body instanceof List) { + //save list of statements + List lst = (List) body; + for (Object obj : lst) { + if (obj instanceof Statement) + inputStatement((Statement) obj); + } + } + connection.commit(); + exchange.getOut().setBody(Boolean.TRUE); + } + + protected void inputStatement(Statement stmt) throws RepositoryException { + connection.add(stmt.getSubject(), stmt.getPredicate(), stmt.getObject()); + } + + protected void sparqlQuery(Exchange exchange, Collection<String> queries) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, RDFHandlerException { + + List list = new ArrayList(); + for (String query : queries) { + +// Long startTime = exchange.getIn().getHeader(START_TIME_QUERY_PROP, Long.class); +// Long ttl = exchange.getIn().getHeader(TTL_QUERY_PROP, Long.class); + String auth = exchange.getIn().getHeader(CONF_QUERY_AUTH, String.class); + Boolean infer = exchange.getIn().getHeader(CONF_INFER, Boolean.class); + + Object output = performSelect(query, auth, infer); + if (queries.size() == 1) { + exchange.getOut().setBody(output); + return; + } else + list.add(output); + + } + exchange.getOut().setBody(list); + } + + protected Object performSelect(String query, String auth, Boolean infer) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException { + TupleQuery tupleQuery = connection.prepareTupleQuery( + QueryLanguage.SPARQL, query); + if (auth != null && auth.length() > 0) + tupleQuery.setBinding(CONF_QUERY_AUTH, valueFactory.createLiteral(auth)); + if (infer != null) + tupleQuery.setBinding(CONF_INFER, valueFactory.createLiteral(infer)); + if (CbSailEndpoint.CbSailOutput.BINARY.equals(queryOutput)) { + final List listOutput = new ArrayList(); + TupleQueryResultHandlerBase handler = new TupleQueryResultHandlerBase() { + @Override + public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException { + Map<String, String> map = new HashMap<String, String>(); + for (String s : bindingSet.getBindingNames()) { + map.put(s, bindingSet.getBinding(s).getValue().stringValue()); + } + listOutput.add(map); + } + }; + tupleQuery.evaluate(handler); + return listOutput; + } else if (CbSailEndpoint.CbSailOutput.XML.equals(queryOutput)) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + SPARQLResultsXMLWriter sparqlWriter = new SPARQLResultsXMLWriter(baos); + tupleQuery.evaluate(sparqlWriter); + return new String(baos.toByteArray()); + } else { + throw new IllegalArgumentException("Query Output[" + queryOutput + "] is not recognized"); + } + } + +// protected Object performConstruct(String query, Long ttl, Long startTime) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, RDFHandlerException { +// GraphQuery tupleQuery = connection.prepareGraphQuery( +// QueryLanguage.SPARQL, query); +// if (ttl != null && ttl > 0) +// tupleQuery.setBinding("ttl", valueFactory.createLiteral(ttl)); +// if (startTime != null && startTime > 0) +// tupleQuery.setBinding("startTime", valueFactory.createLiteral(startTime)); +// if (CbSailEndpoint.CbSailOutput.BINARY.equals(queryOutput)) { +// throw new IllegalArgumentException("In Graph Construct mode, cannot return Java object"); +// } else if (CbSailEndpoint.CbSailOutput.XML.equals(queryOutput)) { +// ByteArrayOutputStream baos = new ByteArrayOutputStream(); +// RDFXMLWriter rdfWriter = new RDFXMLWriter(baos); +// tupleQuery.evaluate(rdfWriter); +// return new String(baos.toByteArray()); +// } else { +// throw new IllegalArgumentException("Query Output[" + queryOutput + "] is not recognized"); +// } +// } + + + @Override + protected void doStart() throws Exception { + CbSailEndpoint cbSailEndpoint = (CbSailEndpoint) getEndpoint(); + connection = cbSailEndpoint.getSailRepository().getConnection(); + } + + @Override + protected void doStop() throws Exception { + connection.close(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/camel.rya/src/main/resources/META-INF/services/org/apache/camel/component/cbsail ---------------------------------------------------------------------- diff --git a/osgi/camel.rya/src/main/resources/META-INF/services/org/apache/camel/component/cbsail b/osgi/camel.rya/src/main/resources/META-INF/services/org/apache/camel/component/cbsail new file mode 100644 index 0000000..69cfb2d --- /dev/null +++ b/osgi/camel.rya/src/main/resources/META-INF/services/org/apache/camel/component/cbsail @@ -0,0 +1 @@ +class=mvm.rya.camel.cbsail.CbSailComponent \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailIntegrationTest.java ---------------------------------------------------------------------- diff --git a/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailIntegrationTest.java b/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailIntegrationTest.java new file mode 100644 index 0000000..8713b3a --- /dev/null +++ b/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailIntegrationTest.java @@ -0,0 +1,116 @@ +package mvm.rya.camel.cbsail; + +/* + * #%L + * mvm.rya.camel.rya + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import mvm.rya.camel.cbsail.CbSailComponent; +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.CamelTestSupport; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.ValueFactoryImpl; + +import java.util.HashMap; + +public class CbSailIntegrationTest extends CamelTestSupport { + + @EndpointInject(uri = "cbsail:tquery?server=stratus13&port=2181&user=root&pwd=password&instanceName=stratus") + ProducerTemplate producer; + + public void testCbSail() throws Exception { + String underGradInfo = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + + " PREFIX ub: <urn:test:onto:univ#>" + + " SELECT * WHERE" + + " {" + + " <http://www.Department0.University0.edu/UndergraduateStudent600> ?pred ?obj ." + + " }"; + HashMap map = new HashMap(); + map.put(CbSailComponent.SPARQL_QUERY_PROP, underGradInfo); + map.put(CbSailComponent.START_TIME_QUERY_PROP, 0l); + map.put(CbSailComponent.TTL_QUERY_PROP, 86400000l); + Object o = producer.requestBodyAndHeaders(null, map); + System.out.println(o); + Thread.sleep(100000); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + ValueFactory vf = new ValueFactoryImpl(); + String underGradInfo = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + + " PREFIX ub: <urn:test:onto:univ#>" + + " SELECT * WHERE" + + " {" + + " <http://www.Department0.University0.edu/UndergraduateStudent60> ?pred ?obj ." + + " }"; + String rawEvents = "PREFIX nh: <http://mvm.com/2011/02/nh#>\n" + + " SELECT * WHERE\n" + + " {\n" + + " ?uuid nh:timestamp ?timestamp.\n" + + " ?uuid nh:site ?site;\n" + + " nh:system ?system;\n" + + " nh:dataSupplier ?dataSupplier;\n" + + " nh:dataType ?dataType;\n" + + " <http://mvm.com/2011/02/nh#count> ?data.\n" + + " } LIMIT 100"; + String latestModels = "PREFIX nh: <http://mvm.com/rdf/2011/02/model#>" + + " PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" + + " SELECT * WHERE" + + " {" + + " ?modelUuid nh:dayOfWeek \"5\";" + + " nh:hourOfDay \"3\";" + + " nh:timestamp ?timestamp;" + +// " FILTER (xsd:integer(?timestamp) > 1297652964633)." + + " nh:dataProperty \"count\";" + + " nh:modelType \"mvm.learning.tpami.SimpleGaussianMMModel\";" + + " nh:site ?site;" + + " nh:dataSupplier ?dataSupplier;" + + " nh:system ?system;" + + " nh:dataType ?dataType;" + + " nh:model ?model;" + + " nh:key ?key." + + " }"; + + from("timer://foo?fixedRate=true&period=60000"). + setHeader(CbSailComponent.SPARQL_QUERY_PROP, constant(underGradInfo)). +// setBody(constant(new StatementImpl(vf.createURI("http://www.Department0.University0.edu/UndergraduateStudent610"), vf.createURI("urn:test:onto:univ#testPred"), vf.createLiteral("test")))). + to("cbsail:tquery?server=stratus13&port=2181&user=root&pwd=password&instanceName=stratus&queryOutput=XML" + +// "&ttl=259200000" +// + "&sparql=" + latestModels" + + "").process(new Processor() { + + @Override + public void process(Exchange exchange) throws Exception { + System.out.println(exchange.getIn().getBody()); +// if (body != null) +// System.out.println(body.size()); + } + }).end(); + } + }; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailPojoMain.java ---------------------------------------------------------------------- diff --git a/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailPojoMain.java b/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailPojoMain.java new file mode 100644 index 0000000..83b9f65 --- /dev/null +++ b/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailPojoMain.java @@ -0,0 +1,44 @@ +package mvm.rya.camel.cbsail; + +/* + * #%L + * mvm.rya.camel.rya + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import mvm.rya.camel.cbsail.CbSailComponent; +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; + +/** + * Class CbSailPojoMain + * Date: May 3, 2011 + * Time: 11:20:23 PM + */ +public class CbSailPojoMain { + + @EndpointInject(uri = "cbsail:tquery?server=stratus13&port=2181&user=root&pwd=password&instanceName=stratus") + ProducerTemplate producer; + + public void executeQuery(String sparql) { + Object o = producer.requestBodyAndHeader(null, CbSailComponent.SPARQL_QUERY_PROP, sparql); + System.out.println(o); + } + + public static void main(String[] args) { + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailTest.java ---------------------------------------------------------------------- diff --git a/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailTest.java b/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailTest.java new file mode 100644 index 0000000..d95ce25 --- /dev/null +++ b/osgi/camel.rya/src/test/java/mvm/rya/camel/cbsail/CbSailTest.java @@ -0,0 +1,204 @@ +package mvm.rya.camel.cbsail; + +/* + * #%L + * mvm.rya.camel.rya + * %% + * Copyright (C) 2014 Rya + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import mvm.rya.accumulo.AccumuloRdfConfiguration; +import mvm.rya.accumulo.AccumuloRyaDAO; +import mvm.rya.api.RdfCloudTripleStoreConfiguration; +import mvm.rya.api.RdfCloudTripleStoreConstants; +import mvm.rya.rdftriplestore.RdfCloudTripleStore; +import mvm.rya.rdftriplestore.RyaSailRepository; +import mvm.rya.rdftriplestore.inference.InferenceEngine; +import mvm.rya.rdftriplestore.namespace.NamespaceManager; +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.mock.MockInstance; +import org.apache.camel.EndpointInject; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.test.CamelTestSupport; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.StatementImpl; +import org.openrdf.repository.Repository; +import org.openrdf.repository.RepositoryConnection; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + */ +public class CbSailTest extends CamelTestSupport { + + static String litdupsNS = "urn:test:litdups#"; + + private RdfCloudTripleStore store; + private Repository repository; + private ValueFactory vf = RdfCloudTripleStoreConstants.VALUE_FACTORY; + + @EndpointInject(uri = "mock:results") + protected MockEndpoint resultEndpoint; + + @Produce(uri = "direct:query") + protected ProducerTemplate template; + + @Override + public void setUp() throws Exception { + super.setUp(); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + repository.shutDown(); + } + + @Override + protected JndiRegistry createRegistry() throws Exception { + store = new MockRdfCloudStore(); +// store.setDisplayQueryPlan(true); +// store.setInferencing(false); + NamespaceManager nm = new NamespaceManager(store.getRyaDAO(), store.getConf()); + store.setNamespaceManager(nm); + repository = new RyaSailRepository(store); + repository.initialize(); + + JndiRegistry registry = super.createRegistry(); + registry.bind(Repository.class.getName(), repository); + return registry; + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + + @Override + public void configure() throws Exception { + from("direct:query"). + to("cbsail:queryEndpoint"). + to("mock:results"); + } + }; + } + + public void testSimpleQuery() throws Exception { + RepositoryConnection conn = repository.getConnection(); + URI cpu = vf.createURI(litdupsNS, "cpu"); + URI loadPerc = vf.createURI(litdupsNS, "loadPerc"); + URI uri1 = vf.createURI(litdupsNS, "uri1"); + conn.add(cpu, loadPerc, uri1); + conn.commit(); + conn.close(); + + resultEndpoint.expectedMessageCount(1); + + //query through camel + String query = "select * where {" + + "<" + cpu.toString() + "> ?p ?o1." + + "}"; + template.sendBodyAndHeader(null, CbSailComponent.SPARQL_QUERY_PROP, query); + + assertMockEndpointsSatisfied(); + } + + public void testSimpleQueryAuth() throws Exception { + RepositoryConnection conn = repository.getConnection(); + URI cpu = vf.createURI(litdupsNS, "cpu"); + URI loadPerc = vf.createURI(litdupsNS, "loadPerc"); + URI uri1 = vf.createURI(litdupsNS, "uri1"); + URI uri2 = vf.createURI(litdupsNS, "uri2"); + URI auth1 = vf.createURI(RdfCloudTripleStoreConstants.AUTH_NAMESPACE, "auth1"); + conn.add(cpu, loadPerc, uri1, auth1); + conn.add(cpu, loadPerc, uri2); + conn.commit(); + conn.close(); + + resultEndpoint.expectedMessageCount(1); + + //query through camel + String query = "select * where {" + + "<" + cpu.toString() + "> ?p ?o1." + + "}"; + template.sendBodyAndHeader(null, CbSailComponent.SPARQL_QUERY_PROP, query); + + assertMockEndpointsSatisfied(); + + resultEndpoint.expectedMessageCount(2); + + query = "select * where {" + + "<" + cpu.toString() + "> ?p ?o1." + + "}"; + Map<String, Object> headers = new HashMap<String, Object>(); + headers.put(CbSailComponent.SPARQL_QUERY_PROP, query); + headers.put(RdfCloudTripleStoreConfiguration.BINDING_AUTH, "auth1"); + template.sendBodyAndHeaders(null, headers); + + assertMockEndpointsSatisfied(); + } + + public void testInsertData() throws Exception { + URI cpu = vf.createURI(litdupsNS, "cpu"); + URI loadPerc = vf.createURI(litdupsNS, "loadPerc"); + URI uri1 = vf.createURI(litdupsNS, "uri1"); + URI uri2 = vf.createURI(litdupsNS, "uri2"); + List<Statement> insert = new ArrayList<Statement>(); + insert.add(new StatementImpl(cpu, loadPerc, uri1)); + insert.add(new StatementImpl(cpu, loadPerc, uri2)); + + resultEndpoint.expectedBodiesReceived(true); + template.sendBody(insert); + assertMockEndpointsSatisfied(); + + resultEndpoint.expectedMessageCount(2); + String query = "select * where {" + + "<" + cpu.toString() + "> ?p ?o1." + + "}"; + template.sendBodyAndHeader(null, CbSailComponent.SPARQL_QUERY_PROP, query); + assertMockEndpointsSatisfied(); + } + + public class MockRdfCloudStore extends RdfCloudTripleStore { + + public MockRdfCloudStore() { + super(); + Instance instance = new MockInstance(); + try { + Connector connector = instance.getConnector("", ""); + setConf(new AccumuloRdfConfiguration()); + AccumuloRyaDAO cdao = new AccumuloRyaDAO(); + cdao.setConnector(connector); + setRyaDAO(cdao); + inferenceEngine = new InferenceEngine(); + inferenceEngine.setRyaDAO(cdao); + inferenceEngine.setRefreshGraphSchedule(1000); //every sec + setInferenceEngine(inferenceEngine); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/pom.xml ---------------------------------------------------------------------- diff --git a/osgi/pom.xml b/osgi/pom.xml new file mode 100644 index 0000000..36df7b1 --- /dev/null +++ b/osgi/pom.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="utf-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <properties> + <maven-bundle-plugin.version>2.1.0</maven-bundle-plugin.version> + </properties> + <parent> + <groupId>mvm.rya</groupId> + <artifactId>parent</artifactId> + <version>3.2.9</version> + </parent> + <artifactId>rya.osgi</artifactId> + <packaging>pom</packaging> + <name>${project.groupId}.${project.artifactId}</name> + <modules> + <module>alx.rya</module> + <module>alx.rya.console</module> + <module>camel.rya</module> + </modules> + <build> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <version>${maven-bundle-plugin.version}</version> + <extensions>true</extensions> + <configuration> + <manifestLocation>META-INF</manifestLocation> + <instructions> + <Bundle-SymbolicName>${project.groupId}.${project.artifactId} + </Bundle-SymbolicName> + <Bundle-Version>${project.version}</Bundle-Version> + <Import-Package>*</Import-Package> + <_exportcontents>*</_exportcontents> + <Bundle-ClassPath>.</Bundle-ClassPath> + <!--<DynamicImport-Package>*</DynamicImport-Package>--> + </instructions> + </configuration> + <executions> + <execution> + <id>genManifest</id> + <phase>process-classes</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/92ddfa59/osgi/sesame-runtime-osgi/openrdf-sesame-osgi.bnd ---------------------------------------------------------------------- diff --git a/osgi/sesame-runtime-osgi/openrdf-sesame-osgi.bnd b/osgi/sesame-runtime-osgi/openrdf-sesame-osgi.bnd new file mode 100644 index 0000000..c0aea07 --- /dev/null +++ b/osgi/sesame-runtime-osgi/openrdf-sesame-osgi.bnd @@ -0,0 +1,7 @@ +-classpath= target/sesame-runtime-osgi.jar +-output= target/sesame-runtime-osgi-2.6.4.jar +Import-Package= *;resolution:=optional +Export-Package= * +Bundle-Version= 2.6.4 +Bundle-SymbolicName= sesame-runtime-osgi +DynamicImport-Package= *
