Search in sources :

Example 11 with Cluster

use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.

the class TestRDSConformityClusterTracker method testUpdateCluster.

@SuppressWarnings("unchecked")
@Test
public void testUpdateCluster() {
    Cluster cluster1 = new Cluster("clustername1", "us-west-1");
    Date date = new Date();
    cluster1.setUpdateTime(date);
    // mock the select query that is issued to see if the record already exists
    ArrayList<Cluster> clusters = new ArrayList<>();
    clusters.add(cluster1);
    TestRDSConformityClusterTracker tracker = new TestRDSConformityClusterTracker();
    when(tracker.getJdbcTemplate().query(Matchers.anyString(), Matchers.any(Object[].class), Matchers.any(RowMapper.class))).thenReturn(clusters);
    cluster1.setOwnerEmail("newemail@test.com");
    ArgumentCaptor<Object> objCap = ArgumentCaptor.forClass(Object.class);
    ArgumentCaptor<String> sqlCap = ArgumentCaptor.forClass(String.class);
    when(tracker.getJdbcTemplate().update(sqlCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture(), objCap.capture())).thenReturn(1);
    tracker.addOrUpdate(cluster1);
    List<Object> args = objCap.getAllValues();
    Assert.assertEquals(sqlCap.getValue(), "update conformitytable set ownerEmail=?,isConforming=?,isOptedOut=?,updateTimestamp=?,excludedRules=?,conformities=?,conformityRules=? where cluster=? and region=?");
    Assert.assertEquals(args.size(), 9);
    Assert.assertEquals(args.get(0).toString(), "newemail@test.com");
    Assert.assertEquals(args.get(1).toString(), "false");
    Assert.assertEquals(args.get(2).toString(), "false");
    Assert.assertEquals(args.get(3).toString(), date.getTime() + "");
    Assert.assertEquals(args.get(7).toString(), "clustername1");
    Assert.assertEquals(args.get(8).toString(), "us-west-1");
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.netflix.simianarmy.conformity.Cluster) Date(java.util.Date) RowMapper(org.springframework.jdbc.core.RowMapper) Test(org.testng.annotations.Test)

Example 12 with Cluster

use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.

the class TestInstanceInVPC method testCheckSoloInstances.

@Test
public void testCheckSoloInstances() throws Exception {
    Set<String> list = Sets.newHashSet();
    list.add(VPC_INSTANCE_ID);
    list.add(INSTANCE_ID);
    Cluster cluster = new Cluster("SoloInstances", REGION, list);
    Conformity result = instanceInVPC.check(cluster);
    Assert.assertNotNull(result);
    Assert.assertEquals(result.getRuleId(), instanceInVPC.getName());
    Assert.assertEquals(result.getFailedComponents().size(), 1);
    Assert.assertEquals(result.getFailedComponents().iterator().next(), INSTANCE_ID);
}
Also used : Cluster(com.netflix.simianarmy.conformity.Cluster) Conformity(com.netflix.simianarmy.conformity.Conformity) Test(org.testng.annotations.Test)

Example 13 with Cluster

use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.

the class RDSConformityClusterTracker method getCluster.

@Override
public Cluster getCluster(String clusterName, String region) {
    Validate.notEmpty(clusterName);
    Validate.notEmpty(region);
    StringBuilder query = new StringBuilder();
    query.append(String.format("select * from %s where cluster = ? and region = ?", table));
    LOGGER.info(String.format("Query is '%s'", query));
    List<Cluster> clusters = jdbcTemplate.query(query.toString(), new String[] { clusterName, region }, new RowMapper<Cluster>() {

        public Cluster mapRow(ResultSet rs, int rowNum) throws SQLException {
            return mapResource(rs);
        }
    });
    Validate.isTrue(clusters.size() <= 1);
    if (clusters.size() == 0) {
        LOGGER.info(String.format("Not found cluster with name %s in region %s", clusterName, region));
        return null;
    } else {
        Cluster cluster = clusters.get(0);
        return cluster;
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Cluster(com.netflix.simianarmy.conformity.Cluster)

Example 14 with Cluster

use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.

the class BasicConformityEmailBuilder method getEntryTable.

@Override
protected String getEntryTable(String emailAddress) {
    StringBuilder table = new StringBuilder();
    table.append(getHtmlTableHeader(getTableColumns()));
    for (Cluster cluster : emailToClusters.get(emailAddress)) {
        for (Conformity conformity : cluster.getConformties()) {
            if (!conformity.getFailedComponents().isEmpty()) {
                table.append(getClusterRow(cluster, conformity));
            }
        }
    }
    table.append("</table>");
    return table.toString();
}
Also used : Cluster(com.netflix.simianarmy.conformity.Cluster) Conformity(com.netflix.simianarmy.conformity.Conformity)

Example 15 with Cluster

use of com.netflix.simianarmy.conformity.Cluster in project SimianArmy by Netflix.

the class SimpleDBConformityClusterTracker method deleteClusters.

@Override
public void deleteClusters(Cluster... clusters) {
    Validate.notNull(clusters);
    LOGGER.info(String.format("Deleting %d clusters", clusters.length));
    for (Cluster cluster : clusters) {
        LOGGER.info(String.format("Deleting cluster %s", cluster.getName()));
        simpleDBClient.deleteAttributes(new DeleteAttributesRequest(domain, getSimpleDBItemName(cluster)));
        LOGGER.info(String.format("Successfully deleted cluster %s", cluster.getName()));
    }
}
Also used : Cluster(com.netflix.simianarmy.conformity.Cluster) DeleteAttributesRequest(com.amazonaws.services.simpledb.model.DeleteAttributesRequest)

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