Search in sources :

Example 1 with NodeMetadataBuilder

use of org.jclouds.compute.domain.NodeMetadataBuilder in project whirr by apache.

the class ListClusterCommandTest method testAllOptions.

@Test
public void testAllOptions() throws Exception {
    ClusterControllerFactory factory = mock(ClusterControllerFactory.class);
    ClusterController controller = mock(ClusterController.class);
    when(factory.create((String) any())).thenReturn(controller);
    NodeMetadata node1 = new NodeMetadataBuilder().name("name1").ids("id1").location(new LocationBuilder().scope(LocationScope.PROVIDER).id("location-id1").description("location-desc1").build()).imageId("image-id").status(NodeMetadata.Status.RUNNING).publicAddresses(Lists.newArrayList("127.0.0.1")).privateAddresses(Lists.newArrayList("127.0.0.1")).build();
    NodeMetadata node2 = new NodeMetadataBuilder().name("name2").ids("id2").location(new LocationBuilder().scope(LocationScope.PROVIDER).id("location-id2").description("location-desc2").build()).imageId("image-id").status(NodeMetadata.Status.RUNNING).publicAddresses(Lists.newArrayList("127.0.0.2")).privateAddresses(Lists.newArrayList("127.0.0.2")).build();
    when(controller.getNodes((ClusterSpec) any())).thenReturn((Set) Sets.newLinkedHashSet(Lists.newArrayList(node1, node2)));
    when(controller.getInstances((ClusterSpec) any(), (ClusterStateStore) any())).thenCallRealMethod();
    ClusterStateStore memStore = new MemoryClusterStateStore();
    memStore.save(createTestCluster(new String[] { "id1", "id2" }, new String[] { "role1", "role2" }));
    ClusterStateStoreFactory stateStoreFactory = mock(ClusterStateStoreFactory.class);
    when(stateStoreFactory.create((ClusterSpec) any())).thenReturn(memStore);
    ListClusterCommand command = new ListClusterCommand(factory, stateStoreFactory);
    Map<String, File> keys = KeyPair.generateTemporaryFiles();
    int rc = command.run(null, out, null, Lists.newArrayList("--instance-templates", "1 noop", "--service-name", "test-service", "--cluster-name", "test-cluster", "--identity", "myusername", "--quiet", "--private-key-file", keys.get("private").getAbsolutePath()));
    assertThat(rc, is(0));
    assertThat(outBytes.toString(), is("id1\timage-id\t127.0.0.1\t127.0.0.1\tRUNNING\tlocation-id1\trole1\n" + "id2\timage-id\t127.0.0.2\t127.0.0.2\tRUNNING\tlocation-id2\trole2\n"));
    verify(factory).create("test-service");
}
Also used : MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStore(org.apache.whirr.state.ClusterStateStore) Matchers.containsString(org.hamcrest.Matchers.containsString) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) NodeMetadataBuilder(org.jclouds.compute.domain.NodeMetadataBuilder) ClusterController(org.apache.whirr.ClusterController) MemoryClusterStateStore(org.apache.whirr.state.MemoryClusterStateStore) ClusterStateStoreFactory(org.apache.whirr.state.ClusterStateStoreFactory) LocationBuilder(org.jclouds.domain.LocationBuilder) ClusterControllerFactory(org.apache.whirr.ClusterControllerFactory) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 ClusterController (org.apache.whirr.ClusterController)1 ClusterControllerFactory (org.apache.whirr.ClusterControllerFactory)1 ClusterStateStore (org.apache.whirr.state.ClusterStateStore)1 ClusterStateStoreFactory (org.apache.whirr.state.ClusterStateStoreFactory)1 MemoryClusterStateStore (org.apache.whirr.state.MemoryClusterStateStore)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)1 NodeMetadataBuilder (org.jclouds.compute.domain.NodeMetadataBuilder)1 LocationBuilder (org.jclouds.domain.LocationBuilder)1 Test (org.junit.Test)1