private void mergeLocalToBuilder() { if (this.containerId != null) { builder.setContainerId(convertToProtoFormat(this.containerId)); } if (this.localResources != null) { addLocalResourcesToProto(); } }
@Override public Map<String, LocalResource> getLocalResources() { initLocalResources(); return this.localResources; }
private void mergeLocalToProto() { if (viaProto) { maybeInitBuilder(); } mergeLocalToBuilder(); proto = builder.build(); viaProto = true; }
@Override public ContainerId getContainerId() { YarnServiceProtos.ResourceLocalizationRequestProtoOrBuilder p = viaProto ? proto : builder; if (this.containerId != null) { return this.containerId; } if (!p.hasContainerId()) { return null; } this.containerId = convertFromProtoFormat(p.getContainerId()); return this.containerId; }
@Override public void setContainerId(ContainerId containerId) { maybeInitBuilder(); if (containerId == null) { builder.clearContainerId(); } this.containerId = containerId; }
public ResourceLocalizationRequestProto getProto() { mergeLocalToProto(); proto = viaProto ? proto : builder.build(); viaProto = true; return proto; }
@Override public ResourceLocalizationResponseProto localize(RpcController controller, ResourceLocalizationRequestProto proto) throws ServiceException { ResourceLocalizationRequestPBImpl request = new ResourceLocalizationRequestPBImpl(proto); try { ResourceLocalizationResponse response = real.localize(request); return ((ResourceLocalizationResponsePBImpl) response).getProto(); } catch (YarnException e) { throw new ServiceException(e); } catch (IOException e) { throw new ServiceException(e); } }
private void initLocalResources() { if (this.localResources != null) { return; } YarnServiceProtos.ResourceLocalizationRequestProtoOrBuilder p = viaProto ? proto : builder; List<YarnProtos.StringLocalResourceMapProto> list = p.getLocalResourcesList(); this.localResources = new HashMap<>(); for (YarnProtos.StringLocalResourceMapProto c : list) { this.localResources.put(c.getKey(), convertFromProtoFormat(c.getValue())); } }
private void addLocalResourcesToProto() { maybeInitBuilder(); builder.clearLocalResources(); if (localResources == null) { return; } Iterable<YarnProtos.StringLocalResourceMapProto> iterable = new Iterable<YarnProtos.StringLocalResourceMapProto>() { @Override public Iterator<YarnProtos.StringLocalResourceMapProto> iterator() { return new Iterator<YarnProtos.StringLocalResourceMapProto>() { Iterator<String> keyIter = localResources.keySet().iterator(); @Override public void remove() { throw new UnsupportedOperationException(); } @Override public YarnProtos.StringLocalResourceMapProto next() { String key = keyIter.next(); return YarnProtos.StringLocalResourceMapProto.newBuilder() .setKey(key). setValue(convertToProtoFormat(localResources.get(key))) .build(); } @Override public boolean hasNext() { return keyIter.hasNext(); } }; } }; builder.addAllLocalResources(iterable); }
@Override public int hashCode() { return getProto().hashCode(); }
@Override public String toString() { return TextFormat.shortDebugString(getProto()); }
@Override public ResourceLocalizationResponse localize( ResourceLocalizationRequest request) throws YarnException, IOException { ResourceLocalizationRequestProto requestProto = ((ResourceLocalizationRequestPBImpl) request).getProto(); try { return new ResourceLocalizationResponsePBImpl( proxy.localize(null, requestProto)); } catch (ServiceException e) { RPCUtil.unwrapAndThrowException(e); return null; } }