/**
  * Initializes the storage provider by loading the configuration values from
  * the passed module configuration.
  *
  * @param \AppserverIo\Appserver\Core\Interfaces\SystemConfigurationInterface $systemConfiguration The system configuration
  * @param \AppserverIo\Server\Interfaces\ModuleConfigurationInterface         $moduleConfiguration The module configuration
  *
  * @throws \Exception Is thrown if the JSON can not be read
  */
 public function __construct(SystemConfigurationInterface $systemConfiguration, ModuleConfigurationInterface $moduleConfiguration)
 {
     // load the configuration values
     $defaultTtl = $moduleConfiguration->getParam(AbstractStorageProvider::DEFAULT_TTL);
     // query whether or not the default TTL is an integer
     if (!is_int($defaultTtl)) {
         throw new \Exception('Default TTL must be an integer.');
     }
     // declare the array for the DNS records
     $dnsRecords = array();
     // iterate over the system configuration and create DNS A records from the found virtual hosts
     foreach ($systemConfiguration->getContainers() as $containerNode) {
         foreach ($containerNode->getServers() as $serverNode) {
             foreach ($serverNode->getVirtualHosts() as $virtualHost) {
                 if (sizeof($dnsNames = explode(' ', $virtualHost->getName())) > 0) {
                     foreach ($dnsNames as $dnsName) {
                         // add the IPv4 + IPv6 address for localhost
                         $dnsRecords[$dnsName]['A'] = array('127.0.0.1');
                         $dnsRecords[$dnsName]['AAAA'] = array('::1');
                     }
                 }
             }
         }
     }
     // set the default TTL and the DNS records
     $this->dsTtl = $defaultTtl;
     $this->dnsRecords = $dnsRecords;
 }
Example #2
0
 /**
  * Initializes the context with the connection to the storage backend.
  *
  * @param \AppserverIo\Appserver\Core\Interfaces\SystemConfigurationInterface $systemConfiguration The system configuration
  */
 public function __construct(SystemConfigurationInterface $systemConfiguration)
 {
     // initialize the storage
     $initialContextNode = $systemConfiguration->getInitialContext();
     $storageNode = $initialContextNode->getStorage();
     $reflectionClass = $this->newReflectionClass($storageNode->getType());
     // create the storage instance
     $storage = $reflectionClass->newInstance();
     // append the storage servers registered in system configuration
     foreach ($storageNode->getStorageServers() as $storageServer) {
         $storage->addServer($storageServer->getAddress(), $storageServer->getPort(), $storageServer->getWeight());
     }
     // add the storage to the initial context
     $this->setStorage($storage);
     // attach the system configuration to the initial context
     $this->setSystemConfiguration($systemConfiguration);
 }
 /**
  * Loads the container instances from the META-INF/containers.xml configuration file of the
  * passed web application path and add/merge them to/with the system configuration.
  *
  * @param \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface         $containerNode       The container node used for property replacement
  * @param \AppserverIo\Appserver\Core\Interfaces\SystemConfigurationInterface $systemConfiguration The system configuration to add/merge the found containers to/with
  * @param string                                                              $webappPath          The path to the web application to search for a META-INF/containers.xml file
  *
  * @return void
  */
 public function loadContainerInstance(ContainerNodeInterface $containerNode, SystemConfigurationInterface $systemConfiguration, $webappPath)
 {
     // load the service to validate the files
     /** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */
     $configurationService = $this->newService('AppserverIo\\Appserver\\Core\\Api\\ConfigurationService');
     // iterate through all server configurations (servers.xml), validate and merge them
     foreach ($this->globDir(AppEnvironmentHelper::getEnvironmentAwareGlobPattern($webappPath, 'META-INF/containers')) as $containersConfigurationFile) {
         try {
             // validate the application specific container configurations
             $configurationService->validateFile($containersConfigurationFile, null);
             // create a new containers node instance
             $containersNodeInstance = new ContainersNode();
             $containersNodeInstance->initFromFile($containersConfigurationFile);
             // load the system properties
             $properties = $this->getSystemProperties($containerNode);
             // prepare the sytsem properties
             $this->prepareSystemProperties($properties, $webappPath);
             /** @var \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNodeInstance */
             foreach ($containersNodeInstance->getContainers() as $containerNodeInstance) {
                 // replace the properties for the found container node instance
                 $containerNodeInstance->replaceProperties($properties);
                 // query whether we've to merge or append the server node instance
                 if ($container = $systemConfiguration->getContainer($containerNodeInstance->getName())) {
                     $container->merge($containerNodeInstance);
                 } else {
                     $systemConfiguration->attachContainer($containerNodeInstance);
                 }
             }
         } catch (ConfigurationException $ce) {
             // load the logger and log the XML validation errors
             $systemLogger = $this->getInitialContext()->getSystemLogger();
             $systemLogger->error($ce->__toString());
             // additionally log a message that server configuration will be missing
             $systemLogger->critical(sprintf('Will skip app specific server configuration because of invalid file %s', $containersConfigurationFile));
         }
     }
 }