2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.tasks;
25 import java.util.Arrays;
26 import java.util.Date;
27 import java.util.UUID;
29 import org.apache.commons.io.FilenameUtils;
30 import org.apache.commons.io.comparator.LastModifiedFileComparator;
31 import org.springframework.scheduling.annotation.Scheduled;
32 import org.springframework.stereotype.Component;
34 import org.onap.aai.logging.LoggingContext;
35 import org.onap.aai.util.AAIConfig;
36 import org.onap.aai.util.AAIConstants;
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
41 public class ScheduledTasks {
43 private static EELFLogger LOGGER = EELFManager.getInstance().getLogger(ScheduledTasks.class);
45 private static final String COMPONENT = "Scheduler";
46 private static final String FROM_APP_ID = "CronApp";
47 private static final long PROPERTY_READ_INTERVAL = 60000; // every minute
49 private String GlobalPropFileName = AAIConstants.AAI_CONFIG_FILENAME;
51 // for read and possibly reloading aaiconfig.properties and other
53 * Load AAI properties.
55 // configuration properties files
56 @Scheduled(fixedRate = PROPERTY_READ_INTERVAL)
57 public void loadAAIProperties() {
58 final UUID transId = UUID.randomUUID();
60 LoggingContext.requestId(transId);
61 LoggingContext.partnerName(FROM_APP_ID);
62 LoggingContext.component(COMPONENT);
64 String dir = FilenameUtils.getFullPathNoEndSeparator(GlobalPropFileName);
65 if (dir == null || dir.length() < 3) {
69 File pdir = new File(dir);
70 File[] files = pdir.listFiles();
71 Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
74 // leave this loop here since we may want to check other configurable
75 // property files in the SAME directory
76 for (File file : files) {
78 if (fn.equals("aaiconfig.properties")) {
79 Date lastMod = new Date(file.lastModified());
80 long lastModTm = lastMod.getTime();
81 Date curTS = new Date();
82 long curTSTm = curTS.getTime();
83 if (curTSTm - lastModTm < PROPERTY_READ_INTERVAL + 1000) {
84 AAIConfig.reloadConfig();
85 LOGGER.info("reloaded from aaiconfig.properties");