Search in sources :

Example 6 with Cluster

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();
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Cluster(com.netflix.simianarmy.conformity.Cluster) Date(java.util.Date)

Example 7 with Cluster

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, ",")));
    }
}
Also used : Cluster(com.netflix.simianarmy.conformity.Cluster)

Example 8 with Cluster

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 = ?");
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.netflix.simianarmy.conformity.Cluster) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.testng.annotations.Test)

Example 9 with Cluster

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')");
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.netflix.simianarmy.conformity.Cluster) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.testng.annotations.Test)

Example 10 with Cluster

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);
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.netflix.simianarmy.conformity.Cluster) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.testng.annotations.Test)

Aggregations

Cluster (com.netflix.simianarmy.conformity.Cluster)18 Test (org.testng.annotations.Test)8 ArrayList (java.util.ArrayList)5 RowMapper (org.springframework.jdbc.core.RowMapper)5 Conformity (com.netflix.simianarmy.conformity.Conformity)4 Date (java.util.Date)3 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)2 Item (com.amazonaws.services.simpledb.model.Item)2 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)2 Instance (com.amazonaws.services.autoscaling.model.Instance)1 SuspendedProcess (com.amazonaws.services.autoscaling.model.SuspendedProcess)1 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)1 DeleteAttributesRequest (com.amazonaws.services.simpledb.model.DeleteAttributesRequest)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AWSClusterCrawler (com.netflix.simianarmy.aws.conformity.crawler.AWSClusterCrawler)1 BasicConfiguration (com.netflix.simianarmy.basic.BasicConfiguration)1 BasicConformityMonkeyContext (com.netflix.simianarmy.basic.conformity.BasicConformityMonkeyContext)1 AutoScalingGroup (com.netflix.simianarmy.conformity.AutoScalingGroup)1 ResultSet (java.sql.ResultSet)1