Skip to content

Commit

Permalink
Add fallback gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
FloBoJa committed Aug 11, 2024
1 parent a40e645 commit 3080d45
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 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

0 comments on commit 3080d45

Please sign in to comment.