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, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.runtime.common.driver.catalog; 020 021import org.apache.reef.driver.catalog.NodeDescriptor; 022import org.apache.reef.driver.catalog.RackDescriptor; 023 024import java.util.ArrayList; 025import java.util.Collections; 026import java.util.List; 027 028public final class RackDescriptorImpl implements RackDescriptor { 029 030 private final String name; 031 032 033 private final List<NodeDescriptorImpl> nodes; 034 035 RackDescriptorImpl(final String name) { 036 this.name = name; 037 this.nodes = new ArrayList<>(); 038 } 039 040 public final String toString() { 041 final StringBuilder sb = new StringBuilder(); 042 sb.append("Rack " + this.name); 043 for (final NodeDescriptorImpl node : nodes) { 044 sb.append("\n\t" + node); 045 } 046 return sb.toString(); 047 } 048 049 public final int hashCode() { 050 return this.name.hashCode(); 051 } 052 053 public final boolean equals(final Object obj) { 054 if (obj instanceof RackDescriptorImpl) { 055 return obj.toString().equals(this.name); 056 } else { 057 return false; 058 } 059 } 060 061 public String getName() { 062 return this.name; 063 } 064 065 @Override 066 public List<NodeDescriptor> getNodes() { 067 return Collections.unmodifiableList(new ArrayList<NodeDescriptor>(this.nodes)); 068 } 069 070 /** 071 * Should only be used from YarnNodeDescriptor constructor. 072 * 073 * @param node to add. 074 */ 075 void addNodeDescriptor(final NodeDescriptorImpl node) { 076 this.nodes.add(node); 077 } 078}