Search in sources :

Example 1 with ReplaceLabelsOnNodeRequestPBImpl

use of org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.ReplaceLabelsOnNodeRequestPBImpl in project hadoop by apache.

the class FileSystemNodeLabelsStore method loadFromMirror.

protected void loadFromMirror(Path newMirrorPath, Path oldMirrorPath) throws IOException {
    // If mirror.new exists, read from mirror.new,
    FSDataInputStream is = null;
    try {
        is = fs.open(newMirrorPath);
    } catch (FileNotFoundException e) {
        try {
            is = fs.open(oldMirrorPath);
        } catch (FileNotFoundException ignored) {
        }
    }
    if (null != is) {
        List<NodeLabel> labels = new AddToClusterNodeLabelsRequestPBImpl(AddToClusterNodeLabelsRequestProto.parseDelimitedFrom(is)).getNodeLabels();
        mgr.addToCluserNodeLabels(labels);
        if (mgr.isCentralizedConfiguration()) {
            // Only load node to labels mapping while using centralized configuration
            Map<NodeId, Set<String>> nodeToLabels = new ReplaceLabelsOnNodeRequestPBImpl(ReplaceLabelsOnNodeRequestProto.parseDelimitedFrom(is)).getNodeToLabels();
            mgr.replaceLabelsOnNode(nodeToLabels);
        }
        is.close();
    }
}
Also used : ReplaceLabelsOnNodeRequestPBImpl(org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.ReplaceLabelsOnNodeRequestPBImpl) NodeLabel(org.apache.hadoop.yarn.api.records.NodeLabel) Set(java.util.Set) AddToClusterNodeLabelsRequestPBImpl(org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.AddToClusterNodeLabelsRequestPBImpl) FileNotFoundException(java.io.FileNotFoundException) NodeId(org.apache.hadoop.yarn.api.records.NodeId) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

Example 2 with ReplaceLabelsOnNodeRequestPBImpl

use of org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.ReplaceLabelsOnNodeRequestPBImpl in project hadoop by apache.

the class FileSystemNodeLabelsStore method recover.

/* (non-Javadoc)
   * @see org.apache.hadoop.yarn.nodelabels.NodeLabelsStore#recover(boolean)
   */
@Override
public void recover() throws YarnException, IOException {
    /*
     * Steps of recover
     * 1) Read from last mirror (from mirror or mirror.old)
     * 2) Read from last edit log, and apply such edit log
     * 3) Write new mirror to mirror.writing
     * 4) Rename mirror to mirror.old
     * 5) Move mirror.writing to mirror
     * 6) Remove mirror.old
     * 7) Remove edit log and create a new empty edit log 
     */
    // Open mirror from serialized file
    Path mirrorPath = new Path(fsWorkingPath, MIRROR_FILENAME);
    Path oldMirrorPath = new Path(fsWorkingPath, MIRROR_FILENAME + ".old");
    loadFromMirror(mirrorPath, oldMirrorPath);
    // Open and process editlog
    editLogPath = new Path(fsWorkingPath, EDITLOG_FILENAME);
    FSDataInputStream is;
    try {
        is = fs.open(editLogPath);
    } catch (FileNotFoundException e) {
        is = null;
    }
    if (null != is) {
        while (true) {
            try {
                // read edit log one by one
                SerializedLogType type = SerializedLogType.values()[is.readInt()];
                switch(type) {
                    case ADD_LABELS:
                        {
                            List<NodeLabel> labels = new AddToClusterNodeLabelsRequestPBImpl(AddToClusterNodeLabelsRequestProto.parseDelimitedFrom(is)).getNodeLabels();
                            mgr.addToCluserNodeLabels(labels);
                            break;
                        }
                    case REMOVE_LABELS:
                        {
                            Collection<String> labels = RemoveFromClusterNodeLabelsRequestProto.parseDelimitedFrom(is).getNodeLabelsList();
                            mgr.removeFromClusterNodeLabels(labels);
                            break;
                        }
                    case NODE_TO_LABELS:
                        {
                            Map<NodeId, Set<String>> map = new ReplaceLabelsOnNodeRequestPBImpl(ReplaceLabelsOnNodeRequestProto.parseDelimitedFrom(is)).getNodeToLabels();
                            if (mgr.isCentralizedConfiguration()) {
                                /*
               * In case of Distributed NodeLabels setup,
               * ignoreNodeToLabelsMappings will be set to true and recover will
               * be invoked. As RM will collect the node labels from NM through
               * registration/HB
               */
                                mgr.replaceLabelsOnNode(map);
                            }
                            break;
                        }
                }
            } catch (EOFException e) {
                // EOF hit, break
                break;
            }
        }
        is.close();
    }
    // Serialize current mirror to mirror.writing
    Path writingMirrorPath = new Path(fsWorkingPath, MIRROR_FILENAME + ".writing");
    FSDataOutputStream os = fs.create(writingMirrorPath, true);
    ((AddToClusterNodeLabelsRequestPBImpl) AddToClusterNodeLabelsRequestPBImpl.newInstance(mgr.getClusterNodeLabels())).getProto().writeDelimitedTo(os);
    ((ReplaceLabelsOnNodeRequestPBImpl) ReplaceLabelsOnNodeRequest.newInstance(mgr.getNodeLabels())).getProto().writeDelimitedTo(os);
    os.close();
    // Move mirror to mirror.old
    if (fs.exists(mirrorPath)) {
        fs.delete(oldMirrorPath, false);
        fs.rename(mirrorPath, oldMirrorPath);
    }
    // move mirror.writing to mirror
    fs.rename(writingMirrorPath, mirrorPath);
    fs.delete(writingMirrorPath, false);
    // remove mirror.old
    fs.delete(oldMirrorPath, false);
    // create a new editlog file
    editlogOs = fs.create(editLogPath, true);
    editlogOs.close();
    LOG.info("Finished write mirror at:" + mirrorPath.toString());
    LOG.info("Finished create editlog file at:" + editLogPath.toString());
}
Also used : Path(org.apache.hadoop.fs.Path) ReplaceLabelsOnNodeRequestPBImpl(org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.ReplaceLabelsOnNodeRequestPBImpl) AddToClusterNodeLabelsRequestPBImpl(org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.AddToClusterNodeLabelsRequestPBImpl) FileNotFoundException(java.io.FileNotFoundException) EOFException(java.io.EOFException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) Collection(java.util.Collection) List(java.util.List) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) Map(java.util.Map)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 AddToClusterNodeLabelsRequestPBImpl (org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.AddToClusterNodeLabelsRequestPBImpl)2 ReplaceLabelsOnNodeRequestPBImpl (org.apache.hadoop.yarn.server.api.protocolrecords.impl.pb.ReplaceLabelsOnNodeRequestPBImpl)2 EOFException (java.io.EOFException)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 Path (org.apache.hadoop.fs.Path)1 NodeId (org.apache.hadoop.yarn.api.records.NodeId)1 NodeLabel (org.apache.hadoop.yarn.api.records.NodeLabel)1