diff options
author | Guangrong Fu <fu.guangrong@zte.com.cn> | 2017-11-10 22:58:18 +0800 |
---|---|---|
committer | Guangrong Fu <fu.guangrong@zte.com.cn> | 2017-11-10 22:58:18 +0800 |
commit | ea08755cd8354a8fe6f30a2797cb5bb3ccb63da8 (patch) | |
tree | aca3dee8351a698d9b74ab5a692afb6f68bd3a26 | |
parent | 0cd31c398821790857c9f4862df35f684eab52fc (diff) |
Cache the CL Name before rule Deploymentv1.0.02.0.0-ONAP1.0.0-ONAP1.0.0-Amsterdambeijing2.0.0-ONAP
Change-Id: I8d0efeaa01eea6163194c86e309e17367fb178db
Issue-ID: HOLMES-85
Signed-off-by: Guangrong Fu <fu.guangrong@zte.com.cn>
-rw-r--r-- | engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java | 24 | ||||
-rw-r--r-- | engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java | 1 |
2 files changed, 22 insertions, 3 deletions
diff --git a/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java b/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java index 9724355..b4cb0b1 100644 --- a/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java +++ b/engine-d/src/main/java/org/onap/holmes/engine/resources/EngineResources.java @@ -20,6 +20,9 @@ import com.codahale.metrics.annotation.Timed; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; import java.util.Locale; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; @@ -66,15 +69,25 @@ public class EngineResources { CorrelationRuleResponse crResponse = new CorrelationRuleResponse(); Locale locale = LanguageUtil.getLocale(httpRequest); try { - String packageName = droolsEngine.deployRule(deployRuleRequest, locale); + String packageName = getPackageName(deployRuleRequest.getContent()); DmaapService.loopControlNames .put(packageName, deployRuleRequest.getLoopControlName()); + String packageNameRet = droolsEngine.deployRule(deployRuleRequest, locale); + if (!packageName.equals(packageNameRet)) { + log.info("The parsed package name is different from that returned by the engine."); + DmaapService.loopControlNames.remove(packageName); + DmaapService.loopControlNames + .put(packageNameRet, deployRuleRequest.getLoopControlName()); + } log.info("Rule deployed. Package name: " + packageName); crResponse.setPackageName(packageName); } catch (CorrelationException correlationException) { log.error(correlationException.getMessage(), correlationException); throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage()); + } catch (RuntimeException e) { + log.error(e.getMessage(), e); + throw ExceptionUtil.buildExceptionResponse(e.getMessage()); } return crResponse; @@ -91,9 +104,8 @@ public class EngineResources { Locale locale = LanguageUtil.getLocale(httpRequest); try { - droolsEngine.undeployRule(packageName, locale); - + DmaapService.loopControlNames.remove(packageName); } catch (CorrelationException correlationException) { log.error(correlationException.getMessage(), correlationException); throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage()); @@ -119,4 +131,10 @@ public class EngineResources { } return true; } + + private String getPackageName(String contents){ + String ret = contents.trim(); + ret = ret.substring(7, ret.indexOf("import")).trim(); + return ret.endsWith(";") ? ret.substring(0, ret.length() - 1) : ret; + } } diff --git a/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java b/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java index 98f4797..6be232f 100644 --- a/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java +++ b/engine-d/src/test/java/org/onap/holmes/engine/resources/EngineResourcesTest.java @@ -66,6 +66,7 @@ public class EngineResourcesTest { @Test
public void deployRule_normal() throws CorrelationException {
DeployRuleRequest deployRuleRequest = new DeployRuleRequest();
+ deployRuleRequest.setContent("package packageName;\n\nimport xxx.xxx.xxx;");
deployRuleRequest.setLoopControlName("loopControlName");
HttpServletRequest httpRequest = PowerMock.createMock(HttpServletRequest.class);
|