Search in sources :

Example 6 with ClusterTopology

use of com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology in project esop by instaclustr.

the class CassandraClusterTopologyTest method testDcFiltering.

@Test
public void testDcFiltering() throws Exception {
    final ClusterTopology topology = getClusterTopology();
    ClusterTopology filtered = ClusterTopology.filter(topology, "dc1");
    Assert.assertEquals(topology.schemaVersion, filtered.schemaVersion);
    Assert.assertEquals(3, topology.endpointDcs.size());
    Assert.assertEquals(3, topology.endpoints.size());
    Assert.assertEquals(3, topology.hostnames.size());
    Assert.assertEquals(3, topology.endpointRacks.size());
}
Also used : ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) Test(org.testng.annotations.Test)

Example 7 with ClusterTopology

use of com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology in project esop by instaclustr.

the class CassandraClusterTopologyTest method testMultipleDcFiltering.

@Test
public void testMultipleDcFiltering() throws Exception {
    final ClusterTopology topology = getClusterTopology();
    ClusterTopology filtered = ClusterTopology.filter(topology, " dc1,   dc2   ,");
    Assert.assertEquals(topology.schemaVersion, filtered.schemaVersion);
    Assert.assertEquals(6, topology.endpointDcs.size());
    Assert.assertEquals(6, topology.endpoints.size());
    Assert.assertEquals(6, topology.hostnames.size());
    Assert.assertEquals(6, topology.endpointRacks.size());
}
Also used : ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) Test(org.testng.annotations.Test)

Example 8 with ClusterTopology

use of com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology in project esop by instaclustr.

the class CassandraClusterTopology method act.

@Override
public ClusterTopology act() throws Exception {
    final String clusterName = new CassandraClusterName(cassandraJMXService).act();
    // map of endpoints and host ids
    final Map<InetAddress, UUID> endpoints = new CassandraEndpoints(cassandraJMXService).act();
    // map of endpoints and dc they belong to
    final Map<InetAddress, String> endpointDcs = new CassandraEndpointDC(cassandraJMXService, endpoints.keySet()).act();
    // map of endpoints and hostnames
    final Map<InetAddress, String> hostnames = new CassandraHostname(endpoints.keySet()).act();
    // map of endpoints and rack they belong to
    final Map<InetAddress, String> endpointRacks = new CassandraEndpointRack(cassandraJMXService, endpoints.keySet()).act();
    final String schemaVersion = new CassandraSchemaVersion(cassandraJMXService).act();
    final ClusterTopology resolvedTopology = constructTopology(clusterName, endpoints, endpointDcs, hostnames, endpointRacks, schemaVersion);
    final Set<String> invalidDcs = ClusterTopology.sanitizeDcs(dcs).stream().filter(dc -> !resolvedTopology.getDcs().contains(dc)).collect(toSet());
    if (!invalidDcs.isEmpty()) {
        throw new IllegalStateException(format("Some DCs to filter on do not exist: %s, existing: %s", invalidDcs, String.join(",", resolvedTopology.getDcs())));
    }
    logger.info(resolvedTopology.toString());
    return resolvedTopology;
}
Also used : Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) CassandraInteraction(com.instaclustr.cassandra.CassandraInteraction) Path(java.nio.file.Path) Collectors.toSet(java.util.stream.Collectors.toSet) Backuper(com.instaclustr.esop.impl.backup.Backuper) CassandraSchemaVersion(com.instaclustr.esop.impl.interaction.CassandraSchemaVersion) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) MoreObjects(com.google.common.base.MoreObjects) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) File(java.io.File) Objects(java.util.Objects) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Paths(java.nio.file.Paths) Entry(java.util.Map.Entry) Optional(java.util.Optional) Collections(java.util.Collections) ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) CassandraJMXService(jmx.org.apache.cassandra.service.CassandraJMXService) ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) CassandraSchemaVersion(com.instaclustr.esop.impl.interaction.CassandraSchemaVersion) UUID(java.util.UUID) InetAddress(java.net.InetAddress)

Example 9 with ClusterTopology

use of com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology in project esop by instaclustr.

the class CassandraClusterTopology method constructTopology.

private ClusterTopology constructTopology(final String clusterName, final Map<InetAddress, UUID> endpoints, final Map<InetAddress, String> endpointDcs, final Map<InetAddress, String> hostnames, final Map<InetAddress, String> endpointRacks, final String schemaVersion) {
    final ClusterTopology topology = new ClusterTopology();
    topology.setTimestamp(System.currentTimeMillis());
    for (InetAddress inetAddress : endpoints.keySet()) {
        final ClusterTopology.NodeTopology nodeTopology = new ClusterTopology.NodeTopology();
        nodeTopology.setCluster(clusterName);
        nodeTopology.setDc(endpointDcs.get(inetAddress));
        nodeTopology.setNodeId(endpoints.get(inetAddress));
        nodeTopology.setHostname(hostnames.get(inetAddress));
        nodeTopology.setRack(endpointRacks.get(inetAddress));
        nodeTopology.setIpAddress(inetAddress.getHostAddress());
        topology.topology.add(nodeTopology);
    }
    topology.clusterName = clusterName;
    topology.schemaVersion = schemaVersion;
    topology.endpoints = endpoints;
    topology.endpointDcs = endpointDcs;
    topology.hostnames = hostnames;
    topology.endpointRacks = endpointRacks;
    return ClusterTopology.filter(topology, dcs);
}
Also used : ClusterTopology(com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology) InetAddress(java.net.InetAddress)

Aggregations

ClusterTopology (com.instaclustr.esop.topology.CassandraClusterTopology.ClusterTopology)9 InetAddress (java.net.InetAddress)4 Test (org.testng.annotations.Test)4 UUID (java.util.UUID)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Backuper (com.instaclustr.esop.impl.backup.Backuper)2 CassandraSchemaVersion (com.instaclustr.esop.impl.interaction.CassandraSchemaVersion)2 IOException (java.io.IOException)2 String.format (java.lang.String.format)2 Path (java.nio.file.Path)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 MoreObjects (com.google.common.base.MoreObjects)1 CassandraInteraction (com.instaclustr.cassandra.CassandraInteraction)1 CassandraVersion (com.instaclustr.cassandra.CassandraVersion)1