无法生成脚本

时间:2016-07-17 12:36:09

标签: chef bootstrapping jclouds

我正在尝试使用jclouds库而不是Knife引导厨师节点,但总是遇到同样的问题。

我的代码在脚本生成期间崩溃,这将在节点中执行。 通过调试,在此行中触发异常

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

脚本的创建已经开始但已崩溃 正是在这里

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

我已经验证配置已添加到数据库并包含接收器。

关于这里发生了什么的任何想法?请帮助我。

这是我的代码:

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");

        } 
}

这是堆栈跟踪:

[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)

0 个答案:

没有答案