Skip to content

Commit

Permalink
Merge pull request #95 from PalladioSimulator/fallback_gateway
Browse files Browse the repository at this point in the history
Add gateway fallback
  • Loading branch information
FloBoJa authored Aug 28, 2024
2 parents a40e645 + 31f0dc3 commit 6b42ab8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class EcmaScriptRules implements Rule {
public static final String ECMASCRIPT_DISCOVERER_ID = "org.palladiosimulator.retriever.extraction.discoverers.ecmascript"
public static final String HOSTNAMES_ID = "org.palladiosimulator.retriever.extraction.rules.ecmascript.hostnames"
public static final String GATEWAY_ROUTES_ID = "org.palladiosimulator.retriever.extraction.rules.ecmascript.routes"
public static final String DONE_ID = "org.palladiosimulator.retriever.extraction.rules.ecmascript.done"

static final CompUnitOrName GATEWAY_NAME = new CompUnitOrName("Gateway")
static final String START_NONWORD_CHARS = "^[\\W]+"
Expand All @@ -46,9 +47,13 @@ class EcmaScriptRules implements Rule {
static final String BLANK = ""

override processRules(RetrieverBlackboard blackboard, Path path) {
if (blackboard.hasPartition(DONE_ID)) return

val compilationUnits = blackboard.getDiscoveredFiles(ECMASCRIPT_DISCOVERER_ID, typeof(CompilationUnitTree))
val compilationUnit = compilationUnits.get(path)
if(compilationUnit === null) return
if (compilationUnit === null && !compilationUnits.empty) {
return
}

var gatewayRouteMap = blackboard.getPartition(GATEWAY_ROUTES_ID) as Map<Path, List<GatewayRoute>>
if (gatewayRouteMap === null) {
Expand Down Expand Up @@ -77,17 +82,32 @@ class EcmaScriptRules implements Rule {
mostSpecificHostnamePath = hostnamePath
}
}


var httpRequests = Map.of
val pcmDetector = blackboard.getPCMDetector as PCMDetector
val httpRequests = findAllHttpRequests(blackboard, compilationUnit)
for (key : httpRequests.keySet) {
for (url : httpRequests.get(key)) {
val mappedURL = mapURL(hostname, "/" + url, gatewayRoutes)
if (!compilationUnits.empty) {
httpRequests = findAllHttpRequests(blackboard, compilationUnit)
for (key : httpRequests.keySet) {
for (url : httpRequests.get(key)) {
val mappedURL = mapURL(hostname, "/" + url, gatewayRoutes)
if (!mappedURL.isPartOf("/" + hostname)) {
pcmDetector.detectCompositeRequiredInterface(GATEWAY_NAME, mappedURL)
}
pcmDetector.detectProvidedOperation(GATEWAY_NAME, null, new RESTOperationName(hostname, "/" + url))
}
}
}

// Require all routes if no requests could be parsed
if (httpRequests.empty) {
for (route : gatewayRoutes) {
val mappedURL = new RESTName(route.targetHost, "/")
if (!mappedURL.isPartOf("/" + hostname)) {
pcmDetector.detectRequiredInterface(GATEWAY_NAME, mappedURL)
pcmDetector.detectCompositeRequiredInterface(GATEWAY_NAME, mappedURL)
}
pcmDetector.detectProvidedOperation(GATEWAY_NAME, null, new RESTOperationName(hostname, "/" + url))
pcmDetector.detectProvidedOperation(GATEWAY_NAME, null, new RESTOperationName(hostname, "/"))
}
blackboard.addPartition(DONE_ID, true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import org.palladiosimulator.retriever.services.Rule

class JaxRSDeploymentRules implements Rule {
public static final String RULE_ID = "org.palladiosimulator.retriever.extraction.rules.jax_rs.deployment"
public static final String DONE_ID = "org.palladiosimulator.retriever.extraction.rules.jax_rs.deployment.done"
public static final String XML_DISCOVERER_ID = "org.palladiosimulator.retriever.extraction.discoverers.xml"
public static final String JAVA_DISCOVERER_ID = "org.palladiosimulator.retriever.extraction.discoverers.java";
public static final String ECMASCRIPT_RULE_ID = "org.palladiosimulator.retriever.extraction.rules.ecmascript"
public static final String ECMASCRIPT_ROUTES_ID = "org.palladiosimulator.retriever.extraction.rules.ecmascript.routes"
public static final String ECMASCRIPT_HOSTNAMES_ID = "org.palladiosimulator.retriever.extraction.rules.ecmascript.hostnames"

override processRules(RetrieverBlackboard blackboard, Path path) {
// TODO: run only once per project
if (blackboard.hasPartition(DONE_ID)) return
val xmls = blackboard.getDiscoveredFiles(XML_DISCOVERER_ID, typeof(Document))

var Map<Path, String> hostnames = new HashMap();
Expand Down Expand Up @@ -107,6 +108,8 @@ class JaxRSDeploymentRules implements Rule {
if (!blackboard.hasPartition(ECMASCRIPT_HOSTNAMES_ID)) {
blackboard.addPartition(ECMASCRIPT_HOSTNAMES_ID, hostnameMap)
}

blackboard.addPartition(DONE_ID, true)
}

override isBuildRule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ public Composite construct(final Collection<Component> allComponents, final Requ
.warn("Chose name " + chosenPrefix + " supported by " + maxSupport + "/" + parts.size() + " parts.");

final Set<OperationInterface> externalRequirements = requirements.stream()
.filter(x -> compositeRequirements.containsEntire(x))
.filter(x -> compositeRequirements.containsEntire(x) || compositeProvisions.containsEntire(x))
.collect(Collectors.toSet());

final Set<OperationInterface> externalProvisions = MapMerger.merge(provisions)
.entrySet()
.stream()
.filter(entry -> entry.getValue()
.stream()
.anyMatch(operation -> compositeProvisions.containsEntire(operation)))
.anyMatch(operation -> compositeRequirements.containsEntire(operation) || compositeProvisions.containsEntire(operation)))
.map(entry -> entry.getKey())
.collect(Collectors.toSet());

Expand Down

0 comments on commit 6b42ab8

Please sign in to comment.