diff options
author | Young Gyu Park <younggyu@google.com> | 2018-10-30 09:47:04 +0900 |
---|---|---|
committer | Young Gyu Park <younggyu@google.com> | 2018-11-05 15:17:48 +0900 |
commit | 36c1ab52b47c095e438cbe3273b09fe32455a9be (patch) | |
tree | 27f776e383142d15e0e5eb00dae6efdecb66963a | |
parent | 588c2b9fa4351eeee60857a04f36a61cbd4dc0a4 (diff) | |
download | dashboard-36c1ab52b47c095e438cbe3273b09fe32455a9be.tar.gz |
Updating util classes, listener and job servlet for HalApiEntity
Test: go/vts-web-staging
Bug: 117130291
Change-Id: I6fb295a15fdc6ad6c4ad768b81f0074643ef69b6
8 files changed, 283 insertions, 290 deletions
diff --git a/src/main/java/com/android/vts/api/DatastoreRestServlet.java b/src/main/java/com/android/vts/api/DatastoreRestServlet.java index c5c097f..5ddf18d 100644 --- a/src/main/java/com/android/vts/api/DatastoreRestServlet.java +++ b/src/main/java/com/android/vts/api/DatastoreRestServlet.java @@ -458,7 +458,7 @@ public class DatastoreRestServlet extends BaseApiServlet { long startTimestamp = -1; long endTimestamp = -1; String testBuildId = null; - long type = 0; + long testType = -1; Set<DeviceInfoEntity> deviceInfoEntitySet = new HashSet<>(); for (TestRunEntity testRunEntity : testRunEntityMap.values()) { passCount += testRunEntity.getPassCount(); @@ -469,7 +469,7 @@ public class DatastoreRestServlet extends BaseApiServlet { if (endTimestamp < 0 || testRunEntity.getEndTimestamp() > endTimestamp) { endTimestamp = testRunEntity.getEndTimestamp(); } - type = testRunEntity.getType(); + testType = testRunEntity.getType(); testBuildId = testRunEntity.getTestBuildId(); List<DeviceInfoEntity> deviceInfoEntityListWithTestRunKey = @@ -483,10 +483,10 @@ public class DatastoreRestServlet extends BaseApiServlet { } } - if (startTimestamp < 0 || testBuildId == null || type == 0) { + if (startTimestamp < 0 || testBuildId == null || testType == -1) { log.debug("startTimestamp => " + startTimestamp); log.debug("testBuildId => " + testBuildId); - log.debug("type => " + type); + log.debug("type => " + testType); log.error("Couldn't infer test run information from runs."); return; } @@ -495,7 +495,7 @@ public class DatastoreRestServlet extends BaseApiServlet { new TestPlanRunEntity( testPlanEntity.getKey(), testPlanName, - type, + testType, startTimestamp, endTimestamp, testBuildId, @@ -528,7 +528,7 @@ public class DatastoreRestServlet extends BaseApiServlet { .collect(Collectors.toList()); HalApiEntity halApiEntity = new HalApiEntity( - testPlanRunEntity.getParent(), + testPlanRunEntity.getOfyKey(), halInterfaceMessage.getHalReleaseLevel().toStringUtf8(), halInterfaceMessage.getHalPackageName().toStringUtf8(), halInterfaceMessage.getHalVersionMajor(), diff --git a/src/main/java/com/android/vts/config/ObjectifyListener.java b/src/main/java/com/android/vts/config/ObjectifyListener.java index 9c4a705..5f35abd 100644 --- a/src/main/java/com/android/vts/config/ObjectifyListener.java +++ b/src/main/java/com/android/vts/config/ObjectifyListener.java @@ -23,6 +23,7 @@ import com.android.vts.entity.ApiCoverageExcludedEntity; import com.android.vts.entity.CodeCoverageEntity; import com.android.vts.entity.CoverageEntity; import com.android.vts.entity.DeviceInfoEntity; +import com.android.vts.entity.HalApiEntity; import com.android.vts.entity.ProfilingPointEntity; import com.android.vts.entity.ProfilingPointRunEntity; import com.android.vts.entity.ProfilingPointSummaryEntity; @@ -87,6 +88,7 @@ public class ObjectifyListener implements ServletContextListener { ObjectifyService.register(BranchEntity.class); ObjectifyService.register(BuildTargetEntity.class); + ObjectifyService.register(HalApiEntity.class); ObjectifyService.register(ApiCoverageEntity.class); ObjectifyService.register(ApiCoverageExcludedEntity.class); ObjectifyService.register(CodeCoverageEntity.class); @@ -106,6 +108,7 @@ public class ObjectifyListener implements ServletContextListener { ObjectifyService.register(TestStatusEntity.class); ObjectifyService.register(TestSuiteFileEntity.class); ObjectifyService.register(TestSuiteResultEntity.class); + ObjectifyService.register(TestAcknowledgmentEntity.class); ObjectifyService.register(RoleEntity.class); ObjectifyService.register(UserEntity.class); ObjectifyService.begin(); @@ -123,6 +126,9 @@ public class ObjectifyListener implements ServletContextListener { servletContextEvent .getServletContext() + .setAttribute("systemConfigProp", systemConfigProp); + servletContextEvent + .getServletContext() .setAttribute("dataStoreFactory", DATA_STORE_FACTORY); servletContextEvent .getServletContext() diff --git a/src/main/java/com/android/vts/entity/HalApiEntity.java b/src/main/java/com/android/vts/entity/HalApiEntity.java index 7fb0e6b..158a4ca 100644 --- a/src/main/java/com/android/vts/entity/HalApiEntity.java +++ b/src/main/java/com/android/vts/entity/HalApiEntity.java @@ -94,6 +94,7 @@ public class HalApiEntity implements DashboardEntity { this.halInterfaceName = halInterfaceName; this.halApi = halApi; this.coveredHalApi = coveredHalApi; + this.updated = new Date(); } /** Saving function for the instance of this class */ diff --git a/src/main/java/com/android/vts/job/BaseJobServlet.java b/src/main/java/com/android/vts/job/BaseJobServlet.java index 3d6232b..18a1d24 100644 --- a/src/main/java/com/android/vts/job/BaseJobServlet.java +++ b/src/main/java/com/android/vts/job/BaseJobServlet.java @@ -16,15 +16,10 @@ package com.android.vts.job; -import com.android.vts.servlet.BaseServlet; -import com.android.vts.util.EmailHelper; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; import java.util.Properties; /** @@ -37,20 +32,20 @@ public abstract class BaseJobServlet extends HttpServlet { */ protected static Properties systemConfigProp = new Properties(); + /** + * This variable is for maximum number of entities per transaction You can find the detail here + * (https://cloud.google.com/datastore/docs/concepts/limits) + */ + protected int MAX_ENTITY_SIZE_PER_TRANSACTION = 300; + @Override public void init(ServletConfig cfg) throws ServletException { super.init(cfg); - try { - InputStream defaultInputStream = - BaseServlet.class.getClassLoader().getResourceAsStream("config.properties"); - systemConfigProp.load(defaultInputStream); - - EmailHelper.setPropertyValues(systemConfigProp); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } + systemConfigProp = + Properties.class.cast(cfg.getServletContext().getAttribute("systemConfigProp")); + + this.MAX_ENTITY_SIZE_PER_TRANSACTION = + Integer.parseInt(systemConfigProp.getProperty("datastore.maxEntitySize")); } } diff --git a/src/main/java/com/android/vts/job/VtsAlertJobServlet.java b/src/main/java/com/android/vts/job/VtsAlertJobServlet.java index 3336c85..be23982 100644 --- a/src/main/java/com/android/vts/job/VtsAlertJobServlet.java +++ b/src/main/java/com/android/vts/job/VtsAlertJobServlet.java @@ -179,29 +179,30 @@ public class VtsAlertJobServlet extends BaseJobServlet { List<TestAcknowledgmentEntity> acks) { Set<String> acknowledged = new HashSet<>(); for (TestAcknowledgmentEntity ack : acks) { - boolean allDevices = ack.devices == null || ack.devices.size() == 0; - boolean allBranches = ack.branches == null || ack.branches.size() == 0; + boolean allDevices = ack.getDevices() == null || ack.getDevices().size() == 0; + boolean allBranches = ack.getBranches() == null || ack.getBranches().size() == 0; boolean isRelevant = allDevices && allBranches; // Determine if the acknowledgment is relevant to the devices. if (!isRelevant) { for (DeviceInfoEntity device : devices) { boolean deviceAcknowledged = - allDevices || ack.devices.contains(device.getBuildFlavor()); + allDevices || ack.getDevices().contains(device.getBuildFlavor()); boolean branchAcknowledged = - allBranches || ack.branches.contains(device.getBranch()); + allBranches || ack.getBranches().contains(device.getBranch()); if (deviceAcknowledged && branchAcknowledged) isRelevant = true; } } if (isRelevant) { // Separate the test cases - boolean allTestCases = ack.testCaseNames == null || ack.testCaseNames.size() == 0; + boolean allTestCases = + ack.getTestCaseNames() == null || ack.getTestCaseNames().size() == 0; if (allTestCases) { acknowledged.addAll(testCases); testCases.removeAll(acknowledged); } else { - for (String testCase : ack.testCaseNames) { + for (String testCase : ack.getTestCaseNames()) { if (testCases.contains(testCase)) { acknowledged.add(testCase); testCases.remove(testCase); diff --git a/src/main/java/com/android/vts/job/VtsSpreadSheetSyncServlet.java b/src/main/java/com/android/vts/job/VtsSpreadSheetSyncServlet.java index 0f1bfbc..45726d9 100644 --- a/src/main/java/com/android/vts/job/VtsSpreadSheetSyncServlet.java +++ b/src/main/java/com/android/vts/job/VtsSpreadSheetSyncServlet.java @@ -17,6 +17,7 @@ package com.android.vts.job; import com.android.vts.entity.ApiCoverageExcludedEntity; +import com.android.vts.entity.DashboardEntity; import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.extensions.appengine.datastore.AppEngineDataStoreFactory; import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp; @@ -162,7 +163,7 @@ public class VtsSpreadSheetSyncServlet extends BaseJobServlet { } } - ApiCoverageExcludedEntity.saveAll(apiCoverageExcludedEntities); + DashboardEntity.saveAll(apiCoverageExcludedEntities, MAX_ENTITY_SIZE_PER_TRANSACTION); } catch (GeneralSecurityException gse) { logger.log(Level.SEVERE, gse.getMessage()); diff --git a/src/main/java/com/android/vts/servlet/BaseServlet.java b/src/main/java/com/android/vts/servlet/BaseServlet.java index 96ba561..5319ee1 100644 --- a/src/main/java/com/android/vts/servlet/BaseServlet.java +++ b/src/main/java/com/android/vts/servlet/BaseServlet.java @@ -26,9 +26,7 @@ import com.google.appengine.api.users.UserService; import com.google.appengine.api.users.UserServiceFactory; import com.google.gson.Gson; -import java.io.FileNotFoundException; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -45,200 +43,191 @@ import javax.servlet.http.HttpSession; public abstract class BaseServlet extends HttpServlet { - protected final Logger logger = Logger.getLogger(getClass().getName()); - - protected String ERROR_MESSAGE_JSP = "WEB-INF/jsp/error_msg.jsp"; - - // Environment variables - protected static String GERRIT_URI; - protected static String GERRIT_SCOPE; - protected static String CLIENT_ID; - protected static String ANALYTICS_ID; - - protected static final String TREE_DEFAULT_PARAM = "treeDefault"; - - public enum PageType { - TOT("Test", "/"), - RELEASE("Release", "/show_release"), - COVERAGE_OVERVIEW("Coverage", "/show_coverage_overview"), - PROFILING_LIST("Profiling", "/show_profiling_list"), - TABLE("", "/show_table"), - TREE("", "/show_tree"), - GRAPH("Profiling", "/show_graph"), - COVERAGE("Coverage", "/show_coverage"), - PERFORMANCE_DIGEST("Performance Digest", "/show_performance_digest"), - PLAN_RELEASE("", "/show_plan_release"), - PLAN_RUN("Plan Run", "/show_plan_run"), - PROFILING_OVERVIEW("", "/show_profiling_overview"); - - public final String defaultName; - public final String defaultUrl; - - PageType(String defaultName, String defaultUrl) { - this.defaultName = defaultName; - this.defaultUrl = defaultUrl; + protected final Logger logger = Logger.getLogger(getClass().getName()); + + protected String ERROR_MESSAGE_JSP = "WEB-INF/jsp/error_msg.jsp"; + + // Environment variables + protected static String GERRIT_URI; + protected static String GERRIT_SCOPE; + protected static String CLIENT_ID; + protected static String ANALYTICS_ID; + + protected static final String TREE_DEFAULT_PARAM = "treeDefault"; + + public enum PageType { + TOT("Test", "/"), + RELEASE("Release", "/show_release"), + COVERAGE_OVERVIEW("Coverage", "/show_coverage_overview"), + PROFILING_LIST("Profiling", "/show_profiling_list"), + TABLE("", "/show_table"), + TREE("", "/show_tree"), + GRAPH("Profiling", "/show_graph"), + COVERAGE("Coverage", "/show_coverage"), + PERFORMANCE_DIGEST("Performance Digest", "/show_performance_digest"), + PLAN_RELEASE("", "/show_plan_release"), + PLAN_RUN("Plan Run", "/show_plan_run"), + PROFILING_OVERVIEW("", "/show_profiling_overview"); + + public final String defaultName; + public final String defaultUrl; + + PageType(String defaultName, String defaultUrl) { + this.defaultName = defaultName; + this.defaultUrl = defaultUrl; + } } - } - public static class Page { + public static class Page { - private final PageType type; - private final String name; - private final String url; + private final PageType type; + private final String name; + private final String url; - public Page(PageType type) { - this.type = type; - this.name = type.defaultName; - this.url = type.defaultUrl; - } + public Page(PageType type) { + this.type = type; + this.name = type.defaultName; + this.url = type.defaultUrl; + } - public Page(PageType type, String name, String url) { - this.type = type; - this.name = type.defaultName + name; - this.url = type.defaultUrl + url; - } + public Page(PageType type, String name, String url) { + this.type = type; + this.name = type.defaultName + name; + this.url = type.defaultUrl + url; + } - public Page(PageType type, String name, String url, Boolean withoutDefault) { - this.type = type; - this.name = name; - this.url = type.defaultUrl + url; - } + public Page(PageType type, String name, String url, Boolean withoutDefault) { + this.type = type; + this.name = name; + this.url = type.defaultUrl + url; + } - public Page(PageType type, String url) { - this.type = type; - this.name = type.defaultName; - this.url = type.defaultUrl + url; - } + public Page(PageType type, String url) { + this.type = type; + this.name = type.defaultName; + this.url = type.defaultUrl + url; + } + + public String getName() { + return name; + } - public String getName() { - return name; + public String getUrl() { + return url; + } } - public String getUrl() { - return url; + public static final List<Page> navbarLinks; + + static { + List<Page> links = new ArrayList<>(); + links.add(new Page(PageType.TOT)); + links.add(new Page(PageType.RELEASE)); + links.add(new Page(PageType.COVERAGE_OVERVIEW)); + links.add(new Page(PageType.PROFILING_LIST)); + navbarLinks = links; } - } - - public static final List<Page> navbarLinks; - - static { - List<Page> links = new ArrayList<>(); - links.add(new Page(PageType.TOT)); - links.add(new Page(PageType.RELEASE)); - links.add(new Page(PageType.COVERAGE_OVERVIEW)); - links.add(new Page(PageType.PROFILING_LIST)); - navbarLinks = links; - } - - public abstract PageType getNavParentType(); - - /** - * Get a list of URL/Display name pairs for the breadcrumb hierarchy. - * - * @param request The HttpServletRequest object for the page request. - * @return a list of Page entries. - */ - public abstract List<Page> getBreadcrumbLinks(HttpServletRequest request); - - /** - * System Configuration Property class - */ - protected static Properties systemConfigProp = new Properties(); - - @Override - public void init(ServletConfig cfg) throws ServletException { - super.init(cfg); - - try { - InputStream defaultInputStream = - BaseServlet.class.getClassLoader().getResourceAsStream("config.properties"); - systemConfigProp.load(defaultInputStream); - - GERRIT_URI = systemConfigProp.getProperty("gerrit.uri"); - GERRIT_SCOPE = systemConfigProp.getProperty("gerrit.scope"); - CLIENT_ID = systemConfigProp.getProperty("appengine.clientID"); - ANALYTICS_ID = systemConfigProp.getProperty("analytics.id"); - - CoverageEntity.setPropertyValues(systemConfigProp); - TestSuiteResultEntity.setPropertyValues(systemConfigProp); - EmailHelper.setPropertyValues(systemConfigProp); - GcsHelper.setGcsProjectId(systemConfigProp.getProperty("gcs.projectID")); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); + + public abstract PageType getNavParentType(); + + /** + * Get a list of URL/Display name pairs for the breadcrumb hierarchy. + * + * @param request The HttpServletRequest object for the page request. + * @return a list of Page entries. + */ + public abstract List<Page> getBreadcrumbLinks(HttpServletRequest request); + + /** System Configuration Property class */ + protected static Properties systemConfigProp = new Properties(); + + @Override + public void init(ServletConfig cfg) throws ServletException { + super.init(cfg); + + systemConfigProp = + Properties.class.cast(cfg.getServletContext().getAttribute("systemConfigProp")); + + GERRIT_URI = systemConfigProp.getProperty("gerrit.uri"); + GERRIT_SCOPE = systemConfigProp.getProperty("gerrit.scope"); + CLIENT_ID = systemConfigProp.getProperty("appengine.clientID"); + ANALYTICS_ID = systemConfigProp.getProperty("analytics.id"); + + CoverageEntity.setPropertyValues(systemConfigProp); + TestSuiteResultEntity.setPropertyValues(systemConfigProp); + EmailHelper.setPropertyValues(systemConfigProp); + GcsHelper.setGcsProjectId(systemConfigProp.getProperty("gcs.projectID")); } - } - - @Override - public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - // If the user is logged out, allow them to log back in and return to the page. - // Set the logout URL to direct back to a login page that directs to the current request. - UserService userService = UserServiceFactory.getUserService(); - Optional<User> currentUser = Optional.ofNullable(userService.getCurrentUser()); - String currentUserEmail = - currentUser.isPresent() - ? currentUser.map(user -> user.getEmail().trim()).orElse("") - : ""; - String requestUri = request.getRequestURI(); - String requestArgs = request.getQueryString(); - String loginURI = userService.createLoginURL(requestUri + '?' + requestArgs); - String logoutURI = userService.createLogoutURL(loginURI); - if (currentUserEmail != "") { - - int activeIndex; - switch (getNavParentType()) { - case PROFILING_LIST: - activeIndex = 3; - break; - case COVERAGE_OVERVIEW: - activeIndex = 2; - break; - case RELEASE: - activeIndex = 1; - break; - default: - activeIndex = 0; - break; - } - if (request.getParameter(TREE_DEFAULT_PARAM) != null) { - HttpSession session = request.getSession(true); - boolean treeDefault = request.getParameter(TREE_DEFAULT_PARAM).equals("true"); - session.setAttribute(TREE_DEFAULT_PARAM, treeDefault); - } - - request.setAttribute("serverName", request.getServerName()); - request.setAttribute("logoutURL", logoutURI); - request.setAttribute("email", currentUserEmail); - request.setAttribute("analyticsID", new Gson().toJson(ANALYTICS_ID)); - request.setAttribute("breadcrumbLinks", getBreadcrumbLinks(request)); - request.setAttribute("navbarLinks", navbarLinks); - request.setAttribute("activeIndex", activeIndex); - response.setContentType("text/html"); - - if (currentUserEmail.endsWith("@google.com") || UserEntity.getUserList() - .contains(currentUserEmail)) { - doGetHandler(request, response); - } else { - RequestDispatcher dispatcher = - request.getRequestDispatcher("WEB-INF/jsp/auth_error.jsp"); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : ", e); + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + // If the user is logged out, allow them to log back in and return to the page. + // Set the logout URL to direct back to a login page that directs to the current request. + UserService userService = UserServiceFactory.getUserService(); + Optional<User> currentUser = Optional.ofNullable(userService.getCurrentUser()); + String currentUserEmail = + currentUser.isPresent() + ? currentUser.map(user -> user.getEmail().trim()).orElse("") + : ""; + String requestUri = request.getRequestURI(); + String requestArgs = request.getQueryString(); + String loginURI = userService.createLoginURL(requestUri + '?' + requestArgs); + String logoutURI = userService.createLogoutURL(loginURI); + if (currentUserEmail != "") { + + int activeIndex; + switch (getNavParentType()) { + case PROFILING_LIST: + activeIndex = 3; + break; + case COVERAGE_OVERVIEW: + activeIndex = 2; + break; + case RELEASE: + activeIndex = 1; + break; + default: + activeIndex = 0; + break; + } + if (request.getParameter(TREE_DEFAULT_PARAM) != null) { + HttpSession session = request.getSession(true); + boolean treeDefault = request.getParameter(TREE_DEFAULT_PARAM).equals("true"); + session.setAttribute(TREE_DEFAULT_PARAM, treeDefault); + } + + request.setAttribute("serverName", request.getServerName()); + request.setAttribute("logoutURL", logoutURI); + request.setAttribute("email", currentUserEmail); + request.setAttribute("analyticsID", new Gson().toJson(ANALYTICS_ID)); + request.setAttribute("breadcrumbLinks", getBreadcrumbLinks(request)); + request.setAttribute("navbarLinks", navbarLinks); + request.setAttribute("activeIndex", activeIndex); + response.setContentType("text/html"); + + if (currentUserEmail.endsWith("@google.com") + || UserEntity.getUserList().contains(currentUserEmail)) { + doGetHandler(request, response); + } else { + RequestDispatcher dispatcher = + request.getRequestDispatcher("WEB-INF/jsp/auth_error.jsp"); + try { + dispatcher.forward(request, response); + } catch (ServletException e) { + logger.log(Level.SEVERE, "Servlet Exception caught : ", e); + } + } + } else { + response.sendRedirect(loginURI); } - } - } else { - response.sendRedirect(loginURI); } - } - - /** - * Implementation of the doGet method to be executed by servlet subclasses. - * - * @param request The HttpServletRequest object. - * @param response The HttpServletResponse object. - */ - public abstract void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException; + + /** + * Implementation of the doGet method to be executed by servlet subclasses. + * + * @param request The HttpServletRequest object. + * @param response The HttpServletResponse object. + */ + public abstract void doGetHandler(HttpServletRequest request, HttpServletResponse response) + throws IOException; } diff --git a/src/main/java/com/android/vts/util/DatastoreHelper.java b/src/main/java/com/android/vts/util/DatastoreHelper.java index 2dbca37..3764c7a 100644 --- a/src/main/java/com/android/vts/util/DatastoreHelper.java +++ b/src/main/java/com/android/vts/util/DatastoreHelper.java @@ -112,8 +112,8 @@ public class DatastoreHelper { DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Key startKey = KeyFactory.createKey(parentKey, kind, lowerBound); Filter startFilter = - new FilterPredicate( - Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN, startKey); + new FilterPredicate( + Entity.KEY_RESERVED_PROPERTY, FilterOperator.GREATER_THAN, startKey); Query q = new Query(kind).setAncestor(parentKey).setFilter(startFilter).setKeysOnly(); return datastore.prepare(q).countEntities(FetchOptions.Builder.withLimit(1)) > 0; } @@ -132,7 +132,7 @@ public class DatastoreHelper { } Key endKey = KeyFactory.createKey(parentKey, kind, upperBound); Filter endFilter = - new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.LESS_THAN, endKey); + new FilterPredicate(Entity.KEY_RESERVED_PROPERTY, FilterOperator.LESS_THAN, endKey); Query q = new Query(kind).setAncestor(parentKey).setFilter(endFilter).setKeysOnly(); return datastore.prepare(q).countEntities(FetchOptions.Builder.withLimit(1)) > 0; } @@ -179,10 +179,10 @@ public class DatastoreHelper { List<Entity> profilingPointRunEntityList = new ArrayList<>(); if (!report.hasStartTimestamp() - || !report.hasEndTimestamp() - || !report.hasTest() - || !report.hasHostInfo() - || !report.hasBuildInfo()) { + || !report.hasEndTimestamp() + || !report.hasTest() + || !report.hasHostInfo() + || !report.hasBuildInfo()) { // missing information return; } @@ -195,8 +195,8 @@ public class DatastoreHelper { TestEntity testEntity = new TestEntity(testName); Key testRunKey = - KeyFactory.createKey( - testEntity.getOldKey(), TestRunEntity.KIND, report.getStartTimestamp()); + KeyFactory.createKey( + testEntity.getOldKey(), TestRunEntity.KIND, report.getStartTimestamp()); long passCount = 0; long failCount = 0; @@ -220,7 +220,7 @@ public class DatastoreHelper { ++failCount; } if (testCase.getSystraceCount() > 0 - && testCase.getSystraceList().get(0).getUrlCount() > 0) { + && testCase.getSystraceList().get(0).getUrlCount() > 0) { String systraceLink = testCase.getSystraceList().get(0).getUrl(0).toStringUtf8(); links.add(systraceLink); } @@ -228,7 +228,7 @@ public class DatastoreHelper { // Process coverage data for test case for (CoverageReportMessage coverage : testCase.getCoverageList()) { CoverageEntity coverageEntity = - CoverageEntity.fromCoverageReport(testRunKey, testCaseName, coverage); + CoverageEntity.fromCoverageReport(testRunKey, testCaseName, coverage); if (coverageEntity == null) { logger.log(Level.WARNING, "Invalid coverage report in test run " + testRunKey); } else { @@ -241,7 +241,7 @@ public class DatastoreHelper { // Process profiling data for test case for (ProfilingReportMessage profiling : testCase.getProfilingList()) { ProfilingPointRunEntity profilingPointRunEntity = - ProfilingPointRunEntity.fromProfilingReport(testRunKey, profiling); + ProfilingPointRunEntity.fromProfilingReport(testRunKey, profiling); if (profilingPointRunEntity == null) { logger.log(Level.WARNING, "Invalid profiling report in test run " + testRunKey); } else { @@ -275,7 +275,7 @@ public class DatastoreHelper { long testRunType = 0; for (AndroidDeviceInfoMessage device : report.getDeviceInfoList()) { DeviceInfoEntity deviceInfoEntity = - DeviceInfoEntity.fromDeviceInfoMessage(testRunKey, device); + DeviceInfoEntity.fromDeviceInfoMessage(testRunKey, device); if (deviceInfoEntity == null) { logger.log(Level.WARNING, "Invalid device info in test run " + testRunKey); } else { @@ -308,7 +308,7 @@ public class DatastoreHelper { // Process global coverage data for (CoverageReportMessage coverage : report.getCoverageList()) { CoverageEntity coverageEntity = - CoverageEntity.fromCoverageReport(testRunKey, new String(), coverage); + CoverageEntity.fromCoverageReport(testRunKey, new String(), coverage); if (coverageEntity == null) { logger.log(Level.WARNING, "Invalid coverage report in test run " + testRunKey); } else { @@ -322,19 +322,19 @@ public class DatastoreHelper { for (ApiCoverageReportMessage apiCoverage : report.getApiCoverageList()) { HalInterfaceMessage halInterfaceMessage = apiCoverage.getHalInterface(); List<String> halApiList = apiCoverage.getHalApiList().stream().map(h -> h.toStringUtf8()) - .collect( - Collectors.toList()); + .collect( + Collectors.toList()); List<String> coveredHalApiList = apiCoverage.getCoveredHalApiList().stream() - .map(h -> h.toStringUtf8()).collect( - Collectors.toList()); + .map(h -> h.toStringUtf8()).collect( + Collectors.toList()); ApiCoverageEntity apiCoverageEntity = new ApiCoverageEntity( - testRunKey, - halInterfaceMessage.getHalPackageName().toStringUtf8(), - halInterfaceMessage.getHalVersionMajor(), - halInterfaceMessage.getHalVersionMinor(), - halInterfaceMessage.getHalInterfaceName().toStringUtf8(), - halApiList, - coveredHalApiList + testRunKey, + halInterfaceMessage.getHalPackageName().toStringUtf8(), + halInterfaceMessage.getHalVersionMajor(), + halInterfaceMessage.getHalVersionMinor(), + halInterfaceMessage.getHalInterfaceName().toStringUtf8(), + halApiList, + coveredHalApiList ); com.googlecode.objectify.Key apiCoverageEntityKey = apiCoverageEntity.save(); if (apiCoverageEntityKey == null) { @@ -345,7 +345,7 @@ public class DatastoreHelper { // Process global profiling data for (ProfilingReportMessage profiling : report.getProfilingList()) { ProfilingPointRunEntity profilingPointRunEntity = - ProfilingPointRunEntity.fromProfilingReport(testRunKey, profiling); + ProfilingPointRunEntity.fromProfilingReport(testRunKey, profiling); if (profilingPointRunEntity == null) { logger.log(Level.WARNING, "Invalid profiling report in test run " + testRunKey); } else { @@ -370,18 +370,18 @@ public class DatastoreHelper { boolean hasCodeCoverage = totalLineCount > 0 && coveredLineCount >= 0; TestRunEntity testRunEntity = - new TestRunEntity( - testEntity.getOldKey(), - testRunType, - startTimestamp, - endTimestamp, - testBuildId, - hostName, - passCount, - failCount, - hasCodeCoverage, - testCaseIds, - links); + new TestRunEntity( + testEntity.getOldKey(), + testRunType, + startTimestamp, + endTimestamp, + testBuildId, + hostName, + passCount, + failCount, + hasCodeCoverage, + testCaseIds, + links); testEntityList.add(testRunEntity.toEntity()); CodeCoverageEntity codeCoverageEntity = new CodeCoverageEntity( @@ -394,11 +394,11 @@ public class DatastoreHelper { if (datastoreTransactionalRetry(test, testEntityList)) { List<List<Entity>> auxiliaryEntityList = - Arrays.asList( - profilingPointRunEntityList, - coverageEntityList, - branchEntityList, - buildTargetEntityList); + Arrays.asList( + profilingPointRunEntityList, + coverageEntityList, + branchEntityList, + buildTargetEntityList); int indexCount = 0; for (List<Entity> entityList : auxiliaryEntityList) { switch (indexCount) { @@ -406,12 +406,12 @@ public class DatastoreHelper { case 1: if (entityList.size() > MAX_ENTITY_SIZE_PER_TRANSACTION) { List<List<Entity>> partitionedList = - Lists.partition(entityList, MAX_ENTITY_SIZE_PER_TRANSACTION); + Lists.partition(entityList, MAX_ENTITY_SIZE_PER_TRANSACTION); partitionedList.forEach( - subEntityList -> { - datastoreTransactionalRetry( - new Entity(NULL_ENTITY_KIND), subEntityList); - }); + subEntityList -> { + datastoreTransactionalRetry( + new Entity(NULL_ENTITY_KIND), subEntityList); + }); } else { datastoreTransactionalRetry(new Entity(NULL_ENTITY_KIND), entityList); } @@ -419,7 +419,7 @@ public class DatastoreHelper { case 2: case 3: datastoreTransactionalRetryWithXG( - new Entity(NULL_ENTITY_KIND), entityList, true); + new Entity(NULL_ENTITY_KIND), entityList, true); break; default: break; @@ -429,7 +429,7 @@ public class DatastoreHelper { if (testRunEntity.getType() == TestRunType.POSTSUBMIT.getNumber()) { VtsAlertJobServlet.addTask(testRunKey); - if (testRunEntity.getHasCodeCoverage()) { + if (testRunEntity.getHasCodeCoverage()) { VtsCoverageAlertJobServlet.addTask(testRunKey); } if (profilingPointKeys.size() > 0) { @@ -437,9 +437,9 @@ public class DatastoreHelper { } } else { logger.log( - Level.WARNING, - "The alert email was not sent as testRunEntity type is not POSTSUBMIT!" + - " \n " + " testRunEntity type => " + testRunEntity.getType()); + Level.WARNING, + "The alert email was not sent as testRunEntity type is not POSTSUBMIT!" + + " \n " + " testRunEntity type => " + testRunEntity.getType()); } } } @@ -506,18 +506,18 @@ public class DatastoreHelper { return; } TestPlanRunEntity testPlanRun = - new TestPlanRunEntity( - testPlanEntity.getKey(), - testPlanName, - type, - startTimestamp, - endTimestamp, - testBuildId, - passCount, - failCount, - 0L, - 0L, - testRunKeys); + new TestPlanRunEntity( + testPlanEntity.getKey(), + testPlanName, + type, + startTimestamp, + endTimestamp, + testBuildId, + passCount, + failCount, + 0L, + 0L, + testRunKeys); // Create the device infos. for (DeviceInfoEntity device : deviceInfoEntitySet) { @@ -549,7 +549,7 @@ public class DatastoreHelper { * @param entityList The list of entity for using datastore put method. */ private static boolean datastoreTransactionalRetryWithXG( - Entity entity, List<Entity> entityList, boolean withXG) { + Entity entity, List<Entity> entityList, boolean withXG) { int retries = 0; while (true) { Transaction txn; @@ -568,7 +568,7 @@ public class DatastoreHelper { Entity datastoreEntity = datastore.get(entity.getKey()); TestEntity datastoreTestEntity = TestEntity.fromEntity(datastoreEntity); if (datastoreTestEntity == null - || !datastoreTestEntity.equals(entity)) { + || !datastoreTestEntity.equals(entity)) { entityList.add(entity); } } else if (entity.getKind().equalsIgnoreCase("TestPlan")) { @@ -584,25 +584,25 @@ public class DatastoreHelper { txn.commit(); break; } catch (ConcurrentModificationException - | DatastoreFailureException - | DatastoreTimeoutException e) { + | DatastoreFailureException + | DatastoreTimeoutException e) { entityList.remove(entity); logger.log( - Level.WARNING, - "Retrying insert kind: " + entity.getKind() + " key: " + entity.getKey()); + Level.WARNING, + "Retrying insert kind: " + entity.getKind() + " key: " + entity.getKey()); if (retries++ >= MAX_WRITE_RETRIES) { logger.log( - Level.SEVERE, - "Exceeded maximum retries kind: " - + entity.getKind() - + " key: " - + entity.getKey()); + Level.SEVERE, + "Exceeded maximum retries kind: " + + entity.getKind() + + " key: " + + entity.getKey()); return false; } } finally { if (txn.isActive()) { logger.log( - Level.WARNING, "Transaction rollback forced for : " + entity.getKind()); + Level.WARNING, "Transaction rollback forced for : " + entity.getKind()); txn.rollback(); } } |