Example #1
0
  public static void tearDown(PVob pvob) throws CleartoolException {
    Set<UCMView> views = pvob.getViews();

    /* The pvob needs to be loaded */
    pvob.load();

    logger.config("Removing views");
    for (UCMView view : views) {
      logger.fine("Removing " + view);
      try {
        view.end();
        view.remove();
      } catch (ViewException e) {
        ExceptionUtils.log(e, true);
      }
    }

    Set<Vob> vobs = pvob.getVobs();

    logger.config("Removing vobs");
    for (Vob vob : vobs) {
      logger.fine("Removing " + vob);
      try {
        vob.unmount();
        vob.remove();
      } catch (CleartoolException e) {
        ExceptionUtils.log(e, true);
      }
    }

    logger.config("Removing pvob");
    pvob.unmount();
    pvob.remove();

    /* For Jens' sake */
    /*
    try {
    	logger.debug( "Checking views: " + CommandLine.getInstance().run( "rgy_check -views" ).stdoutBuffer );
    } catch( Exception e ) {
    	// Because rgy_check returns 1 if anything stranded
    	e.printStackTrace();
    }
    */

    /*
    try {
    	logger.debug( "Checking vobs: " + CommandLine.getInstance().run( "rgy_check -vobs" ).stdoutBuffer );
    } catch( Exception e ) {
    	e.printStackTrace();
    }
    */
  }
Example #2
0
 /**
  * HDFS Path에서 IP주소를 추출한다.
  *
  * @param path HDFS Path
  * @return IP Address
  */
 public static String getIpAddressFromPath(String path) {
   if (!path.startsWith(HDFS_URL_PREFIX)) {
     throw new FileSystemException(ExceptionUtils.getMessage("Invalid path '{}'", path));
   }
   String[] split = org.springframework.util.StringUtils.delete(path, HDFS_URL_PREFIX).split(":");
   return split[0];
 }
Example #3
0
 /**
  * 지정한 경로를 생성한다.
  *
  * @param fs FileSystem
  * @param path 생성할 경로
  * @return 정상적으로 생성한 경우 <tt>true</tt>
  */
 public static boolean mkdir(FileSystem fs, String path) {
   try {
     return FileSystem.mkdirs(fs, new Path(path), FsPermission.getDefault());
   } catch (Exception ex) {
     throw new FileSystemException(ExceptionUtils.getMessage("Cannot create '{}'", path), ex);
   }
 }
Example #4
0
 /**
  * 지정한 경로를 삭제한다.
  *
  * @param fs FileSystem
  * @param path 삭제할 경로
  * @return 정상적으로 삭제한 경우 <tt>true</tt>
  */
 public static boolean delete(FileSystem fs, String path) {
   try {
     return fs.delete(new Path(path), true);
   } catch (Exception ex) {
     throw new FileSystemException(ExceptionUtils.getMessage("Cannot delete '{}'", path), ex);
   }
 }
Example #5
0
 /**
  * 지정한 경로가 파일인지 확인한다.
  *
  * @param fs FileSystem
  * @param path 확인할 Path
  * @return 파일인 경우 <tt>true</tt>
  */
 public static boolean isFile(FileSystem fs, String path) {
   try {
     return fs.isFile(new Path(path));
   } catch (Exception ex) {
     throw new FileSystemException(ExceptionUtils.getMessage("Cannot access '{}'", path), ex);
   }
 }
Example #6
0
 @Override
 protected void onException(NoNetworkException e) throws RuntimeException {
   ExceptionUtils.showException(
       e,
       "from cache: \n" + dianeSampleAwareSearcher.getResult(),
       textView,
       dianeSampleAwareSearcher);
 }
Example #7
0
  @Override
  public void postToFeed(final User user, final Throwable ex) {
    LogHelper.logException(this.getClass(), ex);
    try {
      postToFeed(user, ExceptionUtils.getStackTrace(ex), FeedType.error);

    } catch (NimbitsException e) {
      LogHelper.logException(this.getClass(), e);
    }
  }
 private static void check() {
   if (configuration == null) {
     FreeMarkerConfigurer freeMarkerConfigurer = SpringUtils.getBean("freemarkerConfigurer");
     if (freeMarkerConfigurer != null) {
       configuration = freeMarkerConfigurer.getConfiguration();
     } else {
       ExceptionUtils.throwRuntimeException("spring has not freemarkerConfigurer");
     }
   }
 }
