Search in sources :

Example 21 with ServerContext

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);
}
Also used : ServerContext(org.apache.accumulo.server.ServerContext) UnknownHostException(java.net.UnknownHostException) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) KeeperException(org.apache.zookeeper.KeeperException) UnknownHostException(java.net.UnknownHostException) URL(java.net.URL)

Example 22 with ServerContext

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));
}
Also used : ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) ServerContext(org.apache.accumulo.server.ServerContext) Manager(org.apache.accumulo.manager.Manager) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Test(org.junit.Test)

Example 23 with ServerContext

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));
}
Also used : ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) ServerContext(org.apache.accumulo.server.ServerContext) Manager(org.apache.accumulo.manager.Manager) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) Test(org.junit.Test)

Example 24 with ServerContext

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);
}
Also used : Path(org.apache.hadoop.fs.Path) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) ServerContext(org.apache.accumulo.server.ServerContext) UniqueNameAllocator(org.apache.accumulo.server.tablets.UniqueNameAllocator) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) Manager(org.apache.accumulo.manager.Manager) Test(org.junit.Test)

Example 25 with ServerContext

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);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ServerContext(org.apache.accumulo.server.ServerContext) InstanceId(org.apache.accumulo.core.data.InstanceId) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) NamespaceId(org.apache.accumulo.core.data.NamespaceId) Manager(org.apache.accumulo.manager.Manager) Test(org.junit.Test)

Aggregations

ServerContext (org.apache.accumulo.server.ServerContext)87 Test (org.junit.Test)41 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)18 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)15 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)15 TServerInstance (org.apache.accumulo.core.metadata.TServerInstance)15 HostAndPort (org.apache.accumulo.core.util.HostAndPort)15 Path (org.apache.hadoop.fs.Path)15 ArrayList (java.util.ArrayList)14 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)14 VolumeManager (org.apache.accumulo.server.fs.VolumeManager)13 KeeperException (org.apache.zookeeper.KeeperException)13 ServerAddress (org.apache.accumulo.server.rpc.ServerAddress)12 TableId (org.apache.accumulo.core.data.TableId)11 LiveTServerSet (org.apache.accumulo.server.manager.LiveTServerSet)11 Value (org.apache.accumulo.core.data.Value)10 IOException (java.io.IOException)9 UUID (java.util.UUID)9 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)9 Client (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client)9