sajjad-moradi commented on a change in pull request #5617: URL: https://github.com/apache/incubator-pinot/pull/5617#discussion_r447344931
########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java ########## @@ -303,46 +335,37 @@ private String getZkDownloadURIForSegmentUpload(String rawTableName, String segm } } - private SegmentMetadata getMetadataForURI(String crypterClassHeader, String currentSegmentLocationURI, - File tempEncryptedFile, File tempDecryptedFile, File tempSegmentDir, String metadataProviderClass) + private void getSegmentFileFromURI(String currentSegmentLocationURI, File destFile) Review comment: Makes sense 👍 Refactored. ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java ########## @@ -303,46 +335,37 @@ private String getZkDownloadURIForSegmentUpload(String rawTableName, String segm } } - private SegmentMetadata getMetadataForURI(String crypterClassHeader, String currentSegmentLocationURI, - File tempEncryptedFile, File tempDecryptedFile, File tempSegmentDir, String metadataProviderClass) + private void getSegmentFileFromURI(String currentSegmentLocationURI, File destFile) throws Exception { - SegmentMetadata segmentMetadata; if (currentSegmentLocationURI == null || currentSegmentLocationURI.isEmpty()) { throw new ControllerApplicationException(LOGGER, "Failed to get downloadURI, needed for URI upload", Response.Status.BAD_REQUEST); } - LOGGER.info("Downloading segment from {} to {}", currentSegmentLocationURI, tempEncryptedFile.getAbsolutePath()); - SegmentFetcherFactory.fetchSegmentToLocal(currentSegmentLocationURI, tempEncryptedFile); - segmentMetadata = getSegmentMetadata(crypterClassHeader, tempEncryptedFile, tempDecryptedFile, tempSegmentDir, - metadataProviderClass); - return segmentMetadata; + LOGGER.info("Downloading segment from {} to {}", currentSegmentLocationURI, destFile.getAbsolutePath()); + SegmentFetcherFactory.fetchSegmentToLocal(currentSegmentLocationURI, destFile); } - private SegmentMetadata getSegmentMetadata(String crypterClassHeader, File tempEncryptedFile, File tempDecryptedFile, - File tempSegmentDir, String metadataProviderClass) + private SegmentMetadata getSegmentMetadata(File tempDecryptedFile, File tempSegmentDir, String metadataProviderClass) throws Exception { - - decryptFile(crypterClassHeader, tempEncryptedFile, tempDecryptedFile); - // Call metadata provider to extract metadata with file object uri return MetadataExtractorFactory.create(metadataProviderClass).extractMetadata(tempDecryptedFile, tempSegmentDir); } - private void completeZkOperations(boolean enableParallelPushProtection, HttpHeaders headers, File tempEncryptedFile, + private void completeZkOperations(boolean enableParallelPushProtection, HttpHeaders headers, File uploadedSegmentFile, String rawTableName, SegmentMetadata segmentMetadata, String segmentName, String zkDownloadURI, - boolean moveSegmentToFinalLocation) + boolean moveSegmentToFinalLocation, String crypter) throws Exception { URI finalSegmentLocationURI = URIUtils .getUri(ControllerFilePathProvider.getInstance().getDataDirURI().toString(), rawTableName, URIUtils.encode(segmentName)); ZKOperator zkOperator = new ZKOperator(_pinotHelixResourceManager, _controllerConf, _controllerMetrics); - zkOperator.completeSegmentOperations(rawTableName, segmentMetadata, finalSegmentLocationURI, tempEncryptedFile, - enableParallelPushProtection, headers, zkDownloadURI, moveSegmentToFinalLocation); + zkOperator.completeSegmentOperations(rawTableName, segmentMetadata, finalSegmentLocationURI, uploadedSegmentFile, + enableParallelPushProtection, headers, zkDownloadURI, moveSegmentToFinalLocation, crypter); } - private void decryptFile(String crypterClassHeader, File tempEncryptedFile, File tempDecryptedFile) { - PinotCrypter pinotCrypter = PinotCrypterFactory.create(crypterClassHeader); - LOGGER.info("Using crypter class {}", pinotCrypter.getClass().getName()); + private void decryptFile(String crypterClassName, File tempEncryptedFile, File tempDecryptedFile) { + PinotCrypter pinotCrypter = PinotCrypterFactory.create(crypterClassName); + LOGGER.info("Using crypter class {} for decryption.", pinotCrypter.getClass().getName()); Review comment: Done. ########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSegmentUploadDownloadRestletResource.java ########## @@ -290,6 +300,28 @@ private String extractHttpHeader(HttpHeaders headers, String name) { return value; } + private Pair<Boolean, String> encryptSegmentIfNeeded(String offlineTableName, File tempDecryptedFile, File tempEncryptedFile, + boolean uploadedSegmentIsEncrypted) { + + // get crypter class name from table config + String crypterClassName = _pinotHelixResourceManager.getCrypterClassNameFromTableConfig(offlineTableName); + Review comment: Done. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org