Пример #1
0
 public function writeDataToFile($params)
 {
     // shorthand
     $filename = $this->args[0];
     // what are we doing?
     $printer = new DataPrinter();
     $logParams = $printer->convertToString($params);
     $log = usingLog()->startAction("create YAML file '{$filename}' with contents '{$logParams}'");
     // create an instance of the Symfony YAML writer
     $writer = new Dumper();
     // create the YAML data
     $yamlData = $writer->dump($params, 2);
     if (!is_string($yamlData) || strlen($yamlData) < 6) {
         throw new E5xx_ActionFailed(__METHOD__, "unable to convert data to YAML");
     }
     // prepend the YAML marker
     $yamlData = '---' . PHP_EOL . $yamlData;
     // write the file
     //
     // the loose FALSE test here is exactly what we want, because we want to catch
     // both the situation when the write fails, and when there's zero bytes written
     if (!file_put_contents($filename, $yamlData)) {
         throw new E5xx_ActionFailed(__METHOD__, "unable to write file '{$filename}'");
     }
     // all done
     $log->endAction();
 }
Пример #2
0
 public function set($fieldName, $value)
 {
     // convert $value into something that can appear in our logs
     $convertor = new DataPrinter();
     $printable = $convertor->convertToString($value);
     // what are we doing?
     $log = usingLog()->startAction("set checkpoint field '{$fieldName}' to '{$printable}'");
     // get the checkpoint
     $checkpoint = getCheckpoint();
     // set the value
     $checkpoint->{$fieldName} = $value;
     // all done
     $log->endAction();
 }
Пример #3
0
 public function getModuleSetting($settingPath)
 {
     // what are we doing?
     $log = usingLog()->startAction("get module setting '{$settingPath}'");
     // get the active config
     $config = $this->st->getActiveConfig();
     // we search the config in this order
     $pathsToSearch = ["user.moduleSettings.{$settingPath}" => "user's .storyplayer file", "systemundertest.moduleSettings.{$settingPath}" => "system under test config file", "target.moduleSettings.{$settingPath}" => "test environment config file", "storyplayer.moduleSettings.{$settingPath}" => "storyplayer.json config file"];
     foreach ($pathsToSearch as $searchPath => $origin) {
         if ($config->hasData($searchPath)) {
             $value = $config->getData($searchPath);
             // log the settings
             $printer = new DataPrinter();
             $logValue = $printer->convertToString($value);
             $log->endAction("found in {$origin}: '{$logValue}'");
             return $value;
         }
     }
     // if we get here, the module setting does not exist
     throw new E5xx_ActionFailed(__METHOD__, "unable to find moduleSetting '{$settingPath}'");
 }
Пример #4
0
 public function recvMulti($timeout = null)
 {
     // do we need to set a default timeout?
     if ($timeout === null) {
         $timeout = self::$defaultTimeout;
     }
     // what are we doing?
     if ($timeout == -1) {
         $log = usingLog()->startAction("recvmulti() from ZMQ socket; no timeout");
         $this->args[0]->setSockOpt(ZMQ::SOCKOPT_RCVTIMEO, -1);
     } else {
         $log = usingLog()->startAction("recvmulti() from ZMQ socket; timeout is {$timeout} seconds");
         $this->args[0]->setSockOpt(ZMQ::SOCKOPT_RCVTIMEO, $timeout * 1000);
     }
     // do it
     $return = $this->args[0]->recvmulti();
     // we need to look at the received value
     $printer = new DataPrinter();
     $msg = $printer->convertToString($return);
     // all done
     $log->endAction("result is: {$msg}");
     return $return;
 }
Пример #5
0
 /**
  * convert an array of data to a single string for output, and
  * truncate if required
  *
  * @param  array<mixed>|object $message
  *         the data set to convert
  * @return string
  *         the converted data
  */
 public function convertMessageArray($message)
 {
     $printer = new DataPrinter();
     $parts = false;
     foreach ($message as $part) {
         $parts[] = $printer->convertToString($part);
     }
     $logValue = implode(' ', $parts);
     return $this->truncateIfRequired($logValue);
 }
Пример #6
0
 public function getAppSettings($appName)
 {
     // what are we doing?
     $log = usingLog()->startAction("get all settings for {$appName}");
     // do we have any in the storyplayer.json file?
     $config = $this->st->getConfig();
     if (isset($config->storyplayer, $config->storyplayer->appSettings, $config->storyplayer->appSettings->{$appName})) {
         // success!
         $value = $config->storyplayer->appSettings->{$appName};
         // log the settings
         $printer = new DataPrinter();
         $logValue = $printer->convertToString($value);
         $log->endAction("settings for '{$appName}' are '{$logValue}'");
         // all done
         return $value;
     }
     // TODO: search test environments too?
     // if we get here, then we could not find the settings
     throw new E5xx_ActionFailed(__METHOD__);
 }
