1

I am trying to bootstrap chef node using jclouds libraries instead Knife, but always i get the same problem.

my code crash during script generation ,which will be executed in the nodes. with debugging, the exception is triggered in this line

Statement bootstrap =chefapi.chefService().createBootstrapScriptForGroup("jclouds-chef");

the creation of the script is already started but crashed exactly here

statements.add(createAttributesFile(chefBootFile, config));

I have verified that the configuration is already added to the databag and contains the recepieplease.

Any ideas as to what is going on here? plz help me .

This is my code :

package chef;


import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Properties;

import org.jclouds.Constants;
import org.jclouds.ContextBuilder;
import org.jclouds.chef.ChefApi;
import org.jclouds.chef.ChefService;
import org.jclouds.chef.config.ChefProperties;
import org.jclouds.chef.domain.BootstrapConfig;
import org.jclouds.chef.util.RunListBuilder;

import org.jclouds.scriptbuilder.domain.Statement;

import com.google.common.base.Charsets;
import com.google.common.io.Files;



public class ChefProvisioner {

       public static void main(String[] args) throws IOException {
            ChefProvisioner.provision();
        }

        public static void provision() throws IOException {

            // Configuration            
            String endpoint = "https://api.chef.io/organizations/sacompany";
            String client = "omar_romdhane";
            String validator = "sacompany-validator";
            String clientCredential = Files.toString(new File("C:\\chef\\omar_romdhane.pem"), Charsets.UTF_8);
            String validatorCredential = Files.toString(new File("C:\\chef\\sacompany-validator.pem"), Charsets.UTF_8);



            Properties props = new Properties();
            props.put(ChefProperties.CHEF_VALIDATOR_NAME, validator);
            props.put(ChefProperties.CHEF_VALIDATOR_CREDENTIAL, validatorCredential);
            props.put(Constants.PROPERTY_RELAX_HOSTNAME, "true");
            props.put(Constants.PROPERTY_TRUST_ALL_CERTS, "true");


            ChefApi chefapi = ContextBuilder.newBuilder("chef")
                    .overrides(props)
                    .credentials(client, clientCredential)
                    .endpoint(endpoint)
                    .buildApi(ChefApi.class);


            List<String> runlist = new RunListBuilder().addRecipe("tomcats").build();
            BootstrapConfig bootstrapConfig = BootstrapConfig.builder().runList(runlist).build();



            ChefService chef = chefapi.chefService();
            chef.updateBootstrapConfigForGroup("jclouds-chef", bootstrapConfig);      

            System.out.println(chef.getBootstrapConfigForGroup("jclouds-chef").getRunList());
            Statement bootstrap = chefapi.chefService().createBootstrapScriptForGroup("jclouds-chef");

        } 
}

and this is the stack trace :

[recipe[tomcats]]
Exception in thread "main" java.lang.NullPointerException
    at org.jclouds.chef.functions.GroupToBootScript.createAttributesFile(GroupToBootScript.java:124)
    at org.jclouds.chef.functions.GroupToBootScript.apply(GroupToBootScript.java:96)
    at org.jclouds.chef.internal.BaseChefService.createBootstrapScriptForGroup(BaseChefService.java:160)
    at chef.ChefProvisioner.provision(ChefProvisioner.java:64)
    at chef.ChefProvisioner.main(ChefProvisioner.java:27)
Omar
  • 38
  • 1
  • 5
  • The code looks good. Could you also share the output of the program, and also the contents of the "bootstrap" databag just before the "create script" call? I'm editing as I've just seen the output is already in the output, and that this question is the continuation of [this one](http://stackoverflow.com/questions/38098646/bootstrap-chef-node-with-jclouds/38100383#38100383). Which version of jclouds are you using? – Ignasi Barrera Jul 17 '16 at 21:43
  • the databag displays correctly before script generation,this is the result `{"run_list":["recipe[tomcats]"]}` i use 1.9.0 version .this is the totality of stacktrace because i still use a simple Java class to test the operation of jcloud before integrate it to my java web application – Omar Jul 18 '16 at 01:43
  • Oh, jclouds 1.9.0 has issue [JCLOUDS-890](https://issues.apache.org/jira/browse/JCLOUDS-890), which is exactly what you are experiencing. To bypass it you could just set some dummy attributes in the bootstrap config to avoid the exception, or even better you could try upgrading to jclouds 1.9.2. – Ignasi Barrera Jul 18 '16 at 13:32
  • thanks , i'm going to try – Omar Jul 18 '16 at 13:39
  • thanks Ignasi, it works when i upgrade to jclouds 1.9.2 but now i got another error with SshClient , this is the stacktrace `: Exception in thread "main" com.google.inject.ConfigurationException: Guice configuration errors: 1) No implementation for org.jclouds.ssh.SshClient$Factory was bound. while locating org.jclouds.ssh.SshClient$Factory ` i use jdk 8 and jclouds-sshj 1.9.2 . Any idea plz – Omar Jul 18 '16 at 15:12
  • Hmmm the current code snippet does not show any compute related code. Could you share the relevant bits? – Ignasi Barrera Jul 18 '16 at 15:44
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117623/discussion-between-omar-and-ignasi-barrera). – Omar Jul 18 '16 at 15:50

0 Answers0