26
26
import com .dtolabs .rundeck .plugins .orchestrator .OrchestratorPlugin ;
27
27
28
28
import java .util .Collection ;
29
+ import java .util .List ;
30
+ import java .util .stream .Collectors ;
29
31
30
32
@ Plugin (name = "subset" , service = ServiceNameConstants .Orchestrator )
31
33
@ PluginDescription (title = "Random Subset" , description = "Chooses only a random subset of the target nodes." )
@@ -37,6 +39,22 @@ public class RandomSubsetOrchestratorPlugin implements OrchestratorPlugin {
37
39
38
40
@ Override
39
41
public Orchestrator createOrchestrator (StepExecutionContext context , Collection <INodeEntry > nodes ) {
40
- return new RandomSubsetOrchestrator (count , context , nodes );
42
+ String ident = createWFLayerIdent (context );
43
+ //use the ident as random seed to allow repeatable sequence of random nodes
44
+ //if this orchestrator config is invoked more than once in the same
45
+ //workflow layer
46
+ return new RandomSubsetOrchestrator (count , context , nodes , (long ) ident .hashCode ());
47
+ }
48
+
49
+ public String createWFLayerIdent (final StepExecutionContext context ) {
50
+ //create a string which identifies this execution layer uniquely
51
+ List <Integer > stepContext = context .getStepContext ();
52
+ String ident = context .getFrameworkProject ();
53
+ if (context .getDataContext ().get ("job" ) != null && context .getDataContext ().get ("job" ).get ("execid" ) != null ) {
54
+ ident += context .getDataContext ().get ("job" ).get ("execid" );
55
+ }
56
+
57
+ return ident +
58
+ String .join ("," , stepContext .stream ().map (Object ::toString ).collect (Collectors .toList ()));
41
59
}
42
60
}
0 commit comments