Search in sources :

Example 26 with ClientConfig

use of voldemort.client.ClientConfig in project javaee7-samples by javaee-samples.

the class PersonSessionBean method initDB.

@PostConstruct
private void initDB() {
    //        // start embedded
    //        VoldemortConfig config = VoldemortConfig.loadFromEnvironmentVariable();
    //        VoldemortServer server = new VoldemortServer(config);
    //        server.start();
    // bootstrap
    String bootstrapUrl = "tcp://localhost:6666";
    StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    // create a client that executes operations on a single store
    client = factory.getStoreClient("test");
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory) PostConstruct(javax.annotation.PostConstruct)

Example 27 with ClientConfig

use of voldemort.client.ClientConfig in project voldemort by voldemort.

the class TestClientShutdown method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2 || args.length > 3)
        Utils.croak("USAGE: java VoldemortClientShell store_name bootstrap_url [command_file]");
    String storeName = args[0];
    String bootstrapUrl = args[1];
    StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setEnableLazy(false).setBootstrapUrls(bootstrapUrl));
    DefaultStoreClient<Object, Object> client = null;
    try {
        client = (DefaultStoreClient<Object, Object>) factory.getStoreClient(storeName);
    } catch (Exception e) {
        Utils.croak("Could not connect to server: " + e.getMessage());
    }
    System.out.println("Established connection to " + storeName + " via " + bootstrapUrl);
    client.get("hello");
    System.out.println("Got value");
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory)

Example 28 with ClientConfig

use of voldemort.client.ClientConfig in project voldemort by voldemort.

the class RemoteDataGenerator method generateData.

/**
     * Populate the store with
     * 
     * @param requests key-value pairs with key of size, appending
     * @param postfix for uniqueness.
     * 
     * @param keySize bytes and value of size
     * @param valueSize bytes
     * @param requests How many key-value pairs to generate
     * @param keySize Size (in bytes) of the key
     * @param valueSize Size (in bytes) of the value
     * @param postfix Postfix to append (for uniqueness)
     */
public void generateData(int requests, int keySize, int valueSize, String postfix) {
    StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(url).setMaxThreads(workers));
    StoreClient<String, String> client = storeClientFactory.getStoreClient(storeName);
    for (int i = 0; i < requests; i++) {
        StringBuilder keyBuilder = new StringBuilder(makeString(keySize)).append(i);
        StringBuilder valueBuilder = new StringBuilder(makeString(valueSize)).append(i);
        if (postfix != null) {
            keyBuilder.append(postfix);
        }
        try {
            client.put(keyBuilder.toString(), valueBuilder.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) IOException(java.io.IOException) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreClientFactory(voldemort.client.StoreClientFactory)

Example 29 with ClientConfig

use of voldemort.client.ClientConfig in project voldemort by voldemort.

the class HintedHandoffTestEnvironment method run.

@Override
public void run() {
    Random random = new Random(System.currentTimeMillis());
    cluster = VoldemortTestConstants.getEightNodeClusterWithZones();
    storeDef = storeDefBuilder.build();
    // setup store engines
    for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
        // do only once
        createInnerStore(nodeId);
    }
    for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
        try {
            startServer(nodeId);
        } catch (IOException e) {
            logger.error("Server " + nodeId + "failed to start", e);
        }
    }
    // setup client factory
    String bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
    factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
    // wait for start of servers
    startFinishLatch.countDown();
    try {
        boolean wrapUpSignal = false;
        while (!wrapUpSignal) {
            if (logger.isInfoEnabled()) {
                logger.info("Will sleep for a while or until seeing wrapUpSignal. sleep time: " + statusRefreshIntervalSecond + " Seconds");
            }
            wrapUpSignal = wrapUpRequestLatch.await(statusRefreshIntervalSecond, TimeUnit.SECONDS);
            if (logger.isInfoEnabled()) {
                if (wrapUpSignal) {
                    logger.info("Wake Up and wrap up. Make all servers NORMAL");
                    minNodesAvailable = NUM_NODES_TOTAL;
                } else {
                    logger.info("Wake Up and decide new failure statuses");
                }
                for (Map.Entry<Integer, Store<ByteArray, byte[], byte[]>> entry : realStores.entrySet()) {
                    InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]> engine = (InMemoryPutAssertionStorageEngine<ByteArray, byte[], byte[]>) entry.getValue();
                    logger.info("Outstanding Put Assertions of node [" + entry.getKey() + "]: " + engine.getFailedAssertions().size());
                }
            }
            // decide random number of cluster nodes(at least 1 alive) with
            // random ids to fail
            Integer numNodesToFail = random.nextInt(NUM_NODES_TOTAL - minNodesAvailable + 1);
            Set<Integer> nodesToFail = getUniqueRandomNumbers(NUM_NODES_TOTAL, numNodesToFail);
            if (logger.isInfoEnabled()) {
                logger.info("Setting nodes to Fail: " + nodesToFail.toString());
            }
            for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
                if (nodesToFail.contains(nodeId)) {
                    // fail a node if it's normal
                    if (nodesStatus.get(nodeId) == NodeStatus.NORMAL) {
                        // random pick one failure node
                        Integer failureMode = random.nextInt(3);
                        switch(failureMode) {
                            case 0:
                                makeNodeDown(nodeId);
                                break;
                            case 1:
                                makeNodeSlow(nodeId);
                                break;
                            case 2:
                                makeNodeBdbError(nodeId);
                                break;
                        }
                    }
                // otherwise, leave unchanged
                } else {
                    // make node normal if not normal
                    if (nodesStatus.get(nodeId) != NodeStatus.NORMAL) {
                        makeNodeNormal(nodeId);
                    }
                // otherwise, leave unchanged
                }
            }
        }
    } catch (InterruptedException e) {
    } finally {
        wrapUpFinishLatch.countDown();
    }
}
Also used : Store(voldemort.store.Store) SleepyStore(voldemort.store.SleepyStore) ForceFailStore(voldemort.store.ForceFailStore) IOException(java.io.IOException) Random(java.util.Random) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ByteArray(voldemort.utils.ByteArray) InMemoryPutAssertionStorageEngine(voldemort.store.memory.InMemoryPutAssertionStorageEngine) ClientConfig(voldemort.client.ClientConfig) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with ClientConfig

