use of org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol in project ozone by apache.
the class TestFailoverWithSCMHA method testFailover.
@Test
public void testFailover() throws Exception {
SCMClientConfig scmClientConfig = conf.getObject(SCMClientConfig.class);
scmClientConfig.setRetryCount(1);
scmClientConfig.setRetryInterval(100);
scmClientConfig.setMaxRetryTimeout(1500);
Assert.assertEquals(scmClientConfig.getRetryCount(), 15);
conf.setFromObject(scmClientConfig);
StorageContainerManager scm = getLeader(cluster);
Assert.assertNotNull(scm);
SCMBlockLocationFailoverProxyProvider failoverProxyProvider = new SCMBlockLocationFailoverProxyProvider(conf);
failoverProxyProvider.changeCurrentProxy(scm.getSCMNodeId());
ScmBlockLocationProtocolClientSideTranslatorPB scmBlockLocationClient = new ScmBlockLocationProtocolClientSideTranslatorPB(failoverProxyProvider);
GenericTestUtils.setLogLevel(SCMBlockLocationFailoverProxyProvider.LOG, Level.DEBUG);
GenericTestUtils.LogCapturer logCapture = GenericTestUtils.LogCapturer.captureLogs(SCMBlockLocationFailoverProxyProvider.LOG);
ScmBlockLocationProtocol scmBlockLocationProtocol = TracingUtil.createProxy(scmBlockLocationClient, ScmBlockLocationProtocol.class, conf);
scmBlockLocationProtocol.getScmInfo();
Assert.assertTrue(logCapture.getOutput().contains("Performing failover to suggested leader"));
scm = getLeader(cluster);
SCMContainerLocationFailoverProxyProvider proxyProvider = new SCMContainerLocationFailoverProxyProvider(conf, null);
GenericTestUtils.setLogLevel(SCMContainerLocationFailoverProxyProvider.LOG, Level.DEBUG);
logCapture = GenericTestUtils.LogCapturer.captureLogs(SCMContainerLocationFailoverProxyProvider.LOG);
proxyProvider.changeCurrentProxy(scm.getSCMNodeId());
StorageContainerLocationProtocol scmContainerClient = TracingUtil.createProxy(new StorageContainerLocationProtocolClientSideTranslatorPB(proxyProvider), StorageContainerLocationProtocol.class, conf);
scmContainerClient.allocateContainer(HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.ONE, "ozone");
Assert.assertTrue(logCapture.getOutput().contains("Performing failover to suggested leader"));
}
use of org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol in project ozone by apache.
the class BaseFreonGenerator method findPipelineForTest.
public static Pipeline findPipelineForTest(String pipelineId, StorageContainerLocationProtocol client, Logger log) throws IOException {
List<Pipeline> pipelines = client.listPipelines();
Pipeline pipeline;
if (pipelineId != null && pipelineId.length() > 0) {
pipeline = pipelines.stream().filter(p -> p.getId().toString().equals(pipelineId)).findFirst().orElseThrow(() -> new IllegalArgumentException("Pipeline ID is defined, but there is no such pipeline: " + pipelineId));
} else {
pipeline = pipelines.stream().filter(p -> p.getReplicationConfig().getRequiredNodes() == 3).findFirst().orElseThrow(() -> new IllegalArgumentException("Pipeline ID is NOT defined, and no pipeline " + "has been found with factor=THREE"));
log.info("Using pipeline {}", pipeline.getId());
}
return pipeline;
}
use of org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol in project ozone by apache.
the class DatanodeBlockPutter method call.
@Override
public Void call() throws Exception {
init();
OzoneConfiguration ozoneConf = createOzoneConfiguration();
if (OzoneSecurityUtil.isSecurityEnabled(ozoneConf)) {
throw new IllegalArgumentException("datanode-block-putter is not supported in secure environment");
}
try (StorageContainerLocationProtocol scmLocationClient = createStorageContainerLocationClient(ozoneConf)) {
Pipeline pipeline = findPipelineForTest(pipelineId, scmLocationClient, LOG);
try (XceiverClientManager xceiverClientManager = new XceiverClientManager(ozoneConf)) {
client = xceiverClientManager.acquireClient(pipeline);
timer = getMetrics().timer("put-block");
byte[] data = RandomStringUtils.randomAscii(chunkSize).getBytes(StandardCharsets.UTF_8);
Checksum checksum = new Checksum(ChecksumType.CRC32, 1024 * 1024);
checksumProtobuf = checksum.computeChecksum(data).getProtoBufMessage();
runTests(this::putBlock);
}
} finally {
if (client != null) {
client.close();
}
}
return null;
}
use of org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol in project ozone by apache.
the class TestKeyManagerImpl method testRefreshPipeline.
@Test
public void testRefreshPipeline() throws Exception {
OzoneManager ozoneManager = om;
StorageContainerLocationProtocol sclProtocolMock = mock(StorageContainerLocationProtocol.class);
List<Long> containerIDs = new ArrayList<>();
containerIDs.add(100L);
containerIDs.add(200L);
List<ContainerWithPipeline> cps = new ArrayList<>();
for (Long containerID : containerIDs) {
ContainerWithPipeline containerWithPipelineMock = mock(ContainerWithPipeline.class);
when(containerWithPipelineMock.getPipeline()).thenReturn(getRandomPipeline());
ContainerInfo ci = mock(ContainerInfo.class);
when(ci.getContainerID()).thenReturn(containerID);
when(containerWithPipelineMock.getContainerInfo()).thenReturn(ci);
cps.add(containerWithPipelineMock);
}
when(sclProtocolMock.getContainerWithPipelineBatch(containerIDs)).thenReturn(cps);
ScmClient scmClientMock = mock(ScmClient.class);
when(scmClientMock.getContainerClient()).thenReturn(sclProtocolMock);
OmKeyInfo omKeyInfo = OMRequestTestUtils.createOmKeyInfo("v1", "b1", "k1", ReplicationType.RATIS, ReplicationFactor.THREE);
// Add block to key.
List<OmKeyLocationInfo> omKeyLocationInfoList = new ArrayList<>();
Pipeline pipeline = getRandomPipeline();
OmKeyLocationInfo omKeyLocationInfo = new OmKeyLocationInfo.Builder().setBlockID(new BlockID(100L, 1000L)).setOffset(0).setLength(100L).setPipeline(pipeline).build();
omKeyLocationInfoList.add(omKeyLocationInfo);
OmKeyLocationInfo omKeyLocationInfo2 = new OmKeyLocationInfo.Builder().setBlockID(new BlockID(200L, 1000L)).setOffset(0).setLength(100L).setPipeline(pipeline).build();
omKeyLocationInfoList.add(omKeyLocationInfo2);
OmKeyLocationInfo omKeyLocationInfo3 = new OmKeyLocationInfo.Builder().setBlockID(new BlockID(100L, 2000L)).setOffset(0).setLength(100L).setPipeline(pipeline).build();
omKeyLocationInfoList.add(omKeyLocationInfo3);
omKeyInfo.appendNewBlocks(omKeyLocationInfoList, false);
KeyManagerImpl keyManagerImpl = new KeyManagerImpl(ozoneManager, scmClientMock, conf, "om1");
keyManagerImpl.refresh(omKeyInfo);
verify(sclProtocolMock, times(1)).getContainerWithPipelineBatch(containerIDs);
}
use of org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol 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();
}
Aggregations