Greetings community,
Earlier versions of the saltstack plugin were pretty ugly and didn't use a
class for the different options in a dropdown selector, but instead just
parsed the json in the databoundconstructor. Thankfully, this has been
corrected, but now brings up the issue of how to support older configs.
I have the following code added to readResolve() or
public static class ConverterImpl extends XStream2.PassthruConverter<
SaltAPIBuilder> {
public ConverterImpl(XStream2 xstream) { super(xstream); }
@Override
protected void callback(SaltAPIBuilder obj, UnmarshallingContext context
) {
// Support 1.7 and before
if (obj.clientInterfaces != null) {
obj.arguments = obj.arguments.replaceAll(",", " ");
if (obj.clientInterfaces.has("clientInterface")) {
if (obj.clientInterfaces.getString("clientInterface").equals
("local")) {
obj.clientInterface = new LocalClient(obj.function,
obj.arguments
+ " " + obj.kwarguments, obj.target, obj.targettype);
((LocalClient) obj.clientInterface).setJobPollTime(obj.
clientInterfaces.getInt("jobPollTime"));
((LocalClient) obj.clientInterface).setBlockbuild(obj.
clientInterfaces.getBoolean("blockbuild"));
} else if (obj.clientInterfaces.getString("clientInterface"
).equals("local_batch")) {
obj.clientInterface = new LocalBatchClient(obj.function,
obj.arguments + " " + obj.kwarguments, obj.batchSize, obj.target, obj.
targettype);
} else if (obj.clientInterfaces.getString("clientInterface"
).equals("runner")) {
obj.clientInterface = new RunnerClient(obj.function, obj
.arguments + " " + obj.kwarguments, obj.mods, obj.pillarvalue);
}
}
final XStream xStream = new XStream(new DomDriver());
final String xmlResult = xStream.toXML(obj).toString();
System.out.println("!!!!!! Running ConverterImpl\n" + xmlResult
);
OldDataMonitor.report(context, "1.7.2");
}
}
}
This code attempts to parse the old format, and creates the appropriate new
classes. In the above, the system.out.println result shows the expected
output, but unfortunately there's a problem.
When viewing a job with an older config, nothing is displayed. When viewing
the manage old data page the following error is shown:
TypeNameVersion
hudson.model.FreeStyleProject job1.7.1 1.7.2 ConversionException: Cannot
construct com.waytta.clientinterface.BasicClient :
com.waytta.clientinterface.BasicClient : Cannot construct
com.waytta.clientinterface.BasicClient :
com.waytta.clientinterface.BasicClient ---- Debugging information ----
message : Cannot construct com.waytta.clientinterface.BasicClient :
com.waytta.clientinterface.BasicClient cause-exception :
com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message : Cannot construct com.waytta.clientinterface.BasicClient :
com.waytta.clientinterface.BasicClient class :
com.waytta.clientinterface.BasicClient required-type :
com.waytta.clientinterface.BasicClient converter-type :
hudson.util.RobustReflectionConverter path :
/project/builders/com.waytta.SaltAPIBuilder/clientInterface line number :
52 -------------------------------, InstantiationError: null
Does anyone have a recomendation on how to support this migration and
creating a class from the ConverterImpl?
Thanks :)
--
You received this message because you are subscribed to the Google Groups
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-dev/3825faa2-a769-4a81-9c92-dc0065dea0c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.