use of voldemort.client.ClientConfig in project voldemort by voldemort.

the class CompressingStoreTest method testPutGetWithSocketService.

@Test
public void testPutGetWithSocketService() throws Exception {
    int freePort = ServerTestUtils.findFreePort();
    String clusterXml = VoldemortTestConstants.getOneNodeClusterXml();
    clusterXml = clusterXml.replace("<socket-port>6666</socket-port>", "<socket-port>" + freePort + "</socket-port>");
    AbstractSocketService socketService = ServerTestUtils.getSocketService(useNio, clusterXml, VoldemortTestConstants.getCompressedStoreDefinitionsXml(), "test", freePort);
    socketService.start();
    Thread.sleep(1000);
    SocketStoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls("tcp://localhost:" + freePort).setMaxBootstrapRetries(10));
    StoreClient<String, String> storeClient = storeClientFactory.getStoreClient("test");
    storeClient.put("someKey", "someValue");
    assertEquals(storeClient.getValue("someKey"), "someValue");
    socketService.stop();
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) AbstractSocketService(voldemort.server.AbstractSocketService) ClientConfig(voldemort.client.ClientConfig) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Aggregations

ClientConfig (voldemort.client.ClientConfig)51 SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)37 VoldemortServer (voldemort.server.VoldemortServer)17 IOException (java.io.IOException)15 Properties (java.util.Properties)15 Test (org.junit.Test)15 Before (org.junit.Before)14 ByteArray (voldemort.utils.ByteArray)13 ArrayList (java.util.ArrayList)12 Cluster (voldemort.cluster.Cluster)12 ExecutorService (java.util.concurrent.ExecutorService)10 AdminClient (voldemort.client.protocol.admin.AdminClient)10 Node (voldemort.cluster.Node)10 StoreClientFactory (voldemort.client.StoreClientFactory)9 HashMap (java.util.HashMap)8 List (java.util.List)8 ClientRequestExecutorPool (voldemort.store.socket.clientrequest.ClientRequestExecutorPool)8 File (java.io.File)7 VoldemortException (voldemort.VoldemortException)7 CountDownLatch (java.util.concurrent.CountDownLatch)6