@Override public Location call() throws Exception { return namespacePathLocator.get(namespaceId); } });
private void deleteLocation(NamespaceId namespaceId) throws IOException { // TODO: CDAP-1581: Implement soft delete Location namespaceHome = namespacePathLocator.get(namespaceId); try { if (hasCustomLocation(namespaceQueryAdmin.get(namespaceId))) { LOG.debug("Custom location mapping {} was found while deleting namespace {}. Deleting all data inside it but" + "skipping namespace home directory delete.", namespaceHome, namespaceId); // delete everything inside the namespace home but not the namespace home as its user owned directory Locations.deleteContent(namespaceHome); } else { // a custom location was not provided for this namespace so cdap is responsible for managing the lifecycle of // the location hence delete it. if (namespaceHome.exists() && !namespaceHome.delete(true)) { throw new IOException(String.format("Error while deleting home directory '%s' for namespace '%s'", namespaceHome, namespaceId)); } } } catch (Exception e) { throw new IOException(String.format("Error while deleting home directory %s for namespace %s ", namespaceHome, namespaceId), e); } }
private void deleteNamespace(NamespaceId namespaceId) throws Exception { // since the namespace admin here is an in memory one we need to delete the location explicitly namespacePathLocator.get(namespaceId).delete(true); namespaceAdmin.delete(namespaceId); }
private Location validateCustomLocation(NamespaceMeta namespaceMeta) throws IOException { Location customNamespacedLocation = namespacePathLocator.get(namespaceMeta); if (!customNamespacedLocation.exists()) { throw new IOException(String.format(
private Location copyFile(Id.Artifact artifactId, File artifactContent) throws IOException { Location fileDirectory = namespacePathLocator.get(artifactId.getNamespace().toEntityId()) .append(ARTIFACTS_PATH).append(artifactId.getName()); Location destination = fileDirectory.append(artifactId.getVersion().getVersion()).getTempFile(".jar"); Locations.mkdirsIfNotExists(fileDirectory); // write the file contents try (OutputStream destinationStream = destination.getOutputStream()) { Files.copy(artifactContent.toPath(), destinationStream); } return destination; }
@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; } }
return namespacePathLocator.get(namespaceId).append(dataDir).append(basePath);
/** * 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; }
@Before public void before() throws Exception { store.clear(); NamespacePathLocator namespacePathLocator = AppFabricTestHelper.getInjector().getInstance(NamespacePathLocator.class); namespacePathLocator.get(NamespaceId.DEFAULT).delete(true); NamespaceAdmin admin = AppFabricTestHelper.getInjector().getInstance(NamespaceAdmin.class); admin.create(NamespaceMeta.DEFAULT); }
@BeforeClass public static void setupPermissions() throws IOException { group = UserGroupInformation.getCurrentUser().getPrimaryGroupName(); tablePermissions = ImmutableMap.of("@" + group, "RWX"); // determine the default permissions of created directories (we want to test with different perms) Location loc = dsFrameworkUtil.getInjector().getInstance(NamespacePathLocator.class) .get(DatasetFrameworkTestUtil.NAMESPACE2_ID); loc.mkdirs(); loc = loc.append("permcheckfile"); loc.createNew(); String defaultPermissions = loc.getPermissions(); fsPermissions = "rwxrwx--x"; if (fsPermissions.equals(defaultPermissions)) { // swap the permissions so we can test with different file set permissions than the default fsPermissions = "rwx--x--x"; } }
@BeforeClass public static void setup() throws Exception { NamespacePathLocator namespacePathLocator = AppFabricTestHelper.getInjector().getInstance(NamespacePathLocator.class); namespaceHomeLocation = namespacePathLocator.get(DefaultId.NAMESPACE); NamespaceAdmin namespaceAdmin = AppFabricTestHelper.getInjector().getInstance(NamespaceAdmin.class); namespaceAdmin.create(new NamespaceMeta.Builder().setName(DefaultId.NAMESPACE).build()); Locations.mkdirsIfNotExists(namespaceHomeLocation); }
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()); }
void clear(final NamespaceId namespace) throws IOException { final Id.Namespace namespaceId = Id.Namespace.fromEntityId(namespace); namespacePathLocator.get(namespace).append(ARTIFACTS_PATH).delete(true);
new DefaultNamespacePathLocator(cConf, locationFactory, nsAdmin); Location defaultLoc = namespacePathLocator.get(NamespaceId.DEFAULT); Location ns1Loc = namespacePathLocator.get(ns1); Location sub1 = namespacePathLocator.get(ns1).append("sub1"); Location sub2 = namespacePathLocator.get(ns1).append("sub2"); Assert.assertNotEquals(sub1, sub2);
namespaceAdmin.create(new NamespaceMeta.Builder().setName(namespace1).build()); namespaceAdmin.create(new NamespaceMeta.Builder().setName(namespace2).build()); namespacePathLocator.get(namespace1).mkdirs(); namespacePathLocator.get(namespace2).mkdirs(); namespacePathLocator.get(namespace1).delete(true); Assert.assertTrue(framework.hasInstance(table2ID));
@Test public void test() throws Exception { NamespaceId myspace = new NamespaceId("myspace"); NamespaceMeta myspaceMeta = new NamespaceMeta.Builder().setName(myspace.getNamespace()).build(); // the create/delete will look up meta so store that too namespaceStore.create(myspaceMeta); storageProviderNamespaceAdmin.create(myspaceMeta); Location namespaceLocation = namespacePathLocator.get(myspace); Assert.assertTrue(namespaceLocation.exists()); storageProviderNamespaceAdmin.delete(myspace); Assert.assertFalse(namespaceLocation.exists()); }
Location nsLocation = namespacePathLocator.get(new NamespaceId(NAME)); Assert.assertTrue(nsLocation.exists());
.build(); Location nsLocation = namespacePathLocator.get(meta); nsLocation.mkdirs(); namespaceAdmin.create(meta);
Location nsLocation = namespacePathLocator.get(new NamespaceId(NAME)); Assert.assertTrue(nsLocation.exists());