-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from federicomartinlara1976/develop
Develop
- Loading branch information
Showing
21 changed files
with
637 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
13:51:42.582 [main] INFO n.b.c.c.ChGuadalquivirApplication - Starting ChGuadalquivirApplication using Java 1.8.0_202 on discovery with PID 47281 (/home/federico/git/chguadalquivir-batch/target/classes started by federico in /home/federico/git/chguadalquivir-batch) | ||
13:51:42.585 [main] INFO n.b.c.c.ChGuadalquivirApplication - No active profile set, falling back to 1 default profile: "default" | ||
13:52:26.159 [main] ERROR o.s.boot.SpringApplication - Application run failed | ||
org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server | ||
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) | ||
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54) | ||
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) | ||
at java.lang.Iterable.forEach(Iterable.java:75) | ||
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155) | ||
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123) | ||
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935) | ||
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) | ||
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) | ||
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) | ||
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) | ||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) | ||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) | ||
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) | ||
at net.bounceme.chronos.chguadalquivir.ChGuadalquivirApplication.main(ChGuadalquivirApplication.java:18) | ||
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server | ||
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:229) | ||
at org.springframework.boot.web.servlet.context.WebServerStartStopLifecycle.start(WebServerStartStopLifecycle.java:43) | ||
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178) | ||
... 14 common frames omitted | ||
Caused by: java.lang.IllegalArgumentException: standardService.connector.startFailed | ||
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:238) | ||
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:282) | ||
at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:213) | ||
... 16 common frames omitted | ||
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed | ||
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1077) | ||
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) | ||
at org.apache.catalina.core.StandardService.addConnector(StandardService.java:234) | ||
... 18 common frames omitted | ||
Caused by: java.net.BindException: La dirección ya se está usando | ||
at sun.nio.ch.Net.bind0(Native Method) | ||
at sun.nio.ch.Net.bind(Net.java:433) | ||
at sun.nio.ch.Net.bind(Net.java:425) | ||
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) | ||
at org.apache.tomcat.util.net.NioEndpoint.initServerSocket(NioEndpoint.java:275) | ||
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:230) | ||
at org.apache.tomcat.util.net.AbstractEndpoint.bindWithCleanup(AbstractEndpoint.java:1227) | ||
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1313) | ||
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:617) | ||
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1074) | ||
... 20 common frames omitted |
106 changes: 106 additions & 0 deletions
106
src/main/java/net/bounceme/chronos/chguadalquivir/controller/JobController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package net.bounceme.chronos.chguadalquivir.controller; | ||
|
||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.validation.Valid; | ||
|
||
import org.springframework.batch.core.ExitStatus; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.core.JobParametersBuilder; | ||
import org.springframework.batch.core.launch.JobLauncher; | ||
import org.springframework.beans.factory.NoSuchBeanDefinitionException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import net.bounceme.chronos.chguadalquivir.model.Status; | ||
import net.bounceme.chronos.chguadalquivir.model.Task; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@Slf4j | ||
public class JobController { | ||
|
||
@Autowired | ||
private ApplicationContext ctx; | ||
|
||
@Autowired | ||
private JobLauncher jobLauncher; | ||
|
||
/** | ||
* @return | ||
*/ | ||
@GetMapping("/") | ||
public String index() { | ||
return "Hello world"; | ||
} | ||
|
||
/** | ||
* @return | ||
*/ | ||
@GetMapping("/status") | ||
public ResponseEntity<Status> status() { | ||
Status status = Status.builder().version(System.getProperty("java.version")) | ||
.platform(System.getProperty("os.name")).response("OK").build(); | ||
|
||
return new ResponseEntity<>(status, HttpStatus.OK); | ||
} | ||
|
||
@PostMapping("/execute") | ||
public ResponseEntity<Map<String, Object>> executeTask(@Valid @RequestBody Task task, BindingResult result) { | ||
Map<String, Object> response = new HashMap<>(); | ||
|
||
try { | ||
if (result.hasErrors()) { | ||
List<String> errors = result.getFieldErrors().stream() | ||
.map(error -> String.format("El campo '%s' %s", error.getField(), error.getDefaultMessage())) | ||
.collect(Collectors.toList()); | ||
|
||
response.put("errors", errors); | ||
return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
log.info("Ejecutar: {}", task.getName()); | ||
run(task.getName()); | ||
response.put("mensaje", "Tarea ejecutada correctamente"); | ||
return new ResponseEntity<>(response, HttpStatus.OK); | ||
} catch (Exception e) { | ||
response.put("error", e.getMessage()); | ||
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
/** | ||
* @param name | ||
* @throws Exception | ||
*/ | ||
private void run(String name) throws Exception { | ||
try { | ||
JobParametersBuilder builder = new JobParametersBuilder(); | ||
builder.addDate("date", new Date()); | ||
|
||
Job job = ctx.getBean(name, Job.class); | ||
JobExecution result = jobLauncher.run(job, builder.toJobParameters()); | ||
|
||
// Exit on failure | ||
if (ExitStatus.FAILED.equals(result.getExitStatus())) { | ||
throw new Exception("La tarea ha fallado"); | ||
} | ||
} catch (NoSuchBeanDefinitionException e) { | ||
throw new Exception("Tarea no encontrada"); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/bounceme/chronos/chguadalquivir/model/Status.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package net.bounceme.chronos.chguadalquivir.model; | ||
|
||
import java.io.Serializable; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder(toBuilder = true) | ||
public class Status implements Serializable { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = -6605836896150803431L; | ||
|
||
@Getter | ||
@Setter | ||
private String version; | ||
|
||
@Getter | ||
@Setter | ||
private String platform; | ||
|
||
@Getter | ||
@Setter | ||
private String response; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/net/bounceme/chronos/chguadalquivir/model/Task.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.bounceme.chronos.chguadalquivir.model; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.validation.constraints.NotEmpty; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder(toBuilder = true) | ||
public class Task implements Serializable { | ||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = -6557119505034879817L; | ||
|
||
@NotEmpty(message = "no puede estar vacío") | ||
@Getter | ||
@Setter | ||
private String name; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...in/java/net/bounceme/chronos/chguadalquivir/reader/mapping/StatExecutionsFieldMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.