kylin-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] caolijun1166 closed pull request #295: KYILN-3597 Use SecureRandom instead of Random
Date Fri, 19 Oct 2018 00:39:00 GMT
caolijun1166 closed pull request #295: KYILN-3597 Use SecureRandom instead of Random
URL: https://github.com/apache/kylin/pull/295
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java b/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java
index dbd19559fe..2b003b79f9 100755
--- a/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java
+++ b/core-cube/src/main/java/org/apache/kylin/cube/CubeManager.java
@@ -19,6 +19,8 @@
 package org.apache.kylin.cube;
 
 import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -510,11 +512,11 @@ private String getSnapshotResPath(CubeSegment cubeSegment, String tableName,
Sna
     }
 
     @VisibleForTesting
-    /*private*/ String generateStorageLocation() {
+    /*private*/ String generateStorageLocation() throws NoSuchAlgorithmException {
         String namePrefix = config.getHBaseTableNamePrefix();
         String namespace = config.getHBaseStorageNameSpace();
         String tableName = "";
-        Random ran = new Random();
+        Random ran = SecureRandom.getInstanceStrong();
         do {
             StringBuffer sb = new StringBuffer();
             if ((namespace.equals("default") || namespace.equals("")) == false) {
@@ -568,42 +570,42 @@ public IRealization getRealization(String name) {
     // ============================================================================
 
     // append a full build segment
-    public CubeSegment appendSegment(CubeInstance cube) throws IOException {
+    public CubeSegment appendSegment(CubeInstance cube) throws IOException, NoSuchAlgorithmException
{
         return appendSegment(cube, null, null, null, null);
     }
 
-    public CubeSegment appendSegment(CubeInstance cube, TSRange tsRange) throws IOException
{
+    public CubeSegment appendSegment(CubeInstance cube, TSRange tsRange) throws IOException,
NoSuchAlgorithmException {
         return appendSegment(cube, tsRange, null, null, null);
     }
 
-    public CubeSegment appendSegment(CubeInstance cube, SourcePartition src) throws IOException
{
+    public CubeSegment appendSegment(CubeInstance cube, SourcePartition src) throws IOException,
NoSuchAlgorithmException {
         return appendSegment(cube, src.getTSRange(), src.getSegRange(), src.getSourcePartitionOffsetStart(),
                 src.getSourcePartitionOffsetEnd());
     }
 
     CubeSegment appendSegment(CubeInstance cube, TSRange tsRange, SegmentRange segRange,
             Map<Integer, Long> sourcePartitionOffsetStart, Map<Integer, Long>
sourcePartitionOffsetEnd)
-            throws IOException {
+            throws IOException, NoSuchAlgorithmException {
         try (AutoLock lock = cubeMapLock.lockForWrite()) {
             return segAssist.appendSegment(cube, tsRange, segRange, sourcePartitionOffsetStart,
                     sourcePartitionOffsetEnd);
         }
     }
 
-    public CubeSegment refreshSegment(CubeInstance cube, TSRange tsRange, SegmentRange segRange)
throws IOException {
+    public CubeSegment refreshSegment(CubeInstance cube, TSRange tsRange, SegmentRange segRange)
throws IOException, NoSuchAlgorithmException {
         try (AutoLock lock = cubeMapLock.lockForWrite()) {
             return segAssist.refreshSegment(cube, tsRange, segRange);
         }
     }
 
-    public CubeSegment[] optimizeSegments(CubeInstance cube, Set<Long> cuboidsRecommend)
throws IOException {
+    public CubeSegment[] optimizeSegments(CubeInstance cube, Set<Long> cuboidsRecommend)
throws IOException, NoSuchAlgorithmException {
         try (AutoLock lock = cubeMapLock.lockForWrite()) {
             return segAssist.optimizeSegments(cube, cuboidsRecommend);
         }
     }
 
     public CubeSegment mergeSegments(CubeInstance cube, TSRange tsRange, SegmentRange segRange,
boolean force)
-            throws IOException {
+            throws IOException, NoSuchAlgorithmException {
         try (AutoLock lock = cubeMapLock.lockForWrite()) {
             return segAssist.mergeSegments(cube, tsRange, segRange, force);
         }
@@ -636,7 +638,7 @@ public void promoteCheckpointOptimizeSegments(CubeInstance cube, Map<Long,
Long>
 
         CubeSegment appendSegment(CubeInstance cube, TSRange tsRange, SegmentRange segRange,
                 Map<Integer, Long> sourcePartitionOffsetStart, Map<Integer, Long>
sourcePartitionOffsetEnd)
-                throws IOException {
+                throws IOException, NoSuchAlgorithmException {
             CubeInstance cubeCopy = cube.latestCopyForWrite(); // get a latest copy
 
             checkInputRanges(tsRange, segRange);
@@ -670,7 +672,7 @@ else if (!last.isOffsetCube())
         }
 
         public CubeSegment refreshSegment(CubeInstance cube, TSRange tsRange, SegmentRange
segRange)
-                throws IOException {
+                throws IOException, NoSuchAlgorithmException {
             CubeInstance cubeCopy = cube.latestCopyForWrite(); // get a latest copy
 
             checkInputRanges(tsRange, segRange);
@@ -713,7 +715,7 @@ public CubeSegment refreshSegment(CubeInstance cube, TSRange tsRange,
SegmentRan
             return newSegment;
         }
 
-        public CubeSegment[] optimizeSegments(CubeInstance cube, Set<Long> cuboidsRecommend)
throws IOException {
+        public CubeSegment[] optimizeSegments(CubeInstance cube, Set<Long> cuboidsRecommend)
throws IOException, NoSuchAlgorithmException {
             CubeInstance cubeCopy = cube.latestCopyForWrite(); // get a latest copy
 
             List<CubeSegment> readySegments = cubeCopy.getSegments(SegmentStatusEnum.READY);
@@ -735,7 +737,7 @@ public CubeSegment refreshSegment(CubeInstance cube, TSRange tsRange,
SegmentRan
         }
 
         public CubeSegment mergeSegments(CubeInstance cube, TSRange tsRange, SegmentRange
segRange, boolean force)
-                throws IOException {
+                throws IOException, NoSuchAlgorithmException {
             CubeInstance cubeCopy = cube.latestCopyForWrite(); // get a latest copy
 
             if (cubeCopy.getSegments().isEmpty())
@@ -833,7 +835,7 @@ private void checkCubeIsPartitioned(CubeInstance cube) {
             }
         }
 
-        private CubeSegment newSegment(CubeInstance cube, TSRange tsRange, SegmentRange segRange)
{
+        private CubeSegment newSegment(CubeInstance cube, TSRange tsRange, SegmentRange segRange)
throws NoSuchAlgorithmException {
             DataModelDesc modelDesc = cube.getModel();
 
             CubeSegment segment = new CubeSegment();
diff --git a/core-cube/src/test/java/org/apache/kylin/cube/CubeManagerTest.java b/core-cube/src/test/java/org/apache/kylin/cube/CubeManagerTest.java
index cad5094af5..0d71c4bc2d 100644
--- a/core-cube/src/test/java/org/apache/kylin/cube/CubeManagerTest.java
+++ b/core-cube/src/test/java/org/apache/kylin/cube/CubeManagerTest.java
@@ -23,6 +23,7 @@
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
 import java.util.Map;
 import java.util.NavigableSet;
@@ -388,7 +389,7 @@ public void testAutoMergeWithVolatileRange() throws Exception {
     }
 
     @Test
-    public void testGetCubeNameWithNamespace() {
+    public void testGetCubeNameWithNamespace() throws NoSuchAlgorithmException {
         System.setProperty("kylin.storage.hbase.table-name-prefix", "HELLO_");
         try {
             CubeManager mgr = CubeManager.getInstance(getTestConfig());
@@ -409,7 +410,7 @@ public void testGetCubeNameWithNamespace() {
     }
 
     @Test
-    public void testBuildCubeWithPartitionStartDate() throws IOException {
+    public void testBuildCubeWithPartitionStartDate() throws IOException, NoSuchAlgorithmException
{
         Long PARTITION_DATE_START = 1513123200L;
         Long FIRST_BUILD_DATE_END = 1514764800L;
         Long SECOND_BUILD_DATE_END = 1540339200L;
diff --git a/core-cube/src/test/java/org/apache/kylin/cube/CubeSegmentsTest.java b/core-cube/src/test/java/org/apache/kylin/cube/CubeSegmentsTest.java
index c4dcb596fa..4acbe5fff8 100644
--- a/core-cube/src/test/java/org/apache/kylin/cube/CubeSegmentsTest.java
+++ b/core-cube/src/test/java/org/apache/kylin/cube/CubeSegmentsTest.java
@@ -22,6 +22,7 @@
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
 
 import org.apache.kylin.common.util.LocalFileMetadataTestCase;
 import org.apache.kylin.metadata.model.PartitionDesc;
@@ -45,7 +46,7 @@ public void after() throws Exception {
     }
 
     @Test
-    public void testAppendNonPartitioned() throws IOException {
+    public void testAppendNonPartitioned() throws IOException, NoSuchAlgorithmException {
         CubeManager mgr = mgr();
         CubeInstance cube = mgr.getCube("test_kylin_cube_without_slr_empty");
 
@@ -71,7 +72,7 @@ public void testAppendNonPartitioned() throws IOException {
     }
 
     @Test
-    public void testAppendNonPartitioned2() throws IOException {
+    public void testAppendNonPartitioned2() throws IOException, NoSuchAlgorithmException
{
         CubeManager mgr = mgr();
         CubeInstance cube = mgr.getCube("test_kylin_cube_without_slr_ready");
 
@@ -102,7 +103,7 @@ public void testAppendNonPartitioned2() throws IOException {
     }
 
     @Test
-    public void testPartitioned() throws IOException {
+    public void testPartitioned() throws IOException, NoSuchAlgorithmException {
         CubeManager mgr = mgr();
         CubeInstance cube = mgr.getCube("test_kylin_cube_with_slr_left_join_empty");
 
@@ -157,7 +158,7 @@ public void testPartitioned() throws IOException {
     }
 
     @Test
-    public void testAllowGap() throws IOException {
+    public void testAllowGap() throws IOException, NoSuchAlgorithmException {
 
         CubeManager mgr = mgr();
         CubeInstance cube = mgr.getCube("test_kylin_cube_without_slr_left_join_empty");
diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java b/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java
index d4ff9704ad..b9397fbb4d 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/CubeService.java
@@ -19,6 +19,7 @@
 package org.apache.kylin.rest.service;
 
 import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
@@ -586,7 +587,7 @@ private void releaseAllSegments(CubeInstance cube) throws IOException
{
         CubeManager.getInstance(getConfig()).updateCube(update);
     }
 
-    public void updateOnNewSegmentReady(String cubeName) {
+    public void updateOnNewSegmentReady(String cubeName) throws NoSuchAlgorithmException
{
         final KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
         String serverMode = kylinConfig.getServerMode();
         if (Constant.SERVER_MODE_JOB.equals(serverMode.toLowerCase(Locale.ROOT))
@@ -636,7 +637,7 @@ private void keepCubeRetention(String cubeName) {
         }
     }
 
-    private void mergeCubeSegment(String cubeName) {
+    private void mergeCubeSegment(String cubeName) throws NoSuchAlgorithmException {
         CubeInstance cube = getCubeManager().getCube(cubeName);
         if (!cube.needAutoMerge())
             return;
diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java b/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java
index d8aa7111e6..4320075fb9 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/JobService.java
@@ -19,6 +19,7 @@
 package org.apache.kylin.rest.service;
 
 import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
@@ -210,7 +211,7 @@ private long getTimeStartInMillis(Calendar calendar, JobTimeFilterEnum
timeFilte
 
     public JobInstance submitJob(CubeInstance cube, TSRange tsRange, SegmentRange segRange,
//
             Map<Integer, Long> sourcePartitionOffsetStart, Map<Integer, Long>
sourcePartitionOffsetEnd,
-            CubeBuildTypeEnum buildType, boolean force, String submitter) throws IOException
{
+            CubeBuildTypeEnum buildType, boolean force, String submitter) throws IOException,
NoSuchAlgorithmException {
         aclEvaluate.checkProjectOperationPermission(cube);
         JobInstance jobInstance = submitJobInternal(cube, tsRange, segRange, sourcePartitionOffsetStart,
                 sourcePartitionOffsetEnd, buildType, force, submitter);
@@ -220,7 +221,7 @@ public JobInstance submitJob(CubeInstance cube, TSRange tsRange, SegmentRange
se
 
     public JobInstance submitJobInternal(CubeInstance cube, TSRange tsRange, SegmentRange
segRange, //
             Map<Integer, Long> sourcePartitionOffsetStart, Map<Integer, Long>
sourcePartitionOffsetEnd, //
-            CubeBuildTypeEnum buildType, boolean force, String submitter) throws IOException
{
+            CubeBuildTypeEnum buildType, boolean force, String submitter) throws IOException,
NoSuchAlgorithmException {
         Message msg = MsgPicker.getMsg();
 
         if (cube.getStatus() == RealizationStatusEnum.DESCBROKEN) {
@@ -278,14 +279,14 @@ public JobInstance submitJobInternal(CubeInstance cube, TSRange tsRange,
Segment
     }
 
     public Pair<JobInstance, List<JobInstance>> submitOptimizeJob(CubeInstance
cube, Set<Long> cuboidsRecommend,
-            String submitter) throws IOException, JobException {
+            String submitter) throws IOException, JobException, NoSuchAlgorithmException
{
 
         Pair<JobInstance, List<JobInstance>> result = submitOptimizeJobInternal(cube,
cuboidsRecommend, submitter);
         return result;
     }
 
     private Pair<JobInstance, List<JobInstance>> submitOptimizeJobInternal(CubeInstance
cube,
-            Set<Long> cuboidsRecommend, String submitter) throws IOException {
+            Set<Long> cuboidsRecommend, String submitter) throws IOException, NoSuchAlgorithmException
{
         Message msg = MsgPicker.getMsg();
 
         if (cube.getStatus() == RealizationStatusEnum.DESCBROKEN) {
@@ -335,7 +336,7 @@ public JobInstance submitJobInternal(CubeInstance cube, TSRange tsRange,
Segment
     }
 
     public JobInstance submitRecoverSegmentOptimizeJob(CubeSegment segment, String submitter)
-            throws IOException, JobException {
+            throws IOException, JobException, NoSuchAlgorithmException {
         CubeInstance cubeInstance = segment.getCubeInstance();
 
         checkCubeDescSignature(cubeInstance);
diff --git a/server/src/test/java/org/apache/kylin/rest/controller/CubeControllerTest.java
b/server/src/test/java/org/apache/kylin/rest/controller/CubeControllerTest.java
index d30391b2e0..1872d54481 100644
--- a/server/src/test/java/org/apache/kylin/rest/controller/CubeControllerTest.java
+++ b/server/src/test/java/org/apache/kylin/rest/controller/CubeControllerTest.java
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.io.StringWriter;
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
 
 import org.apache.kylin.cube.CubeInstance;
@@ -185,7 +186,7 @@ public void testDeleteSegmentFromHead() throws IOException {
     }
 
     @Test
-    public void testGetHoles() throws IOException {
+    public void testGetHoles() throws IOException, NoSuchAlgorithmException {
         String cubeName = "test_kylin_cube_with_slr_ready_3_segments";
         CubeDesc[] cubes = cubeDescController.getCube(cubeName);
         Assert.assertNotNull(cubes);
diff --git a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
index 6dd16fe494..7d81483efc 100644
--- a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
+++ b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/util/GridTableHBaseBenchmark.java
@@ -20,6 +20,8 @@
 
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
 import java.util.List;
 import java.util.Random;
 
@@ -58,7 +60,7 @@
     private static final int ROUND = 3;
     protected static final Logger logger = LoggerFactory.getLogger(GridTableHBaseBenchmark.class);
 
-    public static void main(String[] args) throws IOException {
+    public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
         double hitRatio = DFT_HIT_RATIO;
         try {
             hitRatio = Double.parseDouble(args[0]);
@@ -76,7 +78,7 @@ public static void main(String[] args) throws IOException {
         testGridTable(hitRatio, indexRatio);
     }
 
-    public static void testGridTable(double hitRatio, double indexRatio) throws IOException
{
+    public static void testGridTable(double hitRatio, double indexRatio) throws IOException,
NoSuchAlgorithmException {
         logger.info("Testing grid table scanning, hit ratio {}, index ratio {}", hitRatio,
indexRatio);
         StorageURL hbaseUrl = StorageURL.valueOf("default@hbase"); // use hbase-site.xml
on classpath
 
@@ -210,7 +212,7 @@ private static void jumpScan(Connection conn, boolean[] hits, Stats stats)
throw
         }
     }
 
-    private static void prepareData(Connection conn) throws IOException {
+    private static void prepareData(Connection conn) throws IOException, NoSuchAlgorithmException
{
         Table table = conn.getTable(TableName.valueOf(TEST_TABLE));
 
         try {
@@ -256,9 +258,9 @@ private static void dot(int i, int nRows) {
             logger.info(".");
     }
 
-    private static byte[] randomBytes() {
+    private static byte[] randomBytes() throws NoSuchAlgorithmException {
         byte[] bytes = new byte[CELL_SIZE];
-        Random rand = new Random();
+        Random rand = SecureRandom.getInstanceStrong();
         rand.nextBytes(bytes);
         return bytes;
     }
diff --git a/tool/src/main/java/org/apache/kylin/tool/job/CubeBuildingCLI.java b/tool/src/main/java/org/apache/kylin/tool/job/CubeBuildingCLI.java
index b3b11264d5..e2ab60da90 100644
--- a/tool/src/main/java/org/apache/kylin/tool/job/CubeBuildingCLI.java
+++ b/tool/src/main/java/org/apache/kylin/tool/job/CubeBuildingCLI.java
@@ -19,6 +19,7 @@
 package org.apache.kylin.tool.job;
 
 import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
 
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionBuilder;
@@ -91,7 +92,7 @@ protected void execute(OptionsHelper optionsHelper) throws Exception {
         run(cubeName, startTime, endTime, buildType);
     }
 
-    private void run(String cubeName, long startDate, long endDate, String buildType) throws
IOException, JobException {
+    private void run(String cubeName, long startDate, long endDate, String buildType) throws
IOException, JobException, NoSuchAlgorithmException {
         CubeInstance cube = cubeManager.getCube(cubeName);
         Preconditions.checkArgument(cube != null, "Cube named " + cubeName + " does not exist!!!");
         CubeBuildTypeEnum buildTypeEnum = CubeBuildTypeEnum.valueOf(buildType);
@@ -100,7 +101,7 @@ private void run(String cubeName, long startDate, long endDate, String
buildType
     }
 
     private void submitJob(CubeInstance cube, TSRange tsRange, CubeBuildTypeEnum buildType,
-            boolean forceMergeEmptySeg, String submitter) throws IOException, JobException
{
+            boolean forceMergeEmptySeg, String submitter) throws IOException, JobException,
NoSuchAlgorithmException {
         checkCubeDescSignature(cube);
 
         DefaultChainedExecutable job;
diff --git a/tool/src/test/java/org/apache/kylin/tool/HybridCubeCLITest.java b/tool/src/test/java/org/apache/kylin/tool/HybridCubeCLITest.java
index 99b8319386..8982f4062f 100644
--- a/tool/src/test/java/org/apache/kylin/tool/HybridCubeCLITest.java
+++ b/tool/src/test/java/org/apache/kylin/tool/HybridCubeCLITest.java
@@ -19,6 +19,7 @@
 package org.apache.kylin.tool;
 
 import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
 
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.util.LocalFileMetadataTestCase;
@@ -98,7 +99,7 @@ public void test3Delete() throws IOException {
     }
 
     @Test
-    public void testSegmentOverlap() throws IOException {
+    public void testSegmentOverlap() throws IOException, NoSuchAlgorithmException {
         thrown.expect(RuntimeException.class);
         thrown.expectMessage("Segments has overlap");
 
@@ -119,7 +120,7 @@ public void testSegmentOverlap() throws IOException {
     }
 
     @Test
-    public void testSegmentNotOverlap() throws IOException {
+    public void testSegmentNotOverlap() throws IOException, NoSuchAlgorithmException {
         HybridManager hybridManager = HybridManager.getInstance(KylinConfig.getInstanceFromEnv());
         Assert.assertNull(hybridManager.getHybridInstance("ssb_hybrid"));
         HybridCubeCLI.main(new String[] { "-name", "ssb_hybrid", "-project", "default", "-model",
"ssb", "-cubes", "ssb_cube1,ssb_cube2", "-action", "create" });


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message