Search in sources :

Example 71 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class RyaAdminCommandsTest method installWithAccumuloParameters_userAbort.

@Test
public void installWithAccumuloParameters_userAbort() throws DuplicateInstanceNameException, RyaClientException, IOException {
    // Mock the object that performs the install operation.
    final Install mockInstall = mock(Install.class);
    final RyaClient mockCommands = mock(RyaClient.class);
    when(mockCommands.getInstall()).thenReturn(mockInstall);
    final SharedShellState state = new SharedShellState();
    state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
    final String instanceName = "unitTests";
    final boolean enableTableHashPrefix = false;
    final boolean enableEntityCentricIndex = true;
    final boolean enableFreeTextIndex = false;
    final boolean enableTemporalIndex = false;
    final boolean enablePcjIndex = true;
    final String fluoPcjAppName = instanceName + "pcj_updater";
    // Execute the command.
    final InstallConfiguration installConfig = InstallConfiguration.builder().setEnableTableHashPrefix(enableTableHashPrefix).setEnableEntityCentricIndex(enableEntityCentricIndex).setEnableFreeTextIndex(enableFreeTextIndex).setEnableTemporalIndex(enableTemporalIndex).setEnablePcjIndex(enablePcjIndex).setFluoPcjAppName(fluoPcjAppName).build();
    final InstallPrompt mockInstallPrompt = mock(InstallPrompt.class);
    when(mockInstallPrompt.promptInstanceName()).thenReturn(instanceName);
    when(mockInstallPrompt.promptInstallConfiguration(instanceName)).thenReturn(installConfig);
    when(mockInstallPrompt.promptVerified(eq(instanceName), eq(installConfig))).thenReturn(false);
    final RyaAdminCommands commands = new RyaAdminCommands(state, mockInstallPrompt, mock(SparqlPrompt.class), mock(UninstallPrompt.class));
    final String message = commands.installWithAccumuloParameters(instanceName, enableTableHashPrefix, enableEntityCentricIndex, enableFreeTextIndex, enableTemporalIndex, enablePcjIndex, fluoPcjAppName);
    // Verify a message is returned that indicates the success of the operation.
    final String expected = "Skipping Installation.";
    assertEquals(expected, message);
}
Also used : AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) Install(org.apache.rya.api.client.Install) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) UninstallPrompt(org.apache.rya.shell.util.UninstallPrompt) Test(org.junit.Test)

Example 72 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class RyaAdminCommandsTest method removeUser.

@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(java.util.Optional.of(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), mock(UninstallPrompt.class));
    commands.removeUser("alice");
    // Verify the add request was forwarded to the client.
    verify(mockRemoveUser).removeUser(eq("test_instance"), eq("alice"));
}
Also used : RemoveUser(org.apache.rya.api.client.RemoveUser) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) UninstallPrompt(org.apache.rya.shell.util.UninstallPrompt) Test(org.junit.Test)

Example 73 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class RyaConnectionCommands method connectToAccumulo.

@CliCommand(value = CONNECT_ACCUMULO_CMD, help = "Connect the shell to an instance of Accumulo.")
public String connectToAccumulo(@CliOption(key = { "username" }, mandatory = true, help = "The username that will be used to connect to Accummulo.") final String username, @CliOption(key = { "instanceName" }, mandatory = true, help = "The name of the Accumulo instance that will be connected to.") final String instanceName, @CliOption(key = { "zookeepers" }, mandatory = true, help = "A comma delimited list of zookeeper server hostnames.") final String zookeepers) {
    try {
        // Prompt the user for their password.
        final char[] password = passwordPrompt.getPassword();
        final Connector connector = new ConnectorFactory().connect(username, CharBuffer.wrap(password), instanceName, zookeepers);
        // Initialize the connected to Accumulo shared state.
        final AccumuloConnectionDetails accumuloDetails = new AccumuloConnectionDetails(username, password, instanceName, zookeepers);
        final RyaClient commands = AccumuloRyaClientFactory.build(accumuloDetails, connector);
        sharedState.connectedToAccumulo(accumuloDetails, commands);
    } catch (IOException | AccumuloException | AccumuloSecurityException e) {
        throw new RuntimeException("Could not connect to Accumulo. Reason: " + e.getMessage(), e);
    }
    return "Connected. You must select a Rya instance to interact with next.";
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ConnectorFactory(org.apache.rya.shell.util.ConnectorFactory) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) RyaClient(org.apache.rya.api.client.RyaClient) IOException(java.io.IOException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 74 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class RyaConnectionCommands method connectToMongo.

@CliCommand(value = CONNECT_MONGO_CMD, help = "Connect the shell to an instance of MongoDB.")
public String connectToMongo(@CliOption(key = { "username" }, mandatory = false, help = "The username that will be used to connect to MongoDB when performing administrative tasks.") final String username, @CliOption(key = { "hostname" }, mandatory = true, help = "The hostname of the MongoDB that will be connected to.") final String hostname, @CliOption(key = { "port" }, mandatory = true, help = "The port of the MongoDB that will be connected to.") final String port) {
    try {
        // If a username was provided, then prompt for a password.
        char[] password = null;
        if (username != null) {
            password = passwordPrompt.getPassword();
        }
        // Create the Mongo Connection Details that describe the Mongo DB Server we are interacting with.
        final MongoConnectionDetails connectionDetails = new MongoConnectionDetails(hostname, Integer.parseInt(port), Optional.ofNullable(username), Optional.ofNullable(password));
        // Connect to a MongoDB server. TODO Figure out how to provide auth info?
        final MongoClient adminClient = new MongoClient(hostname, Integer.parseInt(port));
        // Make sure the client is closed at shutdown.
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                adminClient.close();
            }
        });
        try {
            // attempt to get the connection point, essentially pinging mongo server.
            adminClient.getConnectPoint();
        } catch (final MongoException e) {
            // had to rethrow to get scope on adminClient.
            adminClient.close();
            throw e;
        }
        // Initialize the connected to Mongo shared state.
        final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, adminClient);
        sharedState.connectedToMongo(connectionDetails, ryaClient);
    } catch (final IOException | MongoException e) {
        throw new RuntimeException("Could not connection to MongoDB. Reason: " + e.getMessage(), e);
    }
    return "Connected. You must select a Rya instance to interact with next.";
}
Also used : MongoConnectionDetails(org.apache.rya.api.client.mongo.MongoConnectionDetails) MongoClient(com.mongodb.MongoClient) MongoException(com.mongodb.MongoException) RyaClient(org.apache.rya.api.client.RyaClient) IOException(java.io.IOException) CliCommand(org.springframework.shell.core.annotation.CliCommand)

Example 75 with RyaClient

use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.

the class RyaAdminCommandsTest method createPCJ_noExportStrategy.

@Test
public void createPCJ_noExportStrategy() throws InstanceDoesNotExistException, RyaClientException, IOException {
    // Mock the object that performs the create operation.
    final String instanceName = "unitTest";
    final RyaClient mockCommands = mock(RyaClient.class);
    final SharedShellState state = new SharedShellState();
    state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
    state.connectedToInstance(instanceName);
    // Execute the command.
    final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mock(SparqlPrompt.class), mock(UninstallPrompt.class));
    final String message = commands.createPcj(false, false);
    // Verify a message is returned that explains what was created.
    assertEquals("The user must specify at least one export strategy: (--exportToRya, --exportToKafka)", message);
}
Also used : AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) RyaClient(org.apache.rya.api.client.RyaClient) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) UninstallPrompt(org.apache.rya.shell.util.UninstallPrompt) Test(org.junit.Test)

Aggregations

RyaClient (org.apache.rya.api.client.RyaClient)105 Test (org.junit.Test)76 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)41 SparqlPrompt (org.apache.rya.shell.util.SparqlPrompt)29 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)26 CliCommand (org.springframework.shell.core.annotation.CliCommand)20 RyaClientException (org.apache.rya.api.client.RyaClientException)18 Install (org.apache.rya.api.client.Install)17 ShellState (org.apache.rya.shell.SharedShellState.ShellState)16 InstallPrompt (org.apache.rya.shell.util.InstallPrompt)16 UninstallPrompt (org.apache.rya.shell.util.UninstallPrompt)16 RyaDetails (org.apache.rya.api.instance.RyaDetails)14 ConsolePrinter (org.apache.rya.shell.util.ConsolePrinter)13 IOException (java.io.IOException)11 InstanceDoesNotExistException (org.apache.rya.api.client.InstanceDoesNotExistException)9 Sail (org.openrdf.sail.Sail)9 ValueFactory (org.openrdf.model.ValueFactory)8 HashSet (java.util.HashSet)7 Connector (org.apache.accumulo.core.client.Connector)7 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)7