2 * Copyright 2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.holmes.engine.resources;
19 import com.codahale.metrics.annotation.Timed;
20 import io.swagger.annotations.Api;
21 import io.swagger.annotations.ApiOperation;
22 import java.util.Locale;
23 import javax.inject.Inject;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.ws.rs.DELETE;
26 import javax.ws.rs.POST;
27 import javax.ws.rs.PUT;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.PathParam;
30 import javax.ws.rs.Produces;
31 import javax.ws.rs.core.Context;
32 import javax.ws.rs.core.MediaType;
33 import lombok.extern.slf4j.Slf4j;
34 import org.jvnet.hk2.annotations.Service;
35 import org.onap.holmes.common.exception.CorrelationException;
36 import org.onap.holmes.common.utils.ExceptionUtil;
37 import org.onap.holmes.common.utils.LanguageUtil;
38 import org.onap.holmes.engine.manager.DroolsEngine;
39 import org.onap.holmes.engine.request.CompileRuleRequest;
40 import org.onap.holmes.engine.request.DeployRuleRequest;
41 import org.onap.holmes.engine.response.CorrelationRuleResponse;
45 @Api(tags = {"Engine Manager"})
46 @Produces(MediaType.APPLICATION_JSON)
48 public class EngineResources {
51 DroolsEngine droolsEngine;
54 @ApiOperation(value = "Add rule to Engine and Cache", response = CorrelationRuleResponse.class)
55 @Produces(MediaType.APPLICATION_JSON)
57 public CorrelationRuleResponse deployRule(DeployRuleRequest deployRuleRequest,
58 @Context HttpServletRequest httpRequest) {
60 CorrelationRuleResponse crResponse = new CorrelationRuleResponse();
61 Locale locale = LanguageUtil.getLocale(httpRequest);
64 String packageName = droolsEngine.deployRule(deployRuleRequest, locale);
65 log.info("Rule deployed. Package name: " + packageName);
66 crResponse.setPackageName(packageName);
68 } catch (CorrelationException correlationException) {
69 log.error(correlationException.getMessage(), correlationException);
70 throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage());
77 @ApiOperation(value = "delete rule")
78 @Produces(MediaType.APPLICATION_JSON)
80 @Path("/{packageName}")
81 public boolean undeployRule(@PathParam("packageName") String packageName,
82 @Context HttpServletRequest httpRequest) {
84 Locale locale = LanguageUtil.getLocale(httpRequest);
88 droolsEngine.undeployRule(packageName, locale);
90 } catch (CorrelationException correlationException) {
91 log.error(correlationException.getMessage(), correlationException);
92 throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage());
99 @ApiOperation(value = "compile rule")
100 @Produces(MediaType.APPLICATION_JSON)
102 public boolean compileRule(CompileRuleRequest compileRuleRequest,
103 @Context HttpServletRequest httpRequest) {
105 Locale locale = LanguageUtil.getLocale(httpRequest);
108 droolsEngine.compileRule(compileRuleRequest.getContent(), locale);
109 } catch (CorrelationException correlationException) {
110 log.error(correlationException.getMessage(), correlationException);
111 throw ExceptionUtil.buildExceptionResponse(correlationException.getMessage());