@NotNull
 private Map<String, Ref> getRemoteRefs(@NotNull Repository db, @NotNull GitVcsRoot gitRoot)
     throws Exception {
   long retryInterval = myConfig.getConnectionRetryIntervalMillis();
   int attemptsLeft = myConfig.getConnectionRetryAttempts();
   while (true) {
     final long start = System.currentTimeMillis();
     Transport transport = null;
     FetchConnection connection = null;
     try {
       transport =
           myTransportFactory.createTransport(
               db, gitRoot.getRepositoryFetchURL(), gitRoot.getAuthSettings());
       connection = transport.openFetch();
       return connection.getRefsMap();
     } catch (NotSupportedException nse) {
       throw friendlyNotSupportedException(gitRoot, nse);
     } catch (TransportException te) {
       attemptsLeft--;
       if (isRecoverable(te) && attemptsLeft > 0) {
         LOG.warn(
             "List remote refs failed: "
                 + te.getMessage()
                 + ", "
                 + attemptsLeft
                 + " attempt(s) left");
       } else {
         throw friendlyTransportException(te, gitRoot);
       }
     } catch (WrongPassphraseException e) {
       throw new VcsException(e.getMessage(), e);
     } finally {
       if (connection != null) connection.close();
       if (transport != null) transport.close();
       final long finish = System.currentTimeMillis();
       PERFORMANCE_LOG.debug(
           "[getRemoteRefs] repository: "
               + LogUtil.describe(gitRoot)
               + ", took "
               + (finish - start)
               + "ms");
     }
     Thread.sleep(retryInterval);
     retryInterval *= 2;
   }
 }
 /**
  * Expected fullPath format:
  *
  * <p>"<git revision hash>|<repository url>|<file relative path>"
  *
  * @param rootEntry indicates the association between VCS root and build configuration
  * @param fullPath change path from IDE patch
  * @return the mapped path
  */
 @NotNull
 public Collection<String> mapFullPath(
     @NotNull final VcsRootEntry rootEntry, @NotNull final String fullPath) {
   OperationContext context = createContext(rootEntry.getVcsRoot(), "map full path");
   try {
     return myMapFullPath.mapFullPath(context, rootEntry, fullPath);
   } catch (VcsException e) {
     LOG.warnAndDebugDetails(
         "Error while mapping path for root " + LogUtil.describe(rootEntry.getVcsRoot()), e);
     return Collections.emptySet();
   } catch (Throwable t) {
     LOG.error("Error while mapping path for root " + LogUtil.describe(rootEntry.getVcsRoot()), t);
     return Collections.emptySet();
   } finally {
     context.close();
   }
 }
 private void logBuildPatch(
     @NotNull VcsRoot root, @Nullable String fromRevision, @NotNull String toRevision) {
   StringBuilder msg = new StringBuilder();
   msg.append("Build");
   if (fromRevision != null) msg.append(" incremental");
   msg.append(" patch in VCS root ").append(LogUtil.describe(root));
   if (fromRevision != null) msg.append(" from revision ").append(fromRevision);
   msg.append(" to revision ").append(toRevision);
   LOG.info(msg.toString());
 }
 @NotNull
 public Map<String, Ref> getRemoteRefs(@NotNull final VcsRoot root) throws VcsException {
   OperationContext context = createContext(root, "list remote refs");
   GitVcsRoot gitRoot = context.getGitRoot();
   try {
     Repository db = context.getRepository();
     Map<String, Ref> remoteRefs = getRemoteRefs(db, gitRoot);
     if (LOG.isDebugEnabled())
       LOG.debug("Remote refs for VCS root " + LogUtil.describe(root) + ": " + remoteRefs);
     return remoteRefs;
   } catch (Exception e) {
     throw context.wrapException(e);
   } finally {
     context.close();
   }
 }
 @NotNull
 public RepositoryStateData getCurrentState(@NotNull GitVcsRoot gitRoot) throws VcsException {
   String refInRoot = gitRoot.getRef();
   String fullRef = GitUtils.expandRef(refInRoot);
   Map<String, String> branchRevisions = new HashMap<String, String>();
   for (Ref ref : getRemoteRefs(gitRoot.getOriginalRoot()).values()) {
     if (!ref.getName().startsWith("ref")) continue;
     if (!gitRoot.isReportTags() && isTag(ref) && !fullRef.equals(ref.getName())) continue;
     branchRevisions.put(ref.getName(), getRevision(ref));
   }
   if (branchRevisions.get(fullRef) == null && !gitRoot.isIgnoreMissingDefaultBranch()) {
     throw new VcsException(
         "Cannot find revision of the default branch '"
             + refInRoot
             + "' of vcs root "
             + LogUtil.describe(gitRoot));
   }
   return RepositoryStateData.createVersionState(fullRef, branchRevisions);
 }
  /** Handles XEP-0337 "log" extensions. */
  private void handleLogRequest(LogPacketExtension log, String jid) {
    JitsiMeetConference conference = getConferenceForMucJid(jid);

    if (conference == null) {
      logger.debug("Room not found for JID: " + jid);
      return;
    }

    Participant participant = conference.findParticipantForRoomJid(jid);

    if (participant == null) {
      logger.info("Ignoring log request from an unknown JID: " + jid);
      return;
    }

    EventAdmin eventAdmin = FocusBundleActivator.getEventAdmin();

    if (eventAdmin == null) return;

    if (LogUtil.LOG_ID_PC_STATS.equals(log.getID())) {
      String content = LogUtil.getContent(log);

      if (content != null) {
        ColibriConference colibriConference = conference.getColibriConference();

        if (colibriConference != null) {
          Event event =
              EventFactory.peerConnectionStats(
                  colibriConference.getConferenceId(), participant.getEndpointId(), content);

          if (event != null) eventAdmin.sendEvent(event);
        } else {
          logger.warn("Unhandled log request" + " - no valid Colibri conference");
        }
      }
    } else if (logger.isInfoEnabled()) {
      logger.info("Ignoring log request with an unknown ID:" + log.getID());
    }
  }
