Package org.ngrinder.script.model

Examples of org.ngrinder.script.model.FileEntry$FileEntrySerializer


  public String getQuickStart(User user,
                              @RequestParam(value = "url", required = true) String urlString,
                              @RequestParam(value = "scriptType", required = true) String scriptType,
                              ModelMap model) {
    URL url = checkValidURL(urlString);
    FileEntry newEntry = fileEntryService.prepareNewEntryForQuickTest(user, urlString,
        scriptHandlerFactory.getHandler(scriptType));
    model.addAttribute(PARAM_QUICK_SCRIPT, newEntry.getPath());
    model.addAttribute(PARAM_QUICK_SCRIPT_REVISION, newEntry.getRevision());
    model.addAttribute(PARAM_TEST, createPerfTestFromQuickStart(user, "Test for " + url.getHost(), url.getHost()));
    Map<String, MutableInt> agentCountMap = agentManagerService.getAvailableAgentCountMap(user);
    model.addAttribute(PARAM_REGION_AGENT_COUNT_MAP, agentCountMap);
    model.addAttribute(PARAM_REGION_LIST, getRegions(agentCountMap));
    addDefaultAttributeOnModel(model);
View Full Code Here


  public HttpEntity<String> getResources(User user, @RequestParam String scriptPath,
                                         @RequestParam(required = false) String ownerId) {
    if (user.getRole() == Role.ADMIN && StringUtils.isNotBlank(ownerId)) {
      user = userService.getOne(ownerId);
    }
    FileEntry fileEntry = fileEntryService.getOne(user, scriptPath);
    String targetHosts = "";
    List<String> fileStringList = newArrayList();
    if (fileEntry != null) {
      List<FileEntry> fileList = fileEntryService.getScriptHandler(fileEntry).getLibAndResourceEntries(user, fileEntry, -1L);
      for (FileEntry each : fileList) {
        fileStringList.add(each.getPath());
      }
      targetHosts = filterHostString(fileEntry.getProperties().get("targetHosts"));
    }

    return toJsonHttpEntity(buildMap("targetHosts", trimToEmpty(targetHosts), "resources", fileStringList));
  }
View Full Code Here

  }


  private void attachFileRevision(User user, PerfTest perfTest) {
    if (perfTest.getStatus() == Status.READY) {
      FileEntry scriptEntry = fileEntryService.getOne(user, perfTest.getScriptName());
      long revision = scriptEntry != null ? scriptEntry.getRevision() : -1;
      perfTest.setScriptRevision(revision);
    }
  }
View Full Code Here

      User user = perfTest.getCreatedUser();

      // Get all files in the script path
      String scriptName = perfTest.getScriptName();
      FileEntry userDefinedGrinderProperties = fileEntryService.getOne(user,
          FilenameUtils.concat(FilenameUtils.getPath(scriptName), DEFAULT_GRINDER_PROPERTIES), -1L);
      if (!config.isSecurityEnabled() && userDefinedGrinderProperties != null) {
        // Make the property overridden by user property.
        GrinderProperties userProperties = new GrinderProperties();
        userProperties.load(new StringReader(userDefinedGrinderProperties.getContent()));
        grinderProperties.putAll(userProperties);
      }
      grinderProperties.setAssociatedFile(new File(DEFAULT_GRINDER_PROPERTIES));
      grinderProperties.setProperty(GRINDER_PROP_SCRIPT, scriptHandler.getScriptExecutePath(scriptName));
