Rendering a describable in global config

96 views
Skip to first unread message

Mads Nielsen

unread,
Apr 9, 2015, 9:13:12 AM4/9/15
to jenkin...@googlegroups.com
Hey Everyone, 

I'm having some issues. I have a plugin which basically only has a global configuration that provides access to a mongo database other plugins can make use of to store data with via a simple interface. I am having an issue with the rendering of the configuration screen

The main plugin simply just extends Plugin and has a config.jelly with the following to show a list of possible datasources

<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
    <f:section title="NoSQL Configuration: ${it.provider}">
        <f:dropdownDescriptorSelector field="provider" title="Database selection" descriptors="${it.getAllProviders()}"/>        
    </f:section>
</j:jelly>
 
I't populates and renders the list of my describable objects just fine, and i can see that the values do get persisted in the xml file on my jenkins instance. However, when the i reload and go back to see the configuration all the fields are blank in the configuration for my describable object. 

I have overriden  the following methods in the Plugin Implemention: 

    @Override
    public void configure(StaplerRequest req, JSONObject formData) throws IOException, ServletException, Descriptor.FormException {
        super.configure(req, formData); //To change body of generated methods, choose Tools | Templates.        
        provider = req.bindJSON(NoSQLProvider.class, formData.getJSONObject("provider"));
        save();
    }

    @Override
    public void start() throws Exception {
        super.start(); //To change body of generated methods, choose Tools | Templates.
        load();
    }

The base implementation of my describable object looks like this: 

public abstract class NoSQLProvider implements Describable<NoSQLProvider>, Serializable {

    public abstract <T> T create(T t) throws NoSQLDataException;
    public abstract <T> T read(Object key, Class<T> clazz) throws NoSQLDataException;
    
    public abstract static class NoSQLDescriptor extends Descriptor<NoSQLProvider> {
        
        public static ExtensionList<NoSQLDescriptor> all() {
            return Jenkins.getInstance().getExtensionList(NoSQLDescriptor.class);
        }

    }
}

I also tried all sorts of things, one of the was calling load() in the constructor of my desribables, for example for MongoDB i have the following descriptor:

    @Extension
    public static final class MongoProviderDescriptor extends NoSQLDescriptor {
        
        public MongoProviderDescriptor() {
            load();
        }
        
        @Override
        public String getDisplayName() {
            return "MongoDB";
        }
    } 

What am i missing here? I've done this before...but i can't figure out what keeps this from working :)

Best regards,
Mads



____________________________________________________________
Mads Nielsen
Consultant
m...@praqma.net
+45 50 98 18 09
Skype: inkspot
Praqma
www.praqma.com
Allerød Stationsvej 4
DK-3450 Allerød
+45 36 77 27 62

Kanstantsin Shautsou

unread,
Apr 9, 2015, 10:06:44 AM4/9/15
to jenkin...@googlegroups.com
Describable binds to config.{groovy||jelly}. Describable must have getter methods in form 'getField()' for field that exists in Describable. 

Mads Nielsen

unread,
Apr 9, 2015, 10:12:47 AM4/9/15
to jenkin...@googlegroups.com
Hey Kanstantin,

I have getters and setters for all the fields in my describable. Atleast i can see in the XML that is produced that i get them stored correctly...for example the MongoDB implementation has the follwing

public class MongoProviderImpl extends NoSQLProvider {
    
    private String database,collection,username;
    private String host = "localhost";
    private int port = 27017;
    private Secret password;
    private MongoDBHolderService service;
    
    @DataBoundConstructor
    public MongoProviderImpl(String host, int port, String database, String collection, String username, Secret password) {
        this.port = port;
        this.host = host;
....
    }
 .....

     /**
     * @return the host
     */
    public String getHost() {
        return host;
    }

    /**
     * @param host the host to set
     */
    public void setHost(String host) {
        this.host = host;
    }

So i have getters and setters for every field in my describable object.



____________________________________________________________
Mads Nielsen
Consultant
m...@praqma.net
+45 50 98 18 09
Skype: inkspot
Praqma
www.praqma.com
Allerød Stationsvej 4
DK-3450 Allerød
+45 36 77 27 62

--
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 jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/e3364359-0b92-48e9-94d8-763a64369839%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kanstantsin Shautsou

unread,
Apr 9, 2015, 10:18:56 AM4/9/15
to jenkin...@googlegroups.com
Link to source java and UI files will be appreciated :)
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/OFSFu3d9080/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAFariutHbOZNs%3DpObFonAJ61oibVp1PNgG1YADUB97C6EAnuVw%40mail.gmail.com.

Mads Nielsen

unread,
Apr 9, 2015, 10:25:14 AM4/9/15
to jenkin...@googlegroups.com

Jesse Glick

unread,
Apr 9, 2015, 11:20:33 AM4/9/15
to Jenkins Dev
On Thu, Apr 9, 2015 at 9:13 AM, Mads Nielsen <m...@praqma.net> wrote:
> The main plugin simply just extends Plugin and has a config.jelly

Extending Plugin is semi-deprecated. Use GlobalConfiguration instead.

Mads Nielsen

unread,
Apr 10, 2015, 9:16:44 AM4/10/15
to jenkin...@googlegroups.com
Thanks Jesse! That did the trick. Switching from Plugin to GlobalConfiguration fixed it...didn't have to change much to get that working!

____________________________________________________________
Mads Nielsen
Consultant
m...@praqma.net
+45 50 98 18 09
Skype: inkspot
Praqma
www.praqma.com
Allerød Stationsvej 4
DK-3450 Allerød
+45 36 77 27 62

--
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 jenkinsci-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages