diff options
Diffstat (limited to 'src/main/java/com/android/vts/servlet')
16 files changed, 0 insertions, 4008 deletions
diff --git a/src/main/java/com/android/vts/servlet/BaseServlet.java b/src/main/java/com/android/vts/servlet/BaseServlet.java deleted file mode 100644 index 5319ee1..0000000 --- a/src/main/java/com/android/vts/servlet/BaseServlet.java +++ /dev/null @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.CoverageEntity; -import com.android.vts.entity.TestSuiteResultEntity; -import com.android.vts.entity.UserEntity; -import com.android.vts.util.EmailHelper; -import com.android.vts.util.GcsHelper; -import com.google.appengine.api.users.User; -import com.google.appengine.api.users.UserService; -import com.google.appengine.api.users.UserServiceFactory; -import com.google.gson.Gson; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.ServletConfig; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -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; - } - } - - public static class Page { - - 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, 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 url) { - this.type = type; - this.name = type.defaultName; - this.url = type.defaultUrl + url; - } - - public String getName() { - return name; - } - - 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 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); - } - } - } 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; -} diff --git a/src/main/java/com/android/vts/servlet/DashboardMainServlet.java b/src/main/java/com/android/vts/servlet/DashboardMainServlet.java deleted file mode 100644 index 73a7287..0000000 --- a/src/main/java/com/android/vts/servlet/DashboardMainServlet.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.TestEntity; -import com.android.vts.entity.TestStatusEntity; -import com.android.vts.entity.UserFavoriteEntity; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.PropertyProjection; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.datastore.Query.Filter; -import com.google.appengine.api.datastore.Query.FilterOperator; -import com.google.appengine.api.datastore.Query.FilterPredicate; -import com.google.appengine.api.users.User; -import com.google.appengine.api.users.UserService; -import com.google.appengine.api.users.UserServiceFactory; -import com.google.gson.Gson; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import java.util.stream.Collectors; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import static com.googlecode.objectify.ObjectifyService.ofy; - -/** Represents the servlet that is invoked on loading the first page of dashboard. */ -public class DashboardMainServlet extends BaseServlet { - private static final String DASHBOARD_MAIN_JSP = "WEB-INF/jsp/dashboard_main.jsp"; - private static final String NO_TESTS_ERROR = "No test results available."; - - @Override - public PageType getNavParentType() { - return PageType.TOT; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - return null; - } - - /** Helper class for displaying test entries on the main dashboard. */ - public class TestDisplay implements Comparable<TestDisplay> { - private final Key testKey; - private final int passCount; - private final int failCount; - private boolean muteNotifications; - private boolean isFavorite; - - /** - * Test display constructor. - * - * @param testKey The key of the test. - * @param passCount The number of tests passing. - * @param failCount The number of tests failing. - * @param muteNotifications The flag for user notification in case of test failure. - * @param isFavorite The flag for showing favorite mark on All Tests Tab page. - */ - public TestDisplay( - Key testKey, - int passCount, - int failCount, - boolean muteNotifications, - boolean isFavorite) { - this.testKey = testKey; - this.passCount = passCount; - this.failCount = failCount; - this.muteNotifications = muteNotifications; - this.isFavorite = isFavorite; - } - - /** - * Get the key of the test. - * - * @return The key of the test. - */ - public String getName() { - return this.testKey.getName(); - } - - /** - * Get the number of passing test cases. - * - * @return The number of passing test cases. - */ - public int getPassCount() { - return this.passCount; - } - - /** - * Get the number of failing test cases. - * - * @return The number of failing test cases. - */ - public int getFailCount() { - return this.failCount; - } - - /** - * Get the notification mute status. - * - * @return True if the subscriber has muted notifications, false otherwise. - */ - public boolean getMuteNotifications() { - return this.muteNotifications; - } - - /** Set the notification mute status. */ - public void setMuteNotifications(boolean muteNotifications) { - this.muteNotifications = muteNotifications; - } - - /** - * Get the favorate status. - * - * @return True if an user set favorate for the test, false otherwise. - */ - public boolean getIsFavorite() { - return this.isFavorite; - } - - /** Set the favorite status. */ - public void setIsFavorite(boolean isFavorite) { - this.isFavorite = isFavorite; - } - - @Override - public int compareTo(TestDisplay test) { - return this.testKey.getName().compareTo(test.getName()); - } - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - UserService userService = UserServiceFactory.getUserService(); - User currentUser = userService.getCurrentUser(); - RequestDispatcher dispatcher = null; - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - HttpSession session = request.getSession(true); - PageType referTo = PageType.TREE; - if (session.getAttribute("treeDefault") != null) { - boolean treeDefault = (boolean) session.getAttribute("treeDefault"); - if (!treeDefault) { - referTo = PageType.TABLE; - } - } - - List<TestDisplay> displayedTests = new ArrayList<>(); - List<Key> unprocessedTestKeys = new ArrayList<>(); - - Map<Key, TestDisplay> testMap = new HashMap<>(); // map from table key to TestDisplay - Map<String, String> subscriptionMap = new HashMap<>(); - - boolean showAll = request.getParameter("showAll") != null; - String error = null; - - List<String> allTestNames = TestEntity.getAllTestNames(); - - List<Key> favoriteKeyList = new ArrayList<Key>(); - Filter userFilter = - new FilterPredicate(UserFavoriteEntity.USER, FilterOperator.EQUAL, currentUser); - Query filterQuery = new Query(UserFavoriteEntity.KIND).setFilter(userFilter); - Iterable<Entity> favoriteIter = datastore.prepare(filterQuery).asIterable(); - favoriteIter.forEach( - fe -> { - Key testKey = UserFavoriteEntity.fromEntity(fe).testKey; - favoriteKeyList.add(testKey); - subscriptionMap.put(testKey.getName(), KeyFactory.keyToString(fe.getKey())); - }); - - Query query = - new Query(TestStatusEntity.KIND) - .addProjection( - new PropertyProjection(TestStatusEntity.PASS_COUNT, Long.class)) - .addProjection( - new PropertyProjection(TestStatusEntity.FAIL_COUNT, Long.class)); - for (Entity status : datastore.prepare(query).asIterable()) { - TestStatusEntity statusEntity = TestStatusEntity.fromEntity(status); - if (statusEntity == null) continue; - Key testKey = KeyFactory.createKey(TestEntity.KIND, statusEntity.getTestName()); - boolean isFavorite = favoriteKeyList.contains(testKey); - TestDisplay display = new TestDisplay(testKey, -1, -1, false, isFavorite); - if (!unprocessedTestKeys.contains(testKey)) { - display = - new TestDisplay( - testKey, - statusEntity.getPassCount(), - statusEntity.getFailCount(), - false, - isFavorite); - } - testMap.put(testKey, display); - } - - if (testMap.size() == 0) { - error = NO_TESTS_ERROR; - } - - if (showAll) { - for (Key testKey : testMap.keySet()) { - displayedTests.add(testMap.get(testKey)); - } - } else { - if (testMap.size() > 0) { - for (Entity favoriteEntity : favoriteIter) { - UserFavoriteEntity favorite = UserFavoriteEntity.fromEntity(favoriteEntity); - Key testKey = favorite.testKey; - if (!testMap.containsKey(testKey)) { - continue; - } - TestDisplay display = testMap.get(testKey); - display.setMuteNotifications(favorite.muteNotifications); - displayedTests.add(display); - } - } - } - displayedTests.sort(Comparator.naturalOrder()); - - response.setStatus(HttpServletResponse.SC_OK); - request.setAttribute("allTestsJson", new Gson().toJson(allTestNames)); - request.setAttribute("subscriptionMapJson", new Gson().toJson(subscriptionMap)); - request.setAttribute("testNames", displayedTests); - request.setAttribute("showAll", showAll); - request.setAttribute("error", error); - request.setAttribute("resultsUrl", referTo.defaultUrl); - dispatcher = request.getRequestDispatcher(DASHBOARD_MAIN_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Excpetion caught : ", e); - } - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowCoverageOverviewServlet.java b/src/main/java/com/android/vts/servlet/ShowCoverageOverviewServlet.java deleted file mode 100644 index 210c980..0000000 --- a/src/main/java/com/android/vts/servlet/ShowCoverageOverviewServlet.java +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Copyright (c) 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.CodeCoverageEntity; -import com.android.vts.entity.DeviceInfoEntity; -import com.android.vts.entity.TestCoverageStatusEntity; -import com.android.vts.entity.TestEntity; -import com.android.vts.entity.TestRunEntity; - -import com.android.vts.proto.VtsReportMessage; -import com.android.vts.util.FilterUtil; -import com.google.cloud.datastore.Datastore; -import com.google.cloud.datastore.DatastoreOptions; -import com.google.cloud.datastore.PathElement; -import com.google.cloud.datastore.StructuredQuery.CompositeFilter; -import com.google.cloud.datastore.StructuredQuery.Filter; -import com.google.cloud.datastore.StructuredQuery.PropertyFilter; -import com.google.gson.Gson; -import com.google.visualization.datasource.DataSourceHelper; -import com.google.visualization.datasource.DataSourceRequest; -import com.google.visualization.datasource.base.DataSourceException; -import com.google.visualization.datasource.base.ReasonType; -import com.google.visualization.datasource.base.ResponseStatus; -import com.google.visualization.datasource.base.StatusType; -import com.google.visualization.datasource.base.TypeMismatchException; -import com.google.visualization.datasource.datatable.ColumnDescription; -import com.google.visualization.datasource.datatable.DataTable; -import com.google.visualization.datasource.datatable.TableRow; -import com.google.visualization.datasource.datatable.value.DateTimeValue; -import com.google.visualization.datasource.datatable.value.NumberValue; -import com.google.visualization.datasource.datatable.value.ValueType; -import com.googlecode.objectify.Key; -import com.ibm.icu.util.GregorianCalendar; -import com.ibm.icu.util.TimeZone; -import java.io.IOException; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.function.Predicate; -import java.util.logging.Level; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; - -import static com.googlecode.objectify.ObjectifyService.ofy; - -/** Represents the servlet that is invoked on loading the coverage overview page. */ -public class ShowCoverageOverviewServlet extends BaseServlet { - - @Override - public PageType getNavParentType() { - return PageType.COVERAGE_OVERVIEW; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - return null; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - - String pageType = - request.getParameter("pageType") == null - ? "html" - : request.getParameter("pageType"); - - RequestDispatcher dispatcher; - if (pageType.equalsIgnoreCase("html")) { - dispatcher = this.getCoverageDispatcher(request, response); - try { - request.setAttribute("pageType", pageType); - response.setStatus(HttpServletResponse.SC_OK); - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : ", e); - } - } else { - - String testName = request.getParameter("testName"); - - DataTable data = getCoverageDataTable(testName); - DataSourceRequest dsRequest = null; - - try { - // Extract the datasource request parameters. - dsRequest = new DataSourceRequest(request); - - // NOTE: If you want to work in restricted mode, which means that only - // requests from the same domain can access the data source, uncomment the following - // call. - // - // DataSourceHelper.verifyAccessApproved(dsRequest); - - // Apply the query to the data table. - DataTable newData = - DataSourceHelper.applyQuery( - dsRequest.getQuery(), data, dsRequest.getUserLocale()); - - // Set the response. - DataSourceHelper.setServletResponse(newData, dsRequest, response); - } catch (RuntimeException rte) { - logger.log(Level.SEVERE, "A runtime exception has occured", rte); - ResponseStatus status = - new ResponseStatus( - StatusType.ERROR, ReasonType.INTERNAL_ERROR, rte.getMessage()); - if (dsRequest == null) { - dsRequest = DataSourceRequest.getDefaultDataSourceRequest(request); - } - DataSourceHelper.setServletErrorResponse(status, dsRequest, response); - } catch (DataSourceException e) { - if (dsRequest != null) { - DataSourceHelper.setServletErrorResponse(e, dsRequest, response); - } else { - DataSourceHelper.setServletErrorResponse(e, request, response); - } - } - } - } - - private List<Key<TestRunEntity>> getTestRunEntityKeyList( - List<TestCoverageStatusEntity> testCoverageStatusEntityList) { - return testCoverageStatusEntityList.stream() - .map( - testCoverageStatusEntity -> { - com.googlecode.objectify.Key testKey = - com.googlecode.objectify.Key.create( - TestEntity.class, - testCoverageStatusEntity.getTestName()); - return com.googlecode.objectify.Key.create( - testKey, - TestRunEntity.class, - testCoverageStatusEntity.getUpdatedTimestamp()); - }) - .collect(Collectors.toList()); - } - - private Predicate<DeviceInfoEntity> isBranchAndDevice(String branch, String device) { - return d -> d.getBranch().equals(branch) && d.getBuildFlavor().equals(device); - } - - private Predicate<DeviceInfoEntity> isBranch(String branch) { - return d -> d.getBranch().equals(branch); - } - - private Predicate<DeviceInfoEntity> isDevice(String device) { - return d -> d.getBuildFlavor().equals(device); - } - - private RequestDispatcher getCoverageDispatcher( - HttpServletRequest request, HttpServletResponse response) { - - String COVERAGE_OVERVIEW_JSP = "WEB-INF/jsp/show_coverage_overview.jsp"; - - RequestDispatcher dispatcher = null; - boolean unfiltered = request.getParameter("unfiltered") != null; - boolean showPresubmit = request.getParameter("showPresubmit") != null; - boolean showPostsubmit = request.getParameter("showPostsubmit") != null; - - // If no params are specified, set to default of postsubmit-only. - if (!(showPresubmit || showPostsubmit)) { - showPostsubmit = true; - } - - // If unfiltered, set showPre- and Post-submit to true for accurate UI. - if (unfiltered) { - showPostsubmit = true; - showPresubmit = true; - } - - // Add test names to list - List<String> resultNames = - Arrays.stream(VtsReportMessage.TestCaseResult.values()) - .map(testCaseResult -> testCaseResult.name()) - .collect(Collectors.toList()); - - Map<String, String[]> parameterMap = request.getParameterMap(); - - List<TestCoverageStatusEntity> testCoverageStatusEntityList = - TestCoverageStatusEntity.getAllTestCoverage(); - - List<com.googlecode.objectify.Key<TestRunEntity>> testRunEntityKeyList = new ArrayList<>(); - - if (Objects.nonNull(parameterMap.get("branch")) - || Objects.nonNull(parameterMap.get("device"))) { - List<com.googlecode.objectify.Key<DeviceInfoEntity>> deviceInfoEntityKeyList = - TestCoverageStatusEntity.getDeviceInfoEntityKeyList( - testCoverageStatusEntityList); - - Collection<DeviceInfoEntity> deviceInfoEntityMap = - ofy().load().keys(() -> deviceInfoEntityKeyList.iterator()).values(); - - Stream<DeviceInfoEntity> deviceInfoEntityStream = Stream.empty(); - if (Objects.nonNull(parameterMap.get("branch")) - && Objects.nonNull(parameterMap.get("device"))) { - String branch = parameterMap.get("branch")[0]; - String device = parameterMap.get("device")[0]; - deviceInfoEntityStream = - deviceInfoEntityMap.stream().filter(isBranchAndDevice(branch, device)); - } else if (Objects.nonNull(parameterMap.get("branch"))) { - String branch = parameterMap.get("branch")[0]; - deviceInfoEntityStream = deviceInfoEntityMap.stream().filter(isBranch(branch)); - } else if (Objects.nonNull(parameterMap.get("device"))) { - String device = parameterMap.get("device")[0]; - deviceInfoEntityStream = deviceInfoEntityMap.stream().filter(isDevice(device)); - } else { - logger.log(Level.WARNING, "unmet search condition!"); - } - testRunEntityKeyList = - deviceInfoEntityStream - .map( - deviceInfoEntity -> { - com.googlecode.objectify.Key testKey = - com.googlecode.objectify.Key.create( - TestEntity.class, - deviceInfoEntity - .getParent() - .getParent() - .getName()); - return com.googlecode.objectify.Key.create( - testKey, - TestRunEntity.class, - deviceInfoEntity.getParent().getId()); - }) - .collect(Collectors.toList()); - logger.log(Level.INFO, "testRunEntityKeyList size => " + testRunEntityKeyList.size()); - } else { - testRunEntityKeyList = this.getTestRunEntityKeyList(testCoverageStatusEntityList); - } - Iterator<Key<TestRunEntity>> testRunEntityKeyIterator = testRunEntityKeyList.iterator(); - - Map<Key<TestRunEntity>, TestRunEntity> keyTestRunEntityMap = - ofy().load().keys(() -> testRunEntityKeyIterator); - - List<com.googlecode.objectify.Key<CodeCoverageEntity>> codeCoverageEntityKeyList = - new ArrayList<>(); - Map<Long, TestRunEntity> testRunEntityMap = new HashMap<>(); - for (Map.Entry<com.googlecode.objectify.Key<TestRunEntity>, TestRunEntity> entry : - keyTestRunEntityMap.entrySet()) { - com.googlecode.objectify.Key codeCoverageEntityKey = - com.googlecode.objectify.Key.create( - entry.getKey(), CodeCoverageEntity.class, entry.getValue().getId()); - codeCoverageEntityKeyList.add(codeCoverageEntityKey); - testRunEntityMap.put(entry.getValue().getId(), entry.getValue()); - } - - Map<com.googlecode.objectify.Key<CodeCoverageEntity>, CodeCoverageEntity> - keyCodeCoverageEntityMap = - ofy().load().keys(() -> codeCoverageEntityKeyList.iterator()); - - Map<Long, CodeCoverageEntity> codeCoverageEntityMap = new HashMap<>(); - for (Map.Entry<com.googlecode.objectify.Key<CodeCoverageEntity>, CodeCoverageEntity> entry : - keyCodeCoverageEntityMap.entrySet()) { - codeCoverageEntityMap.put(entry.getValue().getId(), entry.getValue()); - } - - int coveredLines = 0; - int uncoveredLines = 0; - int passCount = 0; - int failCount = 0; - for (Map.Entry<Long, CodeCoverageEntity> entry : codeCoverageEntityMap.entrySet()) { - TestRunEntity testRunEntity = testRunEntityMap.get(entry.getKey()); - - CodeCoverageEntity codeCoverageEntity = entry.getValue(); - - coveredLines += codeCoverageEntity.getCoveredLineCount(); - uncoveredLines += - codeCoverageEntity.getTotalLineCount() - - codeCoverageEntity.getCoveredLineCount(); - passCount += testRunEntity.getPassCount(); - failCount += testRunEntity.getFailCount(); - } - - FilterUtil.setAttributes(request, parameterMap); - - int[] testStats = new int[VtsReportMessage.TestCaseResult.values().length]; - testStats[VtsReportMessage.TestCaseResult.TEST_CASE_RESULT_PASS.getNumber()] = passCount; - testStats[VtsReportMessage.TestCaseResult.TEST_CASE_RESULT_FAIL.getNumber()] = failCount; - - response.setStatus(HttpServletResponse.SC_OK); - request.setAttribute("resultNames", resultNames); - request.setAttribute("resultNamesJson", new Gson().toJson(resultNames)); - request.setAttribute("testRunEntityList", testRunEntityMap.values()); - request.setAttribute("codeCoverageEntityMap", codeCoverageEntityMap); - request.setAttribute("coveredLines", new Gson().toJson(coveredLines)); - request.setAttribute("uncoveredLines", new Gson().toJson(uncoveredLines)); - request.setAttribute("testStats", new Gson().toJson(testStats)); - - request.setAttribute("unfiltered", unfiltered); - request.setAttribute("showPresubmit", showPresubmit); - request.setAttribute("showPostsubmit", showPostsubmit); - - request.setAttribute( - "deviceOptions", - TestCoverageStatusEntity.getDeviceSet(testCoverageStatusEntityList)); - request.setAttribute( - "branchOptions", - TestCoverageStatusEntity.getBranchSet(testCoverageStatusEntityList)); - dispatcher = request.getRequestDispatcher(COVERAGE_OVERVIEW_JSP); - return dispatcher; - } - - private DataTable getCoverageDataTable(String testName) { - - Datastore datastore = DatastoreOptions.getDefaultInstance().getService(); - - DataTable dataTable = new DataTable(); - ArrayList<ColumnDescription> cd = new ArrayList<>(); - ColumnDescription startDate = - new ColumnDescription("startDate", ValueType.DATETIME, "Date"); - startDate.setPattern("yyyy-MM-dd"); - cd.add(startDate); - cd.add( - new ColumnDescription( - "coveredLineCount", ValueType.NUMBER, "Covered Source Code Line Count")); - cd.add( - new ColumnDescription( - "totalLineCount", ValueType.NUMBER, "Total Source Code Line Count")); - cd.add(new ColumnDescription("percentage", ValueType.NUMBER, "Coverage Ratio (%)")); - - dataTable.addColumns(cd); - - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.MONTH, -6); - Long startTime = cal.getTime().getTime() * 1000; - Long endTime = Calendar.getInstance().getTime().getTime() * 1000; - - com.google.cloud.datastore.Key startKey = - datastore - .newKeyFactory() - .setKind(TestRunEntity.KIND) - .addAncestors( - PathElement.of(TestEntity.KIND, testName), - PathElement.of(TestRunEntity.KIND, startTime)) - .newKey(startTime); - - com.google.cloud.datastore.Key endKey = - datastore - .newKeyFactory() - .setKind(TestRunEntity.KIND) - .addAncestors( - PathElement.of(TestEntity.KIND, testName), - PathElement.of(TestRunEntity.KIND, endTime)) - .newKey(endTime); - - Filter codeCoverageFilter = - CompositeFilter.and( - PropertyFilter.lt("__key__", endKey), - PropertyFilter.gt("__key__", startKey)); - - List<CodeCoverageEntity> codeCoverageEntityList = - ofy().load() - .type(CodeCoverageEntity.class) - .filter(codeCoverageFilter) - .limit(10) - .list(); - - DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); - Map<String, List<CodeCoverageEntity>> codeCoverageEntityListMap = - codeCoverageEntityList - .stream() - .collect( - Collectors.groupingBy( - v -> dateTimeFormatter.print(v.getId() / 1000))); - - codeCoverageEntityListMap.forEach( - (key, entityList) -> { - GregorianCalendar gCal = new GregorianCalendar(); - gCal.setTimeZone(TimeZone.getTimeZone("GMT")); - gCal.setTimeInMillis(entityList.get(0).getId() / 1000); - - Long sumCoveredLine = - entityList.stream().mapToLong(val -> val.getCoveredLineCount()).sum(); - Long sumTotalLine = - entityList.stream().mapToLong(val -> val.getTotalLineCount()).sum(); - float percentage = 0; - if (sumTotalLine > 0) { - BigDecimal coveredLineNum = new BigDecimal(sumCoveredLine); - BigDecimal totalLineNum = new BigDecimal(sumTotalLine); - BigDecimal totalPercent = new BigDecimal(100); - percentage = - coveredLineNum - .multiply(totalPercent) - .divide(totalLineNum, 2, RoundingMode.HALF_DOWN) - .floatValue(); - } - - TableRow tableRow = new TableRow(); - tableRow.addCell(new DateTimeValue(gCal)); - tableRow.addCell(new NumberValue(sumCoveredLine)); - tableRow.addCell(new NumberValue(sumTotalLine)); - tableRow.addCell(new NumberValue(percentage)); - try { - dataTable.addRow(tableRow); - } catch (TypeMismatchException e) { - logger.log(Level.WARNING, "Invalid type! "); - } - }); - - return dataTable; - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowCoverageServlet.java b/src/main/java/com/android/vts/servlet/ShowCoverageServlet.java deleted file mode 100644 index 08e5db6..0000000 --- a/src/main/java/com/android/vts/servlet/ShowCoverageServlet.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import static com.googlecode.objectify.ObjectifyService.ofy; - -import com.android.vts.entity.CoverageEntity; -import com.android.vts.entity.RoleEntity; -import com.android.vts.entity.TestEntity; -import com.android.vts.entity.TestRunEntity; -import com.android.vts.entity.UserEntity; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.Query; -import com.google.gson.Gson; -import com.googlecode.objectify.Ref; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.logging.Level; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Servlet for handling requests to show code coverage. - */ -public class ShowCoverageServlet extends BaseServlet { - - private static final String COVERAGE_JSP = "WEB-INF/jsp/show_coverage.jsp"; - private static final String TREE_JSP = "WEB-INF/jsp/show_tree.jsp"; - - @Override - public PageType getNavParentType() { - return PageType.TOT; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - List<Page> links = new ArrayList<>(); - String testName = request.getParameter("testName"); - links.add(new Page(PageType.TABLE, testName, "?testName=" + testName)); - - String startTime = request.getParameter("startTime"); - links.add(new Page(PageType.COVERAGE, "?testName=" + testName + "&startTime=" + startTime)); - return links; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - RequestDispatcher dispatcher = null; - - String test = request.getParameter("testName"); - String timeString = request.getParameter("startTime"); - - Boolean isModerator = false; - String currentUserEmail = request.getAttribute("email").toString(); - Optional<UserEntity> userEntityOptional = Optional - .ofNullable(UserEntity.getUser(currentUserEmail)); - if (userEntityOptional.isPresent()) { - Ref refRole = Ref.create(RoleEntity.getRole("coverage-moderator")); - isModerator = userEntityOptional.get().getRoles().contains(refRole); - } - - // Process the time key requested - long time = -1; - try { - time = Long.parseLong(timeString); - } catch (NumberFormatException e) { - request.setAttribute("testName", test); - dispatcher = request.getRequestDispatcher(TREE_JSP); - return; - } - - com.googlecode.objectify.Key testKey = com.googlecode.objectify.Key - .create(TestEntity.class, test); - com.googlecode.objectify.Key testRunKey = com.googlecode.objectify.Key - .create(testKey, TestRunEntity.class, time); - - List<CoverageEntity> coverageEntityList = ofy().load().type(CoverageEntity.class) - .ancestor(testRunKey).list(); - - Collections.sort(coverageEntityList, CoverageEntity.isIgnoredComparator); - - request.setAttribute("isModerator", isModerator); - request.setAttribute("testName", request.getParameter("testName")); - request.setAttribute("gerritURI", new Gson().toJson(GERRIT_URI)); - request.setAttribute("gerritScope", new Gson().toJson(GERRIT_SCOPE)); - request.setAttribute("clientId", new Gson().toJson(CLIENT_ID)); - request.setAttribute("startTime", request.getParameter("startTime")); - request.setAttribute("coverageEntityList", coverageEntityList); - - dispatcher = request.getRequestDispatcher(COVERAGE_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : ", e); - } - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowGcsLogServlet.java b/src/main/java/com/android/vts/servlet/ShowGcsLogServlet.java deleted file mode 100644 index ad5e871..0000000 --- a/src/main/java/com/android/vts/servlet/ShowGcsLogServlet.java +++ /dev/null @@ -1,320 +0,0 @@ -/* - * Copyright (c) 2018 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.util.GcsHelper; -import com.google.appengine.api.memcache.ErrorHandlers; -import com.google.appengine.api.memcache.MemcacheService; -import com.google.appengine.api.memcache.MemcacheServiceFactory; -import com.google.auth.oauth2.ServiceAccountCredentials; -import com.google.cloud.storage.Blob; -import com.google.cloud.storage.Bucket; -import com.google.cloud.storage.Storage; -import com.google.cloud.storage.Storage.BlobListOption; -import com.google.cloud.storage.StorageOptions; -import com.google.gson.Gson; -import org.apache.commons.io.IOUtils; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.nio.file.Paths; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.logging.Level; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -/** - * A GCS log servlet read log zip file from Google Cloud Storage bucket and show the content in it - * from the zip file by unarchiving it - */ -@SuppressWarnings("serial") -public class ShowGcsLogServlet extends BaseServlet { - - private static final String GCS_LOG_JSP = "WEB-INF/jsp/show_gcs_log.jsp"; - - /** Google Cloud Storage project's key file to access the storage */ - private static String GCS_KEY_FILE; - /** Google Cloud Storage project's default bucket name for vtslab test result files */ - private static String GCS_BUCKET_NAME; - /** Google Cloud Storage project's default bucket name for vtslab infra log files */ - private static String GCS_INFRA_LOG_BUCKET_NAME; - - /** - * This is the key file to access vtslab-gcs project. It will allow the dashboard to have a full - * control of the bucket. - */ - private InputStream keyFileInputStream; - - /** This is the instance of java google storage library */ - private Storage storage; - - /** This is the instance of App Engine memcache service java library */ - private MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService(); - - /** GCS Test Report Bucket instance */ - private Bucket vtsReportBucket; - - /** GCS Infra Log Bucket instance */ - private Bucket vtsInfraLogBucket; - - @Override - public void init(ServletConfig cfg) throws ServletException { - super.init(cfg); - - GCS_KEY_FILE = systemConfigProp.getProperty("gcs.keyFile"); - GCS_BUCKET_NAME = systemConfigProp.getProperty("gcs.bucketName"); - GCS_INFRA_LOG_BUCKET_NAME = systemConfigProp.getProperty("gcs.infraLogBucketName"); - - String keyFilePath = "keys/" + GCS_KEY_FILE; - - byte[] keyFileByteArray = new byte[0]; - try { - keyFileByteArray = - IOUtils.toByteArray( - this.getClass().getClassLoader().getResourceAsStream(keyFilePath)); - } catch (IOException e) { - e.printStackTrace(); - } - this.keyFileInputStream = new ByteArrayInputStream(keyFileByteArray); - InputStream vtsReportInputStream = new ByteArrayInputStream(keyFileByteArray); - InputStream vtsInfraInputStream = new ByteArrayInputStream(keyFileByteArray); - - Optional<Storage> optionalVtsReportStorage = GcsHelper.getStorage(vtsReportInputStream); - if (optionalVtsReportStorage.isPresent()) { - this.storage = optionalVtsReportStorage.get(); - this.vtsReportBucket = storage.get(GCS_BUCKET_NAME); - } else { - logger.log(Level.SEVERE, "Error on getting storage instance!"); - throw new ServletException("Creating storage instance exception!"); - } - - Optional<Storage> optionalVtsInfraStorage = GcsHelper.getStorage(vtsInfraInputStream); - if (optionalVtsInfraStorage.isPresent()) { - this.storage = optionalVtsInfraStorage.get(); - this.vtsInfraLogBucket = storage.get(GCS_INFRA_LOG_BUCKET_NAME); - } else { - logger.log(Level.SEVERE, "Error on getting storage instance!"); - throw new ServletException("Creating storage instance exception!"); - } - syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO)); - } - - @Override - public PageType getNavParentType() { - return PageType.TOT; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - return null; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - if (keyFileInputStream == null) { - request.setAttribute("error_title", "GCS Key file Error"); - request.setAttribute("error_message", "The GCS Key file is not existed!"); - RequestDispatcher dispatcher = request.getRequestDispatcher(ERROR_MESSAGE_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Excpetion caught : ", e); - } - } else { - String pathInfo = request.getPathInfo(); - if (Objects.nonNull(pathInfo)) { - if (pathInfo.equalsIgnoreCase("/download")) { - downloadHandler(request, response); - } else { - logger.log(Level.INFO, "Path Info => " + pathInfo); - logger.log(Level.WARNING, "Unknown path access!"); - } - } else { - defaultHandler(request, response); - } - } - } - - private void downloadHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - String file = request.getParameter("file") == null ? "/" : request.getParameter("file"); - Path filePathInfo = Paths.get(file); - - Blob blobFile = vtsInfraLogBucket.get(filePathInfo.toString()); - - if (blobFile.exists()) { - response.setContentType("application/octet-stream"); - response.setContentLength(blobFile.getSize().intValue()); - response.setHeader( - "Content-Disposition", - "attachment; filename=\"" + filePathInfo.getFileName() + "\""); - - response.getOutputStream().write(blobFile.getContent()); - } else { - request.setAttribute("error_title", "Infra Log File Not Found"); - request.setAttribute("error_message", "Please contact the administrator!"); - RequestDispatcher dispatcher = request.getRequestDispatcher(ERROR_MESSAGE_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Excpetion caught : ", e); - } - } - } - - private void defaultHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - - String action = - request.getParameter("action") == null ? "read" : request.getParameter("action"); - String path = request.getParameter("path") == null ? "/" : request.getParameter("path"); - String entry = request.getParameter("entry") == null ? "" : request.getParameter("entry"); - Path pathInfo = Paths.get(path); - - List<String> dirList = new ArrayList<>(); - List<String> fileList = new ArrayList<>(); - List<String> entryList = new ArrayList<>(); - Map<String, Object> resultMap = new HashMap<>(); - String entryContent = ""; - - if (pathInfo.toString().endsWith(".zip")) { - - Blob blobFile = (Blob) this.syncCache.get(path.toString()); - if (blobFile == null) { - blobFile = vtsReportBucket.get(path); - this.syncCache.put(path.toString(), blobFile); - } - - if (action.equalsIgnoreCase("read")) { - InputStream blobInputStream = new ByteArrayInputStream(blobFile.getContent()); - ZipInputStream zipInputStream = new ZipInputStream(blobInputStream); - - ZipEntry zipEntry; - while ((zipEntry = zipInputStream.getNextEntry()) != null) { - if (zipEntry.isDirectory()) { - - } else { - if (entry.length() > 0) { - logger.log(Level.INFO, "param entry => " + entry); - if (zipEntry.getName().equals(entry)) { - logger.log(Level.INFO, "matched !!!! " + zipEntry.getName()); - entryContent = - IOUtils.toString( - zipInputStream, StandardCharsets.UTF_8.name()); - } - } else { - entryList.add(zipEntry.getName()); - } - } - } - resultMap.put("entryList", entryList); - resultMap.put("entryContent", entryContent); - - String json = new Gson().toJson(resultMap); - response.setContentType("application/json"); - response.setCharacterEncoding("UTF-8"); - response.getWriter().write(json); - } else { - response.setContentType("application/octet-stream"); - response.setContentLength(blobFile.getSize().intValue()); - response.setHeader( - "Content-Disposition", - "attachment; filename=\"" + pathInfo.getFileName() + "\""); - - response.getOutputStream().write(blobFile.getContent()); - } - - } else { - - logger.log(Level.INFO, "path info => " + pathInfo); - logger.log(Level.INFO, "path name count => " + pathInfo.getNameCount()); - - BlobListOption[] listOptions; - if (pathInfo.getNameCount() == 0) { - listOptions = new BlobListOption[] {BlobListOption.currentDirectory()}; - } else { - String prefixPathString = path.endsWith("/") ? path : path.concat("/"); - if (pathInfo.getNameCount() <= 1) { - dirList.add("/"); - } else { - dirList.add(getParentDirPath(prefixPathString)); - } - - listOptions = - new BlobListOption[] { - BlobListOption.currentDirectory(), - BlobListOption.prefix(prefixPathString) - }; - } - - Iterable<Blob> blobIterable = vtsReportBucket.list(listOptions).iterateAll(); - Iterator<Blob> blobIterator = blobIterable.iterator(); - while (blobIterator.hasNext()) { - Blob blob = blobIterator.next(); - logger.log(Level.INFO, "blob name => " + blob); - if (blob.isDirectory()) { - logger.log(Level.INFO, "directory name => " + blob.getName()); - dirList.add(blob.getName()); - } else { - logger.log(Level.INFO, "file name => " + blob.getName()); - fileList.add(Paths.get(blob.getName()).getFileName().toString()); - } - } - - response.setStatus(HttpServletResponse.SC_OK); - request.setAttribute("entryList", entryList); - request.setAttribute("dirList", dirList); - request.setAttribute("fileList", fileList); - request.setAttribute("path", path); - RequestDispatcher dispatcher = request.getRequestDispatcher(GCS_LOG_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Excpetion caught : ", e); - } - } - } - - private String getParentDirPath(String fileOrDirPath) { - boolean endsWithSlashCheck = fileOrDirPath.endsWith(File.separator); - return fileOrDirPath.substring( - 0, - fileOrDirPath.lastIndexOf( - File.separatorChar, - endsWithSlashCheck - ? fileOrDirPath.length() - 2 - : fileOrDirPath.length() - 1)); - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowGraphServlet.java b/src/main/java/com/android/vts/servlet/ShowGraphServlet.java deleted file mode 100644 index 22b7098..0000000 --- a/src/main/java/com/android/vts/servlet/ShowGraphServlet.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.DeviceInfoEntity; -import com.android.vts.entity.ProfilingPointRunEntity; -import com.android.vts.entity.TestEntity; -import com.android.vts.entity.TestRunEntity; -import com.android.vts.util.DatastoreHelper; -import com.android.vts.util.FilterUtil; -import com.android.vts.util.Graph; -import com.android.vts.util.GraphSerializer; -import com.android.vts.util.Histogram; -import com.android.vts.util.LineGraph; -import com.android.vts.util.PerformanceUtil; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.datastore.Query.Filter; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.lang.StringUtils; - -/** Servlet for handling requests to load graphs. */ -public class ShowGraphServlet extends BaseServlet { - private static final String GRAPH_JSP = "WEB-INF/jsp/show_graph.jsp"; - private static final long DEFAULT_FILTER_OPTION = -1; - - private static final String HIDL_HAL_OPTION = "hidl_hal_mode"; - private static final String[] splitKeysArray = new String[] {HIDL_HAL_OPTION}; - private static final Set<String> splitKeySet = new HashSet<>(Arrays.asList(splitKeysArray)); - private static final String PROFILING_DATA_ALERT = "No profiling data was found."; - - @Override - public PageType getNavParentType() { - return PageType.TOT; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - List<Page> links = new ArrayList<>(); - String testName = request.getParameter("testName"); - links.add(new Page(PageType.TABLE, testName, "?testName=" + testName)); - - String profilingPointName = request.getParameter("profilingPoint"); - links.add( - new Page( - PageType.GRAPH, - "?testName=" + testName + "&profilingPoint=" + profilingPointName)); - return links; - } - - /** - * Process a profiling report message and add it to the map of graphs. - * - * @param profilingRun The Entity of a profiling point run to process. - * @param idString The ID derived from the test run to identify the profiling report. - * @param graphMap A map from graph name to Graph object. - */ - private static void processProfilingRun( - Entity profilingRun, String idString, Map<String, Graph> graphMap) { - ProfilingPointRunEntity pt = ProfilingPointRunEntity.fromEntity(profilingRun); - if (pt == null) return; - String name = PerformanceUtil.getOptionAlias(pt, splitKeySet); - Graph g = null; - if (pt.getLabels() != null && pt.getLabels().size() == pt.getValues().size()) { - g = new LineGraph(name); - } else if (pt.getLabels() == null && pt.getValues().size() > 0) { - g = new Histogram(name); - } else { - return; - } - if (!graphMap.containsKey(name)) { - graphMap.put(name, g); - } - graphMap.get(name).addData(idString, pt); - } - - /** - * Get a summary string describing the devices in the test run. - * - * @param devices The list of device descriptors for a particular test run. - * @return A string describing the devices in the test run. - */ - private static String getDeviceSummary(List<DeviceInfoEntity> devices) { - if (devices == null) return null; - List<String> buildInfos = new ArrayList<>(); - for (DeviceInfoEntity device : devices) { - buildInfos.add(device.getProduct() + " (" + device.getBuildId() + ")"); - } - return StringUtils.join(buildInfos, ", "); - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - RequestDispatcher dispatcher = null; - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - String testName = request.getParameter("testName"); - String profilingPointName = request.getParameter("profilingPoint"); - String selectedDevice = request.getParameter("device"); - Long endTime = null; - if (request.getParameter("endTime") != null) { - String time = request.getParameter("endTime"); - try { - endTime = Long.parseLong(time); - } catch (NumberFormatException e) { - } - } - if (endTime == null) { - endTime = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); - } - Long startTime = endTime - TimeUnit.DAYS.toMicros(1); - - // Set of device names - List<String> devices = DatastoreHelper.getAllBuildFlavors(); - if (!devices.contains(selectedDevice)) selectedDevice = null; - - Map<String, Graph> graphMap = new HashMap<>(); - - // Create a query for test runs matching the time window filter - Key parentKey = KeyFactory.createKey(TestEntity.KIND, testName); - Filter timeFilter = - FilterUtil.getTimeFilter(parentKey, TestRunEntity.KIND, startTime, endTime); - Query testRunQuery = - new Query(TestRunEntity.KIND) - .setAncestor(parentKey) - .setFilter(timeFilter) - .setKeysOnly(); - - // Process the test runs in the query - List<Key> gets = new ArrayList<>(); - for (Entity testRun : - datastore - .prepare(testRunQuery) - .asIterable(DatastoreHelper.getLargeBatchOptions())) { - gets.add( - KeyFactory.createKey( - testRun.getKey(), ProfilingPointRunEntity.KIND, profilingPointName)); - } - Map<Key, Entity> profilingPoints = datastore.get(gets); - Map<Key, Entity> testRunProfiling = new HashMap<>(); - for (Key key : profilingPoints.keySet()) { - testRunProfiling.put(key.getParent(), profilingPoints.get(key)); - } - - Filter deviceFilter = - FilterUtil.getDeviceTimeFilter(parentKey, TestRunEntity.KIND, startTime, endTime); - if (selectedDevice != null) { - deviceFilter = - Query.CompositeFilterOperator.and( - deviceFilter, - new Query.FilterPredicate( - DeviceInfoEntity.BUILD_FLAVOR, - Query.FilterOperator.EQUAL, - selectedDevice)); - } - Query deviceQuery = - new Query(DeviceInfoEntity.KIND) - .setAncestor(parentKey) - .setFilter(deviceFilter) - .setKeysOnly(); - gets = new ArrayList<>(); - for (Entity device : - datastore.prepare(deviceQuery).asIterable(DatastoreHelper.getLargeBatchOptions())) { - if (testRunProfiling.containsKey(device.getParent())) { - gets.add(device.getKey()); - } - } - - Map<Key, Entity> deviceInfos = datastore.get(gets); - Map<Key, List<DeviceInfoEntity>> testRunDevices = new HashMap<>(); - for (Key deviceKey : deviceInfos.keySet()) { - if (!testRunDevices.containsKey(deviceKey.getParent())) { - testRunDevices.put(deviceKey.getParent(), new ArrayList<DeviceInfoEntity>()); - } - DeviceInfoEntity device = DeviceInfoEntity.fromEntity(deviceInfos.get(deviceKey)); - if (device == null) continue; - testRunDevices.get(deviceKey.getParent()).add(device); - } - - for (Key runKey : testRunProfiling.keySet()) { - String idString = getDeviceSummary(testRunDevices.get(runKey)); - if (idString != null) { - processProfilingRun(testRunProfiling.get(runKey), idString, graphMap); - } - } - - // Get the names of the graphs to render - String[] names = graphMap.keySet().toArray(new String[graphMap.size()]); - Arrays.sort(names); - - List<Graph> graphList = new ArrayList<>(); - boolean hasHistogram = false; - for (String name : names) { - Graph g = graphMap.get(name); - if (g.size() > 0) { - graphList.add(g); - if (g instanceof Histogram) hasHistogram = true; - } - } - - String filterVal = request.getParameter("filterVal"); - try { - Long.parseLong(filterVal); - } catch (NumberFormatException e) { - filterVal = Long.toString(DEFAULT_FILTER_OPTION); - } - request.setAttribute("testName", request.getParameter("testName")); - request.setAttribute("filterVal", filterVal); - request.setAttribute("endTime", new Gson().toJson(endTime)); - request.setAttribute("devices", devices); - request.setAttribute("selectedDevice", selectedDevice); - request.setAttribute("showFilterDropdown", hasHistogram); - if (graphList.size() == 0) request.setAttribute("error", PROFILING_DATA_ALERT); - - Gson gson = - new GsonBuilder() - .registerTypeHierarchyAdapter(Graph.class, new GraphSerializer()) - .create(); - request.setAttribute("graphs", gson.toJson(graphList)); - - request.setAttribute("profilingPointName", profilingPointName); - dispatcher = request.getRequestDispatcher(GRAPH_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Excpetion caught : ", e); - } - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowGreenReleaseServlet.java b/src/main/java/com/android/vts/servlet/ShowGreenReleaseServlet.java deleted file mode 100644 index 7fad9a2..0000000 --- a/src/main/java/com/android/vts/servlet/ShowGreenReleaseServlet.java +++ /dev/null @@ -1,502 +0,0 @@ -/* - * Copyright (c) 2018 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.DeviceInfoEntity; -import com.android.vts.entity.TestPlanEntity; -import com.android.vts.entity.TestPlanRunEntity; -import com.android.vts.entity.TestSuiteResultEntity; -import com.android.vts.util.FilterUtil; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.PropertyProjection; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.datastore.Query.Filter; -import com.google.appengine.api.datastore.Query.SortDirection; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -import java.util.Arrays; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Comparator; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -import java.util.logging.Level; -import java.util.stream.Collectors; - -import static com.googlecode.objectify.ObjectifyService.ofy; - -public class ShowGreenReleaseServlet extends BaseServlet { - private static final int MAX_RUNS_PER_PAGE = 9999; - - /** Helper class for displaying each device build info on the green build page. */ - public class DeviceBuildInfo implements Comparable<DeviceBuildInfo>, Cloneable { - - /** Device model name ex) marlin, walleye */ - private String deviceBuildTarget; - /** Candidate Build ID */ - private String candidateBuildId; - /** Candidate Build ID Timestamp for url parameter */ - private Long candidateBuildIdTimestamp; - /** Green Build ID */ - private String greenBuildId; - /** Green Build ID Timestamp for url parameter */ - private Long greenBuildIdTimestamp; - - /** - * Device Build Info constructor. - * - * @param deviceBuildTarget The key of the test. - * @param candidateBuildId The number of tests failing. - */ - public DeviceBuildInfo(String deviceBuildTarget, String candidateBuildId) { - this.deviceBuildTarget = deviceBuildTarget; - this.candidateBuildId = candidateBuildId; - this.candidateBuildIdTimestamp = 0L; - this.greenBuildId = "N/A"; - this.greenBuildIdTimestamp = 0L; - } - - /** - * Get the device name. - * - * @return The device name. - */ - public String getDeviceBuildTarget() { - return this.deviceBuildTarget; - } - - /** - * Get the candidate build ID. - * - * @return The candidate build ID. - */ - public String getCandidateBuildId() { - return this.candidateBuildId; - } - - /** Set the candidate build ID. */ - public void setCandidateBuildId(String candidateBuildId) { - this.candidateBuildId = candidateBuildId; - } - - /** - * Get the candidate build ID timestamp. - * - * @return The candidate build ID timestamp. - */ - public Long getCandidateBuildIdTimestamp() { - return this.candidateBuildIdTimestamp; - } - - /** Set the candidate build ID timestamp. */ - public void setCandidateBuildIdTimestamp(Long candidateBuildIdTimestamp) { - this.candidateBuildIdTimestamp = candidateBuildIdTimestamp; - } - - /** - * Get the green build ID. - * - * @return The green build ID. - */ - public String getGreenBuildId() { - return this.greenBuildId; - } - - /** Set the green build ID. */ - public void setGreenBuildId(String greenBuildId) { - this.greenBuildId = greenBuildId; - } - - /** - * Get the candidate build ID timestamp. - * - * @return The candidate build ID timestamp. - */ - public Long getGreenBuildIdTimestamp() { - return this.greenBuildIdTimestamp; - } - - /** Set the candidate build ID timestamp. */ - public void setGreenBuildIdTimestamp(Long greenBuildIdTimestamp) { - this.greenBuildIdTimestamp = greenBuildIdTimestamp; - } - - @Override - public int compareTo(DeviceBuildInfo deviceBuildInfo) { - return this.deviceBuildTarget.compareTo(deviceBuildInfo.getDeviceBuildTarget()); - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); - } - } - - @Override - public PageType getNavParentType() { - return PageType.RELEASE; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - List<Page> links = new ArrayList<>(); - String planName = request.getParameter("plan"); - links.add(new Page(PageType.PLAN_RELEASE, planName, "?plan=" + planName)); - return links; - } - - // This function will build and return basic parameter HashMap based on parameter information - // and - // this value will also be used on green build page to show the basic structure. - private Map<String, List<DeviceBuildInfo>> getBasicParamMap(Map<String, List<String>> param) { - Map<String, List<DeviceBuildInfo>> basicParamMap = new HashMap<>(); - param.forEach( - (branch, buildTargetList) -> { - List<DeviceBuildInfo> deviceBuildTargetList = new ArrayList<>(); - buildTargetList.forEach( - buildTargetName -> { - deviceBuildTargetList.add( - new DeviceBuildInfo(buildTargetName, "N/A")); - }); - basicParamMap.put(branch, deviceBuildTargetList); - }); - return basicParamMap; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - - String testType = - request.getParameter("type") == null ? "plan" : request.getParameter("type"); - - RequestDispatcher dispatcher; - if (testType.equalsIgnoreCase("plan")) { - dispatcher = this.getTestPlanDispatcher(request, response); - } else { - dispatcher = this.getTestSuiteDispatcher(request, response); - } - - try { - request.setAttribute("testType", testType); - response.setStatus(HttpServletResponse.SC_OK); - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : ", e); - } - } - - private RequestDispatcher getTestPlanDispatcher( - HttpServletRequest request, HttpServletResponse response) { - String GREEN_RELEASE_JSP = "WEB-INF/jsp/show_green_plan_release.jsp"; - - String testPlan = request.getParameter("plan"); - - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.DATE, -7); - Long startTime = cal.getTime().getTime() * 1000; - Long endTime = Calendar.getInstance().getTime().getTime() * 1000; - - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - - Query deviceInfoQuery = - new Query(DeviceInfoEntity.KIND) - .setAncestor(KeyFactory.createKey(TestPlanEntity.KIND, testPlan)) - .addProjection( - new PropertyProjection(DeviceInfoEntity.BRANCH, String.class)) - .addProjection( - new PropertyProjection(DeviceInfoEntity.BUILD_FLAVOR, String.class)) - .setDistinct(true); - - Map<String, List<String>> paramInfoMap = new HashMap<>(); - for (Entity entity : datastore.prepare(deviceInfoQuery).asIterable()) { - String branch = entity.getProperty(DeviceInfoEntity.BRANCH).toString(); - String target = entity.getProperty(DeviceInfoEntity.BUILD_FLAVOR).toString(); - if (paramInfoMap.containsKey(branch)) { - paramInfoMap.get(branch).add(target); - } else { - paramInfoMap.put(branch, new LinkedList<>(Arrays.asList(target))); - } - } - - Map<String, List<DeviceBuildInfo>> baseParamMap = getBasicParamMap(paramInfoMap); - baseParamMap.forEach( - (branchKey, deviceBuildInfoList) -> { - List<List<String>> allPassIdLists = new ArrayList<>(); - Map<String, List<TestPlanRunEntity>> allTestPlanRunEntityMap = new HashMap<>(); - deviceBuildInfoList.forEach( - deviceBuildInfo -> { - Map<String, String[]> paramMap = - new HashMap<String, String[]>() { - { - put("branch", new String[] {branchKey}); - put( - "device", - new String[] { - deviceBuildInfo.getDeviceBuildTarget() - }); - } - }; - - SortDirection dir = SortDirection.DESCENDING; - - boolean unfiltered = false; - boolean showPresubmit = false; - boolean showPostsubmit = true; - Filter typeFilter = - FilterUtil.getTestTypeFilter( - showPresubmit, showPostsubmit, unfiltered); - Key testPlanKey = - KeyFactory.createKey(TestPlanEntity.KIND, testPlan); - Filter testPlanRunFilter = - FilterUtil.getTimeFilter( - testPlanKey, - TestPlanRunEntity.KIND, - startTime, - endTime, - typeFilter); - - List<Filter> userTestFilters = - FilterUtil.getUserTestFilters(paramMap); - userTestFilters.add(0, testPlanRunFilter); - Filter userDeviceFilter = FilterUtil.getUserDeviceFilter(paramMap); - - List<Key> matchingKeyList = - FilterUtil.getMatchingKeys( - testPlanKey, - TestPlanRunEntity.KIND, - userTestFilters, - userDeviceFilter, - dir, - MAX_RUNS_PER_PAGE); - - logger.log( - Level.INFO, - "the number of matching key => " + matchingKeyList.size()); - if (matchingKeyList.size() > 0) { - Map<Key, Entity> entityMap = datastore.get(matchingKeyList); - - List<TestPlanRunEntity> testPlanRunEntityList = - entityMap - .values() - .stream() - .map( - entity -> - TestPlanRunEntity.fromEntity( - entity)) - .collect(Collectors.toList()); - - allTestPlanRunEntityMap.put( - branchKey - + "-" - + deviceBuildInfo.getDeviceBuildTarget(), - testPlanRunEntityList); - - // The passBuildIdList containing all passed buildId List for - // device - List<String> passBuildIdList = - testPlanRunEntityList - .stream() - .filter(entity -> entity.getFailCount() == 0L) - .map(entity -> entity.getTestBuildId()) - .collect(Collectors.toList()); - allPassIdLists.add(passBuildIdList); - logger.log(Level.INFO, "passBuildIdList => " + passBuildIdList); - - // The logic for candidate build ID is starting from here - Comparator<TestPlanRunEntity> byPassing = - Comparator.comparingLong( - elemFirst -> elemFirst.getPassCount()); - - Comparator<TestPlanRunEntity> byNonPassing = - Comparator.comparingLong( - elemFirst -> elemFirst.getFailCount()); - - // This will get the TestPlanRunEntity having maximum number of - // passing and minimum number of fail - Optional<TestPlanRunEntity> testPlanRunEntity = - testPlanRunEntityList - .stream() - .sorted( - byPassing - .reversed() - .thenComparing(byNonPassing)) - .findFirst(); - - String buildId = - testPlanRunEntity - .map(entity -> entity.getTestBuildId()) - .orElse(""); - deviceBuildInfo.setCandidateBuildId(buildId); - Long buildIdTimestamp = - testPlanRunEntity - .map( - entity -> { - return entity.getStartTimestamp(); - }) - .orElse(0L); - deviceBuildInfo.setCandidateBuildIdTimestamp(buildIdTimestamp); - } else { - allPassIdLists.add(new ArrayList<>()); - deviceBuildInfo.setCandidateBuildId("No Test Results"); - } - }); - Set<String> greenBuildIdList = FilterUtil.getCommonElements(allPassIdLists); - if (greenBuildIdList.size() > 0) { - String greenBuildId = greenBuildIdList.iterator().next(); - deviceBuildInfoList.forEach( - deviceBuildInfo -> { - // This is to get the timestamp for greenBuildId - Optional<TestPlanRunEntity> testPlanRunEntity = - allTestPlanRunEntityMap - .get( - branchKey - + "-" - + deviceBuildInfo - .getDeviceBuildTarget()) - .stream() - .filter( - entity -> - entity.getFailCount() == 0L - && entity.getTestBuildId() - .equalsIgnoreCase( - greenBuildId)) - .findFirst(); - // Setting the greenBuildId value and timestamp to - // deviceBuildInfo object - deviceBuildInfo.setGreenBuildId(greenBuildId); - Long buildIdTimestamp = - testPlanRunEntity - .map(entity -> entity.getStartTimestamp()) - .orElse(0L); - deviceBuildInfo.setGreenBuildIdTimestamp(buildIdTimestamp); - }); - } - }); - - request.setAttribute("plan", request.getParameter("plan")); - request.setAttribute("greenBuildInfo", baseParamMap); - RequestDispatcher dispatcher = request.getRequestDispatcher(GREEN_RELEASE_JSP); - return dispatcher; - } - - private RequestDispatcher getTestSuiteDispatcher( - HttpServletRequest request, HttpServletResponse response) { - String GREEN_RELEASE_JSP = "WEB-INF/jsp/show_green_suite_release.jsp"; - - String testPlan = request.getParameter("plan"); - - List<TestSuiteResultEntity> branchTargetInfoList = - ofy().load() - .type(TestSuiteResultEntity.class) - .filter("suitePlan", testPlan) - .project("branch") - .distinct(true) - .project("target") - .distinct(true) - .list(); - - Map<String, List<String>> paramInfoMap = new HashMap<>(); - for (TestSuiteResultEntity testSuiteResultEntity : branchTargetInfoList) { - String branch = testSuiteResultEntity.getBranch(); - String target = testSuiteResultEntity.getTarget(); - if (paramInfoMap.containsKey(branch)) { - paramInfoMap.get(branch).add(target); - } else { - paramInfoMap.put(branch, new LinkedList<>(Arrays.asList(target))); - } - } - - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.DATE, -7); - Long oneWeekAgoTimestamp = cal.getTime().getTime() * 1000; - - Map<String, List<DeviceBuildInfo>> baseParamMap = getBasicParamMap(paramInfoMap); - baseParamMap.forEach( - (branchKey, deviceBuildInfoList) -> { - List<List<String>> allPassIdLists = new ArrayList<>(); - - deviceBuildInfoList.forEach( - deviceBuildInfo -> { - List<String> passBuildIdList = - ofy().load() - .type(TestSuiteResultEntity.class) - .filter("suitePlan", testPlan) - .filter("branch", branchKey) - .filter( - "target", - deviceBuildInfo.getDeviceBuildTarget()) - .filter("failedTestCaseCount", 0) - .filterKey( - ">=", - com.googlecode.objectify.Key.create( - TestSuiteResultEntity.class, - oneWeekAgoTimestamp)) - .project("buildId") - .list() - .stream() - .map(entity -> entity.getBuildId()) - .collect(Collectors.toList()); - allPassIdLists.add(passBuildIdList); - - TestSuiteResultEntity candidateIdEntity = - ofy().load() - .type(TestSuiteResultEntity.class) - .filter("suitePlan", testPlan) - .filter("branch", branchKey) - .filter( - "target", - deviceBuildInfo.getDeviceBuildTarget()) - .filterKey( - ">=", - com.googlecode.objectify.Key.create( - TestSuiteResultEntity.class, - oneWeekAgoTimestamp)) - .project("buildId") - .order("__key__") - .order("-passedTestCaseRatio") - .first() - .now(); - if (candidateIdEntity == null) { - deviceBuildInfo.setCandidateBuildId("N/A"); - } else { - deviceBuildInfo.setCandidateBuildId( - candidateIdEntity.getBuildId()); - } - }); - }); - - request.setAttribute("plan", request.getParameter("plan")); - request.setAttribute("greenBuildInfo", baseParamMap); - RequestDispatcher dispatcher = request.getRequestDispatcher(GREEN_RELEASE_JSP); - return dispatcher; - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowPerformanceDigestServlet.java b/src/main/java/com/android/vts/servlet/ShowPerformanceDigestServlet.java deleted file mode 100644 index 5a70738..0000000 --- a/src/main/java/com/android/vts/servlet/ShowPerformanceDigestServlet.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (c) 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.util.DatastoreHelper; -import com.android.vts.util.PerformanceSummary; -import com.android.vts.util.PerformanceUtil; -import com.android.vts.util.ProfilingPointSummary; -import com.android.vts.util.StatSummary; -import java.io.IOException; -import java.math.RoundingMode; -import java.text.DecimalFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** Servlet for producing tabular performance summaries. */ -public class ShowPerformanceDigestServlet extends BaseServlet { - private static final String PERF_DIGEST_JSP = "WEB-INF/jsp/show_performance_digest.jsp"; - - private static final String MEAN = "Mean"; - private static final String MIN = "Min"; - private static final String MAX = "Max"; - private static final String MEAN_DELTA = "ΔMean (%)"; - private static final String HIGHER_IS_BETTER = - "Note: Higher values are better. Maximum is the best-case performance."; - private static final String LOWER_IS_BETTER = - "Note: Lower values are better. Minimum is the best-case performance."; - private static final String STD = "Std"; - - private static final DecimalFormat FORMATTER; - - /** Initialize the decimal formatter. */ - static { - FORMATTER = new DecimalFormat("#.##"); - FORMATTER.setRoundingMode(RoundingMode.HALF_UP); - } - - @Override - public PageType getNavParentType() { - return PageType.TOT; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - List<Page> links = new ArrayList<>(); - String testName = request.getParameter("testName"); - links.add(new Page(PageType.TABLE, testName, "?testName=" + testName)); - links.add(new Page(PageType.PERFORMANCE_DIGEST, "?testName=" + testName)); - return links; - } - - /** - * Generates an HTML summary of the performance changes for the profiling results in the - * specified table. - * - * <p>Retrieves the past 24 hours of profiling data and compares it to the 24 hours that - * preceded it. Creates a table representation of the mean and standard deviation for each - * profiling point. When performance degrades, the cell is shaded red. - * - * @param profilingPoint The name of the profiling point to summarize. - * @param testSummary The ProfilingPointSummary object to compare against. - * @param perfSummaries List of PerformanceSummary objects for each profiling run (in reverse - * chronological order). - * @param sectionLabels HTML string for the section labels (i.e. for each time interval). - * @returns An HTML string for a table comparing the profiling point results across time - * intervals. - */ - public static String getPerformanceSummary( - String profilingPoint, - ProfilingPointSummary testSummary, - List<PerformanceSummary> perfSummaries, - String sectionLabels) { - String tableHTML = "<table>"; - - // Format section labels - tableHTML += "<tr>"; - tableHTML += "<th class='section-label grey lighten-2'>"; - tableHTML += testSummary.yLabel + "</th>"; - tableHTML += sectionLabels; - tableHTML += "</tr>"; - - String bestCaseString; - switch (testSummary.getRegressionMode()) { - case VTS_REGRESSION_MODE_DECREASING: - bestCaseString = MAX; - break; - default: - bestCaseString = MIN; - break; - } - - // Format column labels - tableHTML += "<tr>"; - for (int i = 0; i <= perfSummaries.size() + 1; i++) { - if (i > 1) { - tableHTML += "<th class='section-label grey lighten-2'>" + MEAN_DELTA + "</th>"; - } - if (i == 0) { - tableHTML += "<th class='section-label grey lighten-2'>"; - tableHTML += testSummary.xLabel + "</th>"; - } else if (i > 0) { - tableHTML += "<th class='section-label grey lighten-2'>" + bestCaseString + "</th>"; - tableHTML += "<th class='section-label grey lighten-2'>" + MEAN + "</th>"; - tableHTML += "<th class='section-label grey lighten-2'>" + STD + "</th>"; - } - } - tableHTML += "</tr>"; - - // Populate data cells - for (StatSummary stats : testSummary) { - String label = stats.getLabel(); - tableHTML += "<tr><td class='axis-label grey lighten-2'>" + label; - tableHTML += "</td><td class='cell inner-cell'>"; - tableHTML += FORMATTER.format(stats.getBestCase()) + "</td>"; - tableHTML += "<td class='cell inner-cell'>"; - tableHTML += FORMATTER.format(stats.getMean()) + "</td>"; - tableHTML += "<td class='cell outer-cell'>"; - if (stats.getCount() < 2) { - tableHTML += " - </td>"; - } else { - tableHTML += FORMATTER.format(stats.getStd()) + "</td>"; - } - for (PerformanceSummary prevPerformance : perfSummaries) { - if (prevPerformance.hasProfilingPoint(profilingPoint)) { - StatSummary baseline = - prevPerformance - .getProfilingPointSummary(profilingPoint) - .getStatSummary(label); - tableHTML += - PerformanceUtil.getAvgCasePerformanceComparisonHTML( - baseline, stats, "cell inner-cell", "cell outer-cell", "", ""); - } else { - tableHTML += "<td></td><td></td><td></td><td></td>"; - } - } - tableHTML += "</tr>"; - } - tableHTML += "</table>"; - return tableHTML; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - RequestDispatcher dispatcher = null; - String testName = request.getParameter("testName"); - String selectedDevice = request.getParameter("device"); - Long startTime = null; - if (request.getParameter("startTime") != null) { - String time = request.getParameter("startTime"); - try { - startTime = Long.parseLong(time); - } catch (NumberFormatException e) { - logger.log(Level.WARNING, "Invalid start time passed to digest servlet: " + time); - } - } - if (startTime == null) { - startTime = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); - } - - // Add today to the list of time intervals to analyze - List<PerformanceSummary> summaries = new ArrayList<>(); - PerformanceSummary today = - new PerformanceSummary(startTime - TimeUnit.DAYS.toMicros(1), startTime); - summaries.add(today); - - // Add yesterday as a baseline time interval for analysis - long oneDayAgo = startTime - TimeUnit.DAYS.toMicros(1); - PerformanceSummary yesterday = - new PerformanceSummary(oneDayAgo - TimeUnit.DAYS.toMicros(1), oneDayAgo); - summaries.add(yesterday); - - // Add last week as a baseline time interval for analysis - long oneWeek = TimeUnit.DAYS.toMicros(7); - long oneWeekAgo = startTime - oneWeek; - String spanString = "<span class='date-label'>"; - String label = - spanString + TimeUnit.MICROSECONDS.toMillis(oneWeekAgo - oneWeek) + "</span>"; - label += " - " + spanString + TimeUnit.MICROSECONDS.toMillis(oneWeekAgo) + "</span>"; - PerformanceSummary lastWeek = - new PerformanceSummary(oneWeekAgo - oneWeek, oneWeekAgo, label); - summaries.add(lastWeek); - PerformanceUtil.updatePerformanceSummary( - testName, oneWeekAgo - oneWeek, startTime, selectedDevice, summaries); - - int colCount = 0; - String sectionLabels = ""; - List<PerformanceSummary> nonEmptySummaries = new ArrayList<>(); - for (PerformanceSummary perfSummary : summaries) { - if (perfSummary.size() == 0) continue; - - nonEmptySummaries.add(perfSummary); - String content = perfSummary.label; - sectionLabels += "<th class='section-label grey lighten-2 center' "; - if (colCount++ == 0) sectionLabels += "colspan='3'"; - else sectionLabels += "colspan='4'"; - sectionLabels += ">" + content + "</th>"; - } - - List<String> tables = new ArrayList<>(); - List<String> tableTitles = new ArrayList<>(); - List<String> tableSubtitles = new ArrayList<>(); - if (nonEmptySummaries.size() != 0) { - PerformanceSummary todayPerformance = nonEmptySummaries.remove(0); - String[] profilingNames = todayPerformance.getProfilingPointNames(); - - for (String profilingPointName : profilingNames) { - ProfilingPointSummary baselinePerformance = - todayPerformance.getProfilingPointSummary(profilingPointName); - String table = - getPerformanceSummary( - profilingPointName, - baselinePerformance, - nonEmptySummaries, - sectionLabels); - if (table != null) { - tables.add(table); - tableTitles.add(profilingPointName); - switch (baselinePerformance.getRegressionMode()) { - case VTS_REGRESSION_MODE_DECREASING: - tableSubtitles.add(HIGHER_IS_BETTER); - break; - default: - tableSubtitles.add(LOWER_IS_BETTER); - break; - } - } - } - } - - request.setAttribute("testName", testName); - request.setAttribute("tables", tables); - request.setAttribute("tableTitles", tableTitles); - request.setAttribute("tableSubtitles", tableSubtitles); - request.setAttribute("startTime", Long.toString(startTime)); - request.setAttribute("selectedDevice", selectedDevice); - request.setAttribute("devices", DatastoreHelper.getAllBuildFlavors()); - - dispatcher = request.getRequestDispatcher(PERF_DIGEST_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : " + e.toString()); - } - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowPlanReleaseServlet.java b/src/main/java/com/android/vts/servlet/ShowPlanReleaseServlet.java deleted file mode 100644 index 0fa28f2..0000000 --- a/src/main/java/com/android/vts/servlet/ShowPlanReleaseServlet.java +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (c) 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.DeviceInfoEntity; -import com.android.vts.entity.TestPlanEntity; -import com.android.vts.entity.TestPlanRunEntity; -import com.android.vts.entity.TestSuiteResultEntity; -import com.android.vts.util.DatastoreHelper; -import com.android.vts.util.FilterUtil; -import com.android.vts.util.Pagination; - -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.datastore.Query.Filter; -import com.google.appengine.api.datastore.Query.SortDirection; -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import org.apache.commons.lang.StringUtils; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.logging.Level; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static com.googlecode.objectify.ObjectifyService.ofy; - -public class ShowPlanReleaseServlet extends BaseServlet { - private static final int MAX_RUNS_PER_PAGE = 90; - - /** the previous cursor string token list where to start */ - private static final LinkedHashSet<String> pageCountTokenSet = new LinkedHashSet<>(); - - @Override - public PageType getNavParentType() { - return PageType.RELEASE; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - String testType = - request.getParameter("type") == null ? "plan" : request.getParameter("type"); - List<Page> links = new ArrayList<>(); - String planName = request.getParameter("plan"); - if (testType.equals("plan")) { - links.add(new Page(PageType.RELEASE, "TEST PLANS", "?type=" + testType, true)); - links.add(new Page(PageType.PLAN_RELEASE, planName, "?plan=" + planName)); - } else { - links.add(new Page(PageType.RELEASE, "TEST SUITES", "?type=" + testType, true)); - links.add( - new Page( - PageType.PLAN_RELEASE, - planName, - "?plan=" + planName + "&type=" + testType)); - } - return links; - } - - /** Model to describe each test plan run . */ - private class TestPlanRunMetadata implements Comparable<TestPlanRunMetadata> { - public final TestPlanRunEntity testPlanRun; - public final List<String> devices; - public final Set<DeviceInfoEntity> deviceSet; - - public TestPlanRunMetadata(TestPlanRunEntity testPlanRun) { - this.testPlanRun = testPlanRun; - this.devices = new ArrayList<>(); - this.deviceSet = new HashSet<>(); - } - - public void addDevice(DeviceInfoEntity device) { - if (device == null || deviceSet.contains(device)) return; - devices.add( - device.getBranch() - + "/" - + device.getBuildFlavor() - + " (" - + device.getBuildId() - + ")"); - deviceSet.add(device); - } - - public JsonObject toJson() { - JsonObject obj = new JsonObject(); - obj.add("testPlanRun", testPlanRun.toJson()); - obj.add("deviceInfo", new JsonPrimitive(StringUtils.join(devices, ", "))); - return obj; - } - - @Override - public int compareTo(TestPlanRunMetadata o) { - return new Long(o.testPlanRun.getStartTimestamp()) - .compareTo(this.testPlanRun.getStartTimestamp()); - } - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - String testType = - request.getParameter("type") == null ? "plan" : request.getParameter("type"); - - RequestDispatcher dispatcher; - if (testType.equalsIgnoreCase("plan")) { - dispatcher = this.getTestPlanDispatcher(request, response); - } else { - dispatcher = this.getTestSuiteDispatcher(request, response); - } - - try { - request.setAttribute("testType", testType); - response.setStatus(HttpServletResponse.SC_OK); - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Excpetion caught : ", e); - } - } - - private RequestDispatcher getTestPlanDispatcher( - HttpServletRequest request, HttpServletResponse response) { - String PLAN_RELEASE_JSP = "WEB-INF/jsp/show_plan_release.jsp"; - - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - - Long startTime = null; // time in microseconds - Long endTime = null; // time in microseconds - if (request.getParameter("startTime") != null) { - String time = request.getParameter("startTime"); - try { - startTime = Long.parseLong(time); - startTime = startTime > 0 ? startTime : null; - } catch (NumberFormatException e) { - startTime = null; - } - } - if (request.getParameter("endTime") != null) { - String time = request.getParameter("endTime"); - try { - endTime = Long.parseLong(time); - endTime = endTime > 0 ? endTime : null; - } catch (NumberFormatException e) { - endTime = null; - } - } - SortDirection dir = SortDirection.DESCENDING; - if (startTime != null && endTime == null) { - dir = SortDirection.ASCENDING; - } - boolean unfiltered = request.getParameter("unfiltered") != null; - boolean showPresubmit = request.getParameter("showPresubmit") != null; - boolean showPostsubmit = request.getParameter("showPostsubmit") != null; - // If no params are specified, set to default of postsubmit-only. - if (!(showPresubmit || showPostsubmit)) { - showPostsubmit = true; - } - - // If unfiltered, set showPre- and Post-submit to true for accurate UI. - if (unfiltered) { - showPostsubmit = true; - showPresubmit = true; - } - Filter typeFilter = FilterUtil.getTestTypeFilter(showPresubmit, showPostsubmit, unfiltered); - String testPlan = request.getParameter("plan"); - Key testPlanKey = KeyFactory.createKey(TestPlanEntity.KIND, testPlan); - Filter testPlanRunFilter = - FilterUtil.getTimeFilter( - testPlanKey, TestPlanRunEntity.KIND, startTime, endTime, typeFilter); - Map<String, String[]> parameterMap = request.getParameterMap(); - List<Filter> userTestFilters = FilterUtil.getUserTestFilters(parameterMap); - userTestFilters.add(0, testPlanRunFilter); - Filter userDeviceFilter = FilterUtil.getUserDeviceFilter(parameterMap); - - List<TestPlanRunMetadata> testPlanRuns = new ArrayList<>(); - Map<Key, TestPlanRunMetadata> testPlanMap = new HashMap<>(); - Key minKey = null; - Key maxKey = null; - List<Key> gets = - FilterUtil.getMatchingKeys( - testPlanKey, - TestPlanRunEntity.KIND, - userTestFilters, - userDeviceFilter, - dir, - MAX_RUNS_PER_PAGE); - Map<Key, Entity> entityMap = datastore.get(gets); - logger.log(Level.INFO, "entityMap => " + entityMap); - for (Key key : gets) { - if (!entityMap.containsKey(key)) { - continue; - } - TestPlanRunEntity testPlanRun = TestPlanRunEntity.fromEntity(entityMap.get(key)); - if (testPlanRun == null) { - continue; - } - TestPlanRunMetadata metadata = new TestPlanRunMetadata(testPlanRun); - testPlanRuns.add(metadata); - testPlanMap.put(key, metadata); - if (minKey == null || key.compareTo(minKey) < 0) { - minKey = key; - } - if (maxKey == null || key.compareTo(maxKey) > 0) { - maxKey = key; - } - } - if (minKey != null && maxKey != null) { - Filter deviceFilter = - FilterUtil.getDeviceTimeFilter( - testPlanKey, TestPlanRunEntity.KIND, minKey.getId(), maxKey.getId()); - Query deviceQuery = - new Query(DeviceInfoEntity.KIND) - .setAncestor(testPlanKey) - .setFilter(deviceFilter) - .setKeysOnly(); - List<Key> deviceGets = new ArrayList<>(); - for (Entity device : - datastore - .prepare(deviceQuery) - .asIterable(DatastoreHelper.getLargeBatchOptions())) { - if (testPlanMap.containsKey(device.getParent())) { - deviceGets.add(device.getKey()); - } - } - logger.log(Level.INFO, "deviceGets => " + deviceGets); - Map<Key, Entity> devices = datastore.get(deviceGets); - for (Key key : devices.keySet()) { - if (!testPlanMap.containsKey(key.getParent())) continue; - DeviceInfoEntity device = DeviceInfoEntity.fromEntity(devices.get(key)); - if (device == null) continue; - TestPlanRunMetadata metadata = testPlanMap.get(key.getParent()); - metadata.addDevice(device); - } - } - - testPlanRuns.sort(Comparator.naturalOrder()); - logger.log(Level.INFO, "testPlanRuns => " + testPlanRuns); - - if (testPlanRuns.size() > 0) { - TestPlanRunMetadata firstRun = testPlanRuns.get(0); - endTime = firstRun.testPlanRun.getStartTimestamp(); - - TestPlanRunMetadata lastRun = testPlanRuns.get(testPlanRuns.size() - 1); - startTime = lastRun.testPlanRun.getStartTimestamp(); - } - - List<JsonObject> testPlanRunObjects = new ArrayList<>(); - for (TestPlanRunMetadata metadata : testPlanRuns) { - testPlanRunObjects.add(metadata.toJson()); - } - - FilterUtil.setAttributes(request, parameterMap); - - request.setAttribute("plan", request.getParameter("plan")); - request.setAttribute( - "hasNewer", - new Gson() - .toJson( - DatastoreHelper.hasNewer( - testPlanKey, TestPlanRunEntity.KIND, endTime))); - request.setAttribute( - "hasOlder", - new Gson() - .toJson( - DatastoreHelper.hasOlder( - testPlanKey, TestPlanRunEntity.KIND, startTime))); - request.setAttribute("planRuns", new Gson().toJson(testPlanRunObjects)); - - request.setAttribute("unfiltered", unfiltered); - request.setAttribute("showPresubmit", showPresubmit); - request.setAttribute("showPostsubmit", showPostsubmit); - request.setAttribute("startTime", new Gson().toJson(startTime)); - request.setAttribute("endTime", new Gson().toJson(endTime)); - request.setAttribute("branches", new Gson().toJson(DatastoreHelper.getAllBranches())); - request.setAttribute("devices", new Gson().toJson(DatastoreHelper.getAllBuildFlavors())); - - RequestDispatcher dispatcher = request.getRequestDispatcher(PLAN_RELEASE_JSP); - return dispatcher; - } - - private RequestDispatcher getTestSuiteDispatcher( - HttpServletRequest request, HttpServletResponse response) { - String PLAN_RELEASE_JSP = "WEB-INF/jsp/show_suite_release.jsp"; - - String testPlan = request.getParameter("plan"); - String testCategoryType = - Objects.isNull(request.getParameter("testCategoryType")) - ? "1" - : request.getParameter("testCategoryType"); - int page = - Objects.isNull(request.getParameter("page")) - ? 1 - : Integer.valueOf(request.getParameter("page")); - String nextPageToken = - Objects.isNull(request.getParameter("nextPageToken")) - ? "" - : request.getParameter("nextPageToken"); - - com.googlecode.objectify.cmd.Query<TestSuiteResultEntity> testSuiteResultEntityQuery = - ofy().load() - .type(TestSuiteResultEntity.class) - .filter("suitePlan", testPlan) - .filter(this.getTestTypeFieldName(testCategoryType), true); - - if (Objects.nonNull(request.getParameter("branch"))) { - request.setAttribute("branch", request.getParameter("branch")); - testSuiteResultEntityQuery = - testSuiteResultEntityQuery.filter("branch", request.getParameter("branch")); - } - if (Objects.nonNull(request.getParameter("hostName"))) { - request.setAttribute("hostName", request.getParameter("hostName")); - testSuiteResultEntityQuery = - testSuiteResultEntityQuery.filter("hostName", request.getParameter("hostName")); - } - if (Objects.nonNull(request.getParameter("buildId"))) { - request.setAttribute("buildId", request.getParameter("buildId")); - testSuiteResultEntityQuery = - testSuiteResultEntityQuery.filter("buildId", request.getParameter("buildId")); - } - if (Objects.nonNull(request.getParameter("deviceName"))) { - request.setAttribute("deviceName", request.getParameter("deviceName")); - testSuiteResultEntityQuery = - testSuiteResultEntityQuery.filter( - "deviceName", request.getParameter("deviceName")); - } - testSuiteResultEntityQuery = testSuiteResultEntityQuery.orderKey(true); - - Pagination<TestSuiteResultEntity> testSuiteResultEntityPagination = - new Pagination( - testSuiteResultEntityQuery, - page, - Pagination.DEFAULT_PAGE_SIZE, - nextPageToken, - pageCountTokenSet); - - String nextPageTokenPagination = testSuiteResultEntityPagination.getNextPageCountToken(); - if (!nextPageTokenPagination.trim().isEmpty()) { - this.pageCountTokenSet.add(nextPageTokenPagination); - } - - logger.log(Level.INFO, "pageCountTokenSet => " + pageCountTokenSet); - - logger.log(Level.INFO, "list => " + testSuiteResultEntityPagination.getList()); - logger.log( - Level.INFO, - "next page count token => " - + testSuiteResultEntityPagination.getNextPageCountToken()); - logger.log( - Level.INFO, - "page min range => " + testSuiteResultEntityPagination.getMinPageRange()); - logger.log( - Level.INFO, - "page max range => " + testSuiteResultEntityPagination.getMaxPageRange()); - logger.log(Level.INFO, "page size => " + testSuiteResultEntityPagination.getPageSize()); - logger.log(Level.INFO, "total count => " + testSuiteResultEntityPagination.getTotalCount()); - - request.setAttribute("plan", testPlan); - request.setAttribute("page", page); - request.setAttribute("testType", "suite"); - request.setAttribute("testCategoryType", testCategoryType); - request.setAttribute("testSuiteResultEntityPagination", testSuiteResultEntityPagination); - RequestDispatcher dispatcher = request.getRequestDispatcher(PLAN_RELEASE_JSP); - return dispatcher; - } - - private String getTestTypeFieldName(String testCategoryType) { - String fieldName; - switch (testCategoryType) { - case "1": // TOT - fieldName = "testTypeIndex.TOT"; - break; - case "2": // OTA - fieldName = "testTypeIndex.OTA"; - break; - case "4": // SIGNED - fieldName = "testTypeIndex.SIGNED"; - break; - default: - fieldName = "testTypeIndex.TOT"; - break; - } - return fieldName; - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowPlanRunServlet.java b/src/main/java/com/android/vts/servlet/ShowPlanRunServlet.java deleted file mode 100644 index 9138a90..0000000 --- a/src/main/java/com/android/vts/servlet/ShowPlanRunServlet.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.DeviceInfoEntity; -import com.android.vts.entity.TestPlanEntity; -import com.android.vts.entity.TestPlanRunEntity; -import com.android.vts.entity.TestRunEntity; -import com.android.vts.proto.VtsReportMessage.TestCaseResult; -import com.android.vts.util.TestRunMetadata; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.EntityNotFoundException; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.Query; -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** Servlet for handling requests to load individual plan runs. */ -public class ShowPlanRunServlet extends BaseServlet { - private static final String PLAN_RUN_JSP = "WEB-INF/jsp/show_plan_run.jsp"; - - @Override - public PageType getNavParentType() { - return PageType.RELEASE; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - List<Page> links = new ArrayList<>(); - String planName = request.getParameter("plan"); - links.add(new Page(PageType.PLAN_RELEASE, planName, "?plan=" + planName)); - - String time = request.getParameter("time"); - links.add(new Page(PageType.PLAN_RUN, "?plan=" + planName + "&time=" + time)); - return links; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - Long time = null; // time in microseconds - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - RequestDispatcher dispatcher = null; - - String plan = request.getParameter("plan"); - - if (request.getParameter("time") != null) { - String timeString = request.getParameter("time"); - try { - time = Long.parseLong(timeString); - time = time > 0 ? time : null; - } catch (NumberFormatException e) { - time = null; - } - } - - // Add result names to list - List<String> resultNames = new ArrayList<>(); - for (TestCaseResult r : TestCaseResult.values()) { - resultNames.add(r.name()); - } - - List<JsonObject> passingTestObjects = new ArrayList<>(); - List<JsonObject> failingTestObjects = new ArrayList<>(); - List<JsonObject> testRunObjects = new ArrayList<>(); - - Key planKey = KeyFactory.createKey(TestPlanEntity.KIND, plan); - Key planRunKey = KeyFactory.createKey(planKey, TestPlanRunEntity.KIND, time); - String testBuildId = ""; - int passCount = 0; - int failCount = 0; - long startTime = 0; - long endTime = 0; - long moduleCount = 0; - long totalApiCount = 0L; - long totalCoveredApiCount = 0L; - try { - Entity testPlanRunEntity = datastore.get(planRunKey); - TestPlanRunEntity testPlanRun = TestPlanRunEntity.fromEntity(testPlanRunEntity); - Map<Key, Entity> testRuns = datastore.get(testPlanRun.getOldTestRuns()); - testBuildId = testPlanRun.getTestBuildId(); - passCount = (int) testPlanRun.getPassCount(); - failCount = (int) testPlanRun.getFailCount(); - totalApiCount = testPlanRun.getTotalApiCount(); - logger.log(Level.INFO, "totalApiCount => " + totalApiCount); - totalCoveredApiCount = testPlanRun.getCoveredApiCount(); - logger.log(Level.INFO, "totalCoveredApiCount => " + totalCoveredApiCount); - startTime = testPlanRun.getStartTimestamp(); - endTime = testPlanRun.getEndTimestamp(); - moduleCount = testPlanRun.getTestRuns().size(); - - for (Key key : testPlanRun.getOldTestRuns()) { - if (!testRuns.containsKey(key)) continue; - TestRunEntity testRunEntity = TestRunEntity.fromEntity(testRuns.get(key)); - if (testRunEntity == null) continue; - Query deviceInfoQuery = new Query(DeviceInfoEntity.KIND).setAncestor(key); - List<DeviceInfoEntity> devices = new ArrayList<>(); - for (Entity device : datastore.prepare(deviceInfoQuery).asIterable()) { - DeviceInfoEntity deviceEntity = DeviceInfoEntity.fromEntity(device); - if (deviceEntity == null) continue; - devices.add(deviceEntity); - } - TestRunMetadata metadata = - new TestRunMetadata(key.getParent().getName(), testRunEntity, devices); - if (metadata.testRun.getFailCount() > 0) { - failingTestObjects.add(metadata.toJson()); - } else { - passingTestObjects.add(metadata.toJson()); - } - } - } catch (EntityNotFoundException e) { - // Invalid parameters - } - testRunObjects.addAll(failingTestObjects); - testRunObjects.addAll(passingTestObjects); - - int[] topBuildResultCounts = new int[TestCaseResult.values().length]; - topBuildResultCounts[TestCaseResult.TEST_CASE_RESULT_PASS.getNumber()] = passCount; - topBuildResultCounts[TestCaseResult.TEST_CASE_RESULT_FAIL.getNumber()] = failCount; - - request.setAttribute("plan", request.getParameter("plan")); - request.setAttribute("time", request.getParameter("time")); - - request.setAttribute("resultNames", resultNames); - request.setAttribute("resultNamesJson", new Gson().toJson(resultNames)); - request.setAttribute("testRuns", new Gson().toJson(testRunObjects)); - request.setAttribute("testBuildId", new Gson().toJson(testBuildId)); - request.setAttribute("startTime", new Gson().toJson(startTime)); - request.setAttribute("endTime", new Gson().toJson(endTime)); - request.setAttribute("moduleCount", new Gson().toJson(moduleCount)); - request.setAttribute("passingTestCaseCount", new Gson().toJson(passCount)); - request.setAttribute("failingTestCaseCount", new Gson().toJson(failCount)); - request.setAttribute("totalApiCount", totalApiCount); - request.setAttribute("totalCoveredApiCount", totalCoveredApiCount); - - // data for pie chart - request.setAttribute("topBuildResultCounts", new Gson().toJson(topBuildResultCounts)); - - dispatcher = request.getRequestDispatcher(PLAN_RUN_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : " + e.toString()); - } - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowProfilingListServlet.java b/src/main/java/com/android/vts/servlet/ShowProfilingListServlet.java deleted file mode 100644 index ce138cc..0000000 --- a/src/main/java/com/android/vts/servlet/ShowProfilingListServlet.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import static com.googlecode.objectify.ObjectifyService.ofy; - -import com.android.vts.entity.TestEntity; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Query; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; -import java.util.stream.Collectors; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Servlet for handling requests to display profiling tests. - */ -public class ShowProfilingListServlet extends BaseServlet { - - private static final String PROFILING_LIST_JSP = "WEB-INF/jsp/show_profiling_list.jsp"; - - @Override - public PageType getNavParentType() { - return PageType.PROFILING_LIST; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - return null; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - List<String> tests = ofy().load().type(TestEntity.class) - .filter(TestEntity.HAS_PROFILING_DATA, true).list().stream() - .sorted(Comparator.comparing(TestEntity::getTestName)).map(t -> t.getTestName()) - .collect(Collectors.toList()); - - response.setStatus(HttpServletResponse.SC_OK); - request.setAttribute("testNames", tests); - RequestDispatcher dispatcher = request.getRequestDispatcher(PROFILING_LIST_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Excpetion caught : ", e); - } - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowProfilingOverviewServlet.java b/src/main/java/com/android/vts/servlet/ShowProfilingOverviewServlet.java deleted file mode 100644 index 5dc8c6e..0000000 --- a/src/main/java/com/android/vts/servlet/ShowProfilingOverviewServlet.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.ProfilingPointEntity; -import com.android.vts.entity.ProfilingPointSummaryEntity; -import com.android.vts.util.BoxPlot; -import com.android.vts.util.DatastoreHelper; -import com.android.vts.util.FilterUtil; -import com.android.vts.util.GraphSerializer; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.datastore.Query.Filter; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.stream.Collectors; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** Servlet for handling requests to load graphs. */ -public class ShowProfilingOverviewServlet extends BaseServlet { - private static final String PROFILING_OVERVIEW_JSP = "WEB-INF/jsp/show_profiling_overview.jsp"; - - @Override - public PageType getNavParentType() { - return PageType.PROFILING_LIST; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - List<Page> links = new ArrayList<>(); - String testName = request.getParameter("testName"); - links.add(new Page(PageType.PROFILING_OVERVIEW, testName, "?testName=" + testName)); - return links; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - RequestDispatcher dispatcher = null; - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - - String testName = request.getParameter("testName"); - long endTime = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis()); - long startTime = endTime - TimeUnit.DAYS.toMicros(30); - - // Create a query for test runs matching the time window filter - - Map<String, String[]> parameterMap = request.getParameterMap(); - boolean hasBranchFilter = parameterMap.containsKey(FilterUtil.FilterKey.BRANCH.getValue()); - Filter deviceFilter; - if (hasBranchFilter) { - deviceFilter = - FilterUtil.FilterKey.BRANCH.getFilterForString( - FilterUtil.getFirstParameter( - parameterMap, FilterUtil.FilterKey.BRANCH.getValue())); - } else { - deviceFilter = - FilterUtil.FilterKey.BRANCH.getFilterForString(ProfilingPointSummaryEntity.ALL); - } - - boolean hasTargetFilter = parameterMap.containsKey(FilterUtil.FilterKey.TARGET.getValue()); - if (hasTargetFilter) { - deviceFilter = - Query.CompositeFilterOperator.and( - deviceFilter, - FilterUtil.FilterKey.TARGET.getFilterForString( - FilterUtil.getFirstParameter( - parameterMap, FilterUtil.FilterKey.TARGET.getValue()))); - } else { - deviceFilter = - Query.CompositeFilterOperator.and( - deviceFilter, - FilterUtil.FilterKey.TARGET.getFilterForString( - ProfilingPointSummaryEntity.ALL)); - } - - Filter startFilter = - new Query.FilterPredicate( - ProfilingPointSummaryEntity.START_TIME, - Query.FilterOperator.GREATER_THAN_OR_EQUAL, - startTime); - Filter endFilter = - new Query.FilterPredicate( - ProfilingPointSummaryEntity.START_TIME, - Query.FilterOperator.LESS_THAN_OR_EQUAL, - endTime); - Filter timeFilter = Query.CompositeFilterOperator.and(startFilter, endFilter); - - Filter filter = Query.CompositeFilterOperator.and(timeFilter, deviceFilter); - - Query profilingPointQuery = - new Query(ProfilingPointEntity.KIND) - .setFilter( - new Query.FilterPredicate( - ProfilingPointEntity.TEST_NAME, - Query.FilterOperator.EQUAL, - testName)); - - List<ProfilingPointEntity> profilingPoints = new ArrayList<>(); - for (Entity e : - datastore - .prepare(profilingPointQuery) - .asIterable(DatastoreHelper.getLargeBatchOptions())) { - ProfilingPointEntity pp = ProfilingPointEntity.fromEntity(e); - if (pp == null) continue; - profilingPoints.add(pp); - } - - Map<ProfilingPointEntity, Iterable<Entity>> asyncEntities = new HashMap<>(); - for (ProfilingPointEntity pp : profilingPoints) { - Query profilingQuery = - new Query(ProfilingPointSummaryEntity.KIND) - .setAncestor(pp.getKey()) - .setFilter(filter); - asyncEntities.put( - pp, - datastore - .prepare(profilingQuery) - .asIterable(DatastoreHelper.getLargeBatchOptions())); - } - - Map<String, BoxPlot> plotMap = new HashMap<>(); - for (ProfilingPointEntity pp : profilingPoints) { - if (!plotMap.containsKey(pp.getProfilingPointName())) { - plotMap.put( - pp.getProfilingPointName(), new BoxPlot(pp.getProfilingPointName(), null, pp.getXLabel())); - } - BoxPlot plot = plotMap.get(pp.getProfilingPointName()); - Set<Long> timestamps = new HashSet<>(); - for (Entity e : asyncEntities.get(pp)) { - ProfilingPointSummaryEntity pps = ProfilingPointSummaryEntity.fromEntity(e); - if (pps == null) continue; - plot.addSeriesData(Long.toString(pps.getStartTime()), pps.getSeries(), pps.getGlobalStats()); - timestamps.add(pps.getStartTime()); - } - List<Long> timestampList = new ArrayList<>(timestamps); - timestampList.sort(Comparator.reverseOrder()); - List<String> timestampStrings = - timestampList.stream().map(Object::toString).collect(Collectors.toList()); - plot.setLabels(timestampStrings); - } - - List<BoxPlot> plots = new ArrayList<>(); - for (String key : plotMap.keySet()) { - BoxPlot plot = plotMap.get(key); - if (plot.size() == 0) continue; - plots.add(plot); - } - plots.sort((b1, b2) -> b1.getName().compareTo(b2.getName())); - - Gson gson = - new GsonBuilder() - .registerTypeHierarchyAdapter(BoxPlot.class, new GraphSerializer()) - .create(); - - FilterUtil.setAttributes(request, parameterMap); - request.setAttribute("plots", gson.toJson(plots)); - request.setAttribute("testName", request.getParameter("testName")); - request.setAttribute("branches", new Gson().toJson(DatastoreHelper.getAllBranches())); - request.setAttribute("devices", new Gson().toJson(DatastoreHelper.getAllBuildFlavors())); - dispatcher = request.getRequestDispatcher(PROFILING_OVERVIEW_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : ", e); - } - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowReleaseServlet.java b/src/main/java/com/android/vts/servlet/ShowReleaseServlet.java deleted file mode 100644 index ae175ae..0000000 --- a/src/main/java/com/android/vts/servlet/ShowReleaseServlet.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.TestPlanEntity; -import com.android.vts.entity.TestSuiteResultEntity; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.users.UserServiceFactory; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; -import java.util.stream.Collectors; - -import static com.googlecode.objectify.ObjectifyService.ofy; - -/** - * Represents the servlet that is invoked on loading the release page. - */ -public class ShowReleaseServlet extends BaseServlet { - - @Override - public PageType getNavParentType() { - return PageType.RELEASE; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - return null; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - String testType = - request.getParameter("type") == null ? "plan" : request.getParameter("type"); - - RequestDispatcher dispatcher; - if (testType.equalsIgnoreCase("plan")) { - dispatcher = this.getTestPlanDispatcher(request, response); - } else { - dispatcher = this.getTestSuiteDispatcher(request, response); - } - - try { - request.setAttribute("testType", testType); - response.setStatus(HttpServletResponse.SC_OK); - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Excpetion caught : ", e); - } - } - - private RequestDispatcher getTestPlanDispatcher( - HttpServletRequest request, HttpServletResponse response) { - String RELEASE_JSP = "WEB-INF/jsp/show_release.jsp"; - - List<TestPlanEntity> testPlanEntityList = ofy().load().type(TestPlanEntity.class).list(); - - List<String> plans = testPlanEntityList.stream() - .sorted(Comparator.comparing(TestPlanEntity::getTestPlanName)) - .map(te -> te.getTestPlanName()).collect(Collectors.toList()); - - request.setAttribute("isAdmin", UserServiceFactory.getUserService().isUserAdmin()); - request.setAttribute("planNames", plans); - RequestDispatcher dispatcher = request.getRequestDispatcher(RELEASE_JSP); - return dispatcher; - } - - private RequestDispatcher getTestSuiteDispatcher( - HttpServletRequest request, HttpServletResponse response) { - String RELEASE_JSP = "WEB-INF/jsp/show_release.jsp"; - - List<TestSuiteResultEntity> suiteResultEntityList = TestSuiteResultEntity.getTestSuitePlans(); - - List<String> plans = - suiteResultEntityList - .stream() - .map(suiteEntity -> suiteEntity.getSuitePlan()) - .collect(Collectors.toList()); - request.setAttribute("isAdmin", UserServiceFactory.getUserService().isUserAdmin()); - request.setAttribute("planNames", plans); - RequestDispatcher dispatcher = request.getRequestDispatcher(RELEASE_JSP); - return dispatcher; - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowTableServlet.java b/src/main/java/com/android/vts/servlet/ShowTableServlet.java deleted file mode 100644 index b56ce9c..0000000 --- a/src/main/java/com/android/vts/servlet/ShowTableServlet.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright (c) 2016 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.CodeCoverageEntity; -import com.android.vts.entity.TestCaseRunEntity; -import com.android.vts.entity.TestEntity; -import com.android.vts.entity.TestRunEntity; -import com.android.vts.proto.VtsReportMessage.TestCaseResult; -import com.android.vts.util.DatastoreHelper; -import com.android.vts.util.FilterUtil; -import com.android.vts.util.TestResults; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.Query.Filter; -import com.google.appengine.api.datastore.Query.SortDirection; -import com.google.gson.Gson; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** Servlet for handling requests to load individual tables. */ -public class ShowTableServlet extends BaseServlet { - private static final String TABLE_JSP = "WEB-INF/jsp/show_table.jsp"; - // Error message displayed on the webpage is tableName passed is null. - private static final String TABLE_NAME_ERROR = "Error : Table name must be passed!"; - private static final String PROFILING_DATA_ALERT = "No profiling data was found."; - private static final int MAX_BUILD_IDS_PER_PAGE = 10; - - @Override - public PageType getNavParentType() { - return PageType.TOT; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - List<Page> links = new ArrayList<>(); - String testName = request.getParameter("testName"); - links.add(new Page(PageType.TABLE, testName, "?testName=" + testName)); - return links; - } - - public static void processTestRun(TestResults testResults, Entity testRun) { - TestRunEntity testRunEntity = TestRunEntity.fromEntity(testRun); - if (testRunEntity == null) { - return; - } - - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - List<Key> gets = new ArrayList<>(); - for (long testCaseId : testRunEntity.getTestCaseIds()) { - gets.add(KeyFactory.createKey(TestCaseRunEntity.KIND, testCaseId)); - } - - List<Entity> testCases = new ArrayList<>(); - Map<Key, Entity> entityMap = datastore.get(gets); - for (Key key : gets) { - if (entityMap.containsKey(key)) { - testCases.add(entityMap.get(key)); - } - } - - testResults.addTestRun(testRun, testCases); - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - boolean unfiltered = request.getParameter("unfiltered") != null; - boolean showPresubmit = request.getParameter("showPresubmit") != null; - boolean showPostsubmit = request.getParameter("showPostsubmit") != null; - - Long startTime = null; // time in microseconds - Long endTime = null; // time in microseconds - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - RequestDispatcher dispatcher = null; - - // message to display if profiling point data is not available - String profilingDataAlert = ""; - - if (request.getParameter("testName") == null) { - request.setAttribute("testName", TABLE_NAME_ERROR); - return; - } - String testName = request.getParameter("testName"); - - if (request.getParameter("startTime") != null) { - String time = request.getParameter("startTime"); - try { - startTime = Long.parseLong(time); - startTime = startTime > 0 ? startTime : null; - } catch (NumberFormatException e) { - startTime = null; - } - } - if (request.getParameter("endTime") != null) { - String time = request.getParameter("endTime"); - try { - endTime = Long.parseLong(time); - endTime = endTime > 0 ? endTime : null; - } catch (NumberFormatException e) { - endTime = null; - } - } - - // If no params are specified, set to default of postsubmit-only. - if (!(showPresubmit || showPostsubmit)) { - showPostsubmit = true; - } - - // If unfiltered, set showPre- and Post-submit to true for accurate UI. - if (unfiltered) { - showPostsubmit = true; - showPresubmit = true; - } - - // Add result names to list - List<String> resultNames = new ArrayList<>(); - for (TestCaseResult r : TestCaseResult.values()) { - resultNames.add(r.name()); - } - - TestResults testResults = new TestResults(testName); - - SortDirection dir = SortDirection.DESCENDING; - if (startTime != null && endTime == null) { - dir = SortDirection.ASCENDING; - } - Key testKey = KeyFactory.createKey(TestEntity.KIND, testName); - - Filter typeFilter = FilterUtil.getTestTypeFilter(showPresubmit, showPostsubmit, unfiltered); - Filter testFilter = - FilterUtil.getTimeFilter( - testKey, TestRunEntity.KIND, startTime, endTime, typeFilter); - - Map<String, String[]> parameterMap = request.getParameterMap(); - List<Filter> userTestFilters = FilterUtil.getUserTestFilters(parameterMap); - userTestFilters.add(0, testFilter); - Filter userDeviceFilter = FilterUtil.getUserDeviceFilter(parameterMap); - - List<Key> gets = - FilterUtil.getMatchingKeys( - testKey, - TestRunEntity.KIND, - userTestFilters, - userDeviceFilter, - dir, - MAX_BUILD_IDS_PER_PAGE); - Map<Key, Entity> entityMap = datastore.get(gets); - for (Key key : gets) { - if (!entityMap.containsKey(key)) { - continue; - } - processTestRun(testResults, entityMap.get(key)); - } - testResults.processReport(); - - if (testResults.profilingPointNames.length == 0) { - profilingDataAlert = PROFILING_DATA_ALERT; - } - - FilterUtil.setAttributes(request, parameterMap); - - request.setAttribute("testName", request.getParameter("testName")); - - request.setAttribute("error", profilingDataAlert); - - // pass values by converting to JSON - request.setAttribute("headerRow", new Gson().toJson(testResults.headerRow)); - request.setAttribute("timeGrid", new Gson().toJson(testResults.timeGrid)); - request.setAttribute("durationGrid", new Gson().toJson(testResults.durationGrid)); - request.setAttribute("summaryGrid", new Gson().toJson(testResults.summaryGrid)); - request.setAttribute("resultsGrid", new Gson().toJson(testResults.resultsGrid)); - request.setAttribute("profilingPointNames", testResults.profilingPointNames); - request.setAttribute("resultNames", resultNames); - request.setAttribute("resultNamesJson", new Gson().toJson(resultNames)); - request.setAttribute("logInfoMap", new Gson().toJson(testResults.logInfoMap)); - - // data for pie chart - request.setAttribute( - "topBuildResultCounts", new Gson().toJson(testResults.totResultCounts)); - request.setAttribute("topBuildId", testResults.totBuildId); - request.setAttribute("startTime", new Gson().toJson(testResults.startTime)); - request.setAttribute("endTime", new Gson().toJson(testResults.endTime)); - request.setAttribute( - "hasNewer", - new Gson() - .toJson( - DatastoreHelper.hasNewer( - testKey, TestRunEntity.KIND, testResults.endTime))); - request.setAttribute( - "hasOlder", - new Gson() - .toJson( - DatastoreHelper.hasOlder( - testKey, TestRunEntity.KIND, testResults.startTime))); - request.setAttribute("unfiltered", unfiltered); - request.setAttribute("showPresubmit", showPresubmit); - request.setAttribute("showPostsubmit", showPostsubmit); - - request.setAttribute("branches", new Gson().toJson(DatastoreHelper.getAllBranches())); - request.setAttribute("devices", new Gson().toJson(DatastoreHelper.getAllBuildFlavors())); - - dispatcher = request.getRequestDispatcher(TABLE_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : " + e.toString()); - } - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowTestAcknowledgmentServlet.java b/src/main/java/com/android/vts/servlet/ShowTestAcknowledgmentServlet.java deleted file mode 100644 index c75352c..0000000 --- a/src/main/java/com/android/vts/servlet/ShowTestAcknowledgmentServlet.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.TestAcknowledgmentEntity; -import com.android.vts.entity.TestEntity; -import com.android.vts.util.DatastoreHelper; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.users.UserServiceFactory; -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class ShowTestAcknowledgmentServlet extends BaseServlet { - private static final String TEST_ACK_JSP = "WEB-INF/jsp/show_test_acknowledgments.jsp"; - - @Override - public PageType getNavParentType() { - return PageType.TOT; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - List<Page> links = new ArrayList<>(); - return links; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - Query ackQuery = new Query(TestAcknowledgmentEntity.KIND); - List<JsonObject> testAcks = new ArrayList<>(); - for (Entity ackEntity : - datastore.prepare(ackQuery).asIterable(DatastoreHelper.getLargeBatchOptions())) { - TestAcknowledgmentEntity ack = TestAcknowledgmentEntity.fromEntity(ackEntity); - if (ack == null) continue; - testAcks.add(ack.toJson()); - } - - List<String> allTestNames = TestEntity.getAllTestNames(); - - request.setAttribute("testAcknowledgments", new Gson().toJson(testAcks)); - request.setAttribute("allTests", new Gson().toJson(allTestNames)); - request.setAttribute("branches", new Gson().toJson(DatastoreHelper.getAllBranches())); - request.setAttribute("devices", new Gson().toJson(DatastoreHelper.getAllBuildFlavors())); - request.setAttribute("readOnly", new Gson().toJson(!UserServiceFactory.getUserService().isUserAdmin())); - - RequestDispatcher dispatcher = request.getRequestDispatcher(TEST_ACK_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : ", e); - } - } -} diff --git a/src/main/java/com/android/vts/servlet/ShowTreeServlet.java b/src/main/java/com/android/vts/servlet/ShowTreeServlet.java deleted file mode 100644 index e087807..0000000 --- a/src/main/java/com/android/vts/servlet/ShowTreeServlet.java +++ /dev/null @@ -1,329 +0,0 @@ -/* - * Copyright (c) 2017 Google Inc. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You may - * obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.android.vts.servlet; - -import com.android.vts.entity.DeviceInfoEntity; -import com.android.vts.entity.ProfilingPointRunEntity; -import com.android.vts.entity.TestCaseRunEntity; -import com.android.vts.entity.TestEntity; -import com.android.vts.entity.TestRunEntity; -import com.android.vts.proto.VtsReportMessage.TestCaseResult; -import com.android.vts.util.DatastoreHelper; -import com.android.vts.util.FilterUtil; -import com.android.vts.util.TestRunDetails; -import com.android.vts.util.TestRunMetadata; -import com.google.appengine.api.datastore.DatastoreService; -import com.google.appengine.api.datastore.DatastoreServiceFactory; -import com.google.appengine.api.datastore.Entity; -import com.google.appengine.api.datastore.Key; -import com.google.appengine.api.datastore.KeyFactory; -import com.google.appengine.api.datastore.Query; -import com.google.appengine.api.datastore.Query.Filter; -import com.google.appengine.api.datastore.Query.SortDirection; -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Servlet for handling requests to load individual tables. - */ -public class ShowTreeServlet extends BaseServlet { - - private static final String TABLE_JSP = "WEB-INF/jsp/show_tree.jsp"; - // Error message displayed on the webpage is tableName passed is null. - private static final String TABLE_NAME_ERROR = "Error : Table name must be passed!"; - private static final String PROFILING_DATA_ALERT = "No profiling data was found."; - private static final int MAX_RESULT_COUNT = 60; - private static final int MAX_PREFETCH_COUNT = 10; - - @Override - public PageType getNavParentType() { - return PageType.TOT; - } - - @Override - public List<Page> getBreadcrumbLinks(HttpServletRequest request) { - List<Page> links = new ArrayList<>(); - String testName = request.getParameter("testName"); - links.add(new Page(PageType.TREE, testName, "?testName=" + testName)); - return links; - } - - /** - * Get the test run details for a test run. - * - * @param metadata The metadata for the test run whose details will be fetched. - * @return The TestRunDetails object for the provided test run. - */ - public static TestRunDetails processTestDetails(TestRunMetadata metadata) { - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - TestRunDetails details = new TestRunDetails(); - List<Key> gets = new ArrayList<>(); - for (long testCaseId : metadata.testRun.getTestCaseIds()) { - gets.add(KeyFactory.createKey(TestCaseRunEntity.KIND, testCaseId)); - } - Map<Key, Entity> entityMap = datastore.get(gets); - for (int i = 0; i < 1; i++) { - for (Key key : entityMap.keySet()) { - TestCaseRunEntity testCaseRun = TestCaseRunEntity.fromEntity(entityMap.get(key)); - if (testCaseRun == null) { - continue; - } - details.addTestCase(testCaseRun); - } - } - return details; - } - - @Override - public void doGetHandler(HttpServletRequest request, HttpServletResponse response) - throws IOException { - boolean unfiltered = request.getParameter("unfiltered") != null; - boolean showPresubmit = request.getParameter("showPresubmit") != null; - boolean showPostsubmit = request.getParameter("showPostsubmit") != null; - Long startTime = null; // time in microseconds - Long endTime = null; // time in microseconds - DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); - RequestDispatcher dispatcher = null; - - // message to display if profiling point data is not available - String profilingDataAlert = ""; - - if (request.getParameter("testName") == null) { - request.setAttribute("testName", TABLE_NAME_ERROR); - return; - } - String testName = request.getParameter("testName"); - - if (request.getParameter("startTime") != null) { - String time = request.getParameter("startTime"); - try { - startTime = Long.parseLong(time); - startTime = startTime > 0 ? startTime : null; - } catch (NumberFormatException e) { - startTime = null; - } - } - if (request.getParameter("endTime") != null) { - String time = request.getParameter("endTime"); - try { - endTime = Long.parseLong(time); - endTime = endTime > 0 ? endTime : null; - } catch (NumberFormatException e) { - endTime = null; - } - } - - // If no params are specified, set to default of postsubmit-only. - if (!(showPresubmit || showPostsubmit)) { - showPostsubmit = true; - } - - // If unfiltered, set showPre- and Post-submit to true for accurate UI. - if (unfiltered) { - showPostsubmit = true; - showPresubmit = true; - } - - // Add result names to list - List<String> resultNames = new ArrayList<>(); - for (TestCaseResult r : TestCaseResult.values()) { - resultNames.add(r.name()); - } - - SortDirection dir = SortDirection.DESCENDING; - if (startTime != null && endTime == null) { - dir = SortDirection.ASCENDING; - } - Key testKey = KeyFactory.createKey(TestEntity.KIND, testName); - - Filter typeFilter = FilterUtil.getTestTypeFilter(showPresubmit, showPostsubmit, unfiltered); - Filter testFilter = - FilterUtil.getTimeFilter( - testKey, TestRunEntity.KIND, startTime, endTime, typeFilter); - - Map<String, String[]> parameterMap = request.getParameterMap(); - List<Filter> userTestFilters = FilterUtil.getUserTestFilters(parameterMap); - userTestFilters.add(0, testFilter); - Filter userDeviceFilter = FilterUtil.getUserDeviceFilter(parameterMap); - - List<TestRunMetadata> testRunMetadata = new ArrayList<>(); - Map<Key, TestRunMetadata> metadataMap = new HashMap<>(); - Key minKey = null; - Key maxKey = null; - List<Key> gets = - FilterUtil.getMatchingKeys( - testKey, - TestRunEntity.KIND, - userTestFilters, - userDeviceFilter, - dir, - MAX_RESULT_COUNT); - Map<Key, Entity> entityMap = datastore.get(gets); - for (Key key : gets) { - if (!entityMap.containsKey(key)) { - continue; - } - TestRunEntity testRunEntity = TestRunEntity.fromEntity(entityMap.get(key)); - if (testRunEntity == null) { - continue; - } - if (minKey == null || key.compareTo(minKey) < 0) { - minKey = key; - } - if (maxKey == null || key.compareTo(maxKey) > 0) { - maxKey = key; - } - TestRunMetadata metadata = new TestRunMetadata(testName, testRunEntity); - testRunMetadata.add(metadata); - metadataMap.put(key, metadata); - } - - List<String> profilingPointNames = new ArrayList<>(); - if (minKey != null && maxKey != null) { - Filter deviceFilter = - FilterUtil.getDeviceTimeFilter( - testKey, TestRunEntity.KIND, minKey.getId(), maxKey.getId()); - Query deviceQuery = - new Query(DeviceInfoEntity.KIND) - .setAncestor(testKey) - .setFilter(deviceFilter) - .setKeysOnly(); - List<Key> deviceGets = new ArrayList<>(); - for (Entity device : - datastore - .prepare(deviceQuery) - .asIterable(DatastoreHelper.getLargeBatchOptions())) { - if (metadataMap.containsKey(device.getParent())) { - deviceGets.add(device.getKey()); - } - } - Map<Key, Entity> devices = datastore.get(deviceGets); - for (Key key : devices.keySet()) { - if (!metadataMap.containsKey(key.getParent())) { - continue; - } - DeviceInfoEntity device = DeviceInfoEntity.fromEntity(devices.get(key)); - if (device == null) { - continue; - } - TestRunMetadata metadata = metadataMap.get(key.getParent()); - metadata.addDevice(device); - } - - Filter profilingFilter = - FilterUtil.getProfilingTimeFilter( - testKey, TestRunEntity.KIND, minKey.getId(), maxKey.getId()); - - Set<String> profilingPoints = new HashSet<>(); - Query profilingPointQuery = - new Query(ProfilingPointRunEntity.KIND) - .setAncestor(testKey) - .setFilter(profilingFilter) - .setKeysOnly(); - for (Entity e : datastore.prepare(profilingPointQuery).asIterable()) { - profilingPoints.add(e.getKey().getName()); - } - - if (profilingPoints.size() == 0) { - profilingDataAlert = PROFILING_DATA_ALERT; - } - profilingPointNames.addAll(profilingPoints); - profilingPointNames.sort(Comparator.naturalOrder()); - } - - testRunMetadata.sort( - (t1, t2) -> - new Long(t2.testRun.getStartTimestamp()).compareTo(t1.testRun.getStartTimestamp())); - List<JsonObject> testRunObjects = new ArrayList<>(); - - int prefetchCount = 0; - for (TestRunMetadata metadata : testRunMetadata) { - if (metadata.testRun.getFailCount() > 0 && prefetchCount < MAX_PREFETCH_COUNT) { - // process - metadata.addDetails(processTestDetails(metadata)); - ++prefetchCount; - } - testRunObjects.add(metadata.toJson()); - } - - int[] topBuildResultCounts = null; - String topBuild = ""; - if (testRunMetadata.size() > 0) { - TestRunMetadata firstRun = testRunMetadata.get(0); - topBuild = firstRun.getDeviceInfo(); - endTime = firstRun.testRun.getStartTimestamp(); - TestRunDetails topDetails = firstRun.getDetails(); - if (topDetails == null) { - topDetails = processTestDetails(firstRun); - } - topBuildResultCounts = topDetails.resultCounts; - - TestRunMetadata lastRun = testRunMetadata.get(testRunMetadata.size() - 1); - startTime = lastRun.testRun.getStartTimestamp(); - } - - FilterUtil.setAttributes(request, parameterMap); - - request.setAttribute("testName", request.getParameter("testName")); - - request.setAttribute("error", profilingDataAlert); - - request.setAttribute("profilingPointNames", profilingPointNames); - request.setAttribute("resultNames", resultNames); - request.setAttribute("resultNamesJson", new Gson().toJson(resultNames)); - request.setAttribute("testRuns", new Gson().toJson(testRunObjects)); - - // data for pie chart - request.setAttribute("topBuildResultCounts", new Gson().toJson(topBuildResultCounts)); - request.setAttribute("topBuildId", topBuild); - request.setAttribute("startTime", new Gson().toJson(startTime)); - request.setAttribute("endTime", new Gson().toJson(endTime)); - request.setAttribute( - "hasNewer", - new Gson().toJson(DatastoreHelper.hasNewer(testKey, TestRunEntity.KIND, endTime))); - request.setAttribute( - "hasOlder", - new Gson() - .toJson(DatastoreHelper.hasOlder(testKey, TestRunEntity.KIND, startTime))); - request.setAttribute("unfiltered", unfiltered); - request.setAttribute("showPresubmit", showPresubmit); - request.setAttribute("showPostsubmit", showPostsubmit); - - request.setAttribute("branches", new Gson().toJson(DatastoreHelper.getAllBranches())); - request.setAttribute("devices", new Gson().toJson(DatastoreHelper.getAllBuildFlavors())); - - dispatcher = request.getRequestDispatcher(TABLE_JSP); - try { - dispatcher.forward(request, response); - } catch (ServletException e) { - logger.log(Level.SEVERE, "Servlet Exception caught : " + e.toString()); - } - } -} |