|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AppserverIo\Provisioning\Api\Node\ProvisionNode |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/appserver-io/provisioning |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Provisioning\Api\Node; |
|
22
|
|
|
|
|
23
|
|
|
use AppserverIo\Description\Annotations as DI; |
|
24
|
|
|
use AppserverIo\Description\Api\Node\AbstractNode; |
|
25
|
|
|
use AppserverIo\Provisioning\Configuration\ProvisionConfigurationInterface; |
|
26
|
|
|
use AppserverIo\Psr\ApplicationServer\Configuration\DatasourceConfigurationInterface; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* DTO to transfer a applications provision configuration. |
|
30
|
|
|
* |
|
31
|
|
|
* @author Tim Wagner <[email protected]> |
|
32
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
|
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
34
|
|
|
* @link https://github.com/appserver-io/provisioning |
|
35
|
|
|
* @link http://www.appserver.io |
|
36
|
|
|
*/ |
|
37
|
|
|
class ProvisionNode extends AbstractNode implements ProvisionConfigurationInterface |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The node containing datasource information. |
|
42
|
|
|
* |
|
43
|
|
|
* @var \AppserverIo\Psr\ApplicationServer\Configuration\DatasourceConfigurationInterface |
|
44
|
|
|
* @DI\Mapping(nodeName="datasource", nodeType="AppserverIo\Description\Api\Node\DatasourceNode") |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $datasource; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* The node containing installation information. |
|
50
|
|
|
* |
|
51
|
|
|
* @var \AppserverIo\Provisioning\Api\Node\InstallationNode |
|
52
|
|
|
* @DI\Mapping(nodeName="installation", nodeType="AppserverIo\Provisioning\Api\Node\InstallationNode") |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $installation; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Injects the datasource node. |
|
58
|
|
|
* |
|
59
|
|
|
* @param \AppserverIo\Psr\ApplicationServer\Configuration\DatasourceConfigurationInterface $datasource The datasource node to inject |
|
60
|
|
|
* |
|
61
|
|
|
* @return void |
|
62
|
|
|
*/ |
|
63
|
|
|
public function injectDatasource(DatasourceConfigurationInterface $datasource) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->datasource = $datasource; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Returns the node containing datasource information. |
|
70
|
|
|
* |
|
71
|
|
|
* @return \AppserverIo\Psr\ApplicationServer\Configuration\DatasourceConfigurationInterface The node containing datasource information |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getDatasource() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->datasource; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Returns the node containing installation information. |
|
80
|
|
|
* |
|
81
|
|
|
* @return \AppserverIo\Provisioning\Api\Node\InstallationNode The node containing installation information |
|
82
|
|
|
*/ |
|
83
|
|
|
public function getInstallation() |
|
84
|
|
|
{ |
|
85
|
|
|
return $this->installation; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* This method reprovisions the provision node with the data from the file passed as parameter. |
|
90
|
|
|
* |
|
91
|
|
|
* Before reinitializing the provisioning node, the file will be reinterpreted with be invoking |
|
92
|
|
|
* the PHP parser again, what again gives you the possibility to replace content by calling the |
|
93
|
|
|
* PHP methods of this class. |
|
94
|
|
|
* |
|
95
|
|
|
* @param string $provisionFile The absolute pathname of the file to reprovision from |
|
96
|
|
|
* |
|
97
|
|
|
* @return void |
|
98
|
|
|
*/ |
|
99
|
|
|
public function reprovision($provisionFile) |
|
100
|
|
|
{ |
|
101
|
|
|
|
|
102
|
|
|
// copy the datasource node temporarily |
|
103
|
|
|
$tmpDatasource = $this->datasource; |
|
104
|
|
|
|
|
105
|
|
|
// replace the variables |
|
106
|
|
|
ob_start(); |
|
107
|
|
|
require $provisionFile; |
|
108
|
|
|
$this->initFromString(ob_get_clean()); |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
// re-attach the database node |
|
111
|
|
|
$this->datasource = $tmpDatasource; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* This method merges the installation steps of the passed provisioning node into the steps of |
|
116
|
|
|
* this instance. If a installation node with the same type already exists, the one of this |
|
117
|
|
|
* instance will be overwritten. |
|
118
|
|
|
* |
|
119
|
|
|
* @param \AppserverIo\Provisioning\Configuration\ProvisionConfigurationInterface $provisionNode The node with the installation steps we want to merge |
|
120
|
|
|
* |
|
121
|
|
|
* @return void |
|
122
|
|
|
*/ |
|
123
|
|
|
public function merge(ProvisionConfigurationInterface $provisionNode) |
|
124
|
|
|
{ |
|
125
|
|
|
|
|
126
|
|
|
// inject the datasource node if available |
|
127
|
|
|
if ($datasource = $provisionNode->getDatasource()) { |
|
128
|
|
|
$this->injectDatasource($datasource); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
// load the steps of this instance |
|
132
|
|
|
$localSteps = $this->getInstallation()->getSteps(); |
|
133
|
|
|
|
|
134
|
|
|
// merge it with the ones found in the passed provisioning node |
|
135
|
|
|
foreach ($provisionNode->getInstallation()->getSteps() as $stepToMerge) { |
|
136
|
|
|
foreach ($localSteps as $key => $step) { |
|
137
|
|
|
if ($step->getType() === $stepToMerge->getType()) { |
|
138
|
|
|
$localSteps[$key] = $stepToMerge; |
|
139
|
|
|
} else { |
|
140
|
|
|
$localSteps[$stepToMerge->getUuid()] = $stepToMerge; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
// set the installation steps |
|
146
|
|
|
$this->getInstallation()->setSteps($localSteps); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|