From 3a8274cde206f4c37255a61f48a7580633994020 Mon Sep 17 00:00:00 2001 From: Chris Schneider Date: Mon, 17 Jun 2019 10:39:28 -0600 Subject: [PATCH] WIP CoreAgentManager --- TODO.md | 9 +++ src/CoreAgentManager.php | 126 +++++++++++++++++++++++++++++++++ tests/CoreAgentManagerTest.php | 21 ++++++ 3 files changed, 156 insertions(+) create mode 100644 TODO.md create mode 100644 src/CoreAgentManager.php create mode 100644 tests/CoreAgentManagerTest.php diff --git a/TODO.md b/TODO.md new file mode 100644 index 00000000..1b3b8840 --- /dev/null +++ b/TODO.md @@ -0,0 +1,9 @@ +TODO: + +* Fix value as string in tagrequest +* Test Connector registers & sends correctly +* Clarify API + - Should Spans be in control of holding their own tags, or only agent-object creating tags? + - Why have both "Agent" and "Request"? +* Create AppMetadata message +* Script to download & start CA diff --git a/src/CoreAgentManager.php b/src/CoreAgentManager.php new file mode 100644 index 00000000..340b8068 --- /dev/null +++ b/src/CoreAgentManager.php @@ -0,0 +1,126 @@ +agent = $agent; + $this->coreAgentDir = + $agent->getConfig()->get("core_agent_dir") . + "/" . + $agent->getConfig()->get("core_agent_full_name"); + + $this->downloader = new CoreAgentDownloader( + $this->coreAgentDir, + $this->agent->getConfig()->get("core_agent_full_name") + ); + } + + /** + * undocumented function + * + * @return void + */ + public function launch() + { + if (! $this->agent->getConfig()->value("core_agent_launch")) { + $this->agent->getLogger()->debug( + "Not attempting to launch Core Agent " . + "due to 'core_agent_launch' setting." + ); + return false; + } + + if (! $this->verify()) { + if (! $this->agent->getConfig()->value("core_agent_download")) { + $this->agent->getLogger()->debug( + "Not attempting to download Core Agent due ". + "to 'core_agent_download' setting." + ); + return false; + } + } + + $this->download(); + + if (! $this->verify()) { + $this->agent->getLogger()->debug( + "Failed to verify Core Agent. Not launching Core Agent." + ); + return false; + } + + return $this->run(); + } + + /** + * Initiate download of the agent + * + * @return void + */ + public function download() + { + $this->downloader->download(); + } + + /** + * + * + * @return void + */ + public function run() + { + try { + subprocess.check_call( + self.agent_binary() + + self.daemonize_flag() + + self.log_level() + + self.log_file() + + self.config_file() + + self.socket_path() + ); + return true; + } catch (Exception $e) { + // TODO detect failure of launch properly + // logger.error("Error running Core Agent: %r", e); + return false; + } + } +} + +/** + * Class CoreAgentDownloader + * + * A helper class for the CoreAgentManager that handles downloading, verifying, + * and unpacking the CoreAgent. + */ +class CoreAgentDownloader +{ + /** + * @param $core_agent_dir + * @param $core_agent_full_name + */ + public function __construct($core_agent_dir, $core_agent_full_name) + { + $this->core_agent_dir = $core_agent_dir; + $this->core_agent_full_name = $core_agent_full_name; + } + + public function download() + { + return null; + } +} diff --git a/tests/CoreAgentManagerTest.php b/tests/CoreAgentManagerTest.php new file mode 100644 index 00000000..e29a1a29 --- /dev/null +++ b/tests/CoreAgentManagerTest.php @@ -0,0 +1,21 @@ +assertNotNull($cam); + } +}