Search in sources :

Example 1 with GetOptions

use of com.ms.silverking.cloud.dht.GetOptions in project SilverKing by Morgan-Stanley.

the class PerspectiveTest method test.

// @Test
public void test() {
    try {
        SynchronousNamespacePerspective<String, String> syncNSP = new DHTClient().openSession(Util.getTestGridConfig()).openSyncNamespacePerspective("_VersionTest", String.class, String.class);
        syncNSP.setDefaultRetrievalVersionConstraint(VersionConstraint.defaultConstraint);
        // syncNSP.setDefaultVersionProvider(syncNSP.getNamespace().getOptions().versionMode(NamespaceVersionMode.CLIENT_SPECIFIED).getVersionMode());
        // syncNSP.set
        printNsoAndNspo(syncNSP);
        PutOptions po = syncNSP.getOptions().getDefaultPutOptions();
        GetOptions go = syncNSP.getOptions().getDefaultGetOptions();
        // syncNSP.setOptions( syncNSP.getOptions().defaultPutOptions( po ));
        System.out.println("\n\n" + go);
        syncNSP.getNamespace().getOptions().versionMode(NamespaceVersionMode.CLIENT_SPECIFIED).revisionMode(RevisionMode.UNRESTRICTED_REVISIONS);
        printNsoAndNspo(syncNSP);
        syncNSP.put("k", "v1", po.version(1));
        // syncNSP.put("k", "v2", po.version(2));
        System.out.println(syncNSP.get("k"));
    // System.out.println( syncNSP.get("k", go));
    // syncNSP.setOptions( syncNSP.getOptions().defaultPutOptions( new PutOptions(opTimeoutController, secondaryTargets, compression, checksumType, checksumCompressedValues, version, userData)));
    // 
    // syncNSP.put(mapA);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : GetOptions(com.ms.silverking.cloud.dht.GetOptions) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient) PutOptions(com.ms.silverking.cloud.dht.PutOptions) IOException(java.io.IOException) ClientException(com.ms.silverking.cloud.dht.client.ClientException)

Example 2 with GetOptions

use of com.ms.silverking.cloud.dht.GetOptions in project SilverKing by Morgan-Stanley.

the class PerspectiveTest method testDefaultsPuts.

@Test
public void testDefaultsPuts() throws ClientException, IOException {
    Namespace ns = session.createNamespace(namespaceName, session.getDefaultNamespaceOptions().versionMode(NamespaceVersionMode.CLIENT_SPECIFIED).revisionMode(RevisionMode.UNRESTRICTED_REVISIONS).defaultPutOptions(session.getDefaultPutOptions().version(5)));
    SynchronousNamespacePerspective<String, String> syncNsp = ns.openSyncPerspective(String.class, String.class);
    PutOptions putOptions = syncNsp.getOptions().getDefaultPutOptions();
    GetOptions getOptions = syncNsp.getOptions().getDefaultGetOptions();
    syncNsp.put("k", "v1");
    printKeyVals(syncNsp, "k", getOptions);
    syncNsp.put("k", "v2", putOptions.version(1));
    printKeyVals(syncNsp, "k", getOptions);
    syncNsp.put("k", "v3");
    printKeyVals(syncNsp, "k", getOptions);
    // this guy is not working as expected
    syncNsp.setDefaultVersion(4);
    syncNsp.put("k", "v4");
    printKeyVals(syncNsp, "k", getOptions);
    // this guy is not working as expected
    syncNsp.setDefaultVersionProvider(new ConstantVersionProvider(6));
    syncNsp.put("k", "v5");
    printKeyVals(syncNsp, "k", getOptions);
    syncNsp.put("k", "v6", putOptions.version(8));
    printKeyVals(syncNsp, "k", getOptions);
}
Also used : ConstantVersionProvider(com.ms.silverking.cloud.dht.client.ConstantVersionProvider) GetOptions(com.ms.silverking.cloud.dht.GetOptions) Namespace(com.ms.silverking.cloud.dht.client.Namespace) PutOptions(com.ms.silverking.cloud.dht.PutOptions) Test(org.junit.Test)

Example 3 with GetOptions

use of com.ms.silverking.cloud.dht.GetOptions in project SilverKing by Morgan-Stanley.

the class RecoverOldAttr method recover.

public void recover(String file, long version) throws PutException, RetrievalException {
    StoredValue<byte[]> oldAttrValue;
    GetOptions getOptions;
    getOptions = syncNSP.getOptions().getDefaultGetOptions().versionConstraint(VersionConstraint.exactMatch(version)).nonExistenceResponse(NonExistenceResponse.NULL_VALUE);
    oldAttrValue = syncNSP.get(file, getOptions);
    if (oldAttrValue == null || oldAttrValue.getValue() == null) {
        System.out.printf("Couldn't find file %s version %d\n", file, version);
    } else {
        System.out.printf("Rewriting file %s version %d\n", file, version);
        syncNSP.put(file, oldAttrValue.getValue());
    }
}
Also used : GetOptions(com.ms.silverking.cloud.dht.GetOptions)

Example 4 with GetOptions

use of com.ms.silverking.cloud.dht.GetOptions in project SilverKing by Morgan-Stanley.

the class DevTest method test.

public void test(int numKeys, int reps, String namespace, Compression compression, ChecksumType checksumType, EnumSet<Test> tests) throws Exception {
    DHTClient client;
    ClientDHTConfiguration dhtConfig;
    DHTSession session;
    AsynchronousNamespacePerspective<String, String> asyncNSP;
    AsyncRetrieval<String, String> asyncRetrieval;
    AsyncPut<String> asyncPut;
    Stopwatch sw;
    PutOptions putOptions;
    asyncPut = null;
    client = new DHTClient();
    dhtConfig = new ClientDHTConfiguration(dhtName, new ZooKeeperConfig(zkLocs));
    session = client.openSession(dhtConfig);
    putOptions = session.getDefaultNamespaceOptions().getDefaultPutOptions().compression(compression).checksumType(checksumType);
    asyncNSP = session.openAsyncNamespacePerspective(namespace, String.class, String.class);
    sw = new SimpleStopwatch();
    if (tests.contains(Test.Put)) {
        System.out.println("\n\n\t\tPUT");
        for (int i = 0; i < reps; i++) {
            // asyncPut = asyncNSP.put("Hello"+ i, "world!");
            asyncPut = asyncNSP.put(createMap(i, numKeys), putOptions);
            asyncPut.waitForCompletion();
        }
        sw.stop();
        displayTimes(sw, reps, numKeys, valueSize);
    }
    if (tests.contains(Test.Get)) {
        System.out.println("\n\n\t\tGET");
        GetOptions getOptions;
        sw.reset();
        getOptions = OptionsHelper.newGetOptions(RetrievalType.VALUE_AND_META_DATA, session.getDefaultNamespaceOptions().getDefaultGetOptions().getVersionConstraint());
        for (int i = 0; i < reps; i++) {
            Set<String> keys;
            Map<String, ? extends StoredValue<String>> values;
            keys = createSet(i, numKeys);
            asyncRetrieval = asyncNSP.get(keys, getOptions);
            asyncRetrieval.waitForCompletion();
            if (displayValues) {
                System.out.printf("keys: %s\n", CollectionUtil.toString(keys));
                values = asyncRetrieval.getStoredValues();
                System.out.printf("values: %s\n", CollectionUtil.toString(values.entrySet()));
                for (Entry<String, ? extends StoredValue<String>> entry : values.entrySet()) {
                    System.out.println(entry.getKey() + " -> " + entry.getValue().getValue() + "\t" + entry.getValue().getMetaData().toString(true));
                }
            }
        }
        sw.stop();
        displayTimes(sw, reps, numKeys, valueSize);
    }
}
Also used : ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) ClientDHTConfiguration(com.ms.silverking.cloud.dht.client.ClientDHTConfiguration) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) DHTSession(com.ms.silverking.cloud.dht.client.DHTSession) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) GetOptions(com.ms.silverking.cloud.dht.GetOptions) PutOptions(com.ms.silverking.cloud.dht.PutOptions) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient)

