*/\r
package org.openo.holmes.rulemgt.bolt.enginebolt;\r
\r
+import javax.inject.Inject;\r
import lombok.extern.slf4j.Slf4j;\r
+import net.sf.json.JSONObject;\r
+import org.apache.http.HttpResponse;\r
import org.jvnet.hk2.annotations.Service;\r
import org.openo.holmes.common.exception.CorrelationException;\r
+import org.openo.holmes.common.utils.I18nProxy;\r
import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
+import org.openo.holmes.rulemgt.constant.RuleMgtConstant;\r
\r
@Service\r
@Slf4j\r
public class EngineWrapper {\r
\r
+ @Inject\r
+ private EngineService engineService;\r
\r
public String deployEngine(CorrelationDeployRule4Engine correlationRule) throws CorrelationException {\r
- return "";\r
+ HttpResponse httpResponse;\r
+ try {\r
+ httpResponse = engineService.deploy(correlationRule);\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DEPLOY_RULE_REST_FAILED,e);\r
+ }\r
+ if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
+ log.info("Call deploy rule rest interface in engine successfully.");\r
+ String content = engineService.getResponseContent(httpResponse);\r
+ try {\r
+ JSONObject json = JSONObject.fromObject(content);\r
+ return json.get(RuleMgtConstant.PACKAGE).toString();\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR,e);\r
+ }\r
+ } else {\r
+ throw new CorrelationException(I18nProxy.ENGINE_DEPLOY_RULE_FAILED);\r
+ }\r
}\r
\r
public boolean deleteRuleFromEngine(String packageName) throws CorrelationException {\r
- return true;\r
+ HttpResponse httpResponse;\r
+ try {\r
+ httpResponse = engineService.delete(packageName);\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CALL_DELETE_RULE_REST_FAILED,e);\r
+ }\r
+ if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
+ log.info("Call delete rule rest interface in engine successfully.");\r
+ return true;\r
+ } else {\r
+ throw new CorrelationException(I18nProxy.ENGINE_DELETE_RULE_FAILED);\r
+ }\r
}\r
\r
public boolean checkRuleFromEngine(CorrelationCheckRule4Engine correlationCheckRule4Engine)\r
throws CorrelationException {\r
- return true;\r
+ HttpResponse httpResponse;\r
+ try {\r
+ httpResponse = engineService.check(correlationCheckRule4Engine);\r
+ } catch (Exception e) {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT__CALL_CHECK_RULE_REST_FAILED,e);\r
+ }\r
+ if (httpResponse.getStatusLine().getStatusCode() == RuleMgtConstant.RESPONSE_STATUS_OK) {\r
+ log.info("Call check rule rest interface in engine successfully.");\r
+ return true;\r
+ } else {\r
+ throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_CHECK_NO_PASS);\r
+ }\r
}\r
}\r