Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 20 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 21 | /** |
| 22 | * A class to represent an intent related event. |
| 23 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 24 | @Beta |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 25 | public class IntentEvent extends AbstractEvent<IntentEvent.Type, Intent> { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 26 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 27 | public enum Type { |
| 28 | /** |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 29 | * Signifies that an intent is to be installed or reinstalled. |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 30 | */ |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 31 | INSTALL_REQ, |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 32 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Signifies that an intent has been successfully installed. |
| 35 | */ |
| 36 | INSTALLED, |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 37 | |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 38 | /** |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 39 | * Signifies that an intent has failed compilation and that it cannot |
| 40 | * be satisfied by the network at this time. |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 41 | */ |
| 42 | FAILED, |
| 43 | |
| 44 | /** |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 45 | * Signifies that an intent will be withdrawn. |
| 46 | */ |
| 47 | WITHDRAW_REQ, |
| 48 | |
| 49 | /** |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 50 | * Signifies that an intent has been withdrawn from the system. |
| 51 | */ |
Ray Milkey | 8c6d00e | 2015-03-13 14:14:34 -0700 | [diff] [blame] | 52 | WITHDRAWN, |
| 53 | |
| 54 | /** |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 55 | * Signifies that an intent has failed installation or withdrawal, but |
| 56 | * still hold some or all of its resources. |
| 57 | * (e.g. link reservations, flow rules on the data plane, etc.) |
| 58 | */ |
| 59 | CORRUPT, |
| 60 | |
| 61 | /** |
Ray Milkey | 8c6d00e | 2015-03-13 14:14:34 -0700 | [diff] [blame] | 62 | * Signifies that an intent has been purged from the system. |
| 63 | */ |
| 64 | PURGED |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 68 | * Creates an event of a given type and for the specified intent and the |
| 69 | * current time. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 70 | * |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 71 | * @param type event type |
| 72 | * @param intent subject intent |
| 73 | * @param time time the event created in milliseconds since start of epoch |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 74 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 75 | public IntentEvent(Type type, Intent intent, long time) { |
| 76 | super(type, intent, time); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 80 | * Creates an event of a given type and for the specified intent and the |
| 81 | * current time. |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 82 | * |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 83 | * @param type event type |
| 84 | * @param intent subject intent |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 85 | */ |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 86 | public IntentEvent(Type type, Intent intent) { |
| 87 | super(type, intent); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Jonathan Hart | 9288836 | 2015-02-13 13:14:59 -0800 | [diff] [blame] | 90 | /** |
| 91 | * Creates an IntentEvent based on the state contained in the given intent |
| 92 | * data. Some states are not sent as external events, and these states will |
| 93 | * return null events. |
| 94 | * |
| 95 | * @param data the intent data to create an event for |
| 96 | * @return new intent event if the state is valid, otherwise null. |
| 97 | */ |
Brian O'Connor | 03406a4 | 2015-02-03 17:28:57 -0800 | [diff] [blame] | 98 | public static IntentEvent getEvent(IntentData data) { |
| 99 | return getEvent(data.state(), data.intent()); |
| 100 | } |
| 101 | |
Jonathan Hart | 9288836 | 2015-02-13 13:14:59 -0800 | [diff] [blame] | 102 | /** |
| 103 | * Creates an IntentEvent based on the given state and intent. Some states |
| 104 | * are not sent as external events, and these states will return null events. |
| 105 | * |
| 106 | * @param state new state of the intent |
| 107 | * @param intent intent to put in event |
| 108 | * @return new intent event if the state is valid, otherwise null. |
| 109 | */ |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 110 | public static IntentEvent getEvent(IntentState state, Intent intent) { |
| 111 | Type type; |
| 112 | switch (state) { |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 113 | case INSTALL_REQ: |
| 114 | type = Type.INSTALL_REQ; |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 115 | break; |
| 116 | case INSTALLED: |
| 117 | type = Type.INSTALLED; |
| 118 | break; |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 119 | case WITHDRAW_REQ: |
| 120 | type = Type.WITHDRAW_REQ; |
| 121 | break; |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 122 | case WITHDRAWN: |
| 123 | type = Type.WITHDRAWN; |
| 124 | break; |
| 125 | case FAILED: |
| 126 | type = Type.FAILED; |
| 127 | break; |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 128 | case CORRUPT: |
| 129 | type = Type.CORRUPT; |
| 130 | break; |
Ray Milkey | 8c6d00e | 2015-03-13 14:14:34 -0700 | [diff] [blame] | 131 | case PURGE_REQ: |
| 132 | type = Type.PURGED; |
| 133 | break; |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 134 | |
Jonathan Hart | 9288836 | 2015-02-13 13:14:59 -0800 | [diff] [blame] | 135 | // fallthrough to default from here |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 136 | case COMPILING: |
| 137 | case INSTALLING: |
| 138 | case RECOMPILING: |
| 139 | case WITHDRAWING: |
| 140 | default: |
Jonathan Hart | 9288836 | 2015-02-13 13:14:59 -0800 | [diff] [blame] | 141 | return null; |
alshabib | a9819bf | 2014-11-30 18:15:52 -0800 | [diff] [blame] | 142 | } |
| 143 | return new IntentEvent(type, intent); |
| 144 | } |
| 145 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 146 | } |