mirror of https://github.com/apache/jclouds.git
More changes in support of Chef environments
- Add and update constructors for org.jclouds.chef.domain.Node - Make Node.chefEnvironment nullable - Add JavaDoc indicating environments apply since Chef 0.10 - Update unit tests
This commit is contained in:
parent
a75d816ad7
commit
ef1dc56484
|
@ -21,6 +21,8 @@ package org.jclouds.chef.domain;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.jclouds.domain.JsonBall;
|
import org.jclouds.domain.JsonBall;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
@ -43,7 +45,12 @@ public class Node {
|
||||||
private Map<String, JsonBall> automatic = Maps.newLinkedHashMap();
|
private Map<String, JsonBall> automatic = Maps.newLinkedHashMap();
|
||||||
@SerializedName("run_list")
|
@SerializedName("run_list")
|
||||||
private List<String> runList = Lists.newArrayList();
|
private List<String> runList = Lists.newArrayList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since chef 0.10
|
||||||
|
*/
|
||||||
@SerializedName("chef_environment")
|
@SerializedName("chef_environment")
|
||||||
|
@Nullable
|
||||||
private String chefEnvironment;
|
private String chefEnvironment;
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
|
@ -52,7 +59,17 @@ public class Node {
|
||||||
|
|
||||||
public Node(String name, Map<String, JsonBall> normal, Map<String, JsonBall> override,
|
public Node(String name, Map<String, JsonBall> normal, Map<String, JsonBall> override,
|
||||||
Map<String, JsonBall> defaultA, Map<String, JsonBall> automatic, Iterable<String> runList) {
|
Map<String, JsonBall> defaultA, Map<String, JsonBall> automatic, Iterable<String> runList) {
|
||||||
|
this(name, normal, override, defaultA, automatic, runList, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since chef 0.10
|
||||||
|
*/
|
||||||
|
public Node(String name, Map<String, JsonBall> normal, Map<String, JsonBall> override,
|
||||||
|
Map<String, JsonBall> defaultA, Map<String, JsonBall> automatic, Iterable<String> runList,
|
||||||
|
String chefEnvironment) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.chefEnvironment = chefEnvironment;
|
||||||
this.normal.putAll(normal);
|
this.normal.putAll(normal);
|
||||||
this.override.putAll(override);
|
this.override.putAll(override);
|
||||||
this.defaultA.putAll(defaultA);
|
this.defaultA.putAll(defaultA);
|
||||||
|
@ -67,7 +84,15 @@ public class Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node(String name, Iterable<String> runList) {
|
public Node(String name, Iterable<String> runList) {
|
||||||
|
this(name, runList, "_default");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since chef 0.10
|
||||||
|
*/
|
||||||
|
public Node(String name, Iterable<String> runList, String chefEnvironment) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.chefEnvironment = chefEnvironment;
|
||||||
Iterables.addAll(this.runList, runList);
|
Iterables.addAll(this.runList, runList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +125,9 @@ public class Node {
|
||||||
return runList;
|
return runList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since chef 0.10
|
||||||
|
*/
|
||||||
public String getChefEnvironment() {
|
public String getChefEnvironment() {
|
||||||
return chefEnvironment;
|
return chefEnvironment;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,6 @@ public class CreateNodeAndPopulateAutomaticAttributesImpl implements CreateNodeA
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Node execute(String nodeName, Iterable<String> runList) {
|
public Node execute(String nodeName, Iterable<String> runList) {
|
||||||
return execute(new Node(nodeName, runList));
|
return execute(new Node(nodeName, runList, "_default"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,13 +341,13 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
|
||||||
public void testCreateNode() throws SecurityException, NoSuchMethodException, IOException {
|
public void testCreateNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = ChefAsyncApi.class.getMethod("createNode", Node.class);
|
Method method = ChefAsyncApi.class.getMethod("createNode", Node.class);
|
||||||
GeneratedHttpRequest httpRequest = processor.createRequest(method, new Node("testnode",
|
GeneratedHttpRequest httpRequest = processor.createRequest(method, new Node("testnode",
|
||||||
ImmutableSet.of("recipe[java]")));
|
ImmutableSet.of("recipe[java]"), "_default"));
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/nodes HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "POST http://localhost:4000/nodes HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n");
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Node\",\"chef_type\":\"node\"}",
|
"{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},\"run_list\":[\"recipe[java]\"],\"chef_environment\":\"_default\",\"json_class\":\"Chef::Node\",\"chef_type\":\"node\"}",
|
||||||
"application/json", false);
|
"application/json", false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
|
||||||
|
@ -361,13 +361,13 @@ public class ChefAsyncApiTest extends BaseAsyncApiTest<ChefAsyncApi> {
|
||||||
public void testUpdateNode() throws SecurityException, NoSuchMethodException, IOException {
|
public void testUpdateNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = ChefAsyncApi.class.getMethod("updateNode", Node.class);
|
Method method = ChefAsyncApi.class.getMethod("updateNode", Node.class);
|
||||||
GeneratedHttpRequest httpRequest = processor.createRequest(method, new Node("testnode",
|
GeneratedHttpRequest httpRequest = processor.createRequest(method, new Node("testnode",
|
||||||
ImmutableSet.of("recipe[java]")));
|
ImmutableSet.of("recipe[java]"), "_default"));
|
||||||
|
|
||||||
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/nodes/testnode HTTP/1.1");
|
assertRequestLineEquals(httpRequest, "PUT http://localhost:4000/nodes/testnode HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n");
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\nX-Chef-Version: " + ChefAsyncApi.VERSION + "-test\n");
|
||||||
assertPayloadEquals(
|
assertPayloadEquals(
|
||||||
httpRequest,
|
httpRequest,
|
||||||
"{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},\"run_list\":[\"recipe[java]\"],\"json_class\":\"Chef::Node\",\"chef_type\":\"node\"}",
|
"{\"name\":\"testnode\",\"normal\":{},\"override\":{},\"default\":{},\"automatic\":{},\"run_list\":[\"recipe[java]\"],\"chef_environment\":\"_default\",\"json_class\":\"Chef::Node\",\"chef_type\":\"node\"}",
|
||||||
"application/json", false);
|
"application/json", false);
|
||||||
|
|
||||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class ParseNodeFromJsonTest {
|
||||||
|
|
||||||
Node node = new Node("adrian-jcloudstest", ImmutableMap.<String, JsonBall> of("tomcat6", new JsonBall(
|
Node node = new Node("adrian-jcloudstest", ImmutableMap.<String, JsonBall> of("tomcat6", new JsonBall(
|
||||||
"{\"ssl_port\":8433}")), ImmutableMap.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(),
|
"{\"ssl_port\":8433}")), ImmutableMap.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(),
|
||||||
ImmutableMap.<String, JsonBall> of(), Collections.singleton("recipe[java]"));
|
ImmutableMap.<String, JsonBall> of(), Collections.singleton("recipe[java]"), "prod");
|
||||||
|
|
||||||
assertEquals(handler.apply(HttpResponse.builder()
|
assertEquals(handler.apply(HttpResponse.builder()
|
||||||
.statusCode(200)
|
.statusCode(200)
|
||||||
|
|
|
@ -221,7 +221,7 @@ public abstract class BaseChefApiLiveTest<C extends Context> extends BaseChefCon
|
||||||
@Test(dependsOnMethods = "testCreateRole")
|
@Test(dependsOnMethods = "testCreateRole")
|
||||||
public void testCreateNode() throws Exception {
|
public void testCreateNode() throws Exception {
|
||||||
chefApi.deleteNode(PREFIX);
|
chefApi.deleteNode(PREFIX);
|
||||||
chefApi.createNode(new Node(PREFIX, Collections.singleton("role[" + PREFIX + "]")));
|
chefApi.createNode(new Node(PREFIX, Collections.singleton("role[" + PREFIX + "]"), "_default"));
|
||||||
node = chefApi.getNode(PREFIX);
|
node = chefApi.getNode(PREFIX);
|
||||||
// TODO check recipes
|
// TODO check recipes
|
||||||
assertNotNull(node);
|
assertNotNull(node);
|
||||||
|
|
|
@ -48,12 +48,13 @@ public class CreateNodeAndPopulateAutomaticAttributesImplTest {
|
||||||
|
|
||||||
Map<String, JsonBall> automatic = ImmutableMap.<String, JsonBall> of();
|
Map<String, JsonBall> automatic = ImmutableMap.<String, JsonBall> of();
|
||||||
|
|
||||||
Node node = new Node("name", ImmutableSet.<String> of());
|
Node node = new Node("name", ImmutableSet.<String> of(), "_default");
|
||||||
|
|
||||||
Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic);
|
Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic);
|
||||||
|
|
||||||
Node nodeWithAutomatic = new Node("name", ImmutableMap.<String, JsonBall> of(), ImmutableMap
|
Node nodeWithAutomatic = new Node("name", ImmutableMap.<String, JsonBall> of(), ImmutableMap
|
||||||
.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), automatic, ImmutableSet.<String> of());
|
.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), automatic, ImmutableSet.<String> of(),
|
||||||
|
"_default");
|
||||||
|
|
||||||
node.getAutomatic().putAll(automaticSupplier.get());
|
node.getAutomatic().putAll(automaticSupplier.get());
|
||||||
chef.createNode(nodeWithAutomatic);
|
chef.createNode(nodeWithAutomatic);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class UpdateAutomaticAttributesOnNodeImplLiveTest extends BaseChefContext
|
||||||
public void testExecute() {
|
public void testExecute() {
|
||||||
Set<String> runList = ImmutableSet.of("role[" + prefix + "]");
|
Set<String> runList = ImmutableSet.of("role[" + prefix + "]");
|
||||||
try {
|
try {
|
||||||
context.getApi().createNode(new Node(prefix, runList));
|
context.getApi().createNode(new Node(prefix, runList, "_default"));
|
||||||
context.utils().injector().getInstance(UpdateAutomaticAttributesOnNodeImpl.class).execute(prefix);
|
context.utils().injector().getInstance(UpdateAutomaticAttributesOnNodeImpl.class).execute(prefix);
|
||||||
Node node = context.getApi().getNode(prefix);
|
Node node = context.getApi().getNode(prefix);
|
||||||
assertEquals(node.getName(), prefix);
|
assertEquals(node.getName(), prefix);
|
||||||
|
|
|
@ -49,12 +49,13 @@ public class UpdateAutomaticAttributesOnNodeImplTest {
|
||||||
|
|
||||||
Map<String, JsonBall> automatic = ImmutableMap.<String, JsonBall> of();
|
Map<String, JsonBall> automatic = ImmutableMap.<String, JsonBall> of();
|
||||||
|
|
||||||
Node node = new Node("name", ImmutableSet.<String> of());
|
Node node = new Node("name", ImmutableSet.<String> of(), "_default");
|
||||||
|
|
||||||
Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic);
|
Supplier<Map<String, JsonBall>> automaticSupplier = Suppliers.<Map<String, JsonBall>> ofInstance(automatic);
|
||||||
|
|
||||||
Node nodeWithAutomatic = new Node("name", ImmutableMap.<String, JsonBall> of(), ImmutableMap
|
Node nodeWithAutomatic = new Node("name", ImmutableMap.<String, JsonBall> of(), ImmutableMap
|
||||||
.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), automatic, ImmutableSet.<String> of());
|
.<String, JsonBall> of(), ImmutableMap.<String, JsonBall> of(), automatic, ImmutableSet.<String> of(),
|
||||||
|
"_default");
|
||||||
|
|
||||||
expect(chef.getNode("name")).andReturn(node);
|
expect(chef.getNode("name")).andReturn(node);
|
||||||
node.getAutomatic().putAll(automaticSupplier.get());
|
node.getAutomatic().putAll(automaticSupplier.get());
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
{"normal":{"tomcat6":{"ssl_port":8433}},"name":"adrian-jcloudstest","override":{},"default":{},"json_class":"Chef::Node","automatic":{},"run_list":["recipe[java]"],"chef_type":"node"}
|
{"normal":{"tomcat6":{"ssl_port":8433}},"name":"adrian-jcloudstest","override":{},"default":{},"json_class":"Chef::Node","automatic":{},"run_list":["recipe[java]"],"chef_type":"node","chef_environment": "prod"}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue