diff options
author | Young Gyu Park <younggyu@google.com> | 2018-04-23 14:36:59 +0900 |
---|---|---|
committer | Keun Soo Yim <yim@google.com> | 2018-04-24 04:42:02 +0000 |
commit | e77faad0c7aa2e79e979ec0c868164dca1b43dca (patch) | |
tree | 5505937fdba102ce2f4c81dedf4259f8a50dfed7 /src/main | |
parent | c01654f86a88f758622aa714ffd903259b449bfa (diff) | |
download | dashboard-e77faad0c7aa2e79e979ec0c868164dca1b43dca.tar.gz |
Scheduling logic improvement for missing time at the end of day.
Test: checking cloud console log
Bug: 78434468
Change-Id: I2e309bdf6f7a9f00f45189cb8a3a39b960b41862
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/android/vts/job/VtsSuiteTestJobServlet.java | 144 | ||||
-rw-r--r-- | src/main/java/com/android/vts/util/TimeUtil.java | 15 |
2 files changed, 96 insertions, 63 deletions
diff --git a/src/main/java/com/android/vts/job/VtsSuiteTestJobServlet.java b/src/main/java/com/android/vts/job/VtsSuiteTestJobServlet.java index 1beffef..137f682 100644 --- a/src/main/java/com/android/vts/job/VtsSuiteTestJobServlet.java +++ b/src/main/java/com/android/vts/job/VtsSuiteTestJobServlet.java @@ -65,6 +65,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; import java.time.Instant; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; @@ -135,72 +137,92 @@ public class VtsSuiteTestJobServlet extends HttpServlet { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - logger.log(Level.INFO, "Job Started!!!!!!!!!!!!!"); + List<String> dateStringList = new ArrayList<>(); long currentMicroSecond = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); - String todayDateString = TimeUtil.getDateString(currentMicroSecond); - String[] dateArray = todayDateString.split("-"); - if (dateArray.length == 3) { - - Queue queue = QueueFactory.getQueue(QUEUE); - - List<TaskOptions> tasks = new ArrayList<>(); - - String fileSeparator = FileSystems.getDefault().getSeparator(); - String year = dateArray[0]; - String month = dateArray[1]; - String day = dateArray[2]; - - List<String> pathList = Arrays.asList(GCS_SUITE_TEST_FOLDER_NAME, year, month, day); - Path pathInfo = Paths.get(String.join(fileSeparator, pathList)); - - List<TestSuiteFileEntity> testSuiteFileEntityList = - ofy().load() - .type(TestSuiteFileEntity.class) - .filter("year", Integer.parseInt(year)) - .filter("month", Integer.parseInt(month)) - .filter("day", Integer.parseInt(day)) - .list(); - - List<String> filePathList = - testSuiteFileEntityList - .stream() - .map(testSuiteFile -> testSuiteFile.getFilePath()) - .collect(Collectors.toList()); - - Bucket vtsReportBucket = this.storage.get(GCS_BUCKET_NAME); - - Storage.BlobListOption[] listOptions = - new Storage.BlobListOption[] { - Storage.BlobListOption.prefix(pathInfo.toString() + fileSeparator) - }; - - Iterable<Blob> blobIterable = vtsReportBucket.list(listOptions).iterateAll(); - Iterator<Blob> blobIterator = blobIterable.iterator(); - while (blobIterator.hasNext()) { - Blob blob = blobIterator.next(); - if (blob.isDirectory()) { - logger.log(Level.INFO, blob.getName() + " directory will be skipped!"); - } else { - if (filePathList.contains(blob.getName())) { - logger.log(Level.INFO, "filePathList contain => " + blob.getName()); - } else if (blob.getName().endsWith(fileSeparator)) { - logger.log(Level.INFO, blob.getName() + " endswith slash!"); + ZonedDateTime checkZonedDateTime = TimeUtil.getZonedDateTime(currentMicroSecond); + String checkDateString = + DateTimeFormatter.ofPattern(TimeUtil.DATE_FORMAT) + .format(checkZonedDateTime.minusMinutes(5)); + String todayDateString = TimeUtil.getDateString(currentMicroSecond); + if (!checkDateString.equals(todayDateString)) { + dateStringList.add(checkDateString); + logger.log(Level.INFO, "Yesterday is added to the process queue and processed!"); + } + dateStringList.add(todayDateString); + + dateStringList.forEach( + dateString -> { + String[] dateArray = dateString.split("-"); + if (dateArray.length == 3) { + + Queue queue = QueueFactory.getQueue(QUEUE); + + List<TaskOptions> tasks = new ArrayList<>(); + + String fileSeparator = FileSystems.getDefault().getSeparator(); + + String year = dateArray[0]; + String month = dateArray[1]; + String day = dateArray[2]; + + List<String> pathList = + Arrays.asList(GCS_SUITE_TEST_FOLDER_NAME, year, month, day); + Path pathInfo = Paths.get(String.join(fileSeparator, pathList)); + + List<TestSuiteFileEntity> testSuiteFileEntityList = + ofy().load() + .type(TestSuiteFileEntity.class) + .filter("year", Integer.parseInt(year)) + .filter("month", Integer.parseInt(month)) + .filter("day", Integer.parseInt(day)) + .list(); + + List<String> filePathList = + testSuiteFileEntityList + .stream() + .map(testSuiteFile -> testSuiteFile.getFilePath()) + .collect(Collectors.toList()); + + Bucket vtsReportBucket = this.storage.get(GCS_BUCKET_NAME); + + Storage.BlobListOption[] listOptions = + new Storage.BlobListOption[] { + Storage.BlobListOption.prefix( + pathInfo.toString() + fileSeparator) + }; + + Iterable<Blob> blobIterable = + vtsReportBucket.list(listOptions).iterateAll(); + Iterator<Blob> blobIterator = blobIterable.iterator(); + while (blobIterator.hasNext()) { + Blob blob = blobIterator.next(); + if (blob.isDirectory()) { + logger.log( + Level.INFO, blob.getName() + " directory will be skipped!"); + } else { + if (filePathList.contains(blob.getName())) { + logger.log( + Level.INFO, + "filePathList contain => " + blob.getName()); + } else if (blob.getName().endsWith(fileSeparator)) { + logger.log(Level.INFO, blob.getName() + " endswith slash!"); + } else { + TaskOptions task = + TaskOptions.Builder.withUrl(SUITE_TEST_URL) + .param("filePath", blob.getName()) + .method(TaskOptions.Method.POST); + tasks.add(task); + } + } + } + TaskQueueHelper.addToQueue(queue, tasks); } else { - TaskOptions task = - TaskOptions.Builder.withUrl(SUITE_TEST_URL) - .param("filePath", blob.getName()) - .method(TaskOptions.Method.POST); - tasks.add(task); + throw new IllegalArgumentException( + todayDateString + " date string not in correct format"); } - } - } - TaskQueueHelper.addToQueue(queue, tasks); - } else { - throw new IllegalArgumentException( - todayDateString + " date string not in correct format"); - } + }); } @Override diff --git a/src/main/java/com/android/vts/util/TimeUtil.java b/src/main/java/com/android/vts/util/TimeUtil.java index 69fbc29..46ed55a 100644 --- a/src/main/java/com/android/vts/util/TimeUtil.java +++ b/src/main/java/com/android/vts/util/TimeUtil.java @@ -26,8 +26,8 @@ import java.util.logging.Logger; public class TimeUtil { protected static final Logger logger = Logger.getLogger(TimeUtil.class.getName()); - protected static final String DATE_FORMAT = "yyyy-MM-dd"; - protected static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss (z)"; + public static final String DATE_FORMAT = "yyyy-MM-dd"; + public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss (z)"; public static final ZoneId PT_ZONE = ZoneId.of("America/Los_Angeles"); /** @@ -53,4 +53,15 @@ public class TimeUtil { ZonedDateTime zdt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timeMillis), PT_ZONE); return DateTimeFormatter.ofPattern(DATE_FORMAT).format(zdt); } + + /** + * Create a ZonedDateTime object from the provided timestamp. + * + * @param timeMicroseconds The time in microseconds + * @return A ZonedDateTime object. + */ + public static ZonedDateTime getZonedDateTime(long timeMicroseconds) { + long timeMillis = TimeUnit.MICROSECONDS.toMillis(timeMicroseconds); + return ZonedDateTime.ofInstant(Instant.ofEpochMilli(timeMillis), PT_ZONE); + } } |