Skip to content

Commit ec3428d

Browse files
authored
Merge pull request #18 from networkupstools/issue-15
Fix issues #15 (double-accounting) and #16 (continued mix-up of DSBC goals and labels)
2 parents 60293ef + b7ba6c1 commit ec3428d

28 files changed

+1014
-535
lines changed

src/org/nut/dynamatrix/Dynamatrix.groovy

Lines changed: 442 additions & 182 deletions
Large diffs are not rendered by default.

src/org/nut/dynamatrix/DynamatrixConfig.groovy

Lines changed: 67 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.nut.dynamatrix;
22

3+
import com.cloudbees.groovy.cps.NonCPS;
34
import org.nut.dynamatrix.Utils;
45
import org.nut.dynamatrix.dynamatrixGlobalState;
56

67
/**
7-
* This class intends to represent one build request configuration
8+
* This class intends to represent one build request configuration.
89
* An instance of it can be passed as the set of arguments for the
910
* customized run Dynamatrix routines, while some defaults can be
1011
* applied so needed fields are all "defined" when we look at them.
@@ -46,8 +47,10 @@ class DynamatrixConfig implements Cloneable {
4647
/** Each of these labels can be String, GString or Pattern object
4748
* to match labels (named as key=value pairs) of build agents:
4849
* <pre>dynamatrixAxesLabels: ['OS', '${COMPILER}VER', 'ARCH'],</pre>
50+
* Normally this object is a Set, but may be initialized as
51+
* a String, List, etc. so a getter is provided.
4952
*/
50-
public Set dynamatrixAxesLabels = []
53+
public def dynamatrixAxesLabels = []
5154

