use of org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider in project ozone by apache.
the class TestReconPipelineReportHandler method testProcessPipelineReport.
@Test
public void testProcessPipelineReport() throws IOException {
// Check with pipeline which does not exist in Recon.
Pipeline pipeline = getRandomPipeline();
PipelineID pipelineID = pipeline.getId();
HddsProtos.PipelineID pipelineIDProto = pipelineID.getProtobuf();
ReconPipelineManager reconPipelineManagerMock = mock(ReconPipelineManager.class);
when(reconPipelineManagerMock.getPipeline(pipelineID)).thenReturn(pipeline);
StorageContainerServiceProvider scmServiceProviderMock = mock(StorageContainerServiceProvider.class);
when(scmServiceProviderMock.getPipeline(pipelineIDProto)).thenReturn(pipeline);
OzoneConfiguration configuration = new OzoneConfiguration();
ReconPipelineReportHandler handler = new ReconPipelineReportHandler(new ReconSafeModeManager(), reconPipelineManagerMock, SCMContext.emptyContext(), configuration, scmServiceProviderMock);
EventPublisher eventPublisherMock = mock(EventPublisher.class);
PipelineReport report = mock(PipelineReport.class);
when(report.getPipelineID()).thenReturn(pipelineIDProto);
handler.processPipelineReport(report, pipeline.getNodes().get(0), eventPublisherMock);
// Verify that the new pipeline was added to pipeline manager.
verify(reconPipelineManagerMock, times(1)).addPipeline(pipeline);
verify(reconPipelineManagerMock, times(1)).getPipeline(pipelineID);
// Check with pipeline which already exists in Recon.
pipeline = getRandomPipeline();
pipelineID = pipeline.getId();
pipelineIDProto = pipelineID.getProtobuf();
when(reconPipelineManagerMock.containsPipeline(pipelineID)).thenReturn(true);
when(reconPipelineManagerMock.getPipeline(pipelineID)).thenReturn(pipeline);
when(report.getPipelineID()).thenReturn(pipelineIDProto);
handler.processPipelineReport(report, pipeline.getNodes().get(0), eventPublisherMock);
// Verify that the pipeline was not added to pipeline manager.
verify(reconPipelineManagerMock, times(0)).addPipeline(pipeline);
verify(reconPipelineManagerMock, times(1)).getPipeline(pipelineID);
}
use of org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider in project ozone by apache.
the class TestStorageContainerServiceProviderImpl method testGetPipelines.
@Test
public void testGetPipelines() throws IOException {
StorageContainerServiceProvider scmProvider = injector.getInstance(StorageContainerServiceProvider.class);
StorageContainerLocationProtocol scmClient = injector.getInstance(StorageContainerLocationProtocol.class);
scmProvider.getPipelines();
verify(scmClient, times(1)).listPipelines();
}
use of org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider in project ozone by apache.
the class TestEndpoints method initializeInjector.
private void initializeInjector() throws Exception {
reconOMMetadataManager = getTestReconOmMetadataManager(initializeNewOmMetadataManager(temporaryFolder.newFolder()), temporaryFolder.newFolder());
datanodeDetails = randomDatanodeDetails();
datanodeDetails2 = randomDatanodeDetails();
datanodeDetails.setHostName(HOST1);
datanodeDetails.setIpAddress(IP1);
datanodeDetails2.setHostName(HOST2);
datanodeDetails2.setIpAddress(IP2);
pipeline = getRandomPipeline(datanodeDetails);
pipelineId = pipeline.getId().getId().toString();
ContainerInfo containerInfo = new ContainerInfo.Builder().setContainerID(containerId).setReplicationConfig(RatisReplicationConfig.getInstance(ReplicationFactor.ONE)).setState(LifeCycleState.OPEN).setOwner("test").setPipelineID(pipeline.getId()).build();
ContainerWithPipeline containerWithPipeline = new ContainerWithPipeline(containerInfo, pipeline);
StorageContainerLocationProtocol mockScmClient = mock(StorageContainerLocationProtocol.class);
StorageContainerServiceProvider mockScmServiceProvider = mock(StorageContainerServiceProviderImpl.class);
when(mockScmServiceProvider.getPipeline(pipeline.getId().getProtobuf())).thenReturn(pipeline);
when(mockScmServiceProvider.getContainerWithPipeline(containerId)).thenReturn(containerWithPipeline);
List<Long> containerIDs = new LinkedList<>();
containerIDs.add(containerId);
List<ContainerWithPipeline> cpw = new LinkedList<>();
cpw.add(containerWithPipeline);
when(mockScmServiceProvider.getExistContainerWithPipelinesInBatch(containerIDs)).thenReturn(cpw);
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(PROMETHEUS_TEST_RESPONSE_FILE);
reconUtilsMock = mock(ReconUtils.class);
HttpURLConnection urlConnectionMock = mock(HttpURLConnection.class);
when(urlConnectionMock.getResponseCode()).thenReturn(HttpServletResponse.SC_OK);
when(urlConnectionMock.getInputStream()).thenReturn(inputStream);
when(reconUtilsMock.makeHttpCall(any(URLConnectionFactory.class), anyString(), anyBoolean())).thenReturn(urlConnectionMock);
when(reconUtilsMock.getReconDbDir(any(OzoneConfiguration.class), anyString())).thenReturn(GenericTestUtils.getRandomizedTestDir());
ReconTestInjector reconTestInjector = new ReconTestInjector.Builder(temporaryFolder).withReconSqlDb().withReconOm(reconOMMetadataManager).withOmServiceProvider(mock(OzoneManagerServiceProviderImpl.class)).addBinding(StorageContainerServiceProvider.class, mockScmServiceProvider).addBinding(OzoneStorageContainerManager.class, ReconStorageContainerManagerFacade.class).withContainerDB().addBinding(ClusterStateEndpoint.class).addBinding(NodeEndpoint.class).addBinding(MetricsServiceProviderFactory.class).addBinding(ContainerHealthSchemaManager.class).addBinding(UtilizationEndpoint.class).addBinding(ReconUtils.class, reconUtilsMock).addBinding(StorageContainerLocationProtocol.class, mockScmClient).build();
nodeEndpoint = reconTestInjector.getInstance(NodeEndpoint.class);
pipelineEndpoint = reconTestInjector.getInstance(PipelineEndpoint.class);
fileCountBySizeDao = getDao(FileCountBySizeDao.class);
GlobalStatsDao globalStatsDao = getDao(GlobalStatsDao.class);
UtilizationSchemaDefinition utilizationSchemaDefinition = getSchemaDefinition(UtilizationSchemaDefinition.class);
Configuration sqlConfiguration = reconTestInjector.getInstance(Configuration.class);
utilizationEndpoint = new UtilizationEndpoint(fileCountBySizeDao, utilizationSchemaDefinition);
fileSizeCountTask = new FileSizeCountTask(fileCountBySizeDao, utilizationSchemaDefinition);
tableCountTask = new TableCountTask(globalStatsDao, sqlConfiguration, reconOMMetadataManager);
reconScm = (ReconStorageContainerManagerFacade) reconTestInjector.getInstance(OzoneStorageContainerManager.class);
clusterStateEndpoint = new ClusterStateEndpoint(reconScm, globalStatsDao);
MetricsServiceProviderFactory metricsServiceProviderFactory = reconTestInjector.getInstance(MetricsServiceProviderFactory.class);
metricsProxyEndpoint = new MetricsProxyEndpoint(metricsServiceProviderFactory);
dslContext = getDslContext();
}
use of org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider in project ozone by apache.
the class TestContainerHealthTask method testDeletedContainer.
@Test
public void testDeletedContainer() throws Exception {
UnhealthyContainersDao unHealthyContainersTableHandle = getDao(UnhealthyContainersDao.class);
ContainerHealthSchemaManager containerHealthSchemaManager = new ContainerHealthSchemaManager(getSchemaDefinition(ContainerSchemaDefinition.class), unHealthyContainersTableHandle);
ReconStorageContainerManagerFacade scmMock = mock(ReconStorageContainerManagerFacade.class);
MockPlacementPolicy placementMock = new MockPlacementPolicy();
ContainerManager containerManagerMock = mock(ContainerManager.class);
StorageContainerServiceProvider scmClientMock = mock(StorageContainerServiceProvider.class);
// Create 2 containers. The first is OPEN will no replicas, the second is
// CLOSED with no replicas.
List<ContainerInfo> mockContainers = getMockContainers(2);
when(scmMock.getScmServiceProvider()).thenReturn(scmClientMock);
when(scmMock.getContainerManager()).thenReturn(containerManagerMock);
when(containerManagerMock.getContainers()).thenReturn(mockContainers);
for (ContainerInfo c : mockContainers) {
when(containerManagerMock.getContainer(c.containerID())).thenReturn(c);
when(scmClientMock.getContainerWithPipeline(c.getContainerID())).thenReturn(new ContainerWithPipeline(c, null));
}
// Container State OPEN with no replicas
when(containerManagerMock.getContainer(ContainerID.valueOf(1L)).getState()).thenReturn(HddsProtos.LifeCycleState.OPEN);
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(1L))).thenReturn(Collections.emptySet());
when(scmClientMock.getContainerWithPipeline(1)).thenReturn(new ContainerWithPipeline(mockContainers.get(0), null));
// Container State CLOSED with no replicas
when(containerManagerMock.getContainer(ContainerID.valueOf(2L)).getState()).thenReturn(HddsProtos.LifeCycleState.CLOSED);
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(2L))).thenReturn(Collections.emptySet());
ContainerInfo mockDeletedContainer = getMockDeletedContainer(2);
when(scmClientMock.getContainerWithPipeline(2)).thenReturn(new ContainerWithPipeline(mockDeletedContainer, null));
List<UnhealthyContainers> all = unHealthyContainersTableHandle.findAll();
Assert.assertTrue(all.isEmpty());
long currentTime = System.currentTimeMillis();
ReconTaskStatusDao reconTaskStatusDao = getDao(ReconTaskStatusDao.class);
ReconTaskConfig reconTaskConfig = new ReconTaskConfig();
reconTaskConfig.setMissingContainerTaskInterval(Duration.ofSeconds(2));
ContainerHealthTask containerHealthTask = new ContainerHealthTask(scmMock.getContainerManager(), scmMock.getScmServiceProvider(), reconTaskStatusDao, containerHealthSchemaManager, placementMock, reconTaskConfig);
containerHealthTask.start();
LambdaTestUtils.await(6000, 1000, () -> (unHealthyContainersTableHandle.count() == 1));
UnhealthyContainers rec = unHealthyContainersTableHandle.fetchByContainerId(1L).get(0);
assertEquals("MISSING", rec.getContainerState());
assertEquals(3, rec.getReplicaDelta().intValue());
ReconTaskStatus taskStatus = reconTaskStatusDao.findById(containerHealthTask.getTaskName());
Assert.assertTrue(taskStatus.getLastUpdatedTimestamp() > currentTime);
}
use of org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider in project ozone by apache.
the class TestContainerHealthTask method testRun.
@SuppressWarnings("checkstyle:methodlength")
@Test
public void testRun() throws Exception {
UnhealthyContainersDao unHealthyContainersTableHandle = getDao(UnhealthyContainersDao.class);
ContainerHealthSchemaManager containerHealthSchemaManager = new ContainerHealthSchemaManager(getSchemaDefinition(ContainerSchemaDefinition.class), unHealthyContainersTableHandle);
ReconStorageContainerManagerFacade scmMock = mock(ReconStorageContainerManagerFacade.class);
MockPlacementPolicy placementMock = new MockPlacementPolicy();
ContainerManager containerManagerMock = mock(ContainerManager.class);
StorageContainerServiceProvider scmClientMock = mock(StorageContainerServiceProvider.class);
ContainerReplica unhealthyReplicaMock = mock(ContainerReplica.class);
when(unhealthyReplicaMock.getState()).thenReturn(State.UNHEALTHY);
ContainerReplica healthyReplicaMock = mock(ContainerReplica.class);
when(healthyReplicaMock.getState()).thenReturn(State.CLOSED);
// Create 6 containers. The first 5 will have various unhealthy states
// defined below. The container with ID=6 will be healthy.
List<ContainerInfo> mockContainers = getMockContainers(6);
when(scmMock.getScmServiceProvider()).thenReturn(scmClientMock);
when(scmMock.getContainerManager()).thenReturn(containerManagerMock);
when(containerManagerMock.getContainers()).thenReturn(mockContainers);
for (ContainerInfo c : mockContainers) {
when(containerManagerMock.getContainer(c.containerID())).thenReturn(c);
when(scmClientMock.getContainerWithPipeline(c.getContainerID())).thenReturn(new ContainerWithPipeline(c, null));
}
// Under replicated
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(1L))).thenReturn(getMockReplicas(1L, State.CLOSED, State.UNHEALTHY));
// return all UNHEALTHY replicas for container ID 2 -> UNDER_REPLICATED
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(2L))).thenReturn(getMockReplicas(2L, State.UNHEALTHY));
// return 0 replicas for container ID 3 -> Missing
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(3L))).thenReturn(Collections.emptySet());
// Return 5 Healthy -> Over replicated
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(4L))).thenReturn(getMockReplicas(4L, State.CLOSED, State.CLOSED, State.CLOSED, State.CLOSED, State.CLOSED));
// Mis-replicated
Set<ContainerReplica> misReplicas = getMockReplicas(5L, State.CLOSED, State.CLOSED, State.CLOSED);
placementMock.setMisRepWhenDnPresent(misReplicas.iterator().next().getDatanodeDetails().getUuid());
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(5L))).thenReturn(misReplicas);
// Return 3 Healthy -> Healthy container
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(6L))).thenReturn(getMockReplicas(6L, State.CLOSED, State.CLOSED, State.CLOSED));
List<UnhealthyContainers> all = unHealthyContainersTableHandle.findAll();
Assert.assertTrue(all.isEmpty());
long currentTime = System.currentTimeMillis();
ReconTaskStatusDao reconTaskStatusDao = getDao(ReconTaskStatusDao.class);
ReconTaskConfig reconTaskConfig = new ReconTaskConfig();
reconTaskConfig.setMissingContainerTaskInterval(Duration.ofSeconds(2));
ContainerHealthTask containerHealthTask = new ContainerHealthTask(scmMock.getContainerManager(), scmMock.getScmServiceProvider(), reconTaskStatusDao, containerHealthSchemaManager, placementMock, reconTaskConfig);
containerHealthTask.start();
LambdaTestUtils.await(6000, 1000, () -> (unHealthyContainersTableHandle.count() == 5));
UnhealthyContainers rec = unHealthyContainersTableHandle.fetchByContainerId(1L).get(0);
assertEquals("UNDER_REPLICATED", rec.getContainerState());
assertEquals(2, rec.getReplicaDelta().intValue());
rec = unHealthyContainersTableHandle.fetchByContainerId(2L).get(0);
assertEquals("UNDER_REPLICATED", rec.getContainerState());
assertEquals(3, rec.getReplicaDelta().intValue());
List<UnhealthyContainers> unhealthyContainers = containerHealthSchemaManager.getUnhealthyContainers(ALL_REPLICAS_UNHEALTHY, 0, Integer.MAX_VALUE);
assertEquals(1, unhealthyContainers.size());
assertEquals(2L, unhealthyContainers.get(0).getContainerId().longValue());
assertEquals(0, unhealthyContainers.get(0).getActualReplicaCount().intValue());
rec = unHealthyContainersTableHandle.fetchByContainerId(3L).get(0);
assertEquals("MISSING", rec.getContainerState());
assertEquals(3, rec.getReplicaDelta().intValue());
rec = unHealthyContainersTableHandle.fetchByContainerId(4L).get(0);
assertEquals("OVER_REPLICATED", rec.getContainerState());
assertEquals(-2, rec.getReplicaDelta().intValue());
rec = unHealthyContainersTableHandle.fetchByContainerId(5L).get(0);
assertEquals("MIS_REPLICATED", rec.getContainerState());
assertEquals(1, rec.getReplicaDelta().intValue());
assertEquals(2, rec.getExpectedReplicaCount().intValue());
assertEquals(1, rec.getActualReplicaCount().intValue());
assertNotNull(rec.getReason());
ReconTaskStatus taskStatus = reconTaskStatusDao.findById(containerHealthTask.getTaskName());
Assert.assertTrue(taskStatus.getLastUpdatedTimestamp() > currentTime);
// Now run the job again, to check that relevant records are updated or
// removed as appropriate. Need to adjust the return value for all the mocks
// Under replicated -> Delta goes from 2 to 1
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(1L))).thenReturn(getMockReplicas(1L, State.CLOSED, State.CLOSED));
// ID 2 was missing - make it healthy now
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(2L))).thenReturn(getMockReplicas(2L, State.CLOSED, State.CLOSED, State.CLOSED));
// return 0 replicas for container ID 3 -> Still Missing
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(3L))).thenReturn(Collections.emptySet());
// Return 4 Healthy -> Delta changes from -2 to -1
when(containerManagerMock.getContainerReplicas(ContainerID.valueOf(4L))).thenReturn(getMockReplicas(4L, State.CLOSED, State.CLOSED, State.CLOSED, State.CLOSED));
// Was mis-replicated - make it healthy now
placementMock.setMisRepWhenDnPresent(null);
LambdaTestUtils.await(6000, 1000, () -> (unHealthyContainersTableHandle.count() == 3));
rec = unHealthyContainersTableHandle.fetchByContainerId(1L).get(0);
assertEquals("UNDER_REPLICATED", rec.getContainerState());
assertEquals(1, rec.getReplicaDelta().intValue());
// This container is now healthy, it should not be in the table any more
assertEquals(0, unHealthyContainersTableHandle.fetchByContainerId(2L).size());
rec = unHealthyContainersTableHandle.fetchByContainerId(3L).get(0);
assertEquals("MISSING", rec.getContainerState());
assertEquals(3, rec.getReplicaDelta().intValue());
rec = unHealthyContainersTableHandle.fetchByContainerId(4L).get(0);
assertEquals("OVER_REPLICATED", rec.getContainerState());
assertEquals(-1, rec.getReplicaDelta().intValue());
// This container is now healthy, it should not be in the table any more
assertEquals(0, unHealthyContainersTableHandle.fetchByContainerId(5L).size());
}
Aggregations