Example 5 with GetOptions

use of com.ms.silverking.cloud.dht.GetOptions in project SilverKing by Morgan-Stanley.

the class PerspectiveTest method test_NamespaceOptions_vs_NamespacePerspectiveOptions.

// @Test
public void test_NamespaceOptions_vs_NamespacePerspectiveOptions() throws ClientException, IOException {
    Namespace ns = session.createNamespace(namespaceName, session.getDefaultNamespaceOptions().versionMode(NamespaceVersionMode.CLIENT_SPECIFIED).revisionMode(RevisionMode.UNRESTRICTED_REVISIONS));
    SynchronousNamespacePerspective<String, String> syncNSPString = ns.openSyncPerspective(String.class, String.class);
    SynchronousNamespacePerspective<String, Integer> syncNSPInt = ns.openSyncPerspective(String.class, Integer.class);
    PutOptions poString = syncNSPString.getOptions().getDefaultPutOptions();
    GetOptions goString = syncNSPString.getOptions().getDefaultGetOptions();
    PutOptions poInt = syncNSPInt.getOptions().getDefaultPutOptions();
    GetOptions goInt = syncNSPInt.getOptions().getDefaultGetOptions();
    syncNSPString.put("k", "v1", poString.version(1));
    syncNSPInt.put("k", 2, poInt.version(2));
    System.out.println(syncNSPString);
    System.out.println(syncNSPString.get("k"));
    System.out.println(syncNSPString.get("k", goString.versionConstraint(VersionConstraint.exactMatch(1))).getValue());
    System.out.println("-");
    System.out.println(syncNSPInt.get("k"));
    System.out.println(syncNSPInt.get("k", goInt.versionConstraint(VersionConstraint.exactMatch(2))).getValue());
    System.out.println(syncNSPInt.get("k", goInt.versionConstraint(VersionConstraint.exactMatch(1))).getValue());
}
Also used : GetOptions(com.ms.silverking.cloud.dht.GetOptions) Namespace(com.ms.silverking.cloud.dht.client.Namespace) PutOptions(com.ms.silverking.cloud.dht.PutOptions)

Aggregations

GetOptions (com.ms.silverking.cloud.dht.GetOptions)5 PutOptions (com.ms.silverking.cloud.dht.PutOptions)4 DHTClient (com.ms.silverking.cloud.dht.client.DHTClient)2 Namespace (com.ms.silverking.cloud.dht.client.Namespace)2 ClientDHTConfiguration (com.ms.silverking.cloud.dht.client.ClientDHTConfiguration)1 ClientException (com.ms.silverking.cloud.dht.client.ClientException)1 ConstantVersionProvider (com.ms.silverking.cloud.dht.client.ConstantVersionProvider)1 DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)1 ZooKeeperConfig (com.ms.silverking.cloud.zookeeper.ZooKeeperConfig)1 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)1 Stopwatch (com.ms.silverking.time.Stopwatch)1 IOException (java.io.IOException)1 Test (org.junit.Test)1