public function testSendingUsingGetMethodPrefersRequestOverQueryParameters() { $a = new DruidNodeDruidQueryExecutor('1.2.3.4', '1234'); $a->setHttpMethod('GET'); $a->setEndPoint('/somewhere/some/place?hey=abc'); $request = $a->createRequest('{"hey":123}'); $query = $request->getQuery()->getAll(); // Does not stomp the query params from request $this->assertArrayHasKey('hey', $query); $this->assertEquals('123', $query['hey']); $this->assertNotEquals('abc', $query['hey']); }
protected function ingest($formattedStartTime, $formattedEndTime, InputInterface $input, OutputInterface $output) { /** @var $logger LoggerInterface */ $logger = new ConsoleLogger($output); $fetcher = new ReferralBatchFetcher(); $fetcher->setOutput($logger); $fetcher->setMySqlCredentials($this->host, $this->user, $this->pass, $this->db); $fetcher->setTimeWindow($formattedStartTime, $formattedEndTime); $filePathToUse = '/tmp/referral_temp_' . time() . '.json'; $preparer = new LocalPhpArrayToJsonFilePreparer(); $preparer->setFilePath($filePathToUse); $indexTaskQueryGenerator = new SimpleIndexQueryGenerator(); $indexTaskQueryParameters = new IndexTaskQueryParameters(); $indexTaskQueryParameters->dataSource = 'referral-report-referrals-cli-test'; $indexTaskQueryParameters->setIntervals($formattedStartTime, $formattedEndTime); $indexTaskQueryParameters->dimensions = array('referral_id', 'facility_id', 'patient_id'); $indexTaskQueryParameters->timeDimension = 'date'; // TODO Fill in with dimensions, etc for referrals. $indexTaskQueryParameters->validate(); $basicDruidJobWatcher = new CallbackBasedIndexingTaskDruidJobWatcher(); /** * @param CallbackBasedIndexingTaskDruidJobWatcher $jobWatcher */ $myOnPendingCallback = function ($jobWatcher) use($output) { $output->writeln('Druid says the job is still running. Trying again in ' . $jobWatcher->watchAttemptDelay . ' seconds...'); }; $basicDruidJobWatcher->setOnJobPending($myOnPendingCallback); $basicDruidJobWatcher->setOutput($logger); $basicDruidJobWatcher->setDruidIp($this->druidIp); $basicDruidJobWatcher->setDruidPort($this->druidPort); $druidQueryExecutor = new DruidNodeDruidQueryExecutor($this->druidIp, $this->druidPort, '/druid/indexer/v1/task'); try { $output->writeln("Fetching referral data from source..."); $fetchedData = $fetcher->fetch(); //////////////////////////////// $output->writeln("Fetched " . count($fetchedData) . " referrals."); if (count($fetchedData) === 0) { $output->writeln("Fetched no records, so stopping here."); return; } if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { $exampleData = print_r($fetchedData[0], true); $output->writeln("The first record looks like:\n\n" . $exampleData . "\n\n"); } $pathOfPreparedData = $preparer->prepare($fetchedData); $indexTaskQueryParameters->setFilePath($pathOfPreparedData); $output->writeln('File is prepared for druid at "' . $pathOfPreparedData . '"'); $output->writeln('Requesting Druid index the source data into dataSource "' . $indexTaskQueryParameters->dataSource . '"'); $ingestionTaskId = $druidQueryExecutor->executeQuery($indexTaskQueryGenerator, $indexTaskQueryParameters, new IndexingTaskResponseHandler()); $output->writeln('Druid has received the job. Job id is "' . $ingestionTaskId . '"'); $output->writeln('Checking Druid for the job status:'); $success = $basicDruidJobWatcher->watchJob($ingestionTaskId); if ($success) { $output->writeln('Done checking druid job status.'); $output->writeln('Cleaning up prepared file "' . $pathOfPreparedData . '"...'); $cleanedUpSuccess = $preparer->cleanup($pathOfPreparedData); if ($cleanedUpSuccess) { $output->writeln('Succesfully cleaned up file.'); } } else { $output->writeln('Job failed or did not finish in time.'); $output->writeln('In the future I will ask you if you want to delete the temporary file but for now I will leave it in place so that ingestion is not interrupted.'); } $output->writeln('Done.'); //////////////////////////////// } catch (\Exception $e) { throw $e; } }