public function diagnosticAction() { if (!$this->getRequest()->isGet()) { throw new UnexpectedException("Resquest must be GET"); } $transactionId = $this->_getTransactionId(); $result = $this->_service->load($transactionId); if (!$result) { throw new NotFoundException("Resource {$transactionId} not found"); } try { if ($result->status == WatcherModel::STATUS_FINISHED) { // Check permissions $this->_helper->allowed('read', $result); $events = $result->getEventList(); $event = array_pop($events); // Return async response $data = $event->eventData; $code = $data['message']['execResult']['code']; $reason = $data['message']['execResult']['reason']; if ($code == "0") { $this->view->result = $reason; } else { $this->view->result = "ERROR"; $this->view->reason = "[{$code}] " . $reason; } } } catch (Exception $e) { \App::log()->warn($e); } }
public function diagnosticAction() { if (!$this->getRequest()->isGet()) { throw new UnexpectedException("Resquest must be GET"); } $transactionId = $this->_getTransactionId(); try { $result = $this->_service->load($transactionId); if ($result->status == WatcherModel::STATUS_FINISHED) { // Check permissions $this->_helper->allowed('read', $result); $events = $result->getEventList(); $event = array_pop($events); // Return async response $data = $event->eventData; $code = $data['message']['execResult']['code']; $reason = $data['message']['execResult']['reason']; if ($code == "0") { $this->view->result = $reason; } else { $this->view->AsyncException = new External\Model\AsyncErrorModel(array('exceptionId' => $code, 'text' => $reason)); } } } catch (Exception $e) { \App::log()->warn($e); } }
protected function _watcherToTransactionId($transactionId, $ids = array(), $customTags = array(), WatcherModel $watcher = null) { $data = array(); if (is_array($ids) && !empty($ids)) { $data['ids'] = $ids; } $tags = $this->getCache()->getTags(); $data['tags'] = $customTags; if (is_array($tags) && !empty($tags)) { $data['tags'] = array_merge($tags, $customTags); } if (!empty($transactionId)) { /** TODO Mapper calling a service ??? :S **/ if (!$watcher) { $watcher = $this->_constructWatcherToTransaction(); } $watcher->entityIds = array_unique(array_merge($watcher->entityIds, array($transactionId))); $watcher->tags = array_unique(array_merge($watcher->tags, $data['tags'])); $this->_internalCreateWatcher($watcher); $transaction = new AsyncTransaction($data); $transaction->id = $transactionId; AsyncService::getInstance()->create($transaction); return $watcher; } }
public function testCreateAndLoad() { $transactionId = $this->_transactionIds[0]; // Create $model = new Async\Model\AsyncTransaction(); $model->setId($transactionId); $model->tags = array('ewewe', '2222ee'); $model->ids = array('ewwwwewe', '2ww222ee'); $this->_asyncService->create($model); // Load $result = $this->_asyncService->load($transactionId); $this->assertNotNull($result->tags); $this->assertEquals($model->tags, $result->tags); $this->assertNotNull($result->ids); $this->assertEquals($model->ids, $result->ids); }
public function setUp() { $this->_asyncService = AsyncService::getInstance(); $this->_transactionIds = array('eeruqw2131saw222sawdd1', 'shduah892189hwhsaskjdh', 'shdshausd21271hudias12'); $this->_data = array('data' => '{tested}'); $this->_user = array('user' => \App::getUserLogged()->getId(), 'organization' => \App::getUserLogged()->getOrganizationId(), 'authType' => \App_Controller_Plugin_Auth::AUTH_TYPE_AUTH_TOKEN); }
/** * 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."; }