Skip to content

Commit

Permalink
YARN-5559. Analyse 2.8.0/3.0.0 jdiff reports and fix any issues. Cont…
Browse files Browse the repository at this point in the history
…ributed by Akira Ajisaka & Wangda Tan
  • Loading branch information
jian-he committed Dec 5, 2016
1 parent 1b5ccea commit 43ebff2
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 38 deletions.
Expand Up @@ -18,7 +18,9 @@

package org.apache.hadoop.yarn.api.protocolrecords;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
Expand All @@ -28,18 +30,48 @@
@Public
@Evolving
public abstract class GetClusterNodeLabelsResponse {
/**
* Creates a new instance.
*
* @param labels Node labels
* @return response
* @deprecated Use {@link #newInstance(List)} instead.
*/
@Deprecated
public static GetClusterNodeLabelsResponse newInstance(Set<String> labels) {
List<NodeLabel> list = new ArrayList<>();
for (String label : labels) {
list.add(NodeLabel.newInstance(label));
}
return newInstance(list);
}

public static GetClusterNodeLabelsResponse newInstance(List<NodeLabel> labels) {
GetClusterNodeLabelsResponse request =
GetClusterNodeLabelsResponse response =
Records.newRecord(GetClusterNodeLabelsResponse.class);
request.setNodeLabels(labels);
return request;
response.setNodeLabelList(labels);
return response;
}

@Public
@Evolving
public abstract void setNodeLabels(List<NodeLabel> labels);
public abstract void setNodeLabelList(List<NodeLabel> labels);

public abstract List<NodeLabel> getNodeLabelList();

/**
* Set node labels to the response.
*
* @param labels Node labels
* @deprecated Use {@link #setNodeLabelList(List)} instead.
*/
@Deprecated
public abstract void setNodeLabels(Set<String> labels);

@Public
@Evolving
public abstract List<NodeLabel> getNodeLabels();
/**
* Get node labels of the response.
*
* @return Node labels
* @deprecated Use {@link #getNodeLabelList()} instead.
*/
@Deprecated
public abstract Set<String> getNodeLabels();
}
Expand Up @@ -899,7 +899,7 @@ public Map<NodeLabel, Set<NodeId>> getLabelsToNodes(Set<String> labels)
@Override
public List<NodeLabel> getClusterNodeLabels() throws YarnException, IOException {
return rmClient.getClusterNodeLabels(
GetClusterNodeLabelsRequest.newInstance()).getNodeLabels();
GetClusterNodeLabelsRequest.newInstance()).getNodeLabelList();
}

@Override
Expand Down
Expand Up @@ -19,7 +19,9 @@
package org.apache.hadoop.yarn.api.protocolrecords.impl.pb;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.hadoop.yarn.api.protocolrecords.GetClusterNodeLabelsResponse;
import org.apache.hadoop.yarn.api.records.NodeLabel;
Expand All @@ -46,7 +48,7 @@ public GetClusterNodeLabelsResponsePBImpl(
viaProto = true;
}

