From 0c795a78a515168eb600744bf43906d4fd195b30 Mon Sep 17 00:00:00 2001 From: GuangrongFu Date: Sat, 18 Dec 2021 15:07:55 +0800 Subject: Switched from Dropwizard to Springboot Issue-ID: HOLMES-511 Signed-off-by: GuangrongFu Change-Id: If845dcc835ca4812d550b842fd861626265b4cf1 --- .../onap/holmes/common/aai/AaiJsonParserUtil.java | 9 +- .../java/org/onap/holmes/common/aai/AaiQuery.java | 6 +- .../onap/holmes/common/aai/AaiQuery4Ccvpn2.java | 7 +- .../org/onap/holmes/common/aai/AaiQueryMdons.java | 2 +- .../onap/holmes/common/aai/AaiResponseUtil.java | 2 +- .../onap/holmes/common/aai/CorrelationUtil.java | 11 +- .../common/api/entity/AlarmsCorrelation.java | 67 ---- .../org/onap/holmes/common/config/GsonConfig.java | 39 +++ .../org/onap/holmes/common/config/MQConfig.java | 35 -- .../onap/holmes/common/constant/AlarmConst.java | 13 - .../common/database/DatabaseConfiguration.java | 78 +++++ .../org/onap/holmes/common/database/DbDaoUtil.java | 40 +++ .../org/onap/holmes/common/dmaap/DmaapService.java | 10 +- .../org/onap/holmes/common/dmaap/Publisher.java | 2 +- .../dmaap/store/ClosedLoopControlNameCache.java | 8 +- .../common/dmaap/store/UniqueRequestIdCache.java | 6 +- .../dropwizard/ioc/annotation/BaseService.java | 34 -- .../common/dropwizard/ioc/annotation/Lazy.java | 34 -- .../dropwizard/ioc/annotation/PostBaseService.java | 34 -- .../dropwizard/ioc/annotation/PreBaseService.java | 34 -- .../common/dropwizard/ioc/annotation/PreLoad.java | 34 -- .../dropwizard/ioc/annotation/PreServiceLoad.java | 35 -- .../dropwizard/ioc/bundle/AutoConfigBundle.java | 367 --------------------- .../ioc/bundle/AutoConfigBundleBuider.java | 42 --- .../dropwizard/ioc/bundle/IOCApplication.java | 42 --- .../ioc/bundle/ServiceLocatorManaged.java | 51 --- .../common/dropwizard/ioc/utils/ServiceBinder.java | 52 --- .../dropwizard/ioc/utils/ServiceLocatorHolder.java | 36 -- .../holmes/common/engine/dao/EngineEntityDao.java | 14 +- .../common/engine/dao/EngineEntityMapper.java | 16 +- .../common/engine/service/EngineEntityService.java | 4 +- .../service/impl/EngineEntityServiceImpl.java | 8 +- .../onap/holmes/common/utils/AlarmInfoMapper.java | 11 +- .../org/onap/holmes/common/utils/CommonUtils.java | 5 +- .../holmes/common/utils/CorrelationRuleMapper.java | 13 +- .../org/onap/holmes/common/utils/DbDaoUtil.java | 91 ----- .../org/onap/holmes/common/utils/JerseyClient.java | 1 - .../org/onap/holmes/common/utils/MsbRegister.java | 2 +- .../holmes/common/utils/RestExceptionHandler.java | 34 ++ .../holmes/common/utils/SpringContextUtil.java | 45 +++ .../utils/transactionid/TransactionIdFilter.java | 8 +- 41 files changed, 307 insertions(+), 1075 deletions(-) delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/config/GsonConfig.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/config/MQConfig.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/database/DatabaseConfiguration.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/database/DbDaoUtil.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/BaseService.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/Lazy.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PostBaseService.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreBaseService.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreLoad.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreServiceLoad.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleBuider.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/IOCApplication.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/ServiceLocatorManaged.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceBinder.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceLocatorHolder.java delete mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/RestExceptionHandler.java create mode 100644 holmes-actions/src/main/java/org/onap/holmes/common/utils/SpringContextUtil.java (limited to 'holmes-actions/src/main/java/org/onap') diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiJsonParserUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiJsonParserUtil.java index ba66628..0a9e4f7 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiJsonParserUtil.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiJsonParserUtil.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.holmes.common.aai * ================================================================================ - * Copyright (C) 2018-2020 Huawei. All rights reserved. + * Copyright (C) 2018-2021 Huawei, ZTE. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,18 +24,15 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import lombok.extern.slf4j.Slf4j; -import org.jvnet.hk2.annotations.Service; -import org.onap.holmes.common.aai.config.AaiConfig; import org.onap.holmes.common.config.MicroServiceConfig; +import org.springframework.stereotype.Component; -import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.MultivaluedMap; import java.util.regex.Matcher; import java.util.regex.Pattern; -@Service @Slf4j +@Component public class AaiJsonParserUtil { public static String getPath(String urlTemplate, String paramName, String paramValue) { diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java index a73eb22..1bf79f2 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java @@ -14,14 +14,14 @@ package org.onap.holmes.common.aai; import lombok.extern.slf4j.Slf4j; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.aai.config.AaiConfig; import org.onap.holmes.common.aai.entity.VmEntity; import org.onap.holmes.common.aai.entity.VnfEntity; import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.JerseyClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; -import javax.inject.Inject; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,7 +30,7 @@ import java.util.Map; @Slf4j public class AaiQuery { - @Inject + @Autowired private AaiResponseUtil aaiResponseUtil; public VnfEntity getAaiVnfData(String vnfId, String vnfName) throws CorrelationException { diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2.java index 41eb2c0..a9d9e53 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.holmes.common.aai * ================================================================================ - * Copyright (C) 2018-2020 Huawei. All rights reserved. + * Copyright (C) 2018-2021 Huawei, ZTE. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,10 +24,9 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import lombok.extern.slf4j.Slf4j; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.aai.config.AaiConfig; -import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.JerseyClient; +import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.Map; @@ -36,8 +35,8 @@ import java.util.regex.Pattern; import static org.onap.holmes.common.aai.AaiJsonParserUtil.*; -@Service @Slf4j +@Service public class AaiQuery4Ccvpn2 { private Map headers; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQueryMdons.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQueryMdons.java index c557003..f9e2e5d 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQueryMdons.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQueryMdons.java @@ -17,13 +17,13 @@ package org.onap.holmes.common.aai; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.aai.config.AaiConfig; import org.onap.holmes.common.config.MicroServiceConfig; import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.JerseyClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; import javax.ws.rs.client.Entity; import javax.ws.rs.core.MultivaluedHashMap; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java index 5ad4984..896e694 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java @@ -18,7 +18,6 @@ package org.onap.holmes.common.aai; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.aai.entity.RelationshipList; import org.onap.holmes.common.aai.entity.RelationshipList.RelatedToProperty; import org.onap.holmes.common.aai.entity.RelationshipList.Relationship; @@ -26,6 +25,7 @@ import org.onap.holmes.common.aai.entity.RelationshipList.RelationshipData; import org.onap.holmes.common.aai.entity.VmEntity; import org.onap.holmes.common.aai.entity.VmResourceLink; import org.onap.holmes.common.aai.entity.VnfEntity; +import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Collections; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/CorrelationUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/CorrelationUtil.java index 6520552..51b4cf0 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/CorrelationUtil.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/CorrelationUtil.java @@ -1,5 +1,5 @@ /** - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2021 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -13,13 +13,14 @@ */ package org.onap.holmes.common.aai; -import java.util.List; -import java.util.Optional; import lombok.extern.slf4j.Slf4j; import org.onap.holmes.common.aai.entity.RelationshipList.Relationship; import org.onap.holmes.common.aai.entity.VmEntity; -import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder; import org.onap.holmes.common.exception.CorrelationException; +import org.onap.holmes.common.utils.SpringContextUtil; + +import java.util.List; +import java.util.Optional; @Slf4j public class CorrelationUtil { @@ -33,7 +34,7 @@ public class CorrelationUtil { public static final CorrelationUtil getInstance() { if (aaiQuery == null) { - aaiQuery = ServiceLocatorHolder.getLocator().getService(AaiQuery.class); + aaiQuery = SpringContextUtil.getBean(AaiQuery.class); } return LazyHolder.INSTANCE; } diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java b/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java deleted file mode 100644 index e21f97d..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/api/entity/AlarmsCorrelation.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.api.entity; - -import com.google.gson.annotations.SerializedName; -import java.util.Date; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@NoArgsConstructor -public class AlarmsCorrelation { - - @SerializedName(value = "ruleid") - private String ruleId; - - @SerializedName(value = "ruleinfo") - private String ruleInfo; - - @SerializedName(value = "resulttype") - private byte resultType; - - @SerializedName(value = "createtime") - private Date createTime; - - @SerializedName(value = "parentalarmid") - private long parentAlarmId; - - @SerializedName(value = "childalarmid") - private long childAlarmId; - - private long reserve1 = -1; - - private long reserve2 = -1; - - private long reserve3 = -1; - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("["); - sb.append("ruleId=").append(ruleId).append(","); - sb.append("ruleInfo=").append(ruleInfo).append(","); - sb.append("createTime=").append(createTime == null ? null : createTime.toString()).append(","); - sb.append("parentAlarmId=").append(parentAlarmId).append(","); - sb.append("childAlarmId=").append(childAlarmId).append(","); - sb.append("reserve1=").append(reserve1).append(","); - sb.append("reserve2=").append(reserve2).append(","); - sb.append("reserve3=").append(reserve3).append("]"); - return sb.toString(); - } -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/config/GsonConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/config/GsonConfig.java new file mode 100644 index 0000000..58a8f35 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/config/GsonConfig.java @@ -0,0 +1,39 @@ +/** + * Copyright 2021 ZTE Corporation. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.holmes.common.config; + +import org.springframework.boot.autoconfigure.http.HttpMessageConverters; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.GsonHttpMessageConverter; + +import java.util.ArrayList; +import java.util.Collection; + +@Configuration +public class GsonConfig { + @Bean + public HttpMessageConverters customConverters() { + Collection> messageConverters = new ArrayList(); + + GsonHttpMessageConverter gsonHttpMessageConverter = new GsonHttpMessageConverter(); + messageConverters.add(gsonHttpMessageConverter); + + return new HttpMessageConverters(true, messageConverters); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/config/MQConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/config/MQConfig.java deleted file mode 100644 index 70ef0cb..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/config/MQConfig.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.holmes.common.config; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@NoArgsConstructor -public class MQConfig { - - private String brokerIp; - - private int brokerPort; - - private String brokerUsername; - - private String brokerPassword; -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/constant/AlarmConst.java b/holmes-actions/src/main/java/org/onap/holmes/common/constant/AlarmConst.java index ba3d80e..0cdb66d 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/constant/AlarmConst.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/constant/AlarmConst.java @@ -16,15 +16,6 @@ package org.onap.holmes.common.constant; public interface AlarmConst { - - String MQ_TOPIC_NAME_ALARMS_CORRELATION = "topic://voss/fm/alarms_correlation"; - - String MQ_TOPIC_NAME_ALARM = "topic://voss/fm/alarm"; - - String NFVO_PATH = "/api/umc/v1/fm/curalarms/findAll"; - - int NFVO_STATUS_OK = 200; - String I18N_EN = "en"; String I18N_ZH = "zh"; @@ -33,10 +24,6 @@ public interface AlarmConst { String ADMIN = "admin"; - int MICRO_SERVICE_STATUS_SUCCESS = 201; - - int MICRO_SERVICE_PORT = 8086; - String HTTP = "http://"; String HTTPS = "https://"; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/database/DatabaseConfiguration.java b/holmes-actions/src/main/java/org/onap/holmes/common/database/DatabaseConfiguration.java new file mode 100644 index 0000000..101c350 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/database/DatabaseConfiguration.java @@ -0,0 +1,78 @@ +/** + * Copyright 2021 ZTE Corporation. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.holmes.common.database; + +import org.jdbi.v3.core.Jdbi; +import org.jdbi.v3.core.mapper.RowMapper; +import org.jdbi.v3.core.spi.JdbiPlugin; +import org.jdbi.v3.postgres.PostgresPlugin; +import org.jdbi.v3.sqlobject.SqlObjectPlugin; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy; + +import javax.sql.DataSource; +import java.util.List; + +@Configuration +public class DatabaseConfiguration { +// +// @Value("${spring.datasource.url}") +// private String url; +// +// @Value("${spring.datasource.username}") +// private String username; +// +// @Value("${spring.datasource.password}") +// private String pwd; +// +// @Value("${spring.datasource.dirver-class-name}") +// private String driverClass; +// +// @Bean +// public DataSource driverManagerDataSource() { +// System.out.println("======================================: " + driverClass); +// DriverManagerDataSource ds = new DriverManagerDataSource(); +// ds.setDriverClassName(driverClass); +// ds.setUrl(url); +// ds.setUsername(username); +// ds.setPassword(pwd); +// return ds; +// } + +// @Bean +// public DataSourceTransactionManager dataSourceTransactionManager(DataSource dataSource) { +// DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(); +// dataSourceTransactionManager.setDataSource(dataSource); +// return dataSourceTransactionManager; +// } + + @Bean + public Jdbi jdbi(DataSource dataSource) { + return Jdbi.create(dataSource) + .installPlugin(new SqlObjectPlugin()) + .installPlugin(new PostgresPlugin()); + } + +// @Bean +// public Jdbi jdbi(DataSource ds, List jdbiPlugins, List> rowMappers) { +// TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(ds); +// Jdbi jdbi = Jdbi.create(proxy); +// jdbiPlugins.forEach(plugin -> jdbi.installPlugin(plugin)); +// rowMappers.forEach(mapper -> jdbi.registerRowMapper(mapper)); +// return jdbi; +// } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/database/DbDaoUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/database/DbDaoUtil.java new file mode 100644 index 0000000..2cbb538 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/database/DbDaoUtil.java @@ -0,0 +1,40 @@ +/** + * Copyright 2017-2021 ZTE Corporation. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.holmes.common.database; + +import org.jdbi.v3.core.Handle; +import org.jdbi.v3.core.Jdbi; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class DbDaoUtil { + private Jdbi jdbi; + + @Autowired + public DbDaoUtil(Jdbi jdbi) { + this.jdbi = jdbi; + } + + public T getJdbiDaoByOnDemand(Class daoClazz) { + return jdbi.onDemand(daoClazz); + } + + @Deprecated + public Handle getHandle() { + return jdbi.open(); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java index e9eb003..de7d74f 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/DmaapService.java @@ -15,7 +15,6 @@ */ package org.onap.holmes.common.dmaap; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.aai.AaiQuery; import org.onap.holmes.common.aai.entity.RelationshipList.Relationship; import org.onap.holmes.common.aai.entity.VmEntity; @@ -30,8 +29,9 @@ import org.onap.holmes.common.exception.CorrelationException; import org.onap.holmes.common.utils.GsonUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; -import javax.inject.Inject; import java.util.Map.Entry; import java.util.Optional; import java.util.UUID; @@ -45,17 +45,17 @@ public class DmaapService { private ClosedLoopControlNameCache closedLoopControlNameCache; private UniqueRequestIdCache uniqueRequestIdCache; - @Inject + @Autowired public void setAaiQuery(AaiQuery aaiQuery) { this.aaiQuery = aaiQuery; } - @Inject + @Autowired public void setClosedLoopControlNameCache(ClosedLoopControlNameCache closedLoopControlNameCache) { this.closedLoopControlNameCache = closedLoopControlNameCache; } - @Inject + @Autowired public void setUniqueRequestIdCache(UniqueRequestIdCache uniqueRequestIdCache) { this.uniqueRequestIdCache = uniqueRequestIdCache; } diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java index 23a04d6..b1c5595 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java @@ -17,9 +17,9 @@ package org.onap.holmes.common.dmaap; import lombok.Getter; import lombok.Setter; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.dmaap.entity.PolicyMsg; import org.onap.holmes.common.utils.JerseyClient; +import org.springframework.stereotype.Service; import javax.ws.rs.client.Entity; import java.util.concurrent.TimeUnit; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCache.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCache.java index 8a692b2..2d9cf99 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCache.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 ZTE Corporation. + * Copyright 2020-2021 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,13 @@ */ package org.onap.holmes.common.dmaap.store; -import org.jvnet.hk2.annotations.Service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; -import javax.inject.Singleton; import java.util.concurrent.ConcurrentHashMap; -@Service -@Singleton +@Component public class ClosedLoopControlNameCache extends ConcurrentHashMap { private static final Logger log = LoggerFactory.getLogger(ClosedLoopControlNameCache.class); diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCache.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCache.java index 070159e..f4e2459 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCache.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 ZTE Corporation. + * Copyright 2020-2021 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,14 @@ */ package org.onap.holmes.common.dmaap.store; -import org.jvnet.hk2.annotations.Service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; import javax.inject.Singleton; import java.util.concurrent.ConcurrentHashMap; -@Service +@Component @Singleton public class UniqueRequestIdCache extends ConcurrentHashMap { diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/BaseService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/BaseService.java deleted file mode 100644 index 9f0ae67..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/BaseService.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * basic services for identification - * @author hu.rui - * - */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface BaseService { - -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/Lazy.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/Lazy.java deleted file mode 100644 index 4f7d046..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/Lazy.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * lazy loading of related services - * @author hu.rui - * - */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface Lazy { - -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PostBaseService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PostBaseService.java deleted file mode 100644 index 4787bec..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PostBaseService.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * load on after basic services - * @author hu.rui - * - */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface PostBaseService { - -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreBaseService.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreBaseService.java deleted file mode 100644 index 669bceb..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreBaseService.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * prior to basic service loading - * @author hu.rui - * - */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface PreBaseService { - -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreLoad.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreLoad.java deleted file mode 100644 index dce3e58..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreLoad.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * load before general service - * @author hu.rui - * - */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface PreLoad { - -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreServiceLoad.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreServiceLoad.java deleted file mode 100644 index 815c1d7..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/annotation/PreServiceLoad.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.annotation; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * - * load before general service,after PreLoad - * @author hu.rui - * - */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface PreServiceLoad { - -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java deleted file mode 100644 index fe9ee5a..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java +++ /dev/null @@ -1,367 +0,0 @@ -/** - * Copyright 2017 - 2021 ZTE Corporation. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.bundle; - -import com.codahale.metrics.health.HealthCheck; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Lists; -import io.dropwizard.Configuration; -import io.dropwizard.ConfiguredBundle; -import io.dropwizard.lifecycle.ServerLifecycleListener; -import io.dropwizard.servlets.tasks.Task; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; -import org.eclipse.jetty.util.component.LifeCycle; -import org.glassfish.hk2.api.ServiceLocator; -import org.glassfish.hk2.api.ServiceLocatorFactory; -import org.glassfish.hk2.utilities.ServiceLocatorUtilities; -import org.glassfish.hk2.utilities.binding.AbstractBinder; -import org.glassfish.jersey.servlet.ServletProperties; -import org.jvnet.hk2.annotations.Service; -import org.onap.holmes.common.dropwizard.ioc.annotation.*; -import org.onap.holmes.common.dropwizard.ioc.utils.ServiceBinder; -import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder; -import org.reflections.Reflections; -import org.reflections.scanners.SubTypesScanner; -import org.reflections.scanners.TypeAnnotationsScanner; -import org.reflections.util.ClasspathHelper; -import org.reflections.util.ConfigurationBuilder; -import org.reflections.util.FilterBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.Path; -import javax.ws.rs.ext.Provider; -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * complete the integration of hK2 container and dropwizard - * - * @author hu.rui - */ - -public class AutoConfigBundle implements ConfiguredBundle { - - private static final Logger LOG = LoggerFactory.getLogger(AutoConfigBundle.class); - - private ServiceLocator locator; - private Reflections reflections; - private Set> services; - - private Bootstrap bootstrap; - - - AutoConfigBundle(final String packageName) { - this(Lists.newArrayList(packageName)); - } - - AutoConfigBundle(List packageNames) { - FilterBuilder filterBuilder = new FilterBuilder(); - - packageNames.stream().forEach(packageName -> filterBuilder.include(FilterBuilder.prefix(packageName))); - ConfigurationBuilder reflectionCfg = new ConfigurationBuilder(); - - packageNames.stream().forEach(packageName -> reflectionCfg.addUrls(ClasspathHelper.forPackage(packageName))); - - reflectionCfg.filterInputsBy(filterBuilder).setScanners(new SubTypesScanner(), - new TypeAnnotationsScanner()); - reflections = new Reflections(reflectionCfg); - - locator = ServiceLocatorFactory.getInstance().create("dw-hk2"); - - ServiceLocatorHolder.setLocator(locator); - - } - - public static AutoConfigBundleBuider newBuilder() { - return new AutoConfigBundleBuider(); - } - - @Override - public void initialize(final Bootstrap bootstrap) { - - this.bootstrap = bootstrap; - registerPreLoadService(); - - LOG.debug("Intialzing auto config bundle."); - } - - private void registerPreLoadService() { - registerService(PreLoad.class); - } - - - @Override - public void run(final T configuration, final Environment environment) { - - registerConfigurationProvider(configuration, environment); - - registerEnvironment(environment); - registerObjectMapper(environment); - - environment.getApplicationContext().getServletContext() - .setAttribute(ServletProperties.SERVICE_LOCATOR, locator); - - registerService(PreBaseService.class); - registerService(BaseService.class); - registerService(PostBaseService.class); - this.registerService(PreServiceLoad.class); - - - registerServices(); - - registerLifecycle(environment); - registerServerLifecycleListeners(environment); - registerJettyLifeCycleListener(environment); - registerTasks(environment); - registerHealthChecks(environment); - registerProviders(environment); - registerResources(environment); - - environment.lifecycle().manage(new ServiceLocatorManaged(locator)); - - } - - - private void registerProviders(Environment environment) { - reflections.getSubTypesOf(Provider.class).stream().filter(services::contains) - .forEach(providerKlass -> { - try { - environment.jersey().register(locator.getService(providerKlass)); - } catch (Exception e) { - LOG.warn("", e); - } - - LOG.info("Registering Dropwizard Provider, class name : {}", providerKlass.getName()); - - }); - - } - - private void registerTasks(Environment environment) { - reflections.getSubTypesOf(Task.class).stream().filter(services::contains).forEach(taskKlass -> { - try { - environment.admin().addTask(locator.getService(taskKlass)); - } catch (Exception e) { - LOG.warn("", e); - } - LOG.info("Registering Dropwizard Task, class name : {}", taskKlass.getName()); - }); - - } - - private void registerJettyLifeCycleListener(Environment environment) { - reflections.getSubTypesOf(LifeCycle.Listener.class).stream().filter(services::contains) - .forEach(lifecycleListenerKlass -> { - try { - environment.lifecycle() - .addLifeCycleListener(locator.getService(lifecycleListenerKlass)); - } catch (Exception e) { - LOG.warn("", e); - } - LOG.info("Registering Dropwizard lifecycleListener, class name : {}", - lifecycleListenerKlass.getName()); - }); - - } - - private void registerServerLifecycleListeners(Environment environment) { - - reflections.getSubTypesOf(ServerLifecycleListener.class).stream().filter(services::contains) - .forEach(serverLifecycleListenerKlass -> { - try { - environment.lifecycle() - .addServerLifecycleListener(locator.getService(serverLifecycleListenerKlass)); - } catch (Exception e) { - LOG.warn("", e); - } - LOG.info("Registering Dropwizard serverLifecycleListener, class name : {}", - serverLifecycleListenerKlass.getName()); - }); - - } - - private void registerLifecycle(Environment environment) { - reflections.getSubTypesOf(LifeCycle.class).stream().filter(services::contains) - .forEach(lifeCycleKlass -> { - try { - environment.lifecycle().manage(locator.getService(lifeCycleKlass)); - } catch (Exception e) { - LOG.warn("", e); - } - LOG.info("Registering Dropwizard LifeCycle, class name : {}", lifeCycleKlass.getName()); - }); - } - - private void registerObjectMapper(Environment environment) { - - final ObjectMapper objectMapper = environment.getObjectMapper(); - - ServiceLocatorUtilities.bind(locator, new AbstractBinder() { - @Override - protected void configure() { - bind(objectMapper).to(ObjectMapper.class); - - LOG.info("Registering Dropwizard objectMapper, class name : {}", - objectMapper.getClass().getName()); - } - }); - - } - - private void registerEnvironment(final Environment environment) { - - ServiceLocatorUtilities.bind(locator, new AbstractBinder() { - @Override - protected void configure() { - bind(environment).to(Environment.class); - - LOG.info("Registering Dropwizard environment, class name : {}", - environment.getClass().getName()); - } - }); - - } - - private void registerConfigurationProvider(final T configuration, final Environment environment) { - - ServiceLocatorUtilities.bind(locator, new AbstractBinder() { - @Override - protected void configure() { - bind(configuration); - LOG.info("Registering Dropwizard Configuration class name:{}", - configuration.getClass().getName()); - bind((Configuration) configuration).to(Configuration.class); - LOG.info("Registering Dropwizard Configuration class name:{}", - Configuration.class.getName()); - } - }); - - registerSubConfigure(configuration, environment); - - } - - private void registerSubConfigure(final T configuration, final Environment environment) { - final List subDeclaredFields = - Arrays.asList(configuration.getClass().getDeclaredFields()); - List parentDeclaredFields = Arrays.asList(Configuration.class.getDeclaredFields()); - - List filtersubDeclaredFields = subDeclaredFields.stream() - .filter(subDeclaredField -> !subDeclaredField.getType().isPrimitive()) - .filter(subDeclaredField -> !subDeclaredField.getType().equals(String.class)) - .filter(subDeclaredField -> !parentDeclaredFields.contains(subDeclaredField)) - .collect(Collectors.toList()); - - ServiceLocatorUtilities.bind(locator, new AbstractBinder() { - @Override - protected void configure() { - filtersubDeclaredFields.forEach(subField -> { - subField.setAccessible(true); - try { - Object subConfig = subField.get(configuration); - if (subConfig != null) { - bind(subConfig); - LOG.info("Registering Dropwizard Sub Configuration class name {}", - subConfig.getClass().getName()); - } - - } catch (Exception e) { - LOG.error("bind sub config:{} fail", subField); - } - }); - } - }); - - } - - private void registerServices() { - services = this.reflections.getTypesAnnotatedWith(Service.class, true); - if (!services.isEmpty()) { - ServiceLocatorUtilities.bind(locator, new ServiceBinder(services)); - services.forEach(s -> LOG.info("Registering Dropwizard service, class name : {}", s.getName())); - recordTimeCost(services); - } else { - LOG.warn("Registering Dropwizard service is empty"); - } - - } - - - private void registerResources(final Environment environment) { - reflections.getTypesAnnotatedWith(Path.class).stream().forEach(resourceClass -> { - - LOG.info("begin Registering Dropwizard resource, class name : {}", resourceClass.getName()); - try { - Object resourceObject = locator.getService(resourceClass); - if (resourceObject != null) { - environment.jersey().register(resourceObject); - LOG.info("Registering Dropwizard resource, class name : {}", resourceClass.getName()); - } else { - LOG.warn(resourceClass.getName() + " not use Service annotation"); - } - } catch (Exception e) { - LOG.error("", e); - } - }); - } - - private void registerHealthChecks(final Environment env) { - reflections.getSubTypesOf(HealthCheck.class).stream().filter(services::contains) - .forEach(healthCheckKlass -> { - try { - env.healthChecks().register(healthCheckKlass.getName(), - locator.getService(healthCheckKlass)); - } catch (Exception e) { - LOG.warn("", e); - } - LOG.info("Registering Dropwizard healthCheck, class name : {}", - healthCheckKlass.getName()); - }); - } - - private void registerService(Class annotationClazz) { - - Set> services = this.reflections.getTypesAnnotatedWith(annotationClazz, true); - if (!services.isEmpty()) { - ServiceLocatorUtilities.bind(locator, new ServiceBinder(services)); - services.forEach(s -> LOG.info("{} Registering service, class name : {}", annotationClazz.getName(), - s.getName())); - recordTimeCost(services); - } else { - LOG.warn("Registering {} service is empty", annotationClazz.getName()); - } - } - - private void recordTimeCost(Set> services) { - services.stream().filter(serviceClazz -> (serviceClazz.getAnnotation(Lazy.class) == null)) - .peek(serviceClazz -> LOG.info("active service, class name : {}", serviceClazz.getName())) - .forEach(serviceClazz -> { - try { - long startTime = System.currentTimeMillis(); - locator.getService(serviceClazz); - LOG.info("active service, class name : {},cost time:{}", serviceClazz.getName(), - (System.currentTimeMillis() - startTime)); - } catch (Exception e) { - LOG.warn("", e); - } - }); - } -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleBuider.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleBuider.java deleted file mode 100644 index a439ff0..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundleBuider.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.bundle; - -import java.util.ArrayList; -import java.util.List; - -import io.dropwizard.Configuration; - -public class AutoConfigBundleBuider { - - private static final String DEFAULT_PACKAGE_NAME="org.onap"; - - private List packageNames=new ArrayList<>(); - - public AutoConfigBundleBuider(){ - packageNames.add( DEFAULT_PACKAGE_NAME); - } - - public AutoConfigBundleBuider addPackageName(String packageName) { - this.packageNames.add(packageName); - return this; - } - - - public AutoConfigBundle build() { - return new AutoConfigBundle(packageNames); - } -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/IOCApplication.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/IOCApplication.java deleted file mode 100644 index 6025028..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/IOCApplication.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.bundle; - -import io.dropwizard.Application; -import io.dropwizard.Configuration; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; - -/** - * complete IOC container startup - * - * @author hu.rui2 - * - */ -public abstract class IOCApplication extends Application { - - - @Override - public void initialize(Bootstrap bootstrap) { - super.initialize(bootstrap); - bootstrap.addBundle(new AutoConfigBundleBuider().build()); - } - - @Override - public void run(T configuration, Environment environment) throws Exception { - - } -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/ServiceLocatorManaged.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/ServiceLocatorManaged.java deleted file mode 100644 index d6c0563..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/ServiceLocatorManaged.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.bundle; - -import org.glassfish.hk2.api.ServiceLocator; - -import io.dropwizard.lifecycle.Managed; - -/** - * Life cycle management for IOC containers - * @author hu.rui - * - */ -public class ServiceLocatorManaged implements Managed{ - - - - private ServiceLocator locator; - - - - public ServiceLocatorManaged(ServiceLocator locator) { - super(); - this.locator = locator; - } - - @Override - public void start() throws Exception { - - - } - - @Override - public void stop() throws Exception { - locator.shutdown(); - } - -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceBinder.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceBinder.java deleted file mode 100644 index f5801c8..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceBinder.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.utils; - -import java.util.Set; - -import org.glassfish.hk2.utilities.binding.AbstractBinder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author hu.rui - * - */ -public class ServiceBinder extends AbstractBinder { - - private static final Logger LOG = LoggerFactory.getLogger(ServiceBinder.class); - - final Set> klasses; - - public ServiceBinder(Set> services) { - this.klasses = services; - } - - @Override - protected void configure() { - for (Class klass : this.klasses) { - - try{ - LOG.info("start active class:"+klass.getName()); - addActiveDescriptor(klass); - }catch(Exception e){ - LOG.info("active class error:"+klass.getName(),e); - } - - - } - } -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceLocatorHolder.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceLocatorHolder.java deleted file mode 100644 index 394ab6c..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/utils/ServiceLocatorHolder.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2017 ZTE Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.dropwizard.ioc.utils; - -import org.glassfish.hk2.api.ServiceLocator; - -/** - * @author hu.rui - * - */ -public class ServiceLocatorHolder { - - private static ServiceLocator locator; - - public static ServiceLocator getLocator() { - return locator; - } - - public static void setLocator(ServiceLocator locator) { - ServiceLocatorHolder.locator = locator; - } - -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/engine/dao/EngineEntityDao.java b/holmes-actions/src/main/java/org/onap/holmes/common/engine/dao/EngineEntityDao.java index 5ca38e0..71c9827 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/engine/dao/EngineEntityDao.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/engine/dao/EngineEntityDao.java @@ -1,5 +1,5 @@ /** - * Copyright 2020 ZTE Corporation. + * Copyright 2020-2021 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,16 @@ package org.onap.holmes.common.engine.dao; +import org.jdbi.v3.sqlobject.config.RegisterRowMapper; +import org.jdbi.v3.sqlobject.customizer.Bind; +import org.jdbi.v3.sqlobject.customizer.BindBean; +import org.jdbi.v3.sqlobject.statement.SqlQuery; +import org.jdbi.v3.sqlobject.statement.SqlUpdate; import org.onap.holmes.common.engine.entity.EngineEntity; -import org.skife.jdbi.v2.sqlobject.Bind; -import org.skife.jdbi.v2.sqlobject.BindBean; -import org.skife.jdbi.v2.sqlobject.SqlQuery; -import org.skife.jdbi.v2.sqlobject.SqlUpdate; -import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper; import java.util.List; -@RegisterMapper(EngineEntityMapper.class) +@RegisterRowMapper(EngineEntityMapper.class) public interface EngineEntityDao { @SqlQuery("SELECT * FROM ENGINE_ENTITY WHERE ID = :id") EngineEntity getEntity(@Bind("id") String id); diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/engine/dao/EngineEntityMapper.java b/holmes-actions/src/main/java/org/onap/holmes/common/engine/dao/EngineEntityMapper.java index cda38a5..5432027 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/engine/dao/EngineEntityMapper.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/engine/dao/EngineEntityMapper.java @@ -1,5 +1,5 @@ /** - * Copyright 2020 ZTE Corporation. + * Copyright 2020-2021 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,20 +16,20 @@ package org.onap.holmes.common.engine.dao; +import org.jdbi.v3.core.mapper.RowMapper; +import org.jdbi.v3.core.statement.StatementContext; import org.onap.holmes.common.engine.entity.EngineEntity; -import org.skife.jdbi.v2.StatementContext; -import org.skife.jdbi.v2.tweak.ResultSetMapper; import java.sql.ResultSet; import java.sql.SQLException; -public class EngineEntityMapper implements ResultSetMapper { +public class EngineEntityMapper implements RowMapper { @Override - public EngineEntity map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException { + public EngineEntity map(ResultSet rs, StatementContext ctx) throws SQLException { EngineEntity entity = new EngineEntity(); - entity.setIp(resultSet.getString("ip")); - entity.setPort(resultSet.getInt("port")); - entity.setLastModified(resultSet.getLong("lastmodified")); + entity.setIp(rs.getString("ip")); + entity.setPort(rs.getInt("port")); + entity.setLastModified(rs.getLong("lastmodified")); return entity; } } \ No newline at end of file diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/engine/service/EngineEntityService.java b/holmes-actions/src/main/java/org/onap/holmes/common/engine/service/EngineEntityService.java index b913f38..630d55c 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/engine/service/EngineEntityService.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/engine/service/EngineEntityService.java @@ -1,5 +1,5 @@ /** - * Copyright 2020 ZTE Corporation. + * Copyright 2020-2021 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,10 @@ package org.onap.holmes.common.engine.service; -import org.jvnet.hk2.annotations.Contract; import org.onap.holmes.common.engine.entity.EngineEntity; import java.util.List; -@Contract public interface EngineEntityService { EngineEntity getEntity(String id); List getAllEntities(); diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/engine/service/impl/EngineEntityServiceImpl.java b/holmes-actions/src/main/java/org/onap/holmes/common/engine/service/impl/EngineEntityServiceImpl.java index 62d2388..7692cf9 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/engine/service/impl/EngineEntityServiceImpl.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/engine/service/impl/EngineEntityServiceImpl.java @@ -16,13 +16,13 @@ package org.onap.holmes.common.engine.service.impl; -import org.jvnet.hk2.annotations.Service; +import org.onap.holmes.common.database.DbDaoUtil; import org.onap.holmes.common.engine.dao.EngineEntityDao; import org.onap.holmes.common.engine.entity.EngineEntity; import org.onap.holmes.common.engine.service.EngineEntityService; -import org.onap.holmes.common.utils.DbDaoUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; -import javax.inject.Inject; import java.util.List; @Service @@ -30,7 +30,7 @@ public class EngineEntityServiceImpl implements EngineEntityService { private EngineEntityDao engineEntityDao; - @Inject + @Autowired public EngineEntityServiceImpl(DbDaoUtil dbDaoUtil){ engineEntityDao = dbDaoUtil.getJdbiDaoByOnDemand(EngineEntityDao.class); } diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java index e5b0830..996df25 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/AlarmInfoMapper.java @@ -1,5 +1,5 @@ /** - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2021 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,17 @@ */ package org.onap.holmes.common.utils; +import org.jdbi.v3.core.mapper.RowMapper; +import org.jdbi.v3.core.statement.StatementContext; import org.onap.holmes.common.api.entity.AlarmInfo; -import org.skife.jdbi.v2.StatementContext; -import org.skife.jdbi.v2.tweak.ResultSetMapper; + import java.sql.ResultSet; import java.sql.SQLException; -public class AlarmInfoMapper implements ResultSetMapper { +public class AlarmInfoMapper implements RowMapper { @Override - public AlarmInfo map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException { + public AlarmInfo map(ResultSet resultSet, StatementContext statementContext) throws SQLException { AlarmInfo alarmInfo = new AlarmInfo(); alarmInfo.setAlarmIsCleared(resultSet.getInt("alarmiscleared")); alarmInfo.setRootFlag(resultSet.getInt("rootflag")); diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/CommonUtils.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/CommonUtils.java index 9aa2e0b..837baed 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/CommonUtils.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/CommonUtils.java @@ -14,11 +14,12 @@ package org.onap.holmes.common.utils; -import org.jvnet.hk2.annotations.Service; + +import org.springframework.stereotype.Component; import java.util.regex.Pattern; -@Service +@Component public class CommonUtils { final static public String IP_REG = "(http(s)?://)?(\\d+\\.\\d+\\.\\d+\\.\\d+)(:(\\d+))?"; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/CorrelationRuleMapper.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/CorrelationRuleMapper.java index a0fbd93..ed1c581 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/CorrelationRuleMapper.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/CorrelationRuleMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 ZTE Corporation. + * Copyright 2017-2021 ZTE Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,18 @@ package org.onap.holmes.common.utils; +import org.jdbi.v3.core.mapper.RowMapper; +import org.jdbi.v3.core.statement.StatementContext; +import org.onap.holmes.common.api.entity.CorrelationRule; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.Properties; -import org.onap.holmes.common.api.entity.CorrelationRule; -import org.skife.jdbi.v2.StatementContext; -import org.skife.jdbi.v2.tweak.ResultSetMapper; -public class CorrelationRuleMapper implements ResultSetMapper { +public class CorrelationRuleMapper implements RowMapper { @Override - public CorrelationRule map(int i, ResultSet resultSet, StatementContext statementContext) throws SQLException { + public CorrelationRule map(ResultSet resultSet, StatementContext statementContext) throws SQLException { CorrelationRule correlationRule = new CorrelationRule(); correlationRule.setName(resultSet.getString("name")); correlationRule.setRid(resultSet.getString("rid")); diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java deleted file mode 100644 index 05792c5..0000000 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/DbDaoUtil.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright 2017-2020 ZTE Corporation. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.holmes.common.utils; - -import io.dropwizard.db.DataSourceFactory; -import io.dropwizard.jdbi.DBIFactory; -import io.dropwizard.setup.Environment; -import org.jvnet.hk2.annotations.Service; -import org.skife.jdbi.v2.DBI; -import org.skife.jdbi.v2.Handle; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Singleton; - -@Singleton -@Service -public class DbDaoUtil { - - private Logger log = LoggerFactory.getLogger(DbDaoUtil.class); - - private DBI jdbi; - @Inject - private Environment environmentProvider; - @Inject - private DataSourceFactory dataSourceFactoryProvider; - - private DBIFactory factory = new DBIFactory(); - - @PostConstruct - public synchronized void init() { - if (jdbi == null) { - jdbi = factory.build(environmentProvider, dataSourceFactoryProvider, "postgres"); - } - } - - public K getDao(Class clazz) { - try { - return jdbi.open(clazz); - } catch (Exception e) { - log.warn("get object instance of Dao error.", e); - } - return null; - } - - public Handle getHandle() { - try { - return jdbi.open(); - } catch (Exception e) { - log.warn("get object instance of Dao error.", e); - } - return null; - } - - public void close(Object obj) { - if (obj != null) { - try { - jdbi.close(obj); - } catch (Exception e) { - log.warn("close jdbi connection error.", e); - } - } - } - - public T getJdbiDaoByOnDemand(Class daoClazz) { - - return jdbi.onDemand(daoClazz); - - } - - public T getJdbiDaoByOpen(Class daoClazz) { - - return jdbi.open(daoClazz); - - } -} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java index cfb601a..d8b5215 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java @@ -16,7 +16,6 @@ package org.onap.holmes.common.utils; -import org.onap.holmes.common.exception.HttpException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java index 33b53c7..957b818 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java @@ -18,13 +18,13 @@ package org.onap.holmes.common.utils; import lombok.Setter; import org.apache.commons.lang3.StringUtils; -import org.jvnet.hk2.annotations.Service; import org.onap.holmes.common.config.MicroServiceConfig; import org.onap.holmes.common.exception.CorrelationException; import org.onap.msb.sdk.discovery.entity.MicroServiceFullInfo; import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/RestExceptionHandler.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/RestExceptionHandler.java new file mode 100644 index 0000000..f70cf68 --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/RestExceptionHandler.java @@ -0,0 +1,34 @@ +/** + * Copyright 2021 ZTE Corporation. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.holmes.common.utils; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import javax.ws.rs.WebApplicationException; + +@RestControllerAdvice +public class RestExceptionHandler { + + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(WebApplicationException.class) + public String handleWebApplicationException(WebApplicationException ex){ + return ex.getResponse().getEntity().toString(); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/SpringContextUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/SpringContextUtil.java new file mode 100644 index 0000000..b959c0a --- /dev/null +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/SpringContextUtil.java @@ -0,0 +1,45 @@ +/** + * Copyright 2021 ZTE Corporation. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.holmes.common.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class SpringContextUtil implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + SpringContextUtil.applicationContext = applicationContext; + } + + public static Object getBean(String name) { + return applicationContext.getBean(name); + } + + public static T getBean(Class clazz) { + return applicationContext.getBean(clazz); + } + + public static T getBean(String name, Class clazz) { + return applicationContext.getBean(name, clazz); + } +} diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/transactionid/TransactionIdFilter.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/transactionid/TransactionIdFilter.java index 9d42b91..725084a 100644 --- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/transactionid/TransactionIdFilter.java +++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/transactionid/TransactionIdFilter.java @@ -1,5 +1,5 @@ /** - * Copyright 2018 - 2021 ZTE Corporation. + * Copyright 2018-2021 ZTE Corporation. *

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,20 +17,22 @@ package org.onap.holmes.common.utils.transactionid; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.jvnet.hk2.annotations.Service; import org.slf4j.MDC; import org.slf4j.Marker; import org.slf4j.MarkerFactory; +import org.springframework.stereotype.Component; import javax.servlet.*; +import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.UUID; -@Service @Slf4j +@Component +@WebFilter(urlPatterns = {"/*"}) public class TransactionIdFilter implements Filter { public static final Marker INVOKE_SYNCHRONOUS; -- cgit 1.2.3-korg