modify not publish messages to DMaaP
[holmes/engine-management.git] / engine-d / src / main / java / org / onap / holmes / engine / dcaepolling / DcaeConfigurationPolling.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.holmes.engine.dcaepolling;
17
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.dmaappolling.SubscriberAction;
26
27 @Slf4j
28 public class DcaeConfigurationPolling implements Runnable{
29
30     private String hostname;
31
32     private String subscriberKey = "sec_fault_unsecure";
33
34     public static long POLLING_PERIOD = 10 * 1000L;
35
36     public DcaeConfigurationPolling(String hostname) {
37         this.hostname = hostname;
38     }
39
40     @Override
41     public void run() {
42         DcaeConfigurations dcaeConfigurations = null;
43         try {
44             dcaeConfigurations = DcaeConfigurationQuery
45                     .getDcaeConfigurations(hostname);
46         } catch (CorrelationException e) {
47             log.error("Failed to polling dcae configurations" + e.getMessage());
48         }
49         if (dcaeConfigurations != null) {
50             DcaeConfigurationsCache.setDcaeConfigurations(dcaeConfigurations);
51             addSubscriber(dcaeConfigurations);
52         }
53     }
54
55     private void addSubscriber(DcaeConfigurations dcaeConfigurations) {
56         SubscriberAction subscriberAction = ServiceLocatorHolder.getLocator()
57                 .getService(SubscriberAction.class);
58         Subscriber subscriber = new Subscriber();
59         subscriber.setUrl(dcaeConfigurations.getSubSecInfo(subscriberKey).getDmaapInfo()
60                 .getTopicUrl());
61         subscriberAction.addSubscriber(subscriber);
62     }
63 }