blob: 2e3ea5d0fdbffebf5ca8cf21dea0e22ed2608adf [file] [log] [blame]
Yi Tseng2a340f72018-11-02 16:52:47 -07001/*
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
17package org.onosproject.grpc.api;
18
19import com.google.common.annotations.Beta;
20import org.onosproject.net.DeviceId;
21
22/**
23 * Abstraction of a gRPC controller which controls specific gRPC
24 * client {@link C} with specific client key {@link K}.
25 *
26 * @param <K> the gRPC client key
27 * @param <C> the gRPC client type
28 */
29@Beta
30public interface GrpcClientController<K extends GrpcClientKey, C extends GrpcClient> {
31
32 /**
33 * Instantiates a new client to operate on a gRPC server identified by
34 * the given information. As a result of this method, a client can be later
35 * obtained by invoking {@link #getClient(DeviceId)}.
36 *
37 * Only one client can exist for the same device ID. Calls to this method are
38 * idempotent fot the same client key, i.e. returns true
39 * if such client already exists but a new one is not created.
40 * If there exists a client with same device ID but different address and port,
41 * removes old one and recreate new one.
42 *
43 * @param clientKey the client key
44 * @return true if the client was created and the channel to the server is open;
45 * false otherwise
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 /**
58 * Removes the gRPC client for the given device. If no client
59 * exists for the given device, the result is a no-op.
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.
67 * Reachability can be tested only if a client is previously created
68 * using {@link #createClient(GrpcClientKey)}.
Yi Tseng5f7fef52018-11-05 11:30:47 -080069 * Note that this only checks the reachability instead of checking service
70 * availability, different gRPC client checks service availability with
71 * different way.
Yi Tseng2a340f72018-11-02 16:52:47 -070072 *
73 * @param deviceId the device identifier
Yi Tseng5f7fef52018-11-05 11:30:47 -080074 * @return true if client was created and is able to contact the gNMI server;
Yi Tseng2a340f72018-11-02 16:52:47 -070075 * false otherwise
76 */
77 boolean isReachable(DeviceId deviceId);
78}