Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed #848, Closed #849 - Allow to add new container/server/virtual … #864

Merged
merged 1 commit into from
Jul 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions resources/templates/etc/appserver/appserver.xml.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ use AppserverIo\Appserver\Meta\Composer\Script\SetupKeys;
<param name="workerAcceptMin" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_SERVER_WORKER_ACCEPT_MIN) ?></param>
<param name="workerAcceptMax" type="integer"><?php echo Setup::getValue(SetupKeys::CONTAINER_SERVER_WORKER_ACCEPT_MAX) ?></param>
<param name="documentRoot" type="string">webapps</param>
<param name="directoryIndex" type="string">index.do index.php index.html index.htm</param>
<param name="directoryIndex" type="string">index.dhtml index.do index.php index.html index.htm</param>
<param name="keepAliveMax" type="integer">64</param>
<param name="keepAliveTimeout" type="integer">5</param>
<param name="autoIndex" type="boolean">false</param>
<param name="errorsPageTemplatePath" type="string">resources/templates/www/error.phtml</param>
<param name="welcomePageTemplatePath" type="string">resources/templates/www/welcome.phtml</param>
<param name="autoIndexTemplatePath" type="string">resources/templates/www/auto_index.phtml</param>
</params>

<!-- An example how to modify response headers -->
<!--
<headers>
Expand Down Expand Up @@ -347,7 +347,7 @@ use AppserverIo\Appserver\Meta\Composer\Script\SetupKeys;
<param name="certPath" type="string">etc/appserver/server.pem</param>
<param name="passphrase" type="string"></param>
<param name="documentRoot" type="string">webapps</param>
<param name="directoryIndex" type="string">index.do index.php index.html index.htm</param>
<param name="directoryIndex" type="string">index.dhtml index.do index.php index.html index.htm</param>
<param name="keepAliveMax" type="integer">64</param>
<param name="keepAliveTimeout" type="integer">5</param>
<param name="autoIndex" type="boolean">false</param>
Expand Down
7 changes: 5 additions & 2 deletions src/AppserverIo/Appserver/Core/AbstractContainerThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ public function main()
$profileLogger->appendThreadContext($this->getContainerNode()->getName());
}

// setup configurations
// initialize the array for the server configurations
$serverConfigurations = array();

// load the server configurations and query whether a server signatures has been set
/** @var \AppserverIo\Appserver\Core\Api\Node\ServerNodeInterface $serverNode */
foreach ($this->getContainerNode()->getServers() as $serverNode) {
// query whether a server signature (software) has been configured
if ($serverNode->getParam('software') == null) {
Expand Down Expand Up @@ -161,7 +164,7 @@ public function main()
// init server array
$servers = array();
// start servers by given configurations
/** @var \AppserverIo\Server\Interfaces\ServerConfigurationInterface $serveConfig */
/** @var \AppserverIo\Server\Interfaces\ServerConfigurationInterface $serverConfig */
foreach ($serverConfigurations as $serverConfig) {
// get type definitions
$serverType = $serverConfig->getType();
Expand Down
65 changes: 65 additions & 0 deletions src/AppserverIo/Appserver/Core/Api/DeploymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
use AppserverIo\Appserver\Core\Api\Node\DeploymentNode;
use AppserverIo\Appserver\Core\Interfaces\ContainerInterface;
use AppserverIo\Psr\Application\ApplicationInterface;
use AppserverIo\Appserver\Core\Api\Node\ServerNode;
use AppserverIo\Appserver\Core\Api\Node\ContainersNode;
use AppserverIo\Appserver\Core\Interfaces\ApplicationServerInterface;

/**
* A service that handles deployment configuration data.
Expand Down Expand Up @@ -152,4 +155,66 @@ public function loadContextInstancesByContainer(ContainerInterface $container)
// return the array with the context instances
return $contextInstances;
}

/**
* Loads the containers, defined by the applications, merges them into
* the system configuration and returns the merged system configuration.
*
* @return \AppserverIo\Appserver\Core\Interfaces\SystemConfigurationInterface The merged system configuration
*/
public function loadContainerInstances()
{

// load the system configuration
/** @var AppserverIo\Appserver\Core\Interfaces\SystemConfigurationInterface $systemConfiguration */
$systemConfiguration = $this->getSystemConfiguration();

// load the service to validate the files
/** @var AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */
$configurationService = $this->newService('AppserverIo\Appserver\Core\Api\ConfigurationService');

/** @var AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNodeInstance */
foreach ($systemConfiguration->getContainers() as $containerName => $containerNodeInstance) {
// load the containers application base directory
$containerAppBase = $this->getBaseDirectory($containerNodeInstance->getHost()->getAppBase());

// iterate over all applications and create the server configuration
foreach (glob($containerAppBase . '/*', GLOB_ONLYDIR) as $webappPath) {
// iterate through all server configurations (servers.xml), validate and merge them
foreach ($this->globDir($webappPath . '/META-INF/containers.xml') 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);

/** @var AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNodeInstance */
foreach ($containersNodeInstance->getContainers() as $containerNodeInstance) {
// 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 file %s, configuration might be faulty.', $serverConfigurationFile)
);
}
}
}
}

// returns the merged system configuration
return $systemConfiguration;
}
}
50 changes: 50 additions & 0 deletions src/AppserverIo/Appserver/Core/Api/Node/AppserverNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,56 @@ public function getContainers()
return $this->containers;
}

/**
* Returns the container with the passed name.
*
* @param string $name The name of the container to return
*
* @return \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface The container node matching the passed name
*/
public function getContainer($name)
{
/** @var \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $server */
foreach ($this->getContainers() as $container) {
if ($container->getName() === $name) {
return $container;
}
}
}

