Search in sources :

Example 11 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class AerospikeClient method grantRoles.

/**
 * Add roles to user's list of roles.
 *
 * @param policy				admin configuration parameters, pass in null for defaults
 * @param user					user name
 * @param roles					role names.  Predefined roles are listed in {@link com.aerospike.client.admin.Role}
 * @throws AerospikeException	if command fails
 */
public final void grantRoles(AdminPolicy policy, String user, List<String> roles) throws AerospikeException {
    AdminCommand command = new AdminCommand();
    command.grantRoles(cluster, policy, user, roles);
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

Example 12 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class NettyCommand method writeAuth.

private void writeAuth(byte[] token) {
    state = AsyncCommand.AUTH_WRITE;
    command.initBuffer();
    AdminCommand admin = new AdminCommand(command.dataBuffer);
    command.dataOffset = admin.setAuthenticate(cluster, token);
    writeByteBuffer();
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

Example 13 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class NioCommand method writeAuth.

private final void writeAuth() throws IOException {
    command.initBuffer();
    AdminCommand admin = new AdminCommand(command.dataBuffer);
    command.dataOffset = admin.setAuthenticate(cluster, command.node);
    byteBuffer.clear();
    byteBuffer.put(command.dataBuffer, 0, command.dataOffset);
    byteBuffer.flip();
    command.putBuffer();
    if (conn.write(byteBuffer)) {
        byteBuffer.clear();
        byteBuffer.limit(8);
        state = AsyncCommand.AUTH_READ_HEADER;
        // Socket timeout applies only to read events.
        // Reset event received because we are switching from a write to a read state.
        // This handles case where write succeeds and read event does not occur.  If we didn't reset,
        // the socket timeout would go through two iterations (double the timeout) because a write
        // event occurred in the first timeout period.
        eventReceived = false;
        conn.registerRead();
    } else {
        state = AsyncCommand.AUTH_WRITE;
        conn.registerWrite();
    }
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

Example 14 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class Node method refresh.

/**
 * Request current status from server node.
 */
public final void refresh(Peers peers) {
    if (!active) {
        return;
    }
    try {
        if (tendConnection.isClosed()) {
            tendConnection = new Connection(cluster.tlsPolicy, host.tlsName, address, cluster.getConnectionTimeout(), cluster.maxSocketIdleNanos, null);
            if (cluster.user != null) {
                try {
                    AdminCommand command = new AdminCommand(ThreadLocalData.getBuffer());
                    command.authenticate(cluster, this, tendConnection);
                } catch (AerospikeException ae) {
                    tendConnection.close();
                    throw ae;
                } catch (Exception e) {
                    tendConnection.close();
                    throw new AerospikeException(e);
                }
            }
        }
        if (peers.usePeers) {
            HashMap<String, String> infoMap = Info.request(tendConnection, "node", "peers-generation", "partition-generation");
            verifyNodeName(infoMap);
            verifyPeersGeneration(infoMap, peers);
            verifyPartitionGeneration(infoMap);
        } else {
            String[] commands = cluster.useServicesAlternate ? new String[] { "node", "partition-generation", "services-alternate" } : new String[] { "node", "partition-generation", "services" };
            HashMap<String, String> infoMap = Info.request(tendConnection, commands);
            verifyNodeName(infoMap);
            verifyPartitionGeneration(infoMap);
            addFriends(infoMap, peers);
        }
        peers.refreshCount++;
        failures = 0;
    } catch (Exception e) {
        if (peers.usePeers) {
            peers.genChanged = true;
        }
        refreshFailed(e);
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) AsyncConnection(com.aerospike.client.async.AsyncConnection) AdminCommand(com.aerospike.client.admin.AdminCommand) AerospikeException(com.aerospike.client.AerospikeException)

Example 15 with AdminCommand

use of com.aerospike.client.admin.AdminCommand in project aerospike-client-java by aerospike.

the class NettyRecover method writeAuth.

private void writeAuth(byte[] token) {
    state = AsyncCommand.AUTH_WRITE;
    dataBuffer = new byte[512];
    AdminCommand admin = new AdminCommand(dataBuffer);
    int len = admin.setAuthenticate(cluster, token);
    ByteBuf byteBuffer = PooledByteBufAllocator.DEFAULT.directBuffer(len);
    byteBuffer.clear();
    byteBuffer.writeBytes(dataBuffer, 0, len);
    ChannelFuture cf = conn.channel.writeAndFlush(byteBuffer);
    cf.addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) {
            if (state == AsyncCommand.AUTH_WRITE) {
                state = AsyncCommand.AUTH_READ_HEADER;
                conn.channel.config().setAutoRead(true);
            }
        }
    });
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) AdminCommand(com.aerospike.client.admin.AdminCommand) ByteBuf(io.netty.buffer.ByteBuf) ChannelFutureListener(io.netty.channel.ChannelFutureListener)

Aggregations

AdminCommand (com.aerospike.client.admin.AdminCommand)22 AerospikeException (com.aerospike.client.AerospikeException)2 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 AsyncConnection (com.aerospike.client.async.AsyncConnection)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1