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 */
018package org.apache.hadoop.hdfs.server.namenode;
019
020import org.apache.hadoop.classification.InterfaceAudience;
021import org.apache.hadoop.fs.permission.PermissionStatus;
022import org.apache.hadoop.fs.StorageType;
023import org.apache.hadoop.hdfs.util.EnumCounters;
024
025import com.google.common.base.Preconditions;
026
027/**
028 * The attributes of an inode.
029 */
030@InterfaceAudience.Private
031public interface INodeDirectoryAttributes extends INodeAttributes {
032  public QuotaCounts getQuotaCounts();
033
034  public boolean metadataEquals(INodeDirectoryAttributes other);
035  
036  /** A copy of the inode directory attributes */
037  public static class SnapshotCopy extends INodeAttributes.SnapshotCopy
038      implements INodeDirectoryAttributes {
039    public SnapshotCopy(byte[] name, PermissionStatus permissions,
040        AclFeature aclFeature, long modificationTime, 
041        XAttrFeature xAttrsFeature) {
042      super(name, permissions, aclFeature, modificationTime, 0L, xAttrsFeature);
043    }
044
045    public SnapshotCopy(INodeDirectory dir) {
046      super(dir);
047    }
048
049    @Override
050    public QuotaCounts getQuotaCounts() {
051      return new QuotaCounts.Builder().nameSpace(-1).
052          storageSpace(-1).typeSpaces(-1).build();
053    }
054
055    public boolean isDirectory() {
056      return true;
057    }
058
059    @Override
060    public boolean metadataEquals(INodeDirectoryAttributes other) {
061      return other != null
062          && getQuotaCounts().equals(other.getQuotaCounts())
063          && getPermissionLong() == other.getPermissionLong()
064          && getAclFeature() == other.getAclFeature()
065          && getXAttrFeature() == other.getXAttrFeature();
066    }
067  }
068
069  public static class CopyWithQuota extends INodeDirectoryAttributes.SnapshotCopy {
070    private QuotaCounts quota;
071
072    public CopyWithQuota(byte[] name, PermissionStatus permissions,
073        AclFeature aclFeature, long modificationTime, long nsQuota,
074        long dsQuota, EnumCounters<StorageType> typeQuotas, XAttrFeature xAttrsFeature) {
075      super(name, permissions, aclFeature, modificationTime, xAttrsFeature);
076      this.quota = new QuotaCounts.Builder().nameSpace(nsQuota).
077          storageSpace(dsQuota).typeSpaces(typeQuotas).build();
078    }
079
080    public CopyWithQuota(INodeDirectory dir) {
081      super(dir);
082      Preconditions.checkArgument(dir.isQuotaSet());
083      final QuotaCounts q = dir.getQuotaCounts();
084      this.quota = new QuotaCounts.Builder().quotaCount(q).build();
085    }
086
087    @Override
088    public QuotaCounts getQuotaCounts() {
089      return new QuotaCounts.Builder().quotaCount(quota).build();
090    }
091  }
092}