|
@@ -23,13 +23,16 @@ import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
+import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
import org.apache.hadoop.yarn.api.records.ContainerStatus;
|
|
import org.apache.hadoop.yarn.api.records.ContainerStatus;
|
|
import org.apache.hadoop.yarn.api.records.NodeHealthStatus;
|
|
import org.apache.hadoop.yarn.api.records.NodeHealthStatus;
|
|
import org.apache.hadoop.yarn.api.records.NodeId;
|
|
import org.apache.hadoop.yarn.api.records.NodeId;
|
|
import org.apache.hadoop.yarn.api.records.ProtoBase;
|
|
import org.apache.hadoop.yarn.api.records.ProtoBase;
|
|
|
|
+import org.apache.hadoop.yarn.api.records.impl.pb.ApplicationIdPBImpl;
|
|
import org.apache.hadoop.yarn.api.records.impl.pb.ContainerStatusPBImpl;
|
|
import org.apache.hadoop.yarn.api.records.impl.pb.ContainerStatusPBImpl;
|
|
import org.apache.hadoop.yarn.api.records.impl.pb.NodeHealthStatusPBImpl;
|
|
import org.apache.hadoop.yarn.api.records.impl.pb.NodeHealthStatusPBImpl;
|
|
import org.apache.hadoop.yarn.api.records.impl.pb.NodeIdPBImpl;
|
|
import org.apache.hadoop.yarn.api.records.impl.pb.NodeIdPBImpl;
|
|
|
|
+import org.apache.hadoop.yarn.proto.YarnProtos.ApplicationIdProto;
|
|
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerStatusProto;
|
|
import org.apache.hadoop.yarn.proto.YarnProtos.ContainerStatusProto;
|
|
import org.apache.hadoop.yarn.proto.YarnProtos.NodeHealthStatusProto;
|
|
import org.apache.hadoop.yarn.proto.YarnProtos.NodeHealthStatusProto;
|
|
import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdProto;
|
|
import org.apache.hadoop.yarn.proto.YarnProtos.NodeIdProto;
|
|
@@ -37,7 +40,9 @@ import org.apache.hadoop.yarn.proto.YarnServerCommonProtos.NodeStatusProto;
|
|
import org.apache.hadoop.yarn.proto.YarnServerCommonProtos.NodeStatusProtoOrBuilder;
|
|
import org.apache.hadoop.yarn.proto.YarnServerCommonProtos.NodeStatusProtoOrBuilder;
|
|
import org.apache.hadoop.yarn.server.api.records.NodeStatus;
|
|
import org.apache.hadoop.yarn.server.api.records.NodeStatus;
|
|
|
|
|
|
-public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements NodeStatus {
|
|
|
|
|
|
+
|
|
|
|
+public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements
|
|
|
|
+ NodeStatus {
|
|
NodeStatusProto proto = NodeStatusProto.getDefaultInstance();
|
|
NodeStatusProto proto = NodeStatusProto.getDefaultInstance();
|
|
NodeStatusProto.Builder builder = null;
|
|
NodeStatusProto.Builder builder = null;
|
|
boolean viaProto = false;
|
|
boolean viaProto = false;
|
|
@@ -45,6 +50,7 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
private NodeId nodeId = null;
|
|
private NodeId nodeId = null;
|
|
private List<ContainerStatus> containers = null;
|
|
private List<ContainerStatus> containers = null;
|
|
private NodeHealthStatus nodeHealthStatus = null;
|
|
private NodeHealthStatus nodeHealthStatus = null;
|
|
|
|
+ private List<ApplicationId> keepAliveApplications = null;
|
|
|
|
|
|
public NodeStatusPBImpl() {
|
|
public NodeStatusPBImpl() {
|
|
builder = NodeStatusProto.newBuilder();
|
|
builder = NodeStatusProto.newBuilder();
|
|
@@ -55,15 +61,14 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
viaProto = true;
|
|
viaProto = true;
|
|
}
|
|
}
|
|
|
|
|
|
- public NodeStatusProto getProto() {
|
|
|
|
-
|
|
|
|
- mergeLocalToProto();
|
|
|
|
|
|
+ public synchronized NodeStatusProto getProto() {
|
|
|
|
+ mergeLocalToProto();
|
|
proto = viaProto ? proto : builder.build();
|
|
proto = viaProto ? proto : builder.build();
|
|
viaProto = true;
|
|
viaProto = true;
|
|
return proto;
|
|
return proto;
|
|
}
|
|
}
|
|
|
|
|
|
- private void mergeLocalToBuilder() {
|
|
|
|
|
|
+ private synchronized void mergeLocalToBuilder() {
|
|
if (this.nodeId != null) {
|
|
if (this.nodeId != null) {
|
|
builder.setNodeId(convertToProtoFormat(this.nodeId));
|
|
builder.setNodeId(convertToProtoFormat(this.nodeId));
|
|
}
|
|
}
|
|
@@ -73,9 +78,12 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
if (this.nodeHealthStatus != null) {
|
|
if (this.nodeHealthStatus != null) {
|
|
builder.setNodeHealthStatus(convertToProtoFormat(this.nodeHealthStatus));
|
|
builder.setNodeHealthStatus(convertToProtoFormat(this.nodeHealthStatus));
|
|
}
|
|
}
|
|
|
|
+ if (this.keepAliveApplications != null) {
|
|
|
|
+ addKeepAliveApplicationsToProto();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- private void mergeLocalToProto() {
|
|
|
|
|
|
+ private synchronized void mergeLocalToProto() {
|
|
if (viaProto)
|
|
if (viaProto)
|
|
maybeInitBuilder();
|
|
maybeInitBuilder();
|
|
mergeLocalToBuilder();
|
|
mergeLocalToBuilder();
|
|
@@ -84,14 +92,14 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
viaProto = true;
|
|
viaProto = true;
|
|
}
|
|
}
|
|
|
|
|
|
- private void maybeInitBuilder() {
|
|
|
|
|
|
+ private synchronized void maybeInitBuilder() {
|
|
if (viaProto || builder == null) {
|
|
if (viaProto || builder == null) {
|
|
builder = NodeStatusProto.newBuilder(proto);
|
|
builder = NodeStatusProto.newBuilder(proto);
|
|
}
|
|
}
|
|
viaProto = false;
|
|
viaProto = false;
|
|
}
|
|
}
|
|
|
|
|
|
- private void addContainersToProto() {
|
|
|
|
|
|
+ private synchronized void addContainersToProto() {
|
|
maybeInitBuilder();
|
|
maybeInitBuilder();
|
|
builder.clearContainersStatuses();
|
|
builder.clearContainersStatuses();
|
|
if (containers == null)
|
|
if (containers == null)
|
|
@@ -124,19 +132,53 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
};
|
|
};
|
|
builder.addAllContainersStatuses(iterable);
|
|
builder.addAllContainersStatuses(iterable);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private synchronized void addKeepAliveApplicationsToProto() {
|
|
|
|
+ maybeInitBuilder();
|
|
|
|
+ builder.clearKeepAliveApplications();
|
|
|
|
+ if (keepAliveApplications == null)
|
|
|
|
+ return;
|
|
|
|
+ Iterable<ApplicationIdProto> iterable = new Iterable<ApplicationIdProto>() {
|
|
|
|
+ @Override
|
|
|
|
+ public Iterator<ApplicationIdProto> iterator() {
|
|
|
|
+ return new Iterator<ApplicationIdProto>() {
|
|
|
|
+
|
|
|
|
+ Iterator<ApplicationId> iter = keepAliveApplications.iterator();
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean hasNext() {
|
|
|
|
+ return iter.hasNext();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public ApplicationIdProto next() {
|
|
|
|
+ return convertToProtoFormat(iter.next());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void remove() {
|
|
|
|
+ throw new UnsupportedOperationException();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ builder.addAllKeepAliveApplications(iterable);
|
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public int getResponseId() {
|
|
|
|
|
|
+ public synchronized int getResponseId() {
|
|
NodeStatusProtoOrBuilder p = viaProto ? proto : builder;
|
|
NodeStatusProtoOrBuilder p = viaProto ? proto : builder;
|
|
return p.getResponseId();
|
|
return p.getResponseId();
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
- public void setResponseId(int responseId) {
|
|
|
|
|
|
+ public synchronized void setResponseId(int responseId) {
|
|
maybeInitBuilder();
|
|
maybeInitBuilder();
|
|
builder.setResponseId(responseId);
|
|
builder.setResponseId(responseId);
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
- public NodeId getNodeId() {
|
|
|
|
|
|
+ public synchronized NodeId getNodeId() {
|
|
NodeStatusProtoOrBuilder p = viaProto ? proto : builder;
|
|
NodeStatusProtoOrBuilder p = viaProto ? proto : builder;
|
|
if (this.nodeId != null) {
|
|
if (this.nodeId != null) {
|
|
return this.nodeId;
|
|
return this.nodeId;
|
|
@@ -148,8 +190,9 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
|
|
|
|
return this.nodeId;
|
|
return this.nodeId;
|
|
}
|
|
}
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public void setNodeId(NodeId nodeId) {
|
|
|
|
|
|
+ public synchronized void setNodeId(NodeId nodeId) {
|
|
maybeInitBuilder();
|
|
maybeInitBuilder();
|
|
if (nodeId == null)
|
|
if (nodeId == null)
|
|
builder.clearNodeId();
|
|
builder.clearNodeId();
|
|
@@ -158,20 +201,35 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public List<ContainerStatus> getContainersStatuses() {
|
|
|
|
|
|
+ public synchronized List<ContainerStatus> getContainersStatuses() {
|
|
initContainers();
|
|
initContainers();
|
|
return this.containers;
|
|
return this.containers;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void setContainersStatuses(List<ContainerStatus> containers) {
|
|
|
|
|
|
+ public synchronized void setContainersStatuses(
|
|
|
|
+ List<ContainerStatus> containers) {
|
|
if (containers == null) {
|
|
if (containers == null) {
|
|
builder.clearContainersStatuses();
|
|
builder.clearContainersStatuses();
|
|
}
|
|
}
|
|
this.containers = containers;
|
|
this.containers = containers;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public synchronized List<ApplicationId> getKeepAliveApplications() {
|
|
|
|
+ initKeepAliveApplications();
|
|
|
|
+ return this.keepAliveApplications;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public synchronized void setKeepAliveApplications(List<ApplicationId> appIds) {
|
|
|
|
+ if (appIds == null) {
|
|
|
|
+ builder.clearKeepAliveApplications();
|
|
|
|
+ }
|
|
|
|
+ this.keepAliveApplications = appIds;
|
|
|
|
+ }
|
|
|
|
|
|
- private void initContainers() {
|
|
|
|
|
|
+ private synchronized void initContainers() {
|
|
if (this.containers != null) {
|
|
if (this.containers != null) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -185,8 +243,22 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private synchronized void initKeepAliveApplications() {
|
|
|
|
+ if (this.keepAliveApplications != null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ NodeStatusProtoOrBuilder p = viaProto ? proto : builder;
|
|
|
|
+ List<ApplicationIdProto> list = p.getKeepAliveApplicationsList();
|
|
|
|
+ this.keepAliveApplications = new ArrayList<ApplicationId>();
|
|
|
|
+
|
|
|
|
+ for (ApplicationIdProto c : list) {
|
|
|
|
+ this.keepAliveApplications.add(convertFromProtoFormat(c));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public NodeHealthStatus getNodeHealthStatus() {
|
|
|
|
|
|
+ public synchronized NodeHealthStatus getNodeHealthStatus() {
|
|
NodeStatusProtoOrBuilder p = viaProto ? proto : builder;
|
|
NodeStatusProtoOrBuilder p = viaProto ? proto : builder;
|
|
if (nodeHealthStatus != null) {
|
|
if (nodeHealthStatus != null) {
|
|
return nodeHealthStatus;
|
|
return nodeHealthStatus;
|
|
@@ -199,7 +271,7 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void setNodeHealthStatus(NodeHealthStatus healthStatus) {
|
|
|
|
|
|
+ public synchronized void setNodeHealthStatus(NodeHealthStatus healthStatus) {
|
|
maybeInitBuilder();
|
|
maybeInitBuilder();
|
|
if (healthStatus == null) {
|
|
if (healthStatus == null) {
|
|
builder.clearNodeHealthStatus();
|
|
builder.clearNodeHealthStatus();
|
|
@@ -231,4 +303,12 @@ public class NodeStatusPBImpl extends ProtoBase<NodeStatusProto> implements Node
|
|
private ContainerStatusProto convertToProtoFormat(ContainerStatus c) {
|
|
private ContainerStatusProto convertToProtoFormat(ContainerStatus c) {
|
|
return ((ContainerStatusPBImpl)c).getProto();
|
|
return ((ContainerStatusPBImpl)c).getProto();
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+ private ApplicationIdPBImpl convertFromProtoFormat(ApplicationIdProto c) {
|
|
|
|
+ return new ApplicationIdPBImpl(c);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private ApplicationIdProto convertToProtoFormat(ApplicationId c) {
|
|
|
|
+ return ((ApplicationIdPBImpl)c).getProto();
|
|
|
|
+ }
|
|
|
|
+}
|