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")
|
@Path("/environments/{environmentname}/recipes")
|
||||||
@Fallback(EmptySetOnNotFoundOr404.class)
|
@Fallback(EmptySetOnNotFoundOr404.class)
|
||||||
Set<String> listEnvironmentRecipes(@PathParam("environmentname") String environmentname);
|
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();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<String> listEnvironmentNodes(String environmentname) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
closer.close();
|
closer.close();
|
||||||
|
|
|
@ -74,6 +74,34 @@ public class ChefApiExpectTest extends BaseChefApiExpectTest<ChefApi> {
|
||||||
assertTrue(api.listEnvironmentRecipes("dev").isEmpty());
|
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
|
@Override
|
||||||
protected Module createModule() {
|
protected Module createModule() {
|
||||||
return new TestChefRestClientModule();
|
return new TestChefRestClientModule();
|
||||||
|
|
|
@ -72,6 +72,7 @@ import com.google.common.primitives.Bytes;
|
||||||
public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiveTest<A> {
|
public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiveTest<A> {
|
||||||
public static final String PREFIX = "jcloudstest-" + System.getProperty("user.name");
|
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 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
|
// It may take a bit until the search index is populated
|
||||||
protected int maxWaitForIndexInMs = 60000;
|
protected int maxWaitForIndexInMs = 60000;
|
||||||
|
@ -470,12 +471,23 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
|
||||||
assertTrue(!recipeList.isEmpty());
|
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" })
|
@AfterClass(groups = { "live", "integration" })
|
||||||
@Override
|
@Override
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
api.deleteClient(PREFIX);
|
api.deleteClient(PREFIX);
|
||||||
api.deleteClient(ADMIN_PREFIX);
|
api.deleteClient(ADMIN_PREFIX);
|
||||||
api.deleteNode(PREFIX);
|
api.deleteNode(PREFIX);
|
||||||
|
api.deleteNode(ENV_NODE);
|
||||||
api.deleteRole(PREFIX);
|
api.deleteRole(PREFIX);
|
||||||
api.deleteDatabag(PREFIX);
|
api.deleteDatabag(PREFIX);
|
||||||
api.deleteEnvironment(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