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.Public;
022import org.apache.hadoop.yarn.util.Records;
023
024/**
025 * Used by Application Master, send a container resource increase request to
026 * Resource Manager
027 */
028@Public
029public abstract class ContainerResourceIncreaseRequest {
030  @Public
031  public static ContainerResourceIncreaseRequest newInstance(
032      ContainerId existingContainerId, Resource targetCapability) {
033    ContainerResourceIncreaseRequest context = Records
034        .newRecord(ContainerResourceIncreaseRequest.class);
035    context.setContainerId(existingContainerId);
036    context.setCapability(targetCapability);
037    return context;
038  }
039
040  @Public
041  public abstract ContainerId getContainerId();
042
043  @Public
044  public abstract void setContainerId(ContainerId containerId);
045
046  @Public
047  public abstract Resource getCapability();
048
049  @Public
050  public abstract void setCapability(Resource capability);
051
052  @Override
053  public int hashCode() {
054    return getCapability().hashCode() + getContainerId().hashCode();
055  }
056  
057  @Override
058  public boolean equals(Object other) {
059    if (other instanceof ContainerResourceIncreaseRequest) {
060      ContainerResourceIncreaseRequest ctx =
061          (ContainerResourceIncreaseRequest) other;
062      
063      if (getContainerId() == null && ctx.getContainerId() != null) {
064        return false;
065      } else if (!getContainerId().equals(ctx.getContainerId())) {
066        return false;
067      }
068      
069      if (getCapability() == null && ctx.getCapability() != null) {
070        return false;
071      } else if (!getCapability().equals(ctx.getCapability())) {
072        return false;
073      }
074      
075      return true;
076    } else {
077      return false;
078    }
079  }
080}