use of org.glassfish.resourcebase.resources.api.ResourceConflictException in project Payara by payara.
the class ResourceUtilities method resolveResourceDuplicatesConflictsWithinArchive.
/**
* Resolves all duplicates and conflicts within an archive and returns a set
* of resources that needs to be created for the archive being deployed. The
* deployment backend would then use these set of resources to check for
* conflicts with resources existing in domain.xml and then continue
* with deployment.
*
* All resource duplicates within an archive found are flagged with a
* WARNING and only one resource is added in the final <code>Resource</code>
* <code>Set</code> returned.
*
* We currently do not handle any resource conflicts found within the archive
* and the method throws an exception when this condition is detected.
*
* @param sunResList a list of <code>SunResourcesXML</code> corresponding to
* sun-resources.xml found within an archive.
*
* @return a Set of <code>Resource</code>s that have been resolved of
* duplicates and conflicts.
*
* @throws org.glassfish.resources.api.ResourceConflictException an exception is thrown when an archive is found to
* have two or more resources that conflict with each other.
*/
public static Set<org.glassfish.resources.api.Resource> resolveResourceDuplicatesConflictsWithinArchive(List<org.glassfish.resources.admin.cli.SunResourcesXML> sunResList) throws ResourceConflictException {
boolean conflictExist = false;
StringBuilder conflictingResources = new StringBuilder();
Set<org.glassfish.resources.api.Resource> resourceSet = new HashSet<org.glassfish.resources.api.Resource>();
Iterator<org.glassfish.resources.admin.cli.SunResourcesXML> sunResourcesXMLIter = sunResList.iterator();
while (sunResourcesXMLIter.hasNext()) {
// get list of resources from one sun-resources.xml file
org.glassfish.resources.admin.cli.SunResourcesXML sunResXML = sunResourcesXMLIter.next();
List<org.glassfish.resources.api.Resource> resources = sunResXML.getResourcesList();
Iterator<org.glassfish.resources.api.Resource> resourcesIter = resources.iterator();
// for each resource mentioned
while (resourcesIter.hasNext()) {
org.glassfish.resources.api.Resource res = resourcesIter.next();
Iterator<org.glassfish.resources.api.Resource> resSetIter = resourceSet.iterator();
boolean addResource = true;
// check if a duplicate has already been added
while (resSetIter.hasNext()) {
Resource existingRes = resSetIter.next();
if (existingRes.equals(res)) {
// duplicate within an archive
addResource = false;
_logger.warning(localStrings.getString("duplicate.resource.sun.resource.xml", getIdToCompare(res), sunResXML.getXMLPath()));
break;
}
// resource being added
if (existingRes.isAConflict(res)) {
// conflict within an archive
addResource = false;
conflictingResources.append("\n");
String message = localStrings.getString("conflict.resource.sun.resource.xml", getIdToCompare(res), sunResXML.getXMLPath());
conflictingResources.append(message);
_logger.warning(message);
if (_logger.isLoggable(Level.FINE))
logAttributes(res);
}
}
if (addResource)
resourceSet.add(res);
}
}
if (conflictingResources.toString().length() > 0) {
throw new ResourceConflictException(conflictingResources.toString());
}
return resourceSet;
}
use of org.glassfish.resourcebase.resources.api.ResourceConflictException in project Payara by payara.
the class ResourceUtilities method getResourceConflictsWithDomainXML.
/**
* Checks if any of the Resource in the given set has a conflict with
* resource definitions in the domain.xml. A <b> conflict </b> is defined
* based on the type of the resource. For example, a JDBC Resource has "jndi-name"
* that is the identifying key where as for a JDBC Connection Pool, it is
* the "name" that must be unique.
*
* @param resList a Set of Resource elements.
* @param resources all resources from domain.xml
*
* @throws org.glassfish.resources.api.ResourceConflictException an exception is thrown when an archive is found to
* have two or more resources that conflict with resources already present in domain.xml.
*/
public static void getResourceConflictsWithDomainXML(final List<Resource> resList, final Resources resources) throws ResourceConflictException {
if (resList != null) {
Iterator<org.glassfish.resources.api.Resource> iterRes = resList.iterator();
StringBuilder conflictingResources = new StringBuilder();
while (iterRes.hasNext()) {
org.glassfish.resources.api.Resource res = iterRes.next();
final String id = getIdToCompare(res);
if (resources.getResourceByName(res.getClass(), id) != null) {
conflictingResources.append("\n");
String message = localStrings.getString("conflict.resource.with.domain.xml", getIdToCompare(res));
conflictingResources.append(message);
_logger.warning(message);
if (_logger.isLoggable(Level.FINE))
logAttributes(res);
}
}
if (conflictingResources.toString().length() > 0) {
throw new ResourceConflictException(conflictingResources.toString());
}
}
}
Aggregations