Ejemplo n.º 1
0
    def post(self, nsInstanceId):

        # 1. [WEB->RESTIF] RECEIVE PROCESS
        try:
            content = request.get_json(force=True)
            data = json.dumps(content)
        except Exception as e:
            data = ''

        # 2. [WEB->RESTIF] RECEIVE LOGGING
        ServiceManager.RecvLogging(self.logger, data, request)

        # 3. [RESTIF->APP] MAKE SEND STRUCT
        header = HttpHeader()
        header.method = ServiceManager.getMethodType(request.method)
        header.api_type = ApiType.NSLCM_API_TYPE
        header.resource_type = ResourceType.NSLCM_INSTANTIATE_NS_TASK
        header.op_type = OPType.Instantiate_NS_OP_TYPE
        header.encoding = ContentEncoding.PLAIN

        Info = ServiceManager.getHttpInfo(nsInstanceId)

        self.clientId = PLTEManager.getInstance().getClientReqId()
        reqMsg = ServiceManager.setApiToStructMsg(request, data, self.clientId,
                                                  header, Info)
        #reqMsg.info.ns_instance_id = nsInstanceId

        # 4. [RESTIF->APP] SEND QUEUE MESSAGE(RELAY)
        PLTEManager.getInstance().sendCommand(ApiDefine.NS_INSTANTIATION, self,
                                              reqMsg)

        # 5. WAIT
        self.receiveReqId = -1
        while self.clientId != self.receiveReqId:
            try:
                time.sleep(1)
            except Exception as e:
                self.logger.error(e)

        # 6. [RESTIF->WEB] SEND LOGGING
        ServiceManager.SendLogging(self.logger, self.resMsg)

        # 7. [RESTIF->WEB] SEND RESPONSE
        return flask.Response(
            self.resMsg.jsonBody,
            # mimetype=content_type,
            status=self.rspCode)
Ejemplo n.º 2
0
    def sendMessage(self, apiName, reqId, receiveMsg):

        httpMsg = HttpReq()
        header = HttpHeader()

        header.method = 1
        header.api_type = 2
        header.op_type = 3
        header.length = 4
        header.encoding = '5'

        httpMsg.tot_len = 100
        httpMsg.msgId = reqId
        httpMsg.ehttpf_idx = 71
        httpMsg.srcQid = 300
        httpMsg.srcSysId = '1'
        httpMsg.http_hdr = header
        httpMsg.jsonBody = receiveMsg

        pData = ctypes.cast(
            ctypes.byref(httpMsg),
            ctypes.POINTER(ctypes.c_char * ctypes.sizeof(httpMsg)))

        try:
            if self.plteQueue is not None:
                self.plteQueue.send(pData.contents.raw, True,
                                    HttpReq.MTYPE_RESTIF_TO_APP_REQ)

        except Exception as e:
            self.logger.error("sendMessage Error! %s" % e)
            return False

        if ConfManager.getInstance().getLogFlag():
            self.logger.info("===============================================")
            self.logger.info("RESTIF -> PLTEIB")
            self.logger.info("===============================================")
            self.logger.info("API_NAME : " + str(apiName))
            self.logger.info("PID   : " + str(reqId))
            self.logger.info("BODY   : " + str(receiveMsg))
            self.logger.info("===============================================")

        return True
Ejemplo n.º 3
0
    def setReqMessage(self, receiveMsg, reqId):

        httpMsg = HttpReq()
        header = HttpHeader()

        header.method = 1
        header.api_type = 2
        header.op_type = 3
        header.encoding = '5'
        header.length = 4

        httpMsg.tid = reqId
        httpMsg.msgId = 6
        httpMsg.ehttpf_idx = 71
        httpMsg.srcQid = 300
        httpMsg.srcSysId = '1'
        httpMsg.http_hdr = header
        httpMsg.jsonBody = receiveMsg

        httpMsg.tot_len = 100

        return httpMsg