use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.
the class InstallCoordinatorTest method testUninstallIntent.
/**
* Uninstalls test Intents.
*/
@Test
public void testUninstallIntent() {
IntentData toUninstall = new IntentData(createTestIntent(), IntentState.WITHDRAWING, new WallClockTimestamp());
List<Intent> intents = Lists.newArrayList();
IntStream.range(0, 10).forEach(val -> {
intents.add(new TestInstallableIntent(val));
});
toUninstall = IntentData.compiled(toUninstall, intents);
installCoordinator.installIntents(Optional.of(toUninstall), Optional.empty());
Intent toUninstallIntent = toUninstall.intent();
TestTools.assertAfter(INSTALL_DELAY, INSTALL_DURATION, () -> {
IntentData newData = intentStore.newData;
assertEquals(toUninstallIntent, newData.intent());
assertEquals(IntentState.WITHDRAWN, newData.state());
assertEquals(ImmutableList.of(), newData.installables());
});
}
use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.
the class InstallCoordinatorTest method testInstallIntent.
/**
* Installs test Intents.
*/
@Test
public void testInstallIntent() {
IntentData toInstall = new IntentData(createTestIntent(), IntentState.INSTALLING, new WallClockTimestamp());
List<Intent> intents = Lists.newArrayList();
IntStream.range(0, 10).forEach(val -> {
intents.add(new TestInstallableIntent(val));
});
toInstall = IntentData.compiled(toInstall, intents);
installCoordinator.installIntents(Optional.empty(), Optional.of(toInstall));
Intent toInstallIntent = toInstall.intent();
TestTools.assertAfter(INSTALL_DELAY, INSTALL_DURATION, () -> {
IntentData newData = intentStore.newData;
assertEquals(toInstallIntent, newData.intent());
assertEquals(IntentState.INSTALLED, newData.state());
assertEquals(intents, newData.installables());
});
}
use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.
the class IntentCleanup method cleanup.
/**
* Iterates through corrupt, failed and pending intents and
* re-submit/withdraw appropriately.
*/
private void cleanup() {
int corruptCount = 0, failedCount = 0, stuckCount = 0, pendingCount = 0, skipped = 0;
// will add items to the pending map.
for (IntentData intentData : store.getPendingData(true, periodMs)) {
log.debug("Resubmit Pending Intent: key {}, state {}, request {}", intentData.key(), intentData.state(), intentData.request());
resubmitPendingRequest(intentData);
pendingCount++;
}
for (IntentData intentData : store.getIntentData(true, periodMs)) {
IntentData pendingIntentData = store.getPendingData(intentData.key());
if (pendingIntentData != null) {
continue;
}
switch(intentData.state()) {
case FAILED:
log.debug("Resubmit Failed Intent: key {}, state {}, request {}", intentData.key(), intentData.state(), intentData.request());
resubmitCorrupt(intentData, false);
failedCount++;
break;
case CORRUPT:
log.debug("Resubmit Corrupt Intent: key {}, state {}, request {}", intentData.key(), intentData.state(), intentData.request());
resubmitCorrupt(intentData, false);
corruptCount++;
break;
// FALLTHROUGH
case INSTALLING:
case WITHDRAWING:
// Instances can have different clocks and potentially we can have problems
// An Intent can be submitted again before the real period of the stuck intents
final WallClockTimestamp time = new WallClockTimestamp(System.currentTimeMillis() - periodMsForStuck);
if (intentData.version().isOlderThan(time)) {
resubmitPendingRequest(intentData);
stuckCount++;
} else {
skipped++;
}
break;
default:
// NOOP
break;
}
}
if (corruptCount + failedCount + stuckCount + pendingCount > 0) {
log.debug("Intent cleanup ran and resubmitted {} corrupt, {} failed, {} stuck, and {} pending intents", corruptCount, failedCount, stuckCount, pendingCount);
}
if (skipped > 0) {
log.debug("Intent cleanup skipped {} intents", skipped);
}
}
use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.
the class DistributedMasterElectionIdStore method activate.
@Activate
public void activate() {
listeners = Maps.newConcurrentMap();
masterElectionIds = storageService.<Pair<DeviceId, Long>, BigInteger>eventuallyConsistentMapBuilder().withName("p4runtime-master-election-ids").withSerializer(SERIALIZER).withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
masterElectionIds.addListener(mapListener);
log.info("Started");
}
use of org.onosproject.store.service.WallClockTimestamp in project onos by opennetworkinglab.
the class DomainIntentInstallerTest method testUninstallAndInstall.
/**
* Do both uninstall and install domain Intents.
*/
@Test
public void testUninstallAndInstall() {
List<Intent> intentsToUninstall = createDomainIntents();
List<Intent> intentsToInstall = createAnotherDomainIntents();
IntentData toUninstall = new IntentData(createP2PIntent(), IntentState.INSTALLED, new WallClockTimestamp());
toUninstall = IntentData.compiled(toUninstall, intentsToUninstall);
IntentData toInstall = new IntentData(createP2PIntent(), IntentState.INSTALLING, new WallClockTimestamp());
toInstall = IntentData.compiled(toInstall, intentsToInstall);
IntentOperationContext<DomainIntent> operationContext;
IntentInstallationContext context = new IntentInstallationContext(toUninstall, toInstall);
operationContext = new IntentOperationContext(intentsToUninstall, intentsToInstall, context);
installer.apply(operationContext);
assertEquals(intentInstallCoordinator.successContext, operationContext);
}
Aggregations