2 * Copyright 2017 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.dropwizard.ioc.utils.ServiceLocatorHolder;
23 import org.onap.holmes.common.exception.CorrelationException;
24 import org.onap.holmes.dsa.dmaappolling.Subscriber;
25 import org.onap.holmes.engine.dmaap.SubscriberAction;
28 public class DcaeConfigurationPolling implements Runnable {
30 private String hostname;
32 public static long POLLING_PERIOD = 30 * 1000L;
34 public DcaeConfigurationPolling(String hostname) {
35 this.hostname = hostname;
40 DcaeConfigurations dcaeConfigurations = null;
42 dcaeConfigurations = DcaeConfigurationQuery
43 .getDcaeConfigurations(hostname);
44 } catch (CorrelationException e) {
45 log.error("Failed to poll the DCAE configurations. " + e.getMessage());
47 if (dcaeConfigurations != null) {
48 DcaeConfigurationsCache.setDcaeConfigurations(dcaeConfigurations);
49 addSubscribers(dcaeConfigurations);
53 private void addSubscribers(DcaeConfigurations dcaeConfigurations) {
54 SubscriberAction subscriberAction = ServiceLocatorHolder.getLocator()
55 .getService(SubscriberAction.class);
56 for (String key : dcaeConfigurations.getSubKeys()) {
57 Subscriber subscriber = new Subscriber();
58 subscriber.setTopic(key);
59 subscriber.setUrl(dcaeConfigurations.getSubSecInfo(key).getDmaapInfo()
61 subscriberAction.addSubscriber(subscriber);