Skip to content

Commit

Permalink
Merge branch 'vmExamplePR318' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lotts committed Dec 9, 2020
2 parents abd3910 + 5c8b228 commit cc752d4
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 19 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Apache Rya (Incubating)
Copyright 2015-2018 The Apache Software Foundation
Copyright 2015-2020 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class IndexingFunctionRegistry {

}

public enum FUNCTION_TYPE {GEO, TEMPORAL, FREETEXT}
public enum FUNCTION_TYPE {GEO, TEMPORAL, FREETEXT, NONE}

public static Set<IRI> getFunctions() {
return SEARCH_FUNCTIONS.keySet();
Expand All @@ -73,7 +73,7 @@ public static Set<IRI> getFunctions() {

public static Var getResultVarFromFunctionCall(IRI function, List<ValueExpr> args) {

FUNCTION_TYPE type = SEARCH_FUNCTIONS.get(function);
FUNCTION_TYPE type = SEARCH_FUNCTIONS.getOrDefault(function, FUNCTION_TYPE.NONE);

switch(type) {
case GEO:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.rya.indexing;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.util.ArrayList;
import java.util.List;

import org.apache.accumulo.core.client.AccumuloException;
import org.apache.accumulo.core.client.AccumuloSecurityException;
import org.apache.accumulo.core.client.Connector;
import org.apache.rya.accumulo.AccumuloRdfConfiguration;
import org.apache.rya.accumulo.AccumuloRyaDAO;
import org.apache.rya.api.RdfCloudTripleStoreConfiguration;
import org.apache.rya.api.persist.RyaDAOException;
import org.apache.rya.indexing.accumulo.ConfigUtils;
import org.apache.rya.rdftriplestore.inference.InferenceEngineException;
import org.apache.rya.sail.config.RyaSailFactory;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.QueryLanguage;
import org.eclipse.rdf4j.query.TupleQueryResult;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.Sail;
import org.junit.Test;

public class IndexingFunctionRegistryFreeTextTest {

private final static String STRING_LENGTH_QUERY = "select (strlen(?o) AS ?o_len) WHERE { ?s <http://worksAt> ?o } LIMIT 1";

private Sail accumuloSail;
private Repository accumuloRepo;
private RepositoryConnection accumuloConn;
private AccumuloRyaDAO accumuloDao;

@Test
public void accumuloConnTest1() throws Exception {
this.init(getAccumuloConf(true));
this.sparqlConnTest(this.accumuloConn, STRING_LENGTH_QUERY);
this.close();
}

@Test
public void accumuloConnTest2() throws Exception {
this.init(getAccumuloConf(false));
this.sparqlConnTest(this.accumuloConn, STRING_LENGTH_QUERY);
this.close();
}


private void init(RdfCloudTripleStoreConfiguration conf) throws AccumuloSecurityException, InferenceEngineException, AccumuloException, RyaDAOException {

this.accumuloSail = RyaSailFactory.getInstance(conf);
this.accumuloRepo = new SailRepository(accumuloSail);
this.accumuloConn = this.accumuloRepo.getConnection();

Connector conn = ConfigUtils.getConnector(conf);
this.accumuloDao = new AccumuloRyaDAO();
this.accumuloDao.setConnector(conn);
this.accumuloDao.init();
}

private void close() throws RyaDAOException {
this.accumuloConn.close();
this.accumuloRepo.shutDown();
this.accumuloSail.shutDown();
this.accumuloDao.destroy();
}

private RdfCloudTripleStoreConfiguration getAccumuloConf(boolean useFreeText) {
RdfCloudTripleStoreConfiguration conf;
conf = new AccumuloRdfConfiguration();
conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, true);
conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, "rya_");
conf.set(AccumuloRdfConfiguration.CLOUDBASE_USER, "root");
conf.set(AccumuloRdfConfiguration.CLOUDBASE_PASSWORD, "");
conf.set(AccumuloRdfConfiguration.CLOUDBASE_INSTANCE, "instance");
conf.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, "");
conf.setBoolean(ConfigUtils.DISPLAY_QUERY_PLAN, true);

conf.setBoolean(ConfigUtils.USE_FREETEXT, useFreeText);

if (useFreeText) {
conf.setStrings(ConfigUtils.FREETEXT_PREDICATES_LIST, RDFS.LABEL.stringValue());
}

return conf;
}

private void sparqlConnTest(RepositoryConnection conn, String query) throws Exception {
ValueFactory vf = SimpleValueFactory.getInstance();

Statement s = vf.createStatement(vf.createIRI("http://Joe"), vf.createIRI("http://worksAt"), vf.createLiteral("CoffeeShop"));
conn.add(s);

TupleQueryResult result = null;
Exception e = null;
List<BindingSet> results = new ArrayList<>();
String o_len = "";

try {
result = conn.prepareTupleQuery(QueryLanguage.SPARQL, query).evaluate();

while (result.hasNext()) {
BindingSet bSet = result.next();
o_len = bSet.getValue("o_len").stringValue();
results.add(bSet);
}

} catch (Exception ex) {
e = ex;
}

assertNull(e);
assertNotNull(result);
assertNotEquals(0, results.size());
assertEquals("10", o_len);

conn.remove(s);
}
}
41 changes: 26 additions & 15 deletions extras/vagrantExample/src/main/vagrant/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ Vagrant.configure(2) do |config|
config.vm.hostname = "rya-example-box"

config.vm.provision "shell", inline: <<-SHELL
# fixme #######################################
set -x ## turn on command echo with expanded variables
set -x ## turn on command echo with expanded variables
# List of dependency versions
export ACCUMULO_VERSION=1.6.6
export HADOOP_VERSION=2.7.2
Expand All @@ -62,11 +61,13 @@ Vagrant.configure(2) do |config|
EOF
sudo -E apt-get -qq update
echo "Installing Java installer..."
# if you want dev tools like javac, change this to openjdk-8-jdk-headless
# if you want dev tools like javac, change this to openjdk-8-jdk-headless
sudo -E apt-get install -y openjdk-8-jre || exit $?
echo "Installing Tomcat..."
sudo useradd -r -m -U -d /opt/tomcat -s /bin/false tomcat
sudo -E apt-get install -y tomcat9 || exit $?
sudo usermod -a -G tomcat vagrant
echo "Installing Unzip..."
apt-get install unzip || exit $?
echo "Setting up environment..."
Expand Down Expand Up @@ -257,18 +258,28 @@ EOF
echo 'Done!'
# --------------------
echo "Installing RDF4J Server"
# creating log dir rdf4j-http-server-${RDF4J_VERSION}
sudo mkdir --parents /usr/share/tomcat9/.RDF4J
sudo chown -R tomcat:tomcat /usr/share/tomcat9
sudo ln --force -s /usr/share/tomcat9/.RDF4J/Server/logs /var/log/tomcat9/rdf4j-server
# create a property that the app will pickup. It defaults to $HOME.
sudo echo 'export JAVA_OPTS="-Dorg.eclipse.rdf4j.appdata.basedir=/var/lib/tomcat9/webapps/rdf4j-server/"' | sudo tee --append '/usr/share/tomcat9/bin/setenv.sh'
# this is the rdf4j data dir. It might need to be registered with tomcat to write there.
export rdf4jServerBase=/opt/tomcat/
sudo install -d -o tomcat -m u=rwx,go=rx ${rdf4jServerBase}
sudo -u tomcat mkdir --parents ${rdf4jServerBase}/server/logs
sudo -u tomcat mkdir --parents ${rdf4jServerBase}/.RDF4J/server/logs
# tomcat v9 requires explicit permissions to the file system.
sudo mkdir --parents /etc/systemd/system/tomcat9.service.d
cat <<EOF | sudo tee --append /etc/systemd/system/tomcat9.service.d/logging-allow.conf
[Service]
ReadWritePaths=${rdf4jServerBase}
EOF
echo 'Restarting Tomcat (or starting)'
sudo -E systemctl daemon-reload || exit 1080
sudo -E systemctl enable tomcat9 || exit 1081
sudo -E systemctl restart tomcat9 || exit 1082
rdf4jwar=/var/lib/tomcat9/webapps/rdf4j-server.war
if [[ ! -s $rdf4jwar ]] ; then
echo "Downloading RDF4J Server"
download --output $rdf4jwar ${mavenRepoUrl}org/eclipse/rdf4j/rdf4j-http-server/${RDF4J_VERSION}/rdf4j-http-server-${RDF4J_VERSION}.war || exit 110
fi
echo "RDF4J http server deployed at http://rya-example-box:8080/rdf4j-server"
# --------------------
echo "Installing RDF4J Workbench"
workbench=/var/lib/tomcat9/webapps/rdf4j-workbench.war
if [[ ! -s $workbench ]] ; then
Expand All @@ -294,16 +305,16 @@ EOF
waitForDeploy /var/lib/tomcat9/webapps/rdf4j-workbench/WEB-INF/lib/
waitForDeploy /var/lib/tomcat9/webapps/rdf4j-server/WEB-INF/lib/
# soft linking the files doesn't seem to work in tomcat, so we copy them instead :(
sudo cp ${ryaIndexing}/dist/lib/* /var/lib/tomcat9/webapps/rdf4j-workbench/WEB-INF/lib/ || exit 113
sudo cp ${ryaIndexing}/dist/lib/* /var/lib/tomcat9/webapps/rdf4j-server/WEB-INF/lib/ || exit 114
sudo -u tomcat cp ${ryaIndexing}/dist/lib/* /var/lib/tomcat9/webapps/rdf4j-workbench/WEB-INF/lib/ || exit 113
sudo -u tomcat cp ${ryaIndexing}/dist/lib/* /var/lib/tomcat9/webapps/rdf4j-server/WEB-INF/lib/ || exit 114
# These are older libs that break tomcat and rdf4j that come with Rya above.
sudo rm --force /var/lib/tomcat9/webapps/rdf4j-workbench/WEB-INF/lib/servlet-api-2.5.jar
sudo rm --force /var/lib/tomcat9/webapps/rdf4j-workbench/WEB-INF/lib/jsp-api-2.1.jar
s=/var/lib/tomcat9/webapps/rdf4j-server/WEB-INF/lib/
sudo rm --force $s/servlet-api-2.5.jar $s/lib/jsp-api-2.1.jar
sudo find "$s" -name 'spring-*-3.*.jar' -exec sudo rm --force {} +
sudo rm $s/spring-aop-4.2.1.RELEASE.jar $s/rdf4j-http-server-spring-2.3.1.jar
sudo rm --force $s/slf4j-log4j12-1.7.25.jar $s/slf4j-api-1.7.25.jar $s/jcabi-log-0.14.jar $s/jcl-over-slf4j-1.7.25.jar $s/minlog-1.3.0.jar $s/commons-logging-1.1.1.jar $s/log4j-1.2.16.jar
sudo rm --force $s/slf4j-log4j12-1.7.25.jar $s/slf4j-api-1.7.25.jar $s/jcabi-log-0.14.jar $s/jcl-over-slf4j-1.7.25.jar $s/minlog-1.3.0.jar $s/commons-logging-1.1.1.jar $s/log4j-1.2.16.jar
sudo chown -R tomcat:tomcat /var/lib/tomcat9/webapps/rdf4j-workbench/WEB-INF/lib/
sudo chown -R tomcat:tomcat /var/lib/tomcat9/webapps/rdf4j-server/WEB-INF/lib/
# ----------------------
Expand All @@ -321,7 +332,7 @@ EOF
sudo mkdir --parents ${ryaVagrant}
sudo unzip -q -o ${ryaVagrant}.jar -d ${ryaVagrant}
waitForDeploy /var/lib/tomcat9/webapps/rdf4j-workbench/transformations
sudo cp ${ryaVagrant}/*.xsl /var/lib/tomcat9/webapps/rdf4j-workbench/transformations/
sudo -u tomcat cp ${ryaVagrant}/*.xsl /var/lib/tomcat9/webapps/rdf4j-workbench/transformations/
sudo chown tomcat:tomcat /var/lib/tomcat9/webapps/rdf4j-workbench/transformations/*
# ----------------------
echo "Deploying Rya Web"
Expand All @@ -338,7 +349,7 @@ EOF
fi
# remove this so we can wait for it to be recreated.
sudo rm -rf /var/lib/tomcat9/webapps/web.rya/WEB-INF/classes
sudo cp ${ryaWar} /var/lib/tomcat9/webapps/web.rya.war
sudo -u tomcat cp ${ryaWar} /var/lib/tomcat9/webapps/web.rya.war
# Wait for the war to deploy
waitForDeploy /var/lib/tomcat9/webapps/web.rya/WEB-INF/classes/
# These are older libs that break tomcat
Expand All @@ -356,7 +367,7 @@ rya.displayqueryplan=true
EOF
echo "Rya web deployed at http://rya-example-box:8080/web.rya/sparqlQuery.jsp"
# restart tomcat
sudo -E service tomcat9 restart
systemctl restart tomcat9 || exit $?
echo "Finished and ready to use!"
echo "You can re-apply these settings without losing data by running the command 'vagrant provision'"
SHELL
Expand Down
2 changes: 1 addition & 1 deletion osgi/rdf4j-runtime-osgi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ under the License.
</snapshots>
<id>bndrepo</id>
<name>aQute BND Repo</name>
<url>http://www.aqute.biz/repo</url>
<url>https://www.aqute.biz/repo</url>
</repository>
</repositories>
</project>

0 comments on commit cc752d4

Please sign in to comment.