Search in sources :

Example 1 with NodeAlreadyExistsException

use of org.apache.hadoop.hdds.scm.node.states.NodeAlreadyExistsException in project ozone by apache.

the class SCMNodeManager method register.

/**
 * Register the node if the node finds that it is not registered with any
 * SCM.
 *
 * @param datanodeDetails - Send datanodeDetails with Node info.
 *                        This function generates and assigns new datanode ID
 *                        for the datanode. This allows SCM to be run
 *                        independent
 *                        of Namenode if required.
 * @param nodeReport      NodeReport.
 * @return SCMRegisteredResponseProto
 */
@Override
public RegisteredCommand register(DatanodeDetails datanodeDetails, NodeReportProto nodeReport, PipelineReportsProto pipelineReportsProto, LayoutVersionProto layoutInfo) {
    if (layoutInfo.getSoftwareLayoutVersion() != scmLayoutVersionManager.getSoftwareLayoutVersion()) {
        return RegisteredCommand.newBuilder().setErrorCode(ErrorCode.errorNodeNotPermitted).setDatanode(datanodeDetails).setClusterID(this.scmStorageConfig.getClusterID()).build();
    }
    if (!isNodeRegistered(datanodeDetails)) {
        InetAddress dnAddress = Server.getRemoteIp();
        if (dnAddress != null) {
            // Mostly called inside an RPC, update ip and peer hostname
            datanodeDetails.setHostName(dnAddress.getHostName());
            datanodeDetails.setIpAddress(dnAddress.getHostAddress());
        }
        try {
            String dnsName;
            String networkLocation;
            datanodeDetails.setNetworkName(datanodeDetails.getUuidString());
            if (useHostname) {
                dnsName = datanodeDetails.getHostName();
            } else {
                dnsName = datanodeDetails.getIpAddress();
            }
            networkLocation = nodeResolve(dnsName);
            if (networkLocation != null) {
                datanodeDetails.setNetworkLocation(networkLocation);
            }
            clusterMap.add(datanodeDetails);
            nodeStateManager.addNode(datanodeDetails, layoutInfo);
            // Check that datanode in nodeStateManager has topology parent set
            DatanodeDetails dn = nodeStateManager.getNode(datanodeDetails);
            Preconditions.checkState(dn.getParent() != null);
            addEntryTodnsToUuidMap(dnsName, datanodeDetails.getUuidString());
            // Updating Node Report, as registration is successful
            processNodeReport(datanodeDetails, nodeReport);
            LOG.info("Registered Data node : {}", datanodeDetails);
            scmNodeEventPublisher.fireEvent(SCMEvents.NEW_NODE, datanodeDetails);
        } catch (NodeAlreadyExistsException e) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Datanode is already registered. Datanode: {}", datanodeDetails.toString());
            }
        } catch (NodeNotFoundException e) {
            LOG.error("Cannot find datanode {} from nodeStateManager", datanodeDetails.toString());
        }
    }
    return RegisteredCommand.newBuilder().setErrorCode(ErrorCode.success).setDatanode(datanodeDetails).setClusterID(this.scmStorageConfig.getClusterID()).build();
}
Also used : NodeNotFoundException(org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) NodeAlreadyExistsException(org.apache.hadoop.hdds.scm.node.states.NodeAlreadyExistsException) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)1 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)1 NodeAlreadyExistsException (org.apache.hadoop.hdds.scm.node.states.NodeAlreadyExistsException)1 NodeNotFoundException (org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException)1