refactored chef module to make a new servlet context listener

This commit is contained in:
Adrian Cole 2010-07-28 00:47:07 -07:00
parent ca247efaed
commit 57ba278cbb
104 changed files with 383 additions and 95 deletions

92
chef/core/pom.xml Normal file
View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
$HeadURL$ $Revision$ $Date$ Copyright (C) 2010 Cloud Conscious, LLC
<info@cloudconscious.com>
====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to you under the Apache License, Version
2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.html Unless required by
applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for
the specific language governing permissions and limitations under the
License.
====================================================================
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-chef-project</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../project/pom.xml</relativePath>
</parent>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-chef</artifactId>
<name>jclouds Chef core</name>
<description>jclouds components to access Chef</description>
<scm>
<connection>scm:svn:http://jclouds.googlecode.com/svn/trunk/chef</connection>
<developerConnection>scm:svn:https://jclouds.googlecode.com/svn/trunk/chef</developerConnection>
<url>http://jclouds.googlecode.com/svn/trunk/chef</url>
</scm>
<!-- bootstrapping: need to fetch the project POM -->
<repositories>
<repository>
<id>jclouds-googlecode-deploy</id>
<url>http://jclouds.googlecode.com/svn/repo</url>
</repository>
<repository>
<id>jclouds-rimu-snapshots-nexus</id>
<url>http://jclouds.rimuhosting.com:8081/nexus/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<jclouds.chef.identity>chef-validator</jclouds.chef.identity>
<jclouds.chef.rsa-key>/etc/chef/validation.pem</jclouds.chef.rsa-key>
<jclouds.chef.endpoint>http://localhost:4000</jclouds.chef.endpoint>
<jclouds.test.identity>${jclouds.chef.identity}</jclouds.test.identity>
<jclouds.test.credential>${jclouds.chef.rsa-key}</jclouds.test.credential>
<jclouds.test.endpoint>${jclouds.chef.endpoint}</jclouds.test.endpoint>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jclouds-log4j</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -55,7 +55,7 @@ public class ChefContextBuilder extends RestContextBuilder<ChefClient, ChefAsync
* {@inheritDoc}
*/
@Override
public ChefContextBuilder withModules(Module... modules) {
public ChefContextBuilder withModules(Iterable<Module> modules) {
return (ChefContextBuilder) super.withModules(modules);
}

View File

@ -15,8 +15,12 @@ import com.google.inject.ImplementedBy;
*/
@ImplementedBy(BaseChefService.class)
public interface ChefService {
/**
* @return a reference to the context that created this.
*/
ChefContext getContext();
void cleanupStaleNodesAndClients(String prefix, int minutesStale);
void cleanupStaleNodesAndClients(String prefix, int secondsStale);
void createNodeAndPopulateAutomaticAttributes(String nodeName, Iterable<String> runList);

View File

@ -1,5 +1,7 @@
package org.jclouds.chef.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Set;
import javax.annotation.Resource;
@ -7,6 +9,7 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.chef.ChefContext;
import org.jclouds.chef.ChefService;
import org.jclouds.chef.domain.Node;
import org.jclouds.chef.reference.ChefConstants;
@ -30,6 +33,7 @@ public class BaseChefService implements ChefService {
@Named(ChefConstants.CHEF_LOGGER)
protected Logger logger = Logger.NULL;
private final ChefContext chefContext;
private final CleanupStaleNodesAndClients cleanupStaleNodesAndClients;
private final CreateNodeAndPopulateAutomaticAttributes createNodeAndPopulateAutomaticAttributes;
private final DeleteAllClientsAndNodesInList deleteAllClientsAndNodesInList;
@ -37,20 +41,24 @@ public class BaseChefService implements ChefService {
private final UpdateAutomaticAttributesOnNode updateAutomaticAttributesOnNode;
@Inject
protected BaseChefService(CleanupStaleNodesAndClients cleanupStaleNodesAndClients,
protected BaseChefService(ChefContext chefContext, CleanupStaleNodesAndClients cleanupStaleNodesAndClients,
CreateNodeAndPopulateAutomaticAttributes createNodeAndPopulateAutomaticAttributes,
DeleteAllClientsAndNodesInList deleteAllClientsAndNodesInList, GetNodes getNodes,
UpdateAutomaticAttributesOnNode updateAutomaticAttributesOnNode) {
this.cleanupStaleNodesAndClients = cleanupStaleNodesAndClients;
this.createNodeAndPopulateAutomaticAttributes = createNodeAndPopulateAutomaticAttributes;
this.deleteAllClientsAndNodesInList = deleteAllClientsAndNodesInList;
this.getNodes = getNodes;
this.updateAutomaticAttributesOnNode = updateAutomaticAttributesOnNode;
this.chefContext = checkNotNull(chefContext, "chefContext");
this.cleanupStaleNodesAndClients = checkNotNull(cleanupStaleNodesAndClients, "cleanupStaleNodesAndClients");
this.createNodeAndPopulateAutomaticAttributes = checkNotNull(createNodeAndPopulateAutomaticAttributes,
"createNodeAndPopulateAutomaticAttributes");
this.deleteAllClientsAndNodesInList = checkNotNull(deleteAllClientsAndNodesInList,
"deleteAllClientsAndNodesInList");
this.getNodes = checkNotNull(getNodes, "getNodes");
this.updateAutomaticAttributesOnNode = checkNotNull(updateAutomaticAttributesOnNode,
"updateAutomaticAttributesOnNode");
}
@Override
public void cleanupStaleNodesAndClients(String prefix, int minutesStale) {
cleanupStaleNodesAndClients.execute(prefix, minutesStale);
public void cleanupStaleNodesAndClients(String prefix, int secondsStale) {
cleanupStaleNodesAndClients.execute(prefix, secondsStale);
}
@Override
@ -83,4 +91,9 @@ public class BaseChefService implements ChefService {
updateAutomaticAttributesOnNode.execute(nodeName);
}
@Override
public ChefContext getContext() {
return chefContext;
}
}

View File

@ -67,5 +67,6 @@ public interface ChefConstants {
*/
public static final String CHEF_LOGGER = "jclouds.chef";
public static final String CHEF_SERVICE_CLIENT = "chef.service.client";
public static final String CHEF_NODENAME = "chef.nodename";
}

Some files were not shown because too many files have changed in this diff Show More