1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package org.apache.hadoop.yarn.server.api.records.impl.pb; 20 21 import org.apache.hadoop.yarn.proto.YarnServerCommonProtos.NodeHealthStatusProto; 22 import org.apache.hadoop.yarn.proto.YarnServerCommonProtos.NodeHealthStatusProtoOrBuilder; 23 import org.apache.hadoop.yarn.server.api.records.NodeHealthStatus; 24 25 import com.google.protobuf.TextFormat; 26 27 public class NodeHealthStatusPBImpl extends NodeHealthStatus { 28 29 private NodeHealthStatusProto.Builder builder; 30 private boolean viaProto = false; 31 private NodeHealthStatusProto proto = NodeHealthStatusProto 32 .getDefaultInstance(); 33 NodeHealthStatusPBImpl()34 public NodeHealthStatusPBImpl() { 35 this.builder = NodeHealthStatusProto.newBuilder(); 36 } 37 NodeHealthStatusPBImpl(NodeHealthStatusProto proto)38 public NodeHealthStatusPBImpl(NodeHealthStatusProto proto) { 39 this.proto = proto; 40 this.viaProto = true; 41 } 42 getProto()43 public NodeHealthStatusProto getProto() { 44 mergeLocalToProto(); 45 this.proto = this.viaProto ? this.proto : this.builder.build(); 46 this.viaProto = true; 47 return this.proto; 48 } 49 50 @Override hashCode()51 public int hashCode() { 52 return getProto().hashCode(); 53 } 54 55 @Override equals(Object other)56 public boolean equals(Object other) { 57 if (other == null) 58 return false; 59 if (other.getClass().isAssignableFrom(this.getClass())) { 60 return this.getProto().equals(this.getClass().cast(other).getProto()); 61 } 62 return false; 63 } 64 65 @Override toString()66 public String toString() { 67 return TextFormat.shortDebugString(getProto()); 68 } 69 mergeLocalToProto()70 private void mergeLocalToProto() { 71 if (this.viaProto) 72 maybeInitBuilder(); 73 this.proto = this.builder.build(); 74 75 this.viaProto = true; 76 } 77 maybeInitBuilder()78 private void maybeInitBuilder() { 79 if (this.viaProto || this.builder == null) { 80 this.builder = NodeHealthStatusProto.newBuilder(this.proto); 81 } 82 this.viaProto = false; 83 } 84 85 @Override getIsNodeHealthy()86 public boolean getIsNodeHealthy() { 87 NodeHealthStatusProtoOrBuilder p = 88 this.viaProto ? this.proto : this.builder; 89 return p.getIsNodeHealthy(); 90 } 91 92 @Override setIsNodeHealthy(boolean isNodeHealthy)93 public void setIsNodeHealthy(boolean isNodeHealthy) { 94 maybeInitBuilder(); 95 this.builder.setIsNodeHealthy(isNodeHealthy); 96 } 97 98 @Override getHealthReport()99 public String getHealthReport() { 100 NodeHealthStatusProtoOrBuilder p = 101 this.viaProto ? this.proto : this.builder; 102 if (!p.hasHealthReport()) { 103 return null; 104 } 105 return (p.getHealthReport()); 106 } 107 108 @Override setHealthReport(String healthReport)109 public void setHealthReport(String healthReport) { 110 maybeInitBuilder(); 111 if (healthReport == null) { 112 this.builder.clearHealthReport(); 113 return; 114 } 115 this.builder.setHealthReport((healthReport)); 116 } 117 118 @Override getLastHealthReportTime()119 public long getLastHealthReportTime() { 120 NodeHealthStatusProtoOrBuilder p = 121 this.viaProto ? this.proto : this.builder; 122 return (p.getLastHealthReportTime()); 123 } 124 125 @Override setLastHealthReportTime(long lastHealthReport)126 public void setLastHealthReportTime(long lastHealthReport) { 127 maybeInitBuilder(); 128 this.builder.setLastHealthReportTime((lastHealthReport)); 129 } 130 131 } 132