From 3080d456bf9f015fec9c2e477d13850b6756534b Mon Sep 17 00:00:00 2001 From: Florian Bossert Date: Sun, 11 Aug 2024 20:07:57 +0200 Subject: [PATCH] Add fallback gateway --- .../extraction/rules/EcmaScriptRules.xtend | 36 ++++++++++++++----- .../rules/JaxRSDeploymentRules.xtend | 5 ++- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend index fce112f5..bc728cc2 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/EcmaScriptRules.xtend @@ -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]+" @@ -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> if (gatewayRouteMap === null) { @@ -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) } } diff --git a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/JaxRSDeploymentRules.xtend b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/JaxRSDeploymentRules.xtend index 1f984aa2..af46755c 100644 --- a/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/JaxRSDeploymentRules.xtend +++ b/bundles/org.palladiosimulator.retriever.extraction.rules/src/org/palladiosimulator/retriever/extraction/rules/JaxRSDeploymentRules.xtend @@ -17,6 +17,7 @@ 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" @@ -24,7 +25,7 @@ class JaxRSDeploymentRules implements Rule { 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 hostnames = new HashMap(); @@ -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() {