-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from rundeck/nodeexec-and-packing
Node-Executor + packaging
- Loading branch information
Showing
9 changed files
with
342 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/main/resources/templates/java-plugin/nodeexecutor/Plugin.java.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.plugin.${javaPluginClass.toLowerCase()}; | ||
|
||
import com.dtolabs.rundeck.core.common.INodeEntry; | ||
import com.dtolabs.rundeck.core.execution.ExecutionContext; | ||
import com.dtolabs.rundeck.core.execution.ExecutionLogger; | ||
import com.dtolabs.rundeck.core.execution.service.NodeExecutor; | ||
import com.dtolabs.rundeck.core.execution.service.NodeExecutorResult; | ||
import com.dtolabs.rundeck.core.execution.service.NodeExecutorResultImpl; | ||
import com.dtolabs.rundeck.core.execution.utils.ResolverUtil; | ||
import com.dtolabs.rundeck.core.execution.workflow.steps.StepFailureReason; | ||
import com.dtolabs.rundeck.core.plugins.Plugin; | ||
import com.dtolabs.rundeck.core.plugins.configuration.Describable; | ||
import com.dtolabs.rundeck.core.plugins.configuration.Description; | ||
import com.dtolabs.rundeck.plugins.ServiceNameConstants; | ||
import com.dtolabs.rundeck.plugins.descriptions.PluginDescription; | ||
import com.dtolabs.rundeck.plugins.util.DescriptionBuilder; | ||
import com.dtolabs.rundeck.plugins.util.PropertyBuilder; | ||
import java.util.Arrays; | ||
|
||
@Plugin(service=ServiceNameConstants.NodeExecutor,name="${sanitizedPluginName}") | ||
@PluginDescription(title="${pluginName}", description="My WorkflowStep plugin description") | ||
public class ${javaPluginClass} implements NodeExecutor, Describable{ | ||
|
||
public static final String SERVICE_PROVIDER_NAME = "${sanitizedPluginName}"; | ||
|
||
public static final String PROJ_PROP_PREFIX = "project."; | ||
public static final String FWK_PROP_PREFIX = "framework."; | ||
|
||
public static final String SIMPLE_CONFIG_STRING = "exampleConfig"; | ||
public static final String SIMPLE_CONFIG_BOOLEAN = "forceFail"; | ||
public static final String SIMPLE_CONFIG_SELECT= "exampleSelect"; | ||
|
||
/** | ||
* Overriding this method gives the plugin a chance to take part in building the {@link | ||
* com.dtolabs.rundeck.core.plugins.configuration.Description} presented by this plugin. This subclass can use the | ||
* {@link DescriptionBuilder} to modify all aspects of the description, add or remove properties, etc. | ||
*/ | ||
@Override | ||
public Description getDescription() { | ||
DescriptionBuilder builder = DescriptionBuilder.builder() | ||
.name(SERVICE_PROVIDER_NAME) | ||
.title("${pluginName}") | ||
.description("Example Workflow Step") | ||
.property(PropertyBuilder.builder() | ||
.string(SIMPLE_CONFIG_STRING) | ||
.title("Example String") | ||
.description("Example description") | ||
.required(true) | ||
.build() | ||
) | ||
.property(PropertyBuilder.builder() | ||
.booleanType(SIMPLE_CONFIG_BOOLEAN) | ||
.title("Force Fail") | ||
.description("Example Boolean, Force Fail Command?") | ||
.required(false) | ||
.defaultValue("false") | ||
.build() | ||
) | ||
.property(PropertyBuilder.builder() | ||
.freeSelect(SIMPLE_CONFIG_SELECT) | ||
.title("Example Free Select") | ||
.description("Example Free Select") | ||
.required(false) | ||
.defaultValue("Blue") | ||
.values("Blue", "Beige", "Black") | ||
.build() | ||
); | ||
|
||
//mapping config input on project and framework level | ||
builder.mapping(SIMPLE_CONFIG_STRING, PROJ_PROP_PREFIX + SIMPLE_CONFIG_STRING); | ||
builder.frameworkMapping(SIMPLE_CONFIG_STRING, FWK_PROP_PREFIX + SIMPLE_CONFIG_STRING); | ||
|
||
builder.mapping(SIMPLE_CONFIG_BOOLEAN, PROJ_PROP_PREFIX + SIMPLE_CONFIG_BOOLEAN); | ||
builder.frameworkMapping(SIMPLE_CONFIG_BOOLEAN, FWK_PROP_PREFIX + SIMPLE_CONFIG_BOOLEAN); | ||
|
||
builder.mapping(SIMPLE_CONFIG_SELECT, PROJ_PROP_PREFIX + SIMPLE_CONFIG_SELECT); | ||
builder.frameworkMapping(SIMPLE_CONFIG_SELECT, FWK_PROP_PREFIX + SIMPLE_CONFIG_SELECT); | ||
|
||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public NodeExecutorResult executeCommand(ExecutionContext context, String[] command, INodeEntry node) { | ||
ExecutionLogger logger= context.getExecutionLogger(); | ||
|
||
String exampleValue = ResolverUtil.resolveProperty(SIMPLE_CONFIG_STRING, | ||
null, | ||
node, | ||
context.getFramework().getFrameworkProjectMgr().getFrameworkProject(context.getFrameworkProject()), | ||
context.getFramework()); | ||
|
||
|
||
String exampleFreeSelect = ResolverUtil.resolveProperty(SIMPLE_CONFIG_SELECT, | ||
null, | ||
node, | ||
context.getFramework().getFrameworkProjectMgr().getFrameworkProject(context.getFrameworkProject()), | ||
context.getFramework()); | ||
|
||
Boolean forceFail = ResolverUtil.resolveBooleanProperty(SIMPLE_CONFIG_BOOLEAN, | ||
false, | ||
node, | ||
context.getFramework().getFrameworkProjectMgr().getFrameworkProject(context.getFrameworkProject()), | ||
context.getFramework()); | ||
|
||
logger.log(2,"[demo-info] Running command: " + Arrays.toString(command) + " on node " + node.getNodename()); | ||
logger.log(2,"[demo-info] node attribute hostname: " + node.getAttributes().get("hostname")); | ||
logger.log(2,"[demo-info] node attribute osFamily: " + node.getAttributes().get("osFamily")); | ||
logger.log(2,"[demo-info] Example Value: " + exampleValue); | ||
logger.log(2,"[demo-info] ExampleFree Value: " + exampleFreeSelect); | ||
logger.log(2,"[demo-info] forceFail Value: " + forceFail); | ||
if (forceFail) { | ||
logger.log(0,"[demo-error] force to fail"); | ||
return NodeExecutorResultImpl.createFailure( | ||
StepFailureReason.ConfigurationFailure, | ||
"[demo-error] Error connecting with node '" + node.getNodename() + "'", | ||
node | ||
); | ||
} | ||
|
||
return NodeExecutorResultImpl.createSuccess(node); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
src/main/resources/templates/java-plugin/nodeexecutor/PluginSpec.groovy.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.plugin.${javaPluginClass.toLowerCase()} | ||
|
||
import com.dtolabs.rundeck.plugins.step.PluginStepContext | ||
import com.dtolabs.rundeck.core.execution.ExecutionContext | ||
import com.dtolabs.rundeck.core.execution.ExecutionLogger | ||
import com.dtolabs.rundeck.core.execution.workflow.steps.StepException | ||
import com.dtolabs.rundeck.plugins.PluginLogger | ||
import com.dtolabs.rundeck.core.common.Framework | ||
import com.dtolabs.rundeck.core.common.INodeEntry; | ||
import com.dtolabs.rundeck.core.common.IRundeckProject | ||
import spock.lang.Specification | ||
import com.dtolabs.rundeck.core.common.ProjectManager | ||
import com.dtolabs.rundeck.core.common.IRundeckProject | ||
|
||
class ${javaPluginClass}Spec extends Specification { | ||
|
||
def getContext(ExecutionLogger logger, Boolean fail){ | ||
|
||
def manager = Mock(ProjectManager){ | ||
getFrameworkProject(_)>> Mock(IRundeckProject) { | ||
hasProperty(('project.exampleConfig')) >> true | ||
getProperty(('project.exampleConfig')) >> "123345" | ||
hasProperty(('project.exampleSelect')) >> true | ||
getProperty(('project.exampleSelect')) >> "Blue" | ||
hasProperty(('project.forceFail')) >> fail | ||
getProperty(('project.forceFail')) >> fail | ||
} | ||
} | ||
|
||
Mock(ExecutionContext){ | ||
getExecutionLogger()>>logger | ||
getFrameworkProject() >> "test" | ||
getFramework() >> Mock(Framework) { | ||
getFrameworkProjectMgr() >> manager | ||
} | ||
|
||
} | ||
} | ||
|
||
def "check Boolean parameter"(){ | ||
|
||
given: | ||
|
||
String[] command = ["ls","-lrt"] | ||
def logger = Mock(ExecutionLogger) | ||
def example = new ${javaPluginClass}() | ||
def context = getContext(logger,true) | ||
def node = Mock(INodeEntry){ | ||
getNodename()>>"test" | ||
getAttributes()>>["hostname":"Test","osFamily":"linux","forceFail":"true"] | ||
} | ||
|
||
when: | ||
example.executeCommand(context, command, node) | ||
|
||
then: | ||
1 * logger.log(0, '[demo-error] force to fail') | ||
|
||
} | ||
|
||
def "run OK"(){ | ||
|
||
given: | ||
|
||
String[] command = ["ls","-lrt"] | ||
def logger = Mock(ExecutionLogger) | ||
def example = new ${javaPluginClass}() | ||
def context = getContext(logger,false) | ||
def node = Mock(INodeEntry){ | ||
getNodename()>>"test" | ||
getAttributes()>>["hostname":"Test","osFamily":"linux"] | ||
} | ||
|
||
when: | ||
example.executeCommand(context, command, node) | ||
|
||
then: | ||
1 * logger.log(2, '[demo-info] Running command: [ls, -lrt] on node test') | ||
|
||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/templates/java-plugin/nodeexecutor/README.md.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# ${pluginName} Rundeck Plugin | ||
|
||
This is a node executor plugin. | ||
|
44 changes: 44 additions & 0 deletions
44
src/main/resources/templates/java-plugin/nodeexecutor/build.gradle.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
version = '0.1.0' | ||
defaultTasks 'clean','build' | ||
apply plugin: 'java' | ||
apply plugin: 'groovy' | ||
apply plugin: 'idea' | ||
sourceCompatibility = 1.8 | ||
ext.rundeckPluginVersion= '2.0' | ||
ext.rundeckVersion= '${rundeckVersion}' | ||
|
||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile 'org.rundeck:rundeck-core:3.0.1+' | ||
|
||
testCompile 'junit:junit:4.12' | ||
testCompile "org.codehaus.groovy:groovy-all:2.4.15" | ||
testCompile "org.spockframework:spock-core:1.0-groovy-2.4" | ||
testCompile "cglib:cglib-nodep:2.2.2" | ||
testCompile group: 'org.objenesis', name: 'objenesis', version: '1.2' | ||
} | ||
|
||
ext.pluginClassNames='com.plugin.${sanitizedPluginName}.${javaPluginClass}' | ||
jar { | ||
manifest { | ||
attributes 'Rundeck-Plugin-Classnames': pluginClassNames | ||
attributes 'Rundeck-Plugin-File-Version': version | ||
attributes 'Rundeck-Plugin-Name': '${pluginName}' | ||
attributes 'Rundeck-Plugin-Description': 'Provide a short description of your plugin here.' | ||
attributes 'Rundeck-Plugin-Rundeck-Compatibility-Version': '3.x' | ||
attributes 'Rundeck-Plugin-Tags': 'java,notification' | ||
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion, 'Rundeck-Plugin-Archive': 'true' | ||
} | ||
from("rundeck-verb-artifact.yaml") { | ||
into("") | ||
} | ||
} | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '4.4.1' | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions
6
src/main/resources/templates/java-plugin/nodeexecutor/java-plugin.structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
build.gradle.template->build.gradle | ||
README.md.template->README.md | ||
icon.png->src/main/resources/resources/icon.png | ||
Plugin.java.template->src/main/java/com/plugin/${javaPluginClass.toLowerCase()}/${javaPluginClass}.java | ||
PluginSpec.groovy.template->src/test/groovy/com/plugin/${javaPluginClass.toLowerCase()}/${javaPluginClass}Spec.groovy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters