Last active
April 27, 2016 07:18
-
-
Save GPrathap/d9299b20f1af2019cc1c049d55556b84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Path("device/stats/tableNames") | |
@GET | |
@Produces("application/json") | |
public Response getDataSourceNames() { | |
ObjectMapper mapper = new ObjectMapper(); | |
JsonNode rootNode = mapper.createObjectNode(); | |
ArrayNode dataSources = mapper.createArrayNode(); | |
try { | |
PrivilegedCarbonContext.startTenantFlow(); | |
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); | |
ctx.setTenantDomain("carbon.super", true); | |
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); | |
AnalyticsDataAPI analyticsDataAPI = new CarbonAnalyticsAPI(); | |
List<String> tableNames = analyticsDataAPI.listTables(tenantId); | |
for (String tableName : tableNames) { | |
JsonNode dataSourceDetails = mapper.createObjectNode(); | |
((ObjectNode) dataSourceDetails).put(Constants.SCHEMA_DEFINITION_COLUMN_NAME, tableName); | |
((ObjectNode) dataSourceDetails).put(Constants.SCHEMA_DEFINITION_COLUMN_TYPE, | |
Constants.DATA_SOURCE_TYPE_BATCH); | |
dataSources.add(dataSourceDetails); | |
} | |
((ObjectNode) rootNode).put(Constants.RESPONSE_STATUS, Constants.SUCCESS_MESSAGE); | |
((ObjectNode) rootNode).put(Constants.RESPONSE_MESSAGE, dataSources); | |
return Response.ok(rootNode.toString()).build(); | |
} catch (AnalyticsException e) { | |
log.error("Error while retrieving data from DAS, " + e); | |
((ObjectNode) rootNode).put(Constants.RESPONSE_STATUS, Constants.FAILURE_MESSAGE); | |
((ObjectNode) rootNode).put(Constants.RESPONSE_MESSAGE, e.getMessage()); | |
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(rootNode).build(); | |
} finally { | |
PrivilegedCarbonContext.endTenantFlow(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment