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.yarn.api.records; 020 021import org.apache.hadoop.classification.InterfaceAudience.Private; 022import org.apache.hadoop.classification.InterfaceAudience.Public; 023import org.apache.hadoop.classification.InterfaceStability.Stable; 024import org.apache.hadoop.classification.InterfaceStability.Unstable; 025import org.apache.hadoop.yarn.util.Records; 026 027@Public 028@Unstable 029public abstract class NodeLabel implements Comparable<NodeLabel> { 030 031 /** 032 * Default node label partition used for displaying. 033 */ 034 @Private 035 @Unstable 036 public static final String DEFAULT_NODE_LABEL_PARTITION = "<DEFAULT_PARTITION>"; 037 038 /** 039 * Node Label expression not set . 040 */ 041 @Private 042 @Unstable 043 public static final String NODE_LABEL_EXPRESSION_NOT_SET = "<Not set>"; 044 045 /** 046 * By default, node label is exclusive or not 047 */ 048 @Private 049 @Unstable 050 public static final boolean DEFAULT_NODE_LABEL_EXCLUSIVITY = true; 051 052 @Private 053 @Unstable 054 public static NodeLabel newInstance(String name) { 055 return newInstance(name, DEFAULT_NODE_LABEL_EXCLUSIVITY); 056 } 057 058 @Private 059 @Unstable 060 public static NodeLabel newInstance(String name, boolean isExclusive) { 061 NodeLabel request = Records.newRecord(NodeLabel.class); 062 request.setName(name); 063 request.setExclusivity(isExclusive); 064 return request; 065 } 066 067 @Public 068 @Stable 069 public abstract String getName(); 070 071 @Private 072 @Unstable 073 public abstract void setName(String name); 074 075 @Public 076 @Stable 077 public abstract boolean isExclusive(); 078 079 @Private 080 @Unstable 081 public abstract void setExclusivity(boolean isExclusive); 082 083 @Override 084 public int compareTo(NodeLabel other) { 085 return getName().compareTo(other.getName()); 086 } 087 088 @Override 089 public boolean equals(Object obj) { 090 if (obj instanceof NodeLabel) { 091 NodeLabel nl = (NodeLabel) obj; 092 return nl.getName().equals(getName()) 093 && nl.isExclusive() == isExclusive(); 094 } 095 return false; 096 } 097 098 @Override 099 public String toString() { 100 StringBuilder sb = new StringBuilder(); 101 sb.append("<"); 102 sb.append(getName()); 103 sb.append(":exclusivity="); 104 sb.append(isExclusive()); 105 sb.append(">"); 106 return sb.toString(); 107 } 108 109 @Override 110 public int hashCode() { 111 return (getName().hashCode() << 16) + (isExclusive() ? 1 : 0); 112 } 113}