Search in sources :

Example 1 with DatanodeCRLStore

use of org.apache.hadoop.hdds.datanode.metadata.DatanodeCRLStore in project ozone by apache.

the class TestReportPublisher method testCRLStatusReportPublisher.

@Test
public void testCRLStatusReportPublisher() throws IOException {
    StateContext dummyContext = Mockito.mock(StateContext.class);
    DatanodeStateMachine dummyStateMachine = Mockito.mock(DatanodeStateMachine.class);
    ReportPublisher publisher = new CRLStatusReportPublisher();
    DatanodeCRLStore dnCrlStore = Mockito.mock(DatanodeCRLStore.class);
    when(dnCrlStore.getLatestCRLSequenceID()).thenReturn(3L);
    List<CRLInfo> pendingCRLs = new ArrayList<>();
    pendingCRLs.add(Mockito.mock(CRLInfo.class));
    pendingCRLs.add(Mockito.mock(CRLInfo.class));
    when(dnCrlStore.getPendingCRLs()).thenReturn(pendingCRLs);
    when(dummyStateMachine.getDnCRLStore()).thenReturn(dnCrlStore);
    when(dummyContext.getParent()).thenReturn(dummyStateMachine);
    publisher.setConf(config);
    ScheduledExecutorService executorService = HadoopExecutors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Unit test ReportManager Thread - %d").build());
    publisher.init(dummyContext, executorService);
    GeneratedMessage report = ((CRLStatusReportPublisher) publisher).getReport();
    Assert.assertNotNull(report);
    for (Descriptors.FieldDescriptor descriptor : report.getDescriptorForType().getFields()) {
        if (descriptor.getNumber() == CRLStatusReport.RECEIVEDCRLID_FIELD_NUMBER) {
            Assert.assertEquals(3L, report.getField(descriptor));
        }
    }
    executorService.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) ArrayList(java.util.ArrayList) DatanodeCRLStore(org.apache.hadoop.hdds.datanode.metadata.DatanodeCRLStore) CRLInfo(org.apache.hadoop.hdds.security.x509.crl.CRLInfo) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) Descriptors(com.google.protobuf.Descriptors) GeneratedMessage(com.google.protobuf.GeneratedMessage) Test(org.junit.Test)

Example 2 with DatanodeCRLStore

use of org.apache.hadoop.hdds.datanode.metadata.DatanodeCRLStore in project ozone by apache.

the class CRLStatusReportPublisher method getReport.

@Override
protected CRLStatusReport getReport() throws IOException {
    CRLStatusReport.Builder builder = CRLStatusReport.newBuilder();
    DatanodeCRLStore dnCRLStore = this.getContext().getParent().getDnCRLStore();
    builder.setReceivedCrlId(dnCRLStore.getLatestCRLSequenceID());
    if (dnCRLStore.getPendingCRLs().size() > 0) {
        List<Long> pendingCRLIds = dnCRLStore.getPendingCRLs().stream().map(CRLInfo::getCrlSequenceID).collect(Collectors.toList());
        builder.addAllPendingCrlIds(pendingCRLIds);
    }
    return builder.build();
}
Also used : CRLStatusReport(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CRLStatusReport) DatanodeCRLStore(org.apache.hadoop.hdds.datanode.metadata.DatanodeCRLStore)

Aggregations

DatanodeCRLStore (org.apache.hadoop.hdds.datanode.metadata.DatanodeCRLStore)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Descriptors (com.google.protobuf.Descriptors)1 GeneratedMessage (com.google.protobuf.GeneratedMessage)1 ArrayList (java.util.ArrayList)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 CRLStatusReport (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CRLStatusReport)1 CRLInfo (org.apache.hadoop.hdds.security.x509.crl.CRLInfo)1 DatanodeStateMachine (org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine)1 StateContext (org.apache.hadoop.ozone.container.common.statemachine.StateContext)1 Test (org.junit.Test)1