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; 027import java.util.List; 028import java.util.Map; 029 030/** 031 * The data structure used to deserialize the REST response 032 * from a call to the Resource Manager to list applications. 033 * For detailed information, please refer to 034 * https://hadoop.apache.org/docs/r2.6.0/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html 035 */ 036@JsonIgnoreProperties(ignoreUnknown = true) 037public final class ListApplicationResponse { 038 039 private static final String LIST_APPLICATION_RESPONSE = "listApplicationResponse"; 040 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); 041 042 private Map<String, List<ApplicationState>> apps; 043 044 @JsonProperty(Constants.APPS) 045 public Map<String, List<ApplicationState>> getApps() { 046 return apps; 047 } 048 049 public void setApps(final Map<String, List<ApplicationState>> apps) { 050 this.apps = apps; 051 } 052 053 public List<ApplicationState> getApplicationStates() { 054 if (!this.apps.containsKey(Constants.APP)) { 055 return null; 056 } 057 return apps.get(Constants.APP); 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 ListApplicationResponse: " + e); 069 } 070 071 return LIST_APPLICATION_RESPONSE + objectString; 072 } 073}