diff options
Diffstat (limited to 'src')
6 files changed, 80 insertions, 24 deletions
diff --git a/src/main/java/com/android/vts/entity/TestSuiteResultEntity.java b/src/main/java/com/android/vts/entity/TestSuiteResultEntity.java index b3d24df..2e12f54 100644 --- a/src/main/java/com/android/vts/entity/TestSuiteResultEntity.java +++ b/src/main/java/com/android/vts/entity/TestSuiteResultEntity.java @@ -391,6 +391,16 @@ public class TestSuiteResultEntity { return deviceName; } + public String getScreenResultLogPath() { + String gcsBucketName = systemConfigProp.getProperty("gcs.bucketName"); + return resultPath.replace("gs://" + gcsBucketName + "/", ""); + } + + public String getScreenInfraLogPath() { + String gcsInfraLogBucketName = systemConfigProp.getProperty("gcs.infraLogBucketName"); + return infraLogPath.replace("gs://" + gcsInfraLogBucketName + "/", ""); + } + private String getNormalizedVersion(String fingerprint) { Map<String, Pattern> partternMap = new HashMap<String, Pattern>() { diff --git a/src/main/java/com/android/vts/servlet/ShowGcsLogServlet.java b/src/main/java/com/android/vts/servlet/ShowGcsLogServlet.java index ec332e5..ad5e871 100644 --- a/src/main/java/com/android/vts/servlet/ShowGcsLogServlet.java +++ b/src/main/java/com/android/vts/servlet/ShowGcsLogServlet.java @@ -34,6 +34,7 @@ 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; @@ -41,7 +42,14 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.*; + +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; @@ -57,8 +65,10 @@ public class ShowGcsLogServlet extends BaseServlet { /** 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 log files */ + /** 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 @@ -72,27 +82,51 @@ public class ShowGcsLogServlet extends BaseServlet { /** This is the instance of App Engine memcache service java library */ private MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService(); - /** GCS Bucket instance */ + /** 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"); - this.keyFileInputStream = - this.getClass().getClassLoader().getResourceAsStream("keys/" + GCS_KEY_FILE); + 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> optionalStorage = GcsHelper.getStorage(this.keyFileInputStream); - if (optionalStorage.isPresent()) { - this.storage = optionalStorage.get(); + 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)); } @@ -138,15 +172,26 @@ public class ShowGcsLogServlet extends BaseServlet { String file = request.getParameter("file") == null ? "/" : request.getParameter("file"); Path filePathInfo = Paths.get(file); - Blob blobFile = vtsReportBucket.get(filePathInfo.toString()); + Blob blobFile = vtsInfraLogBucket.get(filePathInfo.toString()); - response.setContentType("application/octet-stream"); - response.setContentLength(blobFile.getSize().intValue()); - response.setHeader( - "Content-Disposition", - "attachment; filename=\"" + filePathInfo.getFileName() + "\""); + 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()); + 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) diff --git a/src/main/java/com/android/vts/util/GcsHelper.java b/src/main/java/com/android/vts/util/GcsHelper.java index 4cb1811..b2c6aac 100644 --- a/src/main/java/com/android/vts/util/GcsHelper.java +++ b/src/main/java/com/android/vts/util/GcsHelper.java @@ -4,7 +4,6 @@ import com.google.auth.oauth2.ServiceAccountCredentials; import com.google.cloud.storage.Storage; import com.google.cloud.storage.StorageOptions; -import javax.servlet.ServletContext; import java.io.IOException; import java.io.InputStream; import java.util.Optional; @@ -22,6 +21,9 @@ public class GcsHelper { GCS_PROJECT_ID = gcsProjectId; } + /** + * Get GCS storage from Key file input stream parameter. + */ public static Optional<Storage> getStorage(InputStream keyFileInputStream) { if (keyFileInputStream == null) { diff --git a/src/main/resources/config.properties b/src/main/resources/config.properties index e1b9318..20c4ac2 100644 --- a/src/main/resources/config.properties +++ b/src/main/resources/config.properties @@ -14,6 +14,7 @@ analytics.id= gcs.projectID= gcs.keyFile= gcs.bucketName= +gcs.infraLogBucketName= gcs.suiteTestFolderName= bug.tracking.system= diff --git a/src/main/webapp/WEB-INF/jsp/show_suite_release.jsp b/src/main/webapp/WEB-INF/jsp/show_suite_release.jsp index 60fd046..523291a 100644 --- a/src/main/webapp/WEB-INF/jsp/show_suite_release.jsp +++ b/src/main/webapp/WEB-INF/jsp/show_suite_release.jsp @@ -159,7 +159,7 @@ <div class='row'> <div class='col s12'> - <ul class="tabs"> + <ul class="tabs z-depth-1"> <li class="tab col s4" id="totTabLink"> <a class="<c:out value="${testCategoryType == '1' ? 'active' : 'inactive'}"></c:out>" href="${requestScope['javax.servlet.forward.servlet_path']}?plan=${plan}&type=${testType}&testCategoryType=1">TOT</a> </li> @@ -242,15 +242,13 @@ <div class="col s12"> <span class="suite-test-run-metadata"> <b>Result Log Path: </b> - <c:set var="resultLogPath" value="${fn:replace(testSuiteResultEntity.resultPath, 'gs://vts-report/', '')}"/> - <a href="show_gcs_log?path=${resultLogPath}"> - <c:out value="${resultLogPath}"></c:out> + <a href="show_gcs_log?path=${testSuiteResultEntity.screenResultLogPath}"> + <c:out value="${testSuiteResultEntity.screenResultLogPath}"></c:out> </a> <br> <b>Infra Log Path: </b> - <c:set var="infraLogPath" value="${fn:replace(testSuiteResultEntity.infraLogPath, 'gs://vts-report/', '')}"/> - <a href="show_gcs_log/download?file=${infraLogPath}"> - <c:out value="${infraLogPath}"></c:out> + <a href="show_gcs_log/download?file=${testSuiteResultEntity.screenInfraLogPath}"> + <c:out value="${testSuiteResultEntity.screenInfraLogPath}"></c:out> </a> <br> </span> diff --git a/src/test/java/com/android/vts/job/VtsPerformanceJobServletTest.java b/src/test/java/com/android/vts/job/VtsPerformanceJobServletTest.java index f44f038..8416748 100644 --- a/src/test/java/com/android/vts/job/VtsPerformanceJobServletTest.java +++ b/src/test/java/com/android/vts/job/VtsPerformanceJobServletTest.java @@ -45,7 +45,7 @@ public class VtsPerformanceJobServletTest { new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig()); private static final String LABEL = "testLabel"; - private static final String ROOT = "src/test/res/servlet"; + private static final String ROOT = "src/test/resources/servlet"; private static final String[] LABELS = new String[] {"label1", "label2", "label3"}; private static final long[] HIGH_VALS = new long[] {10, 20, 30}; private static final long[] LOW_VALS = new long[] {1, 2, 3}; |