001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.hadoop.hdfs.server.protocol;
019
020 import java.io.DataInput;
021 import java.io.DataOutput;
022 import java.io.IOException;
023
024 import org.apache.hadoop.classification.InterfaceAudience;
025 import org.apache.hadoop.classification.InterfaceStability;
026 import org.apache.hadoop.io.Writable;
027 import org.apache.hadoop.io.WritableFactory;
028 import org.apache.hadoop.io.WritableFactories;
029 import org.apache.hadoop.io.WritableUtils;
030 import org.apache.avro.reflect.Union;
031
032 /**
033 * Base class for data-node command.
034 * Issued by the name-node to notify data-nodes what should be done.
035 */
036
037 // Declare subclasses for Avro's denormalized representation
038 @Union({Void.class,
039 DatanodeCommand.Register.class, DatanodeCommand.Finalize.class,
040 BlockCommand.class, UpgradeCommand.class,
041 BlockRecoveryCommand.class, KeyUpdateCommand.class})
042
043 @InterfaceAudience.Private
044 @InterfaceStability.Evolving
045 public abstract class DatanodeCommand extends ServerCommand {
046 static class Register extends DatanodeCommand {
047 private Register() {super(DatanodeProtocol.DNA_REGISTER);}
048 public void readFields(DataInput in) {}
049 public void write(DataOutput out) {}
050 }
051
052 public static class Finalize extends DatanodeCommand {
053 String blockPoolId;
054 private Finalize() {
055 super(DatanodeProtocol.DNA_FINALIZE);
056 }
057
058 public Finalize(String bpid) {
059 super(DatanodeProtocol.DNA_FINALIZE);
060 blockPoolId = bpid;
061 }
062
063 public String getBlockPoolId() {
064 return blockPoolId;
065 }
066
067 public void readFields(DataInput in) throws IOException {
068 blockPoolId = WritableUtils.readString(in);
069 }
070 public void write(DataOutput out) throws IOException {
071 WritableUtils.writeString(out, blockPoolId);
072 }
073 }
074
075 static { // register a ctor
076 WritableFactories.setFactory(Register.class,
077 new WritableFactory() {
078 public Writable newInstance() {return new Register();}
079 });
080 WritableFactories.setFactory(Finalize.class,
081 new WritableFactory() {
082 public Writable newInstance() {return new Finalize();}
083 });
084 }
085
086 public static final DatanodeCommand REGISTER = new Register();
087
088 public DatanodeCommand() {
089 super();
090 }
091
092 DatanodeCommand(int action) {
093 super(action);
094 }
095 }