Changeset 5171


Ignore:
Timestamp:
Oct 29, 2009, 2:19:35 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1422: More user-configurable job parameters for Base1PluginExecuter

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java

    r5170 r5171  
    448448      else if (command.equals(Request.COMMAND_CONFIGURE_JOB))
    449449      {
    450         storeValue(job, request, getSourceBioAssaySetParameter(null, null));
     450        RequestInformation ri = getConfigureJobParameters();
     451        List<Throwable> errors = validateRequestParameters(ri.getParameters(), request);
     452        if (errors != null)
     453        {
     454          response.setError(errors.size() + " invalid parameter(s) were found in the request", errors);
     455          return;
     456        }
     457       
     458        storeValue(job, request, ri.getParameter(SOURCE_BIOASSAYSET));
     459        storeValue(job, request, ri.getParameter("pluginDirectory"));
     460        storeValue(job, request, ri.getParameter(CHILD_NAME));
     461        storeValue(job, request, ri.getParameter(CHILD_DESCRIPTION));
     462        storeValue(job, request, ri.getParameter("leaveStdin"));
     463        storeValue(job, request, ri.getParameter("leaveStdout"));
    451464        for (PluginParameter<?> p : getJobParameters())
    452465        {
    453466          storeValue(job, request, p);
    454467        }
    455         List<Throwable> errors = validateRequestParameters(getJobParameters(), request);
    456         if (errors == null)
    457           response.setDone("Job configuration complete", Job.ExecutionTime.SHORT);
    458         else
    459           response.setError(errors.size() + " invalid parameter(s) were found in the request", errors);
     468        response.setDone("Job configuration complete", Job.ExecutionTime.SHORT);
    460469      }
    461470      else
     
    576585      Transformation trans = null;
    577586      Directory workingDirectory = null;
    578       boolean leaveStdin = Boolean.TRUE.equals(configuration.getValue("leaveStdin"));
    579       boolean leaveStdout = Boolean.TRUE.equals(configuration.getValue("leaveStdout"));
     587      boolean leaveStdin = Boolean.TRUE.equals(job.getValue("leaveStdin"));
     588      boolean leaveStdout = Boolean.TRUE.equals(job.getValue("leaveStdout"));
     589      String childName = (String)job.getValue(CHILD_NAME);
     590      String childDescription = (String)job.getValue(CHILD_DESCRIPTION);
    580591      IntensityTransform resultTransform = null;
    581592      if (configuration.getValue("resultTransform") != null)
     
    705716          associateFiles(dc, trans, workingDirectory);
    706717          if (chainedProgress != null) chainedProgress.setRange(65, 95);
    707           importData(dc, stdout, trans, resultTransform, chainedProgress);
     718          BioAssaySet child = importData(dc, stdout, trans, resultTransform, chainedProgress);
     719          if (child != null)
     720          {
     721            child.setName(childName);
     722            child.setDescription(childDescription);
     723          }
    708724          dc.commit();
    709725        }
     
    10971113        "Leave stdin.txt",
    10981114        "If the file stdin.txt should be removed after the plug-in execution or not",
    1099         new BooleanParameterType(false, true));
     1115        new BooleanParameterType(null, false));
    11001116      parameters.add(leaveStdinParameter);
    11011117     
     
    11041120        "Leave stdout.txt",
    11051121        "If the file stdout.txt should be removed after the plug-in execution or not",
    1106         new BooleanParameterType(false, true));
     1122        new BooleanParameterType(null, false));
    11071123      parameters.add(leaveStdoutParameter);
    11081124     
     
    11481164      List<PluginParameter<?>> parameters = new ArrayList<PluginParameter<?>>();
    11491165      parameters.add(getSourceBioAssaySetParameter("Bioassay set", "The bioassay set that this plugin will run on"));
     1166     
     1167      DbControl dc = null;
     1168      try
     1169      {
     1170        dc = sc.newDbControl();
     1171        Experiment experiment = getCurrentExperiment(dc);
     1172        BioAssaySet bas = getCurrentBioAssaySet(dc);
     1173        String homeDirectoryPath = "/" + Path.makeSafeFilename(PluginConfiguration.getById(dc, configuration.getId()).getName(), "");
     1174        Directory homeDirectory = experiment == null ? null : experiment.getDirectory();
     1175        if (homeDirectory != null)
     1176        {
     1177          homeDirectoryPath = homeDirectory.getPath() + homeDirectoryPath;
     1178        }
     1179        else
     1180        {
     1181          homeDirectory = User.getById(dc, sc.getLoggedInUserId()).getHomeDirectory();
     1182          if (homeDirectory != null)
     1183          {
     1184            homeDirectoryPath = homeDirectory.getPath() + homeDirectoryPath;
     1185          }
     1186        }
     1187        pluginDirectoryParameter = new PluginParameter<String>(
     1188          "pluginDirectory",
     1189          "Output directory",
     1190          "The directory where a plugin can store its files.",
     1191          new PathParameterType(Path.Type.DIRECTORY, homeDirectoryPath, true));
     1192        parameters.add(pluginDirectoryParameter);
     1193       
     1194        parameters.add(getChildNameParameter(null, null, bas == null ? null : bas.getName()));
     1195        parameters.add(getChildDescriptionParameter(null, null, null));
     1196       
     1197        Boolean leaveStdin = (Boolean)configuration.getValue("leaveStdin");
     1198        leaveStdinParameter = new PluginParameter<Boolean>(
     1199            "leaveStdin",
     1200            "Leave stdin.txt",
     1201            "If the file stdin.txt should be removed after the plug-in execution or not",
     1202            new BooleanParameterType(leaveStdin, false));
     1203        parameters.add(leaveStdinParameter);
     1204         
     1205        Boolean leaveStdout = (Boolean)configuration.getValue("leaveStdout");
     1206        leaveStdoutParameter = new PluginParameter<Boolean>(
     1207            "leaveStdout",
     1208            "Leave stdout.txt",
     1209            "If the file stdout.txt should be removed after the plug-in execution or not",
     1210            new BooleanParameterType(leaveStdout, false));
     1211        parameters.add(leaveStdoutParameter);
     1212
     1213        parameters.add(new PluginParameter<String>("pluginsettings", "Plug-in parameters", null, null));
     1214      }
     1215      finally
     1216      {
     1217        if (dc != null) dc.close();
     1218      }
    11501219     
    11511220      parameters.addAll(getJobParameters());
     
    12761345      return jobParameters;
    12771346    }
    1278     jobParameters = new ArrayList<PluginParameter<?>>();
    1279        
    1280     DbControl dc = null;
    1281     try
    1282     {
    1283       dc = sc.newDbControl();
    1284       Experiment experiment = getCurrentExperiment(dc);
    1285       String homeDirectoryPath = "/" + Path.makeSafeFilename(PluginConfiguration.getById(dc, configuration.getId()).getName(), "");
    1286       Directory homeDirectory = experiment == null ? null : experiment.getDirectory();
    1287       if (homeDirectory != null)
    1288       {
    1289         homeDirectoryPath = homeDirectory.getPath() + homeDirectoryPath;
    1290       }
    1291       else
    1292       {
    1293         homeDirectory = User.getById(dc, sc.getLoggedInUserId()).getHomeDirectory();
    1294         if (homeDirectory != null)
    1295         {
    1296           homeDirectoryPath = homeDirectory.getPath() + homeDirectoryPath;
    1297         }
    1298       }
    1299       pluginDirectoryParameter = new PluginParameter<String>(
    1300         "pluginDirectory",
    1301         "Plugin directory",
    1302         "The directory where a plugin can store its files.",
    1303         new PathParameterType(Path.Type.DIRECTORY, homeDirectoryPath, true));
    1304       jobParameters.add(pluginDirectoryParameter);
    1305      
    1306       Object xml = configuration.getValue(jobParametersParameter.getName());
    1307       // To make the plugin compatible with older configurations
    1308       if (xml == null)
    1309       {
    1310         throw new BaseException("Cant find the jobparameters specification. Reconfigure the plugin.");
    1311       }
    1312       jobParameters.addAll(getJobParametersFromXML(xml.toString(), true));
    1313     }
    1314     finally
    1315     {
    1316       if (dc != null) dc.close();
    1317     }
    1318 
     1347
     1348    Object xml = configuration.getValue(jobParametersParameter.getName());
     1349    // To make the plugin compatible with older configurations
     1350    if (xml == null)
     1351    {
     1352      throw new BaseException("Cant find the jobparameters specification. Reconfigure the plugin.");
     1353    }
     1354    jobParameters = getJobParametersFromXML(xml.toString(), true);
    13191355    return jobParameters;
    13201356  }
     
    13461382    @throws IOException if there is any error reading from stdout.txt
    13471383  */
    1348   private void importData(DbControl dc, File stdout, Transformation t,
     1384  private BioAssaySet importData(DbControl dc, File stdout, Transformation t,
    13491385      IntensityTransform resultTransform, ProgressReporter progress)
    13501386    throws SQLException, IOException
     
    13561392    importer.setIntensityTransform(resultTransform);
    13571393    importer.setProgressReporter(progress);
    1358     importer.doImport();
     1394    return importer.doImport();
    13591395  }
    13601396 
  • trunk/src/test/TestBase1PluginExecuter.java

    r4930 r5171  
    9595   
    9696    // Copy input to output - serial format
    97     int jobId = test_create_job(pluginConfigurationId, experimentId, rootBioAssaySetId, directoryId);
     97    int jobId = test_create_job(pluginConfigurationId, experimentId, rootBioAssaySetId,
     98        directoryId, "Clone serial (keep std*.txt)");
    9899    ok &= TestJob.test_execute(jobId);
    99100   
    100101    // Copy input to output - remove stdin and stdout
    101     int jobIdCleanStd = test_create_job(pluginConfigurationIdCleanStd, experimentId, rootBioAssaySetId, directoryId);
     102    int jobIdCleanStd = test_create_job(pluginConfigurationIdCleanStd, experimentId,
     103        rootBioAssaySetId, directoryId, "Clone serial (remove std*.txt)");
    102104    ok &= TestJob.test_execute(jobIdCleanStd);
    103105   
    104106    // Copy input to output - matrix format
    105     int jobIdMatrix = test_create_job(pluginConfigurationIdMatrix, experimentId, rootBioAssaySetId, directoryId);
     107    int jobIdMatrix = test_create_job(pluginConfigurationIdMatrix, experimentId,
     108        rootBioAssaySetId, directoryId, "Clone matrix (keep std*.txt)");
    106109    ok &= TestJob.test_execute(jobIdMatrix);
    107110   
    108111    // Copy input to output - matrix format - filtered bioassayset
    109     int jobIdMatrix2 = test_create_job(pluginConfigurationIdMatrix, experimentId, filteredBioAssaySetId, directoryId);
     112    int jobIdMatrix2 = test_create_job(pluginConfigurationIdMatrix, experimentId,
     113        filteredBioAssaySetId, directoryId, "Clone filtered matrix (keep std*.txt)");
    110114    ok &= TestJob.test_execute(jobIdMatrix2);
    111115   
    112116    // One-to-one mapping on assays and reporters
    113     int jobId2 = test_create_job(pluginConfigurationIdMatrix, experimentId, rootBioAssaySetId, directoryId);
     117    int jobId2 = test_create_job(pluginConfigurationIdMatrix, experimentId,
     118      rootBioAssaySetId, directoryId, "Clone matrix");
    114119    ok &= TestJob.test_execute(jobId2);
    115120
    116121    // Merge assays +  create subdir
    117     int jobId3 = test_create_job(pluginConfigurationId2, experimentId, rootBioAssaySetId, directoryId,
    118         new Parameter("mergeAssays", "1"), new Parameter("createSubdir", "1"));
     122    int jobId3 = test_create_job(pluginConfigurationId2, experimentId,
     123        rootBioAssaySetId, directoryId, "Merge assays + create sudir",
     124        new Parameter("mergeAssays", "1"),
     125        new Parameter("createSubdir", "1"));
    119126    ok &= TestJob.test_execute(jobId3);
    120127
    121128    // Offset positions
    122     int jobId4 = test_create_job(pluginConfigurationId2, experimentId, rootBioAssaySetId, directoryId,
     129    int jobId4 = test_create_job(pluginConfigurationId2, experimentId,
     130        rootBioAssaySetId, directoryId, "Offset positions",
    123131        new Parameter("offsetPositions", "1"));
    124132    ok &= TestJob.test_execute(jobId4);
    125133
    126134    // Offset positions and merge assays
    127     int jobId5 = test_create_job(pluginConfigurationId2, experimentId, rootBioAssaySetId, directoryId,
    128         new Parameter("mergeAssays", "1"), new Parameter("offsetPositions", "1"));
     135    int jobId5 = test_create_job(pluginConfigurationId2, experimentId,
     136        rootBioAssaySetId, directoryId, "Offset position + merge assays",
     137        new Parameter("mergeAssays", "1"),
     138        new Parameter("offsetPositions", "1"));
    129139    ok &= TestJob.test_execute(jobId5);
    130140
    131141    // Create reporter list
    132     int jobId6 = test_create_job(pluginConfigurationId2, experimentId, rootBioAssaySetId, directoryId,
     142    int jobId6 = test_create_job(pluginConfigurationId2, experimentId,
     143        rootBioAssaySetId, directoryId, "Create reporter list",
    133144        new Parameter("reporterList", "1"));
    134145    ok &= TestJob.test_execute(jobId6);
     
    210221  }
    211222 
    212   static int test_create_job(int pluginConfigurationId, int experimentId, int bioAssaySetId, int directoryId, Parameter... parameters)
     223  static int test_create_job(int pluginConfigurationId, int experimentId, int bioAssaySetId,
     224      int directoryId, String childName, Parameter... parameters)
    213225  {
    214226    if (pluginConfigurationId == 0 || !TestUtil.hasPermission(Permission.CREATE, Item.JOB)) return 0;
     
    231243      for (PluginParameter<?> p : request.getRequestInformation().getParameters())
    232244      {
    233         request.setParameterValue(p.getName(), p.getParameterType().getDefaultValue());
     245        if (p.getParameterType() != null)
     246        {
     247          request.setParameterValue(p.getName(), p.getParameterType().getDefaultValue());
     248        }
    234249      }
    235250     
     
    245260      request.setParameterValue("source", bioAssaySet);
    246261      request.setParameterValue("pluginDirectory", Directory.getById(dc, directoryId).getPath().toString());
    247 
     262      request.setParameterValue("childName", childName);
    248263      write_request_information(request.getRequestInformation());
    249264     
Note: See TracChangeset for help on using the changeset viewer.