Search in sources :

Example 6 with ReconUtils

use of org.apache.hadoop.ozone.recon.ReconUtils in project ozone by apache.

the class MockOzoneServiceProvider method testGetOzoneManagerDBSnapshot.

@Test
public void testGetOzoneManagerDBSnapshot() throws Exception {
    File reconOmSnapshotDbDir = temporaryFolder.newFolder();
    File checkpointDir = Paths.get(reconOmSnapshotDbDir.getAbsolutePath(), "testGetOzoneManagerDBSnapshot").toFile();
    checkpointDir.mkdir();
    File file1 = Paths.get(checkpointDir.getAbsolutePath(), "file1").toFile();
    String str = "File1 Contents";
    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file1), UTF_8));
        writer.write(str);
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
    File file2 = Paths.get(checkpointDir.getAbsolutePath(), "file2").toFile();
    str = "File2 Contents";
    try {
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2), UTF_8));
        writer.write(str);
    } finally {
        writer.close();
    }
    // Create test tar file.
    File tarFile = createTarFile(checkpointDir.toPath());
    InputStream fileInputStream = new FileInputStream(tarFile);
    ReconUtils reconUtilsMock = getMockReconUtils();
    HttpURLConnection httpURLConnectionMock = mock(HttpURLConnection.class);
    when(httpURLConnectionMock.getInputStream()).thenReturn(fileInputStream);
    when(reconUtilsMock.makeHttpCall(any(), anyString(), anyBoolean())).thenReturn(httpURLConnectionMock);
    ReconOMMetadataManager reconOMMetadataManager = mock(ReconOMMetadataManager.class);
    ReconTaskController reconTaskController = getMockTaskController();
    OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(configuration, reconOMMetadataManager, reconTaskController, reconUtilsMock, ozoneManagerProtocol);
    DBCheckpoint checkpoint = ozoneManagerServiceProvider.getOzoneManagerDBSnapshot();
    assertNotNull(checkpoint);
    assertTrue(checkpoint.getCheckpointLocation().toFile().isDirectory());
    assertTrue(checkpoint.getCheckpointLocation().toFile().listFiles().length == 2);
}
Also used : ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) ReconTaskController(org.apache.hadoop.ozone.recon.tasks.ReconTaskController) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) HttpURLConnection(java.net.HttpURLConnection) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) ReconUtils.createTarFile(org.apache.hadoop.ozone.recon.ReconUtils.createTarFile) File(java.io.File) Test(org.junit.Test)

Example 7 with ReconUtils

use of org.apache.hadoop.ozone.recon.ReconUtils in project ozone by apache.

the class TestReconPipelineManager method setup.

@Before
public void setup() throws IOException {
    conf = new OzoneConfiguration();
    conf.set(OZONE_METADATA_DIRS, temporaryFolder.newFolder().getAbsolutePath());
    conf.set(OZONE_SCM_NAMES, "localhost");
    scmStorageConfig = new ReconStorageConfig(conf, new ReconUtils());
    store = DBStoreBuilder.createDBStore(conf, new ReconSCMDBDefinition());
    scmhaManager = MockSCMHAManager.getInstance(true, new MockSCMHADBTransactionBuffer(store));
    scmContext = SCMContext.emptyContext();
}
Also used : ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) MockSCMHADBTransactionBuffer(org.apache.hadoop.hdds.scm.ha.MockSCMHADBTransactionBuffer) Before(org.junit.Before)

Example 8 with ReconUtils

use of org.apache.hadoop.ozone.recon.ReconUtils in project ozone by apache.

the class MockOzoneServiceProvider method getMockReconUtils.

private ReconUtils getMockReconUtils() throws IOException {
    ReconUtils reconUtilsMock = mock(ReconUtils.class);
    when(reconUtilsMock.getReconDbDir(any(), anyString())).thenCallRealMethod();
    doCallRealMethod().when(reconUtilsMock).untarCheckpointFile(any(), any());
    return reconUtilsMock;
}
Also used : ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils)

Example 9 with ReconUtils

use of org.apache.hadoop.ozone.recon.ReconUtils in project ozone by apache.

the class MockOzoneServiceProvider method testSyncDataFromOMDeltaUpdates.

@Test
public void testSyncDataFromOMDeltaUpdates() throws Exception {
    // Non-Empty OM DB to start with.
    ReconOMMetadataManager omMetadataManager = getTestReconOmMetadataManager(initializeNewOmMetadataManager(temporaryFolder.newFolder()), temporaryFolder.newFolder());
    ReconTaskStatusDao reconTaskStatusDaoMock = mock(ReconTaskStatusDao.class);
    doNothing().when(reconTaskStatusDaoMock).update(any(ReconTaskStatus.class));
    ReconTaskController reconTaskControllerMock = getMockTaskController();
    when(reconTaskControllerMock.getReconTaskStatusDao()).thenReturn(reconTaskStatusDaoMock);
    doNothing().when(reconTaskControllerMock).consumeOMEvents(any(OMUpdateEventBatch.class), any(OMMetadataManager.class));
    OzoneManagerServiceProviderImpl ozoneManagerServiceProvider = new OzoneManagerServiceProviderImpl(configuration, omMetadataManager, reconTaskControllerMock, new ReconUtils(), ozoneManagerProtocol);
    OzoneManagerSyncMetrics metrics = ozoneManagerServiceProvider.getMetrics();
    // Should trigger delta updates.
    ozoneManagerServiceProvider.syncDataFromOM();
    ArgumentCaptor<ReconTaskStatus> captor = ArgumentCaptor.forClass(ReconTaskStatus.class);
    verify(reconTaskStatusDaoMock, times(1)).update(captor.capture());
    assertTrue(captor.getValue().getTaskName().equals(OmDeltaRequest.name()));
    verify(reconTaskControllerMock, times(1)).consumeOMEvents(any(OMUpdateEventBatch.class), any(OMMetadataManager.class));
    assertEquals(0, metrics.getNumSnapshotRequests().value());
}
Also used : ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) OzoneManagerSyncMetrics(org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) ReconTaskController(org.apache.hadoop.ozone.recon.tasks.ReconTaskController) ReconOMMetadataManager(org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager) ReconTaskStatusDao(org.hadoop.ozone.recon.schema.tables.daos.ReconTaskStatusDao) ReconTaskStatus(org.hadoop.ozone.recon.schema.tables.pojos.ReconTaskStatus) OMUpdateEventBatch(org.apache.hadoop.ozone.recon.tasks.OMUpdateEventBatch) Test(org.junit.Test)

Example 10 with ReconUtils

use of org.apache.hadoop.ozone.recon.ReconUtils in project ozone by apache.

the class TestStorageContainerServiceProviderImpl method setup.

@Before
public void setup() {
    injector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            try {
                StorageContainerLocationProtocol mockScmClient = mock(StorageContainerLocationProtocol.class);
                ReconUtils reconUtils = new ReconUtils();
                File testDir = GenericTestUtils.getRandomizedTestDir();
                OzoneConfiguration conf = new OzoneConfiguration();
                conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getPath());
                pipelineID = PipelineID.randomId().getProtobuf();
                when(mockScmClient.getPipeline(pipelineID)).thenReturn(mock(Pipeline.class));
                bind(StorageContainerLocationProtocol.class).toInstance(mockScmClient);
                bind(StorageContainerServiceProvider.class).to(StorageContainerServiceProviderImpl.class);
                bind(OzoneConfiguration.class).toInstance(conf);
                bind(ReconUtils.class).toInstance(reconUtils);
            } catch (Exception e) {
                Assert.fail();
            }
        }
    });
}
Also used : StorageContainerServiceProvider(org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider) ReconUtils(org.apache.hadoop.ozone.recon.ReconUtils) StorageContainerLocationProtocol(org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) File(java.io.File) IOException(java.io.IOException) AbstractModule(com.google.inject.AbstractModule) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Before(org.junit.Before)

Aggregations

ReconUtils (org.apache.hadoop.ozone.recon.ReconUtils)16 Test (org.junit.Test)11 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)7 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)6 ReconOMMetadataManager (org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager)6 File (java.io.File)5 DBCheckpoint (org.apache.hadoop.hdds.utils.db.DBCheckpoint)5 NetworkTopology (org.apache.hadoop.hdds.scm.net.NetworkTopology)4 NetworkTopologyImpl (org.apache.hadoop.hdds.scm.net.NetworkTopologyImpl)4 EventQueue (org.apache.hadoop.hdds.server.events.EventQueue)4 OzoneManagerSyncMetrics (org.apache.hadoop.ozone.recon.metrics.OzoneManagerSyncMetrics)4 ReconTaskController (org.apache.hadoop.ozone.recon.tasks.ReconTaskController)4 Before (org.junit.Before)4 UUID (java.util.UUID)3 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)3 MockDatanodeDetails.randomDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 HttpURLConnection (java.net.HttpURLConnection)2