private void validateStartTime() { if (startedTimeBegin < 0) { throw new BadRequestException("startedTimeBegin must be greater than 0"); } if (startedTimeEnd < 0) { throw new BadRequestException("startedTimeEnd must be greater than 0"); } if (startedTimeBegin > startedTimeEnd) { throw new BadRequestException( "startedTimeEnd must be greater than startTimeBegin"); } }
private void validateFinishTime() { if (finishTimeBegin < 0) { throw new BadRequestException("finishTimeBegin must be greater than 0"); } if (finishTimeEnd < 0) { throw new BadRequestException("finishTimeEnd must be greater than 0"); } if (finishTimeBegin > finishTimeEnd) { throw new BadRequestException( "finishTimeEnd must be greater than finishTimeBegin"); } }
private long parseLongValue(String strValue, String queryName) { try { return Long.parseLong(strValue); } catch (NumberFormatException e) { throw new BadRequestException(queryName + " value must be a number!"); } }
private Token<RMDelegationTokenIdentifier> extractToken( HttpServletRequest request) { String encodedToken = request.getHeader(DELEGATION_TOKEN_HEADER); if (encodedToken == null) { String msg = "Header '" + DELEGATION_TOKEN_HEADER + "' containing encoded token not found"; throw new BadRequestException(msg); } return extractToken(encodedToken); }
private Token<RMDelegationTokenIdentifier> extractToken( HttpServletRequest request) { String encodedToken = request.getHeader(DELEGATION_TOKEN_HEADER); if (encodedToken == null) { String msg = "Header '" + DELEGATION_TOKEN_HEADER + "' containing encoded token not found"; throw new BadRequestException(msg); } return extractToken(encodedToken); }
private void validateLimit() { if (limit != null) { limitNumber = parseLongValue(limit, "limit"); if (limitNumber <= 0) { throw new BadRequestException("limit value must be greater then 0"); } } }
private Token<RMDelegationTokenIdentifier> extractToken( HttpServletRequest request) { String encodedToken = request.getHeader(DELEGATION_TOKEN_HEADER); if (encodedToken == null) { String msg = "Header '" + DELEGATION_TOKEN_HEADER + "' containing encoded token not found"; throw new BadRequestException(msg); } return extractToken(encodedToken); }
private void validateQueueExists(ResourceManager rm, String queueQuery) { ResourceScheduler rs = rm.getResourceScheduler(); if (rs instanceof CapacityScheduler) { CapacityScheduler cs = (CapacityScheduler) rs; try { cs.getQueueInfo(queueQuery, false, false); } catch (IOException e) { throw new BadRequestException(e.getMessage()); } } }
private ApplicationTimeoutType parseTimeoutType(String type) { try { // enum string is in the uppercase return ApplicationTimeoutType .valueOf(StringUtils.toUpperCase(type.trim())); } catch (RuntimeException e) { ApplicationTimeoutType[] typeArray = ApplicationTimeoutType.values(); String allAppTimeoutTypes = Arrays.toString(typeArray); throw new BadRequestException("Invalid application-state " + type.trim() + " specified. It should be one of " + allAppTimeoutTypes); } }
private Token<RMDelegationTokenIdentifier> extractToken(String encodedToken) { Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(); try { token.decodeFromUrlString(encodedToken); } catch (Exception ie) { String msg = "Could not decode encoded token"; throw new BadRequestException(msg); } return token; }
private Token<RMDelegationTokenIdentifier> extractToken(String encodedToken) { Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(); try { token.decodeFromUrlString(encodedToken); } catch (Exception ie) { String msg = "Could not decode encoded token"; throw new BadRequestException(msg); } return token; } }
private Token<RMDelegationTokenIdentifier> extractToken(String encodedToken) { Token<RMDelegationTokenIdentifier> token = new Token<RMDelegationTokenIdentifier>(); try { token.decodeFromUrlString(encodedToken); } catch (Exception ie) { String msg = "Could not decode encoded token"; throw new BadRequestException(msg); } return token; } }
public static ApplicationId parseApplicationId(RecordFactory recordFactory, String appId) { if (appId == null || appId.isEmpty()) { throw new NotFoundException("appId, " + appId + ", is empty or null"); } ApplicationId aid = null; try { aid = ApplicationId.fromString(appId); } catch (Exception e) { throw new BadRequestException(e); } if (aid == null) { throw new NotFoundException("app with id " + appId + " not found"); } return aid; }
private static void validateStates(String stateQuery, Set<String> statesQuery) { // stateQuery is deprecated. if (stateQuery != null && !stateQuery.isEmpty()) { statesQuery.add(stateQuery); } Set<String> appStates = parseQueries(statesQuery, true); for (String appState : appStates) { switch (YarnApplicationState.valueOf( StringUtils.toUpperCase(appState))) { case FINISHED: case FAILED: case KILLED: continue; default: throw new BadRequestException("Invalid application-state " + appState + " specified. It should be a final state"); } } }
protected static ApplicationId parseApplicationId(String appId) { if (appId == null || appId.isEmpty()) { throw new NotFoundException("appId, " + appId + ", is empty or null"); } ApplicationId aid = null; try { aid = ApplicationId.fromString(appId); } catch (Exception e) { throw new BadRequestException(e); } if (aid == null) { throw new NotFoundException("appId is null"); } return aid; }
@GET @Path("/containers/{containerid}") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public ContainerInfo getNodeContainer(@javax.ws.rs.core.Context HttpServletRequest hsr, @PathParam("containerid") String id) { ContainerId containerId = null; init(); try { containerId = ContainerId.fromString(id); } catch (Exception e) { throw new BadRequestException("invalid container id, " + id); } Container container = nmContext.getContainers().get(containerId); if (container == null) { throw new NotFoundException("container with id, " + id + ", not found"); } return new ContainerInfo(this.nmContext, container, uriInfo.getBaseUri() .toString(), webapp.name(), hsr.getRemoteUser()); }
protected static ApplicationAttemptId parseApplicationAttemptId( String appAttemptId) { if (appAttemptId == null || appAttemptId.isEmpty()) { throw new NotFoundException("appAttemptId, " + appAttemptId + ", is empty or null"); } ApplicationAttemptId aaid = null; try { aaid = ApplicationAttemptId.fromString(appAttemptId); } catch (Exception e) { throw new BadRequestException(e); } if (aaid == null) { throw new NotFoundException("appAttemptId is null"); } return aaid; }
protected static ContainerId parseContainerId(String containerId) { if (containerId == null || containerId.isEmpty()) { throw new NotFoundException("containerId, " + containerId + ", is empty or null"); } ContainerId cid = null; try { cid = ContainerId.fromString(containerId); } catch (Exception e) { throw new BadRequestException(e); } if (cid == null) { throw new NotFoundException("containerId is null"); } return cid; }
protected Resource createAppSubmissionContextResource( ApplicationSubmissionContextInfo newApp) throws BadRequestException { if (newApp.getResource().getvCores() > rm.getConfig().getInt( YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES, YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES)) { String msg = "Requested more cores than configured max"; throw new BadRequestException(msg); } if (newApp.getResource().getMemory() > rm.getConfig().getInt( YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB, YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB)) { String msg = "Requested more memory than configured max"; throw new BadRequestException(msg); } Resource r = Resource.newInstance(newApp.getResource().getMemory(), newApp .getResource().getvCores()); return r; }
public static void retrieveException(ClientResponse response) { String serverErrorMsg = response.getEntity(String.class); int status = response.getStatus(); if (status == 400) { throw new BadRequestException(serverErrorMsg); } if (status == 403) { throw new ForbiddenException(serverErrorMsg); } if (status == 404) { throw new NotFoundException(serverErrorMsg); } if (status == 409) { throw new ConflictException(serverErrorMsg); } }