List of usage examples for java.io IOException getLocalizedMessage
public String getLocalizedMessage()
From source file:com.datascience.gal.service.Service.java
/** * resets the ds model//from w w w . ja va 2 s.c o m * * @return a simple success message */ @GET @Path("reset") @Produces(MediaType.APPLICATION_JSON) public Response reset(@QueryParam("id") String idString) { try { setup(context); if (idString != null) { String id = idString; dscache.deleteDawidSkene(id); } String message = "nullified the ds object" + (idString == null ? ", and deleted ds with id " + idString : ""); logger.info(message); return Response.ok(message).build(); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } logger.error("problem resetting dscache"); return Response.status(500).build(); }
From source file:com.datascience.gal.service.Service.java
@GET @Path("exists") @Produces(MediaType.APPLICATION_JSON)/*from www .j a v a 2 s. c om*/ public Response exists(@QueryParam("id") String idstr) { String id = "" + 0; if (null == idstr) { logger.info("no id input, using id 0"); } else { id = idstr; } try { setup(context); boolean contains = dscache.hasDawidSkene(id); String message = (contains ? "found ds object: " : "didnt find ds object: ") + id; logger.info(message); return Response.ok(JSONUtils.toJson(contains)).build(); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } catch (Exception e) { logger.error(e.getLocalizedMessage()); } return Response.status(500).build(); }
From source file:org.zenoss.zep.dao.impl.EventDaoHelper.java
public Map<String, Object> createOccurrenceFields(Event event) throws ZepException { Map<String, Object> fields = new HashMap<String, Object>(); String fingerprint = DaoUtils.truncateStringToUtf8(event.getFingerprint(), MAX_FINGERPRINT); fields.put(COLUMN_FINGERPRINT, fingerprint); Integer eventGroupId = null;/* w ww . j ava 2 s .c o m*/ if (event.hasEventGroup()) { String eventGroup = DaoUtils.truncateStringToUtf8(event.getEventGroup(), MAX_EVENT_GROUP); eventGroupId = daoCache.getEventGroupId(eventGroup); } fields.put(COLUMN_EVENT_GROUP_ID, eventGroupId); String eventClass = DaoUtils.truncateStringToUtf8(event.getEventClass(), MAX_EVENT_CLASS); fields.put(COLUMN_EVENT_CLASS_ID, daoCache.getEventClassId(eventClass)); Integer eventClassKeyId = null; if (event.hasEventClassKey()) { String eventClassKey = DaoUtils.truncateStringToUtf8(event.getEventClassKey(), MAX_EVENT_CLASS_KEY); eventClassKeyId = daoCache.getEventClassKeyId(eventClassKey); } fields.put(COLUMN_EVENT_CLASS_KEY_ID, eventClassKeyId); Integer eventKeyId = null; if (event.hasEventKey()) { String eventKey = DaoUtils.truncateStringToUtf8(event.getEventKey(), MAX_EVENT_KEY); eventKeyId = daoCache.getEventKeyId(eventKey); } fields.put(COLUMN_EVENT_KEY_ID, eventKeyId); Object eventClassMappingUuid = null; if (!event.getEventClassMappingUuid().isEmpty()) { eventClassMappingUuid = uuidConverter.toDatabaseType(event.getEventClassMappingUuid()); } fields.put(COLUMN_EVENT_CLASS_MAPPING_UUID, eventClassMappingUuid); fields.put(COLUMN_SEVERITY_ID, event.getSeverity().getNumber()); if (event.hasActor()) { populateEventActorFields(event.getActor(), fields); } Integer monitorId = null; if (event.hasMonitor()) { monitorId = daoCache.getMonitorId(DaoUtils.truncateStringToUtf8(event.getMonitor(), MAX_MONITOR)); } fields.put(COLUMN_MONITOR_ID, monitorId); Integer agentId = null; if (event.hasAgent()) { agentId = daoCache.getAgentId(DaoUtils.truncateStringToUtf8(event.getAgent(), MAX_AGENT)); } fields.put(COLUMN_AGENT_ID, agentId); Integer syslogFacility = null; if (event.hasSyslogFacility()) { syslogFacility = event.getSyslogFacility(); } fields.put(COLUMN_SYSLOG_FACILITY, syslogFacility); Integer syslogPriority = null; if (event.hasSyslogPriority()) { syslogPriority = event.getSyslogPriority().getNumber(); } fields.put(COLUMN_SYSLOG_PRIORITY, syslogPriority); Integer ntEventCode = null; if (event.hasNtEventCode()) { ntEventCode = event.getNtEventCode(); } fields.put(COLUMN_NT_EVENT_CODE, ntEventCode); fields.put(COLUMN_SUMMARY, DaoUtils.truncateStringToUtf8(event.getSummary(), MAX_SUMMARY)); fields.put(COLUMN_MESSAGE, DaoUtils.truncateStringToUtf8(event.getMessage(), MAX_MESSAGE)); String detailsJson = null; if (event.getDetailsCount() > 0) { try { detailsJson = JsonFormat.writeAllDelimitedAsString(mergeDuplicateDetails(event.getDetailsList())); // if the detailsJson string is too big, filter out non-Zenoss // details and try again. long eventMaxSizeBytes = zepConfigService.getConfig().getEventMaxSizeBytes(); if (!isValidDetailsSize(detailsJson, eventMaxSizeBytes)) { detailsJson = JsonFormat.writeAllDelimitedAsString( mergeDuplicateDetails(removeNonZenossDetails(event.getDetailsList()))); if (!isValidDetailsSize(detailsJson, eventMaxSizeBytes)) { // TODO: What to do when we can't reduce the size enough? logger.warn("Could not reduce event size below event_max_size_bytes setting: " + zepConfigService.getConfig().getEventMaxSizeBytes() + " Event: " + event); } } } catch (IOException e) { throw new ZepException(e.getLocalizedMessage(), e); } } fields.put(COLUMN_DETAILS_JSON, detailsJson); String tagsJson = null; if (event.getTagsCount() > 0) { List<EventTag> tags = buildTags(event); try { tagsJson = JsonFormat.writeAllDelimitedAsString(tags); } catch (IOException e) { throw new ZepException(e.getLocalizedMessage(), e); } } fields.put(COLUMN_TAGS_JSON, tagsJson); return fields; }
From source file:com.datascience.gal.service.Service.java
@GET @Path("printPriors") @Produces(MediaType.APPLICATION_JSON)//from www. j a va2 s . c o m public Response printPriors(@QueryParam("id") String idstr) { String output; String id = "" + 0; if (null == idstr) { logger.info("no id input, using id 0"); } else { id = idstr; } try { setup(context); DawidSkene ds = dscache.getDawidSkene(id); output = ds.printPriors(); String message = "returning request for object class probs"; logger.info(message); return Response.ok(output).build(); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } catch (Exception e) { logger.error(e.getLocalizedMessage()); } return Response.status(500).build(); }
From source file:com.datascience.gal.service.Service.java
@GET @Path("classPriors") @Produces(MediaType.APPLICATION_JSON)//from ww w.j av a 2 s .c o m public Response computePriors(@QueryParam("id") String idstr) { Map<String, Double> out = new HashMap<String, Double>(); String id = "" + 0; if (null == idstr) { logger.info("no id input, using id 0"); } else { id = idstr; } try { setup(context); DawidSkene ds = dscache.getDawidSkene(id); out = ds.computePriors(); String message = "returning request for object class probs"; logger.info(message); return Response.ok(JSONUtils.gson.toJson(out)).build(); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } catch (Exception e) { logger.error(e.getLocalizedMessage()); } return Response.status(500).build(); }
From source file:com.datascience.gal.service.Service.java
/** * add a worker-assigned label to the model * //ww w. j a va 2 s . co m * @return a simple success message */ @POST @Path("loadWorkerAssignedLabels") @Produces(MediaType.APPLICATION_JSON) public Response loadWorkerAssignedLabels(@FormParam("data") String data, @FormParam("id") String idstr) { Collection<AssignedLabel> input; String id = "" + 0; if (null == idstr) { logger.info("no id input, using id 0"); } else { id = idstr; } try { setup(context); input = JSONUtils.gson.fromJson(data, JSONUtils.assignedLabelSetType); DawidSkene ds = dscache.getDawidSkene(id); ds.addAssignedLabels(input); dscache.insertDawidSkene(ds); String message = "adding " + input.size() + " labels"; logger.info(message); return Response.ok(message).build(); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } catch (Exception e) { logger.error(e.getLocalizedMessage()); } return Response.status(500).build(); }
From source file:com.datascience.gal.service.Service.java
/** * computes majority votes for objects/*from w ww. j av a 2 s .c om*/ * * @return map of majority votes */ @GET @Path("majorityVotes") @Produces(MediaType.APPLICATION_JSON) public Response majorityVotes(@QueryParam("id") String idstr) { Map<String, String> votes; String id = "" + 0; if (null == idstr) { logger.info("no id input, using id 0"); } else { id = idstr; } try { setup(context); DawidSkene ds = dscache.getDawidSkene(id); votes = ds.getMajorityVote(); String message = "computing majority votes for " + (null == votes ? 0 : votes.size()) + " objects "; logger.info(message); return Response.ok(JSONUtils.gson.toJson(votes)).build(); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } catch (Exception e) { logger.error(e.getLocalizedMessage()); } return Response.status(500).build(); }
From source file:com.datascience.gal.service.Service.java
/** * computes class probs objects/* w ww . j ava 2 s. c o m*/ * * @return map of majority votes */ @GET @Path("objectProb") @Produces(MediaType.APPLICATION_JSON) public Response objectProb(@QueryParam("id") String idstr, @QueryParam("object") String objectName) { Map<String, Double> votes; String id = "" + 0; if (null == idstr) { logger.info("no id input, using id 0"); } else { id = idstr; } try { setup(context); DawidSkene ds = dscache.getDawidSkene(id); votes = ds.getObjectProbs(objectName); String message = "computing object probs for " + objectName; logger.info(message); return Response.ok(JSONUtils.gson.toJson(votes)).build(); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } catch (Exception e) { logger.error(e.getLocalizedMessage()); } return Response.status(500).build(); }
From source file:com.datascience.gal.service.Service.java
/** * add gold labels to the model/*from w w w . j a v a2 s . c o m*/ * * @return a simple success message */ @POST @Path("loadGoldLabels") @Produces(MediaType.APPLICATION_JSON) public Response loadGoldLabels(@FormParam("data") String data, @FormParam("id") String idstr) { Collection<CorrectLabel> input; String id = "" + 0; if (null == idstr) { logger.info("no id input, using id 0"); } else { id = idstr; } try { setup(context); DawidSkene ds = dscache.getDawidSkene(id); input = JSONUtils.gson.fromJson(data, JSONUtils.correctLabelSetType); ds.addCorrectLabels(input); dscache.insertDawidSkene(ds); String message = "adding " + input.size() + " gold labels"; logger.info(message); return Response.ok(message).build(); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } catch (Exception e) { logger.error(e.getLocalizedMessage()); } return Response.status(500).build(); }
From source file:com.datascience.gal.service.Service.java
@GET @Path("printObjectsProbs") @Produces(MediaType.APPLICATION_JSON)/* w w w . j a va 2s. c o m*/ public Response printObjectsProbs(@QueryParam("entropy") String ent, @QueryParam("id") String idstr) { String output; String id = "" + 0; if (null == idstr) { logger.info("no id input, using id 0"); } else { id = idstr; } try { setup(context); DawidSkene ds = dscache.getDawidSkene(id); double entropy = null == ent ? 0. : Double.parseDouble(ent); output = ds.printObjectClassProbabilities(entropy); String message = "returning request for object class probs"; logger.info(message); return Response.ok(output).build(); } catch (IOException e) { logger.error("ioexception: " + e.getLocalizedMessage()); } catch (ClassNotFoundException e) { logger.error("class not found exception: " + e.getLocalizedMessage()); } catch (SQLException e) { logger.error("sql exception: " + e.getLocalizedMessage()); } catch (Exception e) { logger.error(e.getLocalizedMessage()); } return Response.status(500).build(); }