コード例 #1
0
    def __init__(self, queue_id, tas_request):
        self.__script_id = queue_id
        self.__tas_info = tas_request

        self.__play_id = None
        self.__collect_id = None
        self.__forward_group_id = None

        self.__task_id = task_context.__generate_task_id()

        self.__cursor = 0
        self.__variables = {}

        block = script.load(queue_id)
        self.__actions = block.get_commands()
        self.__triggers = block.get_triggers()
        self.__functions = block.get_functions()

        self.__last_input_message = None

        if len(self.__actions) == 0:
            logging.warning(
                "Script-file (script id: '%s') does not have any actions for TAS.",
                queue_id)

        logging.debug(
            "Q Service context is generated (task id: '%s', script id: '%s').",
            self.__task_id, self.__script_id)
        logging.debug(
            "Q Service script '%s' info (commands: '%d', triggers: '%d', functions: '%d').",
            self.__script_id, len(self.__actions), len(self.__triggers),
            len(self.__functions))
コード例 #2
0
    def __new__(cls, queue_id, tas_request, manager):
        if script.exist(queue_id) is False:
            logging.warning("Script-file (queue id: '%s') is not found - reject to create session.", queue_id)
            return None

        instance = object.__new__(cls)
        return instance
コード例 #3
0
    def __init__(self, expression, session_context):
        if (expression is None) or (len(expression) == 0):
            logging.warning(
                "Code expression is empty - impossible to analyse it.")

        self.__expression = expression
        self.__context = session_context
コード例 #4
0
    def __change_tas_link(self, tas_link_original, tas_link_pattern):
        change_tas_link = None
        
        action_link_type = None
        account_id, tas_session_id, party_id, action_id = None, None, None, None

        reg_object = re.match("/telephony/v1/account/(\S+)/sessions/(\S+)/parties/(\S+)/(collect|play)(.*)", tas_link_pattern)
        if reg_object:
            if reg_object.group(1) != "$(accountId)":
                account_id = reg_object.group(1)
            
            if reg_object.group(2) != "$(sessionId)":
                tas_session_id = reg_object.group(2)
            
            if reg_object.group(3) != "$(partyId)":
                party_id = reg_object.group(3)
        
            if reg_object.group(5) != "":
                action_link = reg_object.group(4) + reg_object.group(5)
                reg_object = re.match("(\S+)/(\S+)", action_link)
                if reg_object:
                    action_link_type = reg_object.group(1)
                    action_id = reg_object.group(2)
                
                else:
                    action_link_type = None
        else:
            logging.warning("TAS link pattern format '%s' is differ from expected - ignore processing variables.", tas_link_pattern)
            return change_tas_link
        
        reg_object = re.match("/telephony/v1/account/(\d+)/sessions/(\S+)/parties/(\d+)/(.*)", tas_link_original)
        if reg_object:
            if account_id is None:
                account_id = reg_object.group(1)
            
            if tas_session_id is None:
                tas_session_id = reg_object.group(2)
            
            if party_id is None:
                party_id = reg_object.group(3)
            
            change_tas_link = "/telephony/v1/account/" + account_id + "/sessions/" + tas_session_id + "/parties/" + party_id + "/"
            if action_link_type is None:
                change_tas_link += reg_object.group(4)
            
            else:
                reg_object = re.match("(\S+)/(\S+)", reg_object.group(4))
                if reg_object:
                    change_tas_link += reg_object.group(1) + "/"
                    if action_id is None:
                        change_tas_link += reg_object.group(2)
                    else:
                        change_tas_link += action_id
        
        else:
            logging.warning("Impossible to change specified TAS link obtained in StartTask due to format contradiction.")
        
        return change_tas_link
コード例 #5
0
    def __process_wait_command(self, expected_message):
        logging.debug("(QSim Service task '%s') wait for TAS message ('%s')...", self.__context.get_id(), expected_message)
        
        while self.__active is True:
            response = ""
            
            with self.__tas_message_condition:
                while len(self.__tas_messages) == 0 and self.__active is True:
                    self.__tas_message_condition.wait()

                if len(self.__tas_messages) > 0:
                    response = self.__tas_messages.pop()
            
            if response != expected_message:
                logging.warning("(QSim Service task '%s') unexpected message is received from TAS: '%s' (but expected: '%s'), continue to wait.",
                                self.__context.get_id(), response, expected_message)
                continue
            
            else:
                logging.debug("(QSim Service task '%s') expected response is received '%s', stop waiting process.", self.__context.get_id(), response)
                break
コード例 #6
0
    def __process_send_command(self, action, tas_content, headers, arguments):
        logging.debug("(QSim Service task '%s') command SEND is executing...", self.__context.get_id())
        
        if action == "PLAY":
            tas_link = self.__context.get_tas_link_start_play()
            tas_method = "POST"
        
        elif action == "STOP_PLAY":
            tas_link = self.__context.get_tas_link_stop_play()
            tas_method = "DELETE"

        elif action == "GET_PLAY":
            tas_link = self.__context.get_tas_link_stop_play()
            tas_method = "GET"

        elif action == "COLLECT":
            tas_link = self.__context.get_tas_link_start_collect()
            tas_method = "POST"

        elif action == "GET_COLLECT":
            tas_link = self.__context.get_tas_link_get_collect()
            tas_method = "GET"

        elif action == "STOP_COLLECT":
            tas_link = self.__context.get_tas_link_stop_collect()
            tas_method = "DELETE"

        elif action == "FORWARD":
            party_id = None
            if len(arguments) > 0:
                expression = arguments[0]
                analyser = expression_analyser(expression, self.__context)
                party_id = analyser.evaluate()
                arguments = []

            tas_link = self.__context.get_tas_link_forward(party_id)
            tas_method = "POST"

        elif action == "FORWARD_GROUP":
            tas_link = self.__context.get_tas_link_add_forward_group()
            tas_method = "POST"

        elif action == "PATCH_FORWARD_GROUP":
            tas_link = self.__context.get_tas_link_forward_group()
            tas_method = "PATCH"

        elif action == "GET_FORWARD_GROUP":
            tas_link = self.__context.get_tas_link_forward_group()
            tas_method = "GET"

        elif action == "DELETE_FORWARD_GROUP":
            tas_link = self.__context.get_tas_link_forward_group()
            tas_method = "DELETE"

        elif action == "GET_SESSION":
            tas_link = self.__context.get_tas_link_session()
            tas_method = "GET"

        else:
            logging.error("Unknown send command '%s'.", action)
            return

        if len(arguments) > 0:
            tas_link_pattern = arguments[0]
            tas_link = self.__change_tas_link(tas_link, tas_link_pattern)
        
        tas_content = self.__translate_content(tas_content)
        
        logging.info("(QSim Service task '%s') send command request to TAS ('%s', '%s').", self.__context.get_id(), tas_method, action)


        custom_headers = {"rcaccountid": self.__context.get_rcaccount_id(),
                          "rcextensionid": self.__context.get_rcextension_id(),
                          "rcbrandid": self.__context.get_brand_id(),
                          "origin": "127.0.0.1:" + str(configuration.get_qsim_port())}

        # add new and overwrite existed default custom headers in line with scenario
        for key, value in headers.items():
            custom_headers[key.lower()] = value

        (status, json_response) = self.__send(tas_method, tas_link, tas_content, custom_headers)
        if json_response is not None:
            self.__context.set_last_input_message(json_response)

        if (status >= 200) and (status <= 299):
            if (tas_method == "POST") and (json_response is not None) and (len(json_response) > 0):
                response = json.loads(json_response.decode('utf-8'))

                if action == "PLAY":
                    action_id = response['id']
                    self.__context.set_play_id(action_id)

                elif action == "COLLECT":
                    action_id = response['id']
                    self.__context.set_collect_id(action_id)

                elif action == "FORWARD_GROUP":
                    action_id = response['id']
                    self.__context.set_forward_group_id(action_id)

                else:
                    action_id = None

                logging.info("(QSim Service task '%s') TAS accepts '%s' command '%s' and return action id: '%s'.", self.__context.get_id(), tas_method, action, action_id)
            else:
                logging.vip("(QSim Service task '%s') TAS reply to '%s' command '%s' by success status (code: '%d').", self.__context.get_id(), tas_method, action, status)
        else:
            logging.warning("(QSim Service task '%s') TAS reply to '%s' command '%s' by failure status (code: '%d', reason: '%s').", self.__context.get_id(), tas_method, action, status, json_response)