org.apache.tez.common.TezConverterUtils.java Source code

Java tutorial

Introduction

Here is the source code for org.apache.tez.common.TezConverterUtils.java

Source

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.tez.common;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.yarn.api.records.LocalResource;
import org.apache.hadoop.yarn.api.records.URL;

public class TezConverterUtils {

    /**
     * return a {@link URI} from a given url
     * 
     * @param url
     *          url to convert
     * @return path from {@link URL}
     * @throws URISyntaxException
     */
    @Private
    public static URI getURIFromYarnURL(URL url) throws URISyntaxException {
        String scheme = url.getScheme() == null ? "" : url.getScheme();

        String authority = "";
        if (url.getHost() != null) {
            authority = url.getHost();
            if (url.getUserInfo() != null) {
                authority = url.getUserInfo() + "@" + authority;
            }
            if (url.getPort() > 0) {
                authority += ":" + url.getPort();
            }
        }

        return new URI(scheme, authority, url.getFile(), null, null).normalize();
    }

    @Private
    public static TezLocalResource convertYarnLocalResourceToTez(LocalResource lr) throws URISyntaxException {
        return new TezLocalResource(getURIFromYarnURL(lr.getResource()), lr.getSize(), lr.getTimestamp());
    }

    // @Private
    // public static void writeLocalResource(LocalResource lr, DataOutput out)
    // throws IOException {
    // // Not bothering with type, visibility and pattern. Pattern may be needed
    // at
    // // some point.
    // // Size and length will not be required once Localization happens via YARN
    // -
    // // yarn takes care of validation, original file as well for that matter.
    // writeYARNURL(lr.getResource(), out);
    // out.writeLong(lr.getSize());
    // out.writeLong(lr.getTimestamp());
    // }
    //
    // @Private
    // public static LocalResource readLocalResource(DataInput in) throws
    // IOException {
    // return LocalResource.newInstance(readYARNURL(in), null, null,
    // in.readLong(), in.readLong());
    // }
    //
    // @Private
    // public static void writeYARNURL(URL url, DataOutput out) throws IOException
    // {
    // // Assuming all fields have to be present. Otherwise YARN itself would
    // fail.
    // out.writeUTF(url.getScheme());
    // out.writeUTF(url.getHost());
    // out.writeInt(url.getPort());
    // out.writeUTF(url.getFile());
    // }
    //
    // @Private
    // public static URL readYARNURL(DataInput in) throws IOException {
    // URL url = URL.newInstance(in.readUTF(), in.readUTF(), in.readInt(),
    // in.readUTF());
    // return url;
    // }

}