Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.annotation.Nonnull;
import java.nio.file.Paths;

import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_URI_DELIMITER;

/**
Expand Down Expand Up @@ -131,4 +132,34 @@ public static String getFileName(@Nonnull String keyName) {
// failed to converts a path key
return keyName;
}

/**
* Verifies whether the childKey is an immediate path under the given
* parentKey.
*
* @param parentKey parent key name
* @param childKey child key name
* @return true if childKey is an immediate path under the given parentKey
*/
public static boolean isImmediateChild(String parentKey, String childKey) {

// Empty childKey has no parent, so just returning false.
if (org.apache.commons.lang3.StringUtils.isBlank(childKey)) {
return false;
}
java.nio.file.Path parentPath = Paths.get(parentKey);
java.nio.file.Path childPath = Paths.get(childKey);

java.nio.file.Path childParent = childPath.getParent();
// Following are the valid parentKey formats:
// parentKey="" or parentKey="/" or parentKey="/a" or parentKey="a"
// Following are the valid childKey formats:
// childKey="/" or childKey="/a/b" or childKey="a/b"
if (org.apache.commons.lang3.StringUtils.isBlank(parentKey)) {
return childParent == null ||
OM_KEY_PREFIX.equals(childParent.toString());
}

return parentPath.equals(childParent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import static org.apache.hadoop.fs.ozone.Constants.OZONE_DEFAULT_USER;

import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Assert;

Expand Down Expand Up @@ -120,7 +122,8 @@ public static Collection<Object[]> data() {

private OMMetrics omMetrics;

private boolean enableFileSystemPaths;
@SuppressWarnings("checkstyle:VisibilityModifier")
protected boolean enableFileSystemPaths;

public TestOzoneFileInterfaces(boolean setDefaultFs,
boolean useAbsolutePath, boolean enabledFileSystemPaths) {
Expand All @@ -135,9 +138,8 @@ public void init() throws Exception {
volumeName = RandomStringUtils.randomAlphabetic(10).toLowerCase();
bucketName = RandomStringUtils.randomAlphabetic(10).toLowerCase();

OzoneConfiguration conf = new OzoneConfiguration();
conf.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
enableFileSystemPaths);
OzoneConfiguration conf = getOzoneConfiguration();

cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(3)
.build();
Expand All @@ -162,6 +164,14 @@ public void init() throws Exception {
omMetrics = cluster.getOzoneManager().getMetrics();
}

@NotNull
protected OzoneConfiguration getOzoneConfiguration() {
OzoneConfiguration conf = new OzoneConfiguration();
conf.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
enableFileSystemPaths);
return conf;
}

@After
public void teardown() throws IOException {
if (cluster != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.fs.ozone;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.jetbrains.annotations.NotNull;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

/**
* Test OzoneFileSystem Interfaces layout version V1.
*
* This test will test the various interfaces i.e.
* create, read, write, getFileStatus
*/
@RunWith(Parameterized.class)
public class TestOzoneFileInterfacesV1 extends TestOzoneFileInterfaces {

public TestOzoneFileInterfacesV1(boolean setDefaultFs,
boolean useAbsolutePath, boolean enabledFileSystemPaths) {
super(setDefaultFs, useAbsolutePath, enabledFileSystemPaths);
}

@NotNull
@Override
protected OzoneConfiguration getOzoneConfiguration() {
OzoneConfiguration conf = new OzoneConfiguration();
conf.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
enableFileSystemPaths);
conf.set(OMConfigKeys.OZONE_OM_LAYOUT_VERSION, "V1");
return conf;
}

@Override
@Test
@Ignore("TODO:HDDS-2939")
public void testDirectory() {

}

@Override
@Test
@Ignore("TODO:HDDS-2939")
public void testOzFsReadWrite() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import static org.junit.Assert.fail;

import org.apache.hadoop.test.LambdaTestUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.junit.Assert;
import org.junit.Rule;
Expand Down Expand Up @@ -100,17 +101,26 @@ public TestOzoneFileSystem(boolean setDefaultFs) {
private static final Logger LOG =
LoggerFactory.getLogger(TestOzoneFileSystem.class);

private boolean enabledFileSystemPaths;

private MiniOzoneCluster cluster;
private FileSystem fs;
private OzoneFileSystem o3fs;
private String volumeName;
private String bucketName;
private int rootItemCount;
private Trash trash;
@SuppressWarnings("checkstyle:VisibilityModifier")
protected boolean enabledFileSystemPaths;

@SuppressWarnings("checkstyle:VisibilityModifier")
protected MiniOzoneCluster cluster;
@SuppressWarnings("checkstyle:VisibilityModifier")
protected FileSystem fs;
@SuppressWarnings("checkstyle:VisibilityModifier")
protected OzoneFileSystem o3fs;
@SuppressWarnings("checkstyle:VisibilityModifier")
protected String volumeName;
@SuppressWarnings("checkstyle:VisibilityModifier")
protected String bucketName;
@SuppressWarnings("checkstyle:VisibilityModifier")
protected int rootItemCount;
@SuppressWarnings("checkstyle:VisibilityModifier")
protected Trash trash;

public void testCreateFileShouldCheckExistenceOfDirWithSameName()

throws Exception {
/*
* Op 1. create file -> /d1/d2/d3/d4/key2
Expand Down Expand Up @@ -156,6 +166,28 @@ public void testCreateFileShouldCheckExistenceOfDirWithSameName()
// ignore as its expected
}

// Directory
FileStatus fileStatus = fs.getFileStatus(parent);
assertEquals("FileStatus did not return the directory",
"/d1/d2/d3/d4", fileStatus.getPath().toUri().getPath());
assertTrue("FileStatus did not return the directory",
fileStatus.isDirectory());

// invalid sub directory
try{
fs.getFileStatus(new Path("/d1/d2/d3/d4/key3/invalid"));
fail("Should throw FileNotFoundException");
} catch (FileNotFoundException fnfe) {
// ignore as its expected
}
// invalid file name
try{
fs.getFileStatus(new Path("/d1/d2/d3/d4/invalidkey"));
fail("Should throw FileNotFoundException");
} catch (FileNotFoundException fnfe) {
// ignore as its expected
}

// Cleanup
fs.delete(new Path("/d1/"), true);
}
Expand Down Expand Up @@ -249,12 +281,9 @@ public void tearDown() {
}
}

private void setupOzoneFileSystem()
protected void setupOzoneFileSystem()
throws IOException, TimeoutException, InterruptedException {
OzoneConfiguration conf = new OzoneConfiguration();
conf.setInt(FS_TRASH_INTERVAL_KEY, 1);
conf.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
enabledFileSystemPaths);
OzoneConfiguration conf = getOzoneConfig();
cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(3)
.build();
Expand All @@ -276,7 +305,16 @@ private void setupOzoneFileSystem()
trash = new Trash(conf);
}

private void testOzoneFsServiceLoader() throws IOException {
@NotNull
protected OzoneConfiguration getOzoneConfig() {
OzoneConfiguration conf = new OzoneConfiguration();
conf.setInt(FS_TRASH_INTERVAL_KEY, 1);
conf.setBoolean(OMConfigKeys.OZONE_OM_ENABLE_FILESYSTEM_PATHS,
enabledFileSystemPaths);
return conf;
}

protected void testOzoneFsServiceLoader() throws IOException {
assertEquals(
FileSystem.getFileSystemClass(OzoneConsts.OZONE_URI_SCHEME, null),
OzoneFileSystem.class);
Expand Down Expand Up @@ -441,7 +479,7 @@ private void testFileDelete() throws Exception {

}

private void testListStatus() throws Exception {
protected void testListStatus() throws Exception {
Path parent = new Path("/testListStatus");
Path file1 = new Path(parent, "key1");
Path file2 = new Path(parent, "key2");
Expand Down Expand Up @@ -489,7 +527,7 @@ public void testListStatusWithIntermediateDir() throws Exception {
/**
* Tests listStatus operation on root directory.
*/
private void testListStatusOnRoot() throws Exception {
protected void testListStatusOnRoot() throws Exception {
Path root = new Path("/");
Path dir1 = new Path(root, "dir1");
Path dir12 = new Path(dir1, "dir12");
Expand All @@ -516,7 +554,7 @@ private void testListStatusOnRoot() throws Exception {
/**
* Tests listStatus operation on root directory.
*/
private void testListStatusOnLargeDirectory() throws Exception {
protected void testListStatusOnLargeDirectory() throws Exception {
Path root = new Path("/");
Set<String> paths = new TreeSet<>();
int numDirs = 5111;
Expand All @@ -540,7 +578,7 @@ private void testListStatusOnLargeDirectory() throws Exception {
/**
* Tests listStatus on a path with subdirs.
*/
private void testListStatusOnSubDirs() throws Exception {
protected void testListStatusOnSubDirs() throws Exception {
// Create the following key structure
// /dir1/dir11/dir111
// /dir1/dir12
Expand Down Expand Up @@ -653,7 +691,7 @@ private void assertKeyNotFoundException(IOException ex) {
GenericTestUtils.assertExceptionContains("KEY_NOT_FOUND", ex);
}

private void testGetDirectoryModificationTime()
protected void testGetDirectoryModificationTime()
throws IOException, InterruptedException {
Path mdir1 = new Path("/mdir1");
Path mdir11 = new Path(mdir1, "mdir11");
Expand Down
Loading