Package com.dtolabs.rundeck.core.common

Examples of com.dtolabs.rundeck.core.common.NodesSelector


                         result.getException().getMessage());
        }

        {
            //test script exec item
            final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
            final ArrayList<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();
            final StepExecutionItem testWorkflowCmdItem = new ScriptFileCommandBase(){
                @Override
                public String getScript() {
                    return "a command";
                }
            };
            commands.add(testWorkflowCmdItem);
            final WorkflowImpl workflow = new WorkflowImpl(commands, 1, false,
                WorkflowStrategy.STEP_FIRST);
            final WorkflowExecutionItemImpl executionItem = new WorkflowExecutionItemImpl(workflow);
            final StepFirstWorkflowStrategy strategy = new StepFirstWorkflowStrategy(testFramework);
            final StepExecutionContext context =
                new ExecutionContextImpl.Builder()
                    .frameworkProject(TEST_PROJECT)
                    .user("user1")
                    .nodeSelector(nodeset)
                    .executionListener(new testListener())
                    .framework(testFramework)
                    .nodes(testFramework.filterNodeSet(nodeset, TEST_PROJECT, null))
                    .build();

            //setup testInterpreter for all command types
            final NodeStepExecutionService interpreterService = NodeStepExecutionService.getInstanceForFramework(
                testFramework);
            testInterpreter interpreterMock = new testInterpreter();
            testInterpreter failMock = new testInterpreter();
            failMock.shouldThrowException = true;
            interpreterService.registerInstance("exec", failMock);
            interpreterService.registerInstance("script", interpreterMock);
            interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_NODE_FIRST, failMock);
            interpreterService.registerInstance(WorkflowExecutionItem.COMMAND_TYPE_STEP_FIRST, failMock);
//            interpreterService.registerInstance(JobExecutionItem.COMMAND_TYPE, failMock);

            //set resturn result
            interpreterMock.resultList.add(new NodeStepResultImpl(null));

            final WorkflowExecutionResult result = strategy.executeWorkflow(context, executionItem);

            assertNotNull(result);
            if (!result.isSuccess() && null != result.getException()) {
                result.getException().printStackTrace(System.err);
            }
            assertNull("threw exception: " + result.getException(), result.getException());
            assertTrue(result.isSuccess());
            assertEquals(1, interpreterMock.executionItemList.size());
            final StepExecutionItem executionItem1 = interpreterMock.executionItemList.get(0);
            assertTrue("wrong class: " + executionItem1.getClass().getName(),
                executionItem1 instanceof ScriptFileCommandExecutionItem);
            ScriptFileCommandExecutionItem scriptItem = (ScriptFileCommandExecutionItem) executionItem1;
            assertEquals("a command", scriptItem.getScript());
            assertNull(scriptItem.getScriptAsStream());
            assertNull(scriptItem.getServerScriptFilePath());
            assertEquals(1, interpreterMock.executionContextList.size());
            final ExecutionContext executionContext = interpreterMock.executionContextList.get(0);
            assertEquals(TEST_PROJECT, executionContext.getFrameworkProject());

            assertNotNull(executionContext.getDataContext());
            assertNotNull(executionContext.getDataContext().get("node"));
            assertEquals(0, executionContext.getLoglevel());
            assertEquals("user1", executionContext.getUser());
            assertEquals("expected " + nodeset + ", but was " + executionContext.getNodeSelector(), nodeset,
                executionContext.getNodeSelector());
        }
        {
            //test command exec item
            final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
            final ArrayList<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();
            final StepExecutionItem testWorkflowCmdItem = new ExecCommandBase() {
                @Override
                public String[] getCommand() {
                    return new String[]{"a", "command"};
View Full Code Here


        }
    }
    public void testExecuteWorkflowThreeItems() throws Exception{
        {
            //test workflow of three successful items
            final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
            final ArrayList<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();

            final StepExecutionItem testWorkflowCmdItem = new ExecCommandBase() {
                @Override
                public String[] getCommand() {
View Full Code Here

        }
    }
    public void testWorkflowFailNoKeepgoing() throws Exception{
        {
            //test a workflow with a failing item (1), with keepgoing=false
            final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
            final ArrayList<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();

            final StepExecutionItem testWorkflowCmdItem = new ExecCommandBase() {
                @Override
                public String[] getCommand() {
View Full Code Here

        }
    }
    public void testWorkflowFailYesKeepgoing() throws Exception{
        {
            //test a workflow with a failing item (1), with keepgoing=true
            final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
            final ArrayList<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();

            final StepExecutionItem testWorkflowCmdItem = new ExecCommandBase() {
                @Override
                public String[] getCommand() {
View Full Code Here

            //test a workflow with a failing item (1), with keepgoing=false, and a failureHandler
            final boolean KEEPGOING_TEST = false;
            final boolean STEP_0_RESULT = false;
            final boolean STEP_1_RESULT = true;
            final boolean HANDLER_RESULT = true;
            final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
            final ArrayList<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();

            final StepExecutionItem testHandlerItem = new ScriptFileCommandBase() {
                @Override
                public String getScript() {
View Full Code Here

            //test a workflow with a failing item (1), with keepgoing=true, and a failureHandler that fails
            final boolean KEEPGOING_TEST = true;
            final boolean STEP_0_RESULT = false;
            final boolean STEP_1_RESULT = true;
            final boolean HANDLER_RESULT = false;
            final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
            final ArrayList<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();

            final StepExecutionItem testHandlerItem = new ScriptFileCommandBase() {
                @Override
                public String getScript() {
View Full Code Here

            //test a workflow with a failing item (1), with keepgoing=true, and a failureHandler that succeeds
            final boolean KEEPGOING_TEST = true;
            final boolean STEP_0_RESULT = false;
            final boolean STEP_1_RESULT = true;
            final boolean HANDLER_RESULT = true;
            final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
            final ArrayList<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();

            final StepExecutionItem testHandlerItem = new ScriptFileCommandBase() {
                @Override
                public String getScript() {
View Full Code Here

    }
    public void testGenericItem() throws Exception{

        {
            //test jobref item
            final NodesSelector nodeset = SelectorUtils.singleNode(testFramework.getFrameworkNodeName());
            final ArrayList<StepExecutionItem> commands = new ArrayList<StepExecutionItem>();
            final testWorkflowCmdItem item = new testWorkflowCmdItem();
            item.type = "my-type";
            commands.add(item);
            final WorkflowImpl workflow = new WorkflowImpl(commands, 1, false,
View Full Code Here

    /**
     * Return a new Node Selector that will apply the include/exclude filters if they are set, otherwise
     * it only includes the node with the given nodename
     */
    public NodesSelector nodeSelectorWithDefault(final String nodename) {
        final NodesSelector nodesSelector = SelectorUtils.singleNode(nodename);
        return new NodesSelector() {
            public boolean acceptNode(final INodeEntry entry) {
                return !isBlank() ? NodeSet.this.acceptNode(entry) : nodesSelector.acceptNode(entry);
            }
        };
    }
View Full Code Here

    /**
     * Return a new Node Selector that will apply the include/exclude filters if they are set, otherwise
     * it will accept all nodes
     */
    public NodesSelector nodeSelectorWithDefaultAll() {
        return new NodesSelector() {
            public boolean acceptNode(final INodeEntry entry) {
                return isBlank() || NodeSet.this.acceptNode(entry);
            }
        };
    }
View Full Code Here

TOP

Related Classes of com.dtolabs.rundeck.core.common.NodesSelector

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.