/**
* Returns the containers as array with the container name as key.
*
* @return array The array with the containers
*/
public function getContainersAsArray()
{

// initialize the array for the containers
$containers = array();

// iterate over all found containers and assemble the array
/** @var \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $container */
foreach ($this->getContainers() as $container) {
$containers[$container->getName()] = $container;
}

// return the array with the containers
return $containers;
}

/**
* Attaches the passed container node.
*
* @param \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $container The container node to attach
*
* @return void
*/
public function attachContainer(ContainerNodeInterface $container)
{
$this->containers[$container->getPrimaryKey()] = $container;
}

/**
* Returns an array with the information about the deployed applications.
*
Expand Down
70 changes: 70 additions & 0 deletions src/AppserverIo/Appserver/Core/Api/Node/ContainerNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,56 @@ public function getServers()
return $this->servers;
}

/**
* Returns the servers as array with the server name as key.
*
* @return array The array with the servers
*/
public function getServersAsArray()
{

// initialize the array for the servers
$servers = array();

// iterate over all found servers and assemble the array
/** @var \AppserverIo\Appserver\Core\Api\Node\ServerNodeInterface $server */
foreach ($this->getServers() as $server) {
$servers[$server->getName()] = $server;
}

// return the array with the servers
return $servers;
}

/**
* Returns the server with the passed name.
*
* @param string $name The name of the server to return
*
* @return \AppserverIo\Appserver\Core\Api\Node\ServerNodeInterface The server node matching the passed name
*/
public function getServer($name)
{
/** @var \AppserverIo\Appserver\Core\Api\Node\ServerNodeInterface $server */
foreach ($this->getServers() as $server) {
if ($server->getName() === $name) {
return $server;
}
}
}

/**
* Attaches the passed server node.
*
* @param \AppserverIo\Appserver\Core\Api\Node\ServerNodeInterface $server The server node to attach
*
* @return void
*/
public function attachServer(ServerNodeInterface $server)
{
$this->servers[$server->getPrimaryKey()] = $server;
}

/**
* Return's all upstream nodes
*
Expand All @@ -203,4 +253,24 @@ public function getUpstreams()
{
return $this->upstreams;
}

/**
*This method merges the passed container node into this one.
*
* @param \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNode The container node to merge
*
* @return void
*/
public function merge(ContainerNodeInterface $containerNode)
{
// merge the server nodes
/** @var \AppserverIo\Appserver\Core\Api\Node\ServerNodeInterface $serverNode */
foreach ($containerNode->getServers() as $serverNode) {
if ($serverNodeToMerge = $this->getServer($serverNode->getName())) {
$serverNodeToMerge->merge($serverNode);
} else {
$this->attachServer($serverNode);
}
}
}
}
51 changes: 51 additions & 0 deletions src/AppserverIo/Appserver/Core/Api/Node/ContainersNode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* AppserverIo\Appserver\Core\Api\Node\ContainersNode
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* PHP version 5
*
* @author Tim Wagner <tw@appserver.io>
* @copyright 2015 TechDivision GmbH <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io/appserver
* @link http://www.appserver.io
*/

namespace AppserverIo\Appserver\Core\Api\Node;

/**
* DTO to transfer the application server's container configuration.
*
* @author Tim Wagner <tw@appserver.io>
* @copyright 2015 TechDivision GmbH <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io/appserver
* @link http://www.appserver.io
*/
class ContainersNode extends AbstractNode
{

/**
* Array with nodes for the registered containers.
*
* @var array @AS\Mapping(nodeName="container", nodeType="array", elementType="AppserverIo\Appserver\Core\Api\Node\ContainerNode")
*/
protected $containers = array();

/**
* Returns the array with all available containers.
*
* @return array The available containers
*/
public function getContainers()
{
return $this->containers;
}
}
29 changes: 25 additions & 4 deletions src/AppserverIo/Appserver/Core/Api/Node/ServerNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ServerNode extends AbstractNode implements ServerNodeInterface
* @var \AppserverIo\Appserver\Core\Api\Node\FileHandlersNodeTrait
*/
use FileHandlersNodeTrait;

/**
* The trait for the server headers.
*
Expand Down Expand Up @@ -124,7 +124,7 @@ class ServerNode extends AbstractNode implements ServerNodeInterface
* @var \AppserverIo\Appserver\Core\Api\Node\VirtualHostsNodeTrait
*/
use VirtualHostsNodeTrait;

/**
* The trait for the certificates.
*
Expand Down Expand Up @@ -187,7 +187,7 @@ class ServerNode extends AbstractNode implements ServerNodeInterface
* @AS\Mapping(nodeType="string")
*/
protected $requestContext;

/**
* The stream context to use.
*
Expand Down Expand Up @@ -265,7 +265,7 @@ public function getRequestContext()
{
return $this->requestContext;
}

/**
* Returns the stream context to use.
*
Expand All @@ -275,4 +275,25 @@ public function getStreamContext()
{
return $this->streamContext;
}

/**
*This method merges the passed server node into this one.
*
* @param \AppserverIo\Appserver\Core\Api\Node\ServerNodeInterface $serverNode The server node to merge
*
* @return void
*/
public function merge(ServerNodeInterface $serverNode)
{
// append the certificate nodes found in the passed server node
/** @var \AppserverIo\Appserver\Core\Api\Node\CertificateNode $certificate */
foreach ($serverNode->getCertificates() as $certificate) {
$this->certificates[] = $certificate;
}
// append the virtual host nodes found in the passed server node
/** @var \AppserverIo\Appserver\Core\Api\Node\VirtualHostNode $virtualHost */
foreach ($serverNode->getVirtualHosts() as $virtualHost) {
$this->virtualHosts[] = $virtualHost;
}
}
}
Loading