Search in sources :

Example 36 with AerospikeException

use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.

the class RWTask method doWrite.

/**
 * Write the key at the given index
 */
protected void doWrite(RandomShift random, long keyIdx, boolean multiBin, WritePolicy writePolicy) {
    Key key = new Key(args.namespace, args.setName, keyStart + keyIdx);
    // Use predictable value for 0th bin same as key value
    Bin[] bins = args.getBins(random, multiBin, keyStart + keyIdx);
    try {
        put(writePolicy, key, bins);
    } catch (AerospikeException ae) {
        writeFailure(ae);
        runNextCommand();
    } catch (Exception e) {
        writeFailure(e);
        runNextCommand();
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) AerospikeException(com.aerospike.client.AerospikeException)

Example 37 with AerospikeException

use of com.aerospike.client.AerospikeException in project apex-malhar by apache.

the class AerospikeStore method connect.

/**
 * Create connection with database.
 */
@Override
public void connect() {
    try {
        client = new AerospikeClient(node, port);
        logger.debug("Aerospike connection Success");
    } catch (AerospikeException ex) {
        throw new RuntimeException("closing database resource", ex);
    } catch (Throwable t) {
        DTThrowable.rethrow(t);
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) AerospikeException(com.aerospike.client.AerospikeException) DTThrowable(com.datatorrent.netlet.util.DTThrowable)

Example 38 with AerospikeException

use of com.aerospike.client.AerospikeException in project apex-malhar by apache.

the class AerospikeTestUtils method checkEvents.

static boolean checkEvents() {
    long count = 0;
    AerospikeClient client = null;
    try {
        client = new AerospikeClient(NODE, PORT);
        Statement stmnt = new Statement();
        stmnt.setNamespace(NAMESPACE);
        stmnt.setSetName(SET_NAME);
        RecordSet rs = client.query(null, stmnt);
        while (rs.next()) {
            Record record = rs.getRecord();
            Key key = rs.getKey();
            if (!TestPOJO.check(key, record)) {
                return false;
            }
            count++;
        }
    } catch (AerospikeException e) {
        throw new RuntimeException("Error fetching records: ", e);
    } finally {
        if (null != client) {
            client.close();
        }
    }
    return NUM_TUPLES == count;
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) AerospikeException(com.aerospike.client.AerospikeException) Statement(com.aerospike.client.query.Statement) Record(com.aerospike.client.Record) RecordSet(com.aerospike.client.query.RecordSet) Key(com.aerospike.client.Key)

Example 39 with AerospikeException

use of com.aerospike.client.AerospikeException in project apex-malhar by apache.

the class AerospikeTransactionalStore method getCommittedWindowId.

@Override
public long getCommittedWindowId(String appId, int operatorId) {
    try {
        lastWindowFetchCommand.setFilters(Filter.equal(metaTableOperatorIdColumn, operatorId));
        lastWindowFetchCommand.setFilters(Filter.equal(metaTableAppIdColumn, appId));
        long lastWindow = -1;
        RecordSet recordSet = client.query(null, lastWindowFetchCommand);
        while (recordSet.next()) {
            lastWindow = Long.parseLong(recordSet.getRecord().getValue(metaTableWindowColumn).toString());
        }
        return lastWindow;
    } catch (AerospikeException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) RecordSet(com.aerospike.client.query.RecordSet)

Example 40 with AerospikeException

use of com.aerospike.client.AerospikeException in project apex-malhar by apache.

the class AerospikeTransactionalStore method removeCommittedWindowId.

@Override
public void removeCommittedWindowId(String appId, int operatorId) {
    try {
        String keyString = appId + String.valueOf(operatorId);
        Key key = new Key(namespace, metaSet, keyString.hashCode());
        client.delete(null, key);
    } catch (AerospikeException e) {
        throw new RuntimeException(e);
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Key(com.aerospike.client.Key)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)107 Key (com.aerospike.client.Key)46 Bin (com.aerospike.client.Bin)24 Policy (com.aerospike.client.policy.Policy)24 IndexTask (com.aerospike.client.task.IndexTask)24 Record (com.aerospike.client.Record)19 Test (org.junit.Test)16 Node (com.aerospike.client.cluster.Node)12 IOException (java.io.IOException)10 BeforeClass (org.junit.BeforeClass)10 WritePolicy (com.aerospike.client.policy.WritePolicy)7 HashMap (java.util.HashMap)7 Statement (com.aerospike.client.query.Statement)6 RegisterTask (com.aerospike.client.task.RegisterTask)6 ArrayList (java.util.ArrayList)6 AerospikeClient (com.aerospike.client.AerospikeClient)5 Value (com.aerospike.client.Value)5 RecordSequenceListener (com.aerospike.client.listener.RecordSequenceListener)5 RecordSet (com.aerospike.client.query.RecordSet)5 HashedWheelTimeout (com.aerospike.client.async.HashedWheelTimer.HashedWheelTimeout)4