diff options
author | FengLiang <feng.liang1@zte.com.cn> | 2017-02-21 14:17:15 +0800 |
---|---|---|
committer | FengLiang <feng.liang1@zte.com.cn> | 2017-02-21 14:17:15 +0800 |
commit | 350402a45fbf6f2beda430a2bad9f2f253c32685 (patch) | |
tree | 4766083b18921ca18e2a7bc4d950055dd06c2f72 /engine-d | |
parent | f7907354daf58f6a729556e21ba01cae777de0be (diff) |
Modify exception
remove EngineException and RuleIllegalityException modify CorrelationException
Change-Id: Ic19035b11a377c3492fae1f195d008f8e85faabc
Issue-ID:HOLMES-19
Signed-off-by: FengLiang <feng.liang1@zte.com.cn>
Diffstat (limited to 'engine-d')
-rw-r--r-- | engine-d/src/main/java/org/openo/holmes/enginemgt/manager/DroolsEngine.java | 44 | ||||
-rw-r--r-- | engine-d/src/main/java/org/openo/holmes/enginemgt/resources/EngineResources.java | 47 |
2 files changed, 44 insertions, 47 deletions
diff --git a/engine-d/src/main/java/org/openo/holmes/enginemgt/manager/DroolsEngine.java b/engine-d/src/main/java/org/openo/holmes/enginemgt/manager/DroolsEngine.java index 69fe748..ae2ba11 100644 --- a/engine-d/src/main/java/org/openo/holmes/enginemgt/manager/DroolsEngine.java +++ b/engine-d/src/main/java/org/openo/holmes/enginemgt/manager/DroolsEngine.java @@ -49,6 +49,7 @@ import org.openo.holmes.common.api.entity.CorrelationRule; import org.openo.holmes.common.api.stat.Alarm; import org.openo.holmes.common.config.MQConfig; import org.openo.holmes.common.constant.AlarmConst; +import org.openo.holmes.common.exception.CorrelationException; import org.openo.holmes.common.exception.DbException; import org.openo.holmes.common.exception.EngineException; import org.openo.holmes.common.exception.RuleIllegalityException; @@ -167,7 +168,7 @@ public class DroolsEngine { } public synchronized String deployRule(DeployRuleRequest rule, Locale locale) - throws RuleIllegalityException, EngineException { + throws CorrelationException { StringReader reader = new StringReader(rule.getContent()); Resource res = ResourceFactory.newReaderResource(reader); @@ -176,20 +177,31 @@ public class DroolsEngine { kbuilder.add(res, ResourceType.DRL); if (kbuilder.hasErrors()) { - throw new RuleIllegalityException(kbuilder.getErrors().toString()); + + String errorMsg = I18nProxy.getInstance().getValueByArgs(locale, + I18nProxy.ENGINE_CONTENT_ILLEGALITY, + new String[]{kbuilder.getErrors().toString()}); + throw new CorrelationException(errorMsg); } String packageName = kbuilder.getKnowledgePackages().iterator().next().getName(); if (kbase.getKnowledgePackages().contains(packageName)) { - throw new RuleIllegalityException( - I18nProxy.getInstance().getValue(locale, I18nProxy.ENGINE_CONTAINS_PACKAGE)); + + String errorMsg = I18nProxy.getInstance().getValueByArgs(locale, + I18nProxy.ENGINE_CONTENT_ILLEGALITY,new String[]{ + I18nProxy.getInstance().getValue(locale, I18nProxy.ENGINE_CONTAINS_PACKAGE)}); + + throw new CorrelationException(errorMsg); } try { kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); } catch (Exception e) { - throw new EngineException(e); + + String errorMsg = + I18nProxy.getInstance().getValue(locale, I18nProxy.ENGINE_DEPLOY_RULE_FAILED); + throw new CorrelationException(errorMsg, e); } kbuilder = null; @@ -199,26 +211,30 @@ public class DroolsEngine { } - public synchronized void undeployRule(String packageName) - throws RuleIllegalityException, EngineException { + public synchronized void undeployRule(String packageName, Locale locale) + throws CorrelationException { KnowledgePackage pkg = kbase.getKnowledgePackage(packageName); if (null == pkg) { - throw new RuleIllegalityException(packageName); + String errorMsg = I18nProxy.getInstance().getValueByArgs(locale, + I18nProxy.ENGINE_DELETE_RULE_NULL, + new String[]{packageName}); + throw new CorrelationException(errorMsg); } try { kbase.removeKnowledgePackage(pkg.getName()); } catch (Exception e) { - - throw new EngineException(e); + String errorMsg = I18nProxy.getInstance().getValueByArgs(locale, + I18nProxy.ENGINE_DELETE_RULE_FAILED, new String[]{packageName}); + throw new CorrelationException(errorMsg, e); } } public void compileRule(String content, Locale locale) - throws RuleIllegalityException { + throws CorrelationException { StringReader reader = new StringReader(content); Resource res = ResourceFactory.newReaderResource(reader); @@ -227,7 +243,11 @@ public class DroolsEngine { kbuilder.add(res, ResourceType.DRL); if (kbuilder.hasErrors()) { - throw new RuleIllegalityException(kbuilder.getErrors().toString()); + String errorMsg = I18nProxy.getInstance().getValueByArgs(locale, + I18nProxy.ENGINE_CONTENT_ILLEGALITY, + new String[]{kbuilder.getErrors().toString()}); + log.error(errorMsg); + throw new CorrelationException(errorMsg); } kbuilder = null; } diff --git a/engine-d/src/main/java/org/openo/holmes/enginemgt/resources/EngineResources.java b/engine-d/src/main/java/org/openo/holmes/enginemgt/resources/EngineResources.java index 59fb9e3..054ce52 100644 --- a/engine-d/src/main/java/org/openo/holmes/enginemgt/resources/EngineResources.java +++ b/engine-d/src/main/java/org/openo/holmes/enginemgt/resources/EngineResources.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -32,6 +32,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import lombok.extern.slf4j.Slf4j; import org.jvnet.hk2.annotations.Service; +import org.openo.holmes.common.exception.CorrelationException; import org.openo.holmes.common.exception.EngineException; import org.openo.holmes.common.exception.RuleIllegalityException; import org.openo.holmes.common.utils.ExceptionUtil; @@ -66,19 +67,9 @@ public class EngineResources { String packageName = droolsEngine.deployRule(deployRuleRequest, locale); crResponse.setPackageName(packageName); - } catch (RuleIllegalityException ruleIllegalityException) { - - String errorMsg = I18nProxy.getInstance().getValueByArgs(locale, - I18nProxy.ENGINE_CONTENT_ILLEGALITY, - new String[]{ruleIllegalityException.getMessage()}); - log.error(errorMsg); - throw ExceptionUtil.buildExceptionResponse(errorMsg); - } catch (EngineException e) { - - String errorMsg = - I18nProxy.getInstance().getValue(locale, I18nProxy.ENGINE_DEPLOY_RULE_FAILED); - log.error(errorMsg + ":" + e.getMessage()); - throw ExceptionUtil.buildExceptionResponse(errorMsg); + } catch (CorrelationException correlationException) { + log.error(correlationException.getMessage(), correlationException); + throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage()); } return crResponse; @@ -96,21 +87,11 @@ public class EngineResources { try { - droolsEngine.undeployRule(packageName); - - } catch (RuleIllegalityException ruleIllegalityException) { + droolsEngine.undeployRule(packageName, locale); - String errorMsg = I18nProxy.getInstance().getValueByArgs(locale, - I18nProxy.ENGINE_DELETE_RULE_NULL, - new String[]{ruleIllegalityException.getMessage()}); - log.error(errorMsg); - throw ExceptionUtil.buildExceptionResponse(errorMsg); - } catch (EngineException e) { - - String errorMsg = I18nProxy.getInstance().getValueByArgs(locale, - I18nProxy.ENGINE_DELETE_RULE_FAILED, new String[]{packageName}); - log.error(errorMsg + e.getMessage()); - throw ExceptionUtil.buildExceptionResponse(errorMsg); + } catch (CorrelationException correlationException) { + log.error(correlationException.getMessage(), correlationException); + throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage()); } return true; } @@ -127,13 +108,9 @@ public class EngineResources { try { droolsEngine.compileRule(compileRuleRequest.getContent(), locale); - } catch (RuleIllegalityException ruleIllegalityException) { - - String errorMsg = I18nProxy.getInstance().getValueByArgs(locale, - I18nProxy.ENGINE_CONTENT_ILLEGALITY, - new String[]{ruleIllegalityException.getMessage()}); - log.error(errorMsg); - throw ExceptionUtil.buildExceptionResponse(errorMsg); + } catch (CorrelationException correlationException) { + log.error(correlationException.getMessage(), correlationException); + throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage()); } return true; } |