@Override public Iterable<? extends NodeMetadata> listNodesByIds(Iterable<String> ids) { return FluentIterable.from(listDetailsOnNodesMatching(all())).filter(withIds(toArray(ids, String.class))).toSet(); }
@Override public Iterable<? extends NodeMetadata> listNodesByIds(Iterable<String> ids) { return FluentIterable.from(listDetailsOnNodesMatching(all())).filter(withIds(toArray(ids, String.class))).toSet(); }
@Override public Iterable<? extends NodeMetadata> listNodesByIds(Iterable<String> ids) { return FluentIterable.from(listDetailsOnNodesMatching(all())).filter(withIds(toArray(ids, String.class))).toSet(); }
@Override public Iterable<? extends NodeMetadata> listNodesByIds(Iterable<String> ids) { return FluentIterable.from(listDetailsOnNodesMatching(all())).filter(withIds(toArray(ids, String.class))).toSet(); }
@Override public Iterable<? extends NodeMetadata> listNodesByIds(Iterable<String> ids) { return FluentIterable.from(listDetailsOnNodesMatching(all())).filter(withIds(toArray(ids, String.class))).toSet(); }
private Predicate<NodeMetadata> buildFilterPredicate(String[] ids, String[] roles, ClusterSpec spec) throws IOException { Predicate<NodeMetadata> condition = Predicates.alwaysTrue(); if (ids != null && ids.length > 0) { return Predicates.and(condition, withIds(ids)); } else if (roles != null && roles.length > 0) { List<String> instanceIds = Lists.newArrayList(); Cluster cluster = createClusterStateStore(spec).load(); for (Cluster.Instance instance : cluster.getInstancesMatching( anyRoleIn(Sets.<String>newHashSet(roles)))) { instanceIds.add(instance.getId()); } condition = Predicates.and(condition, withIds(instanceIds.toArray(new String[0]))); return condition; } else { return condition; } }
private Predicate<NodeMetadata> buildFilterPredicate(String[] ids, String[] roles, ClusterSpec spec) throws IOException { Predicate<NodeMetadata> condition = Predicates.alwaysTrue(); if (ids != null && ids.length > 0) { return Predicates.and(condition, withIds(ids)); } else if (roles != null && roles.length > 0) { List<String> instanceIds = Lists.newArrayList(); Cluster cluster = createClusterStateStore(spec).load(); for (Cluster.Instance instance : cluster.getInstancesMatching( anyRoleIn(Sets.<String>newHashSet(roles)))) { instanceIds.add(instance.getId()); } condition = Predicates.and(condition, withIds(instanceIds.toArray(new String[0]))); return condition; } else { return condition; } }
@Test public void testRunScriptByInstanceId() throws Exception { ClusterControllerFactory factory = mock(ClusterControllerFactory.class); ClusterController controller = mock(ClusterController.class); when(factory.create((String)any())).thenReturn(controller); RunScriptCommand command = new RunScriptCommand(factory); Map<String, File> keys = KeyPair.generateTemporaryFiles(); int rc = command.run(null, out, System.err, Lists.newArrayList( "--script", "/dev/null", "--instance-templates", "1 noop", "--instances", "A,B", "--cluster-name", "test-cluster", "--provider", "provider", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath() )); assertThat(rc, is(0)); ArgumentCaptor<Predicate> predicate = ArgumentCaptor.forClass(Predicate.class); verify(controller).runScriptOnNodesMatching( (ClusterSpec)any(), predicate.capture(), (Statement) any()); // check predicate equality by using the object string representation Predicate<NodeMetadata> expected = Predicates.and( Predicates.<NodeMetadata>alwaysTrue(), withIds("A", "B")); assertThat(predicate.getValue().toString(), is(expected.toString())); }
@Test(timeout = TestConstants.ITEST_TIMEOUT) public void testBinMahout() throws Exception { Statement binMahout = Statements.exec("source /etc/profile; $MAHOUT_HOME/bin/mahout"); Cluster.Instance mahoutInstance = findMahoutInstance(); Predicate<NodeMetadata> mahoutClientRole = and(alwaysTrue(), withIds(mahoutInstance.getId())); Map<? extends NodeMetadata, ExecResponse> responses = controller.runScriptOnNodesMatching(clusterSpec, mahoutClientRole, binMahout); LOG.info("Responses for Statement: " + binMahout); for (Map.Entry<? extends NodeMetadata, ExecResponse> entry : responses.entrySet()) { LOG.info("Node[" + entry.getKey().getId() + "]: " + entry.getValue()); } assertResponsesContain(responses, binMahout, "Running on hadoop"); }
@Test(timeout = TestConstants.ITEST_TIMEOUT) public void testPigBin() throws Exception { Statement binPig = Statements.exec(". /etc/profile && pig -e fs -ls /"); Cluster.Instance pigInstance = findPigInstance(); Predicate<NodeMetadata> pigClientRole = and(alwaysTrue(), withIds(pigInstance.getId())); Map<? extends NodeMetadata, ExecResponse> responses = controller.runScriptOnNodesMatching(clusterSpec, pigClientRole, binPig); LOG.info("Responses for Statement: " + binPig); for (Map.Entry<? extends NodeMetadata, ExecResponse> entry : responses.entrySet()) { LOG.info("Node[" + entry.getKey().getId() + "]: " + entry.getValue()); } assertResponsesContain(responses, binPig, "/hadoop"); }
@Test public void testRunScriptByRole() throws Exception { ClusterControllerFactory factory = mock(ClusterControllerFactory.class); ClusterController controller = mock(ClusterController.class); when(factory.create((String)any())).thenReturn(controller); ClusterStateStore memStore = new MemoryClusterStateStore(); memStore.save(createTestCluster( new String[]{"reg/A", "reg/B"}, new String[]{"A", "B"})); ClusterStateStoreFactory stateStoreFactory = mock(ClusterStateStoreFactory.class); when(stateStoreFactory.create((ClusterSpec) any())).thenReturn(memStore); RunScriptCommand command = new RunScriptCommand(factory, stateStoreFactory); Map<String, File> keys = KeyPair.generateTemporaryFiles(); int rc = command.run(null, out, System.err, Lists.newArrayList( "--instance-templates", "1 noop", "--script", "/dev/null", "--roles", "A", "--cluster-name", "test-cluster", "--provider", "provider", "--identity", "myusername", "--credential", "mypassword", "--private-key-file", keys.get("private").getAbsolutePath() )); assertThat(rc, is(0)); ArgumentCaptor<Predicate> predicate = ArgumentCaptor.forClass(Predicate.class); verify(controller).runScriptOnNodesMatching( (ClusterSpec)any(), predicate.capture(), (Statement) any()); // check predicate equality by using the object string representation Predicate<NodeMetadata> expected = Predicates.and( Predicates.<NodeMetadata>alwaysTrue(), withIds("reg/A")); assertThat(predicate.getValue().toString(), is(expected.toString())); }