Example #9
0
 /**
  * HDFS Path에서 Port를 추출한다.
  *
  * @param path HDFS Path
  * @return Port
  */
 public static String getPortFromPath(String path) {
   if (!path.startsWith(HDFS_URL_PREFIX)) {
     throw new FileSystemException(ExceptionUtils.getMessage("Invalid path '{}'", path));
   }
   String[] split = org.springframework.util.StringUtils.delete(path, HDFS_URL_PREFIX).split(":");
   if (split.length != 2) {
     throw new FileSystemException(
         "Invalid path pattern. Path pattern must be \"hdfs://IP:PORT\".");
   }
   return split[1];
 }
Example #10
0
 @SuppressWarnings("unchecked")
 public V call(Object... args) {
   try {
     return (V) getMetaClass().invokeMethod(this, "doCall", args);
   } catch (InvokerInvocationException e) {
     ExceptionUtils.sneakyThrow(e.getCause());
     return null; // unreachable statement
   } catch (Exception e) {
     return (V) throwRuntimeException(e);
   }
 }
Example #11
0
  /**
   * 지정한 경로의 파일을 문자열로 로딩한다. 다음의 조건에 해당하면 처리하지 않는다.
   *
   * <ul>
   *   <li>파일이 아닌 경우
   *   <li>파일의 크기가
   * </ul>
   *
   * @param fs Hadoop의 {@link org.apache.hadoop.fs.FileSystem}
   * @param path Path
   * @param encoding 인코딩
   * @return 문자열
   */
  public static String load(FileSystem fs, String path, String encoding) {
    try {
      FileStatus fileStatus = fs.getFileStatus(new Path(path));
      long length = fileStatus.getLen();
      if (length > MAX_SIZE) {
        throw new IllegalArgumentException("Exceeded " + MAX_SIZE + " bytes : '" + path + "'");
      }
    } catch (Exception ex) {
      throw new FileSystemException(ExceptionUtils.getMessage("Cannot access '{}'", path), ex);
    }

    FSDataInputStream is = null;
    try {
      is = fs.open(new Path(path));
      return IOUtils.toString(is, encoding);
    } catch (IOException e) {
      throw new FileSystemException(ExceptionUtils.getMessage("Cannot load '{}'", path), e);
    } finally {
      IOUtils.closeQuietly(is);
    }
  }
  /**
   * Send mailNotications.
   *
   * @param message The message body itself
   * @param eventType Type of notification
   * @param e An exception (can be null)
   */
  private void sendMailNotifications(String message, NotificationType eventType, Throwable e) {
    String subjectPrefix = SUBJECT_PREFIX + "-" + eventType + ": ";

    // Subject is a specified string + first line of error message
    String subject = subjectPrefix + message.split("\n")[0];

    // Body consists of four parts.
    StringBuffer body = new StringBuffer();

    // 1: The host of the message
    body.append("Host: " + SystemUtils.getLocalHostName() + "\n");
    body.append("Date: " + new Date().toString() + "\n");

    // 2: The origin of the message, found by inspecting stack trace
    for (StackTraceElement elm : Thread.currentThread().getStackTrace()) {
      if (!elm.toString().startsWith(getClass().getName())
          && !elm.toString().startsWith(Notifications.class.getName())
          && !elm.toString().startsWith(Thread.class.getName())) {
        body.append(elm.toString() + "\n");
        break;
      }
    }

    // 3: The given message
    body.append(message + "\n");

    // 4: Optionally the exception
    if (e != null) {
      body.append(ExceptionUtils.getStackTrace(e));
    }

    try {
      // Send the mail
      EMailUtils.sendEmail(MAIL_RECEIVER, MAIL_SENDER, subject, body.toString());

      // Log as error

      log.error("Mailing {}{}", subjectPrefix, message, e);
    } catch (Exception e1) {
      // On trouble: Log and print it to system out, it's the best we can
      // do!

      String msg =
          "Could not send email on "
              + eventType.toString().toLowerCase()
              + " notification:\n"
              + body.toString()
              + "\n";
      System.err.println(msg);
      e1.printStackTrace(System.err);
      log.error(msg, e1);
    }
  }
