use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project hive by apache.
the class TestAccumuloStorageHandler method testNonExternalExistentTable.
@Test(expected = MetaException.class)
public void testNonExternalExistentTable() throws Exception {
MockInstance inst = new MockInstance(test.getMethodName());
Connector conn = inst.getConnector("root", new PasswordToken(""));
String tableName = "table";
// Create the table
conn.tableOperations().create(tableName);
// Define the SerDe Parameters
Map<String, String> params = new HashMap<String, String>();
params.put(AccumuloSerDeParameters.COLUMN_MAPPINGS, "cf:cq");
AccumuloConnectionParameters connectionParams = Mockito.mock(AccumuloConnectionParameters.class);
AccumuloStorageHandler storageHandler = Mockito.mock(AccumuloStorageHandler.class);
StorageDescriptor sd = Mockito.mock(StorageDescriptor.class);
Table table = Mockito.mock(Table.class);
SerDeInfo serDeInfo = Mockito.mock(SerDeInfo.class);
// Call the real preCreateTable method
Mockito.doCallRealMethod().when(storageHandler).preCreateTable(table);
// Return our known table name
Mockito.when(storageHandler.getTableName(table)).thenReturn(tableName);
// Is not an EXTERNAL table
Mockito.when(storageHandler.isExternalTable(table)).thenReturn(false);
// Return the mocked StorageDescriptor
Mockito.when(table.getSd()).thenReturn(sd);
// No location expected with AccumuloStorageHandler
Mockito.when(sd.getLocation()).thenReturn(null);
// Return mocked SerDeInfo
Mockito.when(sd.getSerdeInfo()).thenReturn(serDeInfo);
// Custom parameters
Mockito.when(serDeInfo.getParameters()).thenReturn(params);
// Return the MockInstance's Connector
Mockito.when(connectionParams.getConnector()).thenReturn(conn);
storageHandler.connectionParams = connectionParams;
storageHandler.preCreateTable(table);
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project YCSB by brianfrankcooper.
the class AccumuloClient method init.
@Override
public void init() throws DBException {
colFam = new Text(getProperties().getProperty("accumulo.columnFamily"));
inst = new ZooKeeperInstance(getProperties().getProperty("accumulo.instanceName"), getProperties().getProperty("accumulo.zooKeepers"));
try {
String principal = getProperties().getProperty("accumulo.username");
AuthenticationToken token = new PasswordToken(getProperties().getProperty("accumulo.password"));
connector = inst.getConnector(principal, token);
} catch (AccumuloException e) {
throw new DBException(e);
} catch (AccumuloSecurityException e) {
throw new DBException(e);
}
if (!(getProperties().getProperty("accumulo.pcFlag", "none").equals("none"))) {
System.err.println("Sorry, the ZK based producer/consumer implementation has been removed. " + "Please see YCSB issue #416 for work on adding a general solution to coordinated work.");
}
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.
the class VolumeIT method testReplaceVolume.
private void testReplaceVolume(boolean cleanShutdown) throws Exception {
String[] tableNames = getUniqueNames(3);
verifyVolumesUsed(tableNames[0], false, v1, v2);
// write to 2nd table, but do not flush data to disk before shutdown
writeData(tableNames[1], cluster.getConnector("root", new PasswordToken(ROOT_PASSWORD)));
if (cleanShutdown)
Assert.assertEquals(0, cluster.exec(Admin.class, "stopAll").waitFor());
cluster.stop();
File v1f = new File(v1.toUri());
File v8f = new File(new File(v1.getParent().toUri()), "v8");
Assert.assertTrue("Failed to rename " + v1f + " to " + v8f, v1f.renameTo(v8f));
Path v8 = new Path(v8f.toURI());
File v2f = new File(v2.toUri());
File v9f = new File(new File(v2.getParent().toUri()), "v9");
Assert.assertTrue("Failed to rename " + v2f + " to " + v9f, v2f.renameTo(v9f));
Path v9 = new Path(v9f.toURI());
Configuration conf = new Configuration(false);
conf.addResource(new Path(cluster.getConfig().getConfDir().toURI().toString(), "accumulo-site.xml"));
conf.set(Property.INSTANCE_VOLUMES.getKey(), v8 + "," + v9);
conf.set(Property.INSTANCE_VOLUMES_REPLACEMENTS.getKey(), v1 + " " + v8 + "," + v2 + " " + v9);
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(cluster.getConfig().getConfDir(), "accumulo-site.xml")));
conf.writeXml(fos);
fos.close();
// start cluster and verify that volumes were replaced
cluster.start();
verifyVolumesUsed(tableNames[0], true, v8, v9);
verifyVolumesUsed(tableNames[1], true, v8, v9);
// verify writes to new dir
getConnector().tableOperations().compact(tableNames[0], null, null, true, true);
getConnector().tableOperations().compact(tableNames[1], null, null, true, true);
verifyVolumesUsed(tableNames[0], true, v8, v9);
verifyVolumesUsed(tableNames[1], true, v8, v9);
// check that root tablet is not on volume 1 or 2
ZooReader zreader = new ZooReader(cluster.getZooKeepers(), 30000);
String zpath = ZooUtil.getRoot(new ZooKeeperInstance(cluster.getClientConfig())) + RootTable.ZROOT_TABLET_PATH;
String rootTabletDir = new String(zreader.getData(zpath, false, null), UTF_8);
Assert.assertTrue(rootTabletDir.startsWith(v8.toString()) || rootTabletDir.startsWith(v9.toString()));
getConnector().tableOperations().clone(tableNames[1], tableNames[2], true, new HashMap<>(), new HashSet<>());
getConnector().tableOperations().flush(MetadataTable.NAME, null, null, true);
getConnector().tableOperations().flush(RootTable.NAME, null, null, true);
verifyVolumesUsed(tableNames[0], true, v8, v9);
verifyVolumesUsed(tableNames[1], true, v8, v9);
verifyVolumesUsed(tableNames[2], true, v8, v9);
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.
the class VolumeIT method testRemoveVolumes.
@Test
public void testRemoveVolumes() throws Exception {
String[] tableNames = getUniqueNames(2);
verifyVolumesUsed(tableNames[0], false, v1, v2);
Assert.assertEquals(0, cluster.exec(Admin.class, "stopAll").waitFor());
cluster.stop();
Configuration conf = new Configuration(false);
conf.addResource(new Path(cluster.getConfig().getConfDir().toURI().toString(), "accumulo-site.xml"));
conf.set(Property.INSTANCE_VOLUMES.getKey(), v2.toString());
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(cluster.getConfig().getConfDir(), "accumulo-site.xml")));
conf.writeXml(fos);
fos.close();
// start cluster and verify that volume was decommisioned
cluster.start();
Connector conn = cluster.getConnector("root", new PasswordToken(ROOT_PASSWORD));
conn.tableOperations().compact(tableNames[0], null, null, true, true);
verifyVolumesUsed(tableNames[0], true, v2);
// check that root tablet is not on volume 1
ZooReader zreader = new ZooReader(cluster.getZooKeepers(), 30000);
String zpath = ZooUtil.getRoot(new ZooKeeperInstance(cluster.getClientConfig())) + RootTable.ZROOT_TABLET_PATH;
String rootTabletDir = new String(zreader.getData(zpath, false, null), UTF_8);
Assert.assertTrue(rootTabletDir.startsWith(v2.toString()));
conn.tableOperations().clone(tableNames[0], tableNames[1], true, new HashMap<>(), new HashSet<>());
conn.tableOperations().flush(MetadataTable.NAME, null, null, true);
conn.tableOperations().flush(RootTable.NAME, null, null, true);
verifyVolumesUsed(tableNames[0], true, v2);
verifyVolumesUsed(tableNames[1], true, v2);
}
use of org.apache.accumulo.core.client.security.tokens.PasswordToken in project accumulo by apache.
the class UsersIT method testCreateExistingUser.
@Test
public void testCreateExistingUser() throws Exception {
ClusterUser user0 = getUser(0);
Connector conn = getConnector();
Set<String> currentUsers = conn.securityOperations().listLocalUsers();
// Ensure that the user exists
if (!currentUsers.contains(user0.getPrincipal())) {
PasswordToken token = null;
if (!getCluster().getClientConfig().hasSasl()) {
token = new PasswordToken(user0.getPassword());
}
conn.securityOperations().createLocalUser(user0.getPrincipal(), token);
}
try {
conn.securityOperations().createLocalUser(user0.getPrincipal(), new PasswordToken("better_fail"));
fail("Creating a user that already exists should throw an exception");
} catch (AccumuloSecurityException e) {
assertTrue("Expected USER_EXISTS error", SecurityErrorCode.USER_EXISTS == e.getSecurityErrorCode());
String msg = e.getMessage();
assertTrue("Error message didn't contain principal: '" + msg + "'", msg.contains(user0.getPrincipal()));
}
}
Aggregations