5255
// TODO: Need a way to specify that we only want some extreme value
5356
// but not the whole range, somehow specifiable per-system (e.g. to
@@ -260,9 +263,9 @@ class DynamatrixConfig implements Cloneable {
260263
*
261264
* @see #excludedNodelabels
262265
*/
263-
public Set requiredNodelabels = []
266+
public Set<String> requiredNodelabels = []
264267
/** @see #requiredNodelabels */
265-
public Set excludedNodelabels = []
268+
public Set<String> excludedNodelabels = []
266269

267270
/**
268271
* Same values as for {@code timeout()} step, e.g.
@@ -371,8 +374,16 @@ def parallelStages = prepareDynamatrix(
371374
return (DynamatrixConfig) super.clone();
372375
}
373376

377+
/**
378+
* Prepares the class instance settings for one of pre-defined
379+
* default configurations:
380+
* ['C', 'C-all', 'CXX', 'CXX-all', 'C+CXX', 'C+CXX-all']
381+
*<br/>
382+
* Returns a boolean status (true if OK), or a string with error details.
383+
* @see #initDefault(Map)
384+
*/
374385
public def initDefault(String defaultCfg) {
375-
def debugTrace = this.shouldDebugTrace()
386+
boolean debugTrace = this.shouldDebugTrace()
376387

377388
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(String): called with defaultCfg = ${Utils.castString(defaultCfg)}")
378389

@@ -567,9 +578,13 @@ def parallelStages = prepareDynamatrix(
567578
this.initDefault(dynacfgOrig)
568579
}
569580

581+
/**
582+
* Returns a boolean status (true if OK), or a string with error details
583+
* @see #initDefault(String)
584+
*/
570585
public def initDefault(Map dynacfgOrig) {
571-
def debugErrors = this.shouldDebugErrors()
572-
def debugTrace = this.shouldDebugTrace()
586+
boolean debugErrors = this.shouldDebugErrors()
587+
boolean debugTrace = this.shouldDebugTrace()
573588

574589
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): called with dynacfgOrig = ${Utils.castString(dynacfgOrig)}")
575590

@@ -579,13 +594,13 @@ def parallelStages = prepareDynamatrix(
579594
// Combine a config with defaults from a Set passed to a groovy call()
580595
if (dynacfgOrig.size() > 0) {
581596
// Be sure to only mutilate a copy below, not the original object
582-
dynacfgOrig = dynacfgOrig.clone()
597+
dynacfgOrig = (Map)(dynacfgOrig.clone())
583598

584599
// Note: in addition to standard contents of class DynamatrixConfig,
585600
// the Map passed by caller may contain "defaultDynamatrixConfig" as
586601
// a key for a String value to specify default pre-sets, e.g. "C".
587602
if (dynacfgOrig.containsKey('defaultDynamatrixConfig')) {
588-
def str = dynacfgOrig['defaultDynamatrixConfig'].toString()
603+
String str = dynacfgOrig['defaultDynamatrixConfig'].toString()
589604
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): calling initDefault(${str}) first")
590605
this.initDefault(str)
591606
dynacfgOrig.remove('defaultDynamatrixConfig')
@@ -598,7 +613,13 @@ def parallelStages = prepareDynamatrix(
598613

599614
if (dynacfgOrig.containsKey('dsbcStageTimeoutSettings')) {
600615
// Should be a Map or null; raise an error otherwise
601-
this.dsbcStageTimeoutSettings = dynacfgOrig.dsbcStageTimeoutSettings
616+
if (dynacfgOrig.dsbcStageTimeoutSettings == null
617+
|| Utils.isMap(dynacfgOrig.dsbcStageTimeoutSettings)
618+
) {
619+
this.dsbcStageTimeoutSettings = (Map)(dynacfgOrig.dsbcStageTimeoutSettings)
620+
} else {
621+
throw new InvalidClassException("dsbcStageTimeoutSettings is not a Map")
622+
}
602623
dynacfgOrig.remove('dsbcStageTimeoutSettings')
603624
}
604625

@@ -611,36 +632,36 @@ def parallelStages = prepareDynamatrix(
611632

612633
if (k.equals("mergeMode")) return // continue
613634
try {
614-
def mergeMode = "replace"
635+
String mergeMode = "replace"
615636
try {
616637
// Expected optional value "replace" or "merge"
617-
mergeMode = dynacfgOrig.mergeMode[k].trim()
618-
dynacfgOrig.mergeMode.remove(k)
619-
} catch (Throwable t) {} // keep default setting if no action requested
638+
mergeMode = (((Map)(dynacfgOrig['mergeMode']))[k]).toString().trim()
639+
(Map)(dynacfgOrig['mergeMode']).remove(k)
640+
} catch (Throwable ignored) {} // keep default setting if no action requested
620641

621642
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): mergeMode for k='${k}' is '${mergeMode}'")
622643
switch ("${mergeMode}") {
623644
case "merge":
624-
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): merging: ${this[k]}\n with: ${dynacfgOrig[k]}")
625-
this[k] = Utils.mergeMapSet(this[k], dynacfgOrig[k])
626-
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): result of merge: ${this[k]}")
645+
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): merging: ${this[k.toString()]}\n with: ${dynacfgOrig[k]}")
646+
this[k.toString()] = Utils.mergeMapSet(this[k.toString()], dynacfgOrig[k])
647+
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): result of merge: ${this[k.toString()]}")
627648
break
628649

629650
case "replace":
630651
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): replacing with: ${dynacfgOrig[k]}")
631-
this[k] = dynacfgOrig[k]
652+
this[k.toString()] = dynacfgOrig[k]
632653
//if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): result of replacement: ${this[k]}")
633654
break
634655

635656
default:
636657
if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): defaulting to replace with: ${dynacfgOrig[k]}")
637-
this[k] = dynacfgOrig[k]
658+
this[k.toString()] = dynacfgOrig[k]
638659
//if (debugTrace) this.script.println("[DEBUG] DynamatrixConfig(Map): result of replacement: ${this[k]}")
639660
break
640661
}
641662
} catch(Exception e) {
642663
if (!errs.equals("")) errs += "\n"
643-
def str = "[DEBUG] DynamatrixConfig(Map): ignoring unsupported config key from request: '${k}' => " + dynacfgOrig[k] + " : " + e.toString()
664+
String str = "[DEBUG] DynamatrixConfig(Map): ignoring unsupported config key from request: '${k}' => " + dynacfgOrig[k] + " : " + e.toString()
644665
errs += str
645666
if (debugTrace) this.script.println str
646667
}
@@ -673,37 +694,47 @@ def parallelStages = prepareDynamatrix(
673694
return this
674695
}
675696

