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)