2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.drools.legacy.config;
24 import java.util.List;
25 import java.util.Properties;
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;
38 * Legacy Configurator.
41 public class LegacyConfig implements Startable, TopicListener {
43 private static final Logger logger = LoggerFactory.getLogger(LegacyConfig.class);
44 private static final String CONFIGURATION_PROPERTIES_NAME = "feature-legacy-config";
46 private final Properties properties;
48 private final TopicSource source;
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");
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);
66 source.register(this);
70 public boolean start() {
71 return source.start();
75 public boolean stop() {
80 public void shutdown() {
85 public boolean isAlive() {
86 return source.isAlive();
90 public void onTopicEvent(Topic.CommInfrastructure comm, String topic, String event) {
91 PolicyEngineConstants.getManager().onTopicEvent(comm, topic, event);