Search in sources :

Example 1 with ClientPolicy

use of com.aerospike.client.policy.ClientPolicy in project YCSB by brianfrankcooper.

the class AerospikeClient method init.

@Override
public void init() throws DBException {
    insertPolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY;
    updatePolicy.recordExistsAction = RecordExistsAction.REPLACE_ONLY;
    Properties props = getProperties();
    namespace = props.getProperty("as.namespace", DEFAULT_NAMESPACE);
    String host = props.getProperty("as.host", DEFAULT_HOST);
    String user = props.getProperty("as.user");
    String password = props.getProperty("as.password");
    int port = Integer.parseInt(props.getProperty("as.port", DEFAULT_PORT));
    int timeout = Integer.parseInt(props.getProperty("as.timeout", DEFAULT_TIMEOUT));
    readPolicy.timeout = timeout;
    insertPolicy.timeout = timeout;
    updatePolicy.timeout = timeout;
    deletePolicy.timeout = timeout;
    ClientPolicy clientPolicy = new ClientPolicy();
    if (user != null && password != null) {
        clientPolicy.user = user;
        clientPolicy.password = password;
    }
    try {
        client = new com.aerospike.client.AerospikeClient(clientPolicy, host, port);
    } catch (AerospikeException e) {
        throw new DBException(String.format("Error while creating Aerospike " + "client for %s:%d.", host, port), e);
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) DBException(com.yahoo.ycsb.DBException) ClientPolicy(com.aerospike.client.policy.ClientPolicy) Properties(java.util.Properties)

Example 2 with ClientPolicy

use of com.aerospike.client.policy.ClientPolicy in project gora by apache.

the class AerospikeStore method initialize.

/**
 * {@inheritDoc}
 * In initializing the aerospike datastore, read the mapping file, sets the basic
 * aerospike specific parameters and creates the client with the user defined policies
 *
 * @param keyClass        key class
 * @param persistentClass persistent class
 * @param properties      properties
 */
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
    super.initialize(keyClass, persistentClass, properties);
    try {
        AerospikeMappingBuilder aerospikeMappingBuilder = new AerospikeMappingBuilder();
        aerospikeMappingBuilder.readMappingFile(getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE), keyClass, persistentClass);
        aerospikeParameters = new AerospikeParameters(aerospikeMappingBuilder.getAerospikeMapping(), properties, getConf());
        ClientPolicy policy = new ClientPolicy();
        policy.writePolicyDefault = aerospikeParameters.getAerospikeMapping().getWritePolicy();
        policy.readPolicyDefault = aerospikeParameters.getAerospikeMapping().getReadPolicy();
        // 'SendKey' property is enabled by default as the key is needed in query execution
        policy.readPolicyDefault.sendKey = true;
        policy.writePolicyDefault.sendKey = true;
        // Set the credentials for servers with restricted access
        if (aerospikeParameters.getUsername() != null) {
            policy.user = aerospikeParameters.getUsername();
        }
        if (aerospikeParameters.getPassword() != null) {
            policy.password = aerospikeParameters.getPassword();
        }
        aerospikeClient = new AerospikeClient(policy, aerospikeParameters.getHost(), aerospikeParameters.getPort());
        aerospikeParameters.setServerSpecificParameters(aerospikeClient);
        aerospikeParameters.validateServerBinConfiguration(persistentClass.getFields());
        LOG.info("Aerospike Gora datastore initialized successfully.");
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) ClientPolicy(com.aerospike.client.policy.ClientPolicy) GoraException(org.apache.gora.util.GoraException) AerospikeException(com.aerospike.client.AerospikeException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 3 with ClientPolicy

use of com.aerospike.client.policy.ClientPolicy in project aerospike-client-java by aerospike.

the class AsyncExample method runExamples.

/**
 * Connect and run one or more asynchronous client examples.
 */
public static void runExamples(Console console, Parameters params, List<String> examples) throws Exception {
    EventPolicy eventPolicy = new EventPolicy();
    eventPolicy.maxCommandsInProcess = params.maxCommandsInProcess;
    eventPolicy.maxCommandsInQueue = params.maxCommandsInQueue;
    EventLoops eventLoops;
    switch(params.eventLoopType) {
        default:
        case DIRECT_NIO:
            {
                eventLoops = new NioEventLoops(eventPolicy, 1);
                break;
            }
        case NETTY_NIO:
            {
                EventLoopGroup group = new NioEventLoopGroup(1);
                eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
                break;
            }
        case NETTY_EPOLL:
            {
                EventLoopGroup group = new EpollEventLoopGroup(1);
                eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
                break;
            }
        case NETTY_KQUEUE:
            {
                EventLoopGroup group = new KQueueEventLoopGroup(1);
                eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
                break;
            }
        case NETTY_IOURING:
            {
                EventLoopGroup group = new IOUringEventLoopGroup(1);
                eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
                break;
            }
    }
    try {
        ClientPolicy policy = new ClientPolicy();
        policy.eventLoops = eventLoops;
        policy.user = params.user;
        policy.password = params.password;
        policy.authMode = params.authMode;
        policy.tlsPolicy = params.tlsPolicy;
        params.policy = policy.readPolicyDefault;
        params.writePolicy = policy.writePolicyDefault;
        Host[] hosts = Host.parseHosts(params.host, params.port);
        AerospikeClient client = new AerospikeClient(policy, hosts);
        try {
            EventLoop eventLoop = eventLoops.get(0);
            params.setServerSpecific(client);
            for (String exampleName : examples) {
                runExample(exampleName, client, eventLoop, params, console);
            }
        } finally {
            client.close();
        }
    } finally {
        eventLoops.close();
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) ClientPolicy(com.aerospike.client.policy.ClientPolicy) NioEventLoops(com.aerospike.client.async.NioEventLoops) EventLoops(com.aerospike.client.async.EventLoops) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EventPolicy(com.aerospike.client.async.EventPolicy) Host(com.aerospike.client.Host) NioEventLoops(com.aerospike.client.async.NioEventLoops) IOUringEventLoopGroup(io.netty.incubator.channel.uring.IOUringEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) IOUringEventLoopGroup(io.netty.incubator.channel.uring.IOUringEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) EventLoop(com.aerospike.client.async.EventLoop) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 4 with ClientPolicy

use of com.aerospike.client.policy.ClientPolicy in project aerospike-client-java by aerospike.

the class AerospikeServlet method initConnection.

private boolean initConnection(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String hostString = request.getParameter("host");
    String portString = request.getParameter("port");
    if (client != null && client.isConnected() && hostString != null && portString != null && host.equals(hostString) && Integer.toString(port).equals(portString))
        return true;
    host = hostString;
    if (host == null || host.length() == 0) {
        try {
            host = getServletConfig().getInitParameter("clusterAddr").trim();
        } catch (Exception e) {
            host = "127.0.0.1";
        }
    }
    if (portString == null || portString.length() == 0) {
        try {
            portString = getServletConfig().getInitParameter("clusterPort");
        } catch (Exception e) {
            portString = "3000";
        }
    }
    try {
        port = Integer.parseInt(portString);
    } catch (Exception e) {
        displayLoginError(response, host, portString, null);
        return false;
    }
    try {
        ClientPolicy policy = new ClientPolicy();
        client = new AerospikeClient(policy, host, port);
        if (client.isConnected())
            return true;
        displayLoginError(response, host, portString, null);
        return false;
    } catch (Exception ex) {
        displayLoginError(response, host, portString, ex.getMessage());
        return false;
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) ClientPolicy(com.aerospike.client.policy.ClientPolicy) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) AerospikeException(com.aerospike.client.AerospikeException)

Example 5 with ClientPolicy

use of com.aerospike.client.policy.ClientPolicy in project aerospike-client-java by aerospike.

the class SuiteSync method init.

@BeforeClass
public static void init() {
    System.out.println("Begin AerospikeClient");
    Args args = Args.Instance;
    ClientPolicy policy = new ClientPolicy();
    policy.user = args.user;
    policy.password = args.password;
    policy.authMode = args.authMode;
    policy.tlsPolicy = args.tlsPolicy;
    Host[] hosts = Host.parseHosts(args.host, args.port);
    client = new AerospikeClient(policy, hosts);
    try {
        args.setServerSpecific(client);
    } catch (RuntimeException re) {
        client.close();
        throw re;
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) Args(com.aerospike.test.util.Args) ClientPolicy(com.aerospike.client.policy.ClientPolicy) Host(com.aerospike.client.Host) BeforeClass(org.junit.BeforeClass)

Aggregations

ClientPolicy (com.aerospike.client.policy.ClientPolicy)8 AerospikeClient (com.aerospike.client.AerospikeClient)6 AerospikeException (com.aerospike.client.AerospikeException)4 Host (com.aerospike.client.Host)4 EventPolicy (com.aerospike.client.async.EventPolicy)2 NettyEventLoops (com.aerospike.client.async.NettyEventLoops)2 NioEventLoops (com.aerospike.client.async.NioEventLoops)2 Args (com.aerospike.test.util.Args)2 EventLoopGroup (io.netty.channel.EventLoopGroup)2 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)2 KQueueEventLoopGroup (io.netty.channel.kqueue.KQueueEventLoopGroup)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 IOUringEventLoopGroup (io.netty.incubator.channel.uring.IOUringEventLoopGroup)2 IOException (java.io.IOException)2 Properties (java.util.Properties)2 BeforeClass (org.junit.BeforeClass)2 EventLoop (com.aerospike.client.async.EventLoop)1 EventLoops (com.aerospike.client.async.EventLoops)1 DBException (com.yahoo.ycsb.DBException)1 ServletException (javax.servlet.ServletException)1