2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.tasks;
23 import org.apache.commons.io.FilenameUtils;
24 import org.apache.commons.io.comparator.LastModifiedFileComparator;
25 import org.onap.aai.aailog.logs.AaiScheduledTaskAuditLog;
26 import org.onap.aai.util.AAIConfig;
27 import org.onap.aai.util.AAIConstants;
28 import org.onap.logging.filter.base.ONAPComponents;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.scheduling.annotation.Scheduled;
33 import org.springframework.stereotype.Component;
36 import java.util.Arrays;
37 import java.util.Date;
40 public class ScheduledTasks {
43 private AaiScheduledTaskAuditLog auditLog;
45 private static Logger LOGGER = LoggerFactory.getLogger(ScheduledTasks.class);
46 private static final long PROPERTY_READ_INTERVAL = 60000; // every minute
47 private String GlobalPropFileName = AAIConstants.AAI_CONFIG_FILENAME;
49 // for read and possibly reloading aaiconfig.properties and other
51 * Load AAI properties.
53 // configuration properties files
54 @Scheduled(fixedRate = PROPERTY_READ_INTERVAL)
55 public void loadAAIProperties() {
56 auditLog.logBefore("LoadAaiPropertiesTask", ONAPComponents.AAI.toString() );
57 String dir = FilenameUtils.getFullPathNoEndSeparator(GlobalPropFileName);
58 if (dir == null || dir.length() < 3) {
62 File pdir = new File(dir);
63 File[] files = pdir.listFiles();
64 Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
67 // leave this loop here since we may want to check other configurable
68 // property files in the SAME directory
69 for (File file : files) {
71 if (fn.equals("aaiconfig.properties")) {
72 Date lastMod = new Date(file.lastModified());
73 long lastModTm = lastMod.getTime();
74 Date curTS = new Date();
75 long curTSTm = curTS.getTime();
76 if (curTSTm - lastModTm < PROPERTY_READ_INTERVAL + 1000) {
77 AAIConfig.reloadConfig();
78 LOGGER.debug("reloaded from aaiconfig.properties");