diff options
author | Young Gyu Park <younggyu@google.com> | 2018-05-29 19:07:27 +0900 |
---|---|---|
committer | Young Gyu Park <younggyu@google.com> | 2018-06-01 14:43:39 +0900 |
commit | 3ff7fcf07115812ffe5ec50525e23eda3577ac75 (patch) | |
tree | 549fd84e5a8c0043d951dcdf1e924e2accdda36d /src/main/java/com/android/vts/api | |
parent | 7a9b488cfbfd8b3944142b6d4ba1a9f5eb43c7cd (diff) | |
download | dashboard-3ff7fcf07115812ffe5ec50525e23eda3577ac75.tar.gz |
Project managing tool change from maven to gradleandroid-o-mr1-iot-release-1.0.1
Test: go/vts-web/show_plan_release?plan=cts-on-gsi&type=suite&testCategoryType=4
Bug: 80407473
Change-Id: I6dfcd329d4c33cd5f3edf25c45caed80196c8f99
Diffstat (limited to 'src/main/java/com/android/vts/api')
4 files changed, 233 insertions, 93 deletions
diff --git a/src/main/java/com/android/vts/api/BigtableLegacyJsonServlet.java b/src/main/java/com/android/vts/api/BigtableLegacyJsonServlet.java index d2b4a61..ac69b84 100644 --- a/src/main/java/com/android/vts/api/BigtableLegacyJsonServlet.java +++ b/src/main/java/com/android/vts/api/BigtableLegacyJsonServlet.java @@ -17,6 +17,7 @@ package com.android.vts.api; import com.android.vts.proto.VtsReportMessage.TestReportMessage; +import com.android.vts.servlet.BaseServlet; import com.android.vts.util.DatastoreHelper; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.http.javanet.NetHttpTransport; @@ -25,9 +26,14 @@ import com.google.api.services.oauth2.Oauth2; import com.google.api.services.oauth2.model.Tokeninfo; import com.google.protobuf.InvalidProtocolBufferException; import java.io.BufferedReader; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -38,11 +44,33 @@ import org.json.JSONObject; /** REST endpoint for posting data JSON to the Dashboard. */ @Deprecated public class BigtableLegacyJsonServlet extends HttpServlet { - private static final String SERVICE_CLIENT_ID = System.getProperty("SERVICE_CLIENT_ID"); + private static String SERVICE_CLIENT_ID; private static final String SERVICE_NAME = "VTS Dashboard"; private static final Logger logger = Logger.getLogger(BigtableLegacyJsonServlet.class.getName()); + /** System Configuration Property class */ + protected Properties systemConfigProp = new Properties(); + + @Override + public void init(ServletConfig cfg) throws ServletException { + super.init(cfg); + + try { + InputStream defaultInputStream = + BigtableLegacyJsonServlet.class + .getClassLoader() + .getResourceAsStream("config.properties"); + systemConfigProp.load(defaultInputStream); + + SERVICE_CLIENT_ID = systemConfigProp.getProperty("appengine.serviceClientID"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { @@ -93,7 +121,8 @@ public class BigtableLegacyJsonServlet extends HttpServlet { insertData(payloadJson); break; default: - logger.log(Level.WARNING, + logger.log( + Level.WARNING, "Invalid Datastore REST verb: " + payloadJson.getString("verb")); throw new IOException("Unsupported POST verb."); } @@ -110,8 +139,7 @@ public class BigtableLegacyJsonServlet extends HttpServlet { * * @param payloadJson The JSON object representing the row to be inserted. Of the form: { * (deprecated) 'tableName' : 'table', (deprecated) 'rowKey' : 'row', (deprecated) 'family' - * : - * 'family', (deprecated) 'qualifier' : 'qualifier', 'value' : 'value' } + * : 'family', (deprecated) 'qualifier' : 'qualifier', 'value' : 'value' } * @throws IOException */ private void insertData(JSONObject payloadJson) throws IOException { diff --git a/src/main/java/com/android/vts/api/DatastoreRestServlet.java b/src/main/java/com/android/vts/api/DatastoreRestServlet.java index 8910267..42d7a60 100644 --- a/src/main/java/com/android/vts/api/DatastoreRestServlet.java +++ b/src/main/java/com/android/vts/api/DatastoreRestServlet.java @@ -19,16 +19,24 @@ package com.android.vts.api; import com.android.vts.proto.VtsReportMessage.DashboardPostMessage; import com.android.vts.proto.VtsReportMessage.TestPlanReportMessage; import com.android.vts.proto.VtsReportMessage.TestReportMessage; +import com.android.vts.servlet.BaseServlet; import com.android.vts.util.DatastoreHelper; +import com.android.vts.util.EmailHelper; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.jackson.JacksonFactory; import com.google.api.services.oauth2.Oauth2; import com.google.api.services.oauth2.model.Tokeninfo; + +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -36,10 +44,32 @@ import org.apache.commons.codec.binary.Base64; /** REST endpoint for posting data to the Dashboard. */ public class DatastoreRestServlet extends HttpServlet { - private static final String SERVICE_CLIENT_ID = System.getProperty("SERVICE_CLIENT_ID"); + private static String SERVICE_CLIENT_ID; private static final String SERVICE_NAME = "VTS Dashboard"; private static final Logger logger = Logger.getLogger(DatastoreRestServlet.class.getName()); + /** System Configuration Property class */ + protected Properties systemConfigProp = new Properties(); + + @Override + public void init(ServletConfig cfg) throws ServletException { + super.init(cfg); + + try { + InputStream defaultInputStream = + DatastoreRestServlet.class + .getClassLoader() + .getResourceAsStream("config.properties"); + systemConfigProp.load(defaultInputStream); + + SERVICE_CLIENT_ID = systemConfigProp.getProperty("appengine.serviceClientID"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { @@ -70,7 +100,8 @@ public class DatastoreRestServlet extends HttpServlet { DatastoreHelper.insertTestReport(testReportMessage); } - for (TestPlanReportMessage planReportMessage : postMessage.getTestPlanReportList()) { + for (TestPlanReportMessage planReportMessage : + postMessage.getTestPlanReportList()) { DatastoreHelper.insertTestPlanReport(planReportMessage); } diff --git a/src/main/java/com/android/vts/api/TestDataForDevServlet.java b/src/main/java/com/android/vts/api/TestDataForDevServlet.java index e6a4413..75432c7 100644 --- a/src/main/java/com/android/vts/api/TestDataForDevServlet.java +++ b/src/main/java/com/android/vts/api/TestDataForDevServlet.java @@ -32,6 +32,8 @@ import com.android.vts.entity.TestStatusEntity; import com.android.vts.entity.TestRunEntity.TestRunType; import com.android.vts.entity.TestStatusEntity.TestCaseReference; +import com.android.vts.servlet.BaseServlet; +import com.android.vts.util.EmailHelper; import com.google.appengine.api.datastore.DatastoreFailureException; import com.google.appengine.api.datastore.DatastoreService; import com.google.appengine.api.datastore.DatastoreServiceFactory; @@ -48,7 +50,10 @@ import com.google.appengine.api.users.UserServiceFactory; import com.google.appengine.api.utils.SystemProperty; import com.google.gson.Gson; import com.google.gson.GsonBuilder; + +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.file.FileSystems; @@ -63,11 +68,13 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Random; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.IntStream; +import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -78,8 +85,7 @@ public class TestDataForDevServlet extends HttpServlet { protected static final Logger logger = Logger.getLogger(TestDataForDevServlet.class.getName()); /** Google Cloud Storage project's default directory name for suite test result files */ - private static final String GCS_SUITE_TEST_FOLDER_NAME = - System.getProperty("GCS_SUITE_TEST_FOLDER_NAME"); + private static String GCS_SUITE_TEST_FOLDER_NAME; /** datastore instance to save the test data into datastore through datastore library. */ private DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); @@ -89,6 +95,28 @@ public class TestDataForDevServlet extends HttpServlet { */ private Gson gson = new GsonBuilder().create(); + /** System Configuration Property class */ + protected Properties systemConfigProp = new Properties(); + + @Override + public void init(ServletConfig cfg) throws ServletException { + super.init(cfg); + + try { + InputStream defaultInputStream = + TestDataForDevServlet.class + .getClassLoader() + .getResourceAsStream("config.properties"); + systemConfigProp.load(defaultInputStream); + + GCS_SUITE_TEST_FOLDER_NAME = systemConfigProp.getProperty("gcs.suiteTestFolderName"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * TestReportData class for mapping test-report-data.json. This internal class's each fields * will be automatically mapped to test-report-data.json file through Gson @@ -205,93 +233,117 @@ public class TestDataForDevServlet extends HttpServlet { "aosp_arm_a-userdebug"); branchList.forEach( branch -> - targetList.forEach( - target -> - IntStream.range(0, 10) - .forEach( - idx -> { - String year = String.format("%04d", 2010 + idx); - String month = - String.format("%02d", rand.nextInt(12)); - String day = - String.format("%02d", rand.nextInt(30)); - String fileName = - String.format( - "%02d%02d%02d.bin", - rand.nextInt(23) + 1, - rand.nextInt(59) + 1, - rand.nextInt(59) + 1); - - List<String> pathList = - Arrays.asList( - GCS_SUITE_TEST_FOLDER_NAME == "" - ? "suite_result" - : GCS_SUITE_TEST_FOLDER_NAME, - year, - month, - day, - fileName); - - Path pathInfo = - Paths.get( - String.join( - fileSeparator, - pathList)); - - TestSuiteFileEntity newTestSuiteFileEntity = - new TestSuiteFileEntity( - pathInfo.toString()); - newTestSuiteFileEntity.save(); - - com.googlecode.objectify.Key< - TestSuiteFileEntity> - testSuiteFileParent = - com.googlecode.objectify.Key - .create( + targetList.forEach( + target -> + IntStream.range(0, 10) + .forEach( + idx -> { + String year = + String.format( + "%04d", 2010 + idx); + String month = + String.format( + "%02d", + rand.nextInt(12)); + String day = + String.format( + "%02d", + rand.nextInt(30)); + String fileName = + String.format( + "%02d%02d%02d.bin", + rand.nextInt(23) + 1, + rand.nextInt(59) + 1, + rand.nextInt(59) + 1); + + List<String> pathList = + Arrays.asList( + GCS_SUITE_TEST_FOLDER_NAME + == "" + ? "suite_result" + : GCS_SUITE_TEST_FOLDER_NAME, + year, + month, + day, + fileName); + + Path pathInfo = + Paths.get( + String.join( + fileSeparator, + pathList)); + + TestSuiteFileEntity + newTestSuiteFileEntity = + new TestSuiteFileEntity( + pathInfo + .toString()); + newTestSuiteFileEntity.save(); + + com.googlecode.objectify.Key< + TestSuiteFileEntity> + testSuiteFileParent = + com.googlecode.objectify + .Key.create( TestSuiteFileEntity .class, newTestSuiteFileEntity .getFilePath()); - TestSuiteResultEntity testSuiteResultEntity = - new TestSuiteResultEntity( - testSuiteFileParent, - Instant.now() - .minus( - rand.nextInt( - 100), - ChronoUnit.DAYS) - .getEpochSecond(), - Instant.now() - .minus( - rand.nextInt( - 100), - ChronoUnit.DAYS) - .getEpochSecond(), - 1, - idx / 2 == 0 ? false : true, - pathInfo.toString(), - idx / 2 == 0 ? "/error/infra/log" : "", - "Test Place Name -" + idx, - "Suite Test Plan", - "Suite Version " + idx, - "Suite Test Name", - "Suite Build Number " + idx, - rand.nextInt(), - rand.nextInt(), - branch, - target, - Long.toString(Math.abs(rand.nextLong())), - "Build System Fingerprint " - + idx, - "Build Vendor Fingerprint " - + idx, - rand.nextInt(), - rand.nextInt()); - - testSuiteResultEntity.save(); - }) - ) - ); + TestSuiteResultEntity + testSuiteResultEntity = + new TestSuiteResultEntity( + testSuiteFileParent, + Instant.now() + .minus( + rand + .nextInt( + 100), + ChronoUnit + .DAYS) + .getEpochSecond(), + Instant.now() + .minus( + rand + .nextInt( + 100), + ChronoUnit + .DAYS) + .getEpochSecond(), + 1, + idx / 2 == 0 + ? false + : true, + pathInfo + .toString(), + idx / 2 == 0 + ? "/error/infra/log" + : "", + "Test Place Name -" + + idx, + "Suite Test Plan", + "Suite Version " + + idx, + "Suite Test Name", + "Suite Build Number " + + idx, + rand.nextInt(), + rand.nextInt(), + branch, + target, + Long.toString( + Math + .abs( + rand + .nextLong())), + "Build System Fingerprint " + + idx, + "Build Vendor Fingerprint " + + idx, + rand.nextInt(), + rand.nextInt()); + + testSuiteResultEntity.save(); + }))); resultMap.put("result", "successfully generated!"); return resultMap; } diff --git a/src/main/java/com/android/vts/api/TestSuiteResultRestServlet.java b/src/main/java/com/android/vts/api/TestSuiteResultRestServlet.java index 61931cb..9887ccd 100644 --- a/src/main/java/com/android/vts/api/TestSuiteResultRestServlet.java +++ b/src/main/java/com/android/vts/api/TestSuiteResultRestServlet.java @@ -19,6 +19,7 @@ package com.android.vts.api; import com.android.vts.entity.TestSuiteFileEntity; import com.android.vts.entity.TestSuiteResultEntity; import com.android.vts.proto.TestSuiteResultMessageProto.TestSuiteResultMessage; +import com.android.vts.servlet.BaseServlet; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.jackson.JacksonFactory; @@ -31,22 +32,49 @@ import org.apache.commons.codec.binary.Base64; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.IntStream; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; /** REST endpoint for posting test suite data to the Dashboard. */ public class TestSuiteResultRestServlet extends HttpServlet { - private static final String SERVICE_CLIENT_ID = System.getProperty("SERVICE_CLIENT_ID"); + private static String SERVICE_CLIENT_ID; private static final String SERVICE_NAME = "VTS Dashboard"; private static final Logger logger = Logger.getLogger(TestSuiteResultRestServlet.class.getName()); + /** System Configuration Property class */ + protected Properties systemConfigProp = new Properties(); + + @Override + public void init(ServletConfig cfg) throws ServletException { + super.init(cfg); + + try { + InputStream defaultInputStream = + TestSuiteResultRestServlet.class + .getClassLoader() + .getResourceAsStream("config.properties"); + systemConfigProp.load(defaultInputStream); + + SERVICE_CLIENT_ID = systemConfigProp.getProperty("appengine.serviceClientID"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { @@ -75,7 +103,8 @@ public class TestSuiteResultRestServlet extends HttpServlet { Tokeninfo tokenInfo = oauth2.tokeninfo().setAccessToken(accessToken).execute(); if (tokenInfo.getIssuedTo().equals(SERVICE_CLIENT_ID)) { - Key<TestSuiteFileEntity> testSuiteFileParent = Key.create(TestSuiteFileEntity.class, "suite_result/2019/04/06/132343.bin"); + Key<TestSuiteFileEntity> testSuiteFileParent = + Key.create(TestSuiteFileEntity.class, "suite_result/2019/04/06/132343.bin"); TestSuiteResultEntity testSuiteResultEntity = new TestSuiteResultEntity( testSuiteFileParent, |