/*
 * Copyright (c) 2008-2016, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hazelcast.simulator.coordinator.tasks;

import com.hazelcast.simulator.utils.BashCommand;
import org.apache.log4j.Logger;

import java.io.File;
import java.util.List;
import java.util.Map;

import static com.hazelcast.simulator.utils.FileUtils.getConfigurationFile;
import static com.hazelcast.simulator.utils.FormatUtils.join;

/**
 * Downloads and post-processes the artifacts from either local or remote machine
 *
 * The real work is done by the 'download.sh' script.
 */
public class DownloadTask {
    private static final Logger LOGGER = Logger.getLogger(DownloadTask.class);

    private final List<String> agents;
    private final Map<String, String> simulatorProperties;
    private final File rootDir;
    private final String sessionId;

    public DownloadTask(List<String> agents,
                        Map<String, String> simulatorProperties,
                        File rootDir,
                        String sessionId) {
        this.agents = agents;
        this.simulatorProperties = simulatorProperties;
        this.rootDir = rootDir;
        this.sessionId = sessionId;
    }

    public void run() {
        LOGGER.info("Downloading sessions [" + sessionId + "]");

        String installFile = getConfigurationFile("download.sh").getAbsolutePath();
        String agentIps = join(agents, ",");
        new BashCommand(installFile)
                .ensureJavaOnPath()
                .addEnvironment(simulatorProperties)
                .addParams(rootDir.getAbsolutePath(), sessionId, agentIps)
                .execute();

        LOGGER.info("Downloading complete!");
    }
}

@@ -1950,24 +1950,327 @@
 ents, %22,%22);%0A
+        // setThrowsException(true), which causes to throw and exception rather than%0A        // calling System.exit(), is set on purpose. DownloadTask is run in the shutdown hook mechanism.%0A        // If an error occurs during DownloadTask in the shutdown process, without %22true%22 it yields to deadlock.%0A
         new 
@@ -2458,16 +2458,58 @@
 entIps)%0A
+                .setThrowsException(true)%0A
         

Fix deadlock when error occurs in DownloadTask during shutdown