This blog post is to how to configure and start the Accumulo minicluster. here we implement the cluster in a basic way and more configurable way. Then we connect to the cluster we implement and do basic operation to make sure everything work as expected.
Create a maven project and add the following maven dependency.
‹dependency› ‹groupId›org.apache.accumulo‹/groupId› ‹artifactId›accumulo-minicluster‹/artifactId› ‹version›1.7.0‹/version› ‹/dependency›
First we create a cluster in a basic way. here we provide the pass work and tempro folder. then the username for the cluster will be “root”. Use the following code sample to start the Accumulo.
File tempDir = Files.createTempDir(); try { String password = "pass"; MiniAccumuloCluster accumulo = new MiniAccumuloCluster(tempDir, password); accumulo.start(); Instance instance = new ZooKeeperInstance( accumulo.getInstanceName(), accumulo.getZooKeepers()); Connector conn = instance.getConnector("root", new PasswordToken( "pass")); System.out.println(conn.getInstance().getInstanceName()); accumulo.stop(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AccumuloException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AccumuloSecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); }
Next, what if we want to start the cluster with more configurable way. that is we need to create more clusters with different names and users. And also with no of servers. here the code to do that.
File tempDir = Files.createTempDir(); try { String password = "pass"; String instanceName = "rukspot"; MiniAccumuloConfig config = new MiniAccumuloConfig(tempDir, password).setNumTservers(2).setInstanceName(instanceName); MiniAccumuloCluster accumulo = new MiniAccumuloCluster(config); accumulo.start(); Instance instance = new ZooKeeperInstance(instanceName, accumulo.getZooKeepers()); Connector conn = instance.getConnector("root", new PasswordToken( password)); System.out.println(conn.getInstance().getInstanceName()); accumulo.stop(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AccumuloException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AccumuloSecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); }
At the end you connect to the accumulo instance and check the instance name to verify the connection is successful.
Download the code sample from here.
Add Comment
Comments (0)