@Inject public DistributedFlowOperations(LocationFactory locationFactory, TwillRunnerService runnerService, DeployClient deployClient, QueueAdmin queueAdmin) throws IOException { this.location = locationFactory.create(Constants.Location.FLOWJAR); location.mkdirs(); this.runnerService = runnerService; this.deployClient = deployClient; this.jarUnpackDir = Files.createTempDir(); this.queueAdmin = queueAdmin; }
@WriteOnly private boolean mkdirs(Location location, String permissions) throws IOException { return location.mkdirs(permissions); }
@WriteOnly private boolean mkdirs(Location location) throws IOException { return location.mkdirs(); }
@WriteOnly private boolean mkdirs(Location location, String permissions) throws IOException { return location.mkdirs(permissions); }
@WriteOnly private boolean mkdirs(Location location) throws IOException { return location.mkdirs(); }
/** * Create the directory represented by the location if not exists. * * @param location the location for the directory. * @throws IOException If the location cannot be created */ public static void mkdirsIfNotExists(Location location) throws IOException { // Need to check && mkdir && check to deal with race condition if (!location.isDirectory() && !location.mkdirs() && !location.isDirectory()) { throw new IOException("Failed to create directory at " + location); } }
@Override public ContentWriter create(Map<String, String> headers) throws IOException { Map<String, String> allHeaders = Maps.newHashMap(this.headers); allHeaders.putAll(headers); Location uploadDir = streamTmpLocation.append("upload").getTempFile(Long.toString(System.currentTimeMillis())); uploadDir.mkdirs(); return new FileContentWriter(streamConfig, streamWriter, uploadDir, allHeaders); } }
/** * Create the directory represented by the location with provided permissions if not exists. * @param location the location for the directory. * @param permissions permissions on directory * @throws IOException If the location cannot be created */ private static void mkdirsIfNotExists(Location location, String permissions) throws IOException { // Need to check && mkdir && check to deal with race condition if (!location.isDirectory() && !location.mkdirs(permissions) && !location.isDirectory()) { throw new IOException("Failed to create directory at " + location); } } }
/** * Create the directory represented by the location if not exists. * * @param location the location for the directory. * @throws IOException If the location cannot be created */ public static void mkdirsIfNotExists(Location location) throws IOException { // Need to check && mkdir && check to deal with race condition if (!location.isDirectory() && !location.mkdirs() && !location.isDirectory()) { throw new IOException("Failed to create directory at " + location); } }
/** * Create the directory represented by the location with provided permissions if not exists. * @param location the location for the directory. * @param permissions permissions on directory * @throws IOException If the location cannot be created */ private static void mkdirsIfNotExists(Location location, String permissions) throws IOException { // Need to check && mkdir && check to deal with race condition if (!location.isDirectory() && !location.mkdirs(permissions) && !location.isDirectory()) { throw new IOException("Failed to create directory at " + location); } } }
private boolean ensureDirExists(Location location) throws IOException { return location.isDirectory() || location.mkdirs() || location.isDirectory(); }
/** * Create the directory represented by the location if not exists. * * @param location the location for the directory. * @throws java.io.IOException If the location cannot be created */ public static void mkdirsIfNotExists(Location location) throws IOException { // Need to check && mkdir && check to deal with race condition if (!location.isDirectory() && !location.mkdirs() && !location.isDirectory()) { throw new IOException("Failed to create directory at " + location.toURI()); } }
@Override protected DatasetFramework getFramework() throws DatasetManagementException { InMemoryDatasetFramework framework = new InMemoryDatasetFramework(registryFactory, DEFAULT_MODULES); framework.setAuditPublisher(inMemoryAuditPublisher); try { namespacePathLocator.get(NAMESPACE_ID).mkdirs(); } catch (IOException e) { throw new DatasetManagementException(e.getMessage()); } return framework; } }
/** * Creates a temporary directory through the {@link LocationFactory} provided to this class. */ private Location createTempLocationDirectory() throws IOException { ProgramId programId = context.getProgram().getId(); String tempLocationName = String.format("%s/%s.%s.%s.%s.%s", cConf.get(Constants.AppFabric.TEMP_DIR), programId.getType().name().toLowerCase(), programId.getNamespace(), programId.getApplication(), programId.getProgram(), context.getRunId().getId()); Location location = locationFactory.get(programId.getNamespaceId()).append(tempLocationName); location.mkdirs(); return location; }
/** * Creates a temporary directory through the {@link LocationFactory} provided to this class. */ private Location createTempLocationDirectory() throws IOException { ProgramId programId = context.getProgram().getId(); String tempLocationName = String.format("%s/%s.%s.%s.%s.%s", cConf.get(Constants.AppFabric.TEMP_DIR), programId.getType().name().toLowerCase(), programId.getNamespace(), programId.getApplication(), programId.getProgram(), context.getRunId().getId()); Location location = locationFactory.get(programId.getNamespaceId()).append(tempLocationName); location.mkdirs(); return location; }
private void createNamespace(NamespaceId namespaceId) throws Exception { // since the namespace admin here is an in memory one we need to create the location explicitly namespacePathLocator.get(namespaceId).mkdirs(); // the framework.delete looks up namespace config through namespaceadmin add the meta there too. namespaceAdmin.create(new NamespaceMeta.Builder().setName(namespaceId).build()); }
@Test public void testRollback() throws IOException, TransactionFailureException, DatasetManagementException { // test deletion of an empty output directory FileSet fileSet1 = createFileset(testFileSetInstance1); Location outputLocation = fileSet1.getOutputLocation(); Assert.assertFalse(outputLocation.exists()); Assert.assertTrue(outputLocation.mkdirs()); Assert.assertTrue(outputLocation.exists()); ((FileSetDataset) fileSet1).onFailure(); Assert.assertFalse(outputLocation.exists()); }
@Test public void testDelete() throws IOException { LocationFactory factory = locationFactoryCache.getUnchecked("delete"); Location base = factory.create("test").getTempFile(".tmp"); Assert.assertTrue(base.mkdirs()); Assert.assertTrue(base.append("test1").getTempFile(".tmp").createNew()); Assert.assertTrue(base.append("test2").getTempFile(".tmp").createNew()); Location subDir = base.append("test3"); Assert.assertTrue(subDir.mkdirs()); Assert.assertTrue(subDir.append("test4").getTempFile(".tmp").createNew()); Assert.assertTrue(subDir.append("test5").getTempFile(".tmp").createNew()); Assert.assertTrue(base.delete(true)); Assert.assertFalse(base.exists()); }