Commit 117909b3 authored by Mohammad Ismaeel's avatar Mohammad Ismaeel
Browse files

tapi GUI

parent 7748a4d7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ spec:
    kind: Deployment
    name: tapiservice
  minReplicas: 1
  maxReplicas: 20
  maxReplicas: 1
  metrics:
    - type: Resource
      resource:
+1 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
export TFS_REGISTRY_IMAGES="http://localhost:32000/tfs/"

# Set the list of components, separated by spaces, you want to build images for, and deploy.
export TFS_COMPONENTS="context device pathcomp opticalcontroller service webui nbi"
export TFS_COMPONENTS="context device pathcomp opticalcontroller service tapi webui nbi "

# Uncomment to activate Monitoring (old)
#export TFS_COMPONENTS="${TFS_COMPONENTS} monitoring"
+11 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ service TapiService {
  rpc GetListTopologies     (context.Empty     ) returns (       context.TopologyList    ) {}
  rpc GetTopology        (context.TopologyId    ) returns (       context.Topology        ) {}
  rpc SetService         (context.ServiceList)    returns (context.Empty) {}
  rpc CheckConnectivity ( SocketID)                returns ( CheckStat) {}
}


@@ -29,3 +30,13 @@ message TapiRequest {
  context.ContextId context_id = 1 ;
  context.TopologyId topology_id = 2 ;
}

message SocketID {
  string host = 1; 
   int32 port = 2 ;
}

message CheckStat {
  int32 res = 1 ;
}
 
+36 −8
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import grpc, logging
import grpc, logging , socket
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.context_pb2 import (
@@ -20,7 +20,7 @@ from common.proto.context_pb2 import (
    TopologyList, Empty,
    Service, ServiceId,ServiceList
)
from common.proto.tapi_pb2 import TapiRequest
from common.proto.tapi_pb2 import TapiRequest , SocketID ,CheckStat

from common.proto.tapi_pb2_grpc import TapiServiceStub

@@ -34,20 +34,26 @@ RETRY_DECORATOR = retry(max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION,

class TapiClient:
    def __init__(self, host, port):
        host = self.host
        port = self.port
        self.host = host
        self.port = port
        self.endpoint = '{:s}:{:s}'.format(str(host), str(port))
        LOGGER.debug('Creating channel to {:s}...'.format(str(self.endpoint)))
        LOGGER.info('Creating channel to {:s}...'.format(str(self.endpoint)))
        self.channel = None
        self.stub = None
        self.openconfig_stub=None
        if self.internal_check() ==0 : raise ValueError(f" Unable to connect to  {self.endpoint}")
        self.connect()
        LOGGER.debug('Channel created')
        LOGGER.info('Channel created')

    def connect(self):
        
       
            self.channel = grpc.insecure_channel(self.endpoint)
            self.stub = TapiServiceStub(self.channel)
        
            
             
       
    def close(self):
        if self.channel is not None: self.channel.close()
        self.channel = None
@@ -76,5 +82,27 @@ class TapiClient:
        LOGGER.debug('GetTopology result: {:s}'.format(grpc_message_to_json_string(response)))
        return Empty()
    
    def internal_check (self) : 
        host = self.host
        port  = self.port 
        
        LOGGER.info(f" starting the socket test port {port } {host} ")
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM ) as sock:
            sock.settimeout(3)
            try:
                sock.connect((host, port))
           
                return 1
            except (socket.timeout, socket.error):
                return 0
    @RETRY_DECORATOR
    def CheckConnectivity(self) -> CheckStat :
        request =SocketID ( port = self.port , host = self.host)
        LOGGER.info('CheckConnectivity request: {:s}'.format(grpc_message_to_json_string(request)))
        response = self.stub.CheckConnectivity(request)
        LOGGER.info('CheckConnectivity result: {:s}'.format(grpc_message_to_json_string(response)))
        return response()
    


   
 No newline at end of file
+17 −3
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import grpc, logging, os, time
import grpc, logging, os, time , socket


from common.method_wrappers.Decorator import  MetricsPool, safe_and_metered_rpc_method
@@ -22,7 +22,7 @@ from common.proto.context_pb2 import (
   Service, ServiceId , ServiceList 
)

from common.proto.tapi_pb2 import TapiRequest
from common.proto.tapi_pb2 import TapiRequest , SocketID ,CheckStat
from common.proto.tapi_pb2_grpc import TapiService

from common.tools.mutex_queues.MutexQueues import MutexQueues
@@ -103,3 +103,17 @@ class TapiServiceServicerImpl(TapiService):
            
            LOGGER.info(f"Tapi setservice error  {e}")
        
    
    def CheckConnectivity (self,request:SocketID , context : grpc.ServicerContext)  -> CheckStat   :
        host = request.host
        port  = request.port 
        check_res = CheckStat(res=0)
        LOGGER.info(f" starting the socket test port {port } {host} ")
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM ) as sock:
            sock.settimeout(3)
            try:
                sock.connect((host, port))
                check_res.res = 1 
                return check_res
            except (socket.timeout, socket.error):
                return check_res
Loading