use of org.codehaus.jettison.json.JSONException in project hadoop by apache.
the class TestAHSWebServices method setupClass.
@BeforeClass
public static void setupClass() throws Exception {
conf = new YarnConfiguration();
TimelineStore store = TestApplicationHistoryManagerOnTimelineStore.createStore(MAX_APPS);
TimelineACLsManager aclsManager = new TimelineACLsManager(conf);
aclsManager.setTimelineStore(store);
TimelineDataManager dataManager = new TimelineDataManager(store, aclsManager);
conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
conf.set(YarnConfiguration.YARN_ADMIN_ACL, "foo");
conf.setBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED, true);
conf.set(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, remoteLogRootDir);
dataManager.init(conf);
ApplicationACLsManager appAclsManager = new ApplicationACLsManager(conf);
ApplicationHistoryManagerOnTimelineStore historyManager = new ApplicationHistoryManagerOnTimelineStore(dataManager, appAclsManager);
historyManager.init(conf);
historyClientService = new ApplicationHistoryClientService(historyManager) {
@Override
protected void serviceStart() throws Exception {
// Do Nothing
}
};
historyClientService.init(conf);
historyClientService.start();
ahsWebservice = new AHSWebServices(historyClientService, conf) {
@Override
public String getNMWebAddressFromRM(Configuration configuration, String nodeId) throws ClientHandlerException, UniformInterfaceException, JSONException {
if (nodeId.equals(NM_ID)) {
return NM_WEBADDRESS;
}
return null;
}
};
fs = FileSystem.get(conf);
GuiceServletConfig.setInjector(Guice.createInjector(new WebServletModule()));
}
use of org.codehaus.jettison.json.JSONException in project hadoop by apache.
the class TestRMWebServicesReservation method getReservationIdTestHelper.
/**
* This method is used when a ReservationId is required. Attempt to use REST
* API. If authentication is not enabled, ensure that the response status is
* unauthorized and generate a ReservationId because downstream components
* require a ReservationId for testing.
* @param fallbackReservationId the ReservationId to use if authentication
* is not enabled, causing the getNewReservation
* API to fail.
* @return the object representing the reservation ID.
*/
private ReservationId getReservationIdTestHelper(int fallbackReservationId) throws Exception {
Thread.sleep(1000);
ClientResponse response = constructWebResource(GET_NEW_RESERVATION_PATH).type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class);
if (!this.isAuthenticationEnabled()) {
assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
return ReservationId.newInstance(clock.getTime(), fallbackReservationId);
}
System.out.println("RESPONSE:" + response);
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
ReservationId rid = null;
try {
rid = ReservationId.parseReservationId(json.getString("reservation-id"));
} catch (JSONException j) {
// failure is possible and is checked outside
}
return rid;
}
use of org.codehaus.jettison.json.JSONException in project ORCID-Source by ORCID.
the class SalesForceAdapter method createContactsWithRolesFromJson.
public List<Contact> createContactsWithRolesFromJson(JSONObject object) {
try {
JSONObject firstRecord = extractFirstRecord(object);
JSONObject contactRoles = firstRecord.getJSONObject("Membership_Contact_Roles__r");
List<JSONObject> objectsList = extractObjectListFromRecords(contactRoles);
return objectsList.stream().map(e -> mapperFacade.map(e, Contact.class)).collect(Collectors.toList());
} catch (JSONException e) {
throw new RuntimeException("Error getting contacts with roles list from SalesForce JSON", e);
}
}
use of org.codehaus.jettison.json.JSONException in project ORCID-Source by ORCID.
the class SalesForceAdapter method createConsortiumFromJson.
public Consortium createConsortiumFromJson(JSONObject results) {
try {
int numFound = JsonUtils.extractInt(results, "totalSize");
if (numFound == 0) {
return null;
}
Consortium consortium = new Consortium();
List<Opportunity> opportunityList = new ArrayList<>();
consortium.setOpportunities(opportunityList);
JSONArray records = results.getJSONArray("records");
JSONObject firstRecord = records.getJSONObject(0);
JSONObject opportunities = extractObject(firstRecord, "ConsortiaOpportunities__r");
if (opportunities != null) {
JSONArray opportunityRecords = opportunities.getJSONArray("records");
for (int i = 0; i < opportunityRecords.length(); i++) {
Opportunity salesForceOpportunity = new Opportunity();
JSONObject opportunity = opportunityRecords.getJSONObject(i);
salesForceOpportunity.setId(extractOpportunityId(opportunity));
JSONObject account = extractObject(opportunity, "Account");
salesForceOpportunity.setTargetAccountId(extractAccountId(account));
// salesForceOpportunity.setAccountName(JsonUtils.extractString(account,
// "Name"));
salesForceOpportunity.setAccountName(JsonUtils.extractString(account, "Public_Display_Name__c"));
opportunityList.add(salesForceOpportunity);
}
return consortium;
}
} catch (JSONException e) {
throw new RuntimeException("Error getting consortium record from SalesForce JSON", e);
}
return null;
}
use of org.codehaus.jettison.json.JSONException in project mirrorgate-jira-stories-collector by BBVA.
the class JiraIssueUtils method getPriorSprint.
public SprintDTO getPriorSprint(Object o) {
if (o == null) {
return null;
}
List<String> sprints = null;
if (o instanceof JSONArray) {
JSONArray array = (JSONArray) o;
sprints = new ArrayList<>(array.length());
for (int i = 0; i < array.length(); i++) {
try {
sprints.add((String) array.get(i));
} catch (JSONException e) {
LOGGER.error("Error parsing sprint field", e);
}
}
} else if (o instanceof List) {
sprints = (List<String>) o;
}
return getPriorSprint(sprints);
}
Aggregations