Search in sources :

Example 1 with AdminCommand

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

the class NodeValidator method validateAlias.

private void validateAlias(Cluster cluster, Host alias) throws Exception {
    InetSocketAddress address = new InetSocketAddress(alias.name, alias.port);
    Connection conn = new Connection(cluster.tlsPolicy, alias.tlsName, address, cluster.getConnectionTimeout(), cluster.maxSocketIdleNanos, null);
    try {
        if (cluster.user != null) {
            AdminCommand command = new AdminCommand(ThreadLocalData.getBuffer());
            sessionToken = command.login(cluster, conn, alias);
        }
        HashMap<String, String> map;
        boolean hasClusterName = cluster.clusterName != null && cluster.clusterName.length() > 0;
        if (hasClusterName) {
            map = Info.request(conn, "node", "partition-generation", "features", "cluster-name");
        } else {
            map = Info.request(conn, "node", "partition-generation", "features");
        }
        String nodeName = map.get("node");
        if (nodeName == null) {
            throw new AerospikeException.InvalidNode();
        }
        String genString = map.get("partition-generation");
        int gen;
        try {
            gen = Integer.parseInt(genString);
        } catch (Exception ex) {
            throw new AerospikeException.InvalidNode("Invalid partition-generation: " + genString);
        }
        if (gen == -1) {
            throw new AerospikeException.InvalidNode("Node " + nodeName + ' ' + alias + " is not yet fully initialized");
        }
        if (hasClusterName) {
            String id = map.get("cluster-name");
            if (id == null || !cluster.clusterName.equals(id)) {
                throw new AerospikeException.InvalidNode("Node " + nodeName + ' ' + alias + ' ' + " expected cluster name '" + cluster.clusterName + "' received '" + id + "'");
            }
        }
        this.name = nodeName;
        this.primaryHost = alias;
        this.primaryAddress = address;
        this.conn = conn;
        setFeatures(map);
    } catch (Exception e) {
        conn.close();
        throw e;
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) InetSocketAddress(java.net.InetSocketAddress) AdminCommand(com.aerospike.client.admin.AdminCommand) UnknownHostException(java.net.UnknownHostException) AerospikeException(com.aerospike.client.AerospikeException)

Example 2 with AdminCommand

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

the class NettyCommand method writeAuth.

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

Example 3 with AdminCommand

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

the class AerospikeClient method dropRole.

/**
 * Drop user defined role.
 *
 * @param policy				admin configuration parameters, pass in null for defaults
 * @param roleName				role name
 * @throws AerospikeException	if command fails
 */
public final void dropRole(AdminPolicy policy, String roleName) throws AerospikeException {
    AdminCommand command = new AdminCommand();
    command.dropRole(cluster, policy, roleName);
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

Example 4 with AdminCommand

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

the class AerospikeClient method createRole.

/**
 * Create user defined role.
 *
 * @param policy				admin configuration parameters, pass in null for defaults
 * @param roleName				role name
 * @param privileges			privileges assigned to the role.
 * @throws AerospikeException	if command fails
 */
public final void createRole(AdminPolicy policy, String roleName, List<Privilege> privileges) throws AerospikeException {
    AdminCommand command = new AdminCommand();
    command.createRole(cluster, policy, roleName, privileges);
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

Example 5 with AdminCommand

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

the class AerospikeClient method createRole.

/**
 * Create user defined role with optional privileges and whitelist.
 *
 * @param policy				admin configuration parameters, pass in null for defaults
 * @param roleName				role name
 * @param privileges			optional list of privileges assigned to role.
 * @param whitelist				optional list of allowable IP addresses assigned to role.
 * 								IP addresses can contain wildcards (ie. 10.1.2.0/24).
 * @throws AerospikeException	if command fails
 */
public final void createRole(AdminPolicy policy, String roleName, List<Privilege> privileges, List<String> whitelist) throws AerospikeException {
    AdminCommand command = new AdminCommand();
    command.createRole(cluster, policy, roleName, privileges, whitelist, 0, 0);
}
Also used : AdminCommand(com.aerospike.client.admin.AdminCommand)

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