arina-ielchiieva commented on a change in pull request #1345: DRILL-6494: Drill Plugins Handler URL: https://github.com/apache/drill/pull/1345#discussion_r199801281
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/ActionOnFile.java ########## @@ -0,0 +1,68 @@ +package org.apache.drill.exec.store; + +import org.apache.drill.common.config.CommonConstants; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * The action on the {@link CommonConstants#STORAGE_PLUGINS_OVERRIDE_CONF} file being performed after it's use + */ +public enum ActionOnFile { + + NONE { + @Override + void action(URL url) { + // nothing to do + } + }, + RENAME { + @Override + void action(URL url) { + File pluginsOverrideFile = new File(url.getPath()); + String oldName = CommonConstants.STORAGE_PLUGINS_OVERRIDE_CONF; + String currentDateTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); + String newFileName = new StringBuilder(oldName) + .insert(oldName.lastIndexOf("."), "-" + currentDateTime) + .toString(); + Path pluginsOverrideFilePath = pluginsOverrideFile.toPath(); + try { + Files.move(pluginsOverrideFilePath, pluginsOverrideFilePath.resolveSibling(newFileName)); + } catch (IOException e) { + logger.error("%s file is not renamed after it's use", CommonConstants.STORAGE_PLUGINS_OVERRIDE_CONF, e); + } + } + }, + REMOVE { + @Override + void action(URL url) { + File pluginsOverrideFile = new File(url.getPath()); + try { + Files.delete(pluginsOverrideFile.toPath()); + } catch (IOException e) { + logger.error("%s file is not deleted after it's use", CommonConstants.STORAGE_PLUGINS_OVERRIDE_CONF, e); + } + } + }; + + private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ActionOnFile.class); + + /** + * This is an action which should be performed on the + * {@link org.apache.drill.common.config.CommonConstants#STORAGE_PLUGINS_OVERRIDE_CONF} after successful updating of + * storage plugins configs with Storage Plugins Handler. + * <ul> + * <li>{@link #NONE}: no action will be performed Review comment: Consider adding java doc above each enum element. Rather than here. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services