Package com.comcast.cmb.common.persistence

Examples of com.comcast.cmb.common.persistence.AbstractDurablePersistence


    if (!task.equals("ClearAPIStats") && (!task.equals("StartWorker")) && (!task.equals("StopWorker")) && (host == null || host.equals(""))) {
      logger.error("event=cns_manage_service error_code=missing_parameter_host");
      throw new CMBException(CNSErrorCodes.MissingParameter,"Request parameter Host missing.");
    }

    AbstractDurablePersistence cassandraHandler = DurablePersistenceFactory.getInstance();

    if (task.equals("ClearWorkerQueues")) {

      List<CmbRow<String, String, String>> rows = cassandraHandler.readAllRows(AbstractDurablePersistence.CNS_KEYSPACE, CNS_WORKERS, 1000, 10, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
      List<CNSWorkerStats> statsList = new ArrayList<CNSWorkerStats>();

      if (rows != null) {

        for (CmbRow<String, String, String> row : rows) {

          CNSWorkerStats stats = new CNSWorkerStats();
          stats.setIpAddress(row.getKey());

          if (row.getColumnSlice().getColumnByName("producerTimestamp") != null) {
            stats.setProducerTimestamp(Long.parseLong(row.getColumnSlice().getColumnByName("producerTimestamp").getValue()));
          }

          if (row.getColumnSlice().getColumnByName("consumerTimestamp") != null) {
            stats.setConsumerTimestamp(Long.parseLong(row.getColumnSlice().getColumnByName("consumerTimestamp").getValue()));
          }

          if (row.getColumnSlice().getColumnByName("jmxport") != null) {
            stats.setJmxPort(Long.parseLong(row.getColumnSlice().getColumnByName("jmxport").getValue()));
          }

          if (row.getColumnSlice().getColumnByName("mode") != null) {
            stats.setMode(row.getColumnSlice().getColumnByName("mode").getValue());
          }

          statsList.add(stats);
        }
      }

      for (CNSWorkerStats stats : statsList) {

        if (stats.getIpAddress().equals(host) && stats.getJmxPort() > 0) {

          JMXConnector jmxConnector = null;
          String url = null;

          try {

            long port = stats.getJmxPort();
            url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";

            JMXServiceURL serviceUrl = new JMXServiceURL(url);
            jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);

            MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
            ObjectName cnsWorkerMonitor = new ObjectName("com.comcast.cns.tools:type=CNSWorkerMonitorMBean");
            CNSWorkerMonitorMBean mbeanProxy = JMX.newMBeanProxy(mbeanConn, cnsWorkerMonitor,  CNSWorkerMonitorMBean.class, false);

            mbeanProxy.clearWorkerQueues();

            String res = CNSWorkerStatsPopulator.getGetManageWorkerResponse()
            response.getWriter().println(res);

            return true;

          } finally {

            if (jmxConnector != null) {
              jmxConnector.close();
            }
          }
        }
      }

      throw new CMBException(CMBErrorCodes.NotFound, "Cannot clear worker queues: Host " + host + " not found.");

    } else if (task.equals("RemoveWorkerRecord")) {
     
      cassandraHandler.delete(AbstractDurablePersistence.CNS_KEYSPACE, CNS_WORKERS, host, null, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
      String out = CNSPopulator.getResponseMetadata();
          writeResponse(out, response);
      return true;
     
    } else if (task.equals("ClearAPIStats")) {
     
            CMBControllerServlet.initStats();
            String out = CNSPopulator.getResponseMetadata();
          writeResponse(out, response);
        return true;

    } else if (task.equals("RemoveRecord")) {
     
      cassandraHandler.delete(AbstractDurablePersistence.CNS_KEYSPACE, CNS_API_SERVERS, host, null, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
      String out = CNSPopulator.getResponseMetadata();
          writeResponse(out, response);
      return true;
     
    } else if (task.equals("StartWorker")||task.equals("StopWorker")) {
View Full Code Here


  @Test 
  public void testCassandraCounters() throws PersistenceException {
   
    log.info("Testing Cassandra counters");
   
    AbstractDurablePersistence cassandraHandler = DurablePersistenceFactory.getInstance();
   
    long i = cassandraHandler.getCounter(CMBProperties.getInstance().getCNSKeyspace(), "CNSTopicStats", "bla", "foo", CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
   
    while (i > 0) {
      cassandraHandler.decrementCounter(CMBProperties.getInstance().getCNSKeyspace(), "CNSTopicStats", "bla", "foo", 1, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
      i = cassandraHandler.getCounter(CMBProperties.getInstance().getCNSKeyspace(), "CNSTopicStats", "bla", "foo", CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
    }
   
    cassandraHandler.incrementCounter(CMBProperties.getInstance().getCNSKeyspace(), "CNSTopicStats", "bla", "foo", 1, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
    cassandraHandler.incrementCounter(CMBProperties.getInstance().getCNSKeyspace(), "CNSTopicStats", "bla", "foo", 1, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
    cassandraHandler.incrementCounter(CMBProperties.getInstance().getCNSKeyspace(), "CNSTopicStats", "bla", "foo", 1, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
   
    i = cassandraHandler.getCounter(CMBProperties.getInstance().getCNSKeyspace(), "CNSTopicStats", "bla", "foo", CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER);
   
    assertTrue("Expected counter to be 3, instead found " + i, i == 3);
  }
View Full Code Here

     
      if (lastCNSPingMinute.getAndSet(now/(1000*60)) != now/(1000*60)) {

          try {

            AbstractDurablePersistence cassandraHandler = DurablePersistenceFactory.getInstance();

            // write ping
           
            String serverIp = InetAddress.getLocalHost().getHostAddress();
            String serverPort = CMBProperties.getInstance().getCNSServerPort() + "";
           
            logger.info("event=ping version=" + CMBControllerServlet.VERSION + " ip=" + serverIp + " port=" + serverPort);
           
            Map<String, String> values = new HashMap<String, String>();
           
            values.put("timestamp", now + "");
            values.put("jmxport", System.getProperty("com.sun.management.jmxremote.port", "0"));
            values.put("dataCenter", CMBProperties.getInstance().getCMBDataCenter());
            values.put("serviceUrl", CMBProperties.getInstance().getCNSServiceUrl());
           
                cassandraHandler.insertRow(AbstractDurablePersistence.CNS_KEYSPACE, serverIp + ":" + serverPort, CNS_API_SERVERS, values, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER, null);
               
          } catch (Exception ex) {
            logger.warn("event=ping_failed", ex);
          }
        }
View Full Code Here

          stats.addStatus("REDIS UNAVAILABLE");
        }
       
            try {
       
          AbstractDurablePersistence cassandra = DurablePersistenceFactory.getInstance();
             
              if (!cassandra.isAlive()) {
            stats.addStatus("CASSANDRA UNAVAILABLE");
              }

            } catch (Exception ex) {
          stats.addStatus("CASSANDRA UNAVAILABLE");
View Full Code Here

    return sb.toString();
  }

  private void createReceivers(String queueUrl) {

      AbstractDurablePersistence persistence = DurablePersistenceFactory.getInstance();
      long receiverCount = CQSStressTestProperties.getInstance().getNumberOfReceiversPerQueue();
      List<Receiver> receiverListForQueue = new ArrayList<Receiver>();

      for (int i=0; i<receiverCount; i++) {
        Receiver receiver = new Receiver(queueUrl, i, persistence);
View Full Code Here

  }*/
 
  public static long getQueueMessageCount(CQSQueue queue) throws NoSuchAlgorithmException, UnsupportedEncodingException, PersistenceException {
   
    int numberOfPartitions = queue.getNumberOfPartitions();
    AbstractDurablePersistence cassandraHandler = DurablePersistenceFactory.getInstance();
    String queueHash = Util.hashQueueUrl(queue.getRelativeUrl());
    long messageCount = 0;
   
    for (int i=0; i<numberOfPartitions; i++) {
      String queueKey = queueHash + "_" + i;
      long partitionCount = cassandraHandler.getCount(CMBProperties.getInstance().getCQSKeyspace(), "CQSPartitionedQueueMessages", queueKey, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.COMPOSITE_SERIALIZER);
      messageCount += partitionCount;
    }
   
    return messageCount;
  }
View Full Code Here

  }

  public static List<Long> getPartitionMessageCounts(CQSQueue queue) throws NoSuchAlgorithmException, UnsupportedEncodingException, PersistenceException {
   
    int numberOfPartitions = queue.getNumberOfPartitions();
    AbstractDurablePersistence cassandraHandler = DurablePersistenceFactory.getInstance();
    String queueHash = Util.hashQueueUrl(queue.getRelativeUrl());
    List<Long> messageCounts = new ArrayList<Long>();
   
    for (int i=0; i<numberOfPartitions; i++) {
      String queueKey = queueHash + "_" + i;
      long partitionCount = cassandraHandler.getCount(CMBProperties.getInstance().getCQSKeyspace(), "CQSPartitionedQueueMessages", queueKey, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.COMPOSITE_SERIALIZER);
      messageCounts.add(partitionCount);
    }
   
    return messageCounts;
  }
View Full Code Here

          }
        }
       
        try {
         
          AbstractDurablePersistence cassandra = DurablePersistenceFactory.getInstance();
         
          if (cassandra.isAlive()) {
            sb.append("\t<Cassandra>OK</Cassandra>\n");
          } else {
            sb.append("\t<Cassandra>Ring unavailable.</Cassandra>\n");
            healthy = false;
          }
View Full Code Here

     
      if (lastCQSPingMinute.getAndSet(now/(1000*60)) != now/(1000*60)) {

          try {

            AbstractDurablePersistence cassandraHandler = DurablePersistenceFactory.getInstance();

            // write ping
           
            String serverIp = InetAddress.getLocalHost().getHostAddress();
            String serverPort = CMBProperties.getInstance().getCQSServerPort() + "";
           
            logger.info("event=ping version=" + CMBControllerServlet.VERSION + " ip=" + serverIp + " port=" + serverPort);
           
            Map<String, String> values = new HashMap<String, String>();
           
            values.put("timestamp", now + "");
            values.put("port", CMBProperties.getInstance().getCQSLongPollPort() + "");
            values.put("jmxport", System.getProperty("com.sun.management.jmxremote.port", "0"));
            values.put("dataCenter", CMBProperties.getInstance().getCMBDataCenter());
            values.put("serviceUrl", CMBProperties.getInstance().getCQSServiceUrl());
            values.put("redisServerList", CMBProperties.getInstance().getRedisServerList());
           
                cassandraHandler.insertRow(AbstractDurablePersistence.CQS_KEYSPACE, serverIp + ":" + serverPort, CQS_API_SERVERS, values, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER, CMB_SERIALIZER.STRING_SERIALIZER, null);
               
          } catch (Exception ex) {
            logger.warn("event=ping_failed", ex);
          }
        }
View Full Code Here

TOP

Related Classes of com.comcast.cmb.common.persistence.AbstractDurablePersistence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.