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;
}
}
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();
}
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);
}
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);
}
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);
}
Aggregations