-
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 #11 from rundeck/java-orchestrator
Adding orchestrator java plugin
- Loading branch information
Showing
9 changed files
with
202 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
38 changes: 38 additions & 0 deletions
38
src/main/resources/templates/java-plugin/orchestrator/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,38 @@ | ||
package com.plugin.${javaPluginClass.toLowerCase()}; | ||
|
||
import com.dtolabs.rundeck.core.common.INodeEntry; | ||
import com.dtolabs.rundeck.core.execution.workflow.StepExecutionContext; | ||
import com.dtolabs.rundeck.core.plugins.Plugin; | ||
import com.dtolabs.rundeck.plugins.ServiceNameConstants; | ||
import com.dtolabs.rundeck.plugins.descriptions.PluginDescription; | ||
import com.dtolabs.rundeck.plugins.descriptions.PluginProperty; | ||
import com.dtolabs.rundeck.plugins.orchestrator.Orchestrator; | ||
import com.dtolabs.rundeck.plugins.orchestrator.OrchestratorPlugin; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.nio.ByteBuffer; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
@Plugin(service=ServiceNameConstants.Orchestrator,name="${sanitizedPluginName}") | ||
@PluginDescription(title="${pluginName}", description="My Orchestrator plugin description") | ||
public class ${javaPluginClass} implements OrchestratorPlugin{ | ||
|
||
@PluginProperty(title = "Count", description = "Number of nodes to select from the pool", defaultValue = "1") | ||
protected int count; | ||
|
||
@Override | ||
public Orchestrator createOrchestrator(StepExecutionContext context, Collection<INodeEntry> nodes) { | ||
return new ${javaPluginClass}Orchestrator(count, context, nodes); | ||
} | ||
|
||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/resources/templates/java-plugin/orchestrator/PluginOrchestrator.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,69 @@ | ||
package com.plugin.${javaPluginClass.toLowerCase()}; | ||
|
||
import com.dtolabs.rundeck.core.common.INodeEntry; | ||
import com.dtolabs.rundeck.core.execution.workflow.StepExecutionContext; | ||
import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepResult; | ||
import com.dtolabs.rundeck.plugins.orchestrator.Orchestrator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
/** | ||
* Selects a random subset of the nodes | ||
*/ | ||
public class ${javaPluginClass}Orchestrator implements Orchestrator { | ||
|
||
Random random; | ||
final int count; | ||
List<INodeEntry> nodes; | ||
|
||
public ${javaPluginClass}Orchestrator( | ||
int count, | ||
StepExecutionContext context, | ||
Collection<INodeEntry> nodes | ||
) | ||
{ | ||
this.random = new Random(); | ||
this.count = count; | ||
this.nodes = select(count, nodes); | ||
} | ||
|
||
/** | ||
* Select count random items from the input nodes, or if nodes is smaller than count, reorders them | ||
* @param count number of nodes | ||
* @param nodes input nodes | ||
* @return list of count nodes | ||
*/ | ||
private List<INodeEntry> select(final int count, final Collection<INodeEntry> nodes) { | ||
List<INodeEntry> source = new ArrayList<>(nodes); | ||
List<INodeEntry> selected = new ArrayList<>(); | ||
int total = Math.min(count, nodes.size()); | ||
for (int i = 0; i < total; i++) { | ||
selected.add(source.remove(random.nextInt(source.size()))); | ||
} | ||
return selected; | ||
} | ||
|
||
|
||
@Override | ||
public INodeEntry nextNode() { | ||
if (nodes.size() > 0) { | ||
return nodes.remove(0); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public void returnNode( final INodeEntry node, final boolean success, final NodeStepResult result) | ||
{ | ||
|
||
} | ||
|
||
@Override | ||
public boolean isComplete() { | ||
return nodes.size() == 0; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/resources/templates/java-plugin/orchestrator/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,43 @@ | ||
package com.plugin.${javaPluginClass.toLowerCase()} | ||
|
||
import com.dtolabs.rundeck.core.common.INodeEntry | ||
import com.dtolabs.rundeck.core.common.NodeEntryImpl | ||
import com.dtolabs.rundeck.core.execution.workflow.StepExecutionContext | ||
import spock.lang.Specification | ||
|
||
class ${javaPluginClass}Spec extends Specification { | ||
|
||
private INodeEntry create(String hostname, String rankAttr=null, String rankValue=null){ | ||
INodeEntry iNodeEntry = NodeEntryImpl.create(hostname, hostname); | ||
|
||
if(null!=rankAttr) { | ||
iNodeEntry.getAttributes().put(rankAttr, rankValue); | ||
} | ||
return iNodeEntry; | ||
} | ||
|
||
def "simple test"() { | ||
|
||
given: | ||
INodeEntry node1 = create("Centos6", "memory", "1048"); | ||
INodeEntry node2 = create("Centos7", "memory", "2048"); | ||
INodeEntry node3 = create("Windows2016", "memory", "10240"); | ||
INodeEntry node4 = create("Windows10", "memory", "4096"); | ||
|
||
List<INodeEntry> nodes = Arrays.asList(node1, node2, node3, node4); | ||
|
||
def count=1 | ||
|
||
StepExecutionContext context=Mock(StepExecutionContext) | ||
|
||
when: | ||
def orchestrator=new ${javaPluginClass}Orchestrator(count,context,nodes) | ||
|
||
then: | ||
orchestrator.nextNode()?.hostname!=null | ||
orchestrator.nextNode()?.hostname==null | ||
|
||
} | ||
|
||
|
||
} |
4 changes: 4 additions & 0 deletions
4
src/main/resources/templates/java-plugin/orchestrator/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 orchestrator plugin. | ||
|
39 changes: 39 additions & 0 deletions
39
src/main/resources/templates/java-plugin/orchestrator/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,39 @@ | ||
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" | ||
} | ||
|
||
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,orchestrator' | ||
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion, 'Rundeck-Plugin-Archive': 'true' | ||
} | ||
} | ||
|
||
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.
7 changes: 7 additions & 0 deletions
7
src/main/resources/templates/java-plugin/orchestrator/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,7 @@ | ||
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 | ||
PluginOrchestrator.java.template->src/main/java/com/plugin/${javaPluginClass.toLowerCase()}/${javaPluginClass}Orchestrator.java | ||
PluginSpec.groovy.template->src/test/groovy/com/plugin/${javaPluginClass.toLowerCase()}/${javaPluginClass}Spec.groovy | ||
|