Search in sources :

Example 31 with Instance

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);
    }
}
Also used : SecurityGroupExtension(org.jclouds.compute.extensions.SecurityGroupExtension) Instance(org.apache.whirr.Cluster.Instance) IpPermission(org.jclouds.net.domain.IpPermission) SecurityGroup(org.jclouds.compute.domain.SecurityGroup) IOException(java.io.IOException)

Example 32 with Instance

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()));
}
Also used : PrintStream(java.io.PrintStream) Instance(org.apache.whirr.Cluster.Instance) Cluster(org.apache.whirr.Cluster) ClusterSpec(org.apache.whirr.ClusterSpec) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) Test(org.junit.Test)

Example 33 with Instance

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));
}
Also used : Instance(org.apache.whirr.Cluster.Instance) Test(org.junit.Test)

Example 34 with Instance

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");
        }
    }
}
Also used : TException(org.apache.thrift.TException) Instance(org.apache.whirr.Cluster.Instance) Cassandra(org.apache.cassandra.thrift.Cassandra)

Example 35 with Instance

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());
}
Also used : Instance(org.apache.whirr.Cluster.Instance) Cassandra(org.apache.cassandra.thrift.Cassandra) List(java.util.List) Test(org.junit.Test)

Aggregations

Instance (org.apache.whirr.Cluster.Instance)36 Cluster (org.apache.whirr.Cluster)19 ClusterSpec (org.apache.whirr.ClusterSpec)14 Configuration (org.apache.commons.configuration.Configuration)10 IOException (java.io.IOException)9 InetAddress (java.net.InetAddress)6 ZooKeeperCluster (org.apache.whirr.service.zookeeper.ZooKeeperCluster)6 Test (org.junit.Test)6 ConfigurationException (org.apache.commons.configuration.ConfigurationException)4 StatementBuilder (org.apache.whirr.service.jclouds.StatementBuilder)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Properties (java.util.Properties)3 ExecutionException (java.util.concurrent.ExecutionException)3 Future (java.util.concurrent.Future)3 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)3 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)3 InstanceTemplate (org.apache.whirr.InstanceTemplate)3 ClusterActionEvent (org.apache.whirr.service.ClusterActionEvent)3 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)3 Cassandra (org.apache.cassandra.thrift.Cassandra)2