Search in sources :

Example 6 with MutableInteger

use of org.objectweb.proactive.core.util.MutableInteger in project scheduling by ow2-proactive.

the class NodesLockRestorationManagerTest method testInitialize.

@Test
public void testInitialize() {
    Map<String, MutableInteger> map = Maps.newHashMap();
    map.put("nodeSource", new MutableInteger(42));
    doReturn(map).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    assertThat(nodesLockRestorationManager.isInitialized()).isFalse();
    assertThat(nodesLockRestorationManager.getNodeLockedOnPreviousRun()).isEmpty();
    nodesLockRestorationManager.initialize();
    assertThat(nodesLockRestorationManager.isInitialized()).isTrue();
    assertThat(nodesLockRestorationManager.getNodeLockedOnPreviousRun()).hasSize(1);
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger) Test(org.junit.Test)

Example 7 with MutableInteger

use of org.objectweb.proactive.core.util.MutableInteger in project scheduling by ow2-proactive.

the class NodesLockRestorationManagerTest method testHandleNonMatchingNode.

@Test
public void testHandleNonMatchingNode() {
    RMNodeImpl rmNode = RMNodeHelper.basicWithMockedInternals("ns2", "n1", "h1", "nurl1", "parurl1").getLeft();
    assertThat(rmNode.isLocked()).isFalse();
    Map<String, MutableInteger> table = Maps.newHashMap();
    MutableInteger putResult = table.put("ns1", new MutableInteger(1));
    assertThat(putResult).isNull();
    doReturn(table).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
    nodesLockRestorationManager.initialize();
    assertThat(nodesLockRestorationManager.isInitialized()).isTrue();
    verify(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    nodesLockRestorationManager.handle(rmNode, caller);
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) Test(org.junit.Test)

Example 8 with MutableInteger

use of org.objectweb.proactive.core.util.MutableInteger in project scheduling by ow2-proactive.

the class RMDBManager method entityToMap.

public Map<String, MutableInteger> entityToMap(List<LockHistory> lockHistoryResult) {
    if (lockHistoryResult == null || lockHistoryResult.isEmpty()) {
        return Maps.newHashMap();
    }
    Map<String, MutableInteger> result = new HashMap<>(lockHistoryResult.size(), 1f);
    for (Object entry : lockHistoryResult) {
        LockHistory lockHistory = (LockHistory) entry;
        int lockCount = lockHistory.getLockCount();
        if (lockCount > 0) {
            result.put(lockHistory.getNodeSource(), new MutableInteger(lockCount));
        }
    }
    return result;
}
Also used : LockHistory(org.ow2.proactive.resourcemanager.core.history.LockHistory) HashMap(java.util.HashMap) MutableInteger(org.objectweb.proactive.core.util.MutableInteger)

Example 9 with MutableInteger

use of org.objectweb.proactive.core.util.MutableInteger in project scheduling by ow2-proactive.

the class NodesLockRestorationManager method handle.

/**
 * Handle the specified node for lock restoration.
 *
 * @param node the node to consider.
 */
public void handle(RMNode node, Client caller) {
    if (!isNodeValidToBeRestored(node)) {
        if (log.isDebugEnabled()) {
            String nodeUrl = node.getNodeURL();
            if (!initialized) {
                logSkipReason(nodeUrl, "manager is not yet initialized");
            } else if (node.isLocked()) {
                logSkipReason(nodeUrl, "it is locked");
            } else {
                logSkipReason(nodeUrl, "restoration is complete");
            }
        }
        return;
    }
    String nodeSource = node.getNodeSourceName();
    MutableInteger nodeCount = nodeLockedOnPreviousRun.get(nodeSource);
    if (nodeCount != null) {
        lockNode(node, caller);
        int newNodeCount = nodeCount.add(-1);
        if (newNodeCount == 0) {
            nodeLockedOnPreviousRun.remove(nodeSource);
        }
    }
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger)

Example 10 with MutableInteger

use of org.objectweb.proactive.core.util.MutableInteger in project scheduling by ow2-proactive.

the class NodesLockRestorationManager method initialize.

protected void initialize() {
    Stopwatch stopwatch = null;
    if (log.isInfoEnabled()) {
        stopwatch = Stopwatch.createStarted();
    }
    nodeLockedOnPreviousRun = findNodesLockedOnPreviousRun();
    if (log.isInfoEnabled()) {
        stopwatch.stop();
        log.info("Identifying nodes locked on the previous run required " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
    }
    if (nodeLockedOnPreviousRun.isEmpty()) {
        log.info("There is no locks to restore");
    } else {
        log.info("Here is the number of nodes to lock per node source:");
        for (Map.Entry<String, MutableInteger> entry : nodeLockedOnPreviousRun.entrySet()) {
            log.info("  - nodeSource=" + entry.getKey() + ", host=" + entry.getKey() + ", count=" + entry.getValue().getValue());
        }
    }
    initialized = true;
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger) Stopwatch(com.google.common.base.Stopwatch) Map(java.util.Map)

Aggregations

MutableInteger (org.objectweb.proactive.core.util.MutableInteger)10 Test (org.junit.Test)6 RMNodeImpl (org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)5 Stopwatch (com.google.common.base.Stopwatch)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)1 LockHistory (org.ow2.proactive.resourcemanager.core.history.LockHistory)1 RMDBManager (org.ow2.proactive.resourcemanager.db.RMDBManager)1