2 * Copyright 2017 - 2021 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.holmes.engine.dcae;
18 import lombok.extern.slf4j.Slf4j;
19 import org.onap.holmes.common.dcae.DcaeConfigurationQuery;
20 import org.onap.holmes.common.dcae.DcaeConfigurationsCache;
21 import org.onap.holmes.common.dcae.entity.DcaeConfigurations;
22 import org.onap.holmes.common.exception.CorrelationException;
23 import org.onap.holmes.common.utils.Md5Util;
24 import org.onap.holmes.common.utils.SpringContextUtil;
25 import org.onap.holmes.dsa.dmaappolling.Subscriber;
26 import org.onap.holmes.engine.dmaap.SubscriberAction;
30 public class DcaeConfigurationPolling implements Runnable {
32 private String hostname;
34 public static final long POLLING_PERIOD = 30 * 1000L;
36 private String prevConfigMd5 = Md5Util.md5(null);
38 public DcaeConfigurationPolling(String hostname) {
39 this.hostname = hostname;
44 DcaeConfigurations dcaeConfigurations = null;
46 dcaeConfigurations = DcaeConfigurationQuery.getDcaeConfigurations(hostname);
47 String md5 = Md5Util.md5(dcaeConfigurations);
48 if (prevConfigMd5.equals(md5)) {
49 log.info("Operation aborted due to identical Configurations.");
53 } catch (CorrelationException e) {
54 log.error("Failed to poll the DCAE configurations. " + e.getMessage(), e);
55 } catch (Exception e) {
56 log.info("Failed to generate the MD5 information for new configurations.", e);
58 if (dcaeConfigurations != null) {
59 DcaeConfigurationsCache.setDcaeConfigurations(dcaeConfigurations);
60 addSubscribers(dcaeConfigurations);
64 private void addSubscribers(DcaeConfigurations dcaeConfigurations) {
65 SubscriberAction subscriberAction = SpringContextUtil.getBean(SubscriberAction.class);
66 for (String key : dcaeConfigurations.getSubKeys()) {
67 Subscriber subscriber = new Subscriber();
68 subscriber.setTopic(key);
69 subscriber.setUrl(dcaeConfigurations.getSubSecInfo(key).getDmaapInfo()
71 subscriberAction.addSubscriber(subscriber);