This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
/
WildflyPatchBundleServerPluginComponent.java
205 lines (172 loc) · 9.59 KB
/
WildflyPatchBundleServerPluginComponent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* RHQ Management Platform
* Copyright (C) 2014-2016 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.rhq.enterprise.server.plugins.wflypatch;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
import org.rhq.common.wildfly.Patch;
import org.rhq.common.wildfly.PatchBundle;
import org.rhq.common.wildfly.PatchInfo;
import org.rhq.common.wildfly.PatchParser;
import org.rhq.common.wildfly.PatchProductType;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.domain.configuration.definition.PropertySimpleType;
import org.rhq.core.util.updater.DeploymentProperties;
import org.rhq.core.util.updater.DestinationComplianceMode;
import org.rhq.enterprise.server.bundle.BundleDistributionInfo;
import org.rhq.enterprise.server.bundle.RecipeParseResults;
import org.rhq.enterprise.server.plugin.pc.ServerPluginComponent;
import org.rhq.enterprise.server.plugin.pc.ServerPluginContext;
import org.rhq.enterprise.server.plugin.pc.bundle.BundleServerPluginFacet;
import org.rhq.enterprise.server.plugin.pc.bundle.UnknownRecipeException;
/**
* @author Lukas Krejci
* @since 4.13
*/
public class WildflyPatchBundleServerPluginComponent implements ServerPluginComponent, BundleServerPluginFacet {
@Override
public RecipeParseResults parseRecipe(String recipe) throws UnknownRecipeException {
throw new UnknownRecipeException(
"The Wildfly patches cannot be dealt with using only recipes - the whole distribution file is needed.");
}
@Override
public BundleDistributionInfo processBundleDistributionFile(File distributionFile)
throws Exception {
if (null == distributionFile) {
throw new IllegalArgumentException("distributionFile == null");
}
String fileName = null;
String recipe = null;
RecipeParseResults parseResults = null;
FileInputStream in = new FileInputStream(distributionFile);
try {
PatchInfo patchInfo = PatchParser.parse(in, true);
if (patchInfo == null) {
throw new UnknownRecipeException();
}
if (patchInfo.is(Patch.class)) {
Patch patch = patchInfo.as(Patch.class);
if(PatchProductType.EAP7.equals(patch.getProductType())) {
throw new UnknownRecipeException();
}
String version = patch.getType() == Patch.Type.ONE_OFF ? patch.getTargetVersion() + "+" + patch.getId()
: patch.getTargetVersion();
DeploymentProperties props = new DeploymentProperties(0, patch.getIdentityName(),
version, patch.getDescription(), DestinationComplianceMode.full);
ConfigurationDefinition config = new ConfigurationDefinition("wildfly-patch", null);
PropertyDefinitionSimple patchIdProp = new PropertyDefinitionSimple("patchId", "The ID of the patch",
true,
PropertySimpleType.STRING);
patchIdProp.setDefaultValue(patch.getId());
patchIdProp.setReadOnly(true);
PropertyDefinitionSimple patchTypeProp = new PropertyDefinitionSimple("patchType",
"The type of the patch",
true, PropertySimpleType.STRING);
patchTypeProp.setDefaultValue(patch.getType().toString());
patchTypeProp.setReadOnly(true);
config.put(patchIdProp);
config.put(patchTypeProp);
addCommonProperties(config);
parseResults = new RecipeParseResults(props, config, null);
fileName = patch.getId();
recipe = patch.getContents();
} else if (patchInfo.is(PatchBundle.class)) {
PatchBundle patchBundle = patchInfo.as(PatchBundle.class);
Patch lastPatch = null;
StringBuilder allPatchIds = new StringBuilder();
for (PatchBundle.Element p : patchBundle) {
lastPatch = p.getPatch();
allPatchIds.append(p.getPatch().getId()).append("#");
}
allPatchIds.replace(allPatchIds.length() - 1, allPatchIds.length(), "");
if (lastPatch == null) {
throw new UnknownRecipeException("Not a Wildfly patch");
} else if (PatchProductType.EAP7.equals(lastPatch.getProductType())) {
throw new UnknownRecipeException();
}
DeploymentProperties props = new DeploymentProperties(0, lastPatch.getIdentityName(),
lastPatch.getTargetVersion(), lastPatch.getDescription(), DestinationComplianceMode.full);
ConfigurationDefinition config = new ConfigurationDefinition("wildfly-patch", null);
PropertyDefinitionSimple allPatchIdsProp = new PropertyDefinitionSimple("allPatchIds",
"Hash-separated list of all individual patches the patch bundle is composed of.", true,
PropertySimpleType.STRING);
allPatchIdsProp.setDefaultValue(allPatchIds.toString());
allPatchIdsProp.setReadOnly(true);
PropertyDefinitionSimple patchTypeProp = new PropertyDefinitionSimple("patchType",
"The type of the patch", true, PropertySimpleType.STRING);
patchTypeProp.setDefaultValue("patch-bundle");
patchTypeProp.setReadOnly(true);
config.put(allPatchIdsProp);
config.put(patchTypeProp);
addCommonProperties(config);
parseResults = new RecipeParseResults(props, config, null);
fileName = lastPatch.getIdentityName();
recipe = patchBundle.getContents();
}
} finally {
in.close();
}
fileName += ".zip";
Map<String, File> patchFiles = new HashMap<String, File>();
patchFiles.put(fileName, distributionFile);
return new BundleDistributionInfo(recipe, parseResults, patchFiles);
}
void addCommonProperties(ConfigurationDefinition config) {
PropertyDefinitionSimple overrideProp = new PropertyDefinitionSimple("override",
"The value is a comma-separated list of the miscellaneous items in the patch that can be overridden on the server whether the item reports a conflict or not.",
false, PropertySimpleType.LONG_STRING);
PropertyDefinitionSimple overrideAllProp = new PropertyDefinitionSimple("override-all",
"The argument does not expect any value and is optional. The default is 'false'. It signifies to bypass any content verification on the miscellaneous items changed by the patch.",
false, PropertySimpleType.BOOLEAN);
PropertyDefinitionSimple overrideModules = new PropertyDefinitionSimple("override-modules",
"The argument does not expect any value and is optional. The default is 'false'. It signifies to bypass any content verification on the modules and OSGi bundles affected by the patch.",
false, PropertySimpleType.LONG_STRING);
PropertyDefinitionSimple preserve = new PropertyDefinitionSimple("preserve",
"The value is a comma-separated list of the miscellaneous items that must be preserved and not modified by applying or rolling back a patch.",
false, PropertySimpleType.LONG_STRING);
PropertyDefinitionSimple restart = new PropertyDefinitionSimple("restart",
"This only applies if the server being deployed to is running. When true, the server is stopped before the patch application and started back up afterwards.",
true, PropertySimpleType.BOOLEAN);
restart.setDefaultValue(Boolean.toString(true));
PropertyDefinitionSimple takeOver = new PropertyDefinitionSimple("takeOver",
"Set this to true ONLY in cases where you want this destination to become the new originating destination for the patch deployments to the servers in the resource group. Each server can have at most 1 originating destination for its patch deployments at a time. As an example, you might want to use this in cases where a destination that was used for prior patch deployments was deleted, yet the target servers weren't purged and thus still relate to the deleted destination as their originating destination.",
true, PropertySimpleType.BOOLEAN);
takeOver.setDefaultValue(Boolean.toString(false));
config.put(overrideProp);
config.put(overrideAllProp);
config.put(overrideModules);
config.put(preserve);
config.put(restart);
config.put(takeOver);
}
@Override
public void initialize(ServerPluginContext context) throws Exception {
}
@Override
public void start() {
}
@Override
public void stop() {
}
@Override
public void shutdown() {
}
}