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 021 022import java.util.ArrayList; 023import java.util.HashMap; 024import java.util.List; 025import java.util.Map; 026 027/** 028 * Represents a ContainerInfo in the YARN REST APIs. 029 */ 030public final class ContainerInfo { 031 032 public static final String DEFAULT_SERVICE_DATA = null; 033 private String serviceData = DEFAULT_SERVICE_DATA; 034 035 public static final String DEFAULT_TOKENS = ""; 036 private String tokens = DEFAULT_TOKENS; 037 038 public static final String DEFAULT_ACLS = null; 039 private String acls = DEFAULT_ACLS; 040 041 private List<String> commands = new ArrayList<>(); 042 private Map<String, EnvironmentEntry> environment = new HashMap<>(); 043 private Map<String, LocalResourcesEntry> localResources = new HashMap<>(); 044 045 /** 046 * Adds an environment variable. 047 * 048 * @param key the name of the variable 049 * @param value the value it shall take 050 * @return this 051 */ 052 public ContainerInfo addEnvironment(final String key, final String value) { 053 this.environment.put("entry", new EnvironmentEntry(key, value)); 054 return this; 055 } 056 057 /** 058 * Adds a command to the command list to be executed 059 * 060 * @param command 061 * @return this 062 */ 063 public ContainerInfo addCommand(final String command) { 064 this.commands.add(command); 065 return this; 066 } 067 068 public ContainerInfo addFileResource(final String key, final FileResource fileResource) { 069 this.localResources.put("entry", new LocalResourcesEntry(key, fileResource)); 070 return this; 071 } 072 073 public String getServiceData() { 074 return this.serviceData; 075 } 076 077 public ContainerInfo setServiceData(final String serviceData) { 078 this.serviceData = serviceData; 079 return this; 080 } 081 082 public String getTokens() { 083 return this.tokens; 084 } 085 086 public ContainerInfo setTokens(final String tokens) { 087 this.tokens = tokens; 088 return this; 089 } 090 091 public String getAcls() { 092 return this.acls; 093 } 094 095 public ContainerInfo setAcls(final String acls) { 096 this.acls = acls; 097 return this; 098 } 099 100 public Map<String, EnvironmentEntry> getEnvironment() { 101 return this.environment; 102 } 103 104 public void setEnvironment(final Map<String, EnvironmentEntry> environment) { 105 this.environment = environment; 106 } 107 108 public List<String> getCommands() { 109 return this.commands; 110 } 111 112 public ContainerInfo setCommands(final List<String> commands) { 113 this.commands = commands; 114 return this; 115 } 116 117 public Map<String, LocalResourcesEntry> getLocalResources() { 118 return this.localResources; 119 } 120 121 public ContainerInfo setLocalResources(final Map<String, LocalResourcesEntry> localResources) { 122 this.localResources = localResources; 123 return this; 124 } 125}