Search in sources :

Example 36 with ConstantReconnectionPolicy

use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project ASAP by salmant.

the class AlarmTrigger method Calculate_AVG.

// ////////
public double Calculate_AVG(String metric_name, String subid, String event_date) {
    Cluster cluster;
    Session session;
    cluster = Cluster.builder().addContactPoints(TSDB_Server_IP).withCredentials(TSDB_Server_Username, TSDB_Server_Password).withPort(9042).withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE).withReconnectionPolicy(new ConstantReconnectionPolicy(1000L)).build();
    session = cluster.connect("jcatascopiadb");
    // find the agents in the cluster
    ResultSet results = session.execute("SELECT agentid FROM jcatascopiadb.subscription_agents_table WHERE subid=\'" + subid + "\'");
    double AVG = 0.0;
    double count = 0.0;
    for (Row row : results) {
        String AgentIDs = new String();
        AgentIDs = row.getString("agentid");
        AgentIDs = AgentIDs + ":" + metric_name;
        ResultSet results2 = session.execute("select value, toTimestamp(event_timestamp) AS ET from jcatascopiadb.metric_value_table where metricid=\'" + AgentIDs + "\' and event_date=\'" + event_date + "\' ORDER BY event_timestamp DESC LIMIT 1");
        for (Row row2 : results2) {
            AVG = AVG + Double.parseDouble(row2.getString("value"));
            count = count + 1;
        }
    }
    AVG = AVG / count;
    return AVG;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy)

Example 37 with ConstantReconnectionPolicy

use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project ASAP by salmant.

the class AlarmTrigger method Calculate_MIN.

// ////////
public double Calculate_MIN(String metric_name, String subid, String event_date) {
    Cluster cluster;
    Session session;
    cluster = Cluster.builder().addContactPoints(TSDB_Server_IP).withCredentials(TSDB_Server_Username, TSDB_Server_Password).withPort(9042).withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE).withReconnectionPolicy(new ConstantReconnectionPolicy(1000L)).build();
    session = cluster.connect("jcatascopiadb");
    // find the agents in the cluster
    ResultSet results = session.execute("SELECT agentid FROM jcatascopiadb.subscription_agents_table WHERE subid=\'" + subid + "\'");
    double MIN = Double.MAX_VALUE;
    for (Row row : results) {
        String AgentIDs = new String();
        AgentIDs = row.getString("agentid");
        AgentIDs = AgentIDs + ":" + metric_name;
        ResultSet results2 = session.execute("select value, toTimestamp(event_timestamp) AS ET from jcatascopiadb.metric_value_table where metricid=\'" + AgentIDs + "\' and event_date=\'" + event_date + "\' ORDER BY event_timestamp DESC LIMIT 1");
        for (Row row2 : results2) {
            if (Double.parseDouble(row2.getString("value")) < MIN)
                MIN = Double.parseDouble(row2.getString("value"));
        }
    }
    return MIN;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy)

Example 38 with ConstantReconnectionPolicy

use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project ASAP by salmant.

the class HPA method Fetch_AVG_response_time_metric.

// ///////////////////////////////////////////
public static double Fetch_AVG_response_time_metric(String metric_name, String haproxy_agentid, String event_date) {
    Cluster cluster;
    Session session;
    cluster = Cluster.builder().addContactPoints("194.249.1.175").withCredentials("catascopia_user", "catascopia_pass").withPort(9042).withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE).withReconnectionPolicy(new ConstantReconnectionPolicy(1000L)).build();
    session = cluster.connect("jcatascopiadb");
    haproxy_agentid = haproxy_agentid + ":" + metric_name;
    ResultSet results = session.execute("select value from jcatascopiadb.metric_value_table where metricid=\'" + haproxy_agentid + "\' and event_date=\'" + event_date + "\' ORDER BY event_timestamp DESC LIMIT 1");
    double AVG_response_time_metric = 0.0;
    for (Row row : results) {
        AVG_response_time_metric = Double.parseDouble(row.getString("value"));
    }
    return Math.abs(AVG_response_time_metric);
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) Row(com.datastax.driver.core.Row) Session(com.datastax.driver.core.Session) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy)

