private void validatePaths( String path, ResourcePatternResolver resourceLoader, boolean shouldExist) throws IOException { Resource res = resourceLoader.getResource(path); if (shouldExist) { Assert.isTrue(res.exists(), "The input path [" + path + "] does not exist"); } else { Assert.isTrue(!res.exists(), "The output path [" + path + "] already exists"); } }
@CliCommand( value = {PREFIX + "script"}, help = "Executes a Pig script") public String script( @CliOption( key = {"", "location"}, mandatory = true, help = "Script location") String location) { String jobTracker = hadoopConfiguration.get("mapred.job.tracker"); if (jobTracker == null || jobTracker.length() == 0) { return "You must set Job Tracker URL before run Pig script"; } Resource resource = resourceResolver.getResource(fixLocation(location)); if (!resource.exists()) { return "Cannot resolve " + location; } String uri = location; try { uri = resource.getFile().getAbsolutePath(); } catch (IOException ex) { // ignore - we'll use location } try { if (pigTemplate == null) { init(); } List<ExecJob> results = pigTemplate.executeScript(new PigScript(resource)); ExecJob result = results.get(0); Exception exception = result.getException(); StringBuilder sb = new StringBuilder(result.getStatus().name()); if (exception != null) { sb.append(" ;Cause="); sb.append(exception.getMessage()); } return "Script [" + uri + "] executed succesfully. Returned status " + sb.toString(); } catch (Exception ex) { return "Script [" + uri + "] failed - " + ex; } }
public IDataSet loadUnique(DataSetFormatOptions options, String location) throws DataSetException, IOException { Resource resource = RESOURCE_LOADER.getResource(location); return fromResource(resource, options); }