This is an automated email from the ASF dual-hosted git repository. nic pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/kylin.git
commit d532e5eaf93f2e1751f6e7ccc735da8352ef26c5 Author: etherge <[email protected]> AuthorDate: Thu Jan 23 18:33:02 2020 -0500 minor, sonar issues for throwing exceptions in finnally block --- .../kylin/rest/controller/StreamingController.java | 21 ++++++++++----- .../rest/controller/StreamingV2Controller.java | 31 ++++++++++++++-------- .../v2/coprocessor/endpoint/CubeVisitService.java | 16 +++++++---- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller/StreamingController.java b/server-base/src/main/java/org/apache/kylin/rest/controller/StreamingController.java index 36a8a7c..6d98434 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/controller/StreamingController.java +++ b/server-base/src/main/java/org/apache/kylin/rest/controller/StreamingController.java @@ -113,7 +113,6 @@ public class StreamingController extends BasicController { @RequestMapping(value = "", method = { RequestMethod.POST }, produces = { "application/json" }) @ResponseBody public StreamingRequest saveStreamingConfig(@RequestBody StreamingRequest streamingRequest) { - String project = streamingRequest.getProject(); TableDesc tableDesc = deserializeTableDesc(streamingRequest); if (null == tableDesc) { @@ -138,6 +137,8 @@ public class StreamingController extends BasicController { streamingConfig.setName(tableDesc.getIdentity()); kafkaConfig.setName(tableDesc.getIdentity()); + + InternalErrorException exception = null; try { if (StringUtils.isEmpty(streamingConfig.getName())) { logger.info("StreamingConfig should not be empty."); @@ -160,23 +161,24 @@ public class StreamingController extends BasicController { streamingService.dropStreamingConfig(streamingConfig, project); } catch (IOException e1) { throw new InternalErrorException( - "StreamingConfig is created, but failed to create KafkaConfig: " + e.getLocalizedMessage(), e); + "StreamingConfig is created, but failed to create KafkaConfig: " + e.getLocalizedMessage(), + e); } logger.error("Failed to save KafkaConfig:" + e.getLocalizedMessage(), e); throw new InternalErrorException("Failed to save KafkaConfig: " + e.getLocalizedMessage(), e); } } finally { if (saveKafkaSuccess == false || saveStreamingSuccess == false) { - if (saveStreamingSuccess == true) { StreamingConfig sConfig = streamingService.getStreamingManager() .getStreamingConfig(streamingConfig.getName()); try { streamingService.dropStreamingConfig(sConfig, project); } catch (IOException e) { - throw new InternalErrorException( + exception = new InternalErrorException( "Action failed and failed to rollback the created streaming config: " - + e.getLocalizedMessage(), e); + + e.getLocalizedMessage(), + e); } } if (saveKafkaSuccess == true) { @@ -184,14 +186,19 @@ public class StreamingController extends BasicController { KafkaConfig kConfig = kafkaConfigService.getKafkaConfig(kafkaConfig.getName(), project); kafkaConfigService.dropKafkaConfig(kConfig, project); } catch (IOException e) { - throw new InternalErrorException( + exception = new InternalErrorException( "Action failed and failed to rollback the created kafka config: " - + e.getLocalizedMessage(), e); + + e.getLocalizedMessage(), + e); } } } + } + if (null != exception) { + throw exception; } + streamingRequest.setSuccessful(true); return streamingRequest; } diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller/StreamingV2Controller.java b/server-base/src/main/java/org/apache/kylin/rest/controller/StreamingV2Controller.java index 2843cac..935d273 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/controller/StreamingV2Controller.java +++ b/server-base/src/main/java/org/apache/kylin/rest/controller/StreamingV2Controller.java @@ -52,8 +52,8 @@ import org.apache.kylin.rest.service.CubeService; import org.apache.kylin.rest.service.StreamingV2Service; import org.apache.kylin.rest.service.TableService; import org.apache.kylin.stream.core.model.CubeAssignment; -import org.apache.kylin.stream.core.model.ReplicaSet; import org.apache.kylin.stream.core.model.Node; +import org.apache.kylin.stream.core.model.ReplicaSet; import org.apache.kylin.stream.core.model.stats.ClusterState; import org.apache.kylin.stream.core.model.stats.CubeRealTimeState; import org.apache.kylin.stream.core.model.stats.ReceiverStats; @@ -78,10 +78,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.common.base.Preconditions; /** * StreamingController is defined as Restful API entrance for UI. @@ -136,6 +136,8 @@ public class StreamingV2Controller extends BasicController { boolean saveStreamingSuccess = false, saveTableSuccess = false; KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv(); ProjectInstance projectInstance = ProjectManager.getInstance(kylinConfig).getProject(project); + + InternalErrorException shouldThrow = null; try { try { tableDesc.setUuid(UUID.randomUUID().toString()); @@ -160,22 +162,27 @@ public class StreamingV2Controller extends BasicController { try { tableService.unloadHiveTable(tableDesc.getIdentity(), project); } catch (IOException e) { - throw new InternalErrorException("Action failed and failed to rollback the create table " - + e.getLocalizedMessage(), e); + shouldThrow = new InternalErrorException( + "Action failed and failed to rollback the create table " + e.getLocalizedMessage(), e); } } if (saveStreamingSuccess) { try { streamingService.dropStreamingConfig(streamingSourceConfig); } catch (IOException e) { - throw new InternalErrorException( + shouldThrow = new InternalErrorException( "Action failed and failed to rollback the created streaming config: " - + e.getLocalizedMessage(), e); + + e.getLocalizedMessage(), + e); } } } + } + if (null != shouldThrow) { + throw shouldThrow; } + streamingRequest.setSuccessful(true); return streamingRequest; } @@ -197,8 +204,9 @@ public class StreamingV2Controller extends BasicController { } catch (NoSuchObjectException noObjectException) { logger.info("table not exist in hive meta store for table:" + tableDesc.getIdentity(), noObjectException); - throw new BadRequestException("table doesn't exist in hive meta store for table:" - + tableDesc.getIdentity(), ResponseCode.CODE_UNDEFINED, noObjectException); + throw new BadRequestException( + "table doesn't exist in hive meta store for table:" + tableDesc.getIdentity(), + ResponseCode.CODE_UNDEFINED, noObjectException); } catch (Exception e) { logger.error("error when get metadata from hive meta store for table:" + tableDesc.getIdentity(), e); throw new BadRequestException("error when connect hive meta store", ResponseCode.CODE_UNDEFINED, e); @@ -230,7 +238,8 @@ public class StreamingV2Controller extends BasicController { } if (!incompatibleMsgs.isEmpty()) { logger.info("incompatible for hive and input table schema:{}", incompatibleMsgs); - throw new BadRequestException("incompatible for hive schema and input table schema:" + incompatibleMsgs); + throw new BadRequestException( + "incompatible for hive schema and input table schema:" + incompatibleMsgs); } } } @@ -299,8 +308,8 @@ public class StreamingV2Controller extends BasicController { streamingService.dropStreamingConfig(config); } catch (Exception e) { logger.error(e.getLocalizedMessage(), e); - throw new InternalErrorException("Failed to delete StreamingSourceConfig. " + " Caused by: " - + e.getMessage(), e); + throw new InternalErrorException( + "Failed to delete StreamingSourceConfig. " + " Caused by: " + e.getMessage(), e); } } diff --git a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/coprocessor/endpoint/CubeVisitService.java b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/coprocessor/endpoint/CubeVisitService.java index fd54e2b..f0a8eb9 100644 --- a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/coprocessor/endpoint/CubeVisitService.java +++ b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/coprocessor/endpoint/CubeVisitService.java @@ -150,8 +150,8 @@ public class CubeVisitService extends CubeVisitProtos.CubeVisitService implement private long rowCount; private long rowBytes; - ResourceTrackingCellListIterator(Iterator<List<Cell>> delegate, - long rowCountLimit, long bytesLimit, long deadline) { + ResourceTrackingCellListIterator(Iterator<List<Cell>> delegate, long rowCountLimit, long bytesLimit, + long deadline) { this.delegate = delegate; this.rowCountLimit = rowCountLimit; this.bytesLimit = bytesLimit; @@ -242,12 +242,14 @@ public class CubeVisitService extends CubeVisitProtos.CubeVisitService implement // if user change kylin.properties on kylin server, need to manually redeploy coprocessor jar to update KylinConfig of Env. KylinConfig kylinConfig = KylinConfig.createKylinConfig(request.getKylinProperties()); - + String queryId = request.hasQueryId() ? request.getQueryId() : "UnknownId"; logger.info("start query {} in thread {}", queryId, Thread.currentThread().getName()); + + RuntimeException shouldThrow = null; try (SetAndUnsetThreadLocalConfig autoUnset = KylinConfig.setAndUnsetThreadLocalConfig(kylinConfig); SetThreadName ignored = new SetThreadName("Query %s", queryId)) { - + final long serviceStartTime = System.currentTimeMillis(); region = (HRegion) env.getRegion(); @@ -428,10 +430,14 @@ public class CubeVisitService extends CubeVisitProtos.CubeVisitService implement try { region.closeRegionOperation(); } catch (IOException e) { - throw new RuntimeException(e); + shouldThrow = new RuntimeException(e); } } } + + if (null != shouldThrow) { + throw shouldThrow; + } } @Override