public GetClusterNodeLabelsResponseProto getProto() {
public synchronized GetClusterNodeLabelsResponseProto getProto() {
mergeLocalToProto();
proto = viaProto ? proto : builder.build();
viaProto = true;
Expand Down Expand Up @@ -101,14 +103,43 @@ private void maybeInitBuilder() {
}

@Override
public void setNodeLabels(List<NodeLabel> updatedNodeLabels) {
public synchronized void setNodeLabelList(List<NodeLabel> nodeLabels) {
maybeInitBuilder();
this.updatedNodeLabels = new ArrayList<>();
if (updatedNodeLabels == null) {
if (nodeLabels == null) {
builder.clearNodeLabels();
return;
}
this.updatedNodeLabels.addAll(updatedNodeLabels);
this.updatedNodeLabels.addAll(nodeLabels);
}

/**
* @deprecated Use {@link #getNodeLabelList()} instead.
*/
@Override
@Deprecated
public synchronized Set<String> getNodeLabels() {
Set<String> set = new HashSet<>();
List<NodeLabel> labelList = getNodeLabelList();
if (labelList != null) {
for (NodeLabel label : labelList) {
set.add(label.getName());
}
}
return set;
}

/**
* @deprecated Use {@link #setNodeLabelList(List)} instead.
*/
@Override
@Deprecated
public void setNodeLabels(Set<String> labels) {
List<NodeLabel> list = new ArrayList<>();
for (String s : labels) {
list.add(NodeLabel.newInstance(s));
}
setNodeLabelList(list);
}

private void initLocalNodeLabels() {
Expand All @@ -121,7 +152,7 @@ private void initLocalNodeLabels() {
}

@Override
public List<NodeLabel> getNodeLabels() {
public synchronized List<NodeLabel> getNodeLabelList() {
if (this.updatedNodeLabels != null) {
return this.updatedNodeLabels;
}
Expand Down
Expand Up @@ -73,6 +73,31 @@ public ContainerTokenIdentifier(ContainerId containerID,
CommonNodeLabelsManager.NO_LABEL, ContainerType.TASK);
}

/**
* Creates a instance.
*
* @param appSubmitter appSubmitter
* @param containerID container ID
* @param creationTime creation time
* @param expiryTimeStamp expiry timestamp
* @param hostName hostname
* @param logAggregationContext log aggregation context
* @param masterKeyId master key ID
* @param priority priority
* @param r resource needed by the container
* @param rmIdentifier ResourceManager identifier
* @deprecated Use one of the other constructors instead.
*/
@Deprecated
public ContainerTokenIdentifier(ContainerId containerID, String hostName,
String appSubmitter, Resource r, long expiryTimeStamp, int masterKeyId,
long rmIdentifier, Priority priority, long creationTime,
LogAggregationContext logAggregationContext) {
this(containerID, hostName, appSubmitter, r, expiryTimeStamp, masterKeyId,
rmIdentifier, priority, creationTime, logAggregationContext,
CommonNodeLabelsManager.NO_LABEL);
}

public ContainerTokenIdentifier(ContainerId containerID, String hostName,
String appSubmitter, Resource r, long expiryTimeStamp, int masterKeyId,
long rmIdentifier, Priority priority, long creationTime,
Expand Down
Expand Up @@ -20,32 +20,20 @@

import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;

/**
* The exception that happens when you call invalid state transition.
*
*/
@Public
@Evolving
public class InvalidStateTransitionException extends YarnRuntimeException {
@SuppressWarnings("deprecation")
public class InvalidStateTransitionException extends
InvalidStateTransitonException {

private static final long serialVersionUID = -6188669113571351684L;
private Enum<?> currentState;
private Enum<?> event;
private static final long serialVersionUID = 8610511635996283691L;

public InvalidStateTransitionException(Enum<?> currentState, Enum<?> event) {
super("Invalid event: " + event + " at " + currentState);
this.currentState = currentState;
this.event = event;
super(currentState, event);
}

public Enum<?> getCurrentState() {
return currentState;
}

public Enum<?> getEvent() {
return event;
}

}
Expand Up @@ -20,20 +20,31 @@

import org.apache.hadoop.classification.InterfaceAudience.Public;
import org.apache.hadoop.classification.InterfaceStability.Evolving;
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;

/** @deprecated Use {@link InvalidStateTransitionException} instead. */

@Public
@Evolving
@Deprecated
public class InvalidStateTransitonException extends
InvalidStateTransitionException {
public class InvalidStateTransitonException extends YarnRuntimeException {

private static final long serialVersionUID = 8610511635996283691L;
private static final long serialVersionUID = -6188669113571351684L;
private Enum<?> currentState;
private Enum<?> event;

public InvalidStateTransitonException(Enum<?> currentState, Enum<?> event) {
super(currentState, event);
super("Invalid event: " + event + " at " + currentState);
this.currentState = currentState;
this.event = event;
}

public Enum<?> getCurrentState() {
return currentState;
}

public Enum<?> getEvent() {
return event;
}

}
Expand Up @@ -1534,7 +1534,7 @@ protected ClientRMService createClientRMService() {
// Get node labels collection
GetClusterNodeLabelsResponse response = client
.getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance());
Assert.assertTrue(response.getNodeLabels().containsAll(
Assert.assertTrue(response.getNodeLabelList().containsAll(
Arrays.asList(labelX, labelY)));

// Get node labels mapping
Expand Down Expand Up @@ -1605,7 +1605,7 @@ protected ClientRMService createClientRMService() {
// Get node labels collection
GetClusterNodeLabelsResponse response = client
.getClusterNodeLabels(GetClusterNodeLabelsRequest.newInstance());
Assert.assertTrue(response.getNodeLabels().containsAll(
Assert.assertTrue(response.getNodeLabelList().containsAll(
Arrays.asList(labelX, labelY, labelZ)));

// Get labels to nodes mapping
Expand Down

0 comments on commit 43ebff2

Please sign in to comment.