Package com.dtolabs.rundeck.core.execution

Examples of com.dtolabs.rundeck.core.execution.ExecutionService


    )
        throws NodeStepException
    {

        final ScriptFileCommand script = (ScriptFileCommand) item;
        final ExecutionService executionService = framework.getExecutionService();
        final String filename;

        if (null != script.getScript()) {
            filename = "dispatch-script.tmp";
        } else if (null != script.getServerScriptFilePath()) {
            filename = new File(script.getServerScriptFilePath()).getName();
        } else {
            filename = "dispatch-script.tmp";
        }
        String filepath = BaseFileCopier.generateRemoteFilepathForNode(
                node,
                filename,
                script.getFileExtension()
        );
        final File temp;
        try {
            if (null != script.getScript()) {
                //expand tokens in the script
                temp = BaseFileCopier.writeScriptTempFile(
                        context,
                        null,
                        null,
                        script.getScript(),
                        node
                );
            } else if (null != script.getServerScriptFilePath()) {
                //DON'T expand tokens in the script
                //TODO: make token expansion optional for local file sources
                temp = new File(script.getServerScriptFilePath());
            } else {
                //expand tokens in the script
                temp = BaseFileCopier.writeScriptTempFile(
                        context,
                        null,
                        script.getScriptAsStream(),
                        null,
                        node
                );
            }
            filepath = executionService.fileCopyFile(
                    context,
                    temp,
                    node,
                    filepath
            );
View Full Code Here


                                                                                                         NodeStepException {
        if (!cacheDir.isDirectory() && !cacheDir.mkdirs()) {
            throw new RuntimeException("Unable to create cachedir: " + cacheDir.getAbsolutePath());
        }
        final ScriptURLCommandExecutionItem script = (ScriptURLCommandExecutionItem) item;
        final ExecutionService executionService = framework.getExecutionService();
        //create node context for node and substitute data references in command
        final Map<String, Map<String, String>> nodeDataContext =
            DataContextUtils.addContext("node", DataContextUtils.nodeData(node), context.getDataContext());

        final String finalUrl = expandUrlString(script.getURLString(), nodeDataContext);
        final URL url;
        try {
            url = new URL(finalUrl);
        } catch (MalformedURLException e) {
            throw new NodeStepException(e, StepFailureReason.ConfigurationFailure, node.getNodename());
        }
        if(null!=context.getExecutionListener()){
            context.getExecutionListener().log(4, "Requesting URL: " + url.toExternalForm());
        }

        String cleanUrl = url.toExternalForm().replaceAll("^(https?://)([^:@/]+):[^@/]*@", "$1$2:****@");
        String tempFileName = hashURL(url.toExternalForm()) + ".temp";
        File destinationTempFile = new File(cacheDir, tempFileName);
        File destinationCacheData = new File(cacheDir, tempFileName + ".cache.properties");

        //update from URL if necessary
        final URLFileUpdaterBuilder urlFileUpdaterBuilder = new URLFileUpdaterBuilder()
            .setUrl(url)
            .setAcceptHeader("*/*")
            .setTimeout(DEFAULT_TIMEOUT);
        if (USE_CACHE) {
            urlFileUpdaterBuilder
                .setCacheMetadataFile(destinationCacheData)
                .setCachedContent(destinationTempFile)
                .setUseCaching(true);
        }
        final URLFileUpdater updater = urlFileUpdaterBuilder.createURLFileUpdater();
        try {
            if (null != interaction) {
            //allow mock
                updater.setInteraction(interaction);
            }
            UpdateUtils.update(updater, destinationTempFile);

            logger.debug("Updated nodes resources file: " + destinationTempFile);
        } catch (UpdateUtils.UpdateException e) {
            if (!destinationTempFile.isFile() || destinationTempFile.length() < 1) {
                throw new NodeStepException(
                    "Error requesting URL Script: " + cleanUrl + ": " + e.getMessage(),
                    e,
                    Reason.URLDownloadFailure,
                    node.getNodename());
            } else {
                logger.error(
                    "Error requesting URL script: " + cleanUrl + ": " + e.getMessage(), e);
            }
        }

        final String filepath; //result file path
        try {
            filepath = executionService.fileCopyFile(context, destinationTempFile, node);
        } catch (FileCopierException e) {
            throw new NodeStepException(e.getMessage(), e, StepFailureReason.IOFailure, node.getNodename());
        }

        /**
 
View Full Code Here

    static NodeStepResult executeRemoteScript(final StepExecutionContext context,
                                              final INodeEntry node,
                                              final GeneratedScript script)
        throws NodeStepException {
        final ExecutionService executionService = context.getFramework().getExecutionService();
        if (null != script.getCommand()) {
            //execute the command
            return executionService.executeCommand(context, script.getCommand(), node);
        } else if (null != script.getScript()) {
            final String filepath; //result file path
            try {
                filepath = executionService.fileCopyScriptContent(context, script.getScript(), node);
            } catch (FileCopierException e) {
                throw new NodeStepException(e.getMessage(), e, e.getFailureReason(), node.getNodename());
            }
            return ScriptFileNodeStepExecutor.executeRemoteScript(context,
                                                                  context.getFramework(),
                                                                  node,
                                                                  script.getArgs(),
                                                                  filepath);
        } else if (script instanceof FileBasedGeneratedScript) {
            final FileBasedGeneratedScript fileScript = (FileBasedGeneratedScript) script;
            final String filepath; //result file path
            try {
                filepath = executionService.fileCopyFile(context, fileScript.getScriptFile(), node);
            } catch (FileCopierException e) {
                throw new NodeStepException(e.getMessage(), e, e.getFailureReason(), node.getNodename());
            }
            return ScriptFileNodeStepExecutor.executeRemoteScript(context,
                                                                  context.getFramework(),
View Full Code Here

TOP

Related Classes of com.dtolabs.rundeck.core.execution.ExecutionService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.