diff options
author | 2024-07-02 15:54:12 +0200 | |
---|---|---|
committer | 2024-07-04 14:56:30 +0200 | |
commit | 20fe7a7cefa72abc1294e1e972c28e86403ccb99 (patch) | |
tree | c250970cd8196947041fcfc819ca5d34bffae510 /src/main/java | |
parent | 938d2eee202bb2eb33bd43f718f157b3ad4b84c6 (diff) |
Use eclipse-temurin:8-jre-alpine docker base image in aai-graphadmin
- use /bin/sh instead of /bin/bash for scripts
- use wget instead of curl
- do not check the container user when executing scripts
Issue-ID: AAI-3916
Change-Id: I3e7c6e47f8eb55f1e2f872e7e427b61fae8232bb
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'src/main/java')
4 files changed, 46 insertions, 50 deletions
diff --git a/src/main/java/org/onap/aai/dataexport/DataExportTasks.java b/src/main/java/org/onap/aai/dataexport/DataExportTasks.java index 143312b..8d4ebb0 100644 --- a/src/main/java/org/onap/aai/dataexport/DataExportTasks.java +++ b/src/main/java/org/onap/aai/dataexport/DataExportTasks.java @@ -78,7 +78,7 @@ public class DataExportTasks { private static final Logger LOGGER; private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); - + static { System.setProperty("aai.service.name", DataExportTasks.class.getSimpleName()); Properties props = System.getProperties(); @@ -103,10 +103,10 @@ public class DataExportTasks { */ @Scheduled(cron = "${dataexporttask.cron}" ) public void export() { - + try { exportTask(); - } + } catch (Exception e) { ErrorLogHelper.logError("AAI_8002", "Exception while running export "+ LogFormatTools.getStackTop(e)); } @@ -138,14 +138,14 @@ public class DataExportTasks { } LOGGER.debug("Started exportTask: " + dateFormat.format(new Date())); - + String enableSchemaValidation = AAIConfig.get("aai.dataexport.enable.schema.validation", "false"); String outputLocation = AAIConstants.AAI_HOME_BUNDLECONFIG + AAIConfig.get("aai.dataexport.output.location"); String enableMultipleSnapshots = AAIConfig.get("aai.dataexport.enable.multiple.snapshots", "false"); String nodeConfigurationLocation = AAIConstants.AAI_HOME_BUNDLECONFIG + AAIConfig.get("aai.dataexport.node.config.location"); String inputFilterConfigurationLocation = AAIConstants.AAI_HOME_BUNDLECONFIG + AAIConfig.get("aai.dataexport.input.filter.config.location"); String enablePartialGraph = AAIConfig.get("aai.dataexport.enable.partial.graph", "true"); - + // Check that the output location exist File targetDirFile = new File(outputLocation); if ( !targetDirFile.exists() ) { @@ -155,7 +155,7 @@ public class DataExportTasks { //Delete any existing payload files deletePayload(targetDirFile); } - + File snapshot = null; String snapshotFilePath = null; if ( "false".equalsIgnoreCase(enableMultipleSnapshots)){ @@ -172,7 +172,7 @@ public class DataExportTasks { else { snapshotFilePath = findMultipleSnapshots(); } - + List<String> paramsList = new ArrayList<>(); paramsList.add("-s"); paramsList.add(enableSchemaValidation); @@ -188,10 +188,10 @@ public class DataExportTasks { paramsList.add(enablePartialGraph); paramsList.add("-d"); paramsList.add(snapshotFilePath); - + LOGGER.debug("paramsList is : " + paramsList); - - String[] paramsArray = paramsList.toArray(new String[0]); + + String[] paramsArray = paramsList.toArray(new String[0]); try { DynamicPayloadGenerator.run(loaderFactory, edgeIngestor, schemaVersions, paramsArray, false); LOGGER.debug("DynamicPaylodGenerator completed"); @@ -208,7 +208,7 @@ public class DataExportTasks { } LOGGER.info("Ended exportTask: " + dateFormat.format(new Date())); auditLog.logAfter(); - + } /** * The isDataExportRunning method, checks if the data export task was started separately via command line @@ -220,7 +220,7 @@ public class DataExportTasks { int count = 0; try { - process = new ProcessBuilder().command("bash", "-c", "ps -ef | grep '[D]ynamicPayloadGenerator'").start(); + process = new ProcessBuilder().command("sh", "-c", "ps -ef | grep '[D]ynamicPayloadGenerator'").start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); @@ -244,11 +244,11 @@ public class DataExportTasks { * @return a single snapshot File */ private static File findSnapshot() { - String targetDir = AAIConstants.AAI_HOME + AAIConstants.AAI_FILESEP + "logs" + AAIConstants.AAI_FILESEP + "data" + + String targetDir = AAIConstants.AAI_HOME + AAIConstants.AAI_FILESEP + "logs" + AAIConstants.AAI_FILESEP + "data" + AAIConstants.AAI_FILESEP + "dataSnapshots"; File snapshot = null; File targetDirFile = new File(targetDir); - + File[] allFilesArr = targetDirFile.listFiles((FileFilter) FileFileFilter.FILE); if ( allFilesArr == null || allFilesArr.length == 0 ) { ErrorLogHelper.logError("AAI_8001", "Unable to find data snapshots at " + targetDir); @@ -265,18 +265,18 @@ public class DataExportTasks { } return (snapshot); } - + /** * The method findMultipleSnapshots looks in the data snapshots directory for a set of snapshot files that match the pattern. * @return the file name prefix corresponding to the second to last set of snapshots */ private static String findMultipleSnapshots() { - String targetDir = AAIConstants.AAI_HOME + AAIConstants.AAI_FILESEP + "logs" + AAIConstants.AAI_FILESEP + "data" + + String targetDir = AAIConstants.AAI_HOME + AAIConstants.AAI_FILESEP + "logs" + AAIConstants.AAI_FILESEP + "data" + AAIConstants.AAI_FILESEP + "dataSnapshots"; String snapshotName = null; File targetDirFile = new File(targetDir); TreeMap<String,List<File>> fileMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); - + /*dataSnapshot.graphSON.201804022009.P0 dataSnapshot.graphSON.201804022009.P1 dataSnapshot.graphSON.201804022009.P2 @@ -284,16 +284,16 @@ public class DataExportTasks { dataSnapshot.graphSON.201804022009.P4*/ String snapshotPattern = "^.*dataSnapshot\\.graphSON\\.(\\d+)\\.P.*$"; Pattern p = Pattern.compile (snapshotPattern); - + FileFilter fileFilter = new RegexFileFilter("^.*dataSnapshot\\.graphSON\\.(\\d+)\\.P.*$"); File[] allFilesArr = targetDirFile.listFiles(fileFilter); - + if ( allFilesArr == null || allFilesArr.length == 0 ) { ErrorLogHelper.logError("AAI_8001", "Unable to find data snapshots at " + targetDir); LOGGER.debug("Unable to find data snapshots at " + targetDir); return (null); } - + if ( allFilesArr.length > 1 ) { Arrays.sort(allFilesArr, LastModifiedFileComparator.LASTMODIFIED_REVERSE); for ( File f : allFilesArr ) { @@ -317,13 +317,13 @@ public class DataExportTasks { } if ( fileMap.size() > 1 ) { NavigableMap<String,List<File>> dmap = fileMap.descendingMap(); - + Map.Entry<String,List<File>> fentry = dmap.firstEntry(); LOGGER.debug ("First key in descending map " + fentry.getKey()); - + Map.Entry<String,List<File>> lentry = dmap.higherEntry(fentry.getKey()); LOGGER.debug ("Next key in descending map " + lentry.getKey()); - + List<File> l = lentry.getValue(); snapshotName = l.get(0).getAbsolutePath(); // Remove the .P* extension @@ -348,7 +348,7 @@ public class DataExportTasks { * @throws AAIException */ private static void deletePayload(File targetDirFile) { - + File[] allFilesArr = targetDirFile.listFiles((FileFilter)DirectoryFileFilter.DIRECTORY); if ( allFilesArr == null || allFilesArr.length == 0 ) { LOGGER.debug("No payload files found at " + targetDirFile.getPath()); @@ -359,12 +359,12 @@ public class DataExportTasks { FileUtils.deleteDirectory(f); } catch (IOException e) { - + LOGGER.debug("Unable to delete directory " + f.getAbsolutePath() + " " + e.getMessage()); } - + } - + } /** * The runScript method runs a shell script/command with a variable number of arguments @@ -380,6 +380,6 @@ public class DataExportTasks { ErrorLogHelper.logError("AAI_8002", "Exception while running dynamicPayloadArchive.sh "+ LogFormatTools.getStackTop(e)); LOGGER.debug("Exception while running dynamicPayloadArchive.sh" + LogFormatTools.getStackTop(e)); } - + } } diff --git a/src/main/java/org/onap/aai/datagrooming/DataGroomingTasks.java b/src/main/java/org/onap/aai/datagrooming/DataGroomingTasks.java index 21f3172..4e162ca 100644 --- a/src/main/java/org/onap/aai/datagrooming/DataGroomingTasks.java +++ b/src/main/java/org/onap/aai/datagrooming/DataGroomingTasks.java @@ -49,7 +49,7 @@ import org.springframework.stereotype.Component; public class DataGroomingTasks { private AaiScheduledTaskAuditLog auditLog; - + private static final Logger LOGGER = LoggerFactory.getLogger(DataGroomingTasks.class); private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); @@ -70,7 +70,7 @@ public class DataGroomingTasks { return; } } - + LOGGER.debug("Started cron job dataGrooming @ " + dateFormat.format(new Date())); Map<String, String> dataGroomingFlagMap = new HashMap<>(); @@ -111,7 +111,7 @@ public class DataGroomingTasks { paramsArray.add("-dontFixOrphans"); } if("true".equals(dataGroomingFlagMap.get("enabletimewindowminutes"))){ - paramsArray.add("-timeWindowMinutes"); + paramsArray.add("-timeWindowMinutes"); paramsArray.add(dataGroomingFlagMap.get("timewindowminutesvalue")); } if("true".equals(dataGroomingFlagMap.get("enableskiphostcheck"))){ @@ -119,19 +119,19 @@ public class DataGroomingTasks { } if("true".equals(dataGroomingFlagMap.get("enablesleepminutes"))) { - paramsArray.add("-sleepMinutes"); + paramsArray.add("-sleepMinutes"); paramsArray.add(dataGroomingFlagMap.get("sleepminutesvalue")); } - + if("true".equals(dataGroomingFlagMap.get("enableedgesonly"))){ paramsArray.add("-edgesOnly"); } if("true".equals(dataGroomingFlagMap.get("enableskipedgechecks"))) { paramsArray.add("-skipEdgeChecks"); } - + if("true".equals(dataGroomingFlagMap.get("enablemaxfix"))) { - paramsArray.add("-maxFix"); + paramsArray.add("-maxFix"); paramsArray.add(dataGroomingFlagMap.get("maxfixvalue")); } if("true".equals(dataGroomingFlagMap.get("enabledupecheckoff"))){ @@ -151,7 +151,7 @@ public class DataGroomingTasks { paramsArray.add("-f"); paramsArray.add(dataGroomingFlagMap.get("fvalue")); } - + DataGrooming dataGrooming = new DataGrooming(loaderFactory, schemaVersions); String[] paramsList = paramsArray.toArray(new String[0]); if (AAIConfig.get("aai.cron.enable.dataGrooming").equals("true")) { @@ -174,7 +174,7 @@ public class DataGroomingTasks { int count = 0; try { - process = new ProcessBuilder().command("bash", "-c", "ps -ef | grep '[D]ataGrooming'").start(); + process = new ProcessBuilder().command("sh", "-c", "ps -ef | grep '[D]ataGrooming'").start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); diff --git a/src/main/java/org/onap/aai/datasnapshot/DataSnapshotTasks.java b/src/main/java/org/onap/aai/datasnapshot/DataSnapshotTasks.java index 15fff4b..d8cb65a 100644 --- a/src/main/java/org/onap/aai/datasnapshot/DataSnapshotTasks.java +++ b/src/main/java/org/onap/aai/datasnapshot/DataSnapshotTasks.java @@ -45,13 +45,13 @@ import org.slf4j.MDC; @Component @PropertySource("file:${server.local.startpath}/etc/appprops/datatoolscrons.properties") public class DataSnapshotTasks { - + private AaiScheduledTaskAuditLog auditLog; - + private static final Logger LOGGER = LoggerFactory.getLogger(DataSnapshotTasks.class); private final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); - + @Scheduled(cron = "${datasnapshottasks.cron}" ) public void snapshotScheduleTask() throws AAIException, Exception { auditLog = new AaiScheduledTaskAuditLog(); @@ -86,7 +86,7 @@ public class DataSnapshotTasks { int count = 0; try { - process = new ProcessBuilder().command("bash", "-c", "ps -ef | grep '[D]ataSnapshot'").start(); + process = new ProcessBuilder().command("sh", "-c", "ps -ef | grep '[D]ataSnapshot'").start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); @@ -103,5 +103,3 @@ public class DataSnapshotTasks { return count > 0; } } - - diff --git a/src/main/java/org/onap/aai/historytruncate/HistoryTruncateTasks.java b/src/main/java/org/onap/aai/historytruncate/HistoryTruncateTasks.java index ec6fac3..a2ff86c 100644 --- a/src/main/java/org/onap/aai/historytruncate/HistoryTruncateTasks.java +++ b/src/main/java/org/onap/aai/historytruncate/HistoryTruncateTasks.java @@ -52,7 +52,7 @@ public class HistoryTruncateTasks { @Scheduled(cron = "${historytruncatetasks.cron}" ) public void historyTruncateScheduleTask() throws AAIException, Exception { - + if(!"true".equals(AAIConfig.get("aai.disable.check.historytruncate.running", "false"))){ if(checkIfHistoryTruncateIsRunning()){ LOGGER.debug("History Truncate is already running on the system"); @@ -65,9 +65,9 @@ public class HistoryTruncateTasks { try { if (AAIConfig.get("aai.cron.enable.historytruncate").equals("true")) { // Until we're comfortable with how it is working, we will keep it in "LOG_ONLY" mode - String defaultTruncMode = "LOG_ONLY"; - String defaultTruncWindowDays = "999"; - String [] params = {"-truncateMode",defaultTruncMode,"-truncateWindowDays",defaultTruncWindowDays}; + String defaultTruncMode = "LOG_ONLY"; + String defaultTruncWindowDays = "999"; + String [] params = {"-truncateMode",defaultTruncMode,"-truncateWindowDays",defaultTruncWindowDays}; HistoryTruncate.main(params); } } @@ -87,7 +87,7 @@ public class HistoryTruncateTasks { int count = 0; try { - process = new ProcessBuilder().command("bash", "-c", "ps -ef | grep '[H]istoryTruncate'").start(); + process = new ProcessBuilder().command("sh", "-c", "ps -ef | grep '[H]istoryTruncate'").start(); InputStream is = process.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); @@ -104,5 +104,3 @@ public class HistoryTruncateTasks { return count > 0; } } - - |