use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.
the class BasicConformityMonkey method doMonkeyBusiness.
/** {@inheritDoc} */
@Override
public void doMonkeyBusiness() {
cfg.reload();
context().resetEventReport();
if (isConformityMonkeyEnabled()) {
nonconformingClusters.clear();
conformingClusters.clear();
failedClusters.clear();
nonexistentClusters.clear();
List<Cluster> clusters = crawler.clusters();
Map<String, Set<String>> existingClusterNamesByRegion = Maps.newHashMap();
for (String region : regions) {
existingClusterNamesByRegion.put(region, new HashSet<String>());
}
for (Cluster cluster : clusters) {
existingClusterNamesByRegion.get(cluster.getRegion()).add(cluster.getName());
}
List<Cluster> trackedClusters = clusterTracker.getAllClusters(regions.toArray(new String[regions.size()]));
for (Cluster trackedCluster : trackedClusters) {
if (!existingClusterNamesByRegion.get(trackedCluster.getRegion()).contains(trackedCluster.getName())) {
addCluster(nonexistentClusters, trackedCluster);
}
}
for (String region : regions) {
Collection<Cluster> toDelete = nonexistentClusters.get(region);
if (toDelete != null) {
clusterTracker.deleteClusters(toDelete.toArray(new Cluster[toDelete.size()]));
}
}
LOGGER.info(String.format("Performing conformity check for %d crawled clusters.", clusters.size()));
Date now = calendar.now().getTime();
for (Cluster cluster : clusters) {
boolean conforming;
try {
conforming = ruleEngine.check(cluster);
} catch (Exception e) {
LOGGER.error(String.format("Failed to perform conformity check for cluster %s", cluster.getName()), e);
addCluster(failedClusters, cluster);
continue;
}
cluster.setUpdateTime(now);
cluster.setConforming(conforming);
if (conforming) {
LOGGER.info(String.format("Cluster %s is conforming", cluster.getName()));
addCluster(conformingClusters, cluster);
} else {
LOGGER.info(String.format("Cluster %s is not conforming", cluster.getName()));
addCluster(nonconformingClusters, cluster);
}
if (!leashed) {
LOGGER.info(String.format("Saving cluster %s", cluster.getName()));
clusterTracker.addOrUpdate(cluster);
} else {
LOGGER.info(String.format("The conformity monkey is leashed, no data change is made for cluster %s.", cluster.getName()));
}
}
if (!leashed) {
emailNotifier.sendNotifications();
} else {
LOGGER.info("Conformity monkey is leashed, no notification is sent.");
}
if (cfg.getBoolOrElse(NS + "summaryEmail.enabled", true)) {
sendConformitySummaryEmail();
}
}
}
use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.
the class BasicConformityMonkey method appendSummary.
private void appendSummary(StringBuilder message, String summaryName, Map<String, Collection<Cluster>> regionToClusters, String region, boolean showDetails) {
Collection<Cluster> clusters = regionToClusters.get(region);
if (clusters == null) {
clusters = Lists.newArrayList();
}
message.append(String.format("Total %s clusters = %d in region %s<br/>", summaryName, clusters.size(), region));
if (showDetails) {
List<String> clusterNames = Lists.newArrayList();
for (Cluster cluster : clusters) {
clusterNames.add(cluster.getName());
}
message.append(String.format("List: %s<br/><br/>", StringUtils.join(clusterNames, ",")));
}
}
use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.
the class TestRDSConformityClusterTracker method testGetCluster.
@SuppressWarnings("unchecked")
@Test
public void testGetCluster() {
Cluster cluster1 = new Cluster("clustername1", "us-west-1");
ArrayList<Cluster> clusters = new ArrayList<>();
clusters.add(cluster1);
TestRDSConformityClusterTracker tracker = new TestRDSConformityClusterTracker();
ArgumentCaptor<String> sqlCap = ArgumentCaptor.forClass(String.class);
when(tracker.getJdbcTemplate().query(sqlCap.capture(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))).thenReturn(clusters);
Cluster result = tracker.getCluster("clustername1", "us-west-1");
Assert.assertNotNull(result);
Assert.assertEquals(sqlCap.getValue(), "select * from conformitytable where cluster = ? and region = ?");
}
use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.
the class TestRDSConformityClusterTracker method testGetClusters.
@SuppressWarnings("unchecked")
@Test
public void testGetClusters() {
Cluster cluster1 = new Cluster("clustername1", "us-west-1");
Cluster cluster2 = new Cluster("clustername1", "us-west-2");
Cluster cluster3 = new Cluster("clustername1", "us-east-1");
ArrayList<Cluster> clusters = new ArrayList<>();
clusters.add(cluster1);
clusters.add(cluster2);
clusters.add(cluster3);
TestRDSConformityClusterTracker tracker = new TestRDSConformityClusterTracker();
ArgumentCaptor<String> sqlCap = ArgumentCaptor.forClass(String.class);
when(tracker.getJdbcTemplate().query(sqlCap.capture(), Matchers.any(RowMapper.class))).thenReturn(clusters);
List<Cluster> results = tracker.getAllClusters("us-west-1", "us-west-2", "us-east-1");
Assert.assertEquals(results.size(), 3);
Assert.assertEquals(sqlCap.getValue().toString().trim(), "select * from conformitytable where cluster is not null and region in ('us-west-1','us-west-2','us-east-1')");
}
use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.
the class TestRDSConformityClusterTracker method testGetClusterNotFound.
@SuppressWarnings("unchecked")
@Test
public void testGetClusterNotFound() {
ArrayList<Cluster> clusters = new ArrayList<>();
TestRDSConformityClusterTracker tracker = new TestRDSConformityClusterTracker();
when(tracker.getJdbcTemplate().query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))).thenReturn(clusters);
Cluster cluster = tracker.getCluster("clustername", "us-west-1");
Assert.assertNull(cluster);
}
Aggregations