X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=engine-d%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fholmes%2Fengine%2Fresources%2FEngineResources.java;h=4088d72315b55c4c698c1c60702c969b19a06509;hb=d70f48853bf9ab690f3019b1682c422a6854fd8b;hp=97243554b8946e164bda83dff86103b426f2ad10;hpb=530fcc3970550c2ddbe62f51c59b9705cbaa244b;p=holmes%2Fengine-management.git 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..4088d72 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 @@ -21,6 +21,9 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.DELETE; @@ -48,7 +51,8 @@ import org.onap.holmes.engine.response.CorrelationRuleResponse; @Produces(MediaType.APPLICATION_JSON) @Slf4j public class EngineResources { - + private Pattern packagePattern = Pattern.compile("package[\\s]+([^;]+)[;\\s]*"); + @Inject DroolsEngine droolsEngine; @@ -58,23 +62,37 @@ public class EngineResources { @Timed public CorrelationRuleResponse deployRule( @ApiParam(value = "The request entity of the HTTP call, which comprises three " - + "fields: \"content\" , \"loopcontrolname\" and \"engineid\". " - + "The \"content\" should be a valid Drools rule string and the \"engineid\" " + + "fields: \"content\" , \"loopControlName\" and \"engineId\". " + + "The \"content\" should be a valid Drools rule string and the \"engineId\" " + "has to be \"engine-d\" in the Amsterdam release.", required = true) DeployRuleRequest deployRuleRequest, @Context HttpServletRequest httpRequest) { CorrelationRuleResponse crResponse = new CorrelationRuleResponse(); Locale locale = LanguageUtil.getLocale(httpRequest); try { - String packageName = droolsEngine.deployRule(deployRuleRequest, locale); + String packageName = getPackageName(deployRuleRequest.getContent()); + if(packageName == null) { + throw new CorrelationException("Could not find package name in rule: "+deployRuleRequest.getContent()); + } + DmaapService.loopControlNames .put(packageName, deployRuleRequest.getLoopControlName()); - log.info("Rule deployed. Package name: " + packageName); - crResponse.setPackageName(packageName); + 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: " + packageNameRet); + crResponse.setPackageName(packageNameRet); } 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 +109,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 +136,14 @@ public class EngineResources { } return true; } + + private String getPackageName(String contents){ + Matcher m = packagePattern.matcher(contents); + + if (m.find( )) { + return m.group(1); + }else { + return null; + } + } }