Package com.dianping.cat.message

Examples of com.dianping.cat.message.Transaction


    }
    return null;
  }

  private String queryHostnameFromCMDB(String ip) {
    Transaction t = Cat.newTransaction("CMDB", "queryHostname");
    try {
      String cmdb = String.format(CMDB_HOSTNAME_URL, ip);
      InputStream in = Urls.forIO().readTimeout(1000).connectTimeout(1000).openStream(cmdb);
      String content = Files.forIO().readFrom(in, "utf-8");

      t.setStatus(Transaction.SUCCESS);
      t.addData(content);
      return parseHostname(content.trim());
    } catch (Exception e) {
      t.setStatus(e);
    } finally {
      t.complete();
    }
    return null;
  }
View Full Code Here


    return ipList;
  }

  private Map<String, String> queryProjectInfoFromCMDB(String cmdbDomain) {
    Transaction t = Cat.newTransaction("CMDB", "queryProjectInfo");
    try {
      String cmdb = String.format(CMDB_INFO_URL, cmdbDomain);
      InputStream in = Urls.forIO().readTimeout(1000).connectTimeout(1000).openStream(cmdb);
      String content = Files.forIO().readFrom(in, "utf-8");

      t.setStatus(Transaction.SUCCESS);
      t.addData(content);
      return parseInfos(content.trim());
    } catch (Exception e) {
      t.setStatus(e);
    } finally {
      t.complete();
    }
    return new HashMap<String, String>();
  }
View Full Code Here

    }
    return new HashMap<String, String>();
  }

  private String queryProjectInfoFromCMDB(String url, String jsonName, String attrName) {
    Transaction t = Cat.newTransaction("CMDB", "queryProjectInfo");
    try {
      InputStream in = Urls.forIO().readTimeout(1000).connectTimeout(1000).openStream(url);
      String content = Files.forIO().readFrom(in, "utf-8");

      t.setStatus(Transaction.SUCCESS);
      t.addData(content);
      return parseInfo(content, jsonName, attrName);
    } catch (Exception e) {
      t.setStatus(e);
    } finally {
      t.complete();
    }
    return null;
  }
View Full Code Here

      if (hour < 10) {
        hourStr = "0" + hourStr;
      }

      Transaction t1 = Cat.newTransaction("UpdateHostname", "H" + hourStr);
      try {
        updateHostNameInfo();
        t1.setStatus(Transaction.SUCCESS);
      } catch (Exception e) {
        t1.setStatus(e);
      } finally {
        t1.complete();
      }

      Transaction t2 = Cat.newTransaction("UpdateProjectInfo", "H" + hourStr);
      try {
        updateProjectInfo();
        t2.setStatus(Transaction.SUCCESS);
      } catch (Exception e) {
        t1.setStatus(e);
      } finally {
        t2.complete();
      }

      try {
        long executeMills = System.currentTimeMillis() - startMill;
View Full Code Here

    m_taskManager = taskManager;
  }

  protected void storeReports(boolean atEnd) {
    Bucket<String> reportBucket = null;
    Transaction t = Cat.getProducer().newTransaction("Checkpoint", ID);

    t.setStatus(Message.SUCCESS);
    try {
      reportBucket = m_bucketManager.getReportBucket(m_startTime, MetricAnalyzer.ID);

      for (MetricReport report : m_reports.values()) {
        try {
          String xml = new DefaultXmlBuilder(true).buildXml(report);
          String product = report.getProduct();

          reportBucket.storeById(product, xml);
        } catch (Exception e) {
          t.setStatus(e);
          Cat.logError(e);
        }
      }

      if (atEnd && !isLocalMode()) {
        Date period = new Date(m_startTime);
        String ip = NetworkInterfaceManager.INSTANCE.getLocalHostAddress();
        int binary = 1;

        for (MetricReport report : m_reports.values()) {
          try {
            BusinessReport r = m_businessReportDao.createLocal();
            String product = report.getProduct();

            r.setName(ID);
            r.setProductLine(product);
            r.setPeriod(period);
            r.setIp(ip);
            r.setType(binary);
            r.setContent(DefaultNativeBuilder.build(report));
            r.setCreationDate(new Date());

            m_businessReportDao.insert(r);
          } catch (Throwable e) {
            m_logger.error(report.toString());
            t.setStatus(e);
            Cat.getProducer().logError(e);
          }
        }
        m_taskManager.createTask(period, Constants.CAT, ID, TaskProlicy.DAILY);
      }
    } catch (Exception e) {
      Cat.getProducer().logError(e);
      t.setStatus(e);
      m_logger.error(String.format("Error when storing metric reports of %s!", new Date(m_startTime)), e);
    } finally {
      t.complete();

      if (reportBucket != null) {
        m_bucketManager.closeBucket(reportBucket);
      }
    }
View Full Code Here

  }

  @Override
  protected boolean processTask(Task doing) {
    boolean result = false;
    Transaction t = Cat.newTransaction("Task", doing.getReportName());

    t.addData(doing.toString());
    try {
      result = m_reportFacade.builderReport(doing);
      t.setStatus(Transaction.SUCCESS);
    } catch (Exception e) {
      Cat.logError(e);
    } finally {
      t.complete();
    }
    return result;
  }
