Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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 | 66630c8 | 2014-10-02 21:08:19 -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.store.Store; |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 20 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 21 | import java.util.List; |
| 22 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Manages inventory of end-station intents; not intended for direct use. |
| 25 | */ |
Brian O'Connor | 9476fa1 | 2015-06-25 15:17:17 -0400 | [diff] [blame] | 26 | @Beta |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 27 | public interface IntentStore extends Store<IntentEvent, IntentStoreDelegate> { |
| 28 | |
| 29 | /** |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 30 | * Returns the number of intents in the store. |
Toshio Koide | d32809b | 2014-10-09 10:58:54 -0700 | [diff] [blame] | 31 | * |
| 32 | * @return the number of intents in the store |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 33 | */ |
| 34 | long getIntentCount(); |
| 35 | |
| 36 | /** |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 37 | * Returns an iterable of all intents in the store. |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 38 | * |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 39 | * @return iterable of all intents |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 40 | */ |
| 41 | Iterable<Intent> getIntents(); |
| 42 | |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 43 | |
| 44 | /** |
| 45 | * Returns an iterable of all intent data objects in the store. |
| 46 | * |
| 47 | * @param localOnly should only intents for which this instance is master |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 48 | * be returned |
| 49 | * @param olderThan specified duration in milliseconds (0 for "now") |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 50 | * @return iterable of all intent data objects |
| 51 | */ |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 52 | Iterable<IntentData> getIntentData(boolean localOnly, long olderThan); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 53 | |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 54 | /** |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 55 | * Returns the state of the specified intent. |
| 56 | * |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 57 | * @param intentKey intent identification |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 58 | * @return current intent state |
| 59 | */ |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 60 | IntentState getIntentState(Key intentKey); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 63 | * Returns the list of the installable events associated with the specified |
| 64 | * original intent. |
| 65 | * |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 66 | * @param intentKey original intent identifier |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 67 | * @return compiled installable intents, or null if no installables exist |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 68 | */ |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 69 | List<Intent> getInstallableIntents(Key intentKey); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 70 | |
tom | a1d16b6 | 2014-10-02 23:45:11 -0700 | [diff] [blame] | 71 | /** |
Jonathan Hart | 2085e07 | 2015-02-12 11:44:03 -0800 | [diff] [blame] | 72 | * Writes an IntentData object to the store. |
Yuta HIGUCHI | a94c6e8 | 2014-11-28 18:49:54 -0800 | [diff] [blame] | 73 | * |
Jonathan Hart | 2085e07 | 2015-02-12 11:44:03 -0800 | [diff] [blame] | 74 | * @param newData new intent data to write |
Yuta HIGUCHI | a94c6e8 | 2014-11-28 18:49:54 -0800 | [diff] [blame] | 75 | */ |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 76 | void write(IntentData newData); |
Jonathan Hart | 2085e07 | 2015-02-12 11:44:03 -0800 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Writes a batch of IntentData objects to the store. A batch has no |
| 80 | * semantics, this is simply a convenience API. |
| 81 | * |
| 82 | * @param updates collection of intent data objects to write |
| 83 | */ |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 84 | void batchWrite(Iterable<IntentData> updates); |
Yuta HIGUCHI | a94c6e8 | 2014-11-28 18:49:54 -0800 | [diff] [blame] | 85 | |
Brian O'Connor | ea4d7d1 | 2015-01-28 16:37:46 -0800 | [diff] [blame] | 86 | /** |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 87 | * Returns the intent with the specified identifier. |
| 88 | * |
| 89 | * @param key key |
| 90 | * @return intent or null if not found |
| 91 | */ |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 92 | Intent getIntent(Key key); |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Returns the intent data object associated with the specified key. |
| 96 | * |
| 97 | * @param key key to look up |
| 98 | * @return intent data object |
| 99 | */ |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 100 | IntentData getIntentData(Key key); |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 101 | |
| 102 | /** |
Brian O'Connor | ea4d7d1 | 2015-01-28 16:37:46 -0800 | [diff] [blame] | 103 | * Adds a new operation, which should be persisted and delegated. |
| 104 | * |
Brian O'Connor | cff0332 | 2015-02-03 15:28:59 -0800 | [diff] [blame] | 105 | * @param intent operation |
Brian O'Connor | ea4d7d1 | 2015-01-28 16:37:46 -0800 | [diff] [blame] | 106 | */ |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 107 | void addPending(IntentData intent); |
Brian O'Connor | ea4d7d1 | 2015-01-28 16:37:46 -0800 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * Checks to see whether the calling instance is the master for processing |
| 111 | * this intent, or more specifically, the key contained in this intent. |
| 112 | * |
Brian O'Connor | be28a87 | 2015-02-19 21:44:37 -0800 | [diff] [blame] | 113 | * @param intentKey intentKey to check |
Brian O'Connor | ea4d7d1 | 2015-01-28 16:37:46 -0800 | [diff] [blame] | 114 | * @return true if master; false, otherwise |
| 115 | */ |
| 116 | //TODO better name |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 117 | boolean isMaster(Key intentKey); |
Jonathan Hart | 34f1e38 | 2015-02-24 16:52:23 -0800 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * Returns the intent requests pending processing. |
| 121 | * |
| 122 | * @return pending intents |
| 123 | */ |
Jonathan Hart | 6a8fd1d | 2015-02-25 15:44:37 -0800 | [diff] [blame] | 124 | Iterable<Intent> getPending(); |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * Returns the intent data objects that are pending processing. |
| 128 | * |
| 129 | * @return pending intent data objects |
| 130 | */ |
| 131 | Iterable<IntentData> getPendingData(); |
| 132 | |
| 133 | /** |
Brian O'Connor | c590ebb | 2016-12-08 18:16:41 -0800 | [diff] [blame] | 134 | * Returns the intent data object that are pending processing for a specfied |
| 135 | * key. |
| 136 | * |
| 137 | * @param intentKey key to look up |
| 138 | * @return pending intent data object |
| 139 | */ |
| 140 | IntentData getPendingData(Key intentKey); |
| 141 | |
| 142 | /** |
Brian O'Connor | a6c9b5c | 2015-04-29 22:38:29 -0700 | [diff] [blame] | 143 | * Returns the intent data objects that are pending processing for longer |
| 144 | * than the specified duration. |
| 145 | * |
| 146 | * @param localOnly should only intents for which this instance is master |
| 147 | * be returned |
| 148 | * @param olderThan specified duration in milliseconds (0 for "now") |
| 149 | * @return pending intent data objects |
| 150 | */ |
| 151 | Iterable<IntentData> getPendingData(boolean localOnly, long olderThan); |
Brian O'Connor | 66630c8 | 2014-10-02 21:08:19 -0700 | [diff] [blame] | 152 | } |