Search in sources :

Example 11 with Pair

use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.

the class AsyncOperationImpl method checkForUpdates.

/**
 * Called by subclasses to update incomplete state. Complete updates are handled inside of
 * setResult to ensure that completion results fire exactly once.
 */
protected void checkForUpdates() {
    if (listeners != null) {
        Set<Pair<AsyncOperationListener, EnumSet<OperationState>>> _listeners;
        OperationState opState;
        opState = getState();
        if (opState == OperationState.INCOMPLETE) {
            _listeners = null;
            lock.lock();
            try {
                if (listeners != null) {
                    _listeners = ImmutableSet.copyOf(listeners);
                }
            } finally {
                lock.unlock();
            }
            if (_listeners != null) {
                notificationWorker.fiterForUpdates(this, _listeners, opState);
            }
        }
    }
}
Also used : OperationState(com.ms.silverking.cloud.dht.client.OperationState) Pair(com.ms.silverking.collection.Pair)

Example 12 with Pair

use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.

the class MasterModeDependencyWatcher method readMasterRingTree.

private Pair<RingTree, Triple<String, Long, Long>> readMasterRingTree(com.ms.silverking.cloud.dht.meta.MetaClient dhtMC, DHTConfiguration dhtConfig) throws KeeperException, IOException {
    DHTRingCurTargetZK dhtRingCurTargetZK;
    Triple<String, Long, Long> masterRingAndVersionPair;
    RingTree ringTree;
    dhtRingCurTargetZK = new DHTRingCurTargetZK(dhtMC, dhtConfig);
    masterRingAndVersionPair = dhtRingCurTargetZK.getMasterRingAndVersionPair();
    if (masterRingAndVersionPair == null) {
        throw new RuntimeException("Can't find master ring");
    } else {
        ringTree = SingleRingZK.readTree(mc, masterRingAndVersionPair.getV2(), masterRingAndVersionPair.getV3());
        return new Pair<>(ringTree, masterRingAndVersionPair);
    }
}
Also used : DHTRingCurTargetZK(com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK) Pair(com.ms.silverking.collection.Pair)

Example 13 with Pair

use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.

the class LZ4 method compressFile.

private static final Pair<Triple<Double, Double, Double>, Pair<Integer, Integer>> compressFile(File file) throws IOException {
    Stopwatch readingSW;
    Stopwatch compressionSW;
    Stopwatch decompressionSW;
    byte[] original;
    byte[] compressed;
    byte[] uncompressed;
    readingSW = new SimpleStopwatch();
    System.out.printf("Reading file:          %s\n", file);
    original = FileUtil.readFileAsBytes(file);
    readingSW.stop();
    System.out.printf("Reading elapsed:       %f\n", readingSW.getElapsedSeconds());
    compressionSW = new SimpleStopwatch();
    compressed = new LZ4().compress(original, 0, original.length);
    compressionSW.stop();
    System.out.printf("Compression elapsed:   %f\n", compressionSW.getElapsedSeconds());
    decompressionSW = new SimpleStopwatch();
    uncompressed = new LZ4().decompress(compressed, 0, compressed.length, original.length);
    decompressionSW.stop();
    System.out.printf("Decompression elapsed: %f\n", decompressionSW.getElapsedSeconds());
    return new Pair<>(new Triple<>(readingSW.getElapsedSeconds(), compressionSW.getElapsedSeconds(), decompressionSW.getElapsedSeconds()), new Pair<Integer, Integer>(original.length, compressed.length));
}
Also used : SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) Pair(com.ms.silverking.collection.Pair)

Example 14 with Pair

use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.

the class Ping method ping.

