Search in sources :

Example 6 with ServerAddress

use of org.apache.accumulo.server.rpc.ServerAddress in project accumulo by apache.

the class TServerUtilsTest method testStartServerPortRangeFirstPortUsed.

@Test
public void testStartServerPortRangeFirstPortUsed() throws Exception {
    TServer server = null;
    InetAddress addr = InetAddress.getByName("localhost");
    int[] port = findTwoFreeSequentialPorts(1024);
    String portRange = Integer.toString(port[0]) + "-" + Integer.toString(port[1]);
    // Bind to the port
    ((ConfigurationCopy) factory.getSystemConfiguration()).set(Property.TSERV_CLIENTPORT, portRange);
    try (ServerSocket s = new ServerSocket(port[0], 50, addr)) {
        ServerAddress address = startServer();
        assertNotNull(address);
        server = address.getServer();
        assertNotNull(server);
        assertTrue(port[1] == address.getAddress().getPort());
    } finally {
        if (null != server) {
            TServerUtils.stopTServer(server);
        }
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) TServer(org.apache.thrift.server.TServer) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) ServerSocket(java.net.ServerSocket) TServerSocket(org.apache.thrift.transport.TServerSocket) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 7 with ServerAddress

use of org.apache.accumulo.server.rpc.ServerAddress in project accumulo by apache.

the class ZombieTServer method main.

public static void main(String[] args) throws Exception {
    Random random = new Random(System.currentTimeMillis() % 1000);
    int port = random.nextInt(30000) + 2000;
    Instance instance = HdfsZooInstance.getInstance();
    AccumuloServerContext context = new AccumuloServerContext(instance, new ServerConfigurationFactory(instance));
    TransactionWatcher watcher = new TransactionWatcher();
    final ThriftClientHandler tch = new ThriftClientHandler(context, watcher);
    Processor<Iface> processor = new Processor<>(tch);
    ServerAddress serverPort = TServerUtils.startTServer(context.getConfiguration(), ThriftServerType.CUSTOM_HS_HA, processor, "ZombieTServer", "walking dead", 2, 1, 1000, 10 * 1024 * 1024, null, null, -1, HostAndPort.fromParts("0.0.0.0", port));
    String addressString = serverPort.address.toString();
    String zPath = ZooUtil.getRoot(context.getInstance()) + Constants.ZTSERVERS + "/" + addressString;
    ZooReaderWriter zoo = ZooReaderWriter.getInstance();
    zoo.putPersistentData(zPath, new byte[] {}, NodeExistsPolicy.SKIP);
    ZooLock zlock = new ZooLock(zPath);
    LockWatcher lw = new LockWatcher() {

        @Override
        public void lostLock(final LockLossReason reason) {
            try {
                tch.halt(Tracer.traceInfo(), null, null);
            } catch (Exception ex) {
                log.error("Exception", ex);
                System.exit(1);
            }
        }

        @Override
        public void unableToMonitorLockNode(Throwable e) {
            try {
                tch.halt(Tracer.traceInfo(), null, null);
            } catch (Exception ex) {
                log.error("Exception", ex);
                System.exit(1);
            }
        }
    };
    byte[] lockContent = new ServerServices(addressString, Service.TSERV_CLIENT).toString().getBytes(UTF_8);
    if (zlock.tryLock(lw, lockContent)) {
        log.debug("Obtained tablet server lock {}", zlock.getLockPath());
    }
    // modify metadata
    synchronized (tch) {
        while (!tch.halted) {
            tch.wait();
        }
    }
    System.exit(0);
}
Also used : AccumuloServerContext(org.apache.accumulo.server.AccumuloServerContext) Processor(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Processor) ServerServices(org.apache.accumulo.core.util.ServerServices) Instance(org.apache.accumulo.core.client.Instance) HdfsZooInstance(org.apache.accumulo.server.client.HdfsZooInstance) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) ZooReaderWriter(org.apache.accumulo.server.zookeeper.ZooReaderWriter) ServerConfigurationFactory(org.apache.accumulo.server.conf.ServerConfigurationFactory) TException(org.apache.thrift.TException) ThriftSecurityException(org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException) Iface(org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface) TransactionWatcher(org.apache.accumulo.server.zookeeper.TransactionWatcher) Random(java.util.Random) LockWatcher(org.apache.accumulo.fate.zookeeper.ZooLock.LockWatcher) LockLossReason(org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason) ZooLock(org.apache.accumulo.server.zookeeper.ZooLock)

