mirror of https://github.com/apache/jclouds.git
JCLOUDS-256: Add missing API to list environment nodes
This commit is contained in:
parent
c75c3b9e63
commit
05e8d32d03
|
@ -938,4 +938,20 @@ public interface ChefApi extends Closeable {
|
|||
@Path("/environments/{environmentname}/recipes")
|
||||
@Fallback(EmptySetOnNotFoundOr404.class)
|
||||
Set<String> listEnvironmentRecipes(@PathParam("environmentname") String environmentname);
|
||||
|
||||
/**
|
||||
* @return List of environment nodes.
|
||||
* @throws AuthorizationException
|
||||
* <p/>
|
||||
* "401 Unauthorized" if you are not a recognized user.
|
||||
* <p/>
|
||||
* "403 Forbidden" if you do not have rights to list environment nodes.
|
||||
*/
|
||||
@SinceApiVersion("0.10.0")
|
||||
@Named("environment:nodelist")
|
||||
@GET
|
||||
@Path("/environments/{environmentname}/nodes")
|
||||
@ResponseParser(ParseKeySetFromJson.class)
|
||||
@Fallback(EmptySetOnNotFoundOr404.class)
|
||||
Set<String> listEnvironmentNodes(@PathParam("environmentname") String environmentname);
|
||||
}
|
||||
|
|
|
@ -377,6 +377,11 @@ public class TransientChefApi implements ChefApi {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> listEnvironmentNodes(String environmentname) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
closer.close();
|
||||
|
|
|
@ -74,6 +74,34 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
|
|||
assertTrue(api.listEnvironmentRecipes("dev").isEmpty());
|
||||
}
|
||||
|
||||
public void testListEnvironmentNodesReturns2xx() {
|
||||
ChefApi api = requestSendsResponse(
|
||||
signed(HttpRequest.builder() //
|
||||
.method("GET") //
|
||||
.endpoint("http://localhost:4000/environments/dev/nodes") //
|
||||
.addHeader("X-Chef-Version", ChefApi.VERSION) //
|
||||
.addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
|
||||
HttpResponse.builder().statusCode(200)
|
||||
.payload(payloadFromResourceWithContentType("/environment_nodes.json", MediaType.APPLICATION_JSON)) //
|
||||
.build());
|
||||
Set<String> nodes = api.listEnvironmentNodes("dev");
|
||||
assertEquals(nodes.size(), 3);
|
||||
assertTrue(nodes.contains("blah"));
|
||||
}
|
||||
|
||||
public void testListEnvironmentNodesReturns404() {
|
||||
ChefApi api = requestSendsResponse(
|
||||
signed(HttpRequest.builder() //
|
||||
.method("GET") //
|
||||
.endpoint("http://localhost:4000/environments/dev/nodes") //
|
||||
.addHeader("X-Chef-Version", ChefApi.VERSION) //
|
||||
.addHeader("Accept", MediaType.APPLICATION_JSON).build()), //
|
||||
HttpResponse.builder().statusCode(404)
|
||||
.build());
|
||||
|
||||
assertTrue(api.listEnvironmentNodes("dev").isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Module createModule() {
|
||||
return new TestChefRestClientModule();
|
||||
|
|
|
@ -72,6 +72,7 @@ import com.google.common.primitives.Bytes;
|
|||
public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiveTest<A> {
|
||||
public static final String PREFIX = "jcloudstest-" + System.getProperty("user.name");
|
||||
public static final String ADMIN_PREFIX = "jcloudstest-adm-" + System.getProperty("user.name");
|
||||
public static final String ENV_NODE = PREFIX + "-env-node";
|
||||
|
||||
// It may take a bit until the search index is populated
|
||||
protected int maxWaitForIndexInMs = 60000;
|
||||
|
@ -470,12 +471,23 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
|
|||
assertTrue(!recipeList.isEmpty());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateEnvironment")
|
||||
public void testListEnvironmentNodes() {
|
||||
api.deleteNode(ENV_NODE);
|
||||
api.createNode(Node.builder().name(ENV_NODE).runListElement("role[" + PREFIX + "]").environment(PREFIX).build());
|
||||
node = api.getNode(ENV_NODE);
|
||||
assertNotNull(node, "Created node should not be null");
|
||||
Set<String> nodeList = api.listEnvironmentNodes(PREFIX);
|
||||
assertTrue(!nodeList.isEmpty());
|
||||
}
|
||||
|
||||
@AfterClass(groups = { "live", "integration" })
|
||||
@Override
|
||||
public void tearDown() {
|
||||
api.deleteClient(PREFIX);
|
||||
api.deleteClient(ADMIN_PREFIX);
|
||||
api.deleteNode(PREFIX);
|
||||
api.deleteNode(ENV_NODE);
|
||||
api.deleteRole(PREFIX);
|
||||
api.deleteDatabag(PREFIX);
|
||||
api.deleteEnvironment(PREFIX);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"blah": "https://api.opscode.com/org/directory/nodes/blah",
|
||||
"boxer": "https://api.opscode.com/org/directory/nodes/boxer",
|
||||
"blarrrrgh": "https://api.opscode.com/org/directory/nodes/blarrrrgh"
|
||||
}
|
Loading…
Reference in New Issue