use of com.aerospike.client.Info.NameValueParser in project aerospike-client-java by aerospike.
the class RegisterCommand method register.
public static RegisterTask register(Cluster cluster, Policy policy, byte[] bytes, String serverPath, Language language) {
String content = Base64.encode(bytes, 0, bytes.length, false);
StringBuilder sb = new StringBuilder(serverPath.length() + content.length() + 100);
sb.append("udf-put:filename=");
sb.append(serverPath);
sb.append(";content=");
sb.append(content);
sb.append(";content-len=");
sb.append(content.length());
sb.append(";udf-type=");
sb.append(language);
sb.append(";");
// Send UDF to one node. That node will distribute the UDF to other nodes.
String command = sb.toString();
Node node = cluster.getRandomNode();
Connection conn = node.getConnection(policy.socketTimeout);
try {
Info info = new Info(conn, command);
NameValueParser parser = info.getNameValueParser();
String error = null;
String file = null;
String line = null;
String message = null;
while (parser.next()) {
String name = parser.getName();
if (name.equals("error")) {
error = parser.getValue();
} else if (name.equals("file")) {
file = parser.getValue();
} else if (name.equals("line")) {
line = parser.getValue();
} else if (name.equals("message")) {
message = parser.getStringBase64();
}
}
if (error != null) {
throw new AerospikeException("Registration failed: " + error + Environment.Newline + "File: " + file + Environment.Newline + "Line: " + line + Environment.Newline + "Message: " + message);
}
node.putConnection(conn);
return new RegisterTask(cluster, policy, serverPath);
} catch (RuntimeException re) {
node.closeConnection(conn);
throw re;
}
}
Aggregations