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;
}
public synchronized String deployRule(DeployRuleRequest rule, Locale locale)
- throws RuleIllegalityException, EngineException {
+ throws CorrelationException {
StringReader reader = new StringReader(rule.getContent());
Resource res = ResourceFactory.newReaderResource(reader);
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;
}
- 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);
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;
}
* 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,
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;
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;
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;
}
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;
}