use of org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl in project accumulo by apache.
the class KerberosIT method startMac.
@Before
public void startMac() throws Exception {
MiniClusterHarness harness = new MiniClusterHarness();
mac = harness.create(this, new PasswordToken("unused"), kdc, new MiniClusterConfigurationCallback() {
@Override
public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration coreSite) {
Map<String, String> site = cfg.getSiteConfig();
site.put(Property.INSTANCE_ZK_TIMEOUT.getKey(), "15s");
cfg.setSiteConfig(site);
}
});
mac.getConfig().setNumTservers(1);
mac.start();
// Enabled kerberos auth
Configuration conf = new Configuration(false);
conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
UserGroupInformation.setConfiguration(conf);
}
use of org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl in project accumulo by apache.
the class ExistingMacIT method testExistingInstance.
@Test
public void testExistingInstance() throws Exception {
AccumuloClient client = getCluster().createAccumuloClient("root", new PasswordToken(ROOT_PASSWORD));
client.tableOperations().create("table1");
try (BatchWriter bw = client.createBatchWriter("table1")) {
Mutation m1 = new Mutation("00081");
m1.put("math", "sqroot", "9");
m1.put("math", "sq", "6560");
bw.addMutation(m1);
}
client.tableOperations().flush("table1", null, null, true);
// TODO use constants
client.tableOperations().flush(MetadataTable.NAME, null, null, true);
client.tableOperations().flush(RootTable.NAME, null, null, true);
Set<Entry<ServerType, Collection<ProcessReference>>> procs = getCluster().getProcesses().entrySet();
for (Entry<ServerType, Collection<ProcessReference>> entry : procs) {
if (entry.getKey() == ServerType.ZOOKEEPER)
continue;
for (ProcessReference pr : entry.getValue()) getCluster().killProcess(entry.getKey(), pr);
}
final DefaultConfiguration defaultConfig = DefaultConfiguration.getInstance();
final long zkTimeout = ConfigurationTypeHelper.getTimeInMillis(getCluster().getConfig().getSiteConfig().get(Property.INSTANCE_ZK_TIMEOUT.getKey()));
ZooReaderWriter zrw = new ZooReaderWriter(getCluster().getZooKeepers(), (int) zkTimeout, defaultConfig.get(Property.INSTANCE_SECRET));
final String zInstanceRoot = Constants.ZROOT + "/" + client.instanceOperations().getInstanceId();
while (!AccumuloStatus.isAccumuloOffline(zrw, zInstanceRoot)) {
log.debug("Accumulo services still have their ZK locks held");
Thread.sleep(1000);
}
File hadoopConfDir = createTestDir(ExistingMacIT.class.getSimpleName() + "_hadoop_conf");
FileUtils.deleteQuietly(hadoopConfDir);
assertTrue(hadoopConfDir.mkdirs());
createEmptyConfig(new File(hadoopConfDir, "core-site.xml"));
createEmptyConfig(new File(hadoopConfDir, "hdfs-site.xml"));
File testDir2 = createTestDir(ExistingMacIT.class.getSimpleName() + "_2");
FileUtils.deleteQuietly(testDir2);
MiniAccumuloConfigImpl macConfig2 = new MiniAccumuloConfigImpl(testDir2, "notused");
macConfig2.useExistingInstance(new File(getCluster().getConfig().getConfDir(), "accumulo.properties"), hadoopConfDir);
MiniAccumuloClusterImpl accumulo2 = new MiniAccumuloClusterImpl(macConfig2);
accumulo2.start();
client = accumulo2.createAccumuloClient("root", new PasswordToken(ROOT_PASSWORD));
try (Scanner scanner = client.createScanner("table1", Authorizations.EMPTY)) {
int sum = 0;
for (Entry<Key, Value> entry : scanner) {
sum += Integer.parseInt(entry.getValue().toString());
}
assertEquals(6569, sum);
}
accumulo2.stop();
}
use of org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl in project accumulo by apache.
the class ExistingMacIT method testExistingRunningInstance.
@Test
public void testExistingRunningInstance() throws Exception {
final String table = getUniqueNames(1)[0];
try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
// Ensure that a manager and tserver are up so the existing instance check won't fail.
client.tableOperations().create(table);
try (BatchWriter bw = client.createBatchWriter(table)) {
Mutation m = new Mutation("foo");
m.put("cf", "cq", "value");
bw.addMutation(m);
}
File hadoopConfDir = createTestDir(ExistingMacIT.class.getSimpleName() + "_hadoop_conf_2");
FileUtils.deleteQuietly(hadoopConfDir);
assertTrue(hadoopConfDir.mkdirs());
createEmptyConfig(new File(hadoopConfDir, "core-site.xml"));
createEmptyConfig(new File(hadoopConfDir, "hdfs-site.xml"));
File testDir2 = createTestDir(ExistingMacIT.class.getSimpleName() + "_3");
FileUtils.deleteQuietly(testDir2);
MiniAccumuloConfigImpl macConfig2 = new MiniAccumuloConfigImpl(testDir2, "notused");
macConfig2.useExistingInstance(new File(getCluster().getConfig().getConfDir(), "accumulo.properties"), hadoopConfDir);
System.out.println("conf " + new File(getCluster().getConfig().getConfDir(), "accumulo.properties"));
MiniAccumuloClusterImpl accumulo2 = new MiniAccumuloClusterImpl(macConfig2);
RuntimeException e = assertThrows("A 2nd MAC instance should not be able to start over an existing MAC instance", RuntimeException.class, accumulo2::start);
assertEquals("The Accumulo instance being used is already running. Aborting.", e.getMessage());
}
}
use of org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl in project accumulo by apache.
the class UnorderedWorkAssignerReplicationIT method dataReplicatedToCorrectTable.
@Test
public void dataReplicatedToCorrectTable() throws Exception {
MiniAccumuloConfigImpl peerCfg = new MiniAccumuloConfigImpl(createTestDir(this.getClass().getName() + "_" + this.testName.getMethodName() + "_peer"), ROOT_PASSWORD);
peerCfg.setNumTservers(1);
peerCfg.setInstanceName("peer");
updatePeerConfigFromPrimary(getCluster().getConfig(), peerCfg);
peerCfg.setProperty(Property.REPLICATION_NAME, "peer");
MiniAccumuloClusterImpl peer1Cluster = new MiniAccumuloClusterImpl(peerCfg);
peer1Cluster.start();
try (AccumuloClient clientManager = Accumulo.newClient().from(getClientProperties()).build();
AccumuloClient clientPeer = peer1Cluster.createAccumuloClient("root", new PasswordToken(ROOT_PASSWORD))) {
String peerClusterName = "peer";
String peerUserName = "peer", peerPassword = "foo";
// Create local user
clientPeer.securityOperations().createLocalUser(peerUserName, new PasswordToken(peerPassword));
clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_USER.getKey() + peerClusterName, peerUserName);
clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_PASSWORD.getKey() + peerClusterName, peerPassword);
// ...peer = AccumuloReplicaSystem,instanceName,zookeepers
clientManager.instanceOperations().setProperty(Property.REPLICATION_PEERS.getKey() + peerClusterName, ReplicaSystemFactory.getPeerConfigurationValue(AccumuloReplicaSystem.class, AccumuloReplicaSystem.buildConfiguration(peer1Cluster.getInstanceName(), peer1Cluster.getZooKeepers())));
String managerTable1 = "manager1", peerTable1 = "peer1", managerTable2 = "manager2", peerTable2 = "peer2";
// Create tables
clientPeer.tableOperations().create(peerTable1);
String peerTableId1 = clientPeer.tableOperations().tableIdMap().get(peerTable1);
assertNotNull(peerTableId1);
clientPeer.tableOperations().create(peerTable2);
String peerTableId2 = clientPeer.tableOperations().tableIdMap().get(peerTable2);
assertNotNull(peerTableId2);
// Grant write permission
clientPeer.securityOperations().grantTablePermission(peerUserName, peerTable1, TablePermission.WRITE);
clientPeer.securityOperations().grantTablePermission(peerUserName, peerTable2, TablePermission.WRITE);
Map<String, String> props1 = new HashMap<>();
props1.put(Property.TABLE_REPLICATION.getKey(), "true");
props1.put(Property.TABLE_REPLICATION_TARGET.getKey() + peerClusterName, peerTableId1);
clientManager.tableOperations().create(managerTable1, new NewTableConfiguration().setProperties(props1));
String managerTableId1 = clientManager.tableOperations().tableIdMap().get(managerTable1);
assertNotNull(managerTableId1);
Map<String, String> props2 = new HashMap<>();
props2.put(Property.TABLE_REPLICATION.getKey(), "true");
props2.put(Property.TABLE_REPLICATION_TARGET.getKey() + peerClusterName, peerTableId2);
clientManager.tableOperations().create(managerTable2, new NewTableConfiguration().setProperties(props2));
String managerTableId2 = clientManager.tableOperations().tableIdMap().get(managerTable2);
assertNotNull(managerTableId2);
// Wait for zookeeper updates (configuration) to propagate
sleepUninterruptibly(3, TimeUnit.SECONDS);
// Write some data to table1
long managerTable1Records = 0L;
try (BatchWriter bw = clientManager.createBatchWriter(managerTable1)) {
for (int rows = 0; rows < 2500; rows++) {
Mutation m = new Mutation(managerTable1 + rows);
for (int cols = 0; cols < 100; cols++) {
String value = Integer.toString(cols);
m.put(value, "", value);
managerTable1Records++;
}
bw.addMutation(m);
}
}
// Write some data to table2
long managerTable2Records = 0L;
try (BatchWriter bw = clientManager.createBatchWriter(managerTable2)) {
for (int rows = 0; rows < 2500; rows++) {
Mutation m = new Mutation(managerTable2 + rows);
for (int cols = 0; cols < 100; cols++) {
String value = Integer.toString(cols);
m.put(value, "", value);
managerTable2Records++;
}
bw.addMutation(m);
}
}
log.info("Wrote all data to manager cluster");
Set<String> filesFor1 = clientManager.replicationOperations().referencedFiles(managerTable1), filesFor2 = clientManager.replicationOperations().referencedFiles(managerTable2);
while (!ReplicationTable.isOnline(clientManager)) {
Thread.sleep(500);
}
// Restart the tserver to force a close on the WAL
for (ProcessReference proc : cluster.getProcesses().get(ServerType.TABLET_SERVER)) {
cluster.killProcess(ServerType.TABLET_SERVER, proc);
}
cluster.exec(TabletServer.class);
log.info("Restarted the tserver");
// Read the data -- the tserver is back up and running
Iterators.size(clientManager.createScanner(managerTable1, Authorizations.EMPTY).iterator());
// Wait for both tables to be replicated
log.info("Waiting for {} for {}", filesFor1, managerTable1);
clientManager.replicationOperations().drain(managerTable1, filesFor1);
log.info("Waiting for {} for {}", filesFor2, managerTable2);
clientManager.replicationOperations().drain(managerTable2, filesFor2);
long countTable = 0L;
for (int i = 0; i < 5; i++) {
countTable = 0L;
for (Entry<Key, Value> entry : clientPeer.createScanner(peerTable1, Authorizations.EMPTY)) {
countTable++;
assertTrue("Found unexpected key-value" + entry.getKey().toStringNoTruncate() + " " + entry.getValue(), entry.getKey().getRow().toString().startsWith(managerTable1));
}
log.info("Found {} records in {}", countTable, peerTable1);
if (managerTable1Records != countTable) {
log.warn("Did not find {} expected records in {}, only found {}", managerTable1Records, peerTable1, countTable);
}
}
assertEquals(managerTable1Records, countTable);
for (int i = 0; i < 5; i++) {
countTable = 0L;
for (Entry<Key, Value> entry : clientPeer.createScanner(peerTable2, Authorizations.EMPTY)) {
countTable++;
assertTrue("Found unexpected key-value" + entry.getKey().toStringNoTruncate() + " " + entry.getValue(), entry.getKey().getRow().toString().startsWith(managerTable2));
}
log.info("Found {} records in {}", countTable, peerTable2);
if (managerTable2Records != countTable) {
log.warn("Did not find {} expected records in {}, only found {}", managerTable2Records, peerTable2, countTable);
}
}
assertEquals(managerTable2Records, countTable);
} finally {
peer1Cluster.stop();
}
}
use of org.apache.accumulo.miniclusterImpl.MiniAccumuloConfigImpl in project accumulo by apache.
the class UnorderedWorkAssignerReplicationIT method dataWasReplicatedToThePeerWithoutDrain.
@Test
public void dataWasReplicatedToThePeerWithoutDrain() throws Exception {
MiniAccumuloConfigImpl peerCfg = new MiniAccumuloConfigImpl(createTestDir(this.getClass().getName() + "_" + this.testName.getMethodName() + "_peer"), ROOT_PASSWORD);
peerCfg.setNumTservers(1);
peerCfg.setInstanceName("peer");
updatePeerConfigFromPrimary(getCluster().getConfig(), peerCfg);
peerCfg.setProperty(Property.REPLICATION_NAME, "peer");
MiniAccumuloClusterImpl peerCluster = new MiniAccumuloClusterImpl(peerCfg);
peerCluster.start();
try (AccumuloClient clientManager = Accumulo.newClient().from(getClientProperties()).build();
AccumuloClient clientPeer = peerCluster.createAccumuloClient("root", new PasswordToken(ROOT_PASSWORD))) {
String peerUserName = "repl";
String peerPassword = "passwd";
// Create a user on the peer for replication to use
clientPeer.securityOperations().createLocalUser(peerUserName, new PasswordToken(peerPassword));
String peerClusterName = "peer";
// ...peer = AccumuloReplicaSystem,instanceName,zookeepers
clientManager.instanceOperations().setProperty(Property.REPLICATION_PEERS.getKey() + peerClusterName, ReplicaSystemFactory.getPeerConfigurationValue(AccumuloReplicaSystem.class, AccumuloReplicaSystem.buildConfiguration(peerCluster.getInstanceName(), peerCluster.getZooKeepers())));
// Configure the credentials we should use to authenticate ourselves to the peer for
// replication
clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_USER.getKey() + peerClusterName, peerUserName);
clientManager.instanceOperations().setProperty(Property.REPLICATION_PEER_PASSWORD.getKey() + peerClusterName, peerPassword);
String managerTable = "manager", peerTable = "peer";
clientPeer.tableOperations().create(peerTable);
String peerTableId = clientPeer.tableOperations().tableIdMap().get(peerTable);
assertNotNull(peerTableId);
Map<String, String> props = new HashMap<>();
props.put(Property.TABLE_REPLICATION.getKey(), "true");
props.put(Property.TABLE_REPLICATION_TARGET.getKey() + peerClusterName, peerTableId);
clientManager.tableOperations().create(managerTable, new NewTableConfiguration().setProperties(props));
String managerTableId = clientManager.tableOperations().tableIdMap().get(managerTable);
assertNotNull(managerTableId);
// Give our replication user the ability to write to the table
clientPeer.securityOperations().grantTablePermission(peerUserName, peerTable, TablePermission.WRITE);
// Write some data to table1
try (BatchWriter bw = clientManager.createBatchWriter(managerTable)) {
for (int rows = 0; rows < 5000; rows++) {
Mutation m = new Mutation(Integer.toString(rows));
for (int cols = 0; cols < 100; cols++) {
String value = Integer.toString(cols);
m.put(value, "", value);
}
bw.addMutation(m);
}
}
log.info("Wrote all data to manager cluster");
Set<String> files = clientManager.replicationOperations().referencedFiles(managerTable);
for (String s : files) {
log.info("Found referenced file for {}: {}", managerTable, s);
}
for (ProcessReference proc : cluster.getProcesses().get(ServerType.TABLET_SERVER)) {
cluster.killProcess(ServerType.TABLET_SERVER, proc);
}
cluster.exec(TabletServer.class);
Iterators.size(clientManager.createScanner(managerTable, Authorizations.EMPTY).iterator());
try (var scanner = clientManager.createScanner(ReplicationTable.NAME, Authorizations.EMPTY)) {
for (Entry<Key, Value> kv : scanner) {
log.debug("{} {}", kv.getKey().toStringNoTruncate(), ProtobufUtil.toString(Status.parseFrom(kv.getValue().get())));
}
}
clientManager.replicationOperations().drain(managerTable, files);
try (Scanner manager = clientManager.createScanner(managerTable, Authorizations.EMPTY);
Scanner peer = clientPeer.createScanner(peerTable, Authorizations.EMPTY)) {
Iterator<Entry<Key, Value>> managerIter = manager.iterator(), peerIter = peer.iterator();
assertTrue("No data in manager table", managerIter.hasNext());
assertTrue("No data in peer table", peerIter.hasNext());
while (managerIter.hasNext() && peerIter.hasNext()) {
Entry<Key, Value> managerEntry = managerIter.next(), peerEntry = peerIter.next();
assertEquals(peerEntry.getKey() + " was not equal to " + peerEntry.getKey(), 0, managerEntry.getKey().compareTo(peerEntry.getKey(), PartialKey.ROW_COLFAM_COLQUAL_COLVIS));
assertEquals(managerEntry.getValue(), peerEntry.getValue());
}
assertFalse("Had more data to read from the manager", managerIter.hasNext());
assertFalse("Had more data to read from the peer", peerIter.hasNext());
}
peerCluster.stop();
}
}
Aggregations