Ejemplo n.º 1
0
 public function handle(array $record)
 {
     $this->initStorageApiClient();
     if (!$this->storageApiClient || $record['level'] == Logger::DEBUG) {
         return false;
     }
     $event = new Event();
     if (!empty($record['component'])) {
         $event->setComponent($record['component']);
     } else {
         $event->setComponent($this->appName);
     }
     $event->setMessage(\Keboola\Utils\sanitizeUtf8($record['message']));
     $event->setRunId($this->storageApiClient->getRunId());
     $params = [];
     if (isset($record['http'])) {
         $params['http'] = $record['http'];
     }
     $event->setParams($params);
     $results = [];
     if (isset($record['context']['exceptionId'])) {
         $results['exceptionId'] = $record['context']['exceptionId'];
     }
     if (isset($record['context']['job'])) {
         $results['job'] = $record['context']['job'];
     }
     $event->setResults($results);
     switch ($record['level']) {
         case Logger::ERROR:
             $type = Event::TYPE_ERROR;
             break;
         case Logger::CRITICAL:
         case Logger::EMERGENCY:
         case Logger::ALERT:
             $type = Event::TYPE_ERROR;
             $event->setMessage("Application error");
             $event->setDescription("Contact support@keboola.com");
             break;
         case Logger::WARNING:
         case Logger::NOTICE:
             $type = Event::TYPE_WARN;
             break;
         case Logger::INFO:
         default:
             $type = Event::TYPE_INFO;
             break;
     }
     $event->setType($type);
     $this->storageApiClient->createEvent($event);
     return false;
 }
Ejemplo n.º 2
0
 public function create($command, array $params = [], $lockName = null)
 {
     $this->storageApiClient = $this->storageApiService->getClient();
     $tokenData = $this->storageApiService->getTokenData();
     $job = new Job($this->objectEncryptor, ['id' => $this->storageApiClient->generateId(), 'runId' => $this->storageApiClient->generateRunId($this->storageApiClient->getRunId()), 'project' => ['id' => $tokenData['owner']['id'], 'name' => $tokenData['owner']['name']], 'token' => ['id' => $tokenData['id'], 'description' => $tokenData['description'], 'token' => $this->objectEncryptor->encrypt($this->storageApiClient->getTokenString())], 'component' => $this->componentName, 'command' => $command, 'params' => $params, 'process' => ['host' => gethostname(), 'pid' => getmypid()], 'nestingLevel' => 0, 'createdTime' => date('c')], null, null, null);
     if ($lockName) {
         $job->setLockName($lockName);
     }
     $componentConfiguration = $this->getComponentConfiguration();
     if (isset($componentConfiguration['flags']) && in_array('encrypt', $componentConfiguration['flags'])) {
         $job->setEncrypted(true);
     }
     return $job;
 }
Ejemplo n.º 3
0
 protected function sendEventToSapi($type, $message, $componentName)
 {
     $sapiEvent = new SapiEvent();
     $sapiEvent->setComponent($componentName);
     $sapiEvent->setMessage($message);
     $sapiEvent->setRunId($this->storageApi->getRunId());
     $sapiEvent->setType($type);
     $this->storageApi->createEvent($sapiEvent);
 }
Ejemplo n.º 4
0
 public function ping()
 {
     $options = array('timeout' => 7200, 'headers' => array('X-StorageApi-Token' => $this->storageApi->getTokenString(), 'Accept-Encoding' => 'gzip', 'User-Agent' => $this->storageApi->getUserAgent()));
     if ($this->storageApi->getRunId()) {
         $options['headers']['X-KBC-RunId'] = $this->storageApi->getRunId();
     }
     try {
         $response = $this->client->get('storage/tokens/verify', $options);
     } catch (RequestException $e) {
         $response = $e->getResponse();
         if ($response && $response->getStatusCode() == 503) {
             return false;
         } else {
             throw $e;
         }
     }
     if ($response && $response->getStatusCode() == 200) {
         $body = ResponseDecoder::decode($response);
         return array_key_exists('token', $body);
     }
     return false;
 }
Ejemplo n.º 5
0
 /**
  * Get parent runId to the current runId (defined by SAPI client)
  * @return string Parent part of hierarchical Id.
  */
 public function getParentRunId()
 {
     $runId = $this->client->getRunId();
     if (!empty($runId)) {
         if (($pos = strrpos($runId, '.')) === false) {
             // there is no parent
             $parentRunId = $runId;
         } else {
             $parentRunId = substr($runId, 0, $pos);
         }
     } else {
         // there is no runId
         $parentRunId = '';
     }
     return $parentRunId;
 }
Ejemplo n.º 6
0
 /**
  * Get SAPI run ID
  *
  * @return int
  */
 public function getRunId()
 {
     return $this->storageApi->getRunId();
 }