Search in sources :

Example 6 with IntentEvent

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);
}
Also used : IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) Intent(org.onosproject.net.intent.Intent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) IntentEvent(org.onosproject.net.intent.IntentEvent) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 7 with IntentEvent

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);
    }
}
Also used : IntentListener(org.onosproject.net.intent.IntentListener) CountDownLatch(java.util.concurrent.CountDownLatch) Key(org.onosproject.net.intent.Key) IntentEvent(org.onosproject.net.intent.IntentEvent)

Example 8 with IntentEvent

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;
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IntentEvent(org.onosproject.net.intent.IntentEvent)

Example 9 with IntentEvent

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);
    }
}
Also used : IntentListener(org.onosproject.net.intent.IntentListener) CountDownLatch(java.util.concurrent.CountDownLatch) Key(org.onosproject.net.intent.Key) IntentEvent(org.onosproject.net.intent.IntentEvent)

Example 10 with IntentEvent

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());
}
Also used : IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) IntentData(org.onosproject.net.intent.IntentData) Intent(org.onosproject.net.intent.Intent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) SystemClockTimestamp(org.onosproject.store.trivial.SystemClockTimestamp) Timestamp(org.onosproject.store.Timestamp) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) IntentEvent(org.onosproject.net.intent.IntentEvent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Aggregations

IntentEvent (org.onosproject.net.intent.IntentEvent)17 Test (org.junit.Test)12 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)12 Intent (org.onosproject.net.intent.Intent)12 IntentData (org.onosproject.net.intent.IntentData)12 IntentStoreDelegate (org.onosproject.net.intent.IntentStoreDelegate)12 MockIntent (org.onosproject.net.intent.IntentTestsMocks.MockIntent)12 Timestamp (org.onosproject.store.Timestamp)8 SystemClockTimestamp (org.onosproject.store.trivial.SystemClockTimestamp)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Ignore (org.junit.Ignore)2 IntentListener (org.onosproject.net.intent.IntentListener)2 Key (org.onosproject.net.intent.Key)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MoreObjects (com.google.common.base.MoreObjects)1 ImmutableList (com.google.common.collect.ImmutableList)1