Example 8 with ServerAddress

use of org.apache.accumulo.server.rpc.ServerAddress in project accumulo by apache.

the class TServerUtilsTest method testStartServerZeroPort.

@Test
public void testStartServerZeroPort() throws Exception {
    TServer server = null;
    ((ConfigurationCopy) factory.getSystemConfiguration()).set(Property.TSERV_CLIENTPORT, "0");
    try {
        ServerAddress address = startServer();
        assertNotNull(address);
        server = address.getServer();
        assertNotNull(server);
        assertTrue(address.getAddress().getPort() > 1024);
    } finally {
        if (null != server) {
            TServerUtils.stopTServer(server);
        }
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) TServer(org.apache.thrift.server.TServer) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) Test(org.junit.Test)

Example 9 with ServerAddress

use of org.apache.accumulo.server.rpc.ServerAddress in project accumulo by apache.

the class TServerUtilsTest method testStartServerFreePort.

@Test
public void testStartServerFreePort() throws Exception {
    TServer server = null;
    int port = getFreePort(1024);
    ((ConfigurationCopy) factory.getSystemConfiguration()).set(Property.TSERV_CLIENTPORT, Integer.toString(port));
    try {
        ServerAddress address = startServer();
        assertNotNull(address);
        server = address.getServer();
        assertNotNull(server);
        assertEquals(port, address.getAddress().getPort());
    } finally {
        if (null != server) {
            TServerUtils.stopTServer(server);
        }
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) TServer(org.apache.thrift.server.TServer) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) Test(org.junit.Test)

Example 10 with ServerAddress

use of org.apache.accumulo.server.rpc.ServerAddress in project accumulo by apache.

the class TServerUtilsTest method testStartServerPortRange.

@Test
public void testStartServerPortRange() throws Exception {
    TServer server = null;
    int[] port = findTwoFreeSequentialPorts(1024);
    String portRange = Integer.toString(port[0]) + "-" + Integer.toString(port[1]);
    ((ConfigurationCopy) factory.getSystemConfiguration()).set(Property.TSERV_CLIENTPORT, portRange);
    try {
        ServerAddress address = startServer();
        assertNotNull(address);
        server = address.getServer();
        assertNotNull(server);
        assertTrue(port[0] == address.getAddress().getPort() || port[1] == address.getAddress().getPort());
    } finally {
        if (null != server) {
            TServerUtils.stopTServer(server);
        }
    }
}
Also used : ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) TServer(org.apache.thrift.server.TServer) ServerAddress(org.apache.accumulo.server.rpc.ServerAddress) Test(org.junit.Test)

Aggregations

ServerAddress (org.apache.accumulo.server.rpc.ServerAddress)12 ConfigurationCopy (org.apache.accumulo.core.conf.ConfigurationCopy)5 TServer (org.apache.thrift.server.TServer)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 AccumuloException (org.apache.accumulo.core.client.AccumuloException)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)3 TException (org.apache.thrift.TException)3 KeeperException (org.apache.zookeeper.KeeperException)3 InetAddress (java.net.InetAddress)2 ServerSocket (java.net.ServerSocket)2 UnknownHostException (java.net.UnknownHostException)2 ThriftSecurityException (org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException)2 ThriftTableOperationException (org.apache.accumulo.core.client.impl.thrift.ThriftTableOperationException)2 Property (org.apache.accumulo.core.conf.Property)2 Iface (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface)2 Processor (org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Processor)2 HostAndPort (org.apache.accumulo.core.util.HostAndPort)2 AccumuloProxy (org.apache.accumulo.proxy.thrift.AccumuloProxy)2