@Override
  public void execute(HttpServletRequest req, HttpServletResponse resp, ConfigService configService)
      throws IOException {
    logger.debug("Getting PV's matching wildcard or regex for this appliance.");
    int limit = 500;
    String limitParam = req.getParameter("limit");
    if (limitParam != null) {
      limit = Integer.parseInt(limitParam);
    }

    String nameToMatch = null;
    if (req.getParameter("regex") != null) {
      nameToMatch = req.getParameter("regex");
      logger.debug("Finding PV's for regex " + nameToMatch);
    }

    if (req.getParameter("pv") != null) {
      nameToMatch = req.getParameter("pv");
      nameToMatch = nameToMatch.replace("*", ".*");
      nameToMatch = nameToMatch.replace("?", ".");
      logger.debug("Finding PV's for glob (converted to regex)" + nameToMatch);
    }

    Set<String> pvNamesMatchingRegex = configService.getPVsForApplianceMatchingRegex(nameToMatch);

    LinkedList<String> pvNames = new LinkedList<String>();
    if (limit == -1) {
      pvNames.addAll(pvNamesMatchingRegex);
    } else {
      int pvCount = 0;
      for (String matchedName : pvNamesMatchingRegex) {
        pvNames.add(matchedName);
        pvCount++;
        if (pvCount >= limit) break;
      }
    }

    resp.setContentType(MimeTypeConstants.APPLICATION_JSON);
    try (PrintWriter out = resp.getWriter()) {
      out.println(JSONValue.toJSONString(pvNames));
    } catch (Exception ex) {
      logger.error(
          "Exception getting all pvs on appliance "
              + configService.getMyApplianceInfo().getIdentity(),
          ex);
      resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
  }
예제 #2
0
  @Override
  public void execute(HttpServletRequest req, HttpServletResponse resp, ConfigService configService)
      throws IOException {
    String pvName = req.getParameter("pv");
    logger.debug("Checking to see if we are archiving PV " + pvName);

    resp.addHeader(MimeResponse.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
    resp.setContentType(MimeTypeConstants.APPLICATION_JSON);

    if (pvName == null || pvName.equals("")) {
      resp.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }

    // String pvNameFromRequest = pvName;
    String realName = configService.getRealNameForAlias(pvName);
    if (realName != null) pvName = realName;

    HashMap<String, String> retVal = new HashMap<String, String>();

    PVTypeInfo typeInfo = configService.getTypeInfoForPV(pvName);
    if (typeInfo == null) {
      typeInfo = configService.getTypeInfoForPV(PVNames.stripFieldNameFromPVName(pvName));
      if (typeInfo == null) {
        retVal.put("status", Boolean.FALSE.toString());
      } else {
        retVal.put("status", Boolean.TRUE.toString());
      }
    } else {
      retVal.put("status", Boolean.TRUE.toString());
    }

    try (PrintWriter out = resp.getWriter()) {
      out.println(JSONValue.toJSONString(retVal));
    } catch (Exception ex) {
      logger.error("Exception checking if we are archiving pv " + pvName, ex);
      resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
  }
예제 #3
0
 /**
  * Generate an EPICS PV.
  *
  * @param name The PV name.
  * @param configservice The config service used by this pv
  * @param isControlPV true if this is a pv controlling other pvs
  */
 EPICS_V3_PV(
     final String name,
     ConfigService configservice,
     boolean isControlPV,
     ArchDBRTypes archDBRTypes,
     int jcaCommandThreadId) {
   this(name, false, configservice, jcaCommandThreadId);
   this.archDBRType = archDBRTypes;
   if (archDBRTypes != null) {
     this.con = configservice.getArchiverTypeSystem().getJCADBRConstructor(archDBRType);
   }
   if (isControlPV) {
     this.controlledPVList = new ArrayList<String>();
   }
 }
  @Override
  public void execute(HttpServletRequest req, HttpServletResponse resp, ConfigService configService)
      throws IOException {
    String pvName = req.getParameter("pv");
    if (pvName == null || pvName.equals("")) {
      resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    Event event = configService.getETLLookup().getLatestEventFromDataStores(pvName);
    if (event != null) {
      resp.setContentType(MimeTypeConstants.APPLICATION_JSON);
      HashMap<String, String> result = new HashMap<String, String>();
      result.put("timestamp", TimeUtils.convertToISO8601String(event.getEventTimeStamp()));
      try (PrintWriter out = resp.getWriter()) {
        out.println(JSONValue.toJSONString(result));
      }
    } else {
      resp.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }
  }
예제 #5
0
  /** MonitorListener interface. */
  @Override
  public void monitorChanged(final MonitorEvent ev) {
    // final Logger log = Activator.getLogger();
    // This runs in a CA thread.
    // Ignore values that arrive after stop()
    if (!running) {
      return;
    }
    if (subscription == null) {
      return;
    }
    if (ev.getStatus() == null || !ev.getStatus().isSuccessful()) {
      return;
    }
    if (controlledPVList != null) {
      // this pv is control pv.
      try {
        updateAllControlPVEnablMent(ev);
      } catch (Exception e) {
        logger.error(
            "exception in monitor changed function when updatinng controlled pvs' enablement for "
                + this.name,
            e);
      }
      return;
    }
    state = PVConnectionState.GotMonitor;
    if (!connected) connected = true;
    try {
      try {
        DBR dbr = ev.getDBR();
        if (dbr == null) {
          return;
        }
        if (this.name.endsWith(".RTYP")) {
          String rtypName = (((DBR_String) dbr).getStringValue())[0];
          dbrtimeevent =
              new POJOEvent(
                  ArchDBRTypes.DBR_SCALAR_STRING,
                  TimeUtils.now(),
                  new ScalarStringSampleValue(rtypName),
                  0,
                  0);
          return;
        }
        // dbr.printInfo();

        ArchDBRTypes generatedDBRType = JCA2ArchDBRType.valueOf(dbr);
        if (archDBRType == null) {
          archDBRType = generatedDBRType;
          con = configservice.getArchiverTypeSystem().getJCADBRConstructor(archDBRType);
        } else {
          assert (con != null);
          if (generatedDBRType != archDBRType) {
            logger.warn(
                "The type of PV "
                    + this.name
                    + " has changed from "
                    + archDBRType
                    + " to "
                    + generatedDBRType);
            fireDroppedSample(PVListener.DroppedReason.TYPE_CHANGE);
            return;
          }
        }
        dbrtimeevent = con.newInstance(dbr);
        totalMetaInfo.computeRate(dbrtimeevent);
        dbr = null;
      } catch (Exception e) {
        logger.error(
            "exception in monitor changed function when converting DBR to dbrtimeevent for pv "
                + this.name,
            e);
      }

      updataMetaDataInParentPV(dbrtimeevent);
      // if this pv has meta data , handle here
      if (hasMetaField) {
        // //////////handle the field value when it
        // changes//////////////
        if (changedarchiveFieldsData.size() > 0) {
          logger.debug(
              "Adding changed field for pv " + name + " with " + changedarchiveFieldsData.size());
          HashMap<String, String> tempHashMap = new HashMap<String, String>();
          tempHashMap.putAll(changedarchiveFieldsData);
          // dbrtimeevent.s
          dbrtimeevent.setFieldValues(tempHashMap, true);
          changedarchiveFieldsData.clear();
        }
        // //////////////////////////
        // ////////////save all the fields once every day//////////////
        if (this.lastTimeStampWhenSavingarchiveFields == null) {
          if (allarchiveFieldsData.size() != 0) {
            saveMetaDataOnceEveryDay();
          }
        } else {
          Calendar currentCalendar = Calendar.getInstance();
          currentCalendar.add(Calendar.DAY_OF_MONTH, -1);
          if (currentCalendar.after(lastTimeStampWhenSavingarchiveFields)) {
            // Calendar currentCalendar2=Calendar.getInstance();
            saveMetaDataOnceEveryDay();
          }
        }
        // //////////////////////////////
      }
      fireValueUpdate();
    } catch (final Exception ex) {
      logger.error("exception in monitor changed for pv " + this.name, ex);
    }
  }