/** * Recieve the CORE async responses */ public function postAction() { \App::log()->debug("CORE notification of response of a async operation."); $message = new Request(); if (!$this->_request->isPost()) { throw new \Application\Exceptions\UnexpectedException("Post request expected"); } // Parse the first level of proto buffer $message->parse($this->getRequest()->getRawBody()); // Verify the transactionId if (!$message->hasToken()) { throw new \Application\Exceptions\InvalidArgumentException("Missing transactionId."); } // Verify the proto if (!$message->hasProto()) { throw new \Application\Exceptions\InvalidArgumentException("Missing proto type."); } $event = new EventModel(); $event->namespace = 'connectivity'; $event->entityType = 'transaction'; $event->entityId = $message->getToken(); $event->created = time(); $event->pushEventData = true; $protoType = $message->getProto(); $event->hiddenData = array('protoType' => $protoType); \App::log()->info('Start CORE notification of response of type ' . $protoType . ' from the async operation ' . $event->entityId ?: 'empty'); // Message decode $internalMessage = $this->_decodeMessage($protoType, $message->getMessage()); // Obtaining a PHP Array from proto $parser = new \DrSlump\Protobuf\Codec\PhpArray(); $data = $message->serialize($parser); $messageData = $internalMessage->serialize($parser); \App::log()->debug("Async message: " . Zend_Json::encode($messageData)); \App_Util_Array::filterKeyNames(new \App_Filter_UnderscoreToCamelCase(), $messageData); \App::log()->debug("Async message (filtered): " . Zend_Json::encode($messageData)); if (isset($data['proto'])) { unset($data['proto']); } if (isset($data['token'])) { unset($data['token']); } if (isset($messageData['result'])) { $data['result'] = $messageData['result']; unset($messageData['result']); } if (!empty($messageData['failed']) || @$data['result']['code'] != 0) { $data['hasFailures'] = true; } else { $data['hasFailures'] = false; } \App::log()->debug("Async message (after all): " . Zend_Json::encode($messageData)); $data['message'] = $messageData; $retries = 0; // Map data switch (true) { case $internalMessage instanceof AsyncNotification\Service\BusinessRuleResponse: $event->entityType = 'businessRule'; $event->pushEventData = false; $arMapper = \Application\Model\Mapper\AlarmRuleMapper::getInstance(); // Map alarm rule condition $value =& $data['message']['alarmRuleCondition']; $value = $arMapper->mapConditionFromEricsson($value); // Map business rule type $value =& $data['message']['businessRule']['businessRuleType']; $value = $arMapper->mapBusinessRuleTypeToModel($value); // Map life cycle state (optional) if (isset($data['message']['businessRule']['nextLifecycleState'])) { $value =& $data['message']['businessRule']['nextLifecycleState']; $lcMapper = \Application\Model\Mapper\LifeCycleMapper::getInstance(); $value = $lcMapper->mapLifeCycleStatusFromEricsson($value); } //Workaround: organization must include orgType if (isset($data['message']['organizationId'])) { $data['organizationId'] = OrgCustomerMapper::buildOrgId($data['message']['organizationId']); } break; case $internalMessage instanceof \Application\Proto\SupDiagnosisAsync\DiagnosisNotification: $event->entityType = 'diagnosis'; $retries = \App::config('watcher.event_retries.diagnosis', 10); break; case $internalMessage instanceof AsyncNotification\Service\ReportResponse: $event->entityType = 'report'; break; case $internalMessage instanceof AsyncNotification\Service\TariffSwitchResponse: $event->entityType = 'tariffSwitch'; $event->entityId = OrgServiceProviderMapper::buildOrgId($internalMessage->getServiceProviderId()); break; } $event->eventData = $data; $compressor = new AsyncResponseCompressorEvent(); $compressor->compress($event); \App::log()->debug('The content of the CORE notification of response of type ' . $protoType . ' from the async operation ' . ($event->entityId ?: 'empty') . ' is ' . \Zend_Json::encode($data)); // Invoke the service $result = AsyncService::getInstance()->publish($event, $retries); \App::log()->info('End CORE notification of response of type' . $protoType . ' from the async operation ' . $event->entityId ?: 'empty'); $this->_helper->output('proto'); $this->view->setClass('Application\\Proto\\AsyncNotification\\Service\\Response'); $this->view->code = Application\Proto\AsyncNotification\Service\Response\Code::OK; $this->view->reason = "Successful operation."; }
/** * Handle 3party async response * * @param * $methodName * @param * $proto * @param * $ids * @return mixed */ protected function _sendAsyncRequestFake($methodName, $proto, $ids = array(), $customTags = array(), WatcherModel $watcher = null) { if (!$watcher || !$watcher->id) { $watcher = $this->_watcherToTransactionId($proto->accounting->transaction_id, $ids, $customTags, $watcher); $owned = true; } else { WatcherService::getInstance()->pushEntityId($watcher, $proto->accounting->transaction_id); $owned = false; } $event = $this->constructEventToTransaction(); $event->entityType = $watcher->entityType; $event->entityId = $proto->accounting->transaction_id; $event->eventData = array('hasFailures' => false); try { // Send async request $resp = $this->_sendRequest($methodName, array('protoMessage' => $proto)); $ok = $this->_checkResponse($resp); } catch (EricssonException $e) { if ($e->getErrorMessages()) { $event->eventData = $event->eventData = array('hasFailures' => true, 'message' => array('failed' => $e->getErrorMessages())); $compressor = new AsyncResponseCompressorEvent(); $compressor->compress($event); } else { if ($owned) { WatcherService::getInstance()->delete($watcher); throw $e; } else { $event->eventData = array('hasFailures' => true, 'exceptionMessage' => $e->getMessage(), 'exceptionCode' => $e->getCode()); } } } WatcherService::getInstance()->publishEvent($event); $watcher->reload(); return $watcher; }