public Pair<Boolean, String> ping(String dest, int count) throws IOException {
    ProcessExecutor pe;
    String[] cmd;
    boolean ok;
    String output;
    cmd = new String[4];
    cmd[0] = ping;
    cmd[1] = "-c";
    cmd[2] = Integer.toString(count);
    cmd[3] = dest;
    pe = new ProcessExecutor(cmd);
    try {
        pe.execute();
        ok = pe.getExitCode() == 0;
        output = pe.getOutput();
    } catch (ExitCodeException ece) {
        ok = false;
        output = null;
    }
    return new Pair<>(ok, output);
}
Also used : ProcessExecutor(com.ms.silverking.process.ProcessExecutor) ExitCodeException(org.apache.zookeeper.Shell.ExitCodeException) Pair(com.ms.silverking.collection.Pair)

Example 15 with Pair

use of com.ms.silverking.collection.Pair in project SilverKing by Morgan-Stanley.

the class SKAdmin method waitUntilRunning.

// /////////////////////////////////////////
public Pair<Set<IPAndPort>, Boolean> waitUntilRunning(Set<IPAndPort> activeNodes, int timeoutSeconds) {
    DaemonStateZK daemonStateZK;
    Map<IPAndPort, DaemonState> daemonState;
    daemonStateZK = new DaemonStateZK(dhtMC);
    daemonState = daemonStateZK.waitForQuorumState(activeNodes, DaemonState.RUNNING, timeoutSeconds, true);
    Log.warningf("daemonState: %s", daemonState);
    if (daemonState.isEmpty()) {
        return new Pair<>(ImmutableSet.of(), true);
    } else {
        HashSet<IPAndPort> failedDaemons;
        boolean running;
        running = true;
        failedDaemons = new HashSet<>();
        for (IPAndPort activeNode : activeNodes) {
            DaemonState ds;
            ds = daemonState.get(activeNode);
            System.out.printf("Node: %s\tstate: %s\n", activeNode, ds);
            if (ds == null) {
                failedDaemons.add(activeNode);
                running = false;
            } else {
                if (ds != DaemonState.RUNNING) {
                    running = false;
                }
            }
        }
        return new Pair<>(failedDaemons, running);
    }
}
Also used : DaemonStateZK(com.ms.silverking.cloud.dht.meta.DaemonStateZK) IPAndPort(com.ms.silverking.net.IPAndPort) DaemonState(com.ms.silverking.cloud.dht.daemon.DaemonState) Pair(com.ms.silverking.collection.Pair)

Aggregations

Pair (com.ms.silverking.collection.Pair)16 IPAndPort (com.ms.silverking.net.IPAndPort)6 KeeperException (org.apache.zookeeper.KeeperException)3 DaemonState (com.ms.silverking.cloud.dht.daemon.DaemonState)2 NodeInfo (com.ms.silverking.cloud.dht.daemon.NodeInfo)2 DHTRingCurTargetZK (com.ms.silverking.cloud.dht.meta.DHTRingCurTargetZK)2 SSStorageParameters (com.ms.silverking.cloud.dht.serverside.SSStorageParameters)2 ImmutableList (com.google.common.collect.ImmutableList)1 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)1 OperationState (com.ms.silverking.cloud.dht.client.OperationState)1 StorageParameters (com.ms.silverking.cloud.dht.daemon.storage.StorageParameters)1 DaemonStateZK (com.ms.silverking.cloud.dht.meta.DaemonStateZK)1 PutTrigger (com.ms.silverking.cloud.dht.serverside.PutTrigger)1 RetrieveTrigger (com.ms.silverking.cloud.dht.serverside.RetrieveTrigger)1 InstantiatedRingTree (com.ms.silverking.cloud.toporing.InstantiatedRingTree)1 NamedRingConfiguration (com.ms.silverking.cloud.toporing.meta.NamedRingConfiguration)1 RingConfiguration (com.ms.silverking.cloud.toporing.meta.RingConfiguration)1 RingConfigurationZK (com.ms.silverking.cloud.toporing.meta.RingConfigurationZK)1 Quadruple (com.ms.silverking.collection.Quadruple)1 UUIDBase (com.ms.silverking.id.UUIDBase)1