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.yarn.driver; 020 021import org.apache.hadoop.fs.Path; 022import org.apache.reef.runtime.common.files.REEFFileNames; 023import org.apache.reef.runtime.yarn.driver.parameters.JobSubmissionDirectoryPrefix; 024import org.apache.reef.tang.annotations.Parameter; 025 026import javax.inject.Inject; 027import java.text.SimpleDateFormat; 028import java.util.Calendar; 029 030/** 031 * Default implementation of JobSubmissionDirectoryProvider. 032 * Constructs path to job submission directory based on current date and time and applicationId. 033 */ 034public final class JobSubmissionDirectoryProviderImpl implements JobSubmissionDirectoryProvider { 035 036 /** 037 * The path on (H)DFS which is used as the job's folder. 038 */ 039 private final String jobSubmissionDirectory; 040 private final REEFFileNames fileNames; 041 042 @Inject 043 JobSubmissionDirectoryProviderImpl(@Parameter(JobSubmissionDirectoryPrefix.class) 044 final String jobSubmissionDirectoryPrefix, 045 final REEFFileNames fileNames) { 046 this.jobSubmissionDirectory = jobSubmissionDirectoryPrefix; 047 this.fileNames = fileNames; 048 } 049 050 @Override 051 public Path getJobSubmissionDirectoryPath(final String applicationId) { 052 return new Path(this.jobSubmissionDirectory + 053 "/" + 054 new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_").format(Calendar.getInstance().getTime()) + 055 this.fileNames.getJobFolderPrefix() + 056 applicationId + 057 "/"); 058 } 059}