/** * getNoSQLResource() -- private static method * * this method initializes the nosql resource by attempting to connect to the nosql service. if the connection * attempt succeeds, then mark the resource as available. Otherwise, post an error-fatal and explicitly mark * the service as not-available and return. * * NOTE: * ----- * This resource allocation exists outside of the resource manager because the resource manager instantiates * this class in it's constructor. Were you to request a resource from the resource manager, you'd end-up in * a circular reference and if the whole thing does not come to an immediate shuddering stop, then it would * certainly blow-up the first time you attempt to log an error. So, tl;dr: do not attempt to 'fix' this as * it's not broken. * * @author mike@givingassistant.org * @version 1.0 * * @return Aws\DynamoDb\DynamoDbClient|null * * HISTORY: * ======== * 06-09-17 mks original coding * */ private function getNoSQLResource():Aws\DynamoDb\DynamoDbClient { global $eos; $options = null; date_default_timezone_set(TIME_TIMEZONE); if (empty($this->config)) { echo getDateTime() . CON_ERROR . $this->res . ERROR_CONFIG_RESOURCE_404 . CONFIG_DATABASE_DDB . $eos; return(null); } $noSQLConfig = $this->config[CONFIG_DATABASE_DDB_APPSERVER]; $credentials = [ STRING_KEY => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_KEY_ID], STRING_SECRET => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_ACCESS_KEY] ]; /* * Requests to DynamoDB are made over HTTP(S), and this does not require that you establish an upfront * connection. When you create the client object, you are not making a connection to DynamoDB, you are just * configuring an HTTP client that will make requests to DynamoDB. */ $awsConfig = new Aws\Sdk([ STRING_ENDPOINT => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_DSN] . ':' . $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_PORT], STRING_REGION => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_REGION], STRING_VERSION => $noSQLConfig[CONFIG_DATABASE_DDB_APPSERVER_VERSION], STRING_CREDS => $credentials ]); return $awsConfig->createDynamoDb(); } /** * getLog() - public method * * getLog is the method that is used to fetch log (or Metrics) records from the mongo collection. * * because ddb limits queries to 1MB returns, and the paint is still wet on this schema, for now I'm * going to limit queries for log-file fetching to just the last N records created within the last hour and * we'll just grab up to the limit of the records returned - which should still be a significant number of * records... * * This method reads the last X records created in the last hour (since this method is mainly used for * providing HTML output to the log-reader) and wraps the data in HTML table rows intended for the logDump * utility. * * todo -- pagination support? Query by error-code? Query by eventID? Query by class? * * @author mshallop@pathway.com * @version 1.0 * * @param string $_what defaults to the log template -- should be over-ridden for metrics template * @return null|string * @throws Exception * * HISTORY: * ======== * 06-07-17 mks original coding * 06-14-17 mks refactored for ddb * */ public function getLog(string $_what = TEMPLATE_CLASS_LOGS):string { $result = null; $returnData = null; $marshaler = new Marshaler(); // black-box son converter $lastHour = time() - NUMBER_ONE_HOUR_SEC; if ($_what != TEMPLATE_CLASS_LOGS and $_what != TEMPLATE_CLASS_METRICS) $_what = TEMPLATE_CLASS_LOGS; $eav = $marshaler->marshalJson('{":ts" :' . $lastHour . '}'); $params = [ DDB_STRING_TABLE_NAME => $this->collectionName, DDB_STRING_KEY_COND_EXPR => LOG_CREATED . ' > :ts', DDB_STRING_EXPR_ATTR_VALS => $eav ]; try { $result = $this->connection->query($params); } catch (DynamoDbException $e) { $this->errStack[] = __FILE__ . ':' . __LINE__ . ':' . __METHOD__ . ':' . $this->class . ':' . ERROR_FATAL . ' caught cursor exception: ' . $e->getMessage(); self::throwFatal(); } if (!is_null($result)) { foreach ($result[DDB_STRING_ITEMS] as $row) { $returnData .= '