Exemple #7
0
  /**
   * Make a dataset with the file
   *
   * @return dataset
   */
  private RaobDataSet doMakeRaobDataSet() {
    SoundingAdapter adapter = null;
    try {
      adapter = new NetcdfSoundingAdapter(file);
    } catch (Exception ill) {
    }

    if (adapter == null) {
      try {
        adapter = new CMASoundingAdapter(file);
      } catch (Exception exc) {
        LogUtil.logException("Reading sounding:" + file, exc);
        return null;
      }
    }

    if (adapter == null) {
      throw new IllegalArgumentException("Could not open sounding file:" + file);
    }

    SoundingOb[] obs = adapter.getSoundingObs();
    return new RaobDataSet(adapter, Misc.toList(obs));
  }
  public void persist() {
    DataElementConcept dec = DomainObjectFactory.newDataElementConcept();
    List<DataElementConcept> decs = elements.getElements(dec);
    logger.debug("***** Inside DEC Persist ");
    int count = 0;
    sendProgressEvent(count++, decs.size(), "DECs");

    logger.debug("decs... ");
    if (decs != null) {
      for (ListIterator<DataElementConcept> it = decs.listIterator(); it.hasNext(); ) {
        DataElementConcept newDec = DomainObjectFactory.newDataElementConcept();
        dec = it.next();

        sendProgressEvent(count++, decs.size(), "DEC : " + dec.getLongName());

        List<AlternateName> passedAltNames = new ArrayList<AlternateName>();
        for (AlternateName _an : dec.getAlternateNames()) passedAltNames.add(_an);

        List<Definition> modelDefinitions = new ArrayList<Definition>();
        for (Definition _def : dec.getDefinitions()) modelDefinitions.add(_def);

        List<AdminComponentClassSchemeClassSchemeItem> passedACCSCSI = dec.getAcCsCsis();

        dec.removeDefinitions();
        dec.removeAlternateNames();

        if (!StringUtil.isEmpty(dec.getPublicId()) && dec.getVersion() != null) {
          newDec = existingMapping(dec);
          dec.setId(newDec.getId());
          for (AlternateName _an : passedAltNames) {
            persisterUtil.addAlternateName(dec, _an);
          }
          it.set(newDec);
          persisterUtil.addPackageClassification(dec);
          logger.info(PropertyAccessor.getProperty("mapped.to.existing.dec"));
          continue;
        }

        // update object class with persisted one
        if (dec.getObjectClass().getPublicId() == null)
          dec.setObjectClass(LookupUtil.lookupObjectClass(dec.getObjectClass().getPreferredName()));
        else
          dec.setObjectClass(
              LookupUtil.lookupObjectClass(
                  dec.getObjectClass().getPublicId(), dec.getObjectClass().getVersion()));

        newDec.setObjectClass(dec.getObjectClass());

        // update property with persisted one
        if (dec.getProperty().getPublicId() == null)
          dec.setProperty(LookupUtil.lookupProperty(dec.getProperty().getPreferredName()));
        else
          dec.setProperty(
              LookupUtil.lookupProperty(
                  dec.getProperty().getPublicId(), dec.getProperty().getVersion()));

        newDec.setProperty(dec.getProperty());

        logger.debug("dec name: " + dec.getLongName());
        //        logger.debug("alt Name: " + ne);

        List<String> eager = new ArrayList<String>();
        eager.add("definitions");

        // does this dec exist?
        List l = dataElementConceptDAO.find(newDec, eager);
        logger.debug("***** decs size : " + l.size());
        if (l.size() == 0) {
          logger.debug("***** one or more decs ");
          if (dec.getConceptualDomain() == null)
            dec.setConceptualDomain(defaults.getConceptualDomain());
          dec.setContext(defaults.getContext());
          dec.setLongName(
              dec.getObjectClass().getLongName() + " " + dec.getProperty().getLongName());
          dec.setPreferredDefinition(
              dec.getObjectClass().getPreferredDefinition()
                  + DEC_PREFERRED_DEF_CONCAT_CHAR
                  + dec.getProperty().getPreferredDefinition());

          dec.setPreferredName(
              ConventionUtil.publicIdVersion(dec.getObjectClass())
                  + DEC_PREFERRED_NAME_CONCAT_CHAR
                  + ConventionUtil.publicIdVersion(dec.getProperty()));

          dec.setVersion(new Float(1.0f));
          dec.setWorkflowStatus(defaults.getWorkflowStatus());

          dec.setProperty(LookupUtil.lookupProperty(dec.getProperty().getPreferredName()));

          dec.setAudit(defaults.getAudit());
          dec.setLifecycle(defaults.getLifecycle());

          StringBuilder builder = new StringBuilder();
          for (char currentChar : dec.getPreferredDefinition().toCharArray()) {
            Character replacementChar = charReplacementMap.get(currentChar);
            builder.append(replacementChar != null ? replacementChar : currentChar);
          }
          dec.setPreferredDefinition(builder.toString());
          logger.debug(
              "***** preferred name " + dec.getPreferredName() + " public ID " + dec.getPublicId());
          newDec = dataElementConceptDAO.create(dec);
          logger.info(PropertyAccessor.getProperty("created.dec"));

        } else {
          newDec = (DataElementConcept) l.get(0);
          logger.info(PropertyAccessor.getProperty("existed.dec"));

          /* if DEC alreay exists, check context
           * If context is different, add Used_by alt_name
           */
          dec.setId(newDec.getId());

          if (!newDec.getContext().getId().equals(defaults.getContext().getId())) {
            AlternateName _an = DomainObjectFactory.newAlternateName();
            _an.setName(defaults.getContext().getName());
            _an.setType(AlternateName.TYPE_USED_BY);
            persisterUtil.addAlternateName(dec, _an);
          }
        }

        dec.setId(newDec.getId());
        for (AlternateName _an : passedAltNames) {
          persisterUtil.addAlternateName(dec, _an);
        }

        for (Definition def : modelDefinitions) {
          persisterUtil.addAlternateDefinition(dec, def);
        }

        LogUtil.logAc(newDec, logger);
        logger.info("-- Public ID: " + newDec.getPublicId());
        logger.info(
            PropertyAccessor.getProperty("oc.longName", newDec.getObjectClass().getLongName()));
        logger.info(
            PropertyAccessor.getProperty("prop.longName", newDec.getProperty().getLongName()));

        dec.setAcCsCsis(passedACCSCSI);
        persisterUtil.addPackageClassification(dec);
        it.set(newDec);

        // dec still referenced in DE. Need ID to retrieve it in DEPersister.
        dec.setId(newDec.getId());
      }
    }
    logger.debug("***** End DEC persist");
  }
  /**
   * Get the data for the given DataChoice and selection criteria.
   *
   * @param dataChoice DataChoice for selection
   * @param category DataCategory for the DataChoice (not used)
   * @param subset subsetting criteria
   * @param requestProperties extra request properties
   * @return the Data object for the request
   * @throws RemoteException couldn't create a remote data object
   * @throws VisADException couldn't create the data
   */
  protected Data getDataInner(
      final DataChoice dataChoice,
      DataCategory category,
      final DataSelection subset,
      final Hashtable requestProperties)
      throws VisADException, RemoteException {

    try {
      List times = null;
      if (subset != null) {
        times = getTimesFromDataSelection(subset, dataChoice);
      }
      if (times == null) {
        times = dataChoice.getSelectedDateTimes();
      }

      List dtimes = subset.getTimeDriverTimes();

      if (dtimes != null && useDriverTime == false) {
        useDriverTime = true;
      }

      List<RadarAdapter> adapters = getAdapters();

      DateTime[] realDateTimes = new DateTime[adapters.size()];
      for (int i = 0; i < adapters.size(); i++) {
        realDateTimes[i] = ((RadarAdapter) adapters.get(i)).getBaseTime();
      }
      Arrays.sort(realDateTimes);
      // Flip it to get youngest date first
      boolean isRealTime = isRealTime();
      if (isRealTime) {
        realDateTimes =
            (DateTime[]) Misc.reverseArray(realDateTimes, new DateTime[realDateTimes.length]);
      }
      // if use time driver
      if (useDriverTime) {
        List tests = resetTimesList(realDateTimes, times);
        if (!compareTimeLists(times, tests)) {
          reloadData();
          adapters = getAdapters();

          realDateTimes = new DateTime[adapters.size()];
          for (int i = 0; i < adapters.size(); i++) {
            realDateTimes[i] = ((RadarAdapter) adapters.get(i)).getBaseTime();
          }
          Arrays.sort(realDateTimes);
          // Flip it to get youngest date first
          isRealTime = isRealTime();
          if (isRealTime) {
            realDateTimes =
                (DateTime[]) Misc.reverseArray(realDateTimes, new DateTime[realDateTimes.length]);
          }
          tests = resetTimesList(realDateTimes, times);
        }
        times = tests;
      }
      // if times are null, then that means all times
      DateTime[] dateTimes = null;

      if ((times == null) || (times.size() == 0)) {
        dateTimes = realDateTimes;
      } else {
        dateTimes = new DateTime[times.size()];
        for (int i = 0; i < times.size(); i++) {
          Object time = times.get(i);
          if (time instanceof TwoFacedObject) {
            int index = ((Integer) ((TwoFacedObject) time).getId()).intValue();
            dateTimes[i] = realDateTimes[index];
          } else if (time instanceof DateTime) {
            dateTimes[i] = (DateTime) time;
          }
        }
      }
      Arrays.sort(dateTimes);
      final Data[] datas = new Data[dateTimes.length];
      int timeIndex = 0;
      final MathType[] mt = {null};
      // create a new field of (Time -> (radar data)).
      // fill in the times array and data array with dates/data
      // only from those adapters which match the selected times.
      // if a data object is null, stick it in the list.
      // if all are null, then the MathType (mt) will never get set,
      // so return null.
      //            System.err.println ("Reading " + adapters.size() + " radar files");
      int cnt = 0;
      ThreadManager threadManager = new visad.util.ThreadManager("radar data reading");

      for (Iterator iter = adapters.iterator(); iter.hasNext(); ) {
        final RadarAdapter adapter = (RadarAdapter) iter.next();
        timeIndex = Arrays.binarySearch(dateTimes, adapter.getBaseTime());
        //              System.err.println ("timeIndex:" + timeIndex);
        if (timeIndex < 0) {
          continue;
        }
        cnt++;
        LogUtil.message("Time: " + (cnt) + "/" + dateTimes.length + " From:" + toString());
        final int theTimeIndex = timeIndex;
        threadManager.addRunnable(
            new visad.util.ThreadManager.MyRunnable() {
              public void run() throws Exception {
                Trace.call1("RDS.getData");
                Data d = adapter.getData(dataChoice, subset, requestProperties);
                Trace.call2("RDS.getData");
                datas[theTimeIndex] = d;
                if (d != null) {
                  mt[0] = d.getType();
                } else {
                }
              }
            });
      }

      try {
        // threadManager.debug = true;
        threadManager.runInParallel(getDataContext().getIdv().getMaxDataThreadCount());
      } catch (VisADException ve) {
        LogUtil.printMessage(ve.toString());
      }

      if (mt[0] == null) {
        return null;
      }

      FunctionType ft = new FunctionType(RealType.Time, mt[0]);
      SampledSet domainSet =
          (dateTimes.length == 1)
              ? (SampledSet) new SingletonSet(new RealTuple(dateTimes))
              : (SampledSet) DateTime.makeTimeSet(dateTimes);
      FieldImpl fi = new FieldImpl(ft, domainSet);
      fi.setSamples(datas, false);
      return fi;
    } catch (Exception exc) {
      logException("Creating obs", exc);
    }
    return null;
  }
  /**
   * Make the adapters for the given list of files
   *
   * @param files Data files
   * @throws Exception When bad things happen
   */
  private void makeAdapters(List files) throws Exception {
    adapters = new ArrayList<RadarAdapter>();
    Hashtable<String, RadarAdapter> oldAdapterMap = fileToAdapter;
    fileToAdapter = new Hashtable<String, RadarAdapter>();

    int cnt = 0;

    final List<String> badFiles = new ArrayList<String>();
    final List<Exception> badExceptions = new ArrayList<Exception>();

    final List<RadarAdapter> goodAdapters = new ArrayList<RadarAdapter>();
    final List<String> goodFiles = new ArrayList<String>();
    visad.util.ThreadManager threadManager =
        new visad.util.ThreadManager("radar data initialization");
    LogUtil.message("Initializing radar files");
    for (Iterator iter = files.iterator(); iter.hasNext(); ) {
      final String filename = iter.next().toString();
      RadarAdapter adapter = (RadarAdapter) oldAdapterMap.get(filename);
      cnt++;
      if (adapter == null) {
        threadManager.addRunnable(
            new visad.util.ThreadManager.MyRunnable() {
              public void run() throws Exception {
                try {
                  RadarAdapter myAdapter = makeRadarAdapter(filename);
                  synchronized (goodAdapters) {
                    goodAdapters.add(myAdapter);
                    goodFiles.add(filename);
                  }
                } catch (Exception e) {
                  synchronized (badExceptions) {
                    badExceptions.add(e);
                    badFiles.add(filename);
                  }
                }
              }
            });
      } else {
        goodAdapters.add(adapter);
        goodFiles.add(filename);
      }
    }

    //        threadManager.debug = true;
    threadManager.runInParallel(getDataContext().getIdv().getMaxDataThreadCount());
    LogUtil.message("");

    for (int i = 0; i < goodAdapters.size(); i++) {
      adapters.add(goodAdapters.get(i));
      fileToAdapter.put(goodFiles.get(i), goodAdapters.get(i));
    }

    if (!badFiles.isEmpty()) {
      StringBuffer buf = new StringBuffer();
      if (badFiles.size() < files.size()) {
        buf.append("<html>");
        buf.append("There were problems reading these files:");
        buf.append("<ul>");
        for (Iterator iterator = badFiles.iterator(); iterator.hasNext(); ) {
          buf.append("<li>");
          buf.append((String) iterator.next());
          buf.append("</li>");
        }
        buf.append("</ul>");
        buf.append("<p>Continue loading good data?<p></html>");
        boolean ok = ucar.unidata.util.GuiUtils.askYesNo("Error reading data", buf.toString());

        badExceptions.get(0).printStackTrace();
        if (ok) {
          files.removeAll(badFiles);
        } else {
          throw new VisADException("error reading files");
        }
      } else {
        throw badExceptions.get(0);
      }
    }
    // clean up any old adapters
    for (String source : oldAdapterMap.keySet()) {
      if (fileToAdapter.get(source) == null) {
        ((RadarAdapter) oldAdapterMap.get(source)).doRemove();
      }
    }
    oldAdapterMap = null;
  }