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; 023 024import java.io.IOException; 025import java.io.StringWriter; 026 027/** 028 * Represents a the details of a local resource used 029 * in an HDInsight job submission. 030 * For detailed information, please refer to 031 * https://hadoop.apache.org/docs/r2.6.0/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html 032 */ 033public final class LocalResource { 034 035 public static final String TYPE_FILE = "FILE"; 036 public static final String TYPE_ARCHIVE = "ARCHIVE"; 037 public static final String TYPE_PATTERN = "PATTERN"; 038 public static final String VISIBILITY_PUBLIC = "PUBLIC"; 039 public static final String VISIBILITY_PRIVATE = "PRIVATE"; 040 public static final String VISIBILITY_APPLICATION = "APPLICATION"; 041 private static final String LOCAL_RESOURCE = "localResource"; 042 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); 043 044 private String resource; 045 private String type; 046 private String visibility; 047 private long size; 048 private long timestamp; 049 050 @JsonProperty(Constants.RESOURCE) 051 public String getResource() { 052 return this.resource; 053 } 054 055 public LocalResource setResource(final String resource) { 056 this.resource = resource; 057 return this; 058 } 059 060 @JsonProperty(Constants.TYPE) 061 public String getType() { 062 return this.type; 063 } 064 065 public LocalResource setType(final String type) { 066 this.type = type; 067 return this; 068 } 069 070 @JsonProperty(Constants.VISIBILITY) 071 public String getVisibility() { 072 return this.visibility; 073 } 074 075 public LocalResource setVisibility(final String visibility) { 076 this.visibility = visibility; 077 return this; 078 } 079 080 @JsonProperty(Constants.SIZE) 081 public long getSize() { 082 return this.size; 083 } 084 085 public LocalResource setSize(final long size) { 086 this.size = size; 087 return this; 088 } 089 090 @JsonProperty(Constants.TIMESTAMP) 091 public long getTimestamp() { 092 return this.timestamp; 093 } 094 095 public LocalResource setTimestamp(final long timestamp) { 096 this.timestamp = timestamp; 097 return this; 098 } 099 100 @Override 101 public String toString() { 102 final StringWriter writer = new StringWriter(); 103 final String objectString; 104 try { 105 OBJECT_MAPPER.writeValue(writer, this); 106 objectString = writer.toString(); 107 } catch (final IOException e) { 108 throw new RuntimeException("Exception while serializing LocalResource: " + e); 109 } 110 111 return LOCAL_RESOURCE + objectString; 112 } 113}