Search in sources :

Example 1 with OzoneManagerProtocol

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());
}
Also used : OzoneManagerProtocol(org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) MD5MD5CRC32GzipFileChecksum(org.apache.hadoop.fs.MD5MD5CRC32GzipFileChecksum) MockXceiverClientFactory(org.apache.hadoop.ozone.client.MockXceiverClientFactory) XceiverClientFactory(org.apache.hadoop.hdds.scm.XceiverClientFactory) OmKeyLocationInfo(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo) MD5MD5CRC32GzipFileChecksum(org.apache.hadoop.fs.MD5MD5CRC32GzipFileChecksum) FileChecksum(org.apache.hadoop.fs.FileChecksum) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) OzoneVolume(org.apache.hadoop.ozone.client.OzoneVolume) OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) OmKeyLocationInfoGroup(org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) XceiverClientGrpc(org.apache.hadoop.hdds.scm.XceiverClientGrpc) OmKeyInfo(org.apache.hadoop.ozone.om.helpers.OmKeyInfo) BlockID(org.apache.hadoop.hdds.client.BlockID) RpcClient(org.apache.hadoop.ozone.client.rpc.RpcClient) Test(org.junit.Test)

Example 2 with OzoneManagerProtocol

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;
}
Also used : OzoneManagerProtocol(org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol)

Example 3 with OzoneManagerProtocol

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;
}
Also used : UpgradeFinalizer(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer) OzoneManagerProtocol(org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol)

Example 4 with OzoneManagerProtocol

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;
}
Also used : HddsVersionProvider(org.apache.hadoop.hdds.cli.HddsVersionProvider) OzoneManagerProtocol(org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol) Set(java.util.Set) OmUtils.getOmHostsFromConfig(org.apache.hadoop.ozone.OmUtils.getOmHostsFromConfig) IOException(java.io.IOException) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Collectors(java.util.stream.Collectors) ChronoUnit(java.time.temporal.ChronoUnit) PREPARE_COMPLETED(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus.PREPARE_COMPLETED) Duration(java.time.Duration) Map(java.util.Map) PrepareStatusResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse) PrepareStatus(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus) CommandLine(picocli.CommandLine) OzoneManagerProtocol(org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol) HashMap(java.util.HashMap) Duration(java.time.Duration) IOException(java.io.IOException) IOException(java.io.IOException) PrepareStatus(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse.PrepareStatus) HashMap(java.util.HashMap) Map(java.util.Map) PrepareStatusResponse(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.PrepareStatusResponse)

Example 5 with OzoneManagerProtocol

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;
}
Also used : UpgradeException(org.apache.hadoop.ozone.upgrade.UpgradeException) UpgradeFinalizer(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer) OzoneManagerProtocol(org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol) IOException(java.io.IOException)

Aggregations

OzoneManagerProtocol (org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol)13 Test (org.junit.Test)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 FileChecksum (org.apache.hadoop.fs.FileChecksum)2 MD5MD5CRC32GzipFileChecksum (org.apache.hadoop.fs.MD5MD5CRC32GzipFileChecksum)2 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)2 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)2 UpgradeFinalizer (org.apache.hadoop.ozone.upgrade.UpgradeFinalizer)2 Optional (com.google.common.base.Optional)1 Provides (com.google.inject.Provides)1 File (java.io.File)1 Duration (java.time.Duration)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1