View Full Code Here

   * @return File location in which the perftest script and resources are distributed.
   */
  public ScriptHandler prepareDistribution(PerfTest perfTest) {
    File perfTestDistDirectory = getDistributionPath(perfTest);
    User user = perfTest.getCreatedUser();
    FileEntry scriptEntry = checkNotNull(
        fileEntryService.getOne(user,
            checkNotEmpty(perfTest.getScriptName(), "perfTest should have script name"),
            getSafe(perfTest.getScriptRevision())), "script should exist");
    // Get all files in the script path
    ScriptHandler handler = scriptHandlerFactory.getHandler(scriptEntry);
View Full Code Here

      svnClientManager.getLogClient().doList(SVNURL.fromFile(getUserRepoDirectory(user)).appendPath(path, true),
          svnRevision, svnRevision, true, recursive, new ISVNDirEntryHandler() {
        @Override
        public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {

          FileEntry script = new FileEntry();
          // Exclude base path "/"
          if (StringUtils.isBlank(dirEntry.getRelativePath())) {
            return;
          }
          script.setPath(FilenameUtils.normalize(path + "/" + dirEntry.getRelativePath(), true));
          script.setCreatedDate(dirEntry.getDate());
          script.setLastModifiedDate(dirEntry.getDate());
          script.setDescription(dirEntry.getCommitMessage());
          script.setRevision(dirEntry.getRevision());
          if (dirEntry.getKind() == SVNNodeKind.DIR) {
            script.setFileType(FileType.DIR);
          } else {
            script.getFileType();
            script.setFileSize(dirEntry.getSize());
          }
          fileEntries.add(script);
        }
      });
    } catch (Exception e) {
View Full Code Here

    try {
      svnClientManager.getLogClient().doList(SVNURL.fromFile(getUserRepoDirectory(user)), SVNRevision.HEAD,
          SVNRevision.HEAD, false, true, new ISVNDirEntryHandler() {
        @Override
        public void handleDirEntry(SVNDirEntry dirEntry) throws SVNException {
          FileEntry script = new FileEntry();
          String relativePath = dirEntry.getRelativePath();
          if (StringUtils.isBlank(relativePath)) {
            return;
          }
          script.setCreatedDate(dirEntry.getDate());
          script.setLastModifiedDate(dirEntry.getDate());
          script.setPath(relativePath);
          script.setDescription(dirEntry.getCommitMessage());
          long reversion = dirEntry.getRevision();
          script.setRevision(reversion);
          script.setFileType(dirEntry.getKind() == SVNNodeKind.DIR ? FileType.DIR : null);
          script.setFileSize(dirEntry.getSize());
          scripts.add(script);
        }
      });
    } catch (Exception e) {
      LOG.error("Error while fetching files from SVN for {}", user.getUserId());
View Full Code Here

   * @param path     path in the svn repo
   * @param revision revision of the file
   * @return found {@link FileEntry}, null if not found
   */
  public FileEntry findOne(User user, String path, SVNRevision revision) {
    final FileEntry script = new FileEntry();
    SVNClientManager svnClientManager = null;
    ByteArrayOutputStream outputStream = null;
    try {
      svnClientManager = getSVNClientManager();

      SVNURL userRepoUrl = SVNURL.fromFile(getUserRepoDirectory(user));
      if (userRepoUrl == null) {
        return null;
      }
      SVNRepository repo = svnClientManager.createRepository(userRepoUrl, true);
      SVNNodeKind nodeKind = repo.checkPath(path, -1);
      if (nodeKind == SVNNodeKind.NONE) {
        return null;
      }
      outputStream = new ByteArrayOutputStream();
      SVNProperties fileProperty = new SVNProperties();
      // Get File.
      repo.getFile(path, revision.getNumber(), fileProperty, outputStream);
      SVNDirEntry lastRevisionedEntry = repo.info(path, -1);
      long lastRevisionNumber = (lastRevisionedEntry == null) ? -1 : lastRevisionedEntry.getRevision();
      String revisionStr = fileProperty.getStringValue(SVNProperty.REVISION);
      long revisionNumber = Long.parseLong(revisionStr);
      SVNDirEntry info = repo.info(path, revisionNumber);
      byte[] byteArray = outputStream.toByteArray();
      script.setPath(path);
      for (String name : fileProperty.nameSet()) {
        script.getProperties().put(name, fileProperty.getStringValue(name));
      }
      script.setFileType(FileType.getFileTypeByExtension(FilenameUtils.getExtension(script.getFileName())));
      if (script.getFileType().isEditable()) {
        String autoDetectedEncoding = EncodingUtils.detectEncoding(byteArray, "UTF-8");
        script.setContent(new String(byteArray, autoDetectedEncoding));
        script.setEncoding(autoDetectedEncoding);
        script.setContentBytes(byteArray);
      } else {
        script.setContentBytes(byteArray);
      }
      script.setDescription(info.getCommitMessage());
      script.setRevision(revisionNumber);
      script.setLastRevision(lastRevisionNumber);
      script.setCreatedUser(user);
    } catch (Exception e) {
      LOG.error("Error while fetching a file from SVN {}", user.getUserId() + "_" + path, e);
      return null;
    } finally {
      closeSVNClientManagerQuietly(svnClientManager);
View Full Code Here

      testUrl = StringUtils.defaultIfBlank(testUrl, "http://please_modify_this.com");
    } else {
      name = UrlUtils.getHost(testUrl);
    }
    ScriptHandler scriptHandler = fileEntryService.getScriptHandler(scriptType);
    FileEntry entry = new FileEntry();
    entry.setPath(fileName);
    if (scriptHandler instanceof ProjectHandler) {
      if (!fileEntryService.hasFileEntry(user, PathUtils.join(path, fileName))) {
        fileEntryService.prepareNewEntry(user, path, fileName, name, testUrl, scriptHandler,
            createLibAndResources);
        redirectAttributes.addFlashAttribute("message", fileName + " project is created.");
View Full Code Here

   * @return script/editor
   */
  @RequestMapping("/detail/**")
  public String getOne(User user, @RemainedPath String path,
                       @RequestParam(value = "r", required = false) Long revision, ModelMap model) {
    FileEntry script = fileEntryService.getOne(user, path, revision);
    if (script == null || !script.getFileType().isEditable()) {
      LOG.error("Error while getting file detail on {}. the file does not exist or not editable", path);
      model.clear();
      return "redirect:/script/";
    }
    model.addAttribute("file", script);
    model.addAttribute("lastRevision", script.getLastRevision());
    model.addAttribute("curRevision", script.getRevision());
    model.addAttribute("scriptHandler", fileEntryService.getScriptHandler(script));
    model.addAttribute("ownerId", user.getUserId());
    model.addAttribute("breadcrumbPath", getScriptPathBreadcrumbs(path));
    return "script/editor";
  }
View Full Code Here

TOP

Related Classes of org.ngrinder.script.model.FileEntry$FileEntrySerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.