Search in sources :

Example 1 with SCMVersionResponseProto

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMVersionResponseProto in project ozone by apache.

the class VersionEndpointTask method call.

/**
 * Computes a result, or throws an exception if unable to do so.
 *
 * @return computed result
 * @throws Exception if unable to compute a result
 */
@Override
public EndpointStateMachine.EndPointStates call() throws Exception {
    rpcEndPoint.lock();
    try {
        if (rpcEndPoint.getState().equals(EndpointStateMachine.EndPointStates.GETVERSION)) {
            SCMVersionResponseProto versionResponse = rpcEndPoint.getEndPoint().getVersion(null);
            VersionResponse response = VersionResponse.getFromProtobuf(versionResponse);
            rpcEndPoint.setVersion(response);
            if (!rpcEndPoint.isPassive()) {
                // If end point is passive, datanode does not need to check volumes.
                String scmId = response.getValue(OzoneConsts.SCM_ID);
                String clusterId = response.getValue(OzoneConsts.CLUSTER_ID);
                // Check volumes
                MutableVolumeSet volumeSet = ozoneContainer.getVolumeSet();
                volumeSet.writeLock();
                try {
                    Map<String, StorageVolume> volumeMap = volumeSet.getVolumeMap();
                    Preconditions.checkNotNull(scmId, "Reply from SCM: scmId cannot be null");
                    Preconditions.checkNotNull(clusterId, "Reply from SCM: clusterId cannot be null");
                    // create version file and also set scm ID or cluster ID.
                    for (Map.Entry<String, StorageVolume> entry : volumeMap.entrySet()) {
                        StorageVolume volume = entry.getValue();
                        boolean result = HddsVolumeUtil.checkVolume((HddsVolume) volume, scmId, clusterId, configuration, LOG);
                        if (!result) {
                            volumeSet.failVolume(volume.getStorageDir().getPath());
                        }
                    }
                    if (volumeSet.getVolumesList().size() == 0) {
                        // All volumes are in inconsistent state
                        throw new DiskOutOfSpaceException("All configured Volumes are in Inconsistent State");
                    }
                } finally {
                    volumeSet.writeUnlock();
                }
                // Start the container services after getting the version information
                ozoneContainer.start(clusterId);
            }
            EndpointStateMachine.EndPointStates nextState = rpcEndPoint.getState().getNextState();
            rpcEndPoint.setState(nextState);
            rpcEndPoint.zeroMissedCount();
        } else {
            LOG.debug("Cannot execute GetVersion task as endpoint state machine " + "is in {} state", rpcEndPoint.getState());
        }
    } catch (DiskOutOfSpaceException ex) {
        rpcEndPoint.setState(EndpointStateMachine.EndPointStates.SHUTDOWN);
    } catch (IOException ex) {
        rpcEndPoint.logIfNeeded(ex);
    } finally {
        rpcEndPoint.unlock();
    }
    return rpcEndPoint.getState();
}
Also used : VersionResponse(org.apache.hadoop.ozone.protocol.VersionResponse) IOException(java.io.IOException) DiskOutOfSpaceException(org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException) EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) StorageVolume(org.apache.hadoop.ozone.container.common.volume.StorageVolume) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) Map(java.util.Map) SCMVersionResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMVersionResponseProto)

Example 2 with SCMVersionResponseProto

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMVersionResponseProto in project ozone by apache.

the class TestEndPoint method testGetVersion.

@Test
public /**
 * This test asserts that we are able to make a version call to SCM server
 * and gets back the expected values.
 */
void testGetVersion() throws Exception {
    try (EndpointStateMachine rpcEndPoint = createEndpoint(SCMTestUtils.getConf(), serverAddress, 1000)) {
        SCMVersionResponseProto responseProto = rpcEndPoint.getEndPoint().getVersion(null);
        Assert.assertNotNull(responseProto);
        Assert.assertEquals(VersionInfo.DESCRIPTION_KEY, responseProto.getKeys(0).getKey());
        Assert.assertEquals(VersionInfo.getLatestVersion().getDescription(), responseProto.getKeys(0).getValue());
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) SCMVersionResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMVersionResponseProto) Test(org.junit.Test)

Aggregations

SCMVersionResponseProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMVersionResponseProto)2 EndpointStateMachine (org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine)2 IOException (java.io.IOException)1 Map (java.util.Map)1 MutableVolumeSet (org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet)1 StorageVolume (org.apache.hadoop.ozone.container.common.volume.StorageVolume)1 VersionResponse (org.apache.hadoop.ozone.protocol.VersionResponse)1 DiskOutOfSpaceException (org.apache.hadoop.util.DiskChecker.DiskOutOfSpaceException)1 Test (org.junit.Test)1