@Test public void test() throws Exception { final TSDRMetricPersistenceService metricService = Mockito.mock(TSDRMetricPersistenceService.class); final TSDRLogPersistenceService logService = Mockito.mock(TSDRLogPersistenceService.class); ListMetricsCommand cmd = new ListMetricsCommand(); cmd.category = "EXTERNAL"; cmd.execute(); cmd.execute(); List<TSDRMetricRecord> metric = new ArrayList<>(); metric.add(createMetricRecord()); Mockito.when(metricService.getTSDRMetricRecords(Mockito.anyString(),Mockito.anyLong(),Mockito.anyLong())) .thenReturn(metric); cmd.execute(); List<TSDRLogRecord> logs = new ArrayList<>(); logs.add(createLogRecord()); Mockito.when(logService.getTSDRLogRecords(Mockito.anyString(),Mockito.anyLong(),Mockito.anyLong())) .thenReturn(logs); cmd.category = DataCategory.LOGRECORDS.name(); cmd.execute(); cmd.startDateTime = "10/10/2010 22:22:22"; cmd.endDateTime = "10/10/2010 22:23:22"; cmd.execute(); cmd.startDateTime = "10/10/2010 22:22:22"; cmd.endDateTime = "10/10/2010 22:22:22"; cmd.execute(); }
@Override @SuppressWarnings("checkstyle:RegexpSingleLineJava") public Object execute() throws Exception { PrintStream ps = this.session != null ? this.session.getConsole() : System.out; long startDate = 0; long endDate = Long.MAX_VALUE; if (startDateTime != null) { startDate = getDate(startDateTime); endDate = getDate(endDateTime); } if (startDate >= endDate) { ps.println("StatDateTime value cannot be greater or equal to EndDateTime"); return null; } DataCategory dataCategory = DataCategory.valueOf(category); if ((dataCategory == DataCategory.NETFLOW || dataCategory == DataCategory.SYSLOG || dataCategory == DataCategory.LOGRECORDS || dataCategory == DataCategory.RESTCONF) && logService != null) { List<TSDRLogRecord> logs = logService.getTSDRLogRecords(category, startDate, endDate); if (logs == null || logs.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listLogs(logs)); } else if (metricService != null) { List<TSDRMetricRecord> metrics = metricService.getTSDRMetricRecords(category, startDate, endDate); if (metrics == null || metrics.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listMetrics(metrics)); } return null; }
ListMetricsCommand implements Action { @Override @SuppressWarnings("checkstyle:RegexpSingleLineJava") public Object execute() throws Exception { PrintStream ps = this.session != null ? this.session.getConsole() : System.out; long startDate = 0; long endDate = Long.MAX_VALUE; if (startDateTime != null) { startDate = getDate(startDateTime); endDate = getDate(endDateTime); } if (startDate >= endDate) { ps.println("StatDateTime value cannot be greater or equal to EndDateTime"); return null; } DataCategory dataCategory = DataCategory.valueOf(category); if ((dataCategory == DataCategory.NETFLOW || dataCategory == DataCategory.SYSLOG || dataCategory == DataCategory.LOGRECORDS || dataCategory == DataCategory.RESTCONF) && logService != null) { List<TSDRLogRecord> logs = logService.getTSDRLogRecords(category, startDate, endDate); if (logs == null || logs.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listLogs(logs)); } else if (metricService != null) { List<TSDRMetricRecord> metrics = metricService.getTSDRMetricRecords(category, startDate, endDate); if (metrics == null || metrics.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listMetrics(metrics)); } return null; } }
ListMetricsCommand implements Action { @Override @SuppressWarnings("checkstyle:RegexpSingleLineJava") public Object execute() throws Exception { PrintStream ps = this.session != null ? this.session.getConsole() : System.out; long startDate = 0; long endDate = Long.MAX_VALUE; if (startDateTime != null) { startDate = getDate(startDateTime); endDate = getDate(endDateTime); } if (startDate >= endDate) { ps.println("StatDateTime value cannot be greater or equal to EndDateTime"); return null; } DataCategory dataCategory = DataCategory.valueOf(category); if ((dataCategory == DataCategory.NETFLOW || dataCategory == DataCategory.SYSLOG || dataCategory == DataCategory.LOGRECORDS || dataCategory == DataCategory.RESTCONF) && logService != null) { List<TSDRLogRecord> logs = logService.getTSDRLogRecords(category, startDate, endDate); if (logs == null || logs.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listLogs(logs)); } else if (metricService != null) { List<TSDRMetricRecord> metrics = metricService.getTSDRMetricRecords(category, startDate, endDate); if (metrics == null || metrics.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listMetrics(metrics)); } return null; } ListMetricsCommand(); }
ListMetricsCommand implements Action { @Override @SuppressWarnings("checkstyle:RegexpSingleLineJava") public Object execute() throws Exception { PrintStream ps = this.session != null ? this.session.getConsole() : System.out; long startDate = 0; long endDate = Long.MAX_VALUE; if (startDateTime != null) { startDate = getDate(startDateTime); endDate = getDate(endDateTime); } if (startDate >= endDate) { ps.println("StatDateTime value cannot be greater or equal to EndDateTime"); return null; } DataCategory dataCategory = DataCategory.valueOf(category); if ((dataCategory == DataCategory.NETFLOW || dataCategory == DataCategory.SYSLOG || dataCategory == DataCategory.LOGRECORDS || dataCategory == DataCategory.RESTCONF) && logService != null) { List<TSDRLogRecord> logs = logService.getTSDRLogRecords(category, startDate, endDate); if (logs == null || logs.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listLogs(logs)); } else if (metricService != null) { List<TSDRMetricRecord> metrics = metricService.getTSDRMetricRecords(category, startDate, endDate); if (metrics == null || metrics.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listMetrics(metrics)); } return null; } ListMetricsCommand(); @Override @SuppressWarnings("checkstyle:RegexpSingleLineJava") Object execute(); }
ListMetricsCommand implements Action { @Override @SuppressWarnings("checkstyle:RegexpSingleLineJava") public Object execute() throws Exception { PrintStream ps = this.session != null ? this.session.getConsole() : System.out; long startDate = 0; long endDate = Long.MAX_VALUE; if (startDateTime != null) { startDate = getDate(startDateTime); endDate = getDate(endDateTime); } if (startDate >= endDate) { ps.println("StatDateTime value cannot be greater or equal to EndDateTime"); return null; } DataCategory dataCategory = DataCategory.valueOf(category); if ((dataCategory == DataCategory.NETFLOW || dataCategory == DataCategory.SYSLOG || dataCategory == DataCategory.LOGRECORDS || dataCategory == DataCategory.RESTCONF) && logService != null) { List<TSDRLogRecord> logs = logService.getTSDRLogRecords(category, startDate, endDate); if (logs == null || logs.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listLogs(logs)); } else if (metricService != null) { List<TSDRMetricRecord> metrics = metricService.getTSDRMetricRecords(category, startDate, endDate); if (metrics == null || metrics.isEmpty()) { ps.println("No data of this category in the specified time range. "); return null; } ps.println(listMetrics(metrics)); } return null; } ListMetricsCommand(); @Override @SuppressWarnings("checkstyle:RegexpSingleLineJava") Object execute(); @Argument(index = 0, name = "category", required = true,
            description = "The category of the metrics we want to get", multiValued = false)
    @Completion(ListMetricsCommandCompleter.class)
    public String category; @Argument(index = 1, name = "startDateTime", required = false,
            description = "list the metrics from this time (format: MM/dd/yyyy HH:mm:ss)", multiValued = false)
    public String startDateTime; @Argument(index = 2, name = "endDateTime", required = false,
            description = "list the metrics till this time (format: MM/dd/yyyy HH:mm:ss)", multiValued = false)
    public String endDateTime; }