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.JsonProperty; 022import org.codehaus.jackson.map.ObjectMapper; 023import org.codehaus.jackson.map.annotate.JsonSerialize; 024 025import java.io.IOException; 026import java.io.StringWriter; 027 028/** 029 * Commands used to start an Application Master via the 030 * YARN Resource Manger 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 */ 034public final class Commands { 035 036 public static final String DEFAULT_COMMAND = ""; 037 038 private static final String COMMANDS = "commands"; 039 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); 040 041 private String command = DEFAULT_COMMAND; 042 043 @JsonProperty(Constants.COMMAND) 044 @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY) 045 public String getCommand() { 046 return this.command; 047 } 048 049 public void setCommand(final String command) { 050 this.command = command; 051 } 052 053 @Override 054 public String toString() { 055 final StringWriter writer = new StringWriter(); 056 final String objectString; 057 try { 058 OBJECT_MAPPER.writeValue(writer, this); 059 objectString = writer.toString(); 060 } catch (final IOException e) { 061 throw new RuntimeException("Exception while serializing Commands: " + e); 062 } 063 064 return COMMANDS + objectString; 065 } 066}