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.mapreduce.v2.api.protocolrecords.impl.pb; 20 21 22 import org.apache.hadoop.mapreduce.v2.api.protocolrecords.GetTaskReportsRequest; 23 import org.apache.hadoop.mapreduce.v2.api.records.JobId; 24 import org.apache.hadoop.mapreduce.v2.api.records.TaskType; 25 import org.apache.hadoop.mapreduce.v2.api.records.impl.pb.JobIdPBImpl; 26 import org.apache.hadoop.mapreduce.v2.proto.MRProtos.JobIdProto; 27 import org.apache.hadoop.mapreduce.v2.proto.MRProtos.TaskTypeProto; 28 import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.GetTaskReportsRequestProto; 29 import org.apache.hadoop.mapreduce.v2.proto.MRServiceProtos.GetTaskReportsRequestProtoOrBuilder; 30 import org.apache.hadoop.mapreduce.v2.util.MRProtoUtils; 31 import org.apache.hadoop.yarn.api.records.impl.pb.ProtoBase; 32 33 34 35 public class GetTaskReportsRequestPBImpl extends ProtoBase<GetTaskReportsRequestProto> implements GetTaskReportsRequest { 36 GetTaskReportsRequestProto proto = GetTaskReportsRequestProto.getDefaultInstance(); 37 GetTaskReportsRequestProto.Builder builder = null; 38 boolean viaProto = false; 39 40 private JobId jobId = null; 41 42 GetTaskReportsRequestPBImpl()43 public GetTaskReportsRequestPBImpl() { 44 builder = GetTaskReportsRequestProto.newBuilder(); 45 } 46 GetTaskReportsRequestPBImpl(GetTaskReportsRequestProto proto)47 public GetTaskReportsRequestPBImpl(GetTaskReportsRequestProto proto) { 48 this.proto = proto; 49 viaProto = true; 50 } 51 getProto()52 public GetTaskReportsRequestProto getProto() { 53 mergeLocalToProto(); 54 proto = viaProto ? proto : builder.build(); 55 viaProto = true; 56 return proto; 57 } 58 mergeLocalToBuilder()59 private void mergeLocalToBuilder() { 60 if (this.jobId != null) { 61 builder.setJobId(convertToProtoFormat(this.jobId)); 62 } 63 } 64 mergeLocalToProto()65 private void mergeLocalToProto() { 66 if (viaProto) 67 maybeInitBuilder(); 68 mergeLocalToBuilder(); 69 proto = builder.build(); 70 viaProto = true; 71 } 72 maybeInitBuilder()73 private void maybeInitBuilder() { 74 if (viaProto || builder == null) { 75 builder = GetTaskReportsRequestProto.newBuilder(proto); 76 } 77 viaProto = false; 78 } 79 80 81 @Override getJobId()82 public JobId getJobId() { 83 GetTaskReportsRequestProtoOrBuilder p = viaProto ? proto : builder; 84 if (this.jobId != null) { 85 return this.jobId; 86 } 87 if (!p.hasJobId()) { 88 return null; 89 } 90 this.jobId = convertFromProtoFormat(p.getJobId()); 91 return this.jobId; 92 } 93 94 @Override setJobId(JobId jobId)95 public void setJobId(JobId jobId) { 96 maybeInitBuilder(); 97 if (jobId == null) 98 builder.clearJobId(); 99 this.jobId = jobId; 100 } 101 @Override getTaskType()102 public TaskType getTaskType() { 103 GetTaskReportsRequestProtoOrBuilder p = viaProto ? proto : builder; 104 if (!p.hasTaskType()) { 105 return null; 106 } 107 return convertFromProtoFormat(p.getTaskType()); 108 } 109 110 @Override setTaskType(TaskType taskType)111 public void setTaskType(TaskType taskType) { 112 maybeInitBuilder(); 113 if (taskType == null) { 114 builder.clearTaskType(); 115 return; 116 } 117 builder.setTaskType(convertToProtoFormat(taskType)); 118 } 119 convertFromProtoFormat(JobIdProto p)120 private JobIdPBImpl convertFromProtoFormat(JobIdProto p) { 121 return new JobIdPBImpl(p); 122 } 123 convertToProtoFormat(JobId t)124 private JobIdProto convertToProtoFormat(JobId t) { 125 return ((JobIdPBImpl)t).getProto(); 126 } 127 convertToProtoFormat(TaskType e)128 private TaskTypeProto convertToProtoFormat(TaskType e) { 129 return MRProtoUtils.convertToProtoFormat(e); 130 } 131 convertFromProtoFormat(TaskTypeProto e)132 private TaskType convertFromProtoFormat(TaskTypeProto e) { 133 return MRProtoUtils.convertFromProtoFormat(e); 134 } 135 136 137 138 } 139