From 678100773b8d66e3aaf1875930159fda692ca957 Mon Sep 17 00:00:00 2001 From: GuangrongFu Date: Tue, 14 Mar 2017 08:28:06 +0800 Subject: Optimize the Registration Logic of MSB Change-Id: I5be5a069d389081fad2b4a6fae558799716d91b6 Issue-ID: HOLMES-50 Signed-off-by: GuangrongFu --- .gitignore | 19 ++++++++++++++ .../org/openo/holmes/engine/EngineDActiveApp.java | 29 ++++++++++++++++++++++ .../holmes/engine/resources/EngineResources.java | 28 --------------------- 3 files changed, 48 insertions(+), 28 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..45bb734 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# Ignore Vim temporary files +.*.sw? + +# Ignore changes to the JJB Configuration File +jenkins.ini + +# We don't want .netrc files since they're credential files +.netrc + +# Maven +target/ +dependency-reduced-pom.xml + +# Vagrant +.vagrant + +# IntelliJ +.idea/ +*.iml diff --git a/engine-d/src/main/java/org/openo/holmes/engine/EngineDActiveApp.java b/engine-d/src/main/java/org/openo/holmes/engine/EngineDActiveApp.java index 24bff21..46108be 100644 --- a/engine-d/src/main/java/org/openo/holmes/engine/EngineDActiveApp.java +++ b/engine-d/src/main/java/org/openo/holmes/engine/EngineDActiveApp.java @@ -15,11 +15,40 @@ */ package org.openo.holmes.engine; +import io.dropwizard.setup.Environment; +import java.io.IOException; +import lombok.extern.slf4j.Slf4j; import org.openo.dropwizard.ioc.bundle.IOCApplication; +import org.openo.holmes.common.api.entity.ServiceRegisterEntity; +import org.openo.holmes.common.config.MicroServiceConfig; +import org.openo.holmes.common.utils.MSBRegisterUtil; +@Slf4j public class EngineDActiveApp extends IOCApplication { public static void main(String[] args) throws Exception { new EngineDActiveApp().run(args); } + + @Override + public void run(EngineDAppConfig configuration, Environment environment) throws Exception { + super.run(configuration, environment); + + try { + new MSBRegisterUtil().register(initServiceEntity()); + } catch (IOException e) { + log.warn("Micro service registry httpclient close failure", e); + } + } + + private ServiceRegisterEntity initServiceEntity() { + ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity(); + serviceRegisterEntity.setServiceName("holmes-rule-mgmt"); + serviceRegisterEntity.setProtocol("REST"); + serviceRegisterEntity.setVersion("v1"); + serviceRegisterEntity.setUrl("/openoapi/holmes-rule-mgmt/v1"); + serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9101", 0); + serviceRegisterEntity.setVisualRange("1"); + return serviceRegisterEntity; + } } diff --git a/engine-d/src/main/java/org/openo/holmes/engine/resources/EngineResources.java b/engine-d/src/main/java/org/openo/holmes/engine/resources/EngineResources.java index 194546b..5be8eb9 100644 --- a/engine-d/src/main/java/org/openo/holmes/engine/resources/EngineResources.java +++ b/engine-d/src/main/java/org/openo/holmes/engine/resources/EngineResources.java @@ -19,9 +19,7 @@ package org.openo.holmes.engine.resources; import com.codahale.metrics.annotation.Timed; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -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; @@ -34,12 +32,9 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import lombok.extern.slf4j.Slf4j; 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.LanguageUtil; -import org.openo.holmes.common.utils.MSBRegisterUtil; import org.openo.holmes.engine.manager.DroolsEngine; import org.openo.holmes.engine.request.CompileRuleRequest; import org.openo.holmes.engine.request.DeployRuleRequest; @@ -55,18 +50,6 @@ public class EngineResources { @Inject DroolsEngine droolsEngine; - @Inject - MSBRegisterUtil msbRegisterUtil; - - @PostConstruct - private void initMsbService() { - try { - msbRegisterUtil.register(initServiceEntity()); - } catch (IOException e) { - log.warn("Failed register msb" + e.getMessage(), e); - } - } - @PUT @ApiOperation(value = "Add rule to Engine and Cache", response = CorrelationRuleResponse.class) @Produces(MediaType.APPLICATION_JSON) @@ -129,15 +112,4 @@ public class EngineResources { } return true; } - - private ServiceRegisterEntity initServiceEntity() { - ServiceRegisterEntity serviceRegisterEntity = new ServiceRegisterEntity(); - serviceRegisterEntity.setServiceName("holmes-engine-mgmt"); - serviceRegisterEntity.setProtocol("REST"); - serviceRegisterEntity.setVersion("v1"); - serviceRegisterEntity.setUrl("/openoapi/holmes-engine-mgmt/v1"); - serviceRegisterEntity.setSingleNode(MicroServiceConfig.getServiceIp(), "9102", 0); - serviceRegisterEntity.setVisualRange("1|0"); - return serviceRegisterEntity; - } } -- cgit 1.2.3-korg