diff options
author | GuangrongFu <fu.guangrong@zte.com.cn> | 2017-03-14 08:28:06 +0800 |
---|---|---|
committer | GuangrongFu <fu.guangrong@zte.com.cn> | 2017-03-14 08:28:06 +0800 |
commit | 678100773b8d66e3aaf1875930159fda692ca957 (patch) | |
tree | 3b2328fa2fe32345597751ce0d59170023fbe5c2 /engine-d/src/main/java/org/openo | |
parent | b8e477af70a3d28cd97dc7077fd6d5278aa27a22 (diff) |
Optimize the Registration Logic of MSB
Change-Id: I5be5a069d389081fad2b4a6fae558799716d91b6
Issue-ID: HOLMES-50
Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'engine-d/src/main/java/org/openo')
-rw-r--r-- | engine-d/src/main/java/org/openo/holmes/engine/EngineDActiveApp.java | 29 | ||||
-rw-r--r-- | engine-d/src/main/java/org/openo/holmes/engine/resources/EngineResources.java | 28 |
2 files changed, 29 insertions, 28 deletions
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<EngineDAppConfig> { 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; - } } |