List of usage examples for org.springframework.http HttpStatus ACCEPTED
HttpStatus ACCEPTED
To view the source code for org.springframework.http HttpStatus ACCEPTED.
Click Source Link
From source file:com.nagarro.core.v2.controller.UsersController.java
/** * Changes customer's password.//from w ww. ja v a2 s . c o m * * @formparam new New password * @formparam old Old password. Required only for ROLE_CUSTOMERGROUP */ @Secured({ "ROLE_CUSTOMERGROUP", "ROLE_TRUSTED_CLIENT", "ROLE_CUSTOMERMANAGERGROUP" }) @RequestMapping(value = "/{userId}/password", method = RequestMethod.PUT) @ResponseStatus(value = HttpStatus.ACCEPTED) public void changePassword(@PathVariable final String userId, @RequestParam(required = false) final String old, @RequestParam(value = "new") final String newPassword) { final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); UserSignUpWsDTO customer = new UserSignUpWsDTO(); customer.setPassword(newPassword); validate(customer, "password", passwordStrengthValidator); if (containsRole(auth, "ROLE_TRUSTED_CLIENT") || containsRole(auth, "ROLE_CUSTOMERMANAGERGROUP")) { userService.setPassword(userId, newPassword); } else { if (StringUtils.isEmpty(old)) { throw new RequestParameterException("Request parameter 'old' is missing.", RequestParameterException.MISSING, "old"); } customerFacade.changePassword(old, newPassword); } }
From source file:com.netflix.genie.web.controllers.JobRestController.java
/** * Submit a new job.//w w w . ja v a 2s . c om * * @param jobRequest The job request information * @param clientHost client host sending the request * @param userAgent The user agent string * @param httpServletRequest The http servlet request * @return The submitted job * @throws GenieException For any error */ @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public ResponseEntity<Void> submitJob(@Valid @RequestBody final JobRequest jobRequest, @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) final String clientHost, @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) final String userAgent, final HttpServletRequest httpServletRequest) throws GenieException { log.info("[submitJob] Called json method type to submit job: {}", jobRequest); this.submitJobWithoutAttachmentsRate.increment(); return this.handleSubmitJob(jobRequest, null, clientHost, userAgent, httpServletRequest); }
From source file:com.netflix.genie.web.controllers.JobRestController.java
/** * Submit a new job with attachments./*from www.jav a 2 s. co m*/ * * @param jobRequest The job request information * @param attachments The attachments for the job * @param clientHost client host sending the request * @param userAgent The user agent string * @param httpServletRequest The http servlet request * @return The submitted job * @throws GenieException For any error */ @RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(HttpStatus.ACCEPTED) public ResponseEntity<Void> submitJob(@Valid @RequestPart("request") final JobRequest jobRequest, @RequestPart("attachment") final MultipartFile[] attachments, @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) final String clientHost, @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) final String userAgent, final HttpServletRequest httpServletRequest) throws GenieException { log.info("[submitJob] Called multipart method to submit job: {}", jobRequest); this.submitJobWithAttachmentsRate.increment(); return this.handleSubmitJob(jobRequest, attachments, clientHost, userAgent, httpServletRequest); }
From source file:com.netflix.genie.web.controllers.JobRestController.java
private ResponseEntity<Void> handleSubmitJob(final JobRequest jobRequest, final MultipartFile[] attachments, final String clientHost, final String userAgent, final HttpServletRequest httpServletRequest) throws GenieException { if (jobRequest == null) { throw new GeniePreconditionException("No job request entered. Unable to submit."); }//from ww w. j av a 2s . c om // get client's host from the context final String localClientHost; if (StringUtils.isNotBlank(clientHost)) { localClientHost = clientHost.split(",")[0]; } else { localClientHost = httpServletRequest.getRemoteAddr(); } final JobRequest jobRequestWithId; // If the job request does not contain an id create one else use the one provided. final String jobId; final Optional<String> jobIdOptional = jobRequest.getId(); if (jobIdOptional.isPresent() && StringUtils.isNotBlank(jobIdOptional.get())) { jobId = jobIdOptional.get(); jobRequestWithId = jobRequest; } else { jobId = UUID.randomUUID().toString(); final JobRequest.Builder builder = new JobRequest.Builder(jobRequest.getName(), jobRequest.getUser(), jobRequest.getVersion(), jobRequest.getCommandArgs(), jobRequest.getClusterCriterias(), jobRequest.getCommandCriteria()).withId(jobId) .withDisableLogArchival(jobRequest.isDisableLogArchival()) .withTags(jobRequest.getTags()).withDependencies(jobRequest.getDependencies()) .withApplications(jobRequest.getApplications()); jobRequest.getCpu().ifPresent(builder::withCpu); jobRequest.getMemory().ifPresent(builder::withMemory); jobRequest.getGroup().ifPresent(builder::withGroup); jobRequest.getSetupFile().ifPresent(builder::withSetupFile); jobRequest.getDescription().ifPresent(builder::withDescription); jobRequest.getEmail().ifPresent(builder::withEmail); jobRequest.getTimeout().ifPresent(builder::withTimeout); jobRequestWithId = builder.build(); } // Download attachments int numAttachments = 0; long totalSizeOfAttachments = 0L; if (attachments != null) { log.info("Saving attachments for job {}", jobId); numAttachments = attachments.length; for (final MultipartFile attachment : attachments) { totalSizeOfAttachments += attachment.getSize(); log.debug("Attachment name: {} Size: {}", attachment.getOriginalFilename(), attachment.getSize()); try { this.attachmentService.save(jobId, attachment.getOriginalFilename(), attachment.getInputStream()); } catch (final IOException ioe) { throw new GenieServerException(ioe); } } } final JobMetadata metadata = new JobMetadata.Builder().withClientHost(localClientHost) .withUserAgent(userAgent).withNumAttachments(numAttachments) .withTotalSizeOfAttachments(totalSizeOfAttachments).build(); this.jobCoordinatorService.coordinateJob(jobRequestWithId, metadata); final HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setLocation( ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(jobId).toUri()); return new ResponseEntity<>(httpHeaders, HttpStatus.ACCEPTED); }
From source file:com.netflix.genie.web.controllers.JobRestController.java
/** * Kill job based on given job ID.//w ww . j av a 2s .com * * @param id id for job to kill * @param forwardedFrom The host this request was forwarded from if present * @param request the servlet request * @param response the servlet response * @throws GenieException For any error * @throws IOException on redirect error * @throws ServletException when trying to handle the request */ @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.ACCEPTED) public void killJob(@PathVariable("id") final String id, @RequestHeader(name = JobConstants.GENIE_FORWARDED_FROM_HEADER, required = false) final String forwardedFrom, final HttpServletRequest request, final HttpServletResponse response) throws GenieException, IOException, ServletException { log.info("[killJob] Called for job id: {}. Forwarded from: {}", id, forwardedFrom); // If forwarded from is null this request hasn't been forwarded at all. Check we're on the right node if (this.jobsProperties.getForwarding().isEnabled() && forwardedFrom == null) { final String jobHostname = this.jobSearchService.getJobHost(id); if (!this.hostName.equals(jobHostname)) { log.info("Job {} is not on this node. Forwarding kill request to {}", id, jobHostname); final String forwardUrl = buildForwardURL(request, jobHostname); try { //Need to forward job restTemplate.execute(forwardUrl, HttpMethod.DELETE, forwardRequest -> copyRequestHeaders(request, forwardRequest), (final ClientHttpResponse forwardResponse) -> { response.setStatus(HttpStatus.ACCEPTED.value()); copyResponseHeaders(response, forwardResponse); return null; }); } catch (HttpStatusCodeException e) { log.error("Failed killing job on {}. Error: {}", forwardUrl, e.getMessage()); response.sendError(e.getStatusCode().value(), e.getStatusText()); } catch (Exception e) { log.error("Failed killing job on {}. Error: {}", forwardUrl, e.getMessage()); response.sendError(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); } // No need to do anything on this node return; } } log.info("Job {} is on this node. Attempting to kill.", id); // Job is on this node so try to kill it this.jobCoordinatorService.killJob(id); response.setStatus(HttpStatus.ACCEPTED.value()); }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
private String submitJob(final int documentationId, final JobRequest jobRequest, @Nullable final List<MockMultipartFile> attachments) throws Exception { if (attachments != null) { final RestDocumentationFilter createResultFilter = RestAssuredRestDocumentation.document( "{class-name}/" + documentationId + "/submitJobWithAttachments/", HeaderDocumentation.requestHeaders(HeaderDocumentation.headerWithName(HttpHeaders.CONTENT_TYPE) .description(MediaType.MULTIPART_FORM_DATA_VALUE)), // Request headers RequestDocumentation.requestParts( RequestDocumentation.partWithName("request").description( "The job request JSON. Content type must be application/json for part"), RequestDocumentation.partWithName("attachment").description( "An attachment file. There can be multiple. Type should be octet-stream")), // Request parts Snippets.LOCATION_HEADER // Response Headers );// w w w . j av a2 s .c o m final RequestSpecification jobRequestSpecification = RestAssured.given(this.getRequestSpecification()) .filter(createResultFilter).contentType(MediaType.MULTIPART_FORM_DATA_VALUE) .multiPart("request", GenieObjectMapper.getMapper().writeValueAsString(jobRequest), MediaType.APPLICATION_JSON_VALUE); for (final MockMultipartFile attachment : attachments) { jobRequestSpecification.multiPart("attachment", attachment.getOriginalFilename(), attachment.getBytes(), MediaType.APPLICATION_OCTET_STREAM_VALUE); } return this.getIdFromLocation(jobRequestSpecification.when().port(this.port).post(JOBS_API).then() .statusCode(Matchers.is(HttpStatus.ACCEPTED.value())) .header(HttpHeaders.LOCATION, Matchers.notNullValue()).extract().header(HttpHeaders.LOCATION)); } else { // Use regular POST final RestDocumentationFilter createResultFilter = RestAssuredRestDocumentation.document( "{class-name}/" + documentationId + "/submitJobWithoutAttachments/", Snippets.CONTENT_TYPE_HEADER, // Request headers Snippets.getJobRequestRequestPayload(), // Request Fields Snippets.LOCATION_HEADER // Response Headers ); return this.getIdFromLocation(RestAssured.given(this.getRequestSpecification()) .filter(createResultFilter).contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)).when().port(this.port) .post(JOBS_API).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())) .header(HttpHeaders.LOCATION, Matchers.notNullValue()).extract().header(HttpHeaders.LOCATION)); } }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
/** * Test the job submit method for when the job is killed by sending a DELETE HTTP call. * * @throws Exception If there is a problem. *//*from w w w . j ava2 s . c om*/ @Test public void testSubmitJobMethodKill() throws Exception { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); final List<String> commandArgs = Lists.newArrayList("-c", "'sleep 60'"); final List<ClusterCriteria> clusterCriteriaList = new ArrayList<>(); final Set<String> clusterTags = Sets.newHashSet(LOCALHOST_CLUSTER_TAG); final ClusterCriteria clusterCriteria = new ClusterCriteria(clusterTags); clusterCriteriaList.add(clusterCriteria); final Set<String> commandCriteria = Sets.newHashSet(BASH_COMMAND_TAG); final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, clusterCriteriaList, commandCriteria).withCommandArgs(commandArgs).withDisableLogArchival(true).build(); final String jobId = this.getIdFromLocation(RestAssured.given(this.getRequestSpecification()) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)).when().port(this.port) .post(JOBS_API).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())) .header(HttpHeaders.LOCATION, Matchers.notNullValue()).extract().header(HttpHeaders.LOCATION)); this.waitForRunning(jobId); // Make sure we can get output for a running job RestAssured.given(this.getRequestSpecification()).accept(MediaType.APPLICATION_JSON_VALUE).when() .port(this.port).get(JOBS_API + "/{id}/output/{filePath}", jobId, "").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.equalToIgnoringCase(MediaType.APPLICATION_JSON_UTF8_VALUE)) .body("parent", Matchers.isEmptyOrNullString()).body("directories[0].name", Matchers.is("genie/")) .body("files[0].name", Matchers.is("run")).body("files[1].name", Matchers.is("stderr")) .body("files[2].name", Matchers.is("stdout")); RestAssured.given(this.getRequestSpecification()).when().port(this.port) .get(JOBS_API + "/{id}/output/{filePath}", jobId, "stdout").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(ContentType.TEXT.toString())); // Let it run for a couple of seconds Thread.sleep(2000); // Send a kill request to the job. final RestDocumentationFilter killResultFilter = RestAssuredRestDocumentation .document("{class-name}/killJob/", Snippets.ID_PATH_PARAM); RestAssured.given(this.getRequestSpecification()).filter(killResultFilter).when().port(this.port) .delete(JOBS_API + "/{id}", jobId).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())); this.waitForDone(jobId); RestAssured.given(this.getRequestSpecification()).when().port(this.port).get(JOBS_API + "/{id}", jobId) .then().statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.is(MediaTypes.HAL_JSON_UTF8_VALUE)).body(ID_PATH, Matchers.is(jobId)) .body(STATUS_PATH, Matchers.is(JobStatus.KILLED.toString())) .body(STATUS_MESSAGE_PATH, Matchers.is(JobStatusMessages.JOB_KILLED_BY_USER)); // Kill the job again to make sure it doesn't cause a problem. RestAssured.given(this.getRequestSpecification()).filter(killResultFilter).when().port(this.port) .delete(JOBS_API + "/{id}", jobId).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())); }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
/** * Test the job submit method for when the job is killed as it times out. * * @throws Exception If there is a problem. *//*from w w w . j a v a 2 s . c om*/ @Test public void testSubmitJobMethodKillOnTimeout() throws Exception { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); final List<String> commandArgs = Lists.newArrayList("-c", "'sleep 60'"); final List<ClusterCriteria> clusterCriteriaList = new ArrayList<>(); final Set<String> clusterTags = Sets.newHashSet(LOCALHOST_CLUSTER_TAG); final ClusterCriteria clusterCriteria = new ClusterCriteria(clusterTags); clusterCriteriaList.add(clusterCriteria); final Set<String> commandCriteria = Sets.newHashSet(BASH_COMMAND_TAG); final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, clusterCriteriaList, commandCriteria).withCommandArgs(commandArgs).withTimeout(5).withDisableLogArchival(true).build(); final String id = this.getIdFromLocation(RestAssured.given(this.getRequestSpecification()) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)).when().port(this.port) .post(JOBS_API).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())) .header(HttpHeaders.LOCATION, Matchers.notNullValue()).extract().header(HttpHeaders.LOCATION)); this.waitForDone(id); RestAssured.given(this.getRequestSpecification()).when().port(this.port).get(JOBS_API + "/{id}", id).then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.is(MediaTypes.HAL_JSON_UTF8_VALUE)).body(ID_PATH, Matchers.is(id)) .body(STATUS_PATH, Matchers.is(JobStatus.KILLED.toString())) .body(STATUS_MESSAGE_PATH, Matchers.is("Job exceeded timeout.")); }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
/** * Test the job submit method for when the job fails. * * @throws Exception If there is a problem. *//* w w w . jav a 2s . c o m*/ @Test public void testSubmitJobMethodFailure() throws Exception { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); final List<String> commandArgs = Lists.newArrayList("-c", "'exit 1'"); final List<ClusterCriteria> clusterCriteriaList = new ArrayList<>(); final Set<String> clusterTags = Sets.newHashSet(LOCALHOST_CLUSTER_TAG); final ClusterCriteria clusterCriteria = new ClusterCriteria(clusterTags); clusterCriteriaList.add(clusterCriteria); final Set<String> commandCriteria = Sets.newHashSet(BASH_COMMAND_TAG); final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, clusterCriteriaList, commandCriteria).withCommandArgs(commandArgs).withDisableLogArchival(true).build(); final String id = this.getIdFromLocation(RestAssured.given(this.getRequestSpecification()) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)).when().port(this.port) .post(JOBS_API).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())) .header(HttpHeaders.LOCATION, Matchers.notNullValue()).extract().header(HttpHeaders.LOCATION)); this.waitForDone(id); Assert.assertEquals(this.getStatus(id), "{\"status\":\"FAILED\"}"); RestAssured.given(this.getRequestSpecification()).when().port(this.port).get(JOBS_API + "/{id}", id).then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.is(MediaTypes.HAL_JSON_UTF8_VALUE)).body(ID_PATH, Matchers.is(id)) .body(STATUS_PATH, Matchers.is(JobStatus.FAILED.toString())) .body(STATUS_MESSAGE_PATH, Matchers.is(JobStatusMessages.JOB_FAILED)); }
From source file:com.netflix.genie.web.controllers.JobRestControllerIntegrationTest.java
/** * Test the response content types to ensure UTF-8. * * @throws Exception If there is a problem. *//* w ww . j a v a 2 s.c o m*/ @Test public void testResponseContentType() throws Exception { Assume.assumeTrue(SystemUtils.IS_OS_UNIX); final List<String> commandArgs = Lists.newArrayList("-c", "'echo hello'"); final JobRequest jobRequest = new JobRequest.Builder(JOB_NAME, JOB_USER, JOB_VERSION, Lists.newArrayList(new ClusterCriteria(Sets.newHashSet("localhost"))), Sets.newHashSet("bash")) .withCommandArgs(commandArgs).build(); final String jobId = this.getIdFromLocation(RestAssured.given(this.getRequestSpecification()) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(GenieObjectMapper.getMapper().writeValueAsBytes(jobRequest)).when().port(this.port) .post(JOBS_API).then().statusCode(Matchers.is(HttpStatus.ACCEPTED.value())) .header(HttpHeaders.LOCATION, Matchers.notNullValue()).extract().header(HttpHeaders.LOCATION)); this.waitForDone(jobId); RestAssured.given(this.getRequestSpecification()).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/genie/logs/env.log").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); RestAssured.given(this.getRequestSpecification()).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/genie/logs/genie.log").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); RestAssured.given(this.getRequestSpecification()).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/genie/genie.done").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); RestAssured.given(this.getRequestSpecification()).accept(MediaType.ALL_VALUE).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/stdout").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); RestAssured.given(this.getRequestSpecification()).accept(MediaType.ALL_VALUE).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/stderr").then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); // Verify the file is served as UTF-8 even if it's not RestAssured.given(this.getRequestSpecification()).accept(MediaType.ALL_VALUE).when().port(this.port) .get(JOBS_API + "/" + jobId + "/output/genie/command/" + CMD1_ID + "/config/" + GB18030_TXT).then() .statusCode(Matchers.is(HttpStatus.OK.value())) .contentType(Matchers.containsString(MediaType.TEXT_PLAIN_VALUE)) .contentType(Matchers.containsString("UTF-8")); }