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  DISK(false),
037  SSD(false),
038  ARCHIVE(false),
039  RAM_DISK(true);
040
041  private final boolean isTransient;
042
043  public static final StorageType DEFAULT = DISK;
044
045  public static final StorageType[] EMPTY_ARRAY = {};
046
047  private static final StorageType[] VALUES = values();
048
049  StorageType(boolean isTransient) {
050    this.isTransient = isTransient;
051  }
052
053  public boolean isTransient() {
054    return isTransient;
055  }
056
057  public boolean supportTypeQuota() {
058    return !isTransient;
059  }
060
061  public boolean isMovable() {
062    return !isTransient;
063  }
064
065  public static List<StorageType> asList() {
066    return Arrays.asList(VALUES);
067  }
068
069  public static List<StorageType> getMovableTypes() {
070    return getNonTransientTypes();
071  }
072
073  public static List<StorageType> getTypesSupportingQuota() {
074    return getNonTransientTypes();
075  }
076
077  public static StorageType parseStorageType(int i) {
078    return VALUES[i];
079  }
080
081  public static StorageType parseStorageType(String s) {
082    return StorageType.valueOf(StringUtils.toUpperCase(s));
083  }
084
085  private static List<StorageType> getNonTransientTypes() {
086    List<StorageType> nonTransientTypes = new ArrayList<>();
087    for (StorageType t : VALUES) {
088      if ( t.isTransient == false ) {
089        nonTransientTypes.add(t);
090      }
091    }
092    return nonTransientTypes;
093  }
094}