use of org.onosproject.net.intent.IntentEvent 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.IntentEvent in project onos by opennetworkinglab.
the class IntentRemoveCommand method removeIntent.
/**
* Removes the intent passed as argument.
*
* @param intentService IntentService object
* @param intent intent to remove
*/
private void removeIntent(IntentService intentService, Intent intent) {
IntentListener listener = null;
Key key = intent.key();
final CountDownLatch withdrawLatch, purgeLatch;
if (purgeAfterRemove || sync) {
// set up latch and listener to track uninstall progress
withdrawLatch = new CountDownLatch(1);
purgeLatch = purgeAfterRemove ? new CountDownLatch(1) : null;
listener = (IntentEvent event) -> {
if (Objects.equals(event.subject().key(), key)) {
if (event.type() == IntentEvent.Type.WITHDRAWN || event.type() == IntentEvent.Type.FAILED) {
withdrawLatch.countDown();
} else if (purgeLatch != null && purgeAfterRemove && event.type() == IntentEvent.Type.PURGED) {
purgeLatch.countDown();
}
}
};
intentService.addListener(listener);
} else {
purgeLatch = null;
withdrawLatch = null;
}
// request the withdraw
intentService.withdraw(intent);
if (withdrawLatch != null && (purgeAfterRemove || sync)) {
try {
// wait for withdraw event
withdrawLatch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
print("Timed out waiting for intent {} withdraw", key);
}
if (purgeLatch != null && purgeAfterRemove && CAN_PURGE.contains(intentService.getIntentState(key))) {
intentService.purge(intent);
if (sync) {
/* TODO
Technically, the event comes before map.remove() is called.
If we depend on sync and purge working together, we will
need to address this.
*/
try {
purgeLatch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
print("Timed out waiting for intent {} purge", key);
}
}
}
}
if (listener != null) {
// clean up the listener
intentService.removeListener(listener);
}
}
use of org.onosproject.net.intent.IntentEvent in project onos by opennetworkinglab.
the class IntentEventsListCommand method json.
/**
* Produces a JSON array of intent events.
*
* @param intentEvents the intent events with the data
* @return JSON array with the intent events
*/
private JsonNode json(List<IntentEvent> intentEvents) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (IntentEvent event : intentEvents) {
result.add(json(mapper, event));
}
return result;
}
use of org.onosproject.net.intent.IntentEvent in project onos by opennetworkinglab.
the class VirtualNetworkIntentRemoveCommand method removeIntent.
/**
* Removes the intent using the specified intentService.
*
* @param intentService intent service
* @param intent intent
*/
private void removeIntent(IntentService intentService, Intent intent) {
IntentListener listener = null;
Key key = intent.key();
final CountDownLatch withdrawLatch, purgeLatch;
if (purgeAfterRemove || sync) {
// set up latch and listener to track uninstall progress
withdrawLatch = new CountDownLatch(1);
purgeLatch = purgeAfterRemove ? new CountDownLatch(1) : null;
listener = (IntentEvent event) -> {
if (Objects.equals(event.subject().key(), key)) {
if (event.type() == IntentEvent.Type.WITHDRAWN || event.type() == IntentEvent.Type.FAILED) {
withdrawLatch.countDown();
} else if (purgeLatch != null && purgeAfterRemove && event.type() == IntentEvent.Type.PURGED) {
purgeLatch.countDown();
}
}
};
intentService.addListener(listener);
} else {
purgeLatch = null;
withdrawLatch = null;
}
// request the withdraw
intentService.withdraw(intent);
if ((purgeAfterRemove || sync) && purgeLatch != null) {
try {
// wait for withdraw event
withdrawLatch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
print("Timed out waiting for intent {} withdraw", key);
}
if (purgeAfterRemove && CAN_PURGE.contains(intentService.getIntentState(key))) {
intentService.purge(intent);
if (sync) {
/* TODO
Technically, the event comes before map.remove() is called.
If we depend on sync and purge working together, we will
need to address this.
*/
try {
purgeLatch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
print("Timed out waiting for intent {} purge", key);
}
}
}
}
if (listener != null) {
// clean up the listener
intentService.removeListener(listener);
}
}
use of org.onosproject.net.intent.IntentEvent in project onos by opennetworkinglab.
the class IntentCleanupTest method skipPoll.
/**
* Only submit one of two intents because one is too new.
*/
@Test
public void skipPoll() {
IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {
@Override
public void process(IntentData intentData) {
intentData.setState(CORRUPT);
store.write(intentData);
}
@Override
public void notify(IntentEvent event) {
}
};
store.setDelegate(mockDelegate);
Intent intent = new MockIntent(1L);
IntentData data = new IntentData(intent, INSTALL_REQ, null);
store.addPending(data);
Intent intent2 = new MockIntent(2L);
Timestamp version = new SystemClockTimestamp(1L);
data = new IntentData(intent2, INSTALL_REQ, version);
store.addPending(data);
cleanup.run();
assertEquals("Expect number of submits incorrect", 1, service.submitCounter());
}
Aggregations