use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.
the class ZKPermHandler method initialize.
@Override
public void initialize(ServerContext context) {
zooCache = new ZooCache(context.getZooReaderWriter(), null);
zoo = context.getZooReaderWriter();
InstanceId instanceId = context.getInstanceID();
ZKUserPath = ZKSecurityTool.getInstancePath(instanceId) + "/users";
ZKTablePath = ZKSecurityTool.getInstancePath(instanceId) + "/tables";
ZKNamespacePath = ZKSecurityTool.getInstancePath(instanceId) + "/namespaces";
}
use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.
the class ThriftServerBindsBeforeZooKeeperLockIT method testManagerService.
@SuppressFBWarnings(value = "UNENCRYPTED_SOCKET", justification = "unencrypted socket is okay for testing")
@Test
public void testManagerService() throws Exception {
final MiniAccumuloClusterImpl cluster = (MiniAccumuloClusterImpl) getCluster();
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
final InstanceId instanceID = client.instanceOperations().getInstanceId();
// Wait for the Manager to grab its lock
while (true) {
final ZooReader reader = new ZooReader(cluster.getZooKeepers(), 30000);
try {
List<String> locks = reader.getChildren(Constants.ZROOT + "/" + instanceID + Constants.ZMANAGER_LOCK);
if (!locks.isEmpty()) {
break;
}
} catch (Exception e) {
LOG.debug("Failed to find active manager location, retrying", e);
Thread.sleep(1000);
}
}
LOG.debug("Found active manager");
int freePort = PortUtils.getRandomFreePort();
Process manager = null;
try {
LOG.debug("Starting standby manager on {}", freePort);
manager = startProcess(cluster, ServerType.MANAGER, freePort);
while (true) {
try (Socket s = new Socket("localhost", freePort)) {
if (s.isConnected()) {
// Pass
return;
}
} catch (Exception e) {
LOG.debug("Caught exception trying to connect to Manager", e);
}
// Wait before trying again
Thread.sleep(1000);
// died trying to bind it. Pick a new port and restart it in that case.
if (!manager.isAlive()) {
freePort = PortUtils.getRandomFreePort();
LOG.debug("Manager died, restarting it listening on {}", freePort);
manager = startProcess(cluster, ServerType.MANAGER, freePort);
}
}
} finally {
if (manager != null) {
manager.destroyForcibly();
}
}
}
}
use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.
the class ThriftServerBindsBeforeZooKeeperLockIT method testGarbageCollectorPorts.
@SuppressFBWarnings(value = "UNENCRYPTED_SOCKET", justification = "unencrypted socket is okay for testing")
@Test
public void testGarbageCollectorPorts() throws Exception {
final MiniAccumuloClusterImpl cluster = (MiniAccumuloClusterImpl) getCluster();
try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
InstanceId instanceID = client.instanceOperations().getInstanceId();
// Wait for the Manager to grab its lock
while (true) {
final ZooReader reader = new ZooReader(cluster.getZooKeepers(), 30000);
try {
List<String> locks = reader.getChildren(Constants.ZROOT + "/" + instanceID + Constants.ZGC_LOCK);
if (!locks.isEmpty()) {
break;
}
} catch (Exception e) {
LOG.debug("Failed to find active gc location, retrying", e);
Thread.sleep(1000);
}
}
LOG.debug("Found active gc");
int freePort = PortUtils.getRandomFreePort();
Process manager = null;
try {
LOG.debug("Starting standby gc on {}", freePort);
manager = startProcess(cluster, ServerType.GARBAGE_COLLECTOR, freePort);
while (true) {
try (Socket s = new Socket("localhost", freePort)) {
if (s.isConnected()) {
// Pass
return;
}
} catch (Exception e) {
LOG.debug("Caught exception trying to connect to GC", e);
}
// Wait before trying again
Thread.sleep(1000);
// died trying to bind it. Pick a new port and restart it in that case.
if (!manager.isAlive()) {
freePort = PortUtils.getRandomFreePort();
LOG.debug("GC died, restarting it listening on {}", freePort);
manager = startProcess(cluster, ServerType.GARBAGE_COLLECTOR, freePort);
}
}
} finally {
if (manager != null) {
manager.destroyForcibly();
}
}
}
}
use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.
the class SystemCredentialsIT method main.
public static void main(final String[] args) throws AccumuloException, TableNotFoundException {
var siteConfig = SiteConfiguration.auto();
try (ServerContext context = new ServerContext(siteConfig)) {
Credentials creds;
InstanceId badInstanceID = InstanceId.of(SystemCredentials.class.getName());
if (args.length < 2) {
throw new RuntimeException("Incorrect usage; expected to be run by test only");
}
switch(args[0]) {
case "bad":
creds = SystemCredentials.get(badInstanceID, siteConfig);
break;
case "good":
creds = SystemCredentials.get(context.getInstanceID(), siteConfig);
break;
case "bad_password":
creds = new SystemCredentials(badInstanceID, "!SYSTEM", new PasswordToken("fake"));
break;
default:
throw new RuntimeException("Incorrect usage; expected to be run by test only");
}
try (AccumuloClient client = Accumulo.newClient().from(context.getProperties()).as(creds.getPrincipal(), creds.getToken()).build()) {
client.securityOperations().authenticateUser(creds.getPrincipal(), creds.getToken());
try (Scanner scan = client.createScanner(RootTable.NAME, Authorizations.EMPTY)) {
for (Entry<Key, Value> e : scan) {
e.hashCode();
}
} catch (RuntimeException e) {
e.printStackTrace(System.err);
System.exit(SCAN_FAILED);
}
} catch (AccumuloSecurityException e) {
e.printStackTrace(System.err);
System.exit(AUTHENICATION_FAILED);
}
}
}
use of org.apache.accumulo.core.data.InstanceId in project accumulo by apache.
the class CompactionDriverTest method testTableBeingDeleted.
@Test
public void testTableBeingDeleted() throws Exception {
final InstanceId instance = InstanceId.of(UUID.randomUUID());
final long compactId = 123;
final long cancelId = 122;
final NamespaceId namespaceId = NamespaceId.of("14");
final TableId tableId = TableId.of("43");
final byte[] startRow = new byte[0];
final byte[] endRow = new byte[0];
Manager manager = EasyMock.createNiceMock(Manager.class);
ServerContext ctx = EasyMock.createNiceMock(ServerContext.class);
ZooReaderWriter zrw = EasyMock.createNiceMock(ZooReaderWriter.class);
EasyMock.expect(manager.getInstanceID()).andReturn(instance).anyTimes();
EasyMock.expect(manager.getContext()).andReturn(ctx);
EasyMock.expect(ctx.getZooReaderWriter()).andReturn(zrw);
final String zCancelID = CompactionDriver.createCompactionCancellationPath(instance, tableId);
EasyMock.expect(zrw.getData(zCancelID)).andReturn(Long.toString(cancelId).getBytes());
String deleteMarkerPath = PreDeleteTable.createDeleteMarkerPath(instance, tableId);
EasyMock.expect(zrw.exists(deleteMarkerPath)).andReturn(true);
EasyMock.replay(manager, ctx, zrw);
final CompactionDriver driver = new CompactionDriver(compactId, namespaceId, tableId, startRow, endRow);
final long tableIdLong = Long.parseLong(tableId.toString());
var e = assertThrows(AcceptableThriftTableOperationException.class, () -> driver.isReady(tableIdLong, manager));
assertTrue(e.getTableId().equals(tableId.toString()));
assertTrue(e.getOp().equals(TableOperation.COMPACT));
assertTrue(e.getType().equals(TableOperationExceptionType.OTHER));
assertTrue(e.getDescription().equals(TableOperationsImpl.TABLE_DELETED_MSG));
EasyMock.verify(manager, ctx, zrw);
}
Aggregations