Example #13
0
  public static void handleException(RestRequest request, RestResponse response, Throwable ex) {

    Throwable rootCause = ExceptionUtils.getRootCause(ex);
    rootCause = rootCause == null ? ex : rootCause;

    logger.error("捕获到Rest异常:request={}", request, rootCause);
    RestError restError = new RestError();
    restError.setErrorCode(2);

    if (ex instanceof RestServiceException) {

      RestServiceException rse = (RestServiceException) ex;

      if (rse.getErrorCode() != 0) {

        restError.setErrorCode(rse.getErrorCode());
      }

      restError.setErrorInfo(rse.getMessage());

    } else {

      restError.setErrorInfo(RestApiConstants.DEFAULT_ERROR_INFO);

      if (request.isDebug()) {

        String stackTrace = ExceptionUtils.getStackTrace(rootCause);
        // 截取有用的部分
        stackTrace = StringUtils.substringBefore(stackTrace, RestApiConstants.STACK_TRACE_BEFORE);
        response.setDebugInfo(stackTrace);
      }

      // 统计响应结果
      recordToErrorCounter(request.getCmd());
    }

    response.setStatusCode(500);
    response.setError(restError);
    response.setResponseTime(new Date());
  }
 /**
  * 지정한 URL에 대해서 Input Stream을 반환한다.
  *
  * @param url URL
  * @return Input Stream
  */
 public static InputStream openStream(String url) {
   String message = ExceptionUtils.getMessage("URL '{}' 리소스에 대해서 Input Stream을 얻을 수 없습니다.", url);
   try {
     return new URL(url).openStream();
   } catch (MalformedURLException ex) {
     if (ex.getMessage().contains("no protocol") && url.startsWith("/")) {
       try {
         return new URL("file:" + url).openStream();
       } catch (Exception e) {
         throw new SystemException(message, e);
       }
     }
     throw new SystemException(message, ex);
   } catch (Exception ex) {
     throw new SystemException(message, ex);
   }
 }
 /**
  * 지정한 URL에 대해서 리소스가 존재하는지 확인한다.
  *
  * @param url URL
  * @return 존재하는 경우 <tt>true</tt>
  */
 public static boolean isExist(String url) {
   String message = ExceptionUtils.getMessage("URL '{}' 리소스에 대해서 Input Stream을 얻을 수 없습니다.", url);
   InputStream inputStream = null;
   try {
     inputStream = new URL(url).openStream();
     return true;
   } catch (MalformedURLException ex) {
     if (ex.getMessage().contains("no protocol") && url.startsWith("/")) {
       try {
         inputStream = new URL("file:" + url).openStream();
         return true;
       } catch (Exception e) {
         return false;
       }
     }
     return false;
   } catch (Exception ex) {
     return false;
   } finally {
     IOUtils.closeQuietly(inputStream);
   }
 }
Example #16
0
 /*
  * (non-Javadoc)
  *
  * @see org.apache.commons.collections.MultiHashMap#createCollection(java.util.Collection)
  */
 public Collection<V> createCollection(Collection coll) {
   if (this.collectionClass != null)
     try {
       if (coll == null) {
         return this.collectionClass.newInstance();
       } else {
         return this.collectionClass
             .getConstructor(new Class[] {Collection.class})
             .newInstance(new Object[] {coll});
       }
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
   else if (this.collectionSpecimen != null) {
     try {
       final Collection<V> res = CopyUtils.copy(this.collectionSpecimen);
       if (coll != null) res.addAll(coll);
       return res;
     } catch (Exception e) {
       throw ExceptionUtils.createExn(IllegalStateException.class, "clone() failed", e);
     }
   } else return super.createCollection(coll);
 }
Example #17
0
 @Override
 protected void onGenericException(Exception e) throws RuntimeException {
   ExceptionUtils.showException(e, textView, dianeSampleAwareSearcher);
   //		e.printStackTrace();
 }
Example #18
0
 private String getTrace() {
   return ExceptionUtils.getStackTrace(this);
 }
Example #19
0
 @Override
 protected void onException(CacheTooOldException e) throws RuntimeException {
   ExceptionUtils.showException(e, textView, dianeSampleAwareSearcher);
 };
Example #20
0
 @Override
 protected void onException(LocationNotSoUsefulException e) throws RuntimeException {
   ExceptionUtils.showException(e, textView, dianeSampleAwareSearcher);
 }
Example #21
0
 @Override
 protected void onException(NetworkAwareSearchException e) throws RuntimeException {
   textView.setText(textView.getText() + dianeSampleAwareSearcher.getResult() + "\n\n");
   ExceptionUtils.showException(
       e, "no address geocoding because the exception:", textView, dianeSampleAwareSearcher);
 }
Example #22
0
 protected void onException(StillSearchException e) throws RuntimeException {
   ExceptionUtils.showException(e, textView);
 }
Example #23
0
 protected void onException(RuntimeException e) {
   ExceptionUtils.showException(e, textView, dianeSampleAwareSearcher);
 }
 /**
  * Rethrow the supplied {@link Throwable exception} if it is <em>blacklisted</em>.
  *
  * <p>If the supplied {@code exception} is not <em>blacklisted</em>, this method does nothing.
  */
 public static void rethrowIfBlacklisted(Throwable exception) {
   if (blacklist.stream().anyMatch(exceptionType -> exceptionType.isInstance(exception))) {
     ExceptionUtils.throwAsUncheckedException(exception);
   }
 }