676-
/*
697+
public Set getDynamatrixAxesLabels() {
698+
if (this.@dynamatrixAxesLabels != null
699+
&& !Utils.isList(this.@dynamatrixAxesLabels)
700+
) {
701+
this.sanitycheckDynamatrixAxesLabels()
702+
}
703+
704+
return (Set)(this.@dynamatrixAxesLabels)
705+
}
706+
707+
/**
677708
* Our callers expect a few specific data constructs here:
678709
* either a single string or pattern (that will be remade into
679710
* a single-element array), or an array/list/set/... of such types
680711
*/
681712
public def sanitycheckDynamatrixAxesLabels() {
682713
String errs = ""
683-
if (this.dynamatrixAxesLabels != null) {
684-
if (Utils.isList(this.dynamatrixAxesLabels)) {
714+
if (this.@dynamatrixAxesLabels != null) {
715+
if (Utils.isList(this.@dynamatrixAxesLabels)) {
685716
// TODO: Match superclass to not list all children of Set etc?
686717
// TODO: Check entries if this object that they are strings/patterns
687-
if (this.dynamatrixAxesLabels.size() > 0)
718+
if (this.@dynamatrixAxesLabels.size() > 0)
688719
return true
689720
// Else no automagic... but maybe got strict requirements?
690721
if (this.dynamatrixRequiredLabelCombos.size() > 0)
691722
return true
692723
errs += "Initially requested dynamatrixAxesLabels and dynamatrixRequiredLabelCombos are both empty"
693-
} else if (Utils.isString(this.dynamatrixAxesLabels)) {
694-
if (this.dynamatrixAxesLabels.equals("")) {
695-
this.dynamatrixAxesLabels = null
724+
} else if (Utils.isString(this.@dynamatrixAxesLabels)) {
725+
if ("" == this.@dynamatrixAxesLabels?.toString()) {
726+
this.@dynamatrixAxesLabels = null
696727
} else {
697-
this.dynamatrixAxesLabels = [this.dynamatrixAxesLabels]
728+
this.@dynamatrixAxesLabels = [this.@dynamatrixAxesLabels]
698729
}
699730
return true
700-
} else if (Utils.isRegex(this.dynamatrixAxesLabels)) {
701-
this.dynamatrixAxesLabels = [this.dynamatrixAxesLabels]
731+
} else if (Utils.isRegex(this.@dynamatrixAxesLabels)) {
732+
this.@dynamatrixAxesLabels = [this.@dynamatrixAxesLabels]
702733
return true
703734
} else {
704735
//if (!errs.equals("")) errs += "\n"
705-
errs += "Not sure what type 'dynamatrixAxesLabels' is: ${Utils.castString(this.dynamatrixAxesLabels)}"
706-
//this.dynamatrixAxesLabels = null
736+
errs += "Not sure what type 'dynamatrixAxesLabels' is: ${Utils.castString(this.@dynamatrixAxesLabels)}"
737+
//this.@dynamatrixAxesLabels = null
707738
}
708739
}
709740

@@ -720,8 +751,8 @@ def parallelStages = prepareDynamatrix(
720751
// deliberately does not include this.commonLabelExpr in the return
721752
String commonLabelExpr = ""
722753

723-
def debugErrors = this.shouldDebugErrors()
724-
def debugTrace = this.shouldDebugTrace()
754+
boolean debugErrors = this.shouldDebugErrors()
755+
boolean debugTrace = this.shouldDebugTrace()
725756

726757
// TODO: Use StringBuilder
727758
if (Utils.isListNotEmpty(this.requiredNodelabels)) {
@@ -756,7 +787,9 @@ def parallelStages = prepareDynamatrix(
756787

757788
} // end of class DynamatrixConfig
758789

790+
/** Used in {@link DynamatrixConfig#initDefault}() to pre-select tools and dynamatrix axes */
759791
enum CompilerTypes {
760792
// null,
793+
/** C/C++ compiler type */
761794
C
762795
}

0 commit comments

Comments
 (0)