Package org.jclouds.chef

Examples of org.jclouds.chef.ChefService


    }

    @Override
    public Statement getStatement() {
        Statement statement = null;
        ChefService chefService = getChefService();
        if (chefService != null) {
            List<String> runlist = new RunListBuilder().addRecipes(cookbook).build();
            chefService.updateRunListForGroup(runlist, group);
            statement = chefService.createBootstrapScriptForGroup(group);
        }
        return statement;
    }
View Full Code Here


     * @param services
     * @return
     */
    public static ChefService getChefService(String id, String api, List<ChefService> services) {
        if (!Strings.isNullOrEmpty(id)) {
            ChefService service = null;
            for (ChefService svc : services) {
                if (id.equals(svc.getContext().unwrap().getName())) {
                    service = svc;
                    break;
                }
            }
            if (service == null) {
                throw new IllegalArgumentException("No chef service with id" + id + " found.");
            }
            return service;
        }

        if (!Strings.isNullOrEmpty(api)) {
            ChefService service = null;
            for (ChefService svc : services) {
                if (api.equals(svc.getContext().unwrap().getId())) {
                    service = svc;
                    break;
                }
View Full Code Here

    public static ChefService findOrCreateChefService(String api, String name, String clientName, String clientCredential, String clientKeyFile, String validatorName, String validatorCredential, String validatorKeyFile, String endpoint, List<ChefService> chefServices) {
        if ((name == null && api == null) && (chefServices != null && chefServices.size() == 1)) {
            return chefServices.get(0);
        }

        ChefService chefService = null;
        String apiValue = ChefHelper.getChefApi(api);
        String clientNameValue = ChefHelper.getClientName(clientName);
        String clientCredentialValue = ChefHelper.getClientCredential(clientCredential);
        String clientKeyFileValue = ChefHelper.getClientKeyFile(clientKeyFile);
        String validatorNameValue = ChefHelper.getValidatorName(validatorName);
View Full Code Here

        builder = builder.name(name).modules(ImmutableSet.<Module>of(new SLF4JLoggingModule()));
        builder = builder.name(name).credentials(clientName, clientCredential).overrides(chefConfig);

        ChefContext context = builder.build(ChefContext.class);
        ChefService service = context.getChefService();
        return service;
    }
View Full Code Here

    public List<ChefService> getChefServices() {
        if (api == null) {
            return chefServices;
        } else {
            try {
                ChefService service = getChefService();
                return Collections.singletonList(service);
            } catch (Throwable t) {
                return Collections.emptyList();
            }
        }
View Full Code Here

     * @param bundleContext
     * @param api
     * @return
     */
    public synchronized ChefService waitForChefService(BundleContext bundleContext, String name, String api) {
        ChefService chefService = null;
        try {
            for (int r = 0; r < 6; r++) {
                ServiceReference[] references = null;
                if (name != null) {
                    references = bundleContext.getAllServiceReferences(ChefService.class.getName(), "(" + Constants.NAME + "="
View Full Code Here

               // Run the script in the nodes of the group
               runScriptOnGroup(compute, login, groupName, bootstrap);
               break;
            case CHEF:
               // Create the connection to the Chef server
               ChefService chef = initChefService(System.getProperty("chef.client"),
                     System.getProperty("chef.validator"));

               // Build the runlist for the deployed nodes
               System.out.println("Configuring node runlist in the Chef server...");
               List<String> runlist = new RunListBuilder().addRecipes(recipes.split(",")).build();
               chef.updateRunListForGroup(runlist, groupName);
               Statement chefServerBootstrap = chef.createBootstrapScriptForGroup(groupName);

               // Run the script in the nodes of the group
               System.out.printf(">> installing [%s] on group %s as %s%n", recipes, groupName, login.identity);
               runScriptOnGroup(compute, login, groupName, chefServerBootstrap);
               break;
View Full Code Here

         logger.debug("starting initialization");
         Properties overrides = InitParamsToProperties.INSTANCE.apply(servletContextEvent.getServletContext());

         logger.trace("creating client connection");

         ChefService client = createService(overrides, servletContextEvent);
         logger.debug("created client connection");

         Node node;
         String nodeName;
         while (true) {
            nodeName = findNextNodeName(client, getInitParam(servletContextEvent, CHEF_NODE_PATTERN));
            try {
               node = client.createNodeAndPopulateAutomaticAttributes(nodeName,
                     Splitter.on(',').split(getInitParam(servletContextEvent, CHEF_RUN_LIST)));
               break;
            } catch (IllegalStateException ex) {
               logger.debug("client already exists %s: %s", nodeName, ex.getMessage());
            }
View Full Code Here

   /**
    * removes the node and client if found, and closes the client context.
    */
   @Override
   public void contextDestroyed(ServletContextEvent servletContextEvent) {
      ChefService client = getContextAttributeOrNull(servletContextEvent, CHEF_SERVICE_CLIENT);
      Node node = getContextAttributeOrNull(servletContextEvent, CHEF_NODE);
      if (node != null && client != null) {
         client.deleteAllNodesInList(singleton(node.getName()));
      }
      if (client != null) {
         Closeables.closeQuietly(client.getContext());
      }
   }
View Full Code Here

                    // Run the script in the nodes of the group
                    runScriptOnGroup(compute, login, groupName, bootstrap);
                    break;
                case CHEF:
                    // Create the connection to the Chef server
                    ChefService chef =
                            initChefService(System.getProperty("chef.client"),
                                    System.getProperty("chef.validator"));

                    // Build the runlist for the deployed nodes
                    System.out.println("Configuring node runlist in the Chef server...");
                    List<String> runlist =
                            new RunListBuilder().addRecipes(recipes.split(",")).build();
                    BootstrapConfig config = BootstrapConfig.builder().runList(runlist).build();
                    chef.updateBootstrapConfigForGroup(groupName, config);
                    Statement chefServerBootstrap = chef.createBootstrapScriptForGroup(groupName);

                    // Run the script in the nodes of the group
                    System.out.printf(">> installing [%s] on group %s as %s%n", recipes, groupName,
                            login.identity);
                    runScriptOnGroup(compute, login, groupName, chefServerBootstrap);
View Full Code Here

TOP

Related Classes of org.jclouds.chef.ChefService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.