use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project accumulo by apache.
the class Proxy method execute.
@Override
public void execute(final String[] args) throws Exception {
Opts opts = new Opts();
opts.parseArgs(Proxy.class.getName(), args);
Properties props = new Properties();
if (opts.prop != null) {
props = opts.prop;
} else {
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream("proxy.properties")) {
if (is != null) {
props.load(is);
} else {
System.err.println("proxy.properties needs to be specified as argument (using -p) or on the classpath (by putting the file in conf/)");
System.exit(-1);
}
}
}
boolean useMini = Boolean.parseBoolean(props.getProperty(USE_MINI_ACCUMULO_KEY, USE_MINI_ACCUMULO_DEFAULT));
boolean useMock = Boolean.parseBoolean(props.getProperty(USE_MOCK_INSTANCE_KEY, USE_MOCK_INSTANCE_DEFAULT));
String instance = props.getProperty(ACCUMULO_INSTANCE_NAME_KEY);
String zookeepers = props.getProperty(ZOOKEEPERS_KEY);
if (!useMini && !useMock && instance == null) {
System.err.println("Properties file must contain one of : useMiniAccumulo=true, useMockInstance=true, or instance=<instance name>");
System.exit(1);
}
if (instance != null && zookeepers == null) {
System.err.println("When instance is set in properties file, zookeepers must also be set.");
System.exit(1);
}
if (!props.containsKey("port")) {
System.err.println("No port property");
System.exit(1);
}
if (useMini) {
log.info("Creating mini cluster");
final File folder = Files.createTempDirectory(System.currentTimeMillis() + "").toFile();
final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(folder, "secret");
accumulo.start();
props.setProperty("instance", accumulo.getConfig().getInstanceName());
props.setProperty("zookeepers", accumulo.getZooKeepers());
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void start() {
try {
accumulo.stop();
} catch (Exception e) {
throw new RuntimeException();
} finally {
if (!folder.delete())
log.warn("Unexpected error removing {}", folder);
}
}
});
}
Class<? extends TProtocolFactory> protoFactoryClass = Class.forName(props.getProperty("protocolFactory", TCompactProtocol.Factory.class.getName())).asSubclass(TProtocolFactory.class);
TProtocolFactory protoFactory = protoFactoryClass.newInstance();
int port = Integer.parseInt(props.getProperty("port"));
String hostname = props.getProperty(THRIFT_SERVER_HOSTNAME, THRIFT_SERVER_HOSTNAME_DEFAULT);
HostAndPort address = HostAndPort.fromParts(hostname, port);
ServerAddress server = createProxyServer(address, protoFactory, props);
// Wait for the server to come up
while (!server.server.isServing()) {
Thread.sleep(100);
}
log.info("Proxy server started on {}", server.getAddress());
while (server.server.isServing()) {
Thread.sleep(1000);
}
}
use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project accumulo by apache.
the class StartMojo method execute.
@Override
public void execute() throws MojoExecutionException {
if (shouldSkip()) {
return;
}
File subdir = new File(new File(outputDirectory, "accumulo-maven-plugin"), instanceName);
try {
subdir = subdir.getCanonicalFile();
if (subdir.exists())
FileUtils.forceDelete(subdir);
if (!subdir.mkdirs() && !subdir.isDirectory())
throw new IOException(subdir + " cannot be created as a directory");
MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(subdir, rootPassword);
cfg.setInstanceName(instanceName);
cfg.setZooKeeperPort(zooKeeperPort);
configureMiniClasspath(cfg, miniClasspath);
MiniAccumuloClusterImpl mac = new MiniAccumuloClusterImpl(cfg);
getLog().info("Starting MiniAccumuloCluster: " + mac.getInstanceName() + " in " + mac.getConfig().getDir());
mac.start();
runningClusters.add(mac);
} catch (Exception e) {
throw new MojoExecutionException("Unable to start " + MiniAccumuloCluster.class.getSimpleName(), e);
}
}
use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project incubator-rya by apache.
the class AccumuloIndexSetColumnVisibilityTest method startMiniAccumulo.
private static MiniAccumuloCluster startMiniAccumulo() throws IOException, InterruptedException, AccumuloException, AccumuloSecurityException {
final File miniDataDir = Files.createTempDir();
// Setup and start the Mini Accumulo.
final MiniAccumuloCluster accumulo = new MiniAccumuloCluster(miniDataDir, "password");
accumulo.start();
// Store a connector to the Mini Accumulo.
final Instance instance = new ZooKeeperInstance(accumulo.getInstanceName(), accumulo.getZooKeepers());
accCon = instance.getConnector("root", new PasswordToken("password"));
return accumulo;
}
use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project incubator-rya by apache.
the class AccumuloRyaConnectionCommandsIT method connectToInstance.
@Test
public void connectToInstance() throws IOException {
final MiniAccumuloCluster cluster = getCluster();
final Bootstrap bootstrap = getTestBootstrap();
final JLineShellComponent shell = getTestShell();
// Mock the user entering the correct password.
final ApplicationContext context = bootstrap.getApplicationContext();
final PasswordPrompt mockPrompt = context.getBean(PasswordPrompt.class);
when(mockPrompt.getPassword()).thenReturn("password".toCharArray());
// Connect to the mini accumulo instance.
String cmd = RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " + "--username root " + "--instanceName " + cluster.getInstanceName() + " " + "--zookeepers " + cluster.getZooKeepers();
CommandResult result = shell.executeCommand(cmd);
// Install an instance of rya.
final String instanceName = "testInstance";
final InstallConfiguration installConf = InstallConfiguration.builder().build();
final InstallPrompt installPrompt = context.getBean(InstallPrompt.class);
when(installPrompt.promptInstanceName()).thenReturn("testInstance");
when(installPrompt.promptInstallConfiguration("testInstance")).thenReturn(installConf);
when(installPrompt.promptVerified(instanceName, installConf)).thenReturn(true);
result = shell.executeCommand(RyaAdminCommands.INSTALL_CMD);
assertTrue(result.isSuccess());
// Connect to the instance that was just installed.
cmd = RyaConnectionCommands.CONNECT_INSTANCE_CMD + " --instance " + instanceName;
result = shell.executeCommand(cmd);
assertTrue(result.isSuccess());
// Verify the shell state indicates it is connected to an instance.
final SharedShellState sharedState = context.getBean(SharedShellState.class);
final ShellState state = sharedState.getShellState();
assertEquals(ConnectionState.CONNECTED_TO_INSTANCE, state.getConnectionState());
}
use of org.apache.accumulo.minicluster.MiniAccumuloCluster in project incubator-rya by apache.
the class AccumuloRyaConnectionCommandsIT method disconnect.
@Test
public void disconnect() throws IOException {
final MiniAccumuloCluster cluster = getCluster();
final Bootstrap bootstrap = getTestBootstrap();
final JLineShellComponent shell = getTestShell();
// Mock the user entering the correct password.
final ApplicationContext context = bootstrap.getApplicationContext();
final PasswordPrompt mockPrompt = context.getBean(PasswordPrompt.class);
when(mockPrompt.getPassword()).thenReturn("password".toCharArray());
// Connect to the mini accumulo instance.
final String cmd = RyaConnectionCommands.CONNECT_ACCUMULO_CMD + " " + "--username root " + "--instanceName " + cluster.getInstanceName() + " " + "--zookeepers " + cluster.getZooKeepers();
shell.executeCommand(cmd);
// Disconnect from it.
final CommandResult disconnectResult = shell.executeCommand(RyaConnectionCommands.DISCONNECT_COMMAND_NAME_CMD);
assertTrue(disconnectResult.isSuccess());
}
Aggregations