2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
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============================================
20 * ===================================================================
24 package org.onap.clamp.policy.downloader;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
29 import java.time.Instant;
30 import java.util.ArrayList;
31 import java.util.LinkedHashMap;
32 import java.util.List;
33 import java.util.Map.Entry;
35 import org.onap.clamp.clds.client.PolicyEngineServices;
36 import org.onap.clamp.loop.template.PolicyModelsRepository;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.context.annotation.Configuration;
39 import org.springframework.context.annotation.Profile;
40 import org.springframework.scheduling.annotation.Scheduled;
41 import org.yaml.snakeyaml.Yaml;
44 * This class implements a periodic job that is done in the background to
45 * synchronize policy models available on the policy engine and the clamp
46 * database table PolicyModel.
49 @Profile("clamp-policy-controller")
50 public class PolicyEngineController {
52 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(PolicyEngineController.class);
53 protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
54 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
55 public static final String POLICY_RETRY_INTERVAL = "policy.retry.interval";
56 public static final String POLICY_RETRY_LIMIT = "policy.retry.limit";
58 private final PolicyEngineServices policyEngineServices;
60 private Instant lastInstantExecuted;
63 public PolicyEngineController(PolicyEngineServices policyEngineService,
64 PolicyModelsRepository policyModelsRepository) {
65 this.policyEngineServices = policyEngineService;
68 @Scheduled(fixedRate = 120000)
69 public synchronized void synchronizeAllPolicies() {
70 policyEngineServices.synchronizeAllPolicies();
71 lastInstantExecuted = Instant.now();
74 public Instant getLastInstantExecuted() {
75 return lastInstantExecuted;