Search in sources :

Example 1 with Info

use of com.aerospike.client.Info 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;
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Node(com.aerospike.client.cluster.Node) Connection(com.aerospike.client.cluster.Connection) RegisterTask(com.aerospike.client.task.RegisterTask) Info(com.aerospike.client.Info) NameValueParser(com.aerospike.client.Info.NameValueParser)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)1 Info (com.aerospike.client.Info)1 NameValueParser (com.aerospike.client.Info.NameValueParser)1 Connection (com.aerospike.client.cluster.Connection)1 Node (com.aerospike.client.cluster.Node)1 RegisterTask (com.aerospike.client.task.RegisterTask)1