Skip to content

Commit

Permalink
[WFCORE-5382]: The same Additional Runtime Dependency can be added se…
Browse files Browse the repository at this point in the history
…veral times for a single resource definition.

 * Logging a warning if a runtime dependency is added several times.
 * If the extension package is added as an additional runtime dependecy,
   protecting the read-feature operation form this duplication.

Jira: https://issues.redhat.com/browse/WFCORE-5382
  • Loading branch information
ehsavoie committed Apr 29, 2021
1 parent bd300d0 commit ac59c5f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3639,10 +3639,12 @@ OperationFailedRuntimeException capabilityAlreadyRegisteredInContext(String capa
@Message(id = 479, value = "Attribute '%s' at resource '%s' with unresolved value '%s' cannot be resolved using the non-security-sensitive sources resolution supported by the 'resolve' parameter. Response will report the unresolved value.")
String attributeUnresolvableUsingSimpleResolution(String attribute, String address, ModelNode unresolved);

@Message(id = 480, value = "Expression '%s' cannot be resolved using the non-security-sensitive sources resolution supported by the '%s' operatiob. Response will report the unresolved value.")
@Message(id = 480, value = "Expression '%s' cannot be resolved using the non-security-sensitive sources resolution supported by the '%s' operation. Response will report the unresolved value.")
String expressionUnresolvableUsingSimpleResolution(ModelNode unresolved, String opName);


@LogMessage(level = WARN)
@Message(id = 481, value = "The runtime dependency package '%s' is already registered at location '%s'")
void runtimePackageDependencyAlreadyRegistered(String pckg, String location);


}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import java.util.StringJoiner;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Collectors;

import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.CapabilityReferenceRecorder;
Expand Down Expand Up @@ -197,9 +198,12 @@ private void doExecuteInternal(final OperationContext context, final ModelNode o
extensionParam.get(DEFAULT).set(extension);
feature.get(FEATURE).get(PARAMS).add(extensionParam);
ModelNode packages = feature.get(FEATURE).get(PACKAGES);
ModelNode packageNode = new ModelNode();
packageNode.get(PACKAGE).set(extension);
packages.add(packageNode);
Set<String> alreadyRegisteredPackages = packages.isDefined() ? packages.asList().stream().map(node -> node.get(PACKAGE).asString()).collect(Collectors.toSet()) : new HashSet<>();
if (!alreadyRegisteredPackages.contains(extension)) {
ModelNode pkgNode = new ModelNode();
pkgNode.get(PACKAGE).set(extension);
packages.add(pkgNode);
}
}
}
final Map<PathElement, ModelNode> childResources = recursive ? new HashMap<>() : Collections.<PathElement, ModelNode>emptyMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final class ConcreteResourceRegistration extends AbstractResourceRegistration {
private final Lock readLock;
private final Lock writeLock;

private Set<RuntimePackageDependency> additionalPackages;
private Map<String, RuntimePackageDependency> additionalPackages;

/** Constructor for a root MRR */
ConcreteResourceRegistration(final ResourceDefinition definition,
Expand Down Expand Up @@ -708,10 +708,14 @@ public void registerCapability(RuntimeCapability capability) {
Set<String> packages = capability.getAdditionalRequiredPackages();
if (!packages.isEmpty()) {
if (additionalPackages == null) {
additionalPackages = new HashSet<>();
additionalPackages = new HashMap<>();
}
for (String pkg : packages) {
additionalPackages.add(RuntimePackageDependency.required(pkg));
if (additionalPackages.containsKey(pkg)) {
ControllerLogger.ROOT_LOGGER.runtimePackageDependencyAlreadyRegistered(pkg, getLocationString());
} else {
additionalPackages.put(pkg, RuntimePackageDependency.required(pkg));
}
}
}
} finally {
Expand Down Expand Up @@ -1019,10 +1023,14 @@ public void registerAdditionalRuntimePackages(RuntimePackageDependency... pkgs)
writeLock.lock();
try {
if (additionalPackages == null) {
additionalPackages = new HashSet<>();
additionalPackages = new HashMap<>();
}
for (RuntimePackageDependency pkg : pkgs) {
additionalPackages.add(pkg);
if(additionalPackages.containsKey(pkg.getName())) {
ControllerLogger.ROOT_LOGGER.runtimePackageDependencyAlreadyRegistered(pkg.getName(), getLocationString());
} else {
additionalPackages.put(pkg.getName(), pkg);
}
}
} finally {
writeLock.unlock();
Expand All @@ -1034,7 +1042,7 @@ public Set<RuntimePackageDependency> getAdditionalRuntimePackages() {
checkPermission();
readLock.lock();
try {
return additionalPackages == null ? Collections.emptySet() : Collections.unmodifiableSet(additionalPackages);
return additionalPackages == null ? Collections.emptySet() : Collections.unmodifiableSet(new HashSet<RuntimePackageDependency>(additionalPackages.values()));
} finally {
readLock.unlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import static org.wildfly.common.Assert.checkNotNullParamWithNullPointerException;

import java.util.Objects;


/**
* A runtime package dependency expresses a dependency to a galleon package. A
Expand All @@ -34,6 +36,7 @@
* @author jdenise@redhat.com
*/
public final class RuntimePackageDependency {

private enum TYPE {
REQUIRED,
OPTIONAL,
Expand Down Expand Up @@ -114,4 +117,38 @@ public static RuntimePackageDependency required(String name) {
public static RuntimePackageDependency optional(String name) {
return new RuntimePackageDependency(name, TYPE.OPTIONAL);
}

@Override
public int hashCode() {
int hash = 7;
hash = 71 * hash + Objects.hashCode(this.name);
hash = 71 * hash + Objects.hashCode(this.type);
return hash;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final RuntimePackageDependency other = (RuntimePackageDependency) obj;
if (!Objects.equals(this.name, other.name)) {
return false;
}
if (this.type != other.type) {
return false;
}
return true;
}

@Override
public String toString() {
return "RuntimePackageDependency{" + "name=" + name + ", type=" + type + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ private static class MainResourceDefinition extends SimpleResourceDefinition {

private static final RuntimeCapability MAIN_RESOURCE_CAPABILITY =
RuntimeCapability.Builder.of(MAIN_RESOURCE_CAPABILITY_NAME, true)
.addAdditionalRequiredPackages(MAIN_RESOURCE_PACKAGE_NAME)
.addAdditionalRequiredPackages(MAIN_RESOURCE_PACKAGE_NAME, MAIN_RESOURCE_PACKAGE_NAME)
.build();

private static final AttributeDefinition OPTIONAL_ATTRIBUTE =
Expand Down

0 comments on commit ac59c5f

Please sign in to comment.