2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.aai.tasks;
24 import java.util.Arrays;
25 import java.util.Date;
26 import java.util.UUID;
28 import org.apache.commons.io.FilenameUtils;
29 import org.apache.commons.io.comparator.LastModifiedFileComparator;
30 import org.springframework.scheduling.annotation.Scheduled;
31 import org.springframework.stereotype.Component;
33 import org.openecomp.aai.logging.LoggingContext;
34 import org.openecomp.aai.util.AAIConfig;
35 import org.openecomp.aai.util.AAIConstants;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
40 public class ScheduledTasks {
42 private static EELFLogger LOGGER = EELFManager.getInstance().getLogger(ScheduledTasks.class);
44 private static final String COMPONENT = "Scheduler";
45 private static final String FROM_APP_ID = "CronApp";
46 private static final long PROPERTY_READ_INTERVAL = 60000; // every minute
48 private String GlobalPropFileName = AAIConstants.AAI_CONFIG_FILENAME;
50 // for read and possibly reloading aaiconfig.properties and other
52 * Load AAI properties.
54 // configuration properties files
55 @Scheduled(fixedRate = PROPERTY_READ_INTERVAL)
56 public void loadAAIProperties() {
57 final UUID transId = UUID.randomUUID();
59 LoggingContext.requestId(transId);
60 LoggingContext.partnerName(FROM_APP_ID);
61 LoggingContext.component(COMPONENT);
63 String dir = FilenameUtils.getFullPathNoEndSeparator(GlobalPropFileName);
64 if (dir == null || dir.length() < 3) {
68 File pdir = new File(dir);
69 File[] files = pdir.listFiles();
70 Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
73 // leave this loop here since we may want to check other configurable
74 // property files in the SAME directory
75 for (File file : files) {
77 if (fn.equals("aaiconfig.properties")) {
78 Date lastMod = new Date(file.lastModified());
79 long lastModTm = lastMod.getTime();
80 Date curTS = new Date();
81 long curTSTm = curTS.getTime();
82 if (curTSTm - lastModTm < PROPERTY_READ_INTERVAL + 1000) {
83 AAIConfig.reloadConfig();
84 LOGGER.info("reloaded from aaiconfig.properties");