This project has retired. For details please refer to its Attic page.
Source code
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
028/**
029 * A rack in the cluster.
030 */
031public final class RackDescriptorImpl implements RackDescriptor {
032
033  private final String name;
034
035
036  private final List<NodeDescriptorImpl> nodes;
037
038  RackDescriptorImpl(final String name) {
039    this.name = name;
040    this.nodes = new ArrayList<>();
041  }
042
043  public String toString() {
044    final StringBuilder sb = new StringBuilder();
045    sb.append("Rack " + this.name);
046    for (final NodeDescriptorImpl node : nodes) {
047      sb.append("\n\t" + node);
048    }
049    return sb.toString();
050  }
051
052  public int hashCode() {
053    return this.name.hashCode();
054  }
055
056  public boolean equals(final Object obj) {
057    if (obj instanceof RackDescriptorImpl) {
058      return obj.toString().equals(this.name);
059    } else {
060      return false;
061    }
062  }
063
064  public String getName() {
065    return this.name;
066  }
067
068  @Override
069  public List<NodeDescriptor> getNodes() {
070    return Collections.unmodifiableList(new ArrayList<NodeDescriptor>(this.nodes));
071  }
072
073  /**
074   * Should only be used from YarnNodeDescriptor constructor.
075   *
076   * @param node to add.
077   */
078  void addNodeDescriptor(final NodeDescriptorImpl node) {
079    this.nodes.add(node);
080  }
081}