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 * A response object used in deserialization when querying
030 * the Resource Manager for an application 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 ApplicationResponse {
036
037  private static final String APPLICATION_RESPONSE = "applicationResponse";
038  private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
039
040  private ApplicationState app;
041
042  @JsonProperty(Constants.APP)
043  public ApplicationState getApp() {
044    return this.app;
045  }
046
047  public void setApp(final ApplicationState app) {
048    this.app = app;
049  }
050
051  public ApplicationState getApplicationState() {
052    return app;
053  }
054
055  @Override
056  public String toString() {
057    final StringWriter writer = new StringWriter();
058    final String objectString;
059    try {
060      OBJECT_MAPPER.writeValue(writer, this);
061      objectString = writer.toString();
062    } catch (final IOException e) {
063      throw new RuntimeException("Exception while serializing ApplicationResponse: " + e);
064    }
065
066    return APPLICATION_RESPONSE + objectString;
067  }
068}