Example usage for org.apache.hadoop.yarn.webapp NotFoundException NotFoundException

List of usage examples for org.apache.hadoop.yarn.webapp NotFoundException NotFoundException

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.webapp NotFoundException NotFoundException.

Prototype

public NotFoundException(String msg) 

Source Link

Usage

From source file:com.datatorrent.stram.StreamingContainerManager.java

License:Apache License

private StreamingContainerAgent getContainerAgentFromOperatorId(int operatorId) {
    PTOperator oper = plan.getAllOperators().get(operatorId);
    if (oper != null) {
        StreamingContainerAgent sca = containers.get(oper.getContainer().getExternalId());
        if (sca != null) {
            return sca;
        }//from   www.j a  v  a  2  s  . c om
    }
    // throw exception that propagates to web client
    throw new NotFoundException("Operator ID " + operatorId + " not found");
}

From source file:org.apache.slider.core.restclient.UrlConnectionOperations.java

License:Apache License

/**
 * Uprate error codes 400 and up into faults; 
 * 404 is converted to a {@link NotFoundException},
 * 401 to {@link ForbiddenException}//from  w w  w .  j a v a  2  s.  c  o m
 *
 * @param verb HTTP Verb used
 * @param url URL as string
 * @param resultCode response from the request
 * @param bodyAsString
 *@param body optional body of the request  @throws IOException if the result was considered a failure
 */
public static void uprateFaults(HttpVerb verb, String url, int resultCode, String bodyAsString, byte[] body)
        throws IOException {

    if (resultCode < 400) {
        //success
        return;
    }
    String msg = verb.toString() + " " + url;
    if (resultCode == 404) {
        throw new NotFoundException(msg);
    }
    if (resultCode == 401) {
        throw new ForbiddenException(msg);
    }
    // all other error codes

    // get a string respnse
    if (bodyAsString == null) {
        if (body != null && body.length > 0) {
            bodyAsString = new String(body);
        } else {
            bodyAsString = "";
        }
    }
    String message = msg + " failed with exit code " + resultCode + ", body length " + bodyAsString.length()
            + ":\n" + bodyAsString;
    log.error(message);
    throw new IOException(message);
}

From source file:org.apache.slider.server.appmaster.web.rest.AbstractSliderResource.java

License:Apache License

/**
 * Convert any exception caught into a web application
 * exception for rethrowing/*from www.  j av a  2 s .  c om*/
 * @param path path of request
 * @param ex exception
 * @return an exception to throw
 */
public WebApplicationException buildException(String path, Exception ex) {
    try {
        throw ex;
    } catch (WebApplicationException e) {
        // rethrow direct
        throw e;
    } catch (FileNotFoundException e) {
        return new NotFoundException("Not found: " + path);
    } catch (PathNotFoundException e) {
        return new NotFoundException("Not found: " + path);
    } catch (AuthenticationFailedException e) {
        return new ForbiddenException(path);
    } catch (NoPathPermissionsException e) {
        return new ForbiddenException(path);
    } catch (Exception e) {
        log.error("Error during generation of response: {}", e, e);
        return new WebApplicationException(e);
    }
}

From source file:org.apache.slider.server.appmaster.web.rest.application.ApplicationResource.java

License:Apache License

@GET
@Path(LIVE_CONTAINERS + "/{containerId}")
@Produces({ APPLICATION_JSON })// w  w w  .j ava2 s . com
public ContainerInformation getLiveContainer(@PathParam("containerId") String containerId) {
    markGet(SLIDER_SUBPATH_APPLICATION, LIVE_CONTAINERS);
    try {
        RoleInstance id = state.getLiveInstanceByContainerID(containerId);
        return id.serialize();
    } catch (NoSuchNodeException e) {
        throw new NotFoundException("Unknown container: " + containerId);
    } catch (Exception e) {
        throw buildException(LIVE_CONTAINERS + "/" + containerId, e);
    }
}

From source file:org.apache.slider.server.appmaster.web.rest.application.ApplicationResource.java

License:Apache License

@GET
@Path(LIVE_COMPONENTS + "/{component}")
@Produces({ APPLICATION_JSON })/*w ww.  ja  v  a 2  s . co  m*/
public ComponentInformation getLiveComponent(@PathParam("component") String component) {
    markGet(SLIDER_SUBPATH_APPLICATION, LIVE_COMPONENTS);
    try {
        return state.getComponentInformation(component);
    } catch (YarnRuntimeException e) {
        throw new NotFoundException("Unknown component: " + component);
    } catch (Exception e) {
        throw buildException(LIVE_CONTAINERS + "/" + component, e);
    }
}

From source file:org.apache.slider.server.appmaster.web.rest.application.ApplicationResource.java

License:Apache License

@GET
@Path(LIVE_NODES + "/{hostname}")
@Produces({ APPLICATION_JSON })//ww w .ja v a  2  s  .  com
public NodeInformation getLiveNode(@PathParam("hostname") String hostname) {
    markGet(SLIDER_SUBPATH_APPLICATION, LIVE_COMPONENTS);
    try {
        NodeInformation ni = state.getNodeInformation(hostname);
        if (ni != null) {
            return ni;
        } else {
            throw new NotFoundException("Unknown node: " + hostname);
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw buildException(LIVE_COMPONENTS + "/" + hostname, e);
    }
}

From source file:org.apache.slider.server.appmaster.web.rest.publisher.PublisherResource.java

License:Apache License

/**
 * Get a named config set //  w ww . j  av a 2  s.  co m
 * @param setname name of the config set
 * @return the config set
 * @throws NotFoundException if there was no matching set
 */
private PublishedConfigSet getConfigSet(String setname) {
    PublishedConfigSet configSet = appState.getPublishedConfigSet(setname);
    if (configSet == null) {
        throw new NotFoundException("Not found: " + setname);
    }
    return configSet;
}

From source file:org.apache.slider.server.appmaster.web.rest.publisher.PublisherResource.java

License:Apache License

@GET
@Path("/" + CONFIG)
@Produces({ MediaType.APPLICATION_JSON })
public PublishedConfiguration getConfigurationInstance(@PathParam("setname") String setname,
        @PathParam("config") String config, @Context UriInfo uriInfo, @Context HttpServletResponse res) {
    init(res, uriInfo);//from   ww  w  . j a  va2 s  . c  o  m

    PublishedConfiguration publishedConfig = getPublishedConfiguration(setname, config);
    if (publishedConfig == null) {
        log.info("Configuration {} not found", config);
        throw new NotFoundException("Not found: " + uriInfo.getAbsolutePath());
    }
    return publishedConfig;
}

From source file:org.apache.slider.server.appmaster.web.rest.publisher.PublisherResource.java

License:Apache License

@GET
@Path("/" + CONFIG + "/{propertyName}")
@Produces({ MediaType.APPLICATION_JSON })
public Map<String, String> getConfigurationProperty(@PathParam("setname") String setname,
        @PathParam("config") String config, @PathParam("propertyName") String propertyName,
        @Context UriInfo uriInfo, @Context HttpServletResponse res) {
    PublishedConfiguration publishedConfig = getConfigurationInstance(setname, config, uriInfo, res);
    String propVal = publishedConfig.entries.get(propertyName);
    if (propVal == null) {
        log.debug("Configuration property {} not found in configuration {}", propertyName, config);
        throw new NotFoundException("Property not found: " + propertyName);
    }//from   ww  w .ja v a 2  s. c o m
    Map<String, String> rtnVal = new HashMap<String, String>();
    rtnVal.put(propertyName, propVal);

    return rtnVal;
}

From source file:org.apache.slider.server.appmaster.web.rest.registry.RegistryResource.java

License:Apache License

/**
 * Do the actual processing of requests to responses; can be directly
 * invoked for testing.//  w  w  w  .j  a  v  a  2  s  . com
 * @param path path to query
 * @return the entry
 * @throws WebApplicationException on any failure.
 */
public PathEntryResource resolvePath(String path) throws WebApplicationException {
    try {
        PathEntryResource pathEntry = fromRegistry(path);
        if (log.isDebugEnabled()) {
            log.debug("Resolved:\n{}", pathEntry);
        }
        return pathEntry;
    } catch (WebApplicationException e) {
        // rethrow direct
        throw e;
    } catch (PathNotFoundException e) {
        throw new NotFoundException("Not found: " + path);
    } catch (AuthenticationFailedException e) {
        throw new ForbiddenException(path);
    } catch (NoPathPermissionsException e) {
        throw new ForbiddenException(path);
    } catch (Exception e) {
        log.error("Error during generation of response: {}", e, e);
        throw new WebApplicationException(e);
    }
}