2 * Copyright 2017 ZTE Corporation.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.onap.holmes.rulemgt.bolt.enginebolt;
\r
18 import com.fasterxml.jackson.databind.ObjectMapper;
\r
19 import java.io.IOException;
\r
20 import javax.ws.rs.client.Client;
\r
21 import javax.ws.rs.client.ClientBuilder;
\r
22 import javax.ws.rs.client.Entity;
\r
23 import javax.ws.rs.client.WebTarget;
\r
24 import javax.ws.rs.core.MediaType;
\r
25 import javax.ws.rs.core.Response;
\r
26 import lombok.extern.slf4j.Slf4j;
\r
27 import org.glassfish.jersey.client.ClientConfig;
\r
28 import org.jvnet.hk2.annotations.Service;
\r
29 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
\r
30 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
\r
31 import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
\r
32 import org.onap.holmes.common.config.MicroServiceConfig;
\r
36 public class EngineService {
\r
38 protected Response delete(String packageName) throws IOException {
\r
39 Client client = createClient();
\r
40 WebTarget webTarget = client
\r
41 .target(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH + "/" + packageName);
\r
42 return webTarget.request(MediaType.APPLICATION_JSON).delete();
\r
45 private Client createClient() {
\r
46 ClientConfig clientConfig = new ClientConfig();
\r
47 return ClientBuilder.newClient(clientConfig);
\r
50 protected Response check(CorrelationCheckRule4Engine correlationCheckRule4Engine)
\r
51 throws IOException {
\r
52 Client client = createClient();
\r
53 ObjectMapper mapper = new ObjectMapper();
\r
54 String content = mapper.writeValueAsString(correlationCheckRule4Engine);
\r
55 WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH);
\r
56 return webTarget.request(MediaType.APPLICATION_JSON).post(Entity.entity(content, MediaType.APPLICATION_JSON));
\r
59 protected Response deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws IOException {
\r
60 Client client = createClient();
\r
61 ObjectMapper mapper = new ObjectMapper();
\r
62 String content = mapper.writeValueAsString(correlationDeployRule4Engine);
\r
63 WebTarget webTarget = client.target(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH);
\r
64 return webTarget.request(MediaType.APPLICATION_JSON).put(Entity.entity(content, MediaType.APPLICATION_JSON));
\r