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);
}
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));
}
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;
}
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);
}
}
}
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;
}
Aggregations