From 6a7626d342add433d1c58ee369cf4c54f191ad43 Mon Sep 17 00:00:00 2001 From: GuangrongFu Date: Tue, 14 Mar 2017 09:55:04 +0800 Subject: Optimize the MSB Registration Logic Change-Id: I1b58ef7499a871e5a04ac5f115e246cca4abb022 Issue-ID: HOLMES-50 Signed-off-by: GuangrongFu --- .../org/openo/holmes/rulemgt/RuleActiveApp.java | 29 ++++++++++++++++++++++ .../holmes/rulemgt/resources/RuleMgtResources.java | 22 ---------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleActiveApp.java b/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleActiveApp.java index c7eaf15..96a1f00 100644 --- a/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleActiveApp.java +++ b/rulemgt/src/main/java/org/openo/holmes/rulemgt/RuleActiveApp.java @@ -16,8 +16,15 @@ package org.openo.holmes.rulemgt; +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 RuleActiveApp extends IOCApplication < RuleAppConfig > { public static void main( String[] args ) throws Exception { @@ -29,4 +36,26 @@ public class RuleActiveApp extends IOCApplication < RuleAppConfig > { return "Holmes Rule Management ActiveApp APP "; } + @Override + public void run(RuleAppConfig 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|0"); + return serviceRegisterEntity; + } } 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 2c2c88d..f3256b2 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 @@ -63,20 +63,9 @@ import org.openo.holmes.rulemgt.wrapper.RuleMgtWrapper; @Slf4j 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) @@ -176,15 +165,4 @@ public class RuleMgtResources { I18nProxy.RULE_MANAGEMENT_DATA_FORMAT_ERROR)); } } - - 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; - } } -- cgit 1.2.3-korg