001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.reef.runtime.hdinsight.client.yarnrest; 020 021import org.codehaus.jackson.annotate.JsonIgnoreProperties; 022import org.codehaus.jackson.annotate.JsonProperty; 023import org.codehaus.jackson.map.ObjectMapper; 024 025import java.io.IOException; 026import java.io.StringWriter; 027 028/** 029 * Represents the response to an application ID request to 030 * the YARN Resource Manager via the YARN REST API. 031 * For detailed information, please refer to 032 * https://hadoop.apache.org/docs/r2.6.0/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html 033 */ 034@JsonIgnoreProperties(ignoreUnknown = true) 035public final class ApplicationID { 036 037 private static final String APPLICATION_ID = "applicationId"; 038 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); 039 private String applicationId; 040 private Resource resource; 041 042 @JsonProperty(Constants.APPLICATION_ID) 043 public String getApplicationId() { 044 return applicationId; 045 } 046 047 public void setApplicationId(final String applicationId) { 048 this.applicationId = applicationId; 049 } 050 051 @JsonProperty(Constants.MAXIMUM_RESOURCE_CAPABILITY) 052 public Resource getResource() { 053 return resource; 054 } 055 056 public void setResource(final Resource resource) { 057 this.resource = resource; 058 } 059 060 @Override 061 public String toString() { 062 final StringWriter writer = new StringWriter(); 063 final String objectString; 064 try { 065 OBJECT_MAPPER.writeValue(writer, this); 066 objectString = writer.toString(); 067 } catch (final IOException e) { 068 throw new RuntimeException("Exception while serializing ApplicationID: " + e); 069 } 070 071 return APPLICATION_ID + objectString; 072 } 073}