2323import static org .apache .hadoop .ozone .OzoneConsts .OM_KEY_PREFIX ;
2424import static org .apache .hadoop .ozone .OzoneConsts .OZONE_URI_SCHEME ;
2525import static org .apache .hadoop .ozone .om .OmSnapshotManager .getSnapshotPath ;
26- import static org .apache .hadoop .ozone .om .helpers .BucketLayout .FILE_SYSTEM_OPTIMIZED ;
27- import static org .apache .hadoop .ozone .om .helpers .BucketLayout .LEGACY ;
2826import static org .assertj .core .api .Assertions .assertThat ;
2927import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
3028import static org .junit .jupiter .api .Assertions .assertEquals ;
5452import java .util .UUID ;
5553import java .util .concurrent .TimeoutException ;
5654import org .apache .commons .io .IOUtils ;
57- import org .apache .commons .lang3 .RandomStringUtils ;
5855import org .apache .hadoop .fs .CommonConfigurationKeysPublic ;
5956import org .apache .hadoop .fs .FSDataInputStream ;
6057import org .apache .hadoop .fs .FSDataOutputStream ;
6663import org .apache .hadoop .fs .permission .FsPermission ;
6764import org .apache .hadoop .hdds .client .StandaloneReplicationConfig ;
6865import org .apache .hadoop .hdds .conf .OzoneConfiguration ;
69- import org .apache .hadoop .ozone .MiniOzoneCluster ;
7066import org .apache .hadoop .ozone .OzoneConsts ;
7167import org .apache .hadoop .ozone .TestDataUtil ;
72- import org .apache .hadoop .ozone .client .BucketArgs ;
7368import org .apache .hadoop .ozone .client .ObjectStore ;
7469import org .apache .hadoop .ozone .client .OzoneBucket ;
7570import org .apache .hadoop .ozone .client .OzoneClient ;
7671import org .apache .hadoop .ozone .client .OzoneKey ;
7772import org .apache .hadoop .ozone .client .OzoneSnapshot ;
7873import org .apache .hadoop .ozone .client .OzoneVolume ;
79- import org .apache .hadoop .ozone .om .KeyManagerImpl ;
80- import org .apache .hadoop .ozone .om .OMConfigKeys ;
74+ import org .apache .hadoop .ozone .om .OmConfig ;
8175import org .apache .hadoop .ozone .om .OmSnapshotManager ;
8276import org .apache .hadoop .ozone .om .OzoneManager ;
8377import org .apache .hadoop .ozone .om .exceptions .OMException ;
78+ import org .apache .hadoop .ozone .om .helpers .BucketLayout ;
8479import org .apache .hadoop .ozone .om .helpers .OmKeyArgs ;
8580import org .apache .hadoop .ozone .om .helpers .OpenKeySession ;
8681import org .apache .hadoop .ozone .om .helpers .SnapshotInfo ;
8782import org .apache .hadoop .ozone .om .protocol .OzoneManagerProtocol ;
8883import org .apache .hadoop .security .UserGroupInformation ;
8984import org .apache .ozone .test .GenericTestUtils ;
85+ import org .apache .ozone .test .NonHATests ;
9086import org .junit .jupiter .api .AfterAll ;
9187import org .junit .jupiter .api .AfterEach ;
9288import org .junit .jupiter .api .BeforeAll ;
9995 * Abstract class for OmSnapshot file system tests.
10096 */
10197@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
102- public abstract class TestOmSnapshotFileSystem {
103- protected static final String VOLUME_NAME =
104- "volume" + RandomStringUtils .secure ().nextNumeric (5 );
105- protected static final String BUCKET_NAME_FSO =
106- "bucket-fso-" + RandomStringUtils .secure ().nextNumeric (5 );
107- protected static final String BUCKET_NAME_LEGACY =
108- "bucket-legacy-" + RandomStringUtils .secure ().nextNumeric (5 );
109-
110- private MiniOzoneCluster cluster = null ;
98+ public abstract class TestOmSnapshotFileSystem implements NonHATests .TestCase {
99+
111100 private OzoneClient client ;
112101 private ObjectStore objectStore ;
113102 private OzoneConfiguration conf ;
114103 private OzoneManagerProtocol writeClient ;
115104 private OzoneManager ozoneManager ;
116105 private String keyPrefix ;
117- private final String bucketName ;
106+ private String volumeName ;
107+ private String bucketName ;
108+ private final BucketLayout bucketLayout ;
118109 private final boolean createLinkedBuckets ;
119110 private FileSystem fs ;
120111 private OzoneFileSystem o3fs ;
121- private Map <String , String > linkedBucketMaps = new HashMap <>();
112+ private final Map <String , String > linkedBucketMaps = new HashMap <>();
113+ private OmConfig originalOmConfig ;
122114
123115 private static final Logger LOG =
124- LoggerFactory .getLogger (TestOmSnapshot .class );
116+ LoggerFactory .getLogger (TestOmSnapshotFileSystem .class );
125117
126- public TestOmSnapshotFileSystem (String bucketName , boolean createLinkedBuckets ) throws Exception {
127- this .bucketName = bucketName ;
118+ protected TestOmSnapshotFileSystem (BucketLayout layout , boolean createLinkedBuckets ) {
119+ this .bucketLayout = layout ;
128120 this .createLinkedBuckets = createLinkedBuckets ;
129- init ();
130121 }
131122
132- private void init () throws Exception {
133- conf = new OzoneConfiguration ();
134- conf .setBoolean (OMConfigKeys .OZONE_OM_ENABLE_FILESYSTEM_PATHS , true );
135- cluster = MiniOzoneCluster .newBuilder (conf ).build ();
136- cluster .waitForClusterToBeReady ();
137- client = cluster .newClient ();
123+ @ BeforeAll
124+ public void setupFsClient () throws IOException {
125+ OmConfig omConfig = cluster ().getOzoneManager ().getConfig ();
126+ originalOmConfig = omConfig .copy ();
127+ omConfig .setFileSystemPathEnabled (true );
128+
129+ client = cluster ().newClient ();
138130
139131 objectStore = client .getObjectStore ();
140132 writeClient = objectStore .getClientProxy ().getOzoneManagerClient ();
141- ozoneManager = cluster .getOzoneManager ();
133+ ozoneManager = cluster () .getOzoneManager ();
142134
143- TestDataUtil .createVolume (client , VOLUME_NAME );
144- OzoneBucket bucket = TestDataUtil .createBucket (client , VOLUME_NAME ,
145- new BucketArgs .Builder ().setBucketLayout (FILE_SYSTEM_OPTIMIZED ).build (),
146- BUCKET_NAME_FSO , createLinkedBuckets );
135+ OzoneBucket bucket = TestDataUtil .createVolumeAndBucket (client , bucketLayout , createLinkedBuckets );
147136 if (createLinkedBuckets ) {
148137 linkedBucketMaps .put (bucket .getName (), bucket .getSourceBucket ());
149138 }
150- bucket = TestDataUtil .createBucket (client , VOLUME_NAME ,
151- new BucketArgs .Builder ().setBucketLayout (LEGACY ).build (),
152- BUCKET_NAME_LEGACY , createLinkedBuckets );
153- if (createLinkedBuckets ) {
154- linkedBucketMaps .put (bucket .getName (), bucket .getSourceBucket ());
155- }
156-
157-
158-
159- // stop the deletion services so that keys can still be read
160- KeyManagerImpl keyManager = (KeyManagerImpl ) ozoneManager .getKeyManager ();
161- keyManager .stop ();
162- }
139+ volumeName = bucket .getVolumeName ();
140+ bucketName = bucket .getName ();
163141
164- @ BeforeAll
165- public void setupFsClient () throws IOException {
166142 String rootPath = String .format ("%s://%s.%s/" ,
167- OzoneConsts .OZONE_URI_SCHEME , bucketName , VOLUME_NAME );
143+ OzoneConsts .OZONE_URI_SCHEME , bucketName , volumeName );
144+ conf = new OzoneConfiguration (cluster ().getConf ());
168145 // Set the fs.defaultFS and start the filesystem
169146 conf .set (CommonConfigurationKeysPublic .FS_DEFAULT_NAME_KEY , rootPath );
170147 // Set the number of keys to be processed during batch operate.
@@ -177,9 +154,7 @@ public void setupFsClient() throws IOException {
177154 void tearDown () {
178155 IOUtils .closeQuietly (client );
179156 IOUtils .closeQuietly (fs );
180- if (cluster != null ) {
181- cluster .shutdown ();
182- }
157+ cluster ().getOzoneManager ().getConfig ().setFrom (originalOmConfig );
183158 }
184159
185160 /**
@@ -198,24 +173,16 @@ public void deleteRootDir()
198173 }
199174
200175 for (FileStatus fStatus : fileStatuses ) {
176+ assertEquals (fs .getScheme (), fStatus .getPath ().toUri ().getScheme (), "unexpected scheme" );
201177 fs .delete (fStatus .getPath (), true );
202178 }
203-
204-
205- GenericTestUtils .waitFor (() -> {
206- try {
207- return fs .listStatus (root ).length == 0 ;
208- } catch (Exception e ) {
209- return false ;
210- }
211- }, 1000 , 120000 );
212179 }
213180
214181 @ Test
215182 // based on TestObjectStoreWithFSO:testListKeysAtDifferentLevels
216183 public void testListKeysAtDifferentLevels () throws Exception {
217- OzoneVolume ozoneVolume = objectStore .getVolume (VOLUME_NAME );
218- assertEquals (ozoneVolume .getName (), VOLUME_NAME );
184+ OzoneVolume ozoneVolume = objectStore .getVolume (volumeName );
185+ assertEquals (ozoneVolume .getName (), volumeName );
219186 OzoneBucket ozoneBucket = ozoneVolume .getBucket (bucketName );
220187 assertEquals (ozoneBucket .getName (), bucketName );
221188
@@ -282,7 +249,7 @@ public void testListKeysAtDifferentLevels() throws Exception {
282249 deleteSnapshot (snapshotName );
283250 String expectedMessage = String .format ("Unable to load snapshot. " +
284251 "Snapshot with table key '/%s/%s/%s' is no longer active" ,
285- VOLUME_NAME , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName );
252+ volumeName , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName );
286253 OMException exception = assertThrows (OMException .class ,
287254 () -> ozoneBucket .listKeys (keyPrefix + "a/" , null ));
288255 assertEquals (expectedMessage , exception .getMessage ());
@@ -370,7 +337,7 @@ private void readkey(OzoneBucket ozoneBucket, String key, int length, byte[] inp
370337
371338 // Read using filesystem.
372339 String rootPath = String .format ("%s://%s.%s/" , OZONE_URI_SCHEME ,
373- bucketName , VOLUME_NAME );
340+ bucketName , volumeName );
374341 OzoneFileSystem o3fsNew = (OzoneFileSystem ) FileSystem
375342 .get (new URI (rootPath ), conf );
376343 try (InputStream fsDataInputStream = o3fsNew .open (new Path (key ))) {
@@ -497,21 +464,21 @@ public void testListStatus() throws Exception {
497464 () -> fs .listStatus (snapshotRoot1 ));
498465 assertEquals (String .format ("Unable to load snapshot. " +
499466 "Snapshot with table key '/%s/%s/%s' is no longer active" ,
500- VOLUME_NAME , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName1 ), exception1 .getMessage ());
467+ volumeName , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName1 ), exception1 .getMessage ());
501468
502469 deleteSnapshot (snapshotName2 );
503470 FileNotFoundException exception2 = assertThrows (FileNotFoundException .class ,
504471 () -> fs .listStatus (snapshotRoot2 ));
505472 assertEquals (String .format ("Unable to load snapshot. " +
506473 "Snapshot with table key '/%s/%s/%s' is no longer active" ,
507- VOLUME_NAME , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName2 ), exception2 .getMessage ());
474+ volumeName , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName2 ), exception2 .getMessage ());
508475
509476 deleteSnapshot (snapshotName3 );
510477 FileNotFoundException exception3 = assertThrows (FileNotFoundException .class ,
511478 () -> fs .listStatus (snapshotParent3 ));
512479 assertEquals (String .format ("Unable to load snapshot. " +
513480 "Snapshot with table key '/%s/%s/%s' is no longer active" ,
514- VOLUME_NAME , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName3 ), exception3 .getMessage ());
481+ volumeName , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName3 ), exception3 .getMessage ());
515482 }
516483
517484 @ Test
@@ -546,7 +513,7 @@ public void testListStatusWithIntermediateDir() throws Exception {
546513 () -> fs .listStatus (snapshotParent ));
547514 assertEquals (String .format ("Unable to load snapshot. " +
548515 "Snapshot with table key '/%s/%s/%s' is no longer active" ,
549- VOLUME_NAME , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
516+ volumeName , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
550517 }
551518
552519 @ Test
@@ -582,7 +549,7 @@ public void testGetFileStatus() throws Exception {
582549 () -> fs .listStatus (snapshotParent ));
583550 assertEquals (String .format ("Unable to load snapshot. " +
584551 "Snapshot with table key '/%s/%s/%s' is no longer active" ,
585- VOLUME_NAME , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
552+ volumeName , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
586553 }
587554
588555 @ Test
@@ -623,11 +590,11 @@ void testReadFileFromSnapshot() throws Exception {
623590 () -> fs .open (fileInSnapshot ));
624591 assertEquals (String .format ("FILE_NOT_FOUND: Unable to load snapshot. " +
625592 "Snapshot with table key '/%s/%s/%s' is no longer active" ,
626- VOLUME_NAME , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
593+ volumeName , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
627594 }
628595
629596 private void createAndCommitKey (String keyName ) throws IOException {
630- OmKeyArgs keyArgs = new OmKeyArgs .Builder ().setVolumeName (VOLUME_NAME )
597+ OmKeyArgs keyArgs = new OmKeyArgs .Builder ().setVolumeName (volumeName )
631598 .setBucketName (bucketName ).setKeyName (keyName )
632599 .setAcls (Collections .emptyList ())
633600 .setReplicationConfig (StandaloneReplicationConfig .getInstance (ONE ))
@@ -673,7 +640,7 @@ public void testListStatusOnRoot() throws Exception {
673640 () -> fs .listStatus (snapshotRoot ));
674641 assertEquals (String .format ("Unable to load snapshot. " +
675642 "Snapshot with table key '/%s/%s/%s' is no longer active" ,
676- VOLUME_NAME , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
643+ volumeName , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
677644 }
678645
679646 /**
@@ -728,17 +695,17 @@ public void testListStatusOnLargeDirectory() throws Exception {
728695 () -> fs .listStatus (snapshotRoot ));
729696 assertEquals (String .format ("Unable to load snapshot. " +
730697 "Snapshot with table key '/%s/%s/%s' is no longer active" ,
731- VOLUME_NAME , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
698+ volumeName , linkedBucketMaps .getOrDefault (bucketName , bucketName ), snapshotName ), exception .getMessage ());
732699 }
733700
734701 private String createSnapshot (String snapshotName )
735702 throws IOException , InterruptedException , TimeoutException {
736703
737704 // create snapshot
738- writeClient .createSnapshot (VOLUME_NAME , bucketName , snapshotName );
705+ writeClient .createSnapshot (volumeName , bucketName , snapshotName );
739706
740707 // wait till the snapshot directory exists
741- OzoneSnapshot snapshot = objectStore .getSnapshotInfo (VOLUME_NAME , bucketName , snapshotName );
708+ OzoneSnapshot snapshot = objectStore .getSnapshotInfo (volumeName , bucketName , snapshotName );
742709 SnapshotInfo snapshotInfo = ozoneManager .getMetadataManager ()
743710 .getSnapshotInfoTable ()
744711 .get (SnapshotInfo .getTableKey (snapshot .getVolumeName (), snapshot .getBucketName (), snapshotName ));
@@ -751,6 +718,6 @@ private String createSnapshot(String snapshotName)
751718 }
752719
753720 private void deleteSnapshot (String snapshotName ) throws IOException {
754- writeClient .deleteSnapshot (VOLUME_NAME , bucketName , snapshotName );
721+ writeClient .deleteSnapshot (volumeName , bucketName , snapshotName );
755722 }
756723}
0 commit comments