Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #655 from bsura/develop
Browse files Browse the repository at this point in the history
Add SDK methods to query dashboards and alerts metadata.
  • Loading branch information
bsura authored Sep 12, 2017
2 parents 1e01f99 + ed1bb85 commit 4a23f1d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private List<MetricSchemaRecord> _getUniqueFastScan(MetricSchemaRecordQuery quer

_logger.info("Using FastScan. Will skip rows while scanning.");

final List<MetricSchemaRecord> records = new ArrayList<>();
final Set<MetricSchemaRecord> records = new TreeSet<>();

final ScanMetadata metadata = _constructScanMetadata(query);
String namespace = SchemaService.convertToRegex(query.getNamespace());
Expand Down Expand Up @@ -390,7 +390,7 @@ private List<MetricSchemaRecord> _getUniqueFastScan(MetricSchemaRecordQuery quer
rows = _getSingleRow(newScanStart, end, filterList, metadata.tableName);
}

return records;
return new ArrayList<>(records);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ public List<Alert> getAlerts(boolean includeSharedAlerts) throws IOException, To
assertValidResponse(response, requestUrl);
return fromJson(response.getResult(), new TypeReference<List<Alert>>() { });
}

public List<Alert> getAlertsMeta(boolean includeSharedAlerts) throws IOException, TokenExpiredException {
String requestUrl = RESOURCE + "/meta?shared=" + includeSharedAlerts;
ArgusResponse response = getClient().executeHttpRequest(ArgusHttpClient.RequestType.GET, requestUrl, null);

assertValidResponse(response, requestUrl);
return fromJson(response.getResult(), new TypeReference<List<Alert>>() { });
}

/**
* Returns the alert for the given ID.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,23 @@ public List<Dashboard> getDashboards() throws IOException, TokenExpiredException
assertValidResponse(response, requestUrl);
return fromJson(response.getResult(), new TypeReference<List<Dashboard>>() { });
}

/**
* Returns the list of dashboards owned by the user. Each Dashboard only contains metadata (id, name, description etc.) about the dashbaord.
*
* @param shared True or false depending on whether shared dashboards must be retrieved along with dashboards owned by the user.
*
* @return The list of dashboards owned by the user.
*
* @throws IOException If the server cannot be reached.
* @throws TokenExpiredException If the token sent along with the request has expired
*/
public List<Dashboard> getDashboardsMeta(boolean shared) throws IOException, TokenExpiredException {
String requestUrl = RESOURCE + "/meta?shared=" + shared;
ArgusResponse response = getClient().executeHttpRequest(ArgusHttpClient.RequestType.GET, requestUrl, null);

assertValidResponse(response, requestUrl);
return fromJson(response.getResult(), new TypeReference<List<Dashboard>>() { });
}
}
/* Copyright (c) 2016, Salesforce.com, Inc. All rights reserved. */
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ public void testGetDashboards() throws IOException, TokenExpiredException {
assertEquals(expected, result);
}
}

@Test
public void testGetDashboardsMeta() throws IOException, TokenExpiredException {
try(ArgusService argusService = new ArgusService(getMockedClient("/DashboardServiceTest.json"))) {
DashboardService batchService = argusService.getDashboardService();
List<Dashboard> result = batchService.getDashboardsMeta(false);

Dashboard persistedDashboard = _constructPersistedDashboard();
persistedDashboard.setContent(null);
persistedDashboard.setShared(false);
List<Dashboard> expected = Arrays.asList(new Dashboard[] { persistedDashboard });

assertEquals(expected, result);
}
}

@Test
public void testUpdateDashboard() throws IOException, TokenExpiredException {
Expand Down
7 changes: 7 additions & 0 deletions ArgusSDK/src/test/resources/DashboardServiceTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@
"status": 200,
"message": "success",
"jsonOutput" : "{\"id\":1,\"createdById\":1,\"createdDate\":1472282830936,\"modifiedById\":1,\"modifiedDate\":1472282830936,\"name\":\"TestName\",\"content\":\"UpdatedContent\",\"ownerName\":\"TestOwnerName\",\"shared\":true,\"description\":\"TestDescription\"}"
},{
"type": "GET",
"endpoint": "/dashboards/meta?shared=false",
"jsonInput": null,
"status": 200,
"message": "success",
"jsonOutput": "[{\"id\":1,\"createdById\":1,\"createdDate\":1472282830936,\"modifiedById\":1,\"modifiedDate\":1472282830936,\"name\":\"TestName\",\"content\":null,\"ownerName\":\"TestOwnerName\",\"shared\":false,\"description\":\"TestDescription\"}]"
}]

0 comments on commit 4a23f1d

Please sign in to comment.