use of org.codehaus.jackson.JsonNode in project SimianArmy by Netflix.
the class EddaLaunchConfigJanitorCrawler method getLaunchConfigResourcesInRegion.
private List<Resource> getLaunchConfigResourcesInRegion(String region, String... launchConfigNames) {
String url = eddaClient.getBaseUrl(region) + "/aws/launchConfigurations;";
if (launchConfigNames != null && launchConfigNames.length != 0) {
url += StringUtils.join(launchConfigNames, ',');
LOGGER.info(String.format("Getting launch configurations in region %s for %d ids", region, launchConfigNames.length));
} else {
LOGGER.info(String.format("Getting all launch configurations in region %s", region));
}
url += ";_expand:(launchConfigurationName,createdTime)";
JsonNode jsonNode = null;
try {
jsonNode = eddaClient.getJsonNodeFromUrl(url);
} catch (Exception e) {
LOGGER.error(String.format("Failed to get Jason node from edda for instances in region %s.", region), e);
}
if (jsonNode == null || !jsonNode.isArray()) {
throw new RuntimeException(String.format("Failed to get valid document from %s, got: %s", url, jsonNode));
}
List<Resource> resources = Lists.newArrayList();
Set<String> usedLCs = getLaunchConfigsInUse(region);
for (Iterator<JsonNode> it = jsonNode.getElements(); it.hasNext(); ) {
JsonNode launchConfiguration = it.next();
String lcName = launchConfiguration.get("launchConfigurationName").getTextValue();
Resource lcResource = new AWSResource().withId(lcName).withRegion(region).withResourceType(AWSResourceType.LAUNCH_CONFIG).withLaunchTime(new Date(launchConfiguration.get("createdTime").getLongValue()));
lcResource.setOwnerEmail(getOwnerEmailForResource(lcResource));
lcResource.setAdditionalField(LAUNCH_CONFIG_FIELD_USED_BY_ASG, String.valueOf(usedLCs.contains(lcName)));
resources.add(lcResource);
}
return resources;
}
use of org.codehaus.jackson.JsonNode in project SimianArmy by Netflix.
the class EddaLaunchConfigJanitorCrawler method getLaunchConfigsInUse.
/**
* Gets the launch configs that are currently in use by at least one ASG in a region.
* @param region the region
* @return the set of launch config names
*/
private Set<String> getLaunchConfigsInUse(String region) {
LOGGER.info(String.format("Getting all launch configurations in use in region %s", region));
String url = eddaClient.getBaseUrl(region) + "/aws/autoScalingGroups;_expand:(launchConfigurationName)";
JsonNode jsonNode = null;
try {
jsonNode = eddaClient.getJsonNodeFromUrl(url);
} catch (Exception e) {
LOGGER.error(String.format("Failed to get Jason node from edda for launch configs in use in region %s.", region), e);
}
if (jsonNode == null || !jsonNode.isArray()) {
throw new RuntimeException(String.format("Failed to get valid document from %s, got: %s", url, jsonNode));
}
Set<String> launchConfigs = Sets.newHashSet();
for (Iterator<JsonNode> it = jsonNode.getElements(); it.hasNext(); ) {
launchConfigs.add(it.next().get("launchConfigurationName").getTextValue());
}
return launchConfigs;
}
use of org.codehaus.jackson.JsonNode in project SimianArmy by Netflix.
the class JanitorMonkeyResource method addEvent.
/**
* POST /api/v1/janitor will try a add a new event with the information in the url context.
*
* @param content
* the Json content passed to the http POST request
* @return the response
* @throws IOException
*/
@POST
public Response addEvent(String content) throws IOException {
ObjectMapper mapper = new ObjectMapper();
LOGGER.info(String.format("JSON content: '%s'", content));
JsonNode input = mapper.readTree(content);
String eventType = getStringField(input, "eventType");
String resourceId = getStringField(input, "resourceId");
String region = getStringField(input, "region");
Response.Status responseStatus;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonGenerator gen = JSON_FACTORY.createJsonGenerator(baos, JsonEncoding.UTF8);
gen.writeStartObject();
gen.writeStringField("eventType", eventType);
gen.writeStringField("resourceId", resourceId);
if (StringUtils.isEmpty(eventType) || StringUtils.isEmpty(resourceId)) {
responseStatus = Response.Status.BAD_REQUEST;
gen.writeStringField("message", "eventType and resourceId parameters are all required");
} else {
if (eventType.equals("OPTIN")) {
responseStatus = optInResource(resourceId, true, region, gen);
} else if (eventType.equals("OPTOUT")) {
responseStatus = optInResource(resourceId, false, region, gen);
} else {
responseStatus = Response.Status.BAD_REQUEST;
gen.writeStringField("message", String.format("Unrecognized event type: %s", eventType));
}
}
gen.writeEndObject();
gen.close();
LOGGER.info("entity content is '{}'", baos.toString("UTF-8"));
return Response.status(responseStatus).entity(baos.toString("UTF-8")).build();
}
use of org.codehaus.jackson.JsonNode in project NabAlive by jcheype.
the class ContesApplication method getRand.
public String getRand() throws IOException {
InputStream inputStream = getClass().getResourceAsStream("/contes.json");
JsonNode jsonNodes = mapper.readTree(inputStream);
Iterator<Map.Entry<String, JsonNode>> fields = jsonNodes.get("fields").get(0).get("values").getFields();
List<Map.Entry<String, JsonNode>> listFields = new ArrayList<Map.Entry<String, JsonNode>>();
while (fields.hasNext()) {
listFields.add(fields.next());
}
int sz = listFields.size();
return listFields.get(rand.nextInt(sz)).getValue().getTextValue();
}
use of org.codehaus.jackson.JsonNode in project pinot by linkedin.
the class IndexingConfigTest method testIgnoreUnknown.
@Test
public void testIgnoreUnknown() throws JSONException, IOException {
JSONObject json = new JSONObject();
json.put("invertedIndexColumns", Arrays.asList("a", "b", "c"));
json.put("sortedColumn", Arrays.asList("d", "e", "f"));
json.put("loadMode", "MMAP");
json.put("keyThatIsUnknown", "randomValue");
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(json.toString());
IndexingConfig indexingConfig = mapper.readValue(jsonNode, IndexingConfig.class);
Assert.assertEquals("MMAP", indexingConfig.getLoadMode());
List<String> invertedIndexColumns = indexingConfig.getInvertedIndexColumns();
Assert.assertEquals(3, invertedIndexColumns.size());
Assert.assertEquals("a", invertedIndexColumns.get(0));
Assert.assertEquals("b", invertedIndexColumns.get(1));
Assert.assertEquals("c", invertedIndexColumns.get(2));
List<String> sortedIndexColumns = indexingConfig.getSortedColumn();
Assert.assertEquals(3, sortedIndexColumns.size());
Assert.assertEquals("d", sortedIndexColumns.get(0));
Assert.assertEquals("e", sortedIndexColumns.get(1));
Assert.assertEquals("f", sortedIndexColumns.get(2));
}
Aggregations