Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.grpc.api; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | |
| 22 | /** |
Yi Tseng | d771648 | 2018-10-31 15:34:30 -0700 | [diff] [blame] | 23 | * Abstraction of a gRPC controller which controls specific gRPC client {@link |
| 24 | * C} with specific client key {@link K}. |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 25 | * |
| 26 | * @param <K> the gRPC client key |
| 27 | * @param <C> the gRPC client type |
| 28 | */ |
| 29 | @Beta |
| 30 | public interface GrpcClientController<K extends GrpcClientKey, C extends GrpcClient> { |
| 31 | |
| 32 | /** |
Yi Tseng | d771648 | 2018-10-31 15:34:30 -0700 | [diff] [blame] | 33 | * Instantiates a new client to operate on a gRPC server identified by the |
| 34 | * given information. As a result of this method, a client can be later |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 35 | * obtained by invoking {@link #getClient(DeviceId)}. |
Yi Tseng | d771648 | 2018-10-31 15:34:30 -0700 | [diff] [blame] | 36 | * <p> |
| 37 | * Only one client can exist for the same device ID. Calls to this method |
| 38 | * are idempotent fot the same client key, i.e. returns true if such client |
| 39 | * already exists but a new one is not created. If there exists a client |
| 40 | * with same device ID but different address and port, removes old one and |
| 41 | * recreate new one. |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 42 | * |
| 43 | * @param clientKey the client key |
Yi Tseng | d771648 | 2018-10-31 15:34:30 -0700 | [diff] [blame] | 44 | * @return true if the client was created and the channel to the server is |
| 45 | * open; false otherwise |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 46 | */ |
| 47 | boolean createClient(K clientKey); |
| 48 | |
| 49 | /** |
| 50 | * Retrieves the gRPC client to operate on the given device. |
| 51 | * |
| 52 | * @param deviceId the device identifier |
| 53 | * @return the gRPC client of the device if exists; null otherwise |
| 54 | */ |
| 55 | C getClient(DeviceId deviceId); |
| 56 | |
| 57 | /** |
Yi Tseng | d771648 | 2018-10-31 15:34:30 -0700 | [diff] [blame] | 58 | * Removes the gRPC client for the given device. If no client exists for the |
| 59 | * given device, the result is a no-op. |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 60 | * |
| 61 | * @param deviceId the device identifier |
| 62 | */ |
| 63 | void removeClient(DeviceId deviceId); |
| 64 | |
| 65 | /** |
| 66 | * Check reachability of the gRPC server running on the given device. |
Yi Tseng | d771648 | 2018-10-31 15:34:30 -0700 | [diff] [blame] | 67 | * Reachability can be tested only if a client is previously created using |
| 68 | * {@link #createClient(GrpcClientKey)}. Note that this only checks the |
| 69 | * reachability instead of checking service availability, different |
| 70 | * service-specific gRPC clients might check service availability in a |
Yi Tseng | 5f7fef5 | 2018-11-05 11:30:47 -0800 | [diff] [blame] | 71 | * different way. |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 72 | * |
| 73 | * @param deviceId the device identifier |
Yi Tseng | d771648 | 2018-10-31 15:34:30 -0700 | [diff] [blame] | 74 | * @return true if client was created and is able to contact the gNMI |
| 75 | * server; false otherwise |
Yi Tseng | 2a340f7 | 2018-11-02 16:52:47 -0700 | [diff] [blame] | 76 | */ |
| 77 | boolean isReachable(DeviceId deviceId); |
| 78 | } |