Пример #7
0
 public function get($name)
 {
     // what are we doing?
     $log = usingLog()->startAction("get '{$name}' from the storyplayer config");
     // what is the full path to this data?
     $fullPath = 'storyplayer';
     if (!empty($name)) {
         $fullPath = $fullPath . '.' . $name;
     }
     // get the details
     $config = $this->st->getActiveConfig();
     if (!$config->hasData($fullPath)) {
         $log->endAction("no such setting '{$name}'");
         return null;
     }
     // if we get here, then success \o/
     $value = $config->getData($fullPath);
     // log the settings
     $printer = new DataPrinter();
     $logValue = $printer->convertToString($value);
     $log->endAction("value is: '{$logValue}'");
     // all done
     return $value;
 }
Пример #8
0
 public function getModuleSettings($module)
 {
     // what are we doing?
     $log = usingLog()->startAction("get all settings for '{$module}' from the system-under-test config");
     // what is the full path to this data?
     $fullPath = 'systemundertest.moduleSettings.' . $module;
     // get the details
     $config = $this->st->getActiveConfig();
     if (!$config->hasData($fullPath)) {
         $msg = "no module '{$module}' found in the config";
         $log->endAction($msg);
         throw new E5xx_ActionFailed(__METHOD__, $msg);
     }
     // success!
     $value = $config->getData($fullPath);
     // log the settings
     $printer = new DataPrinter();
     $logValue = $printer->convertToString($value);
     $log->endAction("settings for '{$module}' are '{$logValue}'");
     // all done
     return $value;
 }
Пример #9
0
 /**
  * @param  string $appName
  * @param  string $settingName
  * @return mixed
  */
 protected function getLegacyAppSetting($appName, $settingName)
 {
     // what are we doing?
     $log = usingLog()->startAction("get {$settingName} for '{$appName}' from host '{$this->args[0]}'");
     // make sure we have valid host details
     $hostDetails = $this->getHostDetails();
     // do we have any app settings?
     if (!isset($hostDetails->appSettings)) {
         $log->endAction("host has no appSettings at all");
         throw new E5xx_ActionFailed(__METHOD__);
     }
     if (!isset($hostDetails->appSettings->{$appName})) {
         $log->endAction("host has no appSettings for {$appName}");
         throw new E5xx_ActionFailed(__METHOD__);
     }
     if (!isset($hostDetails->appSettings->{$appName}->{$settingName})) {
         $log->endAction("host has no appSetting '{$settingName}' for {$appName}");
         throw new E5xx_ActionFailed(__METHOD__);
     }
     // yes we do
     $value = $hostDetails->appSettings->{$appName}->{$settingName};
     // log the settings
     $printer = new DataPrinter();
     $logValue = $printer->convertToString($value);
     $log->endAction("setting for '{$appName}' is '{$logValue}'");
     // all done
     return $value;
 }
Пример #10
0
 public function getModuleSetting($setting)
 {
     // what are we doing?
     $log = usingLog()->startAction("get '{$setting}' from test environment's module settings");
     // get the details
     $fullPath = 'target.moduleSettings.' . $setting;
     $config = $this->st->getConfig();
     $value = null;
     if ($config->hasData($fullPath)) {
         $value = $config->getData($fullPath);
     }
     // log the settings
     $printer = new DataPrinter();
     $logValue = $printer->convertToString($value);
     $log->endAction("setting is: '{$logValue}'");
     // all done
     return $value;
 }
 public function addParams($params)
 {
     // build our callable
     $action = function ($def, $hostId) use($params) {
         // convert the params into something we can log
         $printer = new DataPrinter();
         $logParams = $printer->convertToString($params);
         // what are we doing?
         $log = usingLog()->startAction("add params '{$logParams}' to host '{$hostId}'");
         // make sure we have an entry for this host
         if (!isset($def->{$hostId})) {
             $def->{$hostId} = new BaseObject();
         }
         // add our params
         $def->{$hostId}->params = $params;
         // all done
         $log->endAction();
     };
     // build our return object
     $return = new DelayedProvisioningDefinitionAction($this->args[0], $action);
     // all done
     return $return;
 }