Search in sources :

Example 96 with Cluster

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

the class Terminate_a_Container method remove_from_AgentTable_in_cassandra.

// ///////////////////////////////////////////////////////////
public void remove_from_AgentTable_in_cassandra(String new_id) {
    try {
        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");
        ResultSet results = session.execute("DELETE FROM jcatascopiadb.agent_table WHERE  agentid=\'" + new_id + "\';");
    } catch (Exception ex) {
        ex.printStackTrace();
        System.out.println("error in remove_from_AgentTable_in_cassandra()");
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Cluster(com.datastax.driver.core.Cluster) IOException(java.io.IOException) Session(com.datastax.driver.core.Session) ConstantReconnectionPolicy(com.datastax.driver.core.policies.ConstantReconnectionPolicy)

Example 97 with Cluster

use of com.datastax.driver.core.Cluster 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 98 with Cluster

use of com.datastax.driver.core.Cluster 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 99 with Cluster

use of com.datastax.driver.core.Cluster 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 100 with Cluster

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

the class MapperAsyncTest method should_get_query_async_without_blocking.

/**
 * Validates that when using save, get and deleteAsync using the same executor as the caller that the driver
 * does not block indefinitely in a netty worker thread.
 *
 * @jira_ticket JAVA-1070
 * @test_category queries:async
 * @test_category object_mapper
 */
@Test(groups = "short")
public void should_get_query_async_without_blocking() {
    final CountDownLatch latch = new CountDownLatch(1);
    // create a second cluster to perform everything asynchronously,
    // including session initialization
    Cluster cluster2 = register(createClusterBuilder().addContactPoints(getContactPoints()).withPort(ccm().getBinaryPort()).build());
    ListenableFuture<MappingManager> mappingManagerFuture = Futures.transform(cluster2.connectAsync(), new Function<Session, MappingManager>() {

        @Override
        public MappingManager apply(Session session) {
            return new MappingManager(session);
        }
    });
    Futures.addCallback(mappingManagerFuture, new SuccessCallback<MappingManager>() {

        @Override
        public void onSuccess(MappingManager manager) {
            final Mapper<User> mapper = manager.mapper(User.class);
            ListenableFuture<Void> saveFuture = mapper.saveAsync(paul);
            Futures.addCallback(saveFuture, new SuccessCallback<Void>() {

                @Override
                public void onSuccess(Void result) {
                    ListenableFuture<User> getFuture = mapper.getAsync(paul.getUserId());
                    Futures.addCallback(getFuture, new SuccessCallback<User>() {

                        @Override
                        public void onSuccess(User paul) {
                            Futures.addCallback(mapper.deleteAsync(paul), new SuccessCallback<Void>() {

                                @Override
                                public void onSuccess(Void result) {
                                    latch.countDown();
                                }
                            });
                        }
                    });
                }
            });
        }
    });
    try {
        Uninterruptibles.awaitUninterruptibly(latch, 5, MINUTES);
    } catch (Exception e) {
        fail("Operation did not complete normally within 5 minutes");
    }
}
Also used : SuccessCallback(com.datastax.driver.core.utils.MoreFutures.SuccessCallback) Cluster(com.datastax.driver.core.Cluster) CountDownLatch(java.util.concurrent.CountDownLatch) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Session(com.datastax.driver.core.Session) Test(org.testng.annotations.Test)

Aggregations

Cluster (com.datastax.driver.core.Cluster)123 Session (com.datastax.driver.core.Session)74 ResultSet (com.datastax.driver.core.ResultSet)41 Row (com.datastax.driver.core.Row)37 Test (org.junit.Test)33 ConstantReconnectionPolicy (com.datastax.driver.core.policies.ConstantReconnectionPolicy)30 Host (com.datastax.driver.core.Host)10 Metadata (com.datastax.driver.core.Metadata)9 PreparedStatement (com.datastax.driver.core.PreparedStatement)9 ArrayList (java.util.ArrayList)9 LoadBalancingPolicy (com.datastax.driver.core.policies.LoadBalancingPolicy)8 IOException (java.io.IOException)8 PoolingOptions (com.datastax.driver.core.PoolingOptions)7 ReconnectionPolicy (com.datastax.driver.core.policies.ReconnectionPolicy)7 BeforeClass (org.junit.BeforeClass)7 KeyspaceMetadata (com.datastax.driver.core.KeyspaceMetadata)6 QueryOptions (com.datastax.driver.core.QueryOptions)6 InetSocketAddress (java.net.InetSocketAddress)6 BoundStatement (com.datastax.driver.core.BoundStatement)5 SocketOptions (com.datastax.driver.core.SocketOptions)5