View Full Code Here

    Date end = TimeHelper.getCurrentDay();
    Set<String> domains = m_reportService.queryAllDomainNames(start, end, TransactionAnalyzer.ID);

    for (String domain : domains) {
      if (m_configManger.validateDomain(domain)) {
        Transaction t = Cat.newTransaction("ReloadTask", "Reload-Month-" + domain);

        TransactionReport transactionReport = m_reportService.queryTransactionReport(domain, start, end);
        new TransactionReportCountFilter().visitTransactionReport(transactionReport);

        m_reportService.insertMonthlyReport(buildMonthlyReport(domain, start, TransactionAnalyzer.ID),
              com.dianping.cat.consumer.transaction.model.transform.DefaultNativeBuilder.build(transactionReport));

        EventReport eventReport = m_reportService.queryEventReport(domain, start, end);
        m_reportService.insertMonthlyReport(buildMonthlyReport(domain, start, EventAnalyzer.ID),
              com.dianping.cat.consumer.event.model.transform.DefaultNativeBuilder.build(eventReport));

        ProblemReport problemReport = m_reportService.queryProblemReport(domain, start, end);
        m_reportService.insertMonthlyReport(buildMonthlyReport(domain, start, ProblemAnalyzer.ID),
              com.dianping.cat.consumer.problem.model.transform.DefaultNativeBuilder.build(problemReport));

        CrossReport crossReport = m_reportService.queryCrossReport(domain, start, end);
        m_reportService.insertMonthlyReport(buildMonthlyReport(domain, start, CrossAnalyzer.ID),
              com.dianping.cat.consumer.cross.model.transform.DefaultNativeBuilder.build(crossReport));

        MatrixReport matrixReport = m_reportService.queryMatrixReport(domain, start, end);
        new MatrixReportFilter().visitMatrixReport(matrixReport);
        m_reportService.insertMonthlyReport(buildMonthlyReport(domain, start, MatrixAnalyzer.ID),
              com.dianping.cat.consumer.matrix.model.transform.DefaultNativeBuilder.build(matrixReport));

        t.setStatus(Transaction.SUCCESS);
        t.complete();
      }
    }
    String domain = Constants.CAT;

    StateReport stateReport = m_reportService.queryStateReport(domain, start, end);
View Full Code Here

    Date end = TimeHelper.getCurrentDay();
    Set<String> domains = m_reportService.queryAllDomainNames(start, end, TransactionAnalyzer.ID);

    for (String domain : domains) {
      if (m_configManger.validateDomain(domain)) {
        Transaction t = Cat.newTransaction("ReloadTask", "Reload-Week-" + domain);

        TransactionReport transactionReport = m_reportService.queryTransactionReport(domain, start, end);
        new TransactionReportCountFilter().visitTransactionReport(transactionReport);

        m_reportService.insertWeeklyReport(buildWeeklyReport(domain, start, TransactionAnalyzer.ID),
              com.dianping.cat.consumer.transaction.model.transform.DefaultNativeBuilder.build(transactionReport));

        EventReport eventReport = m_reportService.queryEventReport(domain, start, end);
        new EventReportCountFilter().visitEventReport(eventReport);
       
        m_reportService.insertWeeklyReport(buildWeeklyReport(domain, start, EventAnalyzer.ID),
              com.dianping.cat.consumer.event.model.transform.DefaultNativeBuilder.build(eventReport));

        ProblemReport problemReport = m_reportService.queryProblemReport(domain, start, end);
        m_reportService.insertWeeklyReport(buildWeeklyReport(domain, start, ProblemAnalyzer.ID),
              com.dianping.cat.consumer.problem.model.transform.DefaultNativeBuilder.build(problemReport));

        CrossReport crossReport = m_reportService.queryCrossReport(domain, start, end);
        m_reportService.insertWeeklyReport(buildWeeklyReport(domain, start, CrossAnalyzer.ID),
              com.dianping.cat.consumer.cross.model.transform.DefaultNativeBuilder.build(crossReport));

        MatrixReport matrixReport = m_reportService.queryMatrixReport(domain, start, end);
        new MatrixReportFilter().visitMatrixReport(matrixReport);
        m_reportService.insertWeeklyReport(buildWeeklyReport(domain, start, MatrixAnalyzer.ID),
              com.dianping.cat.consumer.matrix.model.transform.DefaultNativeBuilder.build(matrixReport));

        t.setStatus(Transaction.SUCCESS);
        t.complete();
      }
    }
    String domain = Constants.CAT;

    StateReport stateReport = m_reportService.queryStateReport(domain, start, end);
View Full Code Here

  private void sendDailyReport(Date period) {
    Collection<ScheduledReport> reports = m_scheduledManager.queryScheduledReports();

    for (ScheduledReport report : reports) {
      String domain = report.getDomain();
      Transaction t = Cat.newTransaction("ScheduledReport", domain);

      try {
        String names = String.valueOf(report.getNames());
        String content = renderContent(names, domain, period);
        String title = renderTitle(names, domain);
        List<String> emails = m_scheduledManager.queryEmailsBySchReportId(report.getId());
        AlertMessageEntity message = new AlertMessageEntity(domain, title, "ScheduledJob", content, emails);
        boolean result = m_sendManager.sendAlert(AlertChannel.MAIL, message);

        insertMailLog(report.getId(), content, title, result, emails);
        t.addData(emails.toString());
        t.setStatus(Transaction.SUCCESS);
      } catch (Exception e) {
        Cat.logError(e);
        t.setStatus(e);
      } finally {
        t.complete();
      }
    }
  }
View Full Code Here

          dataEntities.add(entity);
          maxSize--;
        }

        if (!dataEntities.isEmpty()) {
          Transaction t = Cat.newTransaction("Sender", "Send");
          boolean success = false;

          try {
            success = sendBatchEntities(dataEntities);
          } catch (Exception e) {
            Cat.logError(e);
          } finally {
            t.setStatus(Transaction.SUCCESS);
            t.complete();
          }

          if (!success) {
            Cat.logError(new RuntimeException("All cat servers: " + m_catServers.getServers()
                  + "are unreachable. DataEntity: " + dataEntities.toString()));
View Full Code Here

TOP

Related Classes of com.dianping.cat.message.Transaction

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.