use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class Monitor method run.
@Override
public void run() {
ServerContext context = getContext();
int[] ports = getConfiguration().getPort(Property.MONITOR_PORT);
for (int port : ports) {
try {
log.debug("Creating monitor on port {}", port);
server = new EmbeddedWebServer(this, port);
server.addServlet(getDefaultServlet(), "/resources/*");
server.addServlet(getRestServlet(), "/rest/*");
server.addServlet(getViewServlet(), "/*");
server.start();
break;
} catch (Exception ex) {
log.error("Unable to start embedded web server", ex);
}
}
if (!server.isRunning()) {
throw new RuntimeException("Unable to start embedded web server on ports: " + Arrays.toString(ports));
}
try {
getMonitorLock();
} catch (Exception e) {
log.error("Failed to get Monitor ZooKeeper lock");
throw new RuntimeException(e);
}
String advertiseHost = getHostname();
if (advertiseHost.equals("0.0.0.0")) {
try {
advertiseHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
log.error("Unable to get hostname", e);
}
}
log.debug("Using {} to advertise monitor location in ZooKeeper", advertiseHost);
try {
URL url = new URL(server.isSecure() ? "https" : "http", advertiseHost, server.getPort(), "/");
final String path = context.getZooKeeperRoot() + Constants.ZMONITOR_HTTP_ADDR;
final ZooReaderWriter zoo = context.getZooReaderWriter();
// Delete before we try to re-create in case the previous session hasn't yet expired
zoo.delete(path);
zoo.putEphemeralData(path, url.toString().getBytes(UTF_8));
log.info("Set monitor address in zookeeper to {}", url);
} catch (Exception ex) {
log.error("Unable to advertise monitor HTTP address in zookeeper", ex);
}
// need to regularly fetch data so plot data is updated
Threads.createThread("Data fetcher", () -> {
while (true) {
try {
fetchData();
} catch (Exception e) {
log.warn("{}", e.getMessage(), e);
}
sleepUninterruptibly(333, TimeUnit.MILLISECONDS);
}
}).start();
monitorInitialized.set(true);
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class ManagerReplicationCoordinatorTest method randomServer.
@Test
public void randomServer() {
Manager manager = EasyMock.createMock(Manager.class);
ZooReader reader = EasyMock.createMock(ZooReader.class);
ServerContext context = EasyMock.createMock(ServerContext.class);
EasyMock.expect(context.getConfiguration()).andReturn(config).anyTimes();
EasyMock.expect(context.getInstanceID()).andReturn(InstanceId.of("1234")).anyTimes();
EasyMock.expect(context.getZooReaderWriter()).andReturn(null).anyTimes();
EasyMock.expect(manager.getContext()).andReturn(context);
EasyMock.expect(manager.getInstanceID()).andReturn(InstanceId.of("1234"));
EasyMock.replay(manager, context, reader);
ManagerReplicationCoordinator coordinator = new ManagerReplicationCoordinator(manager, reader);
TServerInstance inst1 = new TServerInstance(HostAndPort.fromParts("host1", 1234), "session");
assertEquals(inst1, coordinator.getRandomTServer(Collections.singleton(inst1), 0));
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class ManagerReplicationCoordinatorTest method invalidOffset.
@Test
public void invalidOffset() {
Manager manager = EasyMock.createMock(Manager.class);
ServerContext context = EasyMock.createMock(ServerContext.class);
EasyMock.expect(context.getConfiguration()).andReturn(config).anyTimes();
EasyMock.expect(context.getInstanceID()).andReturn(InstanceId.of("1234")).anyTimes();
EasyMock.expect(context.getZooReaderWriter()).andReturn(null).anyTimes();
ZooReader reader = EasyMock.createMock(ZooReader.class);
EasyMock.expect(manager.getContext()).andReturn(context);
EasyMock.expect(manager.getInstanceID()).andReturn(InstanceId.of("1234"));
EasyMock.replay(manager, context, reader);
ManagerReplicationCoordinator coordinator = new ManagerReplicationCoordinator(manager, reader);
TServerInstance inst1 = new TServerInstance(HostAndPort.fromParts("host1", 1234), "session");
assertThrows(IllegalArgumentException.class, () -> coordinator.getRandomTServer(Collections.singleton(inst1), 1));
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class ImportTableTest method testCreateImportDir.
@Test
public void testCreateImportDir() throws Exception {
Manager manager = EasyMock.createMock(Manager.class);
ServerContext context = EasyMock.createMock(ServerContext.class);
VolumeManager volumeManager = EasyMock.createMock(VolumeManager.class);
UniqueNameAllocator uniqueNameAllocator = EasyMock.createMock(UniqueNameAllocator.class);
String[] expDirs = { "hdfs://nn1:8020/import-dir-nn1", "hdfs://nn2:8020/import-dir-nn2", "hdfs://nn3:8020/import-dir-nn3" };
String[] tableDirs = { "hdfs://nn1:8020/apps/accumulo1/tables", "hdfs://nn2:8020/applications/accumulo/tables", "hdfs://nn3:8020/applications/accumulo/tables" };
Set<String> tableDirSet = Set.of(tableDirs);
String dirName = "abcd";
EasyMock.expect(manager.getContext()).andReturn(context);
EasyMock.expect(manager.getVolumeManager()).andReturn(volumeManager).times(3);
EasyMock.expect(context.getUniqueNameAllocator()).andReturn(uniqueNameAllocator);
EasyMock.expect(volumeManager.matchingFileSystem(EasyMock.eq(new Path(expDirs[0])), EasyMock.eq(tableDirSet))).andReturn(new Path(tableDirs[0]));
EasyMock.expect(volumeManager.matchingFileSystem(EasyMock.eq(new Path(expDirs[1])), EasyMock.eq(tableDirSet))).andReturn(new Path(tableDirs[1]));
EasyMock.expect(volumeManager.matchingFileSystem(EasyMock.eq(new Path(expDirs[2])), EasyMock.eq(tableDirSet))).andReturn(new Path(tableDirs[2]));
EasyMock.expect(uniqueNameAllocator.getNextName()).andReturn(dirName).times(3);
ImportedTableInfo ti = new ImportedTableInfo();
ti.tableId = TableId.of("5b");
ti.directories = ImportTable.parseExportDir(Set.of(expDirs));
assertEquals(3, ti.directories.size());
EasyMock.replay(manager, context, volumeManager, uniqueNameAllocator);
CreateImportDir ci = new CreateImportDir(ti);
ci.create(tableDirSet, manager);
assertEquals(3, ti.directories.size());
for (ImportedTableInfo.DirectoryMapping dm : ti.directories) {
assertNotNull(dm.exportDir);
assertNotNull(dm.importDir);
assertTrue(dm.importDir.contains(Constants.HDFS_TABLES_DIR));
assertMatchingFilesystem(dm.exportDir, dm.importDir);
assertTrue(dm.importDir.contains(ti.tableId.canonical() + "/" + Constants.BULK_PREFIX + dirName));
}
EasyMock.verify(manager, context, volumeManager, uniqueNameAllocator);
}
use of org.apache.accumulo.server.ServerContext in project accumulo by apache.
the class CompactionDriverTest method testCancelId.
@Test
public void testCancelId() throws Exception {
final InstanceId instance = InstanceId.of(UUID.randomUUID());
final long compactId = 123;
final long cancelId = 124;
final NamespaceId namespaceId = NamespaceId.of("13");
final TableId tableId = TableId.of("42");
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());
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.COMPACTION_CANCELED_MSG));
EasyMock.verify(manager, ctx, zrw);
}
Aggregations