Commit 89d60b34 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Pre-merge code cleanup

parent d373581d
Loading
Loading
Loading
Loading
+2 −29
Original line number Diff line number Diff line
@@ -343,9 +343,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                    reply_txt = add_lightpath(src, dst, bitrate, bidir)
                else:
                    reply_txt = add_flex_lightpath(src, dst, bitrate, bidir, preferred, ob_band, dj_optical_band_id)
            #logging.info(f"TEEEEEEEEEEEEEEST {oc_type}")
            #logging.info(f"POLIMI {reply_txt}")
            if reply_txt == None:
            if reply_txt is None:
                return service_with_uuids.service_id
            reply_json = json.loads(reply_txt)
            LOGGER.debug('[optical] reply_json[{:s}]={:s}'.format(str(type(reply_json)), str(reply_json)))
@@ -596,11 +594,9 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
        updated_service_with_uuids = get_service_by_id(
            context_client, updated_service_id_with_uuids, rw_copy=True,
            include_config_rules=True, include_constraints=True, include_endpoint_ids=True)
        LOGGER.info('WYY:{}'.format(updated_service_with_uuids))

        # Get active connection
        connections = context_client.ListConnections(updated_service_id_with_uuids)
        LOGGER.info('WWWW:{}'.format(connections))
        if len(connections.connections) == 0:
            MSG = 'Service({:s}) has no connections'
            str_service_id = grpc_message_to_json_string(updated_service_id_with_uuids)
@@ -624,7 +620,6 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
            raise NotImplementedException('service-connection-with-subservices', extra_details=str_extra_details)
        
        if updated_service.service_type == ServiceTypeEnum.SERVICETYPE_OPTICAL_CONNECTIVITY:
            LOGGER.info('WWWW:{}'.format("is optical"))
            context_id_x = json_context_id(DEFAULT_CONTEXT_NAME)
            topology_id_x = json_topology_id(
                DEFAULT_TOPOLOGY_NAME, context_id_x)
@@ -632,8 +627,6 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                TopologyId(**topology_id_x))
        
            str_old_connection = connection_to_string(old_connection)
            LOGGER.info('WWW old_connection={}'.format(grpc_message_to_json_string(old_connection)))
            LOGGER.info('WWW0={}'.format(updated_service_with_uuids.service_config.config_rules))
            if len(updated_service_with_uuids.service_config.config_rules)> 0:
                #if len(updated_service.service_config.config_rules) > 0:
                c_rules_dict = json.loads(
@@ -641,7 +634,6 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                
                #c_rules_dict = json.loads(
                #    updated_service.service_config.config_rules[0].custom.resource_value)
                LOGGER.info('WWW1:{}'.format(c_rules_dict))
                flow_id=None
                #if "ob_id" in c_rules_dict:
                #    ob_id = c_rules_dict["ob_id"]
@@ -668,15 +660,12 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                        new_connection = optical_reply.connections[0]
                        #for candidate_new_connection in pathcomp_reply.connections:
                        str_candidate_new_connection = connection_to_string(new_connection)
                        LOGGER.info('QQQQ_old:{}'.format(str_old_connection))
                        LOGGER.info('QQQQ_new:{}'.format(str_candidate_new_connection))
                        # Change UUID of new connection to prevent collisions
                        tmp_connection = Connection()
                        tmp_connection.CopyFrom(new_connection)
                        tmp_connection.connection_id.connection_uuid.uuid = str(uuid.uuid4())
                        new_connection = tmp_connection
                        service_new = optical_reply.services[0]
                        LOGGER.info('QQQQ:{}'.format(service_new))
                        # Feed TaskScheduler with the service to update, the old connection to
                        # deconfigure and the new connection to configure. It will produce a
                        # schedule of tasks (an ordered list of tasks to be executed) to
@@ -689,7 +678,6 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                        tasks_scheduler.execute_all()
                else:
                    if ("ob_id" in c_rules_dict) and ("low-freq" in c_rules_dict):
                        LOGGER.info('PDP: it is an optical band')
                        ob_id = c_rules_dict["ob_id"]
                        band_txt = get_optical_band(ob_id)
                        optical_band = json.loads(band_txt)
@@ -697,14 +685,12 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                        optical_band = None
                        obs = context_client.GetOpticalBand()
                        for obz in obs:
                            LOGGER.info(f"PDP: {obz.opticalband_id}")
                            if obz.opticalband_id == ob_id:
                                optical_band = obz
                        if optical_band is not None:
                        '''
                        #optical_band = context_client.SelectOpticalBand(ob_id)
                        served_flows = optical_band.get('served_lightpaths')
                        LOGGER.info(f'PDP: served flows {served_flows}')
                        #context_id_x = json_context_id(DEFAULT_CONTEXT_NAME)
                        response = context_client.ListServices(ContextId(**json_context_id(DEFAULT_CONTEXT_NAME)))
                        #response = context_client.ListServices(context_id_x)
@@ -720,7 +706,7 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                                )
                                if ("flow_id" in c_rules_dict):
                                    flow_id = c_rules_dict["flow_id"]
                                    LOGGER.info(f"PDP checking {flow_id} and {served_flows}")
                                    LOGGER.info(f"Checking {flow_id} and {served_flows}")
                                    if flow_id in served_flows:
                                        ##########
                                        updated_service : Optional[Service] = get_service_by_id(
@@ -733,27 +719,17 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                                        updated_service_with_uuids = get_service_by_id(
                                            context_client, updated_service_id_with_uuids, rw_copy=True,
                                            include_config_rules=True, include_constraints=True, include_endpoint_ids=True)
                                        LOGGER.info('WYY:{}'.format(updated_service_with_uuids))

                                        # Get active connection
                                        connections = context_client.ListConnections(updated_service_id_with_uuids)
                                        LOGGER.info('WWWW:{}'.format(connections))
                                        old_connection = connections.connections[0]

                                        '''
                                        for service_idc in service_ids:
                                            service_d = context_client.GetService(service_idc)
                                            c_rules_dict = json.loads(
                                                    service_d.service_config.config_rules[0].custom.resource_value)
                                        '''
                                        LOGGER.info('PDP:{}'.format(c_rules_dict))
                                        flow_id = c_rules_dict["flow_id"]                  
                                        reply_txt = ""
                                        # to get the reply form the optical module
                                        #multi-granular
                                        reply_txt = reconfig_flex_lightpath(flow_id)
                                        reply_json = json.loads(reply_txt)
                                        LOGGER.info('[PDP] reply_json[{:s}]={:s}'.format(str(type(reply_json)), str(reply_json)))
                                        devices = topology_details.devices
                                        context_uuid_x = topology_details.topology_id.context_id.context_uuid.uuid
                                        topology_uuid_x = topology_details.topology_id.topology_uuid.uuid
@@ -768,15 +744,12 @@ class ServiceServiceServicerImpl(ServiceServiceServicer):
                                            new_connection = optical_reply.connections[0]
                                            #for candidate_new_connection in pathcomp_reply.connections:
                                            str_candidate_new_connection = connection_to_string(new_connection)
                                            LOGGER.info('QQQQ_old:{}'.format(str_old_connection))
                                            LOGGER.info('QQQQ_new:{}'.format(str_candidate_new_connection))
                                            # Change UUID of new connection to prevent collisions
                                            tmp_connection = Connection()
                                            tmp_connection.CopyFrom(new_connection)
                                            tmp_connection.connection_id.connection_uuid.uuid = str(uuid.uuid4())
                                            new_connection = tmp_connection
                                            service_new = optical_reply.services[0]
                                            LOGGER.info('QQQQ:{}'.format(service_new))
                                            
                                    
                                            # Feed TaskScheduler with the service to update, the old connection to