use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class FirewallManager method authorizeIngress.
public static void authorizeIngress(ComputeServiceContext computeServiceContext, Set<Instance> instances, final ClusterSpec clusterSpec, List<String> cidrs, int... ports) {
try {
if (computeServiceContext.getComputeService().getSecurityGroupExtension().isPresent()) {
SecurityGroupExtension securityGroupExtension = computeServiceContext.getComputeService().getSecurityGroupExtension().get();
Instance instance = Iterables.getFirst(instances, null);
if (instance != null) {
SecurityGroup group = Iterables.find(securityGroupExtension.listSecurityGroupsForNode(instance.getNodeMetadata().getId()), new Predicate<SecurityGroup>() {
@Override
public boolean apply(SecurityGroup input) {
if (input.getName().contains(clusterSpec.getClusterName()) || input.getId().contains(clusterSpec.getClusterName())) {
return true;
}
// To change body of implemented methods use File | Settings | File Templates.
return false;
}
});
if (group == null) {
group = securityGroupExtension.createSecurityGroup(clusterSpec.getClusterName(), instance.getNodeMetadata().getLocation());
}
for (int port : ports) {
IpPermission.Builder builder = IpPermission.builder();
builder.cidrBlocks(cidrs);
builder.ipProtocol(IpProtocol.TCP);
builder.fromPort(port);
builder.toPort(port);
securityGroupExtension.addIpPermission(builder.build(), group);
}
} else {
LOG.warn("Cannot find any instance for group, so cannot determine security group.");
}
} else {
LOG.warn("No security group extension present for provider, so cannot set up security group.");
}
} catch (Exception e) {
LOG.error("Error setting up security groups: {}", e);
}
}
use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class UtilsTest method testPrintAccess.
@Test
public void testPrintAccess() {
final Instance instance = mock(Instance.class);
when(instance.getPublicIp()).thenReturn("test-public-ip");
when(instance.getRoles()).thenReturn(ImmutableSet.of("test-role"));
Cluster cluster = mock(Cluster.class);
when(cluster.getInstances()).thenReturn(ImmutableSet.<Cluster.Instance>of(instance));
ClusterSpec spec = mock(ClusterSpec.class);
when(spec.getClusterUser()).thenReturn("test-identity");
when(spec.getPrivateKeyFile()).thenReturn(new File("/test/key/path"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
Utils.printSSHConnectionDetails(ps, spec, cluster, 20);
assertEquals("The ssh command did not match", EXPECTED_SSH_COMMAND, new String(baos.toByteArray()));
}
use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class CassandraClusterActionHandlerTest method testGetSeeds.
@Test()
public void testGetSeeds() throws UnknownHostException {
Instance one = getInstance("1");
Instance two = getInstance("2");
Set<Instance> instances = Sets.newLinkedHashSet();
instances.add(one);
CassandraClusterActionHandler handler = new CassandraClusterActionHandler();
// check that the one node is returned
List<Instance> seeds1 = handler.getSeeds(instances);
assertEquals(1, seeds1.size());
assertEquals(one, seeds1.get(0));
// add more nodes, should get two seeds
instances.add(two);
for (int i = 3; i < 10; i++) {
instances.add(getInstance(Integer.toString(i)));
}
List<Instance> seeds2 = handler.getSeeds(instances);
assertEquals(2, seeds2.size());
assertEquals(one, seeds2.get(0));
assertEquals(two, seeds2.get(1));
}
use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class CassandraServiceTest method waitForCassandra.
private void waitForCassandra() {
LOG.info("Waiting for Cassandra to start");
for (Instance instance : cluster.getInstances()) {
int tries = 0;
while (tries < 30) {
try {
Cassandra.Client client = client(instance);
client.describe_cluster_name();
client.getOutputProtocol().getTransport().close();
LOG.info(instance.getPublicIp() + " is up and running");
break;
} catch (TException e) {
try {
LOG.warn(instance.getPublicIp() + " not reachable, try #" + tries + ", waiting 1s");
Thread.sleep(10000);
} catch (InterruptedException e1) {
break;
}
tries += 1;
}
}
if (tries == 10) {
LOG.error("Instance " + instance.getPublicIp() + " is still unavailable after 10 retries");
}
}
}
use of org.apache.whirr.Cluster.Instance in project whirr by apache.
the class CassandraServiceTest method testInstances.
@Test(timeout = TestConstants.ITEST_TIMEOUT)
public void testInstances() throws Exception {
Set<String> endPoints = Sets.newLinkedHashSet();
for (Instance instance : cluster.getInstances()) {
Cassandra.Client client = client(instance);
Map<String, List<String>> tr = client.describe_schema_versions();
for (List<String> version : tr.values()) {
endPoints.addAll(version);
}
client.getOutputProtocol().getTransport().close();
}
LOG.info("List of endpoints: " + endPoints);
for (Instance instance : cluster.getInstances()) {
String address = instance.getPrivateAddress().getHostAddress();
assertTrue(address + " not in cluster!", endPoints.remove(address));
}
assertTrue("Unknown node returned: " + endPoints.toString(), endPoints.isEmpty());
}
Aggregations