// Path: hadoop-mini-clusters-common/src/main/java/com/github/sakserv/minicluster/util/FileUtils.java
// public final class FileUtils {
// 
//     // Logger
//     private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(FileUtils.class);
// 
//     public static void deleteFolder(String directory, boolean quietly) {
//         try {
//             Path directoryPath = Paths.get(directory).toAbsolutePath();
//             if (!quietly) {
//                 LOG.info("FILEUTILS: Deleting contents of directory: {}",
//                         directoryPath.toAbsolutePath().toString());
//             }
//             Files.walkFileTree(directoryPath, new SimpleFileVisitor<Path>() {
//                 @Override
//                 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
//                         throws IOException {
//                     Files.delete(file);
//                     if (!quietly) {
//                         LOG.info("Removing file: {}", file.toAbsolutePath().toString());
//                     }
//                     return FileVisitResult.CONTINUE;
//                 }
// 
//                 @Override
//                 public FileVisitResult postVisitDirectory(Path dir, IOException exc)
//                         throws IOException {
//                     Files.delete(dir);
//                     if (!quietly) {
//                         LOG.info("Removing directory: {}", dir.toAbsolutePath().toString());
//                     }
//                     return FileVisitResult.CONTINUE;
//                 }
//             });
//         } catch (IOException e) {
//             LOG.error("FILEUTILS: Unable to remove {}", directory);
//         }
//     }
// 
//     public static void deleteFolder(String directory) {
//         deleteFolder(directory, false);
//     }
// 
//     @Override
//     public String toString() {
//         return "FileUtils";
//     }
// }


import com.github.sakserv.minicluster.util.FileUtils;
import org.apache.storm.ILocalCluster;
import org.apache.storm.Testing;
import org.apache.storm.generated.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.sakserv.minicluster.MiniCluster;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

    @Override
    public void stop(boolean cleanUp) throws Exception {
        LOG.info("STORM: Stopping StormLocalCluster");
        localCluster.shutdown();
        if(cleanUp) {
            cleanUp();
        }
    }

    @Override
    public void configure() throws Exception {
        stormConf.setDebug(enableDebug);
        stormConf.setNumWorkers(numWorkers);
        stormConf.put("nimbus-daemon", true);
        List<String> stormNimbusSeeds = new ArrayList<>();
        stormNimbusSeeds.add("localhost");
        stormConf.put(Config.NIMBUS_SEEDS, stormNimbusSeeds);
        stormConf.put(Config.NIMBUS_THRIFT_PORT, 6627);
        stormConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN, "org.apache.storm.security.auth.SimpleTransportPlugin");
        stormConf.put(Config.STORM_NIMBUS_RETRY_INTERVAL_CEILING, 60000);
        stormConf.put(Config.STORM_NIMBUS_RETRY_TIMES, 5);
        stormConf.put(Config.STORM_NIMBUS_RETRY_INTERVAL, 2000);
        stormConf.put(Config.NIMBUS_THRIFT_MAX_BUFFER_SIZE, 1048576);
        stormConf.put(Config.STORM_ZOOKEEPER_SERVERS, Arrays.asList(getZookeeperHost()));
        stormConf.put(Config.STORM_ZOOKEEPER_PORT, getZookeeperPort());
    }

    @Override
    public void cleanUp() throws Exception {
// Path: hadoop-mini-clusters-common/src/main/java/com/github/sakserv/minicluster/util/FileUtils.java
// public final class FileUtils {
// 
//     // Logger
//     private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(FileUtils.class);
// 
//     public static void deleteFolder(String directory, boolean quietly) {
//         try {
//             Path directoryPath = Paths.get(directory).toAbsolutePath();
//             if (!quietly) {
//                 LOG.info("FILEUTILS: Deleting contents of directory: {}",
//                         directoryPath.toAbsolutePath().toString());
//             }
//             Files.walkFileTree(directoryPath, new SimpleFileVisitor<Path>() {
//                 @Override
//                 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
//                         throws IOException {
//                     Files.delete(file);
//                     if (!quietly) {
//                         LOG.info("Removing file: {}", file.toAbsolutePath().toString());
//                     }
//                     return FileVisitResult.CONTINUE;
//                 }
// 
//                 @Override
//                 public FileVisitResult postVisitDirectory(Path dir, IOException exc)
//                         throws IOException {
//                     Files.delete(dir);
//                     if (!quietly) {
//                         LOG.info("Removing directory: {}", dir.toAbsolutePath().toString());
//                     }
//                     return FileVisitResult.CONTINUE;
//                 }
//             });
//         } catch (IOException e) {
//             LOG.error("FILEUTILS: Unable to remove {}", directory);
//         }
//     }
// 
//     public static void deleteFolder(String directory) {
//         deleteFolder(directory, false);
//     }
// 
//     @Override
//     public String toString() {
//         return "FileUtils";
//     }
// }


// Path: hadoop-mini-clusters-storm/src/main/java/com/github/sakserv/minicluster/impl/StormLocalCluster.java
import com.github.sakserv.minicluster.util.FileUtils;
import org.apache.storm.ILocalCluster;
import org.apache.storm.Testing;
import org.apache.storm.generated.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.sakserv.minicluster.MiniCluster;
import org.apache.storm.Config;
import org.apache.storm.LocalCluster;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;


    @Override
    public void stop(boolean cleanUp) throws Exception {
        LOG.info("STORM: Stopping StormLocalCluster");
        localCluster.shutdown();
        if(cleanUp) {
            cleanUp();
        }
    }

    @Override
    public void configure() throws Exception {
        stormConf.setDebug(enableDebug);
        stormConf.setNumWorkers(numWorkers);
        stormConf.put("nimbus-daemon", true);
        List<String> stormNimbusSeeds = new ArrayList<>();
        stormNimbusSeeds.add("localhost");
        stormConf.put(Config.NIMBUS_SEEDS, stormNimbusSeeds);
        stormConf.put(Config.NIMBUS_THRIFT_PORT, 6627);
        stormConf.put(Config.STORM_THRIFT_TRANSPORT_PLUGIN, "org.apache.storm.security.auth.SimpleTransportPlugin");
        stormConf.put(Config.STORM_NIMBUS_RETRY_INTERVAL_CEILING, 60000);
        stormConf.put(Config.STORM_NIMBUS_RETRY_TIMES, 5);
        stormConf.put(Config.STORM_NIMBUS_RETRY_INTERVAL, 2000);
        stormConf.put(Config.NIMBUS_THRIFT_MAX_BUFFER_SIZE, 1048576);
        stormConf.put(Config.STORM_ZOOKEEPER_SERVERS, Arrays.asList(getZookeeperHost()));
        stormConf.put(Config.STORM_ZOOKEEPER_PORT, getZookeeperPort());
    }

    @Override
    public void cleanUp() throws Exception {
      FileUtils.deleteFolder("logs");