RYA-104 most interactors complete.
Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/33a04863 Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/33a04863 Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/33a04863 Branch: refs/heads/master Commit: 33a04863581e5a875b2ec9bd23a488b3595640db Parents: 7b571d4 Author: David W. Lotts <david.lo...@parsons.com> Authored: Wed Dec 13 17:34:55 2017 -0500 Committer: kchilton2 <kevin.e.chil...@gmail.com> Committed: Fri Jan 5 16:48:40 2018 -0500 ---------------------------------------------------------------------- .../org/apache/rya/api/client/RyaClient.java | 12 +- .../mongodb/instance/MongoDetailsAdapter.java | 26 +-- .../MongoRyaInstanceDetailsRepository.java | 12 +- .../rya/api/client/mongo/MongoCommand.java | 65 ++++++ .../client/mongo/MongoConnectionDetails.java | 93 +++++++++ .../rya/api/client/mongo/MongoCreatePCJ.java | 58 ++++++ .../rya/api/client/mongo/MongoDeletePCJ.java | 51 +++++ .../client/mongo/MongoGetInstanceDetails.java | 80 ++++++++ .../rya/api/client/mongo/MongoInstall.java | 199 +++++++++++++++++++ .../api/client/mongo/MongoInstanceExists.java | 53 +++++ .../api/client/mongo/MongoListInstances.java | 68 +++++++ .../api/client/mongo/MongoLoadStatements.java | 29 +++ .../client/mongo/MongoLoadStatementsFile.java | 87 ++++++++ .../api/client/mongo/MongoRyaClientFactory.java | 66 ++++++ .../rya/api/client/mongo/MongoUninstall.java | 61 ++++++ .../client/mongo/MongoGetInstanceDetailsIT.java | 123 ++++++++++++ .../rya/api/client/mongo/MongoInstallIT.java | 105 ++++++++++ .../api/client/mongo/MongoInstanceExistsIT.java | 86 ++++++++ .../api/client/mongo/MongoListInstancesIT.java | 71 +++++++ .../client/mongo/MongoLoadStatementsFileIT.java | 132 ++++++++++++ .../rya/api/client/mongo/MongoUninstallIT.java | 78 ++++++++ 21 files changed, 1531 insertions(+), 24 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClient.java ---------------------------------------------------------------------- diff --git a/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClient.java b/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClient.java index 1278193..0a55edb 100644 --- a/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClient.java +++ b/common/rya.api/src/main/java/org/apache/rya/api/client/RyaClient.java @@ -74,16 +74,16 @@ public class RyaClient { this.createPeriodicPcj = createPeriodicPcj; this.deletePeriodicPcj = deletePeriodicPcj; this.listIncrementalQueries = listIncrementalQueries; - this.bactchUpdatePCJ = requireNonNull(batchUpdatePcj); + this.bactchUpdatePCJ = batchUpdatePcj; this.getInstanceDetails = requireNonNull(getInstanceDetails); this.instanceExists = requireNonNull(instanceExists); this.listInstances = requireNonNull(listInstances); - this.addUser = requireNonNull(addUser); - this.removeUser = requireNonNull(removeUser); + this.addUser = addUser; + this.removeUser = removeUser; this.uninstall = requireNonNull(uninstall); - this.loadStatements = requireNonNull(loadStatements); - this.loadStatementsFile = requireNonNull(loadStatementsFile); - this.executeSparqlQuery = requireNonNull(executeSparqlQuery); + this.loadStatements = loadStatements; // FIXME requireNonNull(loadStatements); + this.loadStatementsFile = loadStatementsFile; // FIXME requireNonNull(loadStatementsFile); + this.executeSparqlQuery = executeSparqlQuery; // FIXME requireNonNull(executeSparqlQuery); } /** http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoDetailsAdapter.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoDetailsAdapter.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoDetailsAdapter.java index d11af76..3b77a88 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoDetailsAdapter.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoDetailsAdapter.java @@ -24,9 +24,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; - import org.apache.rya.api.instance.RyaDetails; import org.apache.rya.api.instance.RyaDetails.EntityCentricIndexDetails; import org.apache.rya.api.instance.RyaDetails.FreeTextIndexDetails; @@ -45,6 +42,9 @@ import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObjectBuilder; import com.mongodb.DBObject; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + /** * Serializes configuration details for use in Mongo. * The {@link DBObject} will look like: @@ -182,15 +182,17 @@ public class MongoDetailsAdapter { private static PCJIndexDetails.Builder getPCJIndexDetails(final BasicDBObject basicObj) { final BasicDBObject pcjIndexDBO = (BasicDBObject) basicObj.get(PCJ_DETAILS_KEY); - final PCJIndexDetails.Builder pcjBuilder = PCJIndexDetails.builder() - .setEnabled(pcjIndexDBO.getBoolean(PCJ_ENABLED_KEY)) - .setFluoDetails(new FluoDetails(pcjIndexDBO.getString(PCJ_FLUO_KEY))); - - final BasicDBList pcjs = (BasicDBList) pcjIndexDBO.get(PCJ_PCJS_KEY); - if(pcjs != null) { - for(int ii = 0; ii < pcjs.size(); ii++) { - final BasicDBObject pcj = (BasicDBObject) pcjs.get(ii); - pcjBuilder.addPCJDetails( toPCJDetails(pcj) ); + final PCJIndexDetails.Builder pcjBuilder = PCJIndexDetails.builder(); + if (!pcjIndexDBO.getBoolean(PCJ_ENABLED_KEY)) { + pcjBuilder.setEnabled(false); + } else { + pcjBuilder.setEnabled(true).setFluoDetails(new FluoDetails(pcjIndexDBO.getString(PCJ_FLUO_KEY))); + final BasicDBList pcjs = (BasicDBList) pcjIndexDBO.get(PCJ_PCJS_KEY); + if (pcjs != null) { + for (int ii = 0; ii < pcjs.size(); ii++) { + final BasicDBObject pcj = (BasicDBObject) pcjs.get(ii); + pcjBuilder.addPCJDetails(toPCJDetails(pcj)); + } } } return pcjBuilder; http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoRyaInstanceDetailsRepository.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoRyaInstanceDetailsRepository.java b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoRyaInstanceDetailsRepository.java index 4a961be..9bb558e 100644 --- a/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoRyaInstanceDetailsRepository.java +++ b/dao/mongodb.rya/src/main/java/org/apache/rya/mongodb/instance/MongoRyaInstanceDetailsRepository.java @@ -22,8 +22,9 @@ package org.apache.rya.mongodb.instance; import static com.google.common.base.Preconditions.checkNotNull; import static java.util.Objects.requireNonNull; -import edu.umd.cs.findbugs.annotations.DefaultAnnotation; -import edu.umd.cs.findbugs.annotations.NonNull; +import org.apache.rya.api.instance.RyaDetails; +import org.apache.rya.api.instance.RyaDetailsRepository; +import org.apache.rya.mongodb.instance.MongoDetailsAdapter.MalformedRyaDetailsException; import com.mongodb.BasicDBObject; import com.mongodb.DB; @@ -32,9 +33,8 @@ import com.mongodb.DBObject; import com.mongodb.MongoClient; import com.mongodb.WriteResult; -import org.apache.rya.api.instance.RyaDetails; -import org.apache.rya.api.instance.RyaDetailsRepository; -import org.apache.rya.mongodb.instance.MongoDetailsAdapter.MalformedRyaDetailsException; +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; /** * An implementation of {@link RyaDetailsRepository} that stores a Rya @@ -42,7 +42,7 @@ import org.apache.rya.mongodb.instance.MongoDetailsAdapter.MalformedRyaDetailsEx */ @DefaultAnnotation(NonNull.class) public class MongoRyaInstanceDetailsRepository implements RyaDetailsRepository { - private static final String INSTANCE_DETAILS_COLLECTION_NAME = "instance_details"; + public static final String INSTANCE_DETAILS_COLLECTION_NAME = "instance_details"; private final DB db; private final String instanceName; http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoCommand.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoCommand.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoCommand.java new file mode 100644 index 0000000..24bae95 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoCommand.java @@ -0,0 +1,65 @@ +/** + * 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.api.client.mongo; + +import static java.util.Objects.requireNonNull; + +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An abstract class that holds onto Mongo access information. Extend this + * when implementing a command that interacts with Mongo. + */ +@DefaultAnnotation(NonNull.class) +public abstract class MongoCommand { + + private final MongoConnectionDetails connectionDetails; + private final MongoClient client; + + /** + * Constructs an instance of {@link MongoCommand}. + * + * Details about the values that were used to create the client. (not null) + * + * @param client + * - Provides programatic access to the instance of Mongo + * that hosts Rya instance. (not null) + */ + public MongoCommand(final MongoConnectionDetails connectionDetails, final MongoClient client) { + this.connectionDetails = requireNonNull(connectionDetails); + this.client = requireNonNull(client); + } + + /** + * @return Details about the values that were used to create the connector to mongo. (not null) + */ + public MongoConnectionDetails getMongoConnectionDetails() { + return connectionDetails; + } + + /** + * @return Provides programatic access to the instance of Mongo that hosts Rya instance. + */ + public MongoClient getClient() { + return client; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoConnectionDetails.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoConnectionDetails.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoConnectionDetails.java new file mode 100644 index 0000000..16e0453 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoConnectionDetails.java @@ -0,0 +1,93 @@ +/** + * 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.api.client.mongo; + +import static java.util.Objects.requireNonNull; + +import org.apache.rya.accumulo.AccumuloRdfConfiguration; +import org.apache.rya.mongodb.MongoDBRdfConfiguration; +public class MongoConnectionDetails { + private String username; + private char[] userPass; + private String instance; + private String host; + private String collectionName; + + public MongoConnectionDetails(String username, char[] userPass, String instance, String host, String ryaInstance) { + this.username = username; + this.userPass = userPass.clone(); + this.instance = instance; + this.host = host; + this.collectionName = requireNonNull(ryaInstance); + } + + /** + * @return the username + */ + public String getUsername() { + return this.username; + } + + /** + * @return the password + */ + public char[] getPassword() { + return this.userPass; + } + + /** + * @return the instance + */ + public String getInstance() { + return instance; + } + + /** + * @return the host AKA MongoInstance + */ + public String getHost() { + return host; + } + /** + * @return The Collection/Rya Prefix/Rya instance that was used to establish the connection. + */ + public String getCollectionName() { + return collectionName; + } + + /** + * + * @param ryaInstanceName + * - The Rya instance to connect to. + * @return Constructs a new {@link AccumuloRdfConfiguration} object with values from this object. + */ + public MongoDBRdfConfiguration build(final String ryaInstanceName) { + + // Note, we don't use the MongoDBRdfConfigurationBuilder here because it explicitly sets + // authorizations and visibilities to an empty string if they are not set on the builder. + // If they are null in the MongoRdfConfiguration object, it may do the right thing. + final MongoDBRdfConfiguration conf = new MongoDBRdfConfiguration(); + conf.setMongoInstance(host); + conf.setCollectionName(ryaInstanceName); + conf.setMongoUser(username); + conf.setMongoPassword(new String(userPass)); + return conf; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoCreatePCJ.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoCreatePCJ.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoCreatePCJ.java new file mode 100644 index 0000000..30d0f14 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoCreatePCJ.java @@ -0,0 +1,58 @@ +/** + * 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.api.client.mongo; + +import java.util.Set; + +import org.apache.rya.api.client.CreatePCJ; +import org.apache.rya.api.client.InstanceDoesNotExistException; +import org.apache.rya.api.client.RyaClientException; + +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An Mongo implementation of the {@link CreatePCJ} command. + */ +@DefaultAnnotation(NonNull.class) +public class MongoCreatePCJ extends MongoCommand implements CreatePCJ { + + /** + * Constructs an instance of {@link MongoCreatePCJ}. + * + * @param connectionDetails - Details about the values that were used to create the connector to the cluster. (not null) + * @param client - Provides programatic access to the instance of Mongo + * that hosts Rya instance. (not null) + */ + public MongoCreatePCJ(final MongoConnectionDetails connectionDetails, final MongoClient client) { + super(connectionDetails, client); + } + + @Override + public String createPCJ(final String instanceName, final String sparql) throws InstanceDoesNotExistException { + throw new UnsupportedOperationException("Mongo does not support PCJ indexing."); + } + + @Override + public String createPCJ(String instanceName, String sparql, Set<ExportStrategy> strategies) throws InstanceDoesNotExistException, RyaClientException { + throw new UnsupportedOperationException("Mongo does not support PCJ indexing."); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoDeletePCJ.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoDeletePCJ.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoDeletePCJ.java new file mode 100644 index 0000000..6e16bf0 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoDeletePCJ.java @@ -0,0 +1,51 @@ +/** + * 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.api.client.mongo; + +import org.apache.rya.api.client.DeletePCJ; +import org.apache.rya.api.client.InstanceDoesNotExistException; +import org.apache.rya.api.client.RyaClientException; + +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An Mongo implementation of the {@link DeletePCJ} command. + */ +@DefaultAnnotation(NonNull.class) +public class MongoDeletePCJ extends MongoCommand implements DeletePCJ { + + /** + * Constructs an instance of {@link MongoDeletePCJ}. + * + * @param connectionDetails Details about the values that were used to create the connector to the cluster. (not null) + * @param client Provides programatic access to the instance of Mongo + * that hosts Rya instance. (not null) + */ + public MongoDeletePCJ(final MongoConnectionDetails connectionDetails, final MongoClient client) { + super(connectionDetails, client); + } + + @Override + public void deletePCJ(final String instanceName, final String pcjId) throws InstanceDoesNotExistException, RyaClientException { + throw new UnsupportedOperationException("Mongo does not support PCJ Indexing."); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetails.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetails.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetails.java new file mode 100644 index 0000000..1bfa97a --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetails.java @@ -0,0 +1,80 @@ +/** + * 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.api.client.mongo; + +import static java.util.Objects.requireNonNull; + +import org.apache.rya.api.client.GetInstanceDetails; +import org.apache.rya.api.client.InstanceDoesNotExistException; +import org.apache.rya.api.client.InstanceExists; +import org.apache.rya.api.client.RyaClientException; +import org.apache.rya.api.instance.RyaDetails; +import org.apache.rya.api.instance.RyaDetailsRepository; +import org.apache.rya.api.instance.RyaDetailsRepository.NotInitializedException; +import org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException; +import org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository; + +import com.google.common.base.Optional; +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An Mongo implementation of the {@link GetInstanceDetails} command. + */ +@DefaultAnnotation(NonNull.class) +public class MongoGetInstanceDetails extends MongoCommand implements GetInstanceDetails { + + private final InstanceExists instanceExists; + + /** + * Constructs an instance of {@link MongoGetInstanceDetails}. + * + * @param connectionDetails + * - Details about the values that were used to create the connector to the cluster. (not null) + * @param client + * - Provides programatic access to the instance of Mongo + * that hosts Rya instance. (not null) + */ + public MongoGetInstanceDetails(final MongoConnectionDetails connectionDetails, final MongoClient client) { + super(connectionDetails, client); + instanceExists = new MongoInstanceExists(connectionDetails, client); + } + + @Override + public Optional<RyaDetails> getDetails(final String ryaInstanceName) throws InstanceDoesNotExistException, RyaClientException { + requireNonNull(ryaInstanceName); + + // Ensure the Rya instance exists. + if (!instanceExists.exists(ryaInstanceName)) { + throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName)); + } + + // If the instance has details, then return them. + final RyaDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getClient(), ryaInstanceName); + try { + return Optional.of(detailsRepo.getRyaInstanceDetails()); + } catch (final NotInitializedException e) { + return Optional.absent(); + } catch (final RyaDetailsRepositoryException e) { + throw new RyaClientException("Could not fetch the Rya instance's details.", e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoInstall.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoInstall.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoInstall.java new file mode 100644 index 0000000..2766536 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoInstall.java @@ -0,0 +1,199 @@ +/** + * 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.api.client.mongo; + +import static java.util.Objects.requireNonNull; + +import java.util.Date; + +import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.api.client.Install; +import org.apache.rya.api.client.InstanceExists; +import org.apache.rya.api.client.RyaClientException; +import org.apache.rya.api.instance.RyaDetails; +import org.apache.rya.api.instance.RyaDetails.EntityCentricIndexDetails; +import org.apache.rya.api.instance.RyaDetails.FreeTextIndexDetails; +import org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails; +import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails; +import org.apache.rya.api.instance.RyaDetails.ProspectorDetails; +import org.apache.rya.api.instance.RyaDetails.TemporalIndexDetails; +import org.apache.rya.api.instance.RyaDetailsRepository; +import org.apache.rya.api.instance.RyaDetailsRepository.AlreadyInitializedException; +import org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException; +import org.apache.rya.api.layout.TablePrefixLayoutStrategy; +import org.apache.rya.api.persist.RyaDAOException; +import org.apache.rya.indexing.accumulo.ConfigUtils; +import org.apache.rya.mongodb.MongoDBRdfConfiguration; +import org.apache.rya.mongodb.MongoDBRyaDAO; +import org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository; + +import com.google.common.base.Optional; +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An Mongo implementation of the {@link Install} command. + */ +@DefaultAnnotation(NonNull.class) +public class MongoInstall extends MongoCommand implements Install { + + private final InstanceExists instanceExists; + + /** + * Constructs an instance of {@link MongoInstall}. + * + * @param connectionDetails + * - Details about the values that were used to create the connector to the cluster. (not null) + * @param client + * - Provides programatic access to the instance of Mongo + * that hosts Rya instance. (not null) + */ + public MongoInstall(final MongoConnectionDetails connectionDetails, final MongoClient client) { + super(connectionDetails, client); + instanceExists = new MongoInstanceExists(connectionDetails, client); + } + + @Override + public void install(final String instanceName, final InstallConfiguration installConfig) throws DuplicateInstanceNameException, RyaClientException { + requireNonNull(instanceName, "instanceName required."); + requireNonNull(installConfig, "installConfig required."); + + // Check to see if a Rya instance has already been installed with this name. + if (instanceExists.exists(instanceName)) { + throw new DuplicateInstanceNameException("An instance of Rya has already been installed to this Rya storage " + "with the name '" + instanceName + "'. Try again with a different name."); + } + + // Initialize the Rya Details table. + RyaDetails details; + try { + details = initializeRyaDetails(instanceName, installConfig); + } catch (final AlreadyInitializedException e) { + // This can only happen if somebody else installs an instance of Rya with the name between the check and now. + throw new DuplicateInstanceNameException("An instance of Rya has already been installed to this Rya storage "// + + "with the name '" + instanceName// + + "'. Try again with a different name."); + } catch (final RyaDetailsRepositoryException e) { + throw new RyaClientException("The RyaDetails couldn't be initialized. Details: " + e.getMessage(), e); + } + + // Initialize the rest of the tables used by the Rya instance. + final MongoDBRdfConfiguration ryaConfig = makeRyaConfig(getMongoConnectionDetails(), details); + try { + final MongoDBRyaDAO ryaDao = new MongoDBRyaDAO(ryaConfig, getClient()); + ryaDao.setConf(ryaConfig); + + final TablePrefixLayoutStrategy tls = new TablePrefixLayoutStrategy(); + tls.setTablePrefix(instanceName); + ryaConfig.setTableLayoutStrategy(tls); + + ryaDao.init(); + } catch (final RyaDAOException e) { + throw new RyaClientException("Could not initialize all of the tables for the new Rya instance. " // + + "This instance may be left in a bad state.", e); + } + } + + /** + * @return The version of the application as reported by the manifest. + */ + private String getVersion() { + return "" + this.getClass().getPackage().getImplementationVersion(); + } + + /** + * Initializes the {@link RyaDetails} and stores them for the new instance. + * + * @param instanceName + * - The name of the instance that is being created. (not null) + * @param installConfig + * - The instance's install configuration. (not null) + * @return The {@link RyaDetails} that were stored. + * @throws AlreadyInitializedException + * Could not be initialized because + * a table with this instance name has already exists and is holding the details. + * @throws RyaDetailsRepositoryException + * Something caused the initialization + * operation to fail. + */ + private RyaDetails initializeRyaDetails(final String instanceName, final InstallConfiguration installConfig) throws AlreadyInitializedException, RyaDetailsRepositoryException { + final RyaDetailsRepository detailsRepo = new MongoRyaInstanceDetailsRepository(getClient(), instanceName); + + // Build the PCJ Index details. [not supported in mongo] + final PCJIndexDetails.Builder pcjDetailsBuilder = PCJIndexDetails.builder().setEnabled(false); + + final RyaDetails details = RyaDetails.builder() + // General Metadata + .setRyaInstanceName(instanceName).setRyaVersion(getVersion()) + + // Secondary Index Values + // FIXME .setGeoIndexDetails(new GeoIndexDetails(installConfig.isGeoIndexEnabled())) + .setTemporalIndexDetails(new TemporalIndexDetails(installConfig.isTemporalIndexEnabled())) // + .setFreeTextDetails(new FreeTextIndexDetails(installConfig.isFreeTextIndexEnabled()))// + .setEntityCentricIndexDetails(new EntityCentricIndexDetails(false))// not supported in mongo + .setPCJIndexDetails(pcjDetailsBuilder) + + // Statistics values. + .setProspectorDetails(new ProspectorDetails(Optional.<Date> absent()))// + .setJoinSelectivityDetails(new JoinSelectivityDetails(Optional.<Date> absent()))// + .build(); + + // Initialize the table. + detailsRepo.initialize(details); + + return details; + } + + /** + * Builds a {@link MongoRdfConfiguration} object that will be used by the + * Rya DAO to initialize all of the tables it will need. + * + * @param connectionDetails + * - Indicates how to connect to Mongo. (not null) + * @param details + * - Indicates what needs to be installed. (not null) + * @return A Rya Configuration object that can be used to perform the install. + */ + private static MongoDBRdfConfiguration makeRyaConfig(final MongoConnectionDetails connectionDetails, final RyaDetails details) { + final MongoDBRdfConfiguration conf = new MongoDBRdfConfiguration(); + conf.setBoolean(ConfigUtils.USE_MONGO, true); + // The Rya Instance Name is used as a prefix for the index tables in Mongo. + conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, details.getRyaInstanceName()); + + // Enable the indexers that the instance is configured to use. + conf.set(ConfigUtils.USE_PCJ, "" + details.getPCJIndexDetails().isEnabled()); + // fixme conf.set(OptionalConfigUtils.USE_GEO, "" + details.getGeoIndexDetails().isEnabled() ); + conf.set(ConfigUtils.USE_FREETEXT, "" + details.getFreeTextIndexDetails().isEnabled()); + conf.set(ConfigUtils.USE_TEMPORAL, "" + details.getTemporalIndexDetails().isEnabled()); + + // Mongo does not support entity indexing. + conf.set(ConfigUtils.USE_ENTITY, "" + false); + + conf.set(ConfigUtils.CLOUDBASE_USER, connectionDetails.getUsername()); + conf.set(ConfigUtils.CLOUDBASE_PASSWORD, new String(connectionDetails.getPassword())); + conf.set(MongoDBRdfConfiguration.MONGO_DB_NAME, details.getRyaInstanceName()); + + // This initializes the living indexers that will be used by the application and + // caches them within the configuration object so that they may be used later. + ConfigUtils.setIndexers(conf); + + return conf; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoInstanceExists.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoInstanceExists.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoInstanceExists.java new file mode 100644 index 0000000..2560856 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoInstanceExists.java @@ -0,0 +1,53 @@ +/** + * 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.api.client.mongo; + +import static java.util.Objects.requireNonNull; + +import org.apache.rya.api.client.InstanceExists; +import org.apache.rya.api.client.RyaClientException; + +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An Mongo implementation of the {@link InstanceExists} command. + */ +@DefaultAnnotation(NonNull.class) +public class MongoInstanceExists extends MongoCommand implements InstanceExists { + + /** + * Constructs an insatnce of {@link MongoInstanceExists}. + * + * @param connectionDetails - Details about the values that were used to create the connector to the cluster. (not null) + * @param client - Provides programatic access to the instance of Mongo + * that hosts Rya instance. (not null) + */ + public MongoInstanceExists(final MongoConnectionDetails connectionDetails, final MongoClient client) { + super(connectionDetails, client); + } + + @Override + public boolean exists(final String instanceName) { + requireNonNull( instanceName ); + return super.getClient().getDatabaseNames().contains(instanceName); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoListInstances.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoListInstances.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoListInstances.java new file mode 100644 index 0000000..d301bf2 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoListInstances.java @@ -0,0 +1,68 @@ +/** + * 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.api.client.mongo; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.apache.rya.api.client.ListInstances; +import org.apache.rya.api.client.RyaClientException; +import org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository; + +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An Mongo implementation of the {@link ListInstances} command. + */ +@DefaultAnnotation(NonNull.class) +public class MongoListInstances extends MongoCommand implements ListInstances { + /** + * Constructs an instance of {@link MongoListInstances}. + * + * @param connectionDetails + * - Details about the values that were used to create the connector to the cluster. (not null) + * @param client + * - Provides programatic access to the instance of Mongo + * that hosts Rya instance. (not null) + */ + public MongoListInstances(final MongoConnectionDetails connectionDetails, final MongoClient client) { + super(connectionDetails, client); + } + + @Override + public List<String> listInstances() throws RyaClientException { + final MongoClient client = super.getClient(); + final List<String> dbNames = client.getDatabaseNames(); + final List<String> ryaInstances = new ArrayList<>(); + for (final String db : dbNames) { + final Set<String> collNames = client.getDB(db).getCollectionNames(); + for (final String coll : collNames) { + if (coll.equals(MongoRyaInstanceDetailsRepository.INSTANCE_DETAILS_COLLECTION_NAME)) { + ryaInstances.add(db); + break; + } + } + } + return ryaInstances; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoLoadStatements.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoLoadStatements.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoLoadStatements.java new file mode 100644 index 0000000..844489d --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoLoadStatements.java @@ -0,0 +1,29 @@ +package org.apache.rya.api.client.mongo; + +import org.apache.rya.api.client.InstanceDoesNotExistException; +import org.apache.rya.api.client.LoadStatements; +import org.apache.rya.api.client.RyaClientException; +import org.openrdf.model.Statement; + +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An Mongo implementation of the {@link LoadStatements} command. + */ +@DefaultAnnotation(NonNull.class) +public class MongoLoadStatements extends MongoCommand implements LoadStatements { + + public MongoLoadStatements(MongoConnectionDetails connectionDetails, MongoClient client) { + super(connectionDetails, client); + } + + @Override + public void loadStatements(String ryaInstanceName, Iterable<? extends Statement> statements) throws InstanceDoesNotExistException, RyaClientException { + // TODO Auto-generated method stub + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFile.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFile.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFile.java new file mode 100644 index 0000000..bf525c1 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFile.java @@ -0,0 +1,87 @@ +package org.apache.rya.api.client.mongo; + +import static java.util.Objects.requireNonNull; + +import java.io.IOException; +import java.nio.file.Path; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.log4j.Logger; +import org.apache.rya.api.client.InstanceDoesNotExistException; +import org.apache.rya.api.client.InstanceExists; +import org.apache.rya.api.client.LoadStatementsFile; +import org.apache.rya.api.client.RyaClientException; +import org.apache.rya.api.persist.RyaDAOException; +import org.apache.rya.mongodb.MongoDBRdfConfiguration; +import org.apache.rya.rdftriplestore.inference.InferenceEngineException; +import org.apache.rya.sail.config.RyaSailFactory; +import org.openrdf.repository.RepositoryException; +import org.openrdf.repository.sail.SailRepository; +import org.openrdf.repository.sail.SailRepositoryConnection; +import org.openrdf.rio.RDFFormat; +import org.openrdf.rio.RDFParseException; +import org.openrdf.sail.Sail; +import org.openrdf.sail.SailException; + +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An Mongo implementation of the {@link LoadStatementsFile} command. + */ +@DefaultAnnotation(NonNull.class) +public class MongoLoadStatementsFile extends MongoCommand implements LoadStatementsFile { + private static final Logger log = Logger.getLogger(MongoLoadStatementsFile.class); + + private final InstanceExists instanceExists; + + /** + * Constructs an instance of {@link MongoListInstances}. + * + * @param connectionDetails + * - Details to connect to the server. (not null) + * @param client + * - Provides programmatic access to the instance of Mongo + * that hosts Rya instance. (not null) + */ + public MongoLoadStatementsFile(MongoConnectionDetails connectionDetails, MongoClient client) { + super(connectionDetails, client); + instanceExists = new MongoInstanceExists(connectionDetails, client); + } + + @Override + public void loadStatements(String ryaInstanceName, Path statementsFile, RDFFormat format) throws InstanceDoesNotExistException, RyaClientException { + requireNonNull(ryaInstanceName); + requireNonNull(statementsFile); + requireNonNull(format); + + // Ensure the Rya Instance exists. + if (!instanceExists.exists(ryaInstanceName)) { + throw new InstanceDoesNotExistException(String.format("There is no Rya instance named '%s'.", ryaInstanceName)); + } + + Sail sail = null; + SailRepository sailRepo = null; + SailRepositoryConnection sailRepoConn = null; + // Get a Sail object that is connected to the Rya instance. + final MongoDBRdfConfiguration ryaConf = getMongoConnectionDetails().build(ryaInstanceName); + // ryaConf.setFlush(false); //Accumulo version said: RYA-327 should address this hardcoded value. + try { + sail = RyaSailFactory.getInstance(ryaConf); + } catch (SailException | AccumuloException | AccumuloSecurityException | RyaDAOException | InferenceEngineException e) { + throw new RyaClientException("While getting an sail instance.", e); + } + + // Load the file. + sailRepo = new SailRepository(sail); + try { + sailRepoConn = sailRepo.getConnection(); + sailRepoConn.add(statementsFile.toFile(), null, format); + } catch (RDFParseException | RepositoryException | IOException e) { + throw new RyaClientException("While getting a connection and adding statements from a file.", e); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoRyaClientFactory.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoRyaClientFactory.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoRyaClientFactory.java new file mode 100644 index 0000000..4ea3487 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoRyaClientFactory.java @@ -0,0 +1,66 @@ +/** + * 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.api.client.mongo; + +import static java.util.Objects.requireNonNull; + +import org.apache.rya.api.client.RyaClient; + +import com.mongodb.MongoClient; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * Constructs instance of {@link RyaClient} that are connected to instance of + * Rya hosted by Mongo clusters. + */ +@DefaultAnnotation(NonNull.class) +public class MongoRyaClientFactory { + + /** + * Initialize a set of {@link RyaClient} that will interact with an instance of + * Rya that is hosted by a MongoDB server. + * + * @param connectionDetails - Details about the values that were used to create the connector to the cluster. (not null) + * @param connector - The MongoDB connector the commands will use. (not null) + * @return The initialized commands. + */ + public static RyaClient build( + final MongoConnectionDetails connectionDetails, + final MongoClient connector) { + requireNonNull(connectionDetails); + requireNonNull(connector); + + // Build the RyaCommands option with the initialized commands. + return new RyaClient(// + new MongoInstall(connectionDetails, connector), // + new MongoCreatePCJ(connectionDetails, connector), // + new MongoDeletePCJ(connectionDetails, connector), // + null, null, null, null, + new MongoGetInstanceDetails(connectionDetails, connector), // + new MongoInstanceExists(connectionDetails, connector), // + new MongoListInstances(connectionDetails, connector), // + null, null, + new MongoUninstall(connectionDetails, connector), // + new MongoLoadStatements(connectionDetails, connector), // + new MongoLoadStatementsFile(connectionDetails, connector), // + null);// FIXME new MongoExecuteSparqlQuery(connectionDetails, connector)); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoUninstall.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoUninstall.java b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoUninstall.java new file mode 100644 index 0000000..b3988b8 --- /dev/null +++ b/extras/indexing/src/main/java/org/apache/rya/api/client/mongo/MongoUninstall.java @@ -0,0 +1,61 @@ +/** + * 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.api.client.mongo; + +import org.apache.rya.api.client.InstanceDoesNotExistException; +import org.apache.rya.api.client.RyaClientException; +import org.apache.rya.api.client.Uninstall; + +import com.mongodb.MongoClient; +import com.mongodb.MongoException; + +import edu.umd.cs.findbugs.annotations.DefaultAnnotation; +import edu.umd.cs.findbugs.annotations.NonNull; + +/** + * An Mongo implementation of the {@link Uninstall} command. + */ +@DefaultAnnotation(NonNull.class) +public class MongoUninstall extends MongoCommand implements Uninstall { + + /** + * Constructs an instance of {@link MongoUninstall}. + * + * @param connectionDetails + * - Details about the values that were used to create the connector to the cluster. (not null) + * @param connector + * - Provides programatic access to the instance of Mongo + * that hosts Rya instance. (not null) + */ + public MongoUninstall(final MongoConnectionDetails connectionDetails, final MongoClient client) { + super(connectionDetails, client); + } + + @Override + public void uninstall(final String ryaInstanceName) throws InstanceDoesNotExistException, RyaClientException { + try { + if (!getClient().getDatabaseNames().contains(ryaInstanceName)) { + throw new InstanceDoesNotExistException("The database '" + ryaInstanceName + "' does not exist."); + } + getClient().dropDatabase(ryaInstanceName); + } catch (final MongoException e) { + throw new RyaClientException("Failed to uninstall '" + ryaInstanceName + "' " + e.getLocalizedMessage(), e); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetailsIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetailsIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetailsIT.java new file mode 100644 index 0000000..843ba42 --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoGetInstanceDetailsIT.java @@ -0,0 +1,123 @@ +/** + * 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.api.client.mongo; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import java.util.Date; + +import org.apache.accumulo.core.client.TableExistsException; +import org.apache.rya.api.client.GetInstanceDetails; +import org.apache.rya.api.client.Install; +import org.apache.rya.api.client.Install.InstallConfiguration; +import org.apache.rya.api.client.InstanceDoesNotExistException; +import org.apache.rya.api.client.RyaClientException; +import org.apache.rya.api.instance.RyaDetails; +import org.apache.rya.api.instance.RyaDetails.EntityCentricIndexDetails; +import org.apache.rya.api.instance.RyaDetails.FreeTextIndexDetails; +import org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails; +import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails; +import org.apache.rya.api.instance.RyaDetails.ProspectorDetails; +import org.apache.rya.api.instance.RyaDetails.TemporalIndexDetails; +import org.apache.rya.mongodb.MongoTestBase; +import org.junit.Test; + +import com.google.common.base.Optional; +import com.mongodb.BasicDBObject; +import com.mongodb.MongoException; + +/** + * Tests the methods of {@link MongoGetInstanceDetails}. + */ +public class MongoGetInstanceDetailsIT extends MongoTestBase { + + @Test + public void getDetails() throws MongoException, RyaClientException { + final String instanceName = "instance"; + // Install an instance of Rya. + final InstallConfiguration installConfig = InstallConfiguration.builder() + .setEnableTableHashPrefix(true) + .setEnableEntityCentricIndex(true) + .setEnableFreeTextIndex(true) + .setEnableTemporalIndex(true) + .setEnableGeoIndex(true) + .setEnablePcjIndex(false) + .build(); + + final Install install = new MongoInstall(getConnectionDetails(), this.getMongoClient()); + install.install(instanceName, installConfig); + + // Verify the correct details were persisted. + final GetInstanceDetails getInstanceDetails = new MongoGetInstanceDetails(getConnectionDetails(), this.getMongoClient()); + final Optional<RyaDetails> details = getInstanceDetails.getDetails(instanceName); + + final RyaDetails expectedDetails = RyaDetails.builder() + .setRyaInstanceName(instanceName) + + // The version depends on how the test is packaged, so just grab whatever was stored. + .setRyaVersion( details.get().getRyaVersion() ) + + // FIXME .setGeoIndexDetails( new GeoIndexDetails(true) ) + .setTemporalIndexDetails(new TemporalIndexDetails(true) ) + .setFreeTextDetails( new FreeTextIndexDetails(true) ) + .setEntityCentricIndexDetails( new EntityCentricIndexDetails(false) ) + .setPCJIndexDetails( + PCJIndexDetails.builder() + .setEnabled(false)) + .setProspectorDetails( new ProspectorDetails(Optional.<Date>absent()) ) + .setJoinSelectivityDetails( new JoinSelectivityDetails(Optional.<Date>absent()) ) + .build(); + + assertEquals(expectedDetails, details.get()); + } + + @Test(expected = InstanceDoesNotExistException.class) + public void getDetails_instanceDoesNotExist() throws MongoException, RyaClientException { + final GetInstanceDetails getInstanceDetails = new MongoGetInstanceDetails(getConnectionDetails(), conf.getMongoClient()); + getInstanceDetails.getDetails("instance_name"); + } + + @Test + public void getDetails_instanceDoesNotHaveDetails() throws MongoException, TableExistsException, RyaClientException { + // Mimic a pre-details rya install. + final String instanceName = "instance_name"; + + this.getMongoClient().getDB(instanceName).createCollection("rya_triples", new BasicDBObject()); + + // Verify that the operation returns empty. + final GetInstanceDetails getInstanceDetails = new MongoGetInstanceDetails(getConnectionDetails(), this.getMongoClient()); + final Optional<RyaDetails> details = getInstanceDetails.getDetails(instanceName); + assertFalse( details.isPresent() ); + } + + /** + * @return copy from conf to MongoConnectionDetails + */ + private MongoConnectionDetails getConnectionDetails() { + final MongoConnectionDetails connectionDetails = new MongoConnectionDetails( + conf.getMongoUser(), // + conf.getMongoPassword().toCharArray(), // + conf.getMongoDBName(), // aka instance + conf.getMongoInstance(), // aka hostname + conf.getCollectionName() + ); + return connectionDetails; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstallIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstallIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstallIT.java new file mode 100644 index 0000000..e9dae1c --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstallIT.java @@ -0,0 +1,105 @@ +/** + * 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.api.client.mongo; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import org.apache.rya.api.client.Install; +import org.apache.rya.api.client.Install.DuplicateInstanceNameException; +import org.apache.rya.api.client.Install.InstallConfiguration; +import org.apache.rya.api.client.InstanceExists; +import org.apache.rya.api.client.RyaClientException; +import org.apache.rya.api.client.accumulo.AccumuloInstall; +import org.apache.rya.mongodb.MongoTestBase; +import org.junit.Test; + +/** + * Integration tests the methods of {@link AccumuloInstall}. + */ +public class MongoInstallIT extends MongoTestBase { + + @Test + public void install() throws DuplicateInstanceNameException, RyaClientException { + // Install an instance of Rya. + final String instanceName = conf.getCollectionName(); + final InstallConfiguration installConfig = InstallConfiguration.builder() + .setEnableTableHashPrefix(false) // + .setEnableEntityCentricIndex(false)// + .setEnableFreeTextIndex(false)// + .setEnableTemporalIndex(false)// + .setEnablePcjIndex(false)// + .setEnableGeoIndex(false)// + .setFluoPcjAppName("fluo_app_name")// + .build(); + + final MongoConnectionDetails connectionDetails = new MongoConnectionDetails( + conf.getMongoUser(), // + conf.getMongoPassword().toCharArray(), // + conf.getMongoDBName(), // aka instance + conf.getMongoInstance(), // aka hostname + conf.getCollectionName() + ); + + // Check that the instance does not exist. + assertFalse("Instance should NOT exist yet.", this.getMongoClient().getDatabaseNames().contains(instanceName)); + final InstanceExists instanceExists = new MongoInstanceExists(connectionDetails, this.getMongoClient()); + assertFalse("Instance should NOT exist yet.", instanceExists.exists(instanceName)); + + final Install install = new MongoInstall(connectionDetails, this.getMongoClient()); + install.install(instanceName, installConfig); + + // Check that the instance exists. + assertTrue("Instance should exist.", this.getMongoClient().getDatabaseNames().contains(instanceName)); + List<String> expected = Arrays.asList("instance_details", instanceName + "_triples"); + int count = 0; + String found = ""; + for (String collection : this.getMongoClient().getDatabase(instanceName).listCollectionNames()) + { + System.out.println("Collection names:" + collection); + count += expected.contains(collection) ? 1 : 0; + found += ", " + collection; + } + assertTrue("Tables missing from:" + expected + " actual:" + found, expected.size() == count); + assertTrue("Instance should exist.", instanceExists.exists(instanceName)); + } + + @Test(expected = DuplicateInstanceNameException.class) + public void install_alreadyExists() throws DuplicateInstanceNameException, RyaClientException { + // Install an instance of Rya. + final String instanceName = conf.getCollectionName(); + final InstallConfiguration installConfig = InstallConfiguration.builder().build(); + + final MongoConnectionDetails connectionDetails = new MongoConnectionDetails(conf.getMongoUser(), // + conf.getMongoPassword().toCharArray(), // + conf.getMongoDBName(), // aka instance + conf.getMongoInstance(), // aka hostname + conf.getCollectionName() + ); + + final Install install = new MongoInstall(connectionDetails, this.getMongoClient()); + install.install(instanceName, installConfig); + + // Install it again throws expected error. + install.install(instanceName, installConfig); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstanceExistsIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstanceExistsIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstanceExistsIT.java new file mode 100644 index 0000000..35568bc --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoInstanceExistsIT.java @@ -0,0 +1,86 @@ +/** + * 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.api.client.mongo; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.apache.accumulo.core.client.TableExistsException; +import org.apache.rya.api.client.accumulo.AccumuloInstanceExists; +import org.apache.rya.mongodb.MongoTestBase; +import org.apache.rya.mongodb.instance.MongoRyaInstanceDetailsRepository; +import org.junit.Test; + +import com.mongodb.BasicDBObject; +import com.mongodb.MongoClient; +import com.mongodb.MongoException; + +/** + * Integration tests the methods of {@link AccumuloInstanceExists}. + */ +public class MongoInstanceExistsIT extends MongoTestBase { + + @Test + public void exists_ryaDetailsTable() throws MongoException, TableExistsException { + final MongoClient client = getMongoClient(); + + // Create the Rya instance's Rya details collection. + final String instanceName = "test_instance_"; + client.getDB(instanceName).createCollection(MongoRyaInstanceDetailsRepository.INSTANCE_DETAILS_COLLECTION_NAME, new BasicDBObject()); + + // Verify the command reports the instance exists. + final MongoInstanceExists instanceExists = new MongoInstanceExists(getConnectionDetails(), client); + assertTrue( instanceExists.exists(instanceName) ); + } + + @Test + public void exists_dataTables() throws MongoException, TableExistsException { + final MongoClient client = getMongoClient(); + + // Create the Rya instance's Rya triples collection. + final String instanceName = "test_instance_"; + client.getDB(instanceName).createCollection("rya_triples", new BasicDBObject()); + + // Verify the command reports the instance exists. + final MongoInstanceExists instanceExists = new MongoInstanceExists(getConnectionDetails(), client); + assertTrue( instanceExists.exists(instanceName) ); + } + + @Test + public void doesNotExist() throws MongoException { + // Verify the command reports the instance does not exists. + final MongoInstanceExists instanceExists = new MongoInstanceExists(getConnectionDetails(), getMongoClient()); + assertFalse( instanceExists.exists("some_instance") ); + } + + /** + * @return copy from conf to MongoConnectionDetails + */ + private MongoConnectionDetails getConnectionDetails() { + final MongoConnectionDetails connectionDetails = new MongoConnectionDetails(conf.getMongoUser(), // + conf.getMongoPassword().toCharArray(), // + conf.getMongoDBName(), // aka instance + conf.getMongoInstance(), // aka hostname + conf.getCollectionName() + ); + return connectionDetails; + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoListInstancesIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoListInstancesIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoListInstancesIT.java new file mode 100644 index 0000000..7d5a2fe --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoListInstancesIT.java @@ -0,0 +1,71 @@ +/** + * 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.api.client.mongo; + +import static org.junit.Assert.assertEquals; + +import java.util.Collections; +import java.util.List; + +import org.apache.rya.api.client.Install; +import org.apache.rya.api.client.Install.DuplicateInstanceNameException; +import org.apache.rya.api.client.Install.InstallConfiguration; +import org.apache.rya.api.client.ListInstances; +import org.apache.rya.api.client.RyaClientException; +import org.apache.rya.mongodb.MongoTestBase; +import org.junit.Test; + +import com.beust.jcommander.internal.Lists; +import com.mongodb.MongoException; + +/** + * Integration tests the methods of {@link MongoListInstances}. + */ +public class MongoListInstancesIT extends MongoTestBase { + + @Test + public void listInstances_hasRyaDetailsTable() throws MongoException, DuplicateInstanceNameException, RyaClientException { + // Install a few instances of Rya using the install command. + final Install install = new MongoInstall(getConnectionDetails(), getMongoClient()); + install.install("instance1_", InstallConfiguration.builder().build()); + install.install("instance2_", InstallConfiguration.builder().build()); + install.install("instance3_", InstallConfiguration.builder().build()); + + // Fetch the list and verify it matches what is expected. + final ListInstances listInstances = new MongoListInstances(getConnectionDetails(), getMongoClient()); + final List<String> instances = listInstances.listInstances(); + Collections.sort(instances); + + final List<String> expected = Lists.newArrayList("instance1_", "instance2_", "instance3_"); + assertEquals(expected, instances); + } + + /** + * @return copy from conf to MongoConnectionDetails + */ + private MongoConnectionDetails getConnectionDetails() { + final MongoConnectionDetails connectionDetails = new MongoConnectionDetails(conf.getMongoUser(), // + conf.getMongoPassword().toCharArray(), // + conf.getMongoDBName(), // aka instance + conf.getMongoInstance(), // aka hostname + conf.getCollectionName() + ); + return connectionDetails; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFileIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFileIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFileIT.java new file mode 100644 index 0000000..6794d86 --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoLoadStatementsFileIT.java @@ -0,0 +1,132 @@ +/** + * 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.api.client.mongo; + +import static org.junit.Assert.assertEquals; + +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import org.apache.rya.api.client.Install; +import org.apache.rya.api.client.Install.InstallConfiguration; +import org.apache.rya.api.client.InstanceDoesNotExistException; +import org.apache.rya.api.client.RyaClient; +import org.apache.rya.mongodb.MongoTestBase; +import org.bson.Document; +import org.junit.Test; +import org.openrdf.model.Statement; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.ValueFactoryImpl; +import org.openrdf.rio.RDFFormat; + +import com.mongodb.client.MongoCursor; + +/** + * Integration tests the methods of {@link MongoLoadStatementsFile}. + */ +public class MongoLoadStatementsFileIT extends MongoTestBase { + + @Test(expected = InstanceDoesNotExistException.class) + public void instanceDoesNotExist() throws Exception { + + final RyaClient ryaClient = MongoRyaClientFactory.build(getConnectionDetails(), conf.getMongoClient()); + ryaClient.getLoadStatementsFile().loadStatements(getConnectionDetails().getInstance(), Paths.get("src/test/resources/example.ttl"), RDFFormat.TURTLE); + } + + @Test + public void loadTurtleFile() throws Exception { + // Install an instance of Rya. + final InstallConfiguration installConfig = InstallConfiguration.builder() + .setEnableTableHashPrefix(false) + .setEnableEntityCentricIndex(false) + .setEnableFreeTextIndex(false) + .setEnableTemporalIndex(false) + .setEnablePcjIndex(false) + .setEnableGeoIndex(false) + .build(); + MongoConnectionDetails connectionDetails = getConnectionDetails(); + final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, conf.getMongoClient()); + final Install install = ryaClient.getInstall(); + install.install(connectionDetails.getInstance(), installConfig); + + // Load the test statement file. + ryaClient.getLoadStatementsFile().loadStatements( // + connectionDetails.getInstance(), // + Paths.get("src/test/resources/example.ttl"), // + RDFFormat.TURTLE); + + // Verify that the statements were loaded. + final ValueFactory vf = new ValueFactoryImpl(); + + final List<Statement> expected = new ArrayList<>(); + expected.add( vf.createStatement(vf.createURI("http://example#alice"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#bob")) ); + expected.add( vf.createStatement(vf.createURI("http://example#bob"), vf.createURI("http://example#talksTo"), vf.createURI("http://example#charlie")) ); + expected.add( vf.createStatement(vf.createURI("http://example#charlie"), vf.createURI("http://example#likes"), vf.createURI("http://example#icecream")) ); + + final List<Statement> statements = new ArrayList<>(); + MongoCursor<Document> x = getRyaCollection().find().iterator(); + System.out.println("getRyaCollection().count()=" + getRyaCollection().count()); + while (x.hasNext()) { + Document y = x.next(); + System.out.println("getRyaCollection()=" + y); + } + assertEquals("Expect all rows to be read.", 3, getRyaCollection().count()); + // final WholeRowTripleResolver tripleResolver = new WholeRowTripleResolver(); + // final Scanner scanner = getConnector().createScanner(getRyaInstanceName() + "spo", new Authorizations()); + // final Iterator<Entry<Key, Value>> it = scanner.iterator(); + // while(it.hasNext()) { + // final Entry<Key, Value> next = it.next(); + // + // final Key key = next.getKey(); + // final byte[] row = key.getRow().getBytes(); + // final byte[] columnFamily = key.getColumnFamily().getBytes(); + // final byte[] columnQualifier = key.getColumnQualifier().getBytes(); + // final TripleRow tripleRow = new TripleRow(row, columnFamily, columnQualifier); + // + // final RyaStatement ryaStatement = tripleResolver.deserialize(TABLE_LAYOUT.SPO, tripleRow); + // final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); + // + // // Filter out the rya version statement if it is present. + // if(!isRyaMetadataStatement(vf, statement)) { + // statements.add( statement ); + // } + // } + // + // assertEquals(expected, statements); + } + + private boolean isRyaMetadataStatement(final ValueFactory vf, final Statement statement) { + return statement.getPredicate().equals( vf.createURI("urn:org.apache.rya/2012/05#version") ) || + statement.getPredicate().equals( vf.createURI("urn:org.apache.rya/2012/05#rts") ); + } + /** + * @return copy from conf to MongoConnectionDetails + */ + private MongoConnectionDetails getConnectionDetails() { + final MongoConnectionDetails connectionDetails = new MongoConnectionDetails(// + conf.getMongoUser(), // + conf.getMongoPassword().toCharArray(), // + conf.getMongoDBName(), // aka instance + conf.getMongoInstance(), // aka hostname + conf.getCollectionName() + ); + return connectionDetails; + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/33a04863/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoUninstallIT.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoUninstallIT.java b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoUninstallIT.java new file mode 100644 index 0000000..523b4b2 --- /dev/null +++ b/extras/indexing/src/test/java/org/apache/rya/api/client/mongo/MongoUninstallIT.java @@ -0,0 +1,78 @@ +/** + * 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.api.client.mongo; + +import org.apache.rya.api.client.Install; +import org.apache.rya.api.client.Install.InstallConfiguration; +import org.apache.rya.api.client.InstanceDoesNotExistException; +import org.apache.rya.api.client.InstanceExists; +import org.apache.rya.api.client.RyaClientException; +import org.apache.rya.api.client.Uninstall; +import org.apache.rya.mongodb.MongoTestBase; +import org.junit.Assert; +import org.junit.Test; + +import com.mongodb.MongoException; + +/** + * Integration tests the methods of {@link MongoInstall}. + */ +public class MongoUninstallIT extends MongoTestBase { + + @Test + public void uninstall() throws MongoException, RyaClientException { + // Install an instance of Rya. + final String instanceName = "testInstance_"; + final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(true).setEnableEntityCentricIndex(true).setEnableFreeTextIndex(true).setEnableTemporalIndex(true).setEnablePcjIndex(true).setEnableGeoIndex(true).setFluoPcjAppName("fluo_app_name").build(); + + final Install install = new MongoInstall(getConnectionDetails(), conf.getMongoClient()); + install.install(instanceName, installConfig); + + // Uninstall the instance + final Uninstall uninstall = new MongoUninstall(getConnectionDetails(), conf.getMongoClient()); + uninstall.uninstall(instanceName); + + // Check that the instance no longer exists. + final InstanceExists instanceExists = new MongoInstanceExists(getConnectionDetails(), conf.getMongoClient()); + Assert.assertFalse(instanceExists.exists(instanceName)); + } + + @Test(expected = InstanceDoesNotExistException.class) + public void uninstall_instanceDoesNotExists() throws MongoException, RyaClientException { + // Install an instance of Rya. + final String instanceName = "testInstance_"; + + // Uninstall the instance + final Uninstall uninstall = new MongoUninstall(getConnectionDetails(), conf.getMongoClient()); + uninstall.uninstall(instanceName); + } + + /** + * @return copy from conf to MongoConnectionDetails + */ + private MongoConnectionDetails getConnectionDetails() { + final MongoConnectionDetails connectionDetails = new MongoConnectionDetails(conf.getMongoUser(), // + conf.getMongoPassword().toCharArray(), // + conf.getMongoDBName(), // aka instance + conf.getMongoInstance(), // aka hostname + conf.getCollectionName() + ); + return connectionDetails; + } +} \ No newline at end of file