public MeasuredValueList getMeasuredValueList(MeasureDescriptor md, MeasuredValueFilter filter) throws MonitorException { if (filter.getInterval() != 300 && filter.getInterval() != 3600 && filter.getInterval() != 86400) return getMeasuredValueListRest(md, filter); else return getMeasuredValueListBD(md, filter); }
public MeasuredValueList getMeasuredValueList(MeasureDescriptor md, int samples) throws MonitorException { // TODO Auto-generated method stub MeasuredValueFilter filter = new MeasuredValueFilter(); filter.setFrom(new java.util.Date(0)); filter.setTo(new java.util.Date()); filter.setSamples(samples); filter.setInterval(new Long(0)); return getMeasuredValueListBD(md, filter); }
public MeasuredValueList getMeasuredValueListBD(MeasureDescriptor md, MeasuredValueFilter filter) throws MonitorException { String id = md.getMeasurementTypeId(); String element = id.substring(0, id.indexOf(URICreation.FQN_SEPARATOR_MEASURE) - 1); nodedirectory nd = db.get(nodedirectory.class, element); List<MeasuredValue> valueList; if ((md.getName().contains("netInput_") || md.getName().contains("netOutput_")) && nd.getTipo() != nodedirectory.TYPE_NIC) { valueList = db.getNetworkValues( nd, filter.getFrom(), filter.getTo(), filter.getSamples(), filter.getInterval(), md.getName(), md.getValueType()); } else { valueList = db.getMeasureValues( nd, filter.getFrom(), filter.getTo(), filter.getSamples(), filter.getInterval(), md.getName(), md.getValueType()); } MeasuredValueList mvl = new MeasuredValueList(md); for (MeasuredValue mv : valueList) { mvl.add(mv); } return mvl; }
public MeasuredValueList getMeasuredValueListJMS(MeasureDescriptor md, MeasuredValueFilter filter) throws MonitorException { try { SMIChannelEvent smi = new SMIChannelEvent(0, 0, SMIAction.GET_MEASURE_VALUE); Long seqNumber = ClothoUtils.getSecuenceNumber(); smi.put(SMIChannelEvent.SEQUENCE_NUMBER, seqNumber.toString()); String id = md.getMeasurementTypeId(); smi.put( SMIChannelEvent.FQN_ID, id.substring(0, id.indexOf(URICreation.FQN_SEPARATOR_MEASURE) - 1)); smi.put(SMIChannelEvent.MEASURE_NAME, md.getName()); smi.put(SMIChannelEvent.MEASURE_TYPE_ID, md.getMeasurementTypeId()); smi.put( SMIChannelEvent.MEASURE_FILTER_FROM, (filter.getFrom() == null) ? null : DataTypesUtils.date2String(filter.getFrom().getTime())); smi.put( SMIChannelEvent.MEASURE_FILTER_TO, (filter.getTo() == null) ? null : DataTypesUtils.date2String(filter.getTo().getTime())); smi.put(SMIChannelEvent.MEASURE_FILTER_NUMBER, String.valueOf(filter.getSamples())); smi.put(SMIChannelEvent.MEASURE_FILTER_INTERVAL, String.valueOf(filter.getInterval())); jmsConnectionData.smiChannelProducer.send(jmsConnectionData.session.createObjectMessage(smi)); MessageConsumer messageConsumer = jmsConnectionData.session.createConsumer( jmsConnectionData.smiChannelReply, "element = '" + md.getMeasurementTypeId() + "' AND " + SMIChannelEvent.SEQUENCE_NUMBER + "='" + seqNumber + "'"); ObjectMessage m = (ObjectMessage) messageConsumer.receive(ClothoUtils.EVENT_BUS_TIMEOUT); if (m == null) { log.error("Timeout waiting for a server response. Try later."); throw new MonitorException("Timeout waiting for a server response. Try later."); } smi = (SMIChannelEvent) m.getObject(); Map<String, String> values = (HashMap<String, String>) smi.getSerializable(SMIChannelEvent.MEASURE_VALUES); String units = smi.get(SMIChannelEvent.MEASURE_UNITS); MeasuredValueList mvl = new MeasuredValueList(); mvl.setHref(md.getHref() + URICreation.VALUES); for (String measureDate : values.keySet()) { MeasuredValue mv = new MeasuredValue(); mv.setUnit(units); mv.setValue(values.get(measureDate)); try { mv.setRegisterDate(DataTypesUtils.string2Date(measureDate)); } catch (ParseException e) { log.error("SMDeploymentDriver: Wrong date format received: " + measureDate); continue; } mvl.add(mv); } return mvl; } catch (JMSException e) { log.error( "SMDeploymentDriver: Communication error accessing the SLM. Impossible to retrieve service data.", e); throw new MonitorException( "SMDeploymentDriver: Communication error accessing the SLM. Impossible to retrieve service data." + e.getMessage()); } }