summaryrefslogtreecommitdiffstats
path: root/rulemgt/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'rulemgt/src/main')
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java12
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java12
-rw-r--r--rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java26
3 files changed, 30 insertions, 20 deletions
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
index 57ae0c5..4fcb486 100644
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
+++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleAppConfig.java
@@ -32,9 +32,6 @@ public class RuleAppConfig extends Configuration {
@NotEmpty
private String apidescription = "Holmes rule management rest API";
- @NotEmpty
- private String msbServerAddr;
-
@Valid
@NotNull
private DataSourceFactory database = new DataSourceFactory();
@@ -58,13 +55,4 @@ public class RuleAppConfig extends Configuration {
this.apidescription = apidescription;
}
- @JsonProperty
- public String getMsbServerAddr() {
- return msbServerAddr;
- }
-
- @JsonProperty
- public void setMsbServerAddr(String msbServerAddr) {
- this.msbServerAddr = msbServerAddr;
- }
}
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java
index b96303a..1a1aa83 100644
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java
+++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/bolt/enginebolt/EngineService.java
@@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@@ -32,9 +31,9 @@ import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.jvnet.hk2.annotations.Service;
+import org.openo.holmes.common.config.MicroServiceConfig;
import org.openo.holmes.common.exception.CorrelationException;
import org.openo.holmes.common.utils.I18nProxy;
-import org.openo.holmes.rulemgt.RuleAppConfig;
import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
import org.openo.holmes.rulemgt.constant.RuleMgtConstant;
@@ -42,24 +41,21 @@ import org.openo.holmes.rulemgt.constant.RuleMgtConstant;
@Service
public class EngineService {
- @Inject
- private RuleAppConfig ruleAppConfig;
-
protected HttpResponse delete(String packageName) throws IOException {
- return deleteRequest(ruleAppConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH + "/" + packageName);
+ return deleteRequest(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH + "/" + packageName);
}
protected HttpResponse check(CorrelationCheckRule4Engine correlationCheckRule4Engine)
throws IOException {
ObjectMapper mapper = new ObjectMapper();
String content = mapper.writeValueAsString(correlationCheckRule4Engine);
- return postRequest(ruleAppConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH, content);
+ return postRequest(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH, content);
}
protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine) throws IOException {
ObjectMapper mapper = new ObjectMapper();
String content = mapper.writeValueAsString(correlationDeployRule4Engine);
- return putRequest(ruleAppConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH, content);
+ return putRequest(MicroServiceConfig.getMsbServerAddr() + RuleMgtConstant.ENGINE_PATH, content);
}
private HttpResponse postRequest(String url, String content) throws IOException {
diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java
index 682faf0..08d66f7 100644
--- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java
+++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/resources/RuleMgtResources.java
@@ -22,6 +22,7 @@ import io.swagger.annotations.ApiParam;
import io.swagger.annotations.SwaggerDefinition;
import java.io.IOException;
import java.util.Locale;
+import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DELETE;
@@ -36,11 +37,14 @@ import javax.ws.rs.core.MediaType;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.jvnet.hk2.annotations.Service;
+import org.openo.holmes.common.api.entity.ServiceRegisterEntity;
+import org.openo.holmes.common.config.MicroServiceConfig;
import org.openo.holmes.common.exception.CorrelationException;
import org.openo.holmes.common.utils.ExceptionUtil;
import org.openo.holmes.common.utils.I18nProxy;
import org.openo.holmes.common.utils.JacksonUtil;
import org.openo.holmes.common.utils.LanguageUtil;
+import org.openo.holmes.common.utils.MSBRegisterUtil;
import org.openo.holmes.common.utils.UserUtil;
import org.openo.holmes.rulemgt.bean.request.RuleCreateRequest;
import org.openo.holmes.rulemgt.bean.request.RuleDeleteRequest;
@@ -60,8 +64,19 @@ import org.openo.holmes.rulemgt.wrapper.RuleMgtWrapper;
public class RuleMgtResources {
@Inject
+ private MSBRegisterUtil msbRegisterUtil;
+ @Inject
private RuleMgtWrapper ruleMgtWrapper;
+ @PostConstruct
+ public void init() {
+ try {
+ msbRegisterUtil.register(initServiceEntity());
+ } catch (IOException e) {
+ log.warn("Micro service registry httpclient close failure",e);
+ }
+ }
+
@PUT
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Save the alarm+ rule to the database, and deployed to the engine when the enable to open.", response = RuleAddAndUpdateResponse.class)
@@ -161,4 +176,15 @@ public class RuleMgtResources {
I18nProxy.RULE_MANAGEMENT_DATA_FORMAT_ERROR));
}
}
+
+ private ServiceRegisterEntity initServiceEntity() {
+ ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity();
+ serviceRegisterEntity.setServiceName("holmes");
+ serviceRegisterEntity.setProtocol("REST");
+ serviceRegisterEntity.setVersion("v1");
+ serviceRegisterEntity.setUrl("/api/holmes/v1");
+ serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9101", 0);
+ serviceRegisterEntity.setVisualRange("1");
+ return serviceRegisterEntity;
+ }
}