diff options
author | Young Gyu Park <younggyu@google.com> | 2018-08-28 14:13:46 +0900 |
---|---|---|
committer | Young Gyu Park <younggyu@google.com> | 2018-09-07 14:41:24 +0900 |
commit | 0efd811cf59e40da011f90d6fd8510a619e8cd6f (patch) | |
tree | b586b357120de25c0159e272c7a1acc2125f419a /src/main/java | |
parent | 85586068d384d4e51d22cee1fe0f3ab75167a34a (diff) | |
download | dashboard-0efd811cf59e40da011f90d6fd8510a619e8cd6f.tar.gz |
Malformed report log path caused by multiple projects creation.
Test: go/vts-web-staging
Bug: 112661963
Change-Id: I57e1aba6597baf526bc8bc7cef0742fae65e2e6b
Diffstat (limited to 'src/main/java')
3 files changed, 73 insertions, 16 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) { |