Example 39 with ConstantReconnectionPolicy

use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project java-driver by datastax.

the class HostConnectionPoolMultiTest method createCluster.

private void createCluster(int core, int max) {
    PoolingOptions poolingOptions = new PoolingOptions().setConnectionsPerHost(LOCAL, core, max);
    SocketOptions socketOptions = new SocketOptions().setReadTimeoutMillis(1000);
    cluster = Cluster.builder().addContactPoints(scassandra.address(1).getAddress()).withPort(scassandra.getBinaryPort()).withQueryOptions(nonDebouncingQueryOptions()).withPoolingOptions(poolingOptions).withSocketOptions(socketOptions).withReconnectionPolicy(new ConstantReconnectionPolicy(1000)).build();
    cluster.connect();
}
Also used : ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy)

Example 40 with ConstantReconnectionPolicy

use of com.datastax.driver.core.policies.ConstantReconnectionPolicy in project java-driver by datastax.

the class ReconnectionTest method should_cancel_reconnection_attempts.

@CCMConfig(dirtiesContext = true, numberOfNodes = 2, createCluster = false)
@Test(groups = "long")
public void should_cancel_reconnection_attempts() throws InterruptedException {
    // Stop a node and cancel the reconnection attempts to it
    CountingReconnectionPolicy reconnectionPolicy = new CountingReconnectionPolicy(new ConstantReconnectionPolicy(reconnectionDelayMillis));
    Cluster cluster = register(Cluster.builder().addContactPoints(getContactPoints().get(0)).withPort(ccm().getBinaryPort()).withReconnectionPolicy(reconnectionPolicy).build());
    cluster.connect();
    // Stop a node and cancel the reconnection attempts to it
    ccm().stop(2);
    Host host2 = TestUtils.findHost(cluster, 2);
    host2.getReconnectionAttemptFuture().cancel(false);
    // The reconnection count should not vary over time anymore
    int initialCount = reconnectionPolicy.count.get();
    TimeUnit.MILLISECONDS.sleep(reconnectionDelayMillis * 2);
    assertThat(reconnectionPolicy.count.get()).isEqualTo(initialCount);
    // Restart the node, which will trigger an UP notification
    ccm().start(2);
    ccm().waitForUp(2);
    // The driver should now see the node as UP again
    assertThat(cluster).host(2).comesUpWithin(Cluster.NEW_NODE_DELAY_SECONDS * 2, SECONDS);
}
Also used : ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy) Test(org.testng.annotations.Test)

Aggregations

ConstantReconnectionPolicy (com.datastax.driver.core.policies.ConstantReconnectionPolicy)44 Cluster (com.datastax.driver.core.Cluster)29 ResultSet (com.datastax.driver.core.ResultSet)28 Session (com.datastax.driver.core.Session)28 Row (com.datastax.driver.core.Row)26 Test (org.testng.annotations.Test)10 RoundRobinPolicy (com.datastax.driver.core.policies.RoundRobinPolicy)7 Builder (com.datastax.driver.core.Cluster.Builder)3 CacheBuilder (com.google.common.cache.CacheBuilder)3 IOException (java.io.IOException)3 PreparedStatement (com.datastax.driver.core.PreparedStatement)2 BeforeClass (org.junit.BeforeClass)2 Configuration (com.datastax.driver.core.Configuration)1 PoolingOptions (com.datastax.driver.core.PoolingOptions)1 QueryOptions (com.datastax.driver.core.QueryOptions)1 SocketOptions (com.datastax.driver.core.SocketOptions)1 ExponentialReconnectionPolicy (com.datastax.driver.core.policies.ExponentialReconnectionPolicy)1 LimitingLoadBalancingPolicy (com.datastax.driver.core.policies.LimitingLoadBalancingPolicy)1 Policies (com.datastax.driver.core.policies.Policies)1 ReconnectionPolicy (com.datastax.driver.core.policies.ReconnectionPolicy)1