Removing deprecated DMAAP library
[policy/drools-pdp.git] / feature-legacy-config / src / main / java / org / onap / policy / drools / legacy / config / LegacyConfig.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2024 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.drools.legacy.config;
23
24 import java.util.List;
25 import java.util.Properties;
26 import lombok.Getter;
27 import org.onap.policy.common.capabilities.Startable;
28 import org.onap.policy.common.endpoints.event.comm.Topic;
29 import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
30 import org.onap.policy.common.endpoints.event.comm.TopicListener;
31 import org.onap.policy.common.endpoints.event.comm.TopicSource;
32 import org.onap.policy.drools.persistence.SystemPersistenceConstants;
33 import org.onap.policy.drools.system.PolicyEngineConstants;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36
37 /**
38  * Legacy Configurator.
39  */
40 @Getter
41 public class LegacyConfig implements Startable, TopicListener {
42
43     private static final Logger logger = LoggerFactory.getLogger(LegacyConfig.class);
44     private static final String CONFIGURATION_PROPERTIES_NAME = "feature-legacy-config";
45
46     private final Properties properties;
47
48     private final TopicSource source;
49
50     /**
51      * Constructor.
52      */
53     public LegacyConfig() {
54         properties = SystemPersistenceConstants.getManager().getProperties(CONFIGURATION_PROPERTIES_NAME);
55         List<TopicSource> sources = TopicEndpointManager.getManager().addTopicSources(properties);
56         if (sources.isEmpty()) {
57             throw new IllegalStateException("LegacyConfig cannot be instantiated, no sources");
58         }
59
60         this.source = sources.get(0);
61         if (sources.size() != 1) {
62             logger.warn("LegacyConfig: more than one source is configured ({}), using {}",
63                     sources.size(), this.source);
64         }
65
66         source.register(this);
67     }
68
69     @Override
70     public boolean start() {
71         return source.start();
72     }
73
74     @Override
75     public boolean stop() {
76         return source.stop();
77     }
78
79     @Override
80     public void shutdown() {
81         source.shutdown();
82     }
83
84     @Override
85     public boolean isAlive() {
86         return source.isAlive();
87     }
88
89     @Override
90     public void onTopicEvent(Topic.CommInfrastructure comm, String topic, String event) {
91         PolicyEngineConstants.getManager().onTopicEvent(comm, topic, event);
92     }
93 }