use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class IntentCleanupTestMock method installingPoll.
/**
* Trigger resubmit of intent in INSTALLING for too long.
*/
@Test
@Ignore("The implementation is dependent on the SimpleStore")
public void installingPoll() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
intentData.setState(INSTALLING);
store.write(intentData);
}
@Override
public void notify(IntentEvent event) {
cleanup.event(event);
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
Timestamp version = new SystemClockTimestamp(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, version);
store.addPending(data);
service.addPending(data);
expectLastCall().once();
replay(service);
cleanup.run();
verify(service);
reset(service);
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class IntentCleanupTestMock method corruptEvent.
/**
* Verify resubmit in response to CORRUPT event.
*/
@Test
public void corruptEvent() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
intentData.setState(CORRUPT);
store.write(intentData);
}
@Override
public void notify(IntentEvent event) {
cleanup.event(event);
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, null);
service.submit(intent);
expectLastCall().once();
replay(service);
store.addPending(data);
verify(service);
reset(service);
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class GossipIntentStoreTest method testPending.
/**
* Tests the operation of the APIs for the pending map.
*/
@Test
public void testPending() {
// crete a new intent and add it as pending
Intent intent = builder1.build();
IntentData installed = new IntentData(intent, IntentState.INSTALLED, new IntentTestsMocks.MockTimestamp(11));
intentStore.addPending(installed);
// check that the getPending() API returns the new pending intent
Iterable<Intent> pendingIntentIteratorAll = intentStore.getPending();
assertThat(pendingIntentIteratorAll.iterator().hasNext(), is(true));
pendingIntentIteratorAll.forEach(data -> assertThat(data, is(intent)));
// check that the getPendingData() API returns the IntentData for the
// new pending intent
Iterable<IntentData> pendingDataIteratorAll = intentStore.getPendingData();
assertThat(pendingDataIteratorAll.iterator().hasNext(), is(true));
pendingDataIteratorAll.forEach(data -> assertThat(data, is(installed)));
// check that the new pending intent is returned by the getPendingData()
// API when a time stamp is provided
Iterable<IntentData> pendingDataIteratorSelected = intentStore.getPendingData(true, 10L);
assertThat(pendingDataIteratorSelected.iterator().hasNext(), is(true));
pendingDataIteratorSelected.forEach(data -> assertThat(data, is(installed)));
// check that the new pending intent is returned by the getPendingData()
// API when a time stamp is provided
Iterable<IntentData> pendingDataIteratorAllFromTimestamp = intentStore.getPendingData(false, 0L);
assertThat(pendingDataIteratorAllFromTimestamp.iterator().hasNext(), is(true));
pendingDataIteratorSelected.forEach(data -> assertThat(data, is(installed)));
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class DomainIntentInstaller method apply.
@Override
public void apply(IntentOperationContext<DomainIntent> context) {
Optional<IntentData> toUninstall = context.toUninstall();
Optional<IntentData> toInstall = context.toInstall();
List<DomainIntent> uninstallIntents = context.intentsToUninstall();
List<DomainIntent> installIntents = context.intentsToInstall();
if (!toInstall.isPresent() && !toUninstall.isPresent()) {
intentInstallCoordinator.intentInstallSuccess(context);
return;
}
if (toUninstall.isPresent()) {
IntentData intentData = toUninstall.get();
trackerService.removeTrackedResources(intentData.key(), intentData.intent().resources());
uninstallIntents.forEach(installable -> trackerService.removeTrackedResources(intentData.intent().key(), installable.resources()));
}
if (toInstall.isPresent()) {
IntentData intentData = toInstall.get();
trackerService.addTrackedResources(intentData.key(), intentData.intent().resources());
installIntents.forEach(installable -> trackerService.addTrackedResources(intentData.key(), installable.resources()));
}
// Generate domain Intent operations
DomainIntentOperations.Builder builder = DomainIntentOperations.builder();
DomainIntentOperationsContext domainOperationsContext;
uninstallIntents.forEach(builder::remove);
installIntents.forEach(builder::add);
domainOperationsContext = new DomainIntentOperationsContext() {
@Override
public void onSuccess(DomainIntentOperations idops) {
intentInstallCoordinator.intentInstallSuccess(context);
}
@Override
public void onError(DomainIntentOperations idos) {
intentInstallCoordinator.intentInstallFailed(context);
}
};
log.debug("submitting domain intent {} -> {}", toUninstall.map(x -> x.key().toString()).orElse("<empty>"), toInstall.map(x -> x.key().toString()).orElse("<empty>"));
// Submit domain Inten operations with domain context
domainIntentService.sumbit(builder.build(domainOperationsContext));
}
use of org.onosproject.net.intent.IntentData in project onos by opennetworkinglab.
the class PurgeRequest method shouldAcceptPurge.
private boolean shouldAcceptPurge() {
if (!stored.isPresent()) {
log.info("Purge for intent {}, but intent is not present", data.key());
return true;
}
IntentData storedData = stored.get();
if (storedData.state() == IntentState.WITHDRAWN || storedData.state() == IntentState.FAILED) {
return true;
}
log.info("Purge for intent {} is rejected because intent state is {}", data.key(), storedData.state());
return false;
}
Aggregations