use of org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol in project ozone by apache.
the class TestReplicatedFileChecksumHelper method testOneBlock.
@Test
public void testOneBlock() throws IOException {
// test the file checksum of a file with one block.
OzoneConfiguration conf = new OzoneConfiguration();
RpcClient mockRpcClient = Mockito.mock(RpcClient.class);
List<DatanodeDetails> dns = Arrays.asList(DatanodeDetails.newBuilder().setUuid(UUID.randomUUID()).build());
Pipeline pipeline;
pipeline = Pipeline.newBuilder().setId(PipelineID.randomId()).setReplicationConfig(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.THREE)).setState(Pipeline.PipelineState.CLOSED).setNodes(dns).build();
XceiverClientGrpc xceiverClientGrpc = new XceiverClientGrpc(pipeline, conf) {
@Override
public XceiverClientReply sendCommandAsync(ContainerProtos.ContainerCommandRequestProto request, DatanodeDetails dn) {
return buildValidResponse();
}
};
XceiverClientFactory factory = Mockito.mock(XceiverClientFactory.class);
when(factory.acquireClientForReadData(ArgumentMatchers.any())).thenReturn(xceiverClientGrpc);
when(mockRpcClient.getXceiverClientManager()).thenReturn(factory);
OzoneManagerProtocol om = Mockito.mock(OzoneManagerProtocol.class);
when(mockRpcClient.getOzoneManagerClient()).thenReturn(om);
BlockID blockID = new BlockID(1, 1);
OmKeyLocationInfo omKeyLocationInfo = new OmKeyLocationInfo.Builder().setPipeline(pipeline).setBlockID(blockID).build();
List<OmKeyLocationInfo> omKeyLocationInfoList = Arrays.asList(omKeyLocationInfo);
OmKeyInfo omKeyInfo = new OmKeyInfo.Builder().setVolumeName(null).setBucketName(null).setKeyName(null).setOmKeyLocationInfos(Collections.singletonList(new OmKeyLocationInfoGroup(0, omKeyLocationInfoList))).setCreationTime(Time.now()).setModificationTime(Time.now()).setDataSize(0).setReplicationConfig(RatisReplicationConfig.getInstance(HddsProtos.ReplicationFactor.ONE)).setFileEncryptionInfo(null).setAcls(null).build();
when(om.lookupKey(ArgumentMatchers.any())).thenReturn(omKeyInfo);
OzoneVolume mockVolume = Mockito.mock(OzoneVolume.class);
when(mockVolume.getName()).thenReturn("vol1");
OzoneBucket bucket = Mockito.mock(OzoneBucket.class);
when(bucket.getName()).thenReturn("bucket1");
ReplicatedFileChecksumHelper helper = new ReplicatedFileChecksumHelper(mockVolume, bucket, "dummy", 10, mockRpcClient);
helper.compute();
FileChecksum fileChecksum = helper.getFileChecksum();
assertTrue(fileChecksum instanceof MD5MD5CRC32GzipFileChecksum);
assertEquals(1, helper.getKeyLocationInfoList().size());
}
use of org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol in project ozone by apache.
the class CancelPrepareSubCommand method call.
@Override
public Void call() throws Exception {
OzoneManagerProtocol client = parent.createOmClient(omServiceId);
client.cancelOzoneManagerPrepare();
System.out.println("Cancel prepare succeeded, cluster can now accept " + "write requests.");
return null;
}
use of org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol in project ozone by apache.
the class FinalizationStatusSubCommand method call.
@Override
public Void call() throws Exception {
OzoneManagerProtocol client = parent.createOmClient(omServiceId, omHost, false);
String upgradeClientID = "Upgrade-Client-" + UUID.randomUUID().toString();
UpgradeFinalizer.StatusAndMessages progress = client.queryUpgradeFinalizationProgress(upgradeClientID, false, true);
System.out.println(progress.status());
return null;
}
use of org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol in project ozone by apache.
the class PrepareSubCommand method call.
@Override
public Void call() throws Exception {
OzoneManagerProtocol client = parent.createOmClient(omServiceId);
long prepareTxnId = client.prepareOzoneManager(txnApplyWaitTimeSeconds, txnApplyCheckIntervalSeconds);
System.out.println("Ozone Manager Prepare Request successfully returned " + "with Transaction Id : [" + prepareTxnId + "].");
Map<String, Boolean> omPreparedStatusMap = new HashMap<>();
Set<String> omHosts = getOmHostsFromConfig(parent.getParent().getOzoneConf(), omServiceId);
omHosts.forEach(h -> omPreparedStatusMap.put(h, false));
Duration pTimeout = Duration.of(prepareTimeOut, ChronoUnit.SECONDS);
Duration pInterval = Duration.of(prepareCheckInterval, ChronoUnit.SECONDS);
System.out.println();
System.out.println("Checking individual OM instances for prepare request " + "completion...");
long endTime = System.currentTimeMillis() + pTimeout.toMillis();
int expectedNumPreparedOms = omPreparedStatusMap.size();
int currentNumPreparedOms = 0;
while (System.currentTimeMillis() < endTime && currentNumPreparedOms < expectedNumPreparedOms) {
for (Map.Entry<String, Boolean> e : omPreparedStatusMap.entrySet()) {
if (!e.getValue()) {
String omHost = e.getKey();
try (OzoneManagerProtocol singleOmClient = parent.createOmClient(omServiceId, omHost, false)) {
PrepareStatusResponse response = singleOmClient.getOzoneManagerPrepareStatus(prepareTxnId);
PrepareStatus status = response.getStatus();
System.out.println("OM : [" + omHost + "], Prepare " + "Status : [" + status.name() + "], Current Transaction Id : [" + response.getCurrentTxnIndex() + "]");
if (status.equals(PREPARE_COMPLETED)) {
e.setValue(true);
currentNumPreparedOms++;
}
} catch (IOException ioEx) {
System.out.println("Exception while checking preparation " + "completeness for [" + omHost + "], Error : [" + ioEx.getMessage() + "]");
}
}
}
if (currentNumPreparedOms < expectedNumPreparedOms) {
System.out.println("Waiting for " + prepareCheckInterval + " seconds before retrying...");
Thread.sleep(pInterval.toMillis());
}
}
if (currentNumPreparedOms < (expectedNumPreparedOms + 1) / 2) {
throw new Exception("OM Preparation failed since a majority OMs are not" + " prepared yet.");
} else {
System.out.println();
System.out.println("OM Preparation successful! ");
if (currentNumPreparedOms == expectedNumPreparedOms) {
System.out.println("All OMs are prepared");
} else {
System.out.println("A majority of OMs are prepared. OMs that are not " + "prepared : " + omPreparedStatusMap.entrySet().stream().filter(e -> !e.getValue()).map(e -> e.getKey()).collect(Collectors.joining()));
}
System.out.println("No new write requests will be allowed until " + "preparation is cancelled or upgrade/downgrade is done.");
}
return null;
}
use of org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol in project ozone by apache.
the class FinalizeUpgradeSubCommand method call.
@Override
public Void call() throws Exception {
boolean forceHA = false;
OzoneManagerProtocol client = parent.createOmClient(omServiceId, omHost, forceHA);
String upgradeClientID = "Upgrade-Client-" + UUID.randomUUID().toString();
try {
UpgradeFinalizer.StatusAndMessages finalizationResponse = client.finalizeUpgrade(upgradeClientID);
if (isFinalized(finalizationResponse.status())) {
System.out.println("Upgrade has already been finalized.");
emitExitMsg();
return null;
} else if (!isStarting(finalizationResponse.status())) {
System.err.println("Invalid response from Ozone Manager.");
System.err.println("Current finalization status is: " + finalizationResponse.status());
throw new IOException("Exiting...");
}
} catch (UpgradeException e) {
handleInvalidRequestAfterInitiatingFinalization(force, e);
}
monitorAndWaitFinalization(client, upgradeClientID);
return null;
}
Aggregations