Repository: incubator-rya Updated Branches: refs/heads/master ed0b0f7fd -> f0b11e2cd
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/ab4fca46/extras/rya.console/src/main/java/org/apache/rya/shell/RyaAdminCommands.java ---------------------------------------------------------------------- diff --git a/extras/rya.console/src/main/java/org/apache/rya/shell/RyaAdminCommands.java b/extras/rya.console/src/main/java/org/apache/rya/shell/RyaAdminCommands.java index 33bfd98..7e8b71f 100644 --- a/extras/rya.console/src/main/java/org/apache/rya/shell/RyaAdminCommands.java +++ b/extras/rya.console/src/main/java/org/apache/rya/shell/RyaAdminCommands.java @@ -24,20 +24,10 @@ import java.io.IOException; import java.util.Collections; import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.shell.core.CommandMarker; -import org.springframework.shell.core.annotation.CliAvailabilityIndicator; -import org.springframework.shell.core.annotation.CliCommand; -import org.springframework.shell.core.annotation.CliOption; -import org.springframework.stereotype.Component; - -import com.google.common.base.Optional; - import org.apache.rya.api.client.GetInstanceDetails; import org.apache.rya.api.client.Install.DuplicateInstanceNameException; import org.apache.rya.api.client.Install.InstallConfiguration; import org.apache.rya.api.client.InstanceDoesNotExistException; -import org.apache.rya.api.client.PCJDoesNotExistException; import org.apache.rya.api.client.RyaClient; import org.apache.rya.api.client.RyaClientException; import org.apache.rya.api.instance.RyaDetails; @@ -47,6 +37,14 @@ import org.apache.rya.shell.util.InstallPrompt; import org.apache.rya.shell.util.InstanceNamesFormatter; import org.apache.rya.shell.util.RyaDetailsFormatter; import org.apache.rya.shell.util.SparqlPrompt; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.shell.core.CommandMarker; +import org.springframework.shell.core.annotation.CliAvailabilityIndicator; +import org.springframework.shell.core.annotation.CliCommand; +import org.springframework.shell.core.annotation.CliOption; +import org.springframework.stereotype.Component; + +import com.google.common.base.Optional; /** * Rya Shell commands that have to do with administrative tasks. @@ -56,11 +54,12 @@ public class RyaAdminCommands implements CommandMarker { public static final String CREATE_PCJ_CMD = "create-pcj"; public static final String DELETE_PCJ_CMD = "delete-pcj"; - public static final String BATCH_UPDATE_PCJ_CMD = "batch-update-pcj"; public static final String GET_INSTANCE_DETAILS_CMD = "get-instance-details"; public static final String INSTALL_CMD = "install"; public static final String LIST_INSTANCES_CMD = "list-instances"; public static final String UNINSTALL_CMD = "uninstall"; + public static final String ADD_USER_CMD = "add-user"; + public static final String REMOVE_USER_CMD = "remove-user"; private final SharedShellState state; private final InstallPrompt installPrompt; @@ -71,7 +70,7 @@ public class RyaAdminCommands implements CommandMarker { * * @param state - Holds shared state between all of the command classes. (not null) * @param installPrompt - Prompts a user for installation details. (not null) - * @param sparqlPrompt - Prompts a user for create PCJ details. (not null) + * @param sparqlPrompt - Prompts a user for a SPARQL query. (not null) */ @Autowired public RyaAdminCommands(final SharedShellState state, final InstallPrompt installPrompt, final SparqlPrompt sparqlPrompt) { @@ -101,7 +100,9 @@ public class RyaAdminCommands implements CommandMarker { */ @CliAvailabilityIndicator({ GET_INSTANCE_DETAILS_CMD, - UNINSTALL_CMD }) + UNINSTALL_CMD, + ADD_USER_CMD, + REMOVE_USER_CMD}) public boolean areInstanceCommandsAvailable() { switch(state.getShellState().getConnectionState()) { case CONNECTED_TO_INSTANCE: @@ -116,8 +117,7 @@ public class RyaAdminCommands implements CommandMarker { */ @CliAvailabilityIndicator({ CREATE_PCJ_CMD, - DELETE_PCJ_CMD, - BATCH_UPDATE_PCJ_CMD}) + DELETE_PCJ_CMD }) public boolean arePCJCommandsAvailable() { // The PCJ commands are only available if the Shell is connected to an instance of Rya // that is new enough to use the RyaDetailsRepository and is configured to maintain PCJs. @@ -141,18 +141,18 @@ public class RyaAdminCommands implements CommandMarker { public String listInstances() { // Fetch the command that is connected to the store. final ShellState shellState = state.getShellState(); - final RyaClient ryaClient = shellState.getConnectedCommands().get(); - final Optional<String> ryaInstanceName = shellState.getRyaInstanceName(); + final RyaClient commands = shellState.getConnectedCommands().get(); + final Optional<String> ryaInstance = shellState.getRyaInstanceName(); try { // Sort the names alphabetically. - final List<String> instanceNames = ryaClient.getListInstances().listInstances(); + final List<String> instanceNames = commands.getListInstances().listInstances(); Collections.sort( instanceNames ); final String report; final InstanceNamesFormatter formatter = new InstanceNamesFormatter(); - if(ryaInstanceName.isPresent()) { - report = formatter.format(instanceNames, ryaInstanceName.get()); + if(ryaInstance.isPresent()) { + report = formatter.format(instanceNames, ryaInstance.get()); } else { report = formatter.format(instanceNames); } @@ -166,7 +166,7 @@ public class RyaAdminCommands implements CommandMarker { @CliCommand(value = INSTALL_CMD, help = "Create a new instance of Rya.") public String install() { // Fetch the commands that are connected to the store. - final RyaClient ryaClient = state.getShellState().getConnectedCommands().get(); + final RyaClient commands = state.getShellState().getConnectedCommands().get(); String instanceName = null; InstallConfiguration installConfig = null; @@ -182,7 +182,7 @@ public class RyaAdminCommands implements CommandMarker { } // Execute the command. - ryaClient.getInstall().install(instanceName, installConfig); + commands.getInstall().install(instanceName, installConfig); return String.format("The Rya instance named '%s' has been installed.", instanceName); } catch(final DuplicateInstanceNameException e) { @@ -196,18 +196,18 @@ public class RyaAdminCommands implements CommandMarker { public String getInstanceDetails() { // Fetch the command that is connected to the store. final ShellState shellState = state.getShellState(); - final RyaClient ryaClient = shellState.getConnectedCommands().get(); - final String ryaInstanceName = shellState.getRyaInstanceName().get(); + final RyaClient commands = shellState.getConnectedCommands().get(); + final String ryaInstance = shellState.getRyaInstanceName().get(); try { - final Optional<RyaDetails> details = ryaClient.getGetInstanceDetails().getDetails(ryaInstanceName); + final Optional<RyaDetails> details = commands.getGetInstanceDetails().getDetails(ryaInstance); if(details.isPresent()) { return new RyaDetailsFormatter().format(details.get()); } else { return "This instance of Rya does not have a Rya Details table. Consider migrating to a newer version of Rya."; } } catch(final InstanceDoesNotExistException e) { - throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstanceName), e); + throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e); } catch (final RyaClientException e) { throw new RuntimeException("Could not get the instance details. Reason: " + e.getMessage(), e); } @@ -217,18 +217,18 @@ public class RyaAdminCommands implements CommandMarker { public String createPcj() { // Fetch the command that is connected to the store. final ShellState shellState = state.getShellState(); - final RyaClient ryaClient = shellState.getConnectedCommands().get(); - final String ryaInstanceName = shellState.getRyaInstanceName().get(); + final RyaClient commands = shellState.getConnectedCommands().get(); + final String ryaInstance = shellState.getRyaInstanceName().get(); try { // Prompt the user for the SPARQL. final String sparql = sparqlPrompt.getSparql(); // Execute the command. - final String pcjId = ryaClient.getCreatePCJ().createPCJ(ryaInstanceName, sparql); + final String pcjId = commands.getCreatePCJ().createPCJ(ryaInstance, sparql); // Return a message that indicates the ID of the newly created ID. return String.format("The PCJ has been created. Its ID is '%s'.", pcjId); } catch (final InstanceDoesNotExistException e) { - throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstanceName), e); + throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e); } catch (final IOException | RyaClientException e) { throw new RuntimeException("Could not create the PCJ. Provided reasons: " + e.getMessage(), e); } @@ -240,39 +240,54 @@ public class RyaAdminCommands implements CommandMarker { final String pcjId) { // Fetch the command that is connected to the store. final ShellState shellState = state.getShellState(); - final RyaClient ryaClient = shellState.getConnectedCommands().get(); - final String ryaInstanceName = shellState.getRyaInstanceName().get(); + final RyaClient commands = shellState.getConnectedCommands().get(); + final String ryaInstance = shellState.getRyaInstanceName().get(); try { // Execute the command. - ryaClient.getDeletePCJ().deletePCJ(ryaInstanceName, pcjId); + commands.getDeletePCJ().deletePCJ(ryaInstance, pcjId); return "The PCJ has been deleted."; } catch (final InstanceDoesNotExistException e) { - throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstanceName), e); + throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e); } catch (final RyaClientException e) { throw new RuntimeException("The PCJ could not be deleted. Provided reason: " + e.getMessage(), e); } } - @CliCommand(value = BATCH_UPDATE_PCJ_CMD, help = "Batch update a PCJ index using this client. This operation may take a long time.") - public String batchUpdatePcj( - @CliOption(key={"pcjId"}, mandatory = true, help = "The ID of the PCJ that will be updated.") - final String pcjId) { - // Fetch the command that is connected to the store. + @CliCommand(value = ADD_USER_CMD, help = "Adds an authorized user to the Rya instance.") + public void addUser( + @CliOption(key = {"username"}, mandatory = true, help = "The username of the user that will be granted access.") + final String username) { + // Fetch the Rya client that is connected to the store. final ShellState shellState = state.getShellState(); final RyaClient ryaClient = shellState.getConnectedCommands().get(); - final String ryaInstanceName = shellState.getRyaInstanceName().get(); + final String ryaInstance = shellState.getRyaInstanceName().get(); try { - ryaClient.getBatchUpdatePCJ().batchUpdate(ryaInstanceName, pcjId); - return "The PCJ's results have been updated."; - } catch(final InstanceDoesNotExistException e) { - throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstanceName), e); - } catch(final PCJDoesNotExistException e) { - throw new RuntimeException(String.format("A PCJ with ID '%s' does not exist.", pcjId), e); - } catch(final RyaClientException e) { - throw new RuntimeException("The PCJ could not be deleted. Provided reason: " + e.getMessage(), e); + ryaClient.getAddUser().addUser(ryaInstance, username); + } catch (final InstanceDoesNotExistException e) { + throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e); + } catch (final RyaClientException e) { + throw new RuntimeException("The user's access could not be granted. Provided reason: " + e.getMessage(), e); + } + } + + @CliCommand(value = REMOVE_USER_CMD, help = "Removes an authorized user from the Rya instance.") + public void removeUser( + @CliOption(key = {"username"}, mandatory = true, help = "The username of the user whose access will be revoked.") + final String username) { + // Fetch the Rya client that is connected to the store. + final ShellState shellState = state.getShellState(); + final RyaClient ryaClient = shellState.getConnectedCommands().get(); + final String ryaInstance = shellState.getRyaInstanceName().get(); + + try { + ryaClient.getRemoveUser().removeUser(ryaInstance, username); + } catch (final InstanceDoesNotExistException e) { + throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e); + } catch (final RyaClientException e) { + throw new RuntimeException("The user's access could not be revoked. Provided reason: " + e.getMessage(), e); } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/ab4fca46/extras/rya.console/src/main/java/org/apache/rya/shell/util/RyaDetailsFormatter.java ---------------------------------------------------------------------- diff --git a/extras/rya.console/src/main/java/org/apache/rya/shell/util/RyaDetailsFormatter.java b/extras/rya.console/src/main/java/org/apache/rya/shell/util/RyaDetailsFormatter.java index fb00296..dace754 100644 --- a/extras/rya.console/src/main/java/org/apache/rya/shell/util/RyaDetailsFormatter.java +++ b/extras/rya.console/src/main/java/org/apache/rya/shell/util/RyaDetailsFormatter.java @@ -23,13 +23,14 @@ import static java.util.Objects.requireNonNull; import edu.umd.cs.findbugs.annotations.DefaultAnnotation; import edu.umd.cs.findbugs.annotations.NonNull; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; - import org.apache.rya.api.instance.RyaDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails; +import com.google.common.base.Joiner; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; + /** * Formats an instance of {@link RyaDetails}. */ @@ -50,12 +51,13 @@ public class RyaDetailsFormatter { report.append("General Metadata:\n"); report.append(" Instance Name: ").append(details.getRyaInstanceName()).append("\n"); report.append(" RYA Version: ").append( details.getRyaVersion() ).append("\n"); + report.append(" Users: ").append( Joiner.on(", ").join(details.getUsers()) ).append("\n"); report.append("Secondary Indicies:\n"); report.append(" Entity Centric Index:\n"); report.append(" Enabled: ").append( details.getEntityCentricIndexDetails().isEnabled() ).append("\n"); - report.append(" Geospatial Index:\n"); - report.append(" Enabled: ").append( details.getGeoIndexDetails().isEnabled() ).append("\n"); + //RYA-215 report.append(" Geospatial Index:\n"); + //RYA-215 report.append(" Enabled: ").append( details.getGeoIndexDetails().isEnabled() ).append("\n"); report.append(" Free Text Index:\n"); report.append(" Enabled: ").append( details.getFreeTextIndexDetails().isEnabled() ).append("\n"); report.append(" Temporal Index:\n"); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/ab4fca46/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java b/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java index b3cc379..4aa1210 100644 --- a/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java +++ b/extras/rya.console/src/test/java/org/apache/rya/shell/RyaAdminCommandsTest.java @@ -29,12 +29,7 @@ import java.util.Date; import java.util.List; import java.util.TimeZone; -import org.junit.Test; - -import com.google.common.base.Optional; -import com.google.common.collect.Lists; - -import org.apache.rya.api.client.BatchUpdatePCJ; +import org.apache.rya.api.client.AddUser; import org.apache.rya.api.client.CreatePCJ; import org.apache.rya.api.client.DeletePCJ; import org.apache.rya.api.client.GetInstanceDetails; @@ -43,14 +38,13 @@ import org.apache.rya.api.client.Install.DuplicateInstanceNameException; import org.apache.rya.api.client.Install.InstallConfiguration; import org.apache.rya.api.client.InstanceDoesNotExistException; import org.apache.rya.api.client.ListInstances; -import org.apache.rya.api.client.PCJDoesNotExistException; +import org.apache.rya.api.client.RemoveUser; import org.apache.rya.api.client.RyaClient; import org.apache.rya.api.client.RyaClientException; import org.apache.rya.api.client.accumulo.AccumuloConnectionDetails; 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.GeoIndexDetails; import org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails; @@ -60,6 +54,10 @@ import org.apache.rya.api.instance.RyaDetails.ProspectorDetails; import org.apache.rya.api.instance.RyaDetails.TemporalIndexDetails; import org.apache.rya.shell.util.InstallPrompt; import org.apache.rya.shell.util.SparqlPrompt; +import org.junit.Test; + +import com.google.common.base.Optional; +import com.google.common.collect.Lists; /** * Unit tests the methods of {@link RyaAdminCommands}. @@ -125,33 +123,6 @@ public class RyaAdminCommandsTest { } @Test - public void batchUpdatePCJ() throws InstanceDoesNotExistException, PCJDoesNotExistException, RyaClientException { - // Mock the object that performs the update PCJ operation. - final BatchUpdatePCJ mockBatchUpdatePCJ = mock(BatchUpdatePCJ.class); - - final RyaClient mockRyaClient = mock(RyaClient.class); - when(mockRyaClient.getBatchUpdatePCJ()).thenReturn( mockBatchUpdatePCJ ); - - final SharedShellState state = new SharedShellState(); - state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockRyaClient); - final String instanceName = "unitTests"; - state.connectedToInstance(instanceName); - - // Execute the command. - final String pcjId = "12343214312"; - - final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mock(SparqlPrompt.class)); - final String message = commands.batchUpdatePcj(pcjId); - - // Verify the values that were provided to the command were passed through to the BatchUpdatePCJ. - verify(mockBatchUpdatePCJ).batchUpdate(eq(instanceName), eq(pcjId)); - - // Verify a message is returned that explains what was updated. - final String expected = "The PCJ's results have been updated."; - assertEquals(message, expected); - } - - @Test public void getInstanceDetails() throws InstanceDoesNotExistException, RyaClientException { // This test is failed if the default timezone was not EST, so now it's fixed at EST. // If you get assert mismatch of EST!=EDT, try the deprecated getTimeZone("EST") instead. @@ -161,8 +132,11 @@ public class RyaAdminCommandsTest { final String instanceName = "test_instance"; final RyaDetails details = RyaDetails.builder().setRyaInstanceName(instanceName) .setRyaVersion("1.2.3.4") + .addUser("alice") + .addUser("bob") + .addUser("charlie") .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) ) - .setGeoIndexDetails( new GeoIndexDetails(true) ) + //RYA-215.setGeoIndexDetails( new GeoIndexDetails(true) ) .setTemporalIndexDetails( new TemporalIndexDetails(true) ) .setFreeTextDetails( new FreeTextIndexDetails(true) ) .setPCJIndexDetails( @@ -203,11 +177,12 @@ public class RyaAdminCommandsTest { "General Metadata:\n" + " Instance Name: test_instance\n" + " RYA Version: 1.2.3.4\n" + + " Users: alice, bob, charlie\n" + "Secondary Indicies:\n" + " Entity Centric Index:\n" + " Enabled: true\n" + - " Geospatial Index:\n" + - " Enabled: true\n" + + //RYA-215" Geospatial Index:\n" + + //RYA-215" Enabled: true\n" + " Free Text Index:\n" + " Enabled: true\n" + " Temporal Index:\n" + @@ -291,4 +266,44 @@ public class RyaAdminCommandsTest { " d\n"; assertEquals(expected, message); } + + @Test + public void addUser() throws Exception { + // Mock the object that performs the Add User command. + final AddUser mockAddUser = mock(AddUser.class); + + final RyaClient mockClient = mock(RyaClient.class); + when(mockClient.getAddUser()).thenReturn( mockAddUser ); + + final SharedShellState state = new SharedShellState(); + state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockClient); + state.connectedToInstance("test_instance"); + + // Execute the command. + final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mock(SparqlPrompt.class)); + commands.addUser("alice"); + + // Verify the add request was forwarded to the client. + verify(mockAddUser).addUser(eq("test_instance"), eq("alice")); + } + + @Test + public void removeUser() throws Exception { + // Mock the object that performs the Add User command. + final RemoveUser mockRemoveUser = mock(RemoveUser.class); + + final RyaClient mockClient = mock(RyaClient.class); + when(mockClient.getRemoveUser()).thenReturn( mockRemoveUser ); + + final SharedShellState state = new SharedShellState(); + state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockClient); + state.connectedToInstance("test_instance"); + + // Execute the command. + final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mock(SparqlPrompt.class)); + commands.removeUser("alice"); + + // Verify the add request was forwarded to the client. + verify(mockRemoveUser).removeUser(eq("test_instance"), eq("alice")); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/ab4fca46/extras/rya.console/src/test/java/org/apache/rya/shell/util/RyaDetailsFormatterTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.console/src/test/java/org/apache/rya/shell/util/RyaDetailsFormatterTest.java b/extras/rya.console/src/test/java/org/apache/rya/shell/util/RyaDetailsFormatterTest.java index 62ef666..9e45a4f 100644 --- a/extras/rya.console/src/test/java/org/apache/rya/shell/util/RyaDetailsFormatterTest.java +++ b/extras/rya.console/src/test/java/org/apache/rya/shell/util/RyaDetailsFormatterTest.java @@ -23,14 +23,9 @@ import static org.junit.Assert.assertEquals; import java.util.Date; import java.util.TimeZone; -import org.junit.Test; - -import com.google.common.base.Optional; - 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.GeoIndexDetails; import org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.FluoDetails; @@ -38,6 +33,9 @@ import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails.PCJUpdateStrategy; import org.apache.rya.api.instance.RyaDetails.ProspectorDetails; import org.apache.rya.api.instance.RyaDetails.TemporalIndexDetails; +import org.junit.Test; + +import com.google.common.base.Optional; /** * Tests the methods of {@link RyaDetailsFormatter}. @@ -51,8 +49,11 @@ public class RyaDetailsFormatterTest { // Create the object that will be formatted. final RyaDetails details = RyaDetails.builder().setRyaInstanceName("test_instance") .setRyaVersion("1.2.3.4") + .addUser("alice") + .addUser("bob") + .addUser("charlie") .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) ) - .setGeoIndexDetails( new GeoIndexDetails(true) ) + //RYA-215 .setGeoIndexDetails( new GeoIndexDetails(true) ) .setTemporalIndexDetails( new TemporalIndexDetails(true) ) .setFreeTextDetails( new FreeTextIndexDetails(true) ) .setPCJIndexDetails( @@ -79,11 +80,12 @@ public class RyaDetailsFormatterTest { "General Metadata:\n" + " Instance Name: test_instance\n" + " RYA Version: 1.2.3.4\n" + + " Users: alice, bob, charlie\n" + "Secondary Indicies:\n" + " Entity Centric Index:\n" + " Enabled: true\n" + - " Geospatial Index:\n" + - " Enabled: true\n" + + //RYA-215 " Geospatial Index:\n" + + //RYA-215 " Enabled: true\n" + " Free Text Index:\n" + " Enabled: true\n" + " Temporal Index:\n" + http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/ab4fca46/extras/rya.geoindexing/src/main/java/org/apache/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java ---------------------------------------------------------------------- diff --git a/extras/rya.geoindexing/src/main/java/org/apache/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java b/extras/rya.geoindexing/src/main/java/org/apache/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java index 2e99b62..90dd134 100644 --- a/extras/rya.geoindexing/src/main/java/org/apache/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java +++ b/extras/rya.geoindexing/src/main/java/org/apache/rya/indexing/accumulo/geo/GeoMesaGeoIndexer.java @@ -1,5 +1,3 @@ -package org.apache.rya.indexing.accumulo.geo; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,8 +16,9 @@ package org.apache.rya.indexing.accumulo.geo; * specific language governing permissions and limitations * under the License. */ +package org.apache.rya.indexing.accumulo.geo; - +import static java.util.Objects.requireNonNull; import java.io.IOException; import java.io.Serializable; @@ -39,6 +38,16 @@ import org.apache.accumulo.core.client.mock.MockInstance; import org.apache.commons.lang.StringUtils; import org.apache.hadoop.conf.Configuration; import org.apache.log4j.Logger; +import org.apache.rya.accumulo.experimental.AbstractAccumuloIndexer; +import org.apache.rya.api.RdfCloudTripleStoreConfiguration; +import org.apache.rya.api.domain.RyaStatement; +import org.apache.rya.api.resolver.RyaToRdfConversions; +import org.apache.rya.indexing.GeoIndexer; +import org.apache.rya.indexing.Md5Hash; +import org.apache.rya.indexing.OptionalConfigUtils; +import org.apache.rya.indexing.StatementConstraints; +import org.apache.rya.indexing.StatementSerializer; +import org.apache.rya.indexing.accumulo.ConfigUtils; import org.geotools.data.DataStore; import org.geotools.data.DataStoreFinder; import org.geotools.data.DataUtilities; @@ -68,19 +77,8 @@ import org.openrdf.query.QueryEvaluationException; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.io.ParseException; -import com.vividsolutions.jts.io.WKTReader; import info.aduna.iteration.CloseableIteration; -import org.apache.rya.accumulo.experimental.AbstractAccumuloIndexer; -import org.apache.rya.api.RdfCloudTripleStoreConfiguration; -import org.apache.rya.api.domain.RyaStatement; -import org.apache.rya.api.resolver.RyaToRdfConversions; -import org.apache.rya.indexing.GeoIndexer; -import org.apache.rya.indexing.Md5Hash; -import org.apache.rya.indexing.OptionalConfigUtils; -import org.apache.rya.indexing.StatementConstraints; -import org.apache.rya.indexing.StatementSerializer; -import org.apache.rya.indexing.accumulo.ConfigUtils; /** * A {@link GeoIndexer} wrapper around a GeoMesa {@link AccumuloDataStore}. This class configures and connects to the Datastore, creates the @@ -277,7 +275,7 @@ public class GeoMesaGeoIndexer extends AbstractAccumuloIndexer implements GeoInd final SimpleFeature newFeature = SimpleFeatureBuilder.build(featureType, noValues, statementId); // write the statement data to the fields - final Geometry geom = GeoParseUtils.getGeometry(statement); + final Geometry geom = GeoParseUtils.getGeometry(statement); if(geom == null || geom.isEmpty() || !geom.isValid()) { throw new ParseException("Could not create geometry for statement " + statement); } @@ -435,16 +433,27 @@ public class GeoMesaGeoIndexer extends AbstractAccumuloIndexer implements GeoInd @Override public String getTableName() { - return getTableName(conf); + return getTableName(conf); } /** - * Get the Accumulo table that will be used by this index. + * Get the Accumulo table that will be used by this index. * @param conf * @return table name guaranteed to be used by instances of this index */ - public static String getTableName(Configuration conf) { - return ConfigUtils.getTablePrefix(conf) + TABLE_SUFFIX; + public static String getTableName(final Configuration conf) { + return makeTableName( ConfigUtils.getTablePrefix(conf) ); + } + + /** + * Make the Accumulo table name used by this indexer for a specific instance of Rya. + * + * @param ryaInstanceName - The name of the Rya instance the table name is for. (not null) + * @return The Accumulo table name used by this indexer for a specific instance of Rya. + */ + public static String makeTableName(final String ryaInstanceName) { + requireNonNull(ryaInstanceName); + return ryaInstanceName + TABLE_SUFFIX; } private void deleteStatements(final Collection<RyaStatement> ryaStatements) throws IOException { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/ab4fca46/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/AccumuloPcjStorage.java ---------------------------------------------------------------------- diff --git a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/AccumuloPcjStorage.java b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/AccumuloPcjStorage.java index 282d438..6024d12 100644 --- a/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/AccumuloPcjStorage.java +++ b/extras/rya.indexing.pcj/src/main/java/org/apache/rya/indexing/pcj/storage/accumulo/AccumuloPcjStorage.java @@ -32,21 +32,20 @@ import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; import org.apache.accumulo.core.security.Authorizations; -import org.apache.rya.indexing.pcj.storage.PCJIdFactory; -import org.apache.rya.indexing.pcj.storage.PcjMetadata; -import org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage; -import org.openrdf.query.BindingSet; -import org.openrdf.query.MalformedQueryException; - import org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository; +import org.apache.rya.accumulo.utils.TablePermissions; import org.apache.rya.api.instance.RyaDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails; import org.apache.rya.api.instance.RyaDetailsRepository; import org.apache.rya.api.instance.RyaDetailsRepository.RyaDetailsRepositoryException; import org.apache.rya.api.instance.RyaDetailsUpdater; -import org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator; import org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotApplyMutationException; +import org.apache.rya.indexing.pcj.storage.PCJIdFactory; +import org.apache.rya.indexing.pcj.storage.PcjMetadata; +import org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage; +import org.openrdf.query.BindingSet; +import org.openrdf.query.MalformedQueryException; /** * An Accumulo backed implementation of {@link PrecomputedJoinStorage}. @@ -54,6 +53,8 @@ import org.apache.rya.api.instance.RyaDetailsUpdater.RyaDetailsMutator.CouldNotA @DefaultAnnotation(NonNull.class) public class AccumuloPcjStorage implements PrecomputedJoinStorage { + private static final TablePermissions TABLE_PERMISSIONS = new TablePermissions(); + // Factories that are used to create new PCJs. private final PCJIdFactory pcjIdFactory = new PCJIdFactory(); private final PcjTableNameFactory pcjTableNameFactory = new PcjTableNameFactory(); @@ -107,17 +108,14 @@ public class AccumuloPcjStorage implements PrecomputedJoinStorage { final String pcjId = pcjIdFactory.nextId(); try { new RyaDetailsUpdater(ryaDetailsRepo).update( - new RyaDetailsMutator() { - @Override - public RyaDetails mutate(final RyaDetails originalDetails) { - // Create the new PCJ's details. - final PCJDetails.Builder newPcjDetails = PCJDetails.builder().setId( pcjId ); - - // Add them to the instance's details. - final RyaDetails.Builder mutated = RyaDetails.builder(originalDetails); - mutated.getPCJIndexDetails().addPCJDetails( newPcjDetails ); - return mutated.build(); - } + originalDetails -> { + // Create the new PCJ's details. + final PCJDetails.Builder newPcjDetails = PCJDetails.builder().setId( pcjId ); + + // Add them to the instance's details. + final RyaDetails.Builder mutated = RyaDetails.builder(originalDetails); + mutated.getPCJIndexDetails().addPCJDetails( newPcjDetails ); + return mutated.build(); }); } catch (final RyaDetailsRepositoryException | CouldNotApplyMutationException e) { throw new PCJStorageException(String.format("Could not create a new PCJ for Rya instance '%s' " + @@ -127,6 +125,18 @@ public class AccumuloPcjStorage implements PrecomputedJoinStorage { // Create the table that will hold the PCJ's results. final String pcjTableName = pcjTableNameFactory.makeTableName(ryaInstanceName, pcjId); pcjTables.createPcjTable(accumuloConn, pcjTableName, varOrders, sparql); + + // Add access to the PCJ table to all users who are authorized for this instance of Rya. + try { + for(final String user : ryaDetailsRepo.getRyaInstanceDetails().getUsers()) { + TABLE_PERMISSIONS.grantAllPermissions(user, pcjTableName, accumuloConn); + } + } catch (final RyaDetailsRepositoryException | AccumuloException | AccumuloSecurityException e) { + throw new PCJStorageException(String.format("Could not grant authorized users access to the " + + "new PCJ index table '%s' for Rya instance '%s' because of a problem while granting " + + "the permissions.", pcjTableName, ryaInstanceName), e); + } + return pcjId; } @@ -177,14 +187,11 @@ public class AccumuloPcjStorage implements PrecomputedJoinStorage { // Update the Rya Details for this instance to no longer include the PCJ. try { new RyaDetailsUpdater(ryaDetailsRepo).update( - new RyaDetailsMutator() { - @Override - public RyaDetails mutate(final RyaDetails originalDetails) { - // Drop the PCJ's metadata from the instance's metadata. - final RyaDetails.Builder mutated = RyaDetails.builder(originalDetails); - mutated.getPCJIndexDetails().removePCJDetails(pcjId); - return mutated.build(); - } + originalDetails -> { + // Drop the PCJ's metadata from the instance's metadata. + final RyaDetails.Builder mutated = RyaDetails.builder(originalDetails); + mutated.getPCJIndexDetails().removePCJDetails(pcjId); + return mutated.build(); }); } catch (final RyaDetailsRepositoryException | CouldNotApplyMutationException e) { throw new PCJStorageException(String.format("Could not drop an existing PCJ for Rya instance '%s' " + http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/ab4fca46/extras/rya.pcj.fluo/pcj.fluo.demo/src/main/java/org/apache/rya/indexing/pcj/fluo/demo/DemoDriver.java ---------------------------------------------------------------------- diff --git a/extras/rya.pcj.fluo/pcj.fluo.demo/src/main/java/org/apache/rya/indexing/pcj/fluo/demo/DemoDriver.java b/extras/rya.pcj.fluo/pcj.fluo.demo/src/main/java/org/apache/rya/indexing/pcj/fluo/demo/DemoDriver.java index 6b3b973..e8f10b8 100644 --- a/extras/rya.pcj.fluo/pcj.fluo.demo/src/main/java/org/apache/rya/indexing/pcj/fluo/demo/DemoDriver.java +++ b/extras/rya.pcj.fluo/pcj.fluo.demo/src/main/java/org/apache/rya/indexing/pcj/fluo/demo/DemoDriver.java @@ -34,29 +34,16 @@ import org.apache.accumulo.core.client.Instance; import org.apache.accumulo.core.client.ZooKeeperInstance; import org.apache.accumulo.core.client.security.tokens.PasswordToken; import org.apache.accumulo.minicluster.MiniAccumuloCluster; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.rya.indexing.pcj.fluo.app.export.rya.RyaExportParameters; -import org.apache.rya.indexing.pcj.fluo.app.observers.FilterObserver; -import org.apache.rya.indexing.pcj.fluo.app.observers.JoinObserver; -import org.apache.rya.indexing.pcj.fluo.app.observers.QueryResultObserver; -import org.apache.rya.indexing.pcj.fluo.app.observers.StatementPatternObserver; -import org.apache.rya.indexing.pcj.fluo.app.observers.TripleObserver; -import org.apache.rya.indexing.pcj.fluo.demo.Demo.DemoExecutionException; -import org.openrdf.repository.RepositoryConnection; -import org.openrdf.repository.RepositoryException; - -import com.google.common.base.Optional; -import com.google.common.io.Files; - import org.apache.fluo.api.client.FluoClient; import org.apache.fluo.api.client.FluoFactory; import org.apache.fluo.api.config.FluoConfiguration; import org.apache.fluo.api.config.ObserverSpecification; import org.apache.fluo.api.mini.MiniFluo; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; import org.apache.rya.accumulo.AccumuloRdfConfiguration; import org.apache.rya.accumulo.AccumuloRyaDAO; import org.apache.rya.accumulo.instance.AccumuloRyaInstanceDetailsRepository; @@ -64,7 +51,6 @@ import org.apache.rya.api.RdfCloudTripleStoreConfiguration; 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.GeoIndexDetails; import org.apache.rya.api.instance.RyaDetails.JoinSelectivityDetails; import org.apache.rya.api.instance.RyaDetails.PCJIndexDetails; import org.apache.rya.api.instance.RyaDetails.ProspectorDetails; @@ -72,8 +58,20 @@ 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.indexing.pcj.fluo.app.export.rya.RyaExportParameters; +import org.apache.rya.indexing.pcj.fluo.app.observers.FilterObserver; +import org.apache.rya.indexing.pcj.fluo.app.observers.JoinObserver; +import org.apache.rya.indexing.pcj.fluo.app.observers.QueryResultObserver; +import org.apache.rya.indexing.pcj.fluo.app.observers.StatementPatternObserver; +import org.apache.rya.indexing.pcj.fluo.app.observers.TripleObserver; +import org.apache.rya.indexing.pcj.fluo.demo.Demo.DemoExecutionException; import org.apache.rya.rdftriplestore.RdfCloudTripleStore; import org.apache.rya.rdftriplestore.RyaSailRepository; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.RepositoryException; + +import com.google.common.base.Optional; +import com.google.common.io.Files; /** * Runs {@link Demo}s that require Rya and Fluo. @@ -274,7 +272,7 @@ public class DemoDriver { .setRyaVersion("0.0.0.0") .setFreeTextDetails( new FreeTextIndexDetails(true) ) .setEntityCentricIndexDetails( new EntityCentricIndexDetails(true) ) - .setGeoIndexDetails( new GeoIndexDetails(true) ) + //RYA-215 .setGeoIndexDetails( new GeoIndexDetails(true) ) .setTemporalIndexDetails( new TemporalIndexDetails(true) ) .setPCJIndexDetails( PCJIndexDetails.builder()