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.io.data.loading.impl;
020
021import org.apache.commons.lang.builder.EqualsBuilder;
022import org.apache.commons.lang3.builder.HashCodeBuilder;
023import org.apache.reef.annotations.Unstable;
024
025/**
026 * POJO that represents a distributed data set partition. Basically, it contains the path where
027 * the data files are located for this partition, and the location where we want
028 * this data to be loaded into.
029 *
030 */
031@Unstable
032public final class DistributedDataSetPartition {
033
034  /**
035   * The path of the distributed data set partition. If we use HDFS, it will be the
036   * hdfs path.
037   */
038  private final String path;
039
040  /**
041   * The location (either a rackName or a nodeName) where we want the data in
042   * this distributed partition to be loaded into. It can contain a wildcard at
043   * the end, for example /datacenter1/*.
044   */
045  private final String location;
046
047  /**
048   * Number of desired splits for this partition.
049   */
050  private final int desiredSplits;
051
052  DistributedDataSetPartition(final String path, final String location, final int desiredSplits) {
053    this.path = path;
054    this.location = location;
055    this.desiredSplits = desiredSplits;
056  }
057
058  /**
059   * Returns the path to the distributed data partition.
060   *
061   * @return the path of the distributed data partition
062   */
063  String getPath() {
064    return path;
065  }
066
067  /**
068   * Returns the location where we want the data in this partition to be loaded
069   * into.
070   *
071   * @return the location where to load this data into.
072   */
073  String getLocation() {
074    return location;
075  }
076
077  /**
078   * Returns the number of desired splits for this data partition.
079   *
080   * @return the number of desired splits
081   */
082  int getDesiredSplits() {
083    return desiredSplits;
084  }
085
086  /**
087   * @return a new DistributedDataSetPartition Builder.
088   */
089  public static Builder newBuilder() {
090    return new Builder();
091  }
092
093  @Override
094  public boolean equals(final Object obj) {
095    if (obj == this) {
096      return true;
097    }
098    if (!(obj instanceof DistributedDataSetPartition)) {
099      return false;
100    }
101    final DistributedDataSetPartition that = (DistributedDataSetPartition) obj;
102    return new EqualsBuilder().append(this.path, that.path).append(this.location, that.location)
103        .append(this.desiredSplits, that.desiredSplits).isEquals();
104  }
105
106  @Override
107  public int hashCode() {
108    return new HashCodeBuilder(17, 37).append(this.path).append(this.location).append(this.desiredSplits).toHashCode();
109  }
110
111  @Override
112  public String toString() {
113    return "{" + this.path + "," + this.location + "," + this.desiredSplits + "}";
114  }
115
116  /**
117   * {@link DistributedDataSetPartition}s are build using this Builder.
118   */
119  public static final class Builder implements org.apache.reef.util.Builder<DistributedDataSetPartition> {
120
121    private String path;
122    private String location;
123    private int desiredSplits;
124
125    private Builder() {
126    }
127
128    /**
129     * Sets the path of the distributed data set partition.
130     *
131     * @param path
132     *          the path to set
133     * @return this
134     */
135    public Builder setPath(final String path) {
136      this.path = path;
137      return this;
138    }
139
140
141    /**
142     * Sets the location where we want the data in this partition to be loaded
143     * into.
144     *
145     * @param location
146     *          the location to set
147     * @return this
148     */
149    public Builder setLocation(final String location) {
150      this.location = location;
151      return this;
152    }
153
154    /**
155     * Sets the desired number of splits for this partition.
156     * @param desiredSplits
157     *          the number of desired splits
158     * @return this
159     */
160    public Builder setDesiredSplits(final int desiredSplits) {
161      this.desiredSplits = desiredSplits;
162      return this;
163    }
164
165    /**
166     * Builds the {@link DistributedDataSetPartition}.
167     */
168    @Override
169    public DistributedDataSetPartition build() {
170      return new DistributedDataSetPartition(this.path, this.location, this.desiredSplits);
171    }
172  }
173}