final Set<String> ourServerGroups = getOurServerGroups(context);
final Map<String, Set<byte[]>> deploymentHashes = new HashMap<String, Set<byte[]>>();
final Set<String> relevantDeployments = new HashSet<String>();
final Set<byte[]> requiredContent = new HashSet<byte[]>();
final Resource rootResource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
clearDomain(rootResource);
for (final ModelNode resourceDescription : domainModel.asList()) {
final PathAddress resourceAddress = PathAddress.pathAddress(resourceDescription.require("domain-resource-address"));
if (ignoredResourceRegistry.isResourceExcluded(resourceAddress)) {
continue;
}
final Resource resource = getResource(resourceAddress, rootResource, context);
if (resourceAddress.size() == 1 && resourceAddress.getElement(0).getKey().equals(EXTENSION)) {
final String module = resourceAddress.getElement(0).getValue();
if (!appliedExtensions.contains(module)) {
appliedExtensions.add(module);
initializeExtension(module);
}
}
resource.writeModel(resourceDescription.get("domain-resource-model"));
// Track deployment and management content hashes and server group deployments so we can pull over the content we need
if (resourceAddress.size() == 1) {
PathElement pe = resourceAddress.getElement(0);
String peKey = pe.getKey();
if (peKey.equals(DEPLOYMENT)) {
ModelNode model = resource.getModel();
String id = resourceAddress.getElement(0).getValue();
if (model.hasDefined(CONTENT)) {
for (ModelNode contentItem : model.get(CONTENT).asList()) {
if (contentItem.hasDefined(HASH)) {
Set<byte[]> hashes = deploymentHashes.get(id);
if (hashes == null) {
hashes = new HashSet<byte[]>();
deploymentHashes.put(id, hashes);
}
hashes.add(contentItem.get(HASH).asBytes());
}
}
}
} else if (peKey.equals(MANAGEMENT_CLIENT_CONTENT)) {
// We need to pull over management content from the master HC's repo
ModelNode model = resource.getModel();
if (model.hasDefined(HASH)) {
requiredContent.add(model.get(HASH).asBytes());
}
}
} else if (resourceAddress.size() == 2
&& resourceAddress.getElement(0).getKey().equals(SERVER_GROUP)
&& ourServerGroups.contains(resourceAddress.getElement(0).getValue())
&& resourceAddress.getElement(1).getKey().equals(DEPLOYMENT)) {
relevantDeployments.add(resourceAddress.getElement(1).getValue());
}
}
// Make sure we have all needed deployment and management client content
for (String id : relevantDeployments) {
Set<byte[]> hashes = deploymentHashes.remove(id);
if (hashes != null) {
requiredContent.addAll(hashes);
}
}
for (byte[] hash : requiredContent) {
fileRepository.getDeploymentFiles(hash);
}
if (!context.isBooting()) {
final Resource domainRootResource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
final ModelNode endRoot = Resource.Tools.readModel(domainRootResource);
final Set<ServerIdentity> affectedServers = new HashSet<ServerIdentity>();
final ModelNode hostModel = endRoot.require(HOST).asPropertyList().iterator().next().getValue();
final ModelNode existingHostModel = startRoot.require(HOST).asPropertyList().iterator().next().getValue();