private void getProfiles(Map<String, ProfileElement> profiles, String name) { if (profiles.containsKey(name)) return; ProfileElement pe = getProfile(name); if (pe == null) { throw new IllegalArgumentException("Profile " + name + " is unknown"); } profiles.put(name, pe); for (String included : pe.getIncludedProfiles()) { getProfiles(profiles, included); } }
private static RuntimeException findDuplicateProfile(String namespaceURI, String currentProfile, Set<String> processedProfiles, DomainModel domainModel) { String duplicate = null; for (String profile : processedProfiles) { if (profile.equals(currentProfile)) { continue; } ProfileElement pe = domainModel.getProfile(profile); if (pe.getSubsystem(namespaceURI) != null) { duplicate = profile; break; } } return new IllegalStateException(String.format("Subsystem with namespace %s " + "is declared in multiple profiles that are related to each " + "other via inclusion. Profiles are %s and %s. A subsystem can " + "only appear once in a given server runtime, so declaring the " + "same subsystem in multiple related profiles is illegal.", namespaceURI, duplicate, currentProfile)); }
@Override protected void applyUpdate(final DomainModel element) throws UpdateFailedException { final ProfileElement profileElement = element.getProfile(profileName); if (profileElement == null) { throw new UpdateFailedException("Profile '" + profileName + "' is not configured on this domain"); } subsystemRemove.applyUpdate(profileElement); }
@Override public DomainSubsystemAdd getCompensatingUpdate(final DomainModel original) { return new DomainSubsystemAdd(profileName, subsystemRemove.getCompensatingUpdate(original.getProfile(profileName))); }
@Override public DomainSubsystemRemove getCompensatingUpdate(final DomainModel original) { return new DomainSubsystemRemove(profileName, subsystemAdd.getCompensatingUpdate(original.getProfile(profileName))); }
@Override protected void applyUpdate(final DomainModel element) throws UpdateFailedException { ProfileElement pe = element.getProfile(profileName); if (pe == null) { throw new UpdateFailedException("Profile '" + profileName + "' does not exist"); } if (! pe.removeIncludedProfile(includedProfileName)) { throw new UpdateFailedException("Profile '" + profileName + "' does not include profile '" + includedProfileName +"'"); } }
@Override public AbstractDomainModelUpdate<?> getCompensatingUpdate(final DomainModel original) { final String namespaceUri = update.getSubsystemNamespaceUri(); final E element = update.getModelElementType().cast(original.getProfile(profileName).getSubsystem(namespaceUri)); if (element == null) { throw new IllegalArgumentException("No such subsystem '" + namespaceUri + "' declared on profile '" + profileName + "'"); } final AbstractSubsystemUpdate<E, ?> compensatingUpdate = update.getCompensatingUpdate(element); return createUpdate(profileName, compensatingUpdate); }
@Override protected void applyUpdate(final DomainModel element) throws UpdateFailedException { ProfileElement pe = element.getProfile(profileName); if (pe == null) { throw new UpdateFailedException("Profile '" + profileName + "' does not exist"); } if (! pe.addIncludedProfile(includedProfileName)) { throw new UpdateFailedException("Profile '" + profileName + "' already includes profile '" + includedProfileName +"'"); } }
@Override protected void applyUpdate(final DomainModel element) throws UpdateFailedException { final ProfileElement profileElement = element.getProfile(profileName); final String namespaceUri = update.getSubsystemNamespaceUri(); final E subsystemElement = update.getModelElementType().cast(profileElement.getSubsystem(namespaceUri)); if (subsystemElement == null) { throw new UpdateFailedException("No such subsystem '" + namespaceUri + "' declared on profile '" + profileName + "'"); } update.applyUpdate(subsystemElement); }
@Override protected void applyUpdate(final DomainModel element) throws UpdateFailedException { final String namespaceUri = subsystemAdd.getNamespaceUri(); if (! element.getProfile(profileName).addSubsystem(namespaceUri, subsystemAdd.createSubsystemElement())) { throw new UpdateFailedException("Subsystem '" + namespaceUri + "' is already configured in profile '" + profileName + "'"); } }
@Override protected void applyUpdate(final DomainModel element) throws UpdateFailedException { // Validate empty ProfileElement pe = element.getProfile(profileName); if (pe != null && (pe.getIncludedProfiles().size() > 0 || pe.getSubsystems().size() > 0)) { throw new UpdateFailedException("Profile '" + profileName + "' is not empty and cannot be removed"); } // Validate unused StringBuilder illegal = null; for (String serverGroupName : element.getServerGroupNames()) { ServerGroupElement sge = element.getServerGroup(serverGroupName); if (profileName.equals(sge.getName())) { if (illegal == null) { illegal = new StringBuilder(sge.getName()); } else { illegal.append(", "); illegal.append(sge.getName()); } } } if (illegal != null) { throw new UpdateFailedException(String.format("Profile %s cannot be removed as it is still used by server groups %s", profileName, illegal.toString())); } element.removeProfile(profileName); }
private static void processProfile(DomainModel domainModel, ProfileElement profile, List<AbstractServerModelUpdate<?>> list, Set<String> processedProfiles, Set<String> processedSubsystems) { if (! processedProfiles.add(profile.getName())) { // we already hit this one via another path return; } // Parent profile subsystems first for (String included : profile.getIncludedProfiles()) { processProfile(domainModel, domainModel.getProfile(included), list, processedProfiles, processedSubsystems); } for (AbstractSubsystemElement<? extends AbstractSubsystemElement<?>> subsystemElement : profile.getSubsystems()) { String namespaceURI = subsystemElement.getElementName().getNamespaceURI(); if (processedSubsystems.contains(namespaceURI)) { // FIXME catch this problem in domain model parsing throw findDuplicateProfile(namespaceURI, profile.getName(), processedProfiles, domainModel); } // todo: find a better way around this generics issue processSubsystem((AbstractSubsystemElement) subsystemElement, list); processedSubsystems.add(namespaceURI); } }
final ProfileElement leafProfile = domainModel.getProfile(profileName); if (profileName == null) { throw new IllegalArgumentException("Domain model does not contain a profile named '" + profileName + "'");