Search in sources :

Example 36 with URISyntaxException

use of java.net.URISyntaxException in project hadoop by apache.

the class JobSubmitter method addMRFrameworkToDistributedCache.

@SuppressWarnings("deprecation")
private static void addMRFrameworkToDistributedCache(Configuration conf) throws IOException {
    String framework = conf.get(MRJobConfig.MAPREDUCE_APPLICATION_FRAMEWORK_PATH, "");
    if (!framework.isEmpty()) {
        URI uri;
        try {
            uri = new URI(framework);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("Unable to parse '" + framework + "' as a URI, check the setting for " + MRJobConfig.MAPREDUCE_APPLICATION_FRAMEWORK_PATH, e);
        }
        String linkedName = uri.getFragment();
        // resolve any symlinks in the URI path so using a "current" symlink
        // to point to a specific version shows the specific version
        // in the distributed cache configuration
        FileSystem fs = FileSystem.get(conf);
        Path frameworkPath = fs.makeQualified(new Path(uri.getScheme(), uri.getAuthority(), uri.getPath()));
        FileContext fc = FileContext.getFileContext(frameworkPath.toUri(), conf);
        frameworkPath = fc.resolvePath(frameworkPath);
        uri = frameworkPath.toUri();
        try {
            uri = new URI(uri.getScheme(), uri.getAuthority(), uri.getPath(), null, linkedName);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
        DistributedCache.addCacheArchive(uri, conf);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) FileContext(org.apache.hadoop.fs.FileContext)

Example 37 with URISyntaxException

use of java.net.URISyntaxException in project hadoop by apache.

the class SwiftRestClient method pathToObjectLocation.

/**
   * Create the URI needed to query the location of an object
   * @param path object path to retrieve information about
   * @return the URI for the location operation
   * @throws SwiftException if the URI could not be constructed
   */
private URI pathToObjectLocation(SwiftObjectPath path) throws SwiftException {
    URI uri;
    String dataLocationURI = objectLocationURI.toString();
    try {
        if (path.toString().startsWith("/")) {
            dataLocationURI = dataLocationURI.concat(path.toUriPath());
        } else {
            dataLocationURI = dataLocationURI.concat("/").concat(path.toUriPath());
        }
        uri = new URI(dataLocationURI);
    } catch (URISyntaxException e) {
        throw new SwiftException(e);
    }
    return uri;
}
Also used : SwiftException(org.apache.hadoop.fs.swift.exceptions.SwiftException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 38 with URISyntaxException

use of java.net.URISyntaxException in project hadoop by apache.

the class SwiftRestClient method findObjects.

/**
   * Find objects in a location
   * @param location URI
   * @param requestHeaders optional request headers
   * @return the body of te response
   * @throws IOException IO problems
   */
private byte[] findObjects(String location, final Header[] requestHeaders) throws IOException {
    URI uri;
    preRemoteCommand("findObjects");
    try {
        uri = new URI(location);
    } catch (URISyntaxException e) {
        throw new SwiftException("Bad URI: " + location, e);
    }
    return perform("findObjects", uri, new GetMethodProcessor<byte[]>() {

        @Override
        public byte[] extractResult(GetMethod method) throws IOException {
            if (method.getStatusCode() == SC_NOT_FOUND) {
                //no result
                throw new FileNotFoundException("Not found " + method.getURI());
            }
            return method.getResponseBody();
        }

        @Override
        protected int[] getAllowedStatusCodes() {
            return new int[] { SC_OK, SC_NOT_FOUND };
        }

        @Override
        protected void setup(GetMethod method) throws SwiftInternalStateException {
            setHeaders(method, requestHeaders);
        }
    });
}
Also used : SwiftInternalStateException(org.apache.hadoop.fs.swift.exceptions.SwiftInternalStateException) GetMethod(org.apache.commons.httpclient.methods.GetMethod) FileNotFoundException(java.io.FileNotFoundException) SwiftException(org.apache.hadoop.fs.swift.exceptions.SwiftException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI)

Example 39 with URISyntaxException

use of java.net.URISyntaxException in project hadoop by apache.

the class WebAppProxyServlet method methodAction.

/**
   * The action against the HTTP method.
   * @param req the HttpServletRequest
   * @param resp the HttpServletResponse
   * @param method the HTTP method
   * @throws ServletException
   * @throws IOException
   */
private void methodAction(final HttpServletRequest req, final HttpServletResponse resp, final HTTP method) throws ServletException, IOException {
    try {
        String userApprovedParamS = req.getParameter(ProxyUriUtils.PROXY_APPROVAL_PARAM);
        boolean userWasWarned = false;
        boolean userApproved = Boolean.parseBoolean(userApprovedParamS);
        boolean securityEnabled = isSecurityEnabled();
        boolean isRedirect = false;
        String pathInfo = req.getPathInfo();
        final String remoteUser = req.getRemoteUser();
        String[] parts = null;
        if (pathInfo != null) {
            // parsed
            if (pathInfo.startsWith(REDIRECT)) {
                pathInfo = pathInfo.substring(REDIRECT.length());
                isRedirect = true;
            }
            parts = pathInfo.split("/", 3);
        }
        if ((parts == null) || (parts.length < 2)) {
            LOG.warn("{} gave an invalid proxy path {}", remoteUser, pathInfo);
            notFound(resp, "Your path appears to be formatted incorrectly.");
            return;
        }
        //parts[0] is empty because path info always starts with a /
        String appId = parts[1];
        String rest = parts.length > 2 ? parts[2] : "";
        ApplicationId id = Apps.toAppID(appId);
        if (id == null) {
            LOG.warn("{} attempting to access {} that is invalid", remoteUser, appId);
            notFound(resp, appId + " appears to be formatted incorrectly.");
            return;
        }
        // already redirected the response, so we can just return.
        if (isRedirect && handleRedirect(appId, req, resp)) {
            return;
        }
        if (securityEnabled) {
            String cookieName = getCheckCookieName(id);
            Cookie[] cookies = req.getCookies();
            if (cookies != null) {
                for (Cookie c : cookies) {
                    if (cookieName.equals(c.getName())) {
                        userWasWarned = true;
                        userApproved = userApproved || Boolean.parseBoolean(c.getValue());
                        break;
                    }
                }
            }
        }
        boolean checkUser = securityEnabled && (!userWasWarned || !userApproved);
        FetchedAppReport fetchedAppReport;
        try {
            fetchedAppReport = getFetchedAppReport(id);
        } catch (ApplicationNotFoundException e) {
            fetchedAppReport = null;
        }
        ApplicationReport applicationReport = null;
        if (fetchedAppReport != null) {
            applicationReport = fetchedAppReport.getApplicationReport();
        }
        if (applicationReport == null) {
            LOG.warn("{} attempting to access {} that was not found", remoteUser, id);
            URI toFetch = ProxyUriUtils.getUriFromTrackingPlugins(id, this.trackingUriPlugins);
            if (toFetch != null) {
                ProxyUtils.sendRedirect(req, resp, toFetch.toString());
                return;
            }
            notFound(resp, "Application " + appId + " could not be found " + "in RM or history server");
            return;
        }
        URI trackingUri = getTrackingUri(req, resp, id, applicationReport.getOriginalTrackingUrl(), fetchedAppReport.getAppReportSource());
        // If the tracking URI is null, there was a redirect, so just return.
        if (trackingUri == null) {
            return;
        }
        String runningUser = applicationReport.getUser();
        if (checkUser && !runningUser.equals(remoteUser)) {
            LOG.info("Asking {} if they want to connect to the " + "app master GUI of {} owned by {}", remoteUser, appId, runningUser);
            warnUserPage(resp, ProxyUriUtils.getPathAndQuery(id, rest, req.getQueryString(), true), runningUser, id);
            return;
        }
        // Append the user-provided path and query parameter to the original
        // tracking url.
        URI toFetch = buildTrackingUrl(trackingUri, req, rest);
        LOG.info("{} is accessing unchecked {}" + " which is the app master GUI of {} owned by {}", remoteUser, toFetch, appId, runningUser);
        switch(applicationReport.getYarnApplicationState()) {
            case KILLED:
            case FINISHED:
            case FAILED:
                ProxyUtils.sendRedirect(req, resp, toFetch.toString());
                return;
            default:
        }
        Cookie c = null;
        if (userWasWarned && userApproved) {
            c = makeCheckCookie(id, true);
        }
        proxyLink(req, resp, toFetch, c, getProxyHost(), method);
    } catch (URISyntaxException | YarnException e) {
        throw new IOException(e);
    }
}
Also used : Cookie(javax.servlet.http.Cookie) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) FetchedAppReport(org.apache.hadoop.yarn.server.webproxy.AppReportFetcher.FetchedAppReport)

Example 40 with URISyntaxException

use of java.net.URISyntaxException in project hadoop by apache.

the class TestProxyUriUtils method testGetProxyUriFromPluginsReturnsValidUriWhenAble.

@Test
public void testGetProxyUriFromPluginsReturnsValidUriWhenAble() throws URISyntaxException {
    ApplicationId id = BuilderUtils.newApplicationId(6384623l, 5);
    List<TrackingUriPlugin> list = Lists.newArrayListWithExpectedSize(2);
    // Insert a plugin that returns null.
    list.add(new TrackingUriPlugin() {

        public URI getTrackingUri(ApplicationId id) throws URISyntaxException {
            return null;
        }
    });
    // Insert a plugin that returns a valid URI.
    list.add(new TrackingUriPlugin() {

        public URI getTrackingUri(ApplicationId id) throws URISyntaxException {
            return new URI("http://history.server.net/");
        }
    });
    URI result = ProxyUriUtils.getUriFromTrackingPlugins(id, list);
    assertNotNull(result);
}
Also used : URISyntaxException(java.net.URISyntaxException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) TrackingUriPlugin(org.apache.hadoop.yarn.util.TrackingUriPlugin) URI(java.net.URI) Test(org.junit.Test)

Aggregations

URISyntaxException (java.net.URISyntaxException)4043 URI (java.net.URI)2496 IOException (java.io.IOException)1273 File (java.io.File)716 URL (java.net.URL)702 ArrayList (java.util.ArrayList)407 Test (org.junit.Test)274 MalformedURLException (java.net.MalformedURLException)270 InputStream (java.io.InputStream)224 HashMap (java.util.HashMap)212 Response (javax.ws.rs.core.Response)194 Test (org.testng.annotations.Test)175 Parameters (org.testng.annotations.Parameters)166 Builder (javax.ws.rs.client.Invocation.Builder)165 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)165 Map (java.util.Map)162 StorageException (com.microsoft.azure.storage.StorageException)142 Path (java.nio.file.Path)141 URIBuilder (org.apache.http.client.utils.URIBuilder)140 List (java.util.List)125