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);
}
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"));
}
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.";
}
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.";
}
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);
}
Aggregations