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
019package org.apache.hadoop.fs;
020
021import java.util.Arrays;
022import java.util.ArrayList;
023import java.util.List;
024
025import org.apache.hadoop.classification.InterfaceAudience;
026import org.apache.hadoop.classification.InterfaceStability;
027import org.apache.hadoop.util.StringUtils;
028
029/**
030 * Defines the types of supported storage media. The default storage
031 * medium is assumed to be DISK.
032 */
033@InterfaceAudience.Public
034@InterfaceStability.Unstable
035public enum StorageType {
036  // sorted by the speed of the storage types, from fast to slow
037  RAM_DISK(true),
038  SSD(false),
039  DISK(false),
040  ARCHIVE(false);
041
042  private final boolean isTransient;
043
044  public static final StorageType DEFAULT = DISK;
045
046  public static final StorageType[] EMPTY_ARRAY = {};
047
048  private static final StorageType[] VALUES = values();
049
050  StorageType(boolean isTransient) {
051    this.isTransient = isTransient;
052  }
053
054  public boolean isTransient() {
055    return isTransient;
056  }
057
058  public boolean supportTypeQuota() {
059    return !isTransient;
060  }
061
062  public boolean isMovable() {
063    return !isTransient;
064  }
065
066  public static List<StorageType> asList() {
067    return Arrays.asList(VALUES);
068  }
069
070  public static List<StorageType> getMovableTypes() {
071    return getNonTransientTypes();
072  }
073
074  public static List<StorageType> getTypesSupportingQuota() {
075    return getNonTransientTypes();
076  }
077
078  public static StorageType parseStorageType(int i) {
079    return VALUES[i];
080  }
081
082  public static StorageType parseStorageType(String s) {
083    return StorageType.valueOf(StringUtils.toUpperCase(s));
084  }
085
086  private static List<StorageType> getNonTransientTypes() {
087    List<StorageType> nonTransientTypes = new ArrayList<>();
088    for (StorageType t : VALUES) {
089      if ( t.isTransient == false ) {
090        nonTransientTypes.add(t);
091      }
092    }
093    return nonTransientTypes;
094  }
095}