Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -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 | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.mastership; |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 17 | |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame] | 18 | import java.util.concurrent.CompletableFuture; |
Jian Li | 25fc9ad | 2016-05-03 17:35:44 -0700 | [diff] [blame] | 19 | import java.util.concurrent.TimeUnit; |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame] | 20 | |
Jian Li | 25fc9ad | 2016-05-03 17:35:44 -0700 | [diff] [blame] | 21 | import org.onlab.util.Tools; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.cluster.NodeId; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.net.MastershipRole; |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Service for administering the inventory of device masterships. |
| 28 | */ |
| 29 | public interface MastershipAdminService { |
| 30 | |
Jian Li | 25fc9ad | 2016-05-03 17:35:44 -0700 | [diff] [blame] | 31 | long TIMEOUT_MILLIS = 3000; |
| 32 | |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Applies the current mastership role for the specified device. |
| 35 | * |
| 36 | * @param instance controller instance identifier |
| 37 | * @param deviceId device identifier |
| 38 | * @param role requested role |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame] | 39 | * @return future that is completed when the role is set |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 40 | */ |
Madan Jampani | de003d9 | 2015-05-11 17:14:20 -0700 | [diff] [blame] | 41 | CompletableFuture<Void> setRole(NodeId instance, DeviceId deviceId, MastershipRole role); |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 42 | |
Thomas Vachuska | 1e68bdd | 2014-11-29 13:53:10 -0800 | [diff] [blame] | 43 | /** |
Jian Li | 25fc9ad | 2016-05-03 17:35:44 -0700 | [diff] [blame] | 44 | * Synchronous version of setRole. |
| 45 | * Applies the current mastership role for the specified device. |
| 46 | * |
| 47 | * @param instance controller instance identifier |
| 48 | * @param deviceId device identifier |
| 49 | * @param role requested role |
| 50 | */ |
| 51 | default void setRoleSync(NodeId instance, DeviceId deviceId, MastershipRole role) { |
| 52 | Tools.futureGetOrElse(setRole(instance, deviceId, role), TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null); |
| 53 | } |
| 54 | |
| 55 | /** |
Thomas Vachuska | 1e68bdd | 2014-11-29 13:53:10 -0800 | [diff] [blame] | 56 | * Balances the mastership to be shared as evenly as possibly by all |
| 57 | * online instances. |
| 58 | */ |
| 59 | void balanceRoles(); |
| 60 | |
pierventre | e915bd3 | 2021-05-06 09:27:00 +0200 | [diff] [blame] | 61 | /** |
| 62 | * Attempts to demote a node to the bottom of the backup list. It is not allowed |
| 63 | * to demote the current master |
| 64 | * |
| 65 | * @param instance controller instance identifier |
| 66 | * @param deviceId device identifier |
| 67 | */ |
| 68 | void demote(NodeId instance, DeviceId deviceId); |
| 69 | |
Ayaka Koshibe | 8d504a9 | 2014-09-22 17:07:36 -0700 | [diff] [blame] | 70 | } |