Package com.dtolabs.rundeck.core.execution.workflow.steps.node

Examples of com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException


    @Override
    public void executeNodeStep(PluginStepContext context, Map<String, Object> map, INodeEntry entry)
        throws NodeStepException {
        if(null==command || "".equals(command.trim())) {
            throw new NodeStepException("Command is not set",
                                        StepFailureReason.ConfigurationFailure,
                                        entry.getNodename());
        }
        String[] split = OptsUtil.burst(command);
        Map<String, Map<String, String>> nodeData = DataContextUtils.addContext("node",
                                                                                DataContextUtils.nodeData(entry),
                                                                                context.getDataContext());

        final String[] finalCommand = DataContextUtils.replaceDataReferences(split, nodeData);
        StringBuilder preview=new StringBuilder();

        for (int i = 0; i < finalCommand.length; i++) {
            preview.append("'").append(finalCommand[i]).append("'");
        }
        context.getLogger().log(5, "LocalExecNodeStepPlugin, running command ("+split.length+"): " + preview.toString());
        Map<String, String> env = DataContextUtils.generateEnvVarsFromContext(nodeData);
        final int result;
        try {
            result = ScriptExecUtil.runLocalCommand(finalCommand, env, null, System.out, System.err);
            if(result!=0) {
                throw new NodeStepException("Result code was " + result,
                                            NodeStepFailureReason.NonZeroResultCode,
                                            entry.getNodename());
            }
        } catch (IOException e) {
            throw new NodeStepException(e, StepFailureReason.IOFailure, entry.getNodename());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new NodeStepException(e, StepFailureReason.Interrupted, entry.getNodename());
        }
    }
View Full Code Here


                                                                                                     NodeStepException {
            executionItemList.add(executionItem);
            executionContextList.add(executionContext);
            nodeEntryList.add(iNodeEntry);
            if (shouldThrowException) {
                throw new NodeStepException("testInterpreter test exception", null,iNodeEntry.getNodename());
            }
            return resultList.get(index++);
        }
View Full Code Here

                    temp,
                    node,
                    filepath
            );
        } catch (FileCopierException e) {
            throw new NodeStepException(
                    e.getMessage(),
                    e,
                    e.getFailureReason(),
                    node.getNodename()
            );
View Full Code Here

        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());
        }

        /**
         * TODO: Avoid this horrific hack. Discover how to get SCP task to preserve the execute bit.
         */
 
View Full Code Here

        final List<INodeEntry> nodes1 = INodeEntryComparator.rankOrderedNodes(nodes, context
                .getNodeRankAttribute(),
                context.isNodeRankOrderAscending());
        //reorder based on configured rank property and order

        NodeStepException caught = null;
        INodeEntry failedNode = null;
        for (final INodeEntry node : nodes1) {
            if (thread.isInterrupted()
                || thread instanceof ServiceThreadBase && ((ServiceThreadBase) thread).isAborted()) {
                interrupted = true;
                break;
            }
            context.getExecutionListener().log(Constants.DEBUG_LEVEL,
                                               "Executing command on node: " + node.getNodename() + ", "
                                               + node.toString());
            try {

                if (thread.isInterrupted()
                    || thread instanceof ServiceThreadBase && ((ServiceThreadBase) thread).isAborted()) {
                    interrupted = true;
                    break;
                }
                final NodeStepResult result;

                //execute the step or dispatchable
                if (null != item) {
                    result = framework.getExecutionService().executeNodeStep(context, item, node);
                } else {
                    result = toDispatch.dispatch(context, node);

                }
                resultMap.put(node.getNodename(), result);
                if (!result.isSuccess()) {
                    success = false;
//                    context.getExecutionListener().log(Constants.ERR_LEVEL,
//                        "Failed execution for node " + node.getNodename() + ": " + result);
                    failures.put(node.getNodename(), result);
                    if (!keepgoing) {
                        failedNode = node;
                        break;
                    }
                } else {
                    nodeNames.remove(node.getNodename());
                }
            } catch (NodeStepException e) {
                success = false;
                failures.put(node.getNodename(),
                             new NodeStepResultImpl(e, e.getFailureReason(), e.getMessage(), node)
                );
                context.getExecutionListener().log(Constants.ERR_LEVEL,
                                                   "Failed dispatching to node " + node.getNodename() + ": "
                                                   + e.getMessage());

                final StringWriter stringWriter = new StringWriter();
                e.printStackTrace(new PrintWriter(stringWriter));
                context.getExecutionListener().log(Constants.DEBUG_LEVEL,
                                                   "Failed dispatching to node " + node.getNodename() + ": "
                                                   + stringWriter.toString());

                if (!keepgoing) {
                    failedNode = node;
                    caught = e;
                    break;
                }
            }
        }
        if (!keepgoing && failures.size() > 0 && null != failedListener) {
            //tell listener of failed node list
            failedListener.nodesFailed(failures);
        }
        if (!keepgoing && null != caught) {
            throw new DispatcherException(
                "Failed dispatching to node " + failedNode.getNodename() + ": " + caught.getMessage(), caught,
                failedNode);
        }
        if (keepgoing && nodeNames.size() > 0) {
            if (null != failedListener) {
                //tell listener of failed node list
View Full Code Here

                                                                                                     NodeStepException {
            executionItemList.add(executionItem);
            executionContextList.add(executionContext);
            nodeEntryList.add(iNodeEntry);
            if (shouldThrowException) {
                throw new NodeStepException("testInterpreter test exception",null,iNodeEntry.getNodename());
            }
            System.out.println("return index: (" + index + ") in size: " + resultList.size());
            return resultList.get(index++);
        }
View Full Code Here

            DispatcherException exception
                    = NodeDispatchStepExecutor.extractDispatcherException(dispatcherStepResult);
            HashMap<String, NodeStepResult> stringNodeStepResultHashMap = new HashMap<String,
                    NodeStepResult>();
            resultMap = stringNodeStepResultHashMap;
            NodeStepException nodeStepException = exception.getNodeStepException();
            if (null != nodeStepException && null != exception.getNode()) {
                NodeStepResult nodeExecutorResult = nodeStepResultFromNodeStepException(
                        exception.getNode(),
                        nodeStepException
                );
                stringNodeStepResultHashMap.put(
                        nodeStepException.getNodeName(),
                        nodeExecutorResult
                );
            }
        } else {
            return handlerExecContext;
View Full Code Here

                    //dispatch failed for a specific node
                    final String key = node.getNodename();
                    if (!failures.containsKey(key)) {
                        failures.put(key, new ArrayList<StepExecutionResult>());
                    }
                    NodeStepException nodeStepException = e.getNodeStepException();
                    if (null != nodeStepException) {
                        failures.get(key).add(
                                nodeStepResultFromNodeStepException(node, nodeStepException)
                        );
                    }
View Full Code Here

                        results.add(stepResult);
                    }
                }else if (NodeDispatchStepExecutor.isWrappedDispatcherException(executionResult)) {
                    DispatcherException exception
                        = NodeDispatchStepExecutor.extractDispatcherException(executionResult);
                    NodeStepException nodeStepException = exception.getNodeStepException();
                    if (null != nodeStepException) {
                        results.add(nodeStepResultFromNodeStepException(node, nodeStepException));
                    }
                }
            }
View Full Code Here

                        results.put(num, stepResult);
                    }
                } else if (NodeDispatchStepExecutor.isWrappedDispatcherException(executionResult)) {
                    DispatcherException exception
                        = NodeDispatchStepExecutor.extractDispatcherException(executionResult);
                    NodeStepException nodeStepException = exception.getNodeStepException();
                    if (null != nodeStepException) {
                        results.put(
                                num,
                                nodeStepResultFromNodeStepException(node, nodeStepException)
                        );
View Full Code Here

TOP

Related Classes of com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException

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.