blob: 8e0679bb0a7db98a64d0edbe70e91fa3440094ee [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2014-present Open Networking Foundation
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.mastership;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070017
Madan Jampanide003d92015-05-11 17:14:20 -070018import java.util.concurrent.CompletableFuture;
Jian Li25fc9ad2016-05-03 17:35:44 -070019import java.util.concurrent.TimeUnit;
Madan Jampanide003d92015-05-11 17:14:20 -070020
Jian Li25fc9ad2016-05-03 17:35:44 -070021import org.onlab.util.Tools;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.cluster.NodeId;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.MastershipRole;
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070025
26/**
27 * Service for administering the inventory of device masterships.
28 */
29public interface MastershipAdminService {
30
Jian Li25fc9ad2016-05-03 17:35:44 -070031 long TIMEOUT_MILLIS = 3000;
32
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070033 /**
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 Jampanide003d92015-05-11 17:14:20 -070039 * @return future that is completed when the role is set
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070040 */
Madan Jampanide003d92015-05-11 17:14:20 -070041 CompletableFuture<Void> setRole(NodeId instance, DeviceId deviceId, MastershipRole role);
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070042
Thomas Vachuska1e68bdd2014-11-29 13:53:10 -080043 /**
Jian Li25fc9ad2016-05-03 17:35:44 -070044 * 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 Vachuska1e68bdd2014-11-29 13:53:10 -080056 * Balances the mastership to be shared as evenly as possibly by all
57 * online instances.
58 */
59 void balanceRoles();
60
Ayaka Koshibe8d504a92014-09-22 17:07:36 -070061}