From 70fbf99f8ce34f64c1c25424bea147d0bede1c99 Mon Sep 17 00:00:00 2001 From: Luca Trubbiani Date: Tue, 13 Feb 2024 17:40:13 +0100 Subject: [PATCH] Format files --- .gitignore | 2 + .prettierrc.yml | 2 + .../core/annotations/ApiVersion.java | 5 +- .../factories/builders/BuilderFactory.java | 12 +- .../factories/runtimes/RuntimeFactory.java | 5 +- .../handlers/VersionedHandlerMapping.java | 35 +- .../v1/base/ArtifactController.java | 21 +- .../v1/base/DataItemController.java | 21 +- .../v1/base/FunctionController.java | 27 +- .../v1/base/ProjectController.java | 37 +- .../controllers/v1/base/RunController.java | 29 +- .../controllers/v1/base/SecretController.java | 18 +- .../controllers/v1/base/TaskController.java | 23 +- .../v1/base/WorkflowController.java | 23 +- .../v1/context/ArtifactContextController.java | 111 +++--- .../v1/context/DataItemContextController.java | 111 +++--- .../v1/context/FunctionContextController.java | 135 ++++--- .../v1/context/RunContextController.java | 56 ++- .../v1/context/SecretContextController.java | 59 ++-- .../v1/context/TaskContextController.java | 60 ++-- .../v1/context/WorkflowContextController.java | 111 +++--- .../filters/entities/SecretEntityFilter.java | 9 +- .../core/services/RunServiceImpl.java | 261 +++++++------- .../context/ArtifactContextServiceImpl.java | 207 ++++++----- .../context/DataItemContextServiceImpl.java | 211 ++++++----- .../context/FunctionContextServiceImpl.java | 331 +++++++++--------- .../context/SecretContextServiceImpl.java | 19 +- .../context/WorkflowContextServiceImpl.java | 211 ++++++----- .../interfaces/SecretContextService.java | 3 +- .../core/ConvertFunctionTests.java | 25 +- .../core/CoreApplicationTests.java | 6 +- .../core/K8sSecretHelperTests.java | 95 +++-- .../core/KanikoImageBuilderTest.java | 29 +- .../core/PersonSerializationTest.java | 16 +- .../K8sDeploymentFramework.java | 108 +++--- .../k8s/infrastructure/K8sJobFramework.java | 94 ++--- .../k8s/infrastructure/K8sServeFramework.java | 108 +++--- .../fsm/StateMachineTest.java | 249 ++++++------- .../runtime/container/ContainerRuntime.java | 74 ++-- .../specs/function/FunctionContainerSpec.java | 15 +- .../models/specs/run/RunContainerSpec.java | 7 +- .../models/specs/task/TaskDeploySpec.java | 3 +- .../models/specs/task/TaskJobSpec.java | 3 +- .../models/specs/task/TaskServeSpec.java | 3 +- .../runners/ContainerDeployRunner.java | 39 +-- .../container/runners/ContainerJobRunner.java | 1 - .../runners/ContainerServeRunner.java | 39 +-- .../runtime/dbt/DbtRuntime.java | 16 +- .../specs/function/FunctionDbtSpec.java | 3 +- .../dbt/models/specs/run/RunDbtSpec.java | 3 +- .../models/specs/task/TaskTransformSpec.java | 7 +- .../dbt/runners/DbtTransformRunner.java | 33 +- .../runtime/mlrun/MlrunRuntime.java | 10 +- .../specs/function/FunctionMlrunSpec.java | 9 +- .../mlrun/models/specs/run/RunMlrunSpec.java | 3 +- .../models/specs/task/TaskMlrunSpec.java | 3 +- .../mlrun/runners/MlrunMlrunRunner.java | 31 +- .../runtime/nefertem/NefertemRuntime.java | 68 ++-- .../specs/function/FunctionNefertemSpec.java | 9 +- .../models/specs/run/RunNefertemSpec.java | 3 +- .../models/specs/task/TaskInferSpec.java | 3 +- .../models/specs/task/TaskMetricSpec.java | 3 +- .../models/specs/task/TaskProfileSpec.java | 3 +- .../models/specs/task/TaskValidateSpec.java | 7 +- .../nefertem/runners/NefertemInferRunner.java | 31 +- .../runners/NefertemMetricRunner.java | 33 +- .../runners/NefertemProfileRunner.java | 31 +- .../runners/NefertemValidateRunner.java | 31 +- 68 files changed, 1657 insertions(+), 1752 deletions(-) diff --git a/.gitignore b/.gitignore index f688d459..4626a481 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,8 @@ build/ ### Env variable ### .env +node_modules + ### Checkstyle folder### /src/checkstyle diff --git a/.prettierrc.yml b/.prettierrc.yml index e6a0949e..782c7c6d 100644 --- a/.prettierrc.yml +++ b/.prettierrc.yml @@ -1,4 +1,6 @@ # Prettier configuration +plugins: + - prettier-plugin-java overrides: - files: - "*.java" diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/annotations/ApiVersion.java b/application/src/main/java/it/smartcommunitylabdhub/core/annotations/ApiVersion.java index 54ba38ea..d9f8f81b 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/annotations/ApiVersion.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/annotations/ApiVersion.java @@ -1,10 +1,9 @@ package it.smartcommunitylabdhub.core.annotations; -import org.springframework.web.bind.annotation.Mapping; - import java.lang.annotation.*; +import org.springframework.web.bind.annotation.Mapping; -@Target({ElementType.TYPE, ElementType.METHOD}) +@Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented @Mapping diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/components/infrastructure/factories/builders/BuilderFactory.java b/application/src/main/java/it/smartcommunitylabdhub/core/components/infrastructure/factories/builders/BuilderFactory.java index 6082d81f..4a34a4bc 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/components/infrastructure/factories/builders/BuilderFactory.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/components/infrastructure/factories/builders/BuilderFactory.java @@ -18,7 +18,10 @@ public class BuilderFactory { - private final Map> builderMap; + private final Map< + String, + ? extends Builder + > builderMap; /** * Constructor to create the BuilderFactory with a list of Builders. @@ -72,9 +75,10 @@ > String getBuilderFromAnnotation(B builder) { return concreteBuilder; } - public Map> getBuilders( - String runtime - ) { + public Map< + String, + ? extends Builder + > getBuilders(String runtime) { return builderMap .entrySet() .stream() diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/components/infrastructure/factories/runtimes/RuntimeFactory.java b/application/src/main/java/it/smartcommunitylabdhub/core/components/infrastructure/factories/runtimes/RuntimeFactory.java index 6f2f9e2c..ee4292ae 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/components/infrastructure/factories/runtimes/RuntimeFactory.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/components/infrastructure/factories/runtimes/RuntimeFactory.java @@ -18,7 +18,10 @@ public class RuntimeFactory { - private final Map> runtimeMap; + private final Map< + String, + Runtime + > runtimeMap; /** * Constructor to create the RuntimeFactory with a list of Runtimes. diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/config/handlers/VersionedHandlerMapping.java b/application/src/main/java/it/smartcommunitylabdhub/core/config/handlers/VersionedHandlerMapping.java index 94e26837..5b518146 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/config/handlers/VersionedHandlerMapping.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/config/handlers/VersionedHandlerMapping.java @@ -2,6 +2,9 @@ import it.smartcommunitylabdhub.core.annotations.ApiVersion; import jakarta.servlet.http.HttpServletRequest; +import java.lang.reflect.Method; +import java.util.Map; +import java.util.Optional; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMethod; @@ -14,10 +17,6 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.util.pattern.PathPattern; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.Optional; - public class VersionedHandlerMapping extends RequestMappingHandlerMapping { private static final String VERSION_ATTRIBUTE = "version"; @@ -69,12 +68,12 @@ private RequestMappingInfo createVersionedMappingInfo(RequestMappingInfo mapping // .getPatternString(); String originalPattern = Optional - .ofNullable(mappingInfo) - .map(RequestMappingInfo::getPathPatternsCondition) - .map(PathPatternsRequestCondition::getPatterns) - .flatMap(patterns -> patterns.stream().findFirst()) - .map(PathPattern::getPatternString) - .orElse("/error"); + .ofNullable(mappingInfo) + .map(RequestMappingInfo::getPathPatternsCondition) + .map(PathPatternsRequestCondition::getPatterns) + .flatMap(patterns -> patterns.stream().findFirst()) + .map(PathPattern::getPatternString) + .orElse("/error"); String versionedPattern = "/api/" + version + originalPattern; @@ -84,13 +83,13 @@ private RequestMappingInfo createVersionedMappingInfo(RequestMappingInfo mapping if (mappingInfo != null) { RequestMappingInfo.Builder builder = mappingInfo - .mutate() - .paths(versionedPattern) - .methods(mappingInfo.getMethodsCondition().getMethods().toArray(RequestMethod[]::new)) - .params(mappingInfo.getParamsCondition().getExpressions().toArray(String[]::new)) - .headers(mappingInfo.getHeadersCondition().getExpressions().toArray(String[]::new)) - .consumes(getMediaTypeStrings(mappingInfo.getConsumesCondition())) - .produces(getMediaTypeStrings(mappingInfo.getProducesCondition())); + .mutate() + .paths(versionedPattern) + .methods(mappingInfo.getMethodsCondition().getMethods().toArray(RequestMethod[]::new)) + .params(mappingInfo.getParamsCondition().getExpressions().toArray(String[]::new)) + .headers(mappingInfo.getHeadersCondition().getExpressions().toArray(String[]::new)) + .consumes(getMediaTypeStrings(mappingInfo.getConsumesCondition())) + .produces(getMediaTypeStrings(mappingInfo.getProducesCondition())); if (mappingInfo.getName() != null) { builder.mappingName(mappingInfo.getName()); @@ -119,7 +118,7 @@ protected void handleMatch(RequestMappingInfo info, String lookupPath, HttpServl String version = (String) request.getAttribute(VERSION_ATTRIBUTE); if (version != null) { Map uriTemplateVariables = (Map) request.getAttribute( - HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE + HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE ); if (uriTemplateVariables != null) { uriTemplateVariables.put("version", version); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/ArtifactController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/ArtifactController.java index f75dfb32..b131c21a 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/ArtifactController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/ArtifactController.java @@ -7,6 +7,7 @@ import it.smartcommunitylabdhub.commons.services.interfaces.ArtifactService; import it.smartcommunitylabdhub.core.annotations.ApiVersion; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -15,8 +16,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @RequestMapping("/artifacts") @ApiVersion("v1") @@ -35,9 +34,9 @@ public ResponseEntity> getArtifacts(@RequestParam Map createArtifact(@Valid @RequestBody Artifact artifactDTO) { return ResponseEntity.ok(this.artifactService.createArtifact(artifactDTO)); @@ -46,20 +45,20 @@ public ResponseEntity createArtifact(@Valid @RequestBody Artifact arti @Operation(summary = "Get an artifact by uuid", description = "Return an artifact") @GetMapping(path = "/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getArtifact( - @ValidateField @PathVariable(name = "uuid", required = true) String uuid + @ValidateField @PathVariable(name = "uuid", required = true) String uuid ) { return ResponseEntity.ok(this.artifactService.getArtifact(uuid)); } @Operation(summary = "Update specific artifact", description = "Update and return the artifact") @PutMapping( - path = "/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateArtifact( - @Valid @RequestBody Artifact artifactDTO, - @ValidateField @PathVariable String uuid + @Valid @RequestBody Artifact artifactDTO, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.artifactService.updateArtifact(artifactDTO, uuid)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/DataItemController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/DataItemController.java index c7477e16..316ddf72 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/DataItemController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/DataItemController.java @@ -7,6 +7,7 @@ import it.smartcommunitylabdhub.commons.services.interfaces.DataItemService; import it.smartcommunitylabdhub.core.annotations.ApiVersion; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -15,8 +16,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @RequestMapping("/dataitems") @ApiVersion("v1") @@ -35,9 +34,9 @@ public ResponseEntity> getDataItems(@RequestParam Map createDataItem(@Valid @RequestBody DataItem dataItemDTO) { return ResponseEntity.ok(this.dataItemService.createDataItem(dataItemDTO)); @@ -46,20 +45,20 @@ public ResponseEntity createDataItem(@Valid @RequestBody DataItem data @Operation(summary = "Get a dataItem by uuid", description = "Return an dataItem") @GetMapping(path = "/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getDataItem( - @ValidateField @PathVariable(name = "uuid", required = true) String uuid + @ValidateField @PathVariable(name = "uuid", required = true) String uuid ) { return ResponseEntity.ok(this.dataItemService.getDataItem(uuid)); } @Operation(summary = "Update specific dataItem", description = "Update and return the dataItem") @PutMapping( - path = "/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateDataItem( - @Valid @RequestBody DataItem dataItemDTO, - @ValidateField @PathVariable String uuid + @Valid @RequestBody DataItem dataItemDTO, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.dataItemService.updateDataItem(dataItemDTO, uuid)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/FunctionController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/FunctionController.java index d2e3e494..1358be26 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/FunctionController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/FunctionController.java @@ -8,6 +8,8 @@ import it.smartcommunitylabdhub.commons.services.interfaces.FunctionService; import it.smartcommunitylabdhub.core.annotations.ApiVersion; import jakarta.validation.Valid; +import java.util.List; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -16,9 +18,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Map; - @RestController @RequestMapping("/functions") @ApiVersion("v1") @@ -37,9 +36,9 @@ public ResponseEntity> getFunctions(@RequestParam Map createFunction(@Valid @RequestBody Function functionDTO) { return ResponseEntity.ok(this.functionService.createFunction(functionDTO)); @@ -48,20 +47,20 @@ public ResponseEntity createFunction(@Valid @RequestBody Function func @Operation(summary = "Get a function by uuid", description = "Return an function") @GetMapping(path = "/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getFunction( - @ValidateField @PathVariable(name = "uuid", required = true) String uuid + @ValidateField @PathVariable(name = "uuid", required = true) String uuid ) { return ResponseEntity.ok(this.functionService.getFunction(uuid)); } @Operation(summary = "Update specific function", description = "Update and return the function") @PutMapping( - path = "/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateFunction( - @Valid @RequestBody Function functionDTO, - @ValidateField @PathVariable String uuid + @Valid @RequestBody Function functionDTO, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.functionService.updateFunction(functionDTO, uuid)); } @@ -69,8 +68,8 @@ public ResponseEntity updateFunction( @Operation(summary = "Delete a function", description = "Delete a specific function") @DeleteMapping(path = "/{uuid}") public ResponseEntity deleteFunction( - @ValidateField @PathVariable String uuid, - @RequestParam(value = "cascade", defaultValue = "false") Boolean cascade + @ValidateField @PathVariable String uuid, + @RequestParam(value = "cascade", defaultValue = "false") Boolean cascade ) { return ResponseEntity.ok(this.functionService.deleteFunction(uuid, cascade)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/ProjectController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/ProjectController.java index ad6eac6d..03678304 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/ProjectController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/ProjectController.java @@ -11,6 +11,9 @@ import it.smartcommunitylabdhub.commons.services.interfaces.ProjectService; import it.smartcommunitylabdhub.core.annotations.ApiVersion; import jakarta.validation.Valid; +import java.util.List; +import java.util.Map; +import java.util.Set; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -20,10 +23,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Map; -import java.util.Set; - @RestController @RequestMapping("/projects") @ApiVersion("v1") @@ -43,9 +42,9 @@ public ResponseEntity> getProjects(@RequestParam Map createProject(@Valid @RequestBody Project projectDTO) { return ResponseEntity.ok(this.projectService.createProject(projectDTO)); @@ -54,20 +53,20 @@ public ResponseEntity createProject(@Valid @RequestBody Project project @Operation(summary = "Get an project by name", description = "Return an project") @GetMapping(path = "/{name}", produces = "application/json; charset=UTF-8") public ResponseEntity getProject( - @ValidateField @PathVariable(name = "name", required = true) String name + @ValidateField @PathVariable(name = "name", required = true) String name ) { return ResponseEntity.ok(this.projectService.getProject(name)); } @Operation(summary = "Update specific project", description = "Update and return the project") @PutMapping( - path = "/{name}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "/{name}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateProject( - @RequestBody Project projectDTO, - @ValidateField @PathVariable(name = "name", required = true) String name + @RequestBody Project projectDTO, + @ValidateField @PathVariable(name = "name", required = true) String name ) { return ResponseEntity.ok(this.projectService.updateProject(projectDTO, name)); } @@ -75,8 +74,8 @@ public ResponseEntity updateProject( @Operation(summary = "Delete a project", description = "Delete a specific project") @DeleteMapping(path = "/{name}") public ResponseEntity deleteProject( - @ValidateField @PathVariable(name = "name", required = true) String name, - @RequestParam(name = "cascade") Boolean cascade + @ValidateField @PathVariable(name = "name", required = true) String name, + @RequestParam(name = "cascade") Boolean cascade ) { return ResponseEntity.ok(this.projectService.deleteProject(name, cascade)); } @@ -108,8 +107,8 @@ public ResponseEntity> projectSecrets(@ValidateField @PathVariable @Operation(summary = "Read project secret data", description = "Get project secrets data for the specified keys") @GetMapping(path = "/{name}/secrets/data", produces = "application/json; charset=UTF-8") public ResponseEntity> projectSecretData( - @ValidateField @PathVariable String name, - @RequestParam Set keys + @ValidateField @PathVariable String name, + @RequestParam Set keys ) { return ResponseEntity.ok(this.projectService.getProjectSecretData(name, keys)); } @@ -117,8 +116,8 @@ public ResponseEntity> projectSecretData( @Operation(summary = "Store project secret data", description = "Store project secrets data") @PutMapping(path = "/{name}/secrets/data", produces = "application/json; charset=UTF-8") public ResponseEntity storeProjectSecretData( - @ValidateField @PathVariable String name, - @RequestBody Map values + @ValidateField @PathVariable String name, + @RequestBody Map values ) { this.projectService.storeProjectSecretData(name, values); return ResponseEntity.ok().build(); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/RunController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/RunController.java index b6f3164d..7adc3c11 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/RunController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/RunController.java @@ -12,6 +12,7 @@ import it.smartcommunitylabdhub.core.annotations.ApiVersion; import it.smartcommunitylabdhub.fsm.pollers.PollingService; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -19,8 +20,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @RequestMapping("/runs") @ApiVersion("v1") @@ -49,8 +48,8 @@ public ResponseEntity getRun(@ValidateField @PathVariable(name = "uuid", re @Operation(summary = "Run log list", description = "Return the log list for a specific run") @GetMapping(path = "/{uuid}/log", produces = "application/json; charset=UTF-8") public ResponseEntity> getRunLog( - @ValidateField @PathVariable(name = "uuid", required = true) String uuid, - Pageable pageable + @ValidateField @PathVariable(name = "uuid", required = true) String uuid, + Pageable pageable ) { return ResponseEntity.ok(this.logService.getLogsByRunUuid(uuid, pageable)); } @@ -63,9 +62,9 @@ public ResponseEntity> getRuns(@RequestParam Map filte @Operation(summary = "Create and execute a run", description = "Create a run and then execute it") @PostMapping( - path = "", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createRun(@Valid @RequestBody Run inputRunDTO) { return ResponseEntity.ok(this.runService.createRun(inputRunDTO)); @@ -73,9 +72,9 @@ public ResponseEntity createRun(@Valid @RequestBody Run inputRunDTO) { @Operation(summary = "Update specific run", description = "Update and return the update run") @PutMapping( - path = "/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateRun(@Valid @RequestBody Run runDTO, @ValidateField @PathVariable String uuid) { return ResponseEntity.ok(this.runService.updateRun(runDTO, uuid)); @@ -84,17 +83,17 @@ public ResponseEntity updateRun(@Valid @RequestBody Run runDTO, @ValidateFi @Operation(summary = "Delete a run", description = "Delete a specific run") @DeleteMapping(path = "/{uuid}") public ResponseEntity deleteRun( - @ValidateField @PathVariable(name = "uuid", required = true) String uuid, - @RequestParam(name = "cascade", defaultValue = "false") Boolean cascade + @ValidateField @PathVariable(name = "uuid", required = true) String uuid, + @RequestParam(name = "cascade", defaultValue = "false") Boolean cascade ) { return ResponseEntity.ok(this.runService.deleteRun(uuid, cascade)); } @Operation(summary = "Stop a run", description = "Stop a specific run") @PostMapping( - path = "/{uuid}/stop", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "/{uuid}/stop", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity stopRun(@ValidateField @PathVariable String uuid) { Runnable runnable = runnableStoreService.find(uuid); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/SecretController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/SecretController.java index 8b034001..748cc7c1 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/SecretController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/SecretController.java @@ -29,9 +29,9 @@ public ResponseEntity getSecret(@ValidateField @PathVariable(name = "uui @Operation(summary = "Create a secret", description = "Create and return a new secret") @PostMapping( - path = "", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createSecret(@Valid @RequestBody Secret secretDTO) { return ResponseEntity.ok(this.secretService.createProjectSecret(secretDTO)); @@ -39,13 +39,13 @@ public ResponseEntity createSecret(@Valid @RequestBody Secret secretDTO) @Operation(summary = "Update a secret", description = "Update and return a secret") @PutMapping( - path = "/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateSecret( - @Valid @RequestBody Secret functionDTO, - @ValidateField @PathVariable String uuid + @Valid @RequestBody Secret functionDTO, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.secretService.updateProjectSecret(functionDTO, uuid)); } @@ -53,7 +53,7 @@ public ResponseEntity updateSecret( @Operation(summary = "Delete a secret", description = "Delete a specific secret") @DeleteMapping(path = "/{uuid}") public ResponseEntity deleteSecret( - @ValidateField @PathVariable(name = "uuid", required = true) String uuid + @ValidateField @PathVariable(name = "uuid", required = true) String uuid ) { return ResponseEntity.ok(this.secretService.deleteProjectSecret(uuid)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/TaskController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/TaskController.java index d024489e..e04e726e 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/TaskController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/TaskController.java @@ -7,6 +7,7 @@ import it.smartcommunitylabdhub.commons.services.interfaces.TaskService; import it.smartcommunitylabdhub.core.annotations.ApiVersion; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -14,8 +15,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @RequestMapping("/tasks") @ApiVersion("v1") @@ -39,9 +38,9 @@ public ResponseEntity> getTasks(@RequestParam Map fil @Operation(summary = "Create a task", description = "Create and return a new task") @PostMapping( - path = "", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createTask(@Valid @RequestBody Task taskDTO) { return ResponseEntity.ok(this.taskService.createTask(taskDTO)); @@ -49,13 +48,13 @@ public ResponseEntity createTask(@Valid @RequestBody Task taskDTO) { @Operation(summary = "Update a task", description = "Update and return a task") @PutMapping( - path = "/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateTask( - @Valid @RequestBody Task functionDTO, - @ValidateField @PathVariable String uuid + @Valid @RequestBody Task functionDTO, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.taskService.updateTask(functionDTO, uuid)); } @@ -63,8 +62,8 @@ public ResponseEntity updateTask( @Operation(summary = "Delete a task", description = "Delete a specific task") @DeleteMapping(path = "/{uuid}") public ResponseEntity deleteTask( - @ValidateField @PathVariable(name = "uuid", required = true) String uuid, - @RequestParam(name = "cascade", defaultValue = "false") Boolean cascade + @ValidateField @PathVariable(name = "uuid", required = true) String uuid, + @RequestParam(name = "cascade", defaultValue = "false") Boolean cascade ) { return ResponseEntity.ok(this.taskService.deleteTask(uuid, cascade)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/WorkflowController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/WorkflowController.java index e69713b8..2aa32018 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/WorkflowController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/base/WorkflowController.java @@ -8,6 +8,8 @@ import it.smartcommunitylabdhub.commons.services.interfaces.WorkflowService; import it.smartcommunitylabdhub.core.annotations.ApiVersion; import jakarta.validation.Valid; +import java.util.List; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -16,9 +18,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Map; - @RestController @RequestMapping("/workflows") @ApiVersion("v1") @@ -37,9 +36,9 @@ public ResponseEntity> getWorkflows(@RequestParam Map createWorkflow(@Valid @RequestBody Workflow workflowDTO) { return ResponseEntity.ok(this.workflowService.createWorkflow(workflowDTO)); @@ -48,20 +47,20 @@ public ResponseEntity createWorkflow(@Valid @RequestBody Workflow work @Operation(summary = "Get an workflow by uuid", description = "Return an workflow") @GetMapping(path = "/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getWorkflow( - @ValidateField @PathVariable(name = "uuid", required = true) String uuid + @ValidateField @PathVariable(name = "uuid", required = true) String uuid ) { return ResponseEntity.ok(this.workflowService.getWorkflow(uuid)); } @Operation(summary = "Update specific workflow", description = "Update and return the workflow") @PutMapping( - path = "/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + path = "/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateWorkflow( - @Valid @RequestBody Workflow workflowDTO, - @ValidateField @PathVariable String uuid + @Valid @RequestBody Workflow workflowDTO, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.workflowService.updateWorkflow(workflowDTO, uuid)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/ArtifactContextController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/ArtifactContextController.java index 0a6ff1d7..197fdb07 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/ArtifactContextController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/ArtifactContextController.java @@ -7,6 +7,7 @@ import it.smartcommunitylabdhub.core.annotations.ApiVersion; import it.smartcommunitylabdhub.core.services.context.interfaces.ArtifactContextService; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -15,8 +16,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @ApiVersion("v1") @Validated @@ -27,131 +26,131 @@ public class ArtifactContextController extends AbstractContextController { ArtifactContextService artifactContextService; @Operation( - summary = "Create an artifact in a project context", - description = "First check if project exist and then create the artifact for the project (context)" + summary = "Create an artifact in a project context", + description = "First check if project exist and then create the artifact for the project (context)" ) @PostMapping( - value = "/artifacts", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/artifacts", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createArtifact( - @ValidateField @PathVariable String project, - @Valid @RequestBody Artifact artifactDTO + @ValidateField @PathVariable String project, + @Valid @RequestBody Artifact artifactDTO ) { return ResponseEntity.ok(this.artifactContextService.createArtifact(project, artifactDTO)); } @Operation( - summary = "Retrive only the latest version of all artifact", - description = "First check if project exist and then return a list of the latest version of each artifact related to a project)" + summary = "Retrive only the latest version of all artifact", + description = "First check if project exist and then return a list of the latest version of each artifact related to a project)" ) @GetMapping(path = "/artifacts", produces = "application/json; charset=UTF-8") public ResponseEntity> getLatestArtifacts( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + Pageable pageable ) { return ResponseEntity.ok(this.artifactContextService.getLatestByProjectName(filter, project, pageable)); } @Operation( - summary = "Retrieve all versions of the artifact sort by creation", - description = "First check if project exist and then return a list of all version of the artifact sort by creation)" + summary = "Retrieve all versions of the artifact sort by creation", + description = "First check if project exist and then return a list of all version of the artifact sort by creation)" ) @GetMapping(path = "/artifacts/{name}", produces = "application/json; charset=UTF-8") public ResponseEntity> getAllArtifacts( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + Pageable pageable ) { return ResponseEntity.ok( - this.artifactContextService.getByProjectNameAndArtifactName(filter, project, name, pageable) + this.artifactContextService.getByProjectNameAndArtifactName(filter, project, name, pageable) ); } @Operation( - summary = "Retrive a specific artifact version given the artifact uuid", - description = "First check if project exist and then return a specific version of the artifact identified by the uuid)" + summary = "Retrive a specific artifact version given the artifact uuid", + description = "First check if project exist and then return a specific version of the artifact identified by the uuid)" ) @GetMapping(path = "/artifacts/{name}/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getArtifactByUuid( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.artifactContextService.getByProjectAndArtifactAndUuid(project, name, uuid)); } @Operation( - summary = "Retrive the latest version of an artifact", - description = "First check if project exist and then return the latest version of an artifact)" + summary = "Retrive the latest version of an artifact", + description = "First check if project exist and then return the latest version of an artifact)" ) @GetMapping(path = "/artifacts/{name}/latest", produces = "application/json; charset=UTF-8") public ResponseEntity getLatestArtifactByName( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name ) { return ResponseEntity.ok(this.artifactContextService.getLatestByProjectNameAndArtifactName(project, name)); } @Operation( - summary = "Create an or update an artifact in a project context", - description = "First check if project exist, if artifact exist update one otherwise create a new version of the artifact" + summary = "Create an or update an artifact in a project context", + description = "First check if project exist, if artifact exist update one otherwise create a new version of the artifact" ) @PostMapping( - value = "/artifacts/{name}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/artifacts/{name}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createOrUpdateArtifact( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @Valid @RequestBody Artifact artifactDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @Valid @RequestBody Artifact artifactDTO ) { return ResponseEntity.ok(this.artifactContextService.createOrUpdateArtifact(project, name, artifactDTO)); } @Operation( - summary = "Update if exist an artifact in a project context", - description = "First check if project exist, if artifact exist update." + summary = "Update if exist an artifact in a project context", + description = "First check if project exist, if artifact exist update." ) @PutMapping( - value = "/artifacts/{name}/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/artifacts/{name}/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateUpdateArtifact( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid, - @Valid @RequestBody Artifact artifactDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid, + @Valid @RequestBody Artifact artifactDTO ) { return ResponseEntity.ok(this.artifactContextService.updateArtifact(project, name, uuid, artifactDTO)); } @Operation( - summary = "Delete a specific artifact version", - description = "First check if project exist, then delete a specific artifact version" + summary = "Delete a specific artifact version", + description = "First check if project exist, then delete a specific artifact version" ) @DeleteMapping(path = "/artifacts/{name}/{uuid}") public ResponseEntity deleteSpecificArtifactVersion( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.artifactContextService.deleteSpecificArtifactVersion(project, name, uuid)); } @Operation( - summary = "Delete all version of an artifact", - description = "First check if project exist, then delete a specific artifact version" + summary = "Delete all version of an artifact", + description = "First check if project exist, then delete a specific artifact version" ) @DeleteMapping(path = "/artifacts/{name}") public ResponseEntity deleteArtifact( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name ) { return ResponseEntity.ok(this.artifactContextService.deleteAllArtifactVersions(project, name)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/DataItemContextController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/DataItemContextController.java index 38fa94b8..80dd9536 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/DataItemContextController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/DataItemContextController.java @@ -7,6 +7,7 @@ import it.smartcommunitylabdhub.core.annotations.ApiVersion; import it.smartcommunitylabdhub.core.services.context.interfaces.DataItemContextService; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -15,8 +16,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @ApiVersion("v1") @Validated @@ -27,131 +26,131 @@ public class DataItemContextController extends AbstractContextController { DataItemContextService dataItemContextService; @Operation( - summary = "Create an dataItem in a project context", - description = "First check if project exist and then create the dataItem for the project (context)" + summary = "Create an dataItem in a project context", + description = "First check if project exist and then create the dataItem for the project (context)" ) @PostMapping( - value = "/dataitems", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/dataitems", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createDataItem( - @ValidateField @PathVariable String project, - @Valid @RequestBody DataItem dataItemDTO + @ValidateField @PathVariable String project, + @Valid @RequestBody DataItem dataItemDTO ) { return ResponseEntity.ok(this.dataItemContextService.createDataItem(project, dataItemDTO)); } @Operation( - summary = "Retrive only the latest version of all dataItem", - description = "First check if project exist and then return a list of the latest version of each dataItem related to a project)" + summary = "Retrive only the latest version of all dataItem", + description = "First check if project exist and then return a list of the latest version of each dataItem related to a project)" ) @GetMapping(path = "/dataitems", produces = "application/json; charset=UTF-8") public ResponseEntity> getLatestDataItems( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + Pageable pageable ) { return ResponseEntity.ok(this.dataItemContextService.getLatestByProjectName(filter, project, pageable)); } @Operation( - summary = "Retrieve all versions of the dataItem sort by creation", - description = "First check if project exist and then return a list of all version of the dataItem sort by creation)" + summary = "Retrieve all versions of the dataItem sort by creation", + description = "First check if project exist and then return a list of all version of the dataItem sort by creation)" ) @GetMapping(path = "/dataitems/{name}", produces = "application/json; charset=UTF-8") public ResponseEntity> getAllDataItems( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + Pageable pageable ) { return ResponseEntity.ok( - this.dataItemContextService.getByProjectNameAndDataItemName(filter, project, name, pageable) + this.dataItemContextService.getByProjectNameAndDataItemName(filter, project, name, pageable) ); } @Operation( - summary = "Retrive a specific dataItem version given the dataItem uuid", - description = "First check if project exist and then return a specific version of the dataItem identified by the uuid)" + summary = "Retrive a specific dataItem version given the dataItem uuid", + description = "First check if project exist and then return a specific version of the dataItem identified by the uuid)" ) @GetMapping(path = "/dataitems/{name}/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getDataItemByUuid( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.dataItemContextService.getByProjectAndDataItemAndUuid(project, name, uuid)); } @Operation( - summary = "Retrive the latest version of an dataItem", - description = "First check if project exist and then return the latest version of an dataItem)" + summary = "Retrive the latest version of an dataItem", + description = "First check if project exist and then return the latest version of an dataItem)" ) @GetMapping(path = "/dataitems/{name}/latest", produces = "application/json; charset=UTF-8") public ResponseEntity getLatestDataItemByName( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name ) { return ResponseEntity.ok(this.dataItemContextService.getLatestByProjectNameAndDataItemName(project, name)); } @Operation( - summary = "Create an or update an dataItem in a project context", - description = "First check if project exist, if dataItem exist update one otherwise create a new version of the dataItem" + summary = "Create an or update an dataItem in a project context", + description = "First check if project exist, if dataItem exist update one otherwise create a new version of the dataItem" ) @PostMapping( - value = "/dataitems/{name}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/dataitems/{name}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createOrUpdateDataItem( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @Valid @RequestBody DataItem dataItemDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @Valid @RequestBody DataItem dataItemDTO ) { return ResponseEntity.ok(this.dataItemContextService.createOrUpdateDataItem(project, name, dataItemDTO)); } @Operation( - summary = "Update if exist an dataItem in a project context", - description = "First check if project exist, if dataItem exist update." + summary = "Update if exist an dataItem in a project context", + description = "First check if project exist, if dataItem exist update." ) @PutMapping( - value = "/dataitems/{name}/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/dataitems/{name}/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateUpdateDataItem( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid, - @Valid @RequestBody DataItem dataItemDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid, + @Valid @RequestBody DataItem dataItemDTO ) { return ResponseEntity.ok(this.dataItemContextService.updateDataItem(project, name, uuid, dataItemDTO)); } @Operation( - summary = "Delete a specific dataItem version", - description = "First check if project exist, then delete a specific dataItem version" + summary = "Delete a specific dataItem version", + description = "First check if project exist, then delete a specific dataItem version" ) @DeleteMapping(path = "/dataitems/{name}/{uuid}") public ResponseEntity deleteSpecificDataItemVersion( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.dataItemContextService.deleteSpecificDataItemVersion(project, name, uuid)); } @Operation( - summary = "Delete all version of an dataItem", - description = "First check if project exist, then delete a specific dataItem version" + summary = "Delete all version of an dataItem", + description = "First check if project exist, then delete a specific dataItem version" ) @DeleteMapping(path = "/dataitems/{name}") public ResponseEntity deleteDataItem( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name ) { return ResponseEntity.ok(this.dataItemContextService.deleteAllDataItemVersions(project, name)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/FunctionContextController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/FunctionContextController.java index 2bef2bee..5f406439 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/FunctionContextController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/FunctionContextController.java @@ -11,6 +11,8 @@ import it.smartcommunitylabdhub.core.annotations.ApiVersion; import it.smartcommunitylabdhub.core.services.context.interfaces.FunctionContextService; import jakarta.validation.Valid; +import java.util.List; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -19,9 +21,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.List; -import java.util.Map; - @RestController @ApiVersion("v1") @Validated @@ -38,119 +37,119 @@ public class FunctionContextController extends AbstractContextController { RunService runService; @Operation( - summary = "Create an function in a project context", - description = "First check if project exist and then create the function for the project (context)" + summary = "Create an function in a project context", + description = "First check if project exist and then create the function for the project (context)" ) @PostMapping( - value = "/functions", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/functions", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createFunction( - @ValidateField @PathVariable String project, - @Valid @RequestBody Function functionDTO + @ValidateField @PathVariable String project, + @Valid @RequestBody Function functionDTO ) { return ResponseEntity.ok(this.functionContextService.createFunction(project, functionDTO)); } @Operation( - summary = "Retrive only the latest version of all function", - description = "First check if project exist and then return a list of the latest version of each function related to a project)" + summary = "Retrive only the latest version of all function", + description = "First check if project exist and then return a list of the latest version of each function related to a project)" ) @GetMapping(path = "/functions", produces = "application/json; charset=UTF-8") public ResponseEntity> getLatestFunctions( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + Pageable pageable ) { return ResponseEntity.ok(this.functionContextService.getLatestByProjectName(filter, project, pageable)); } @Operation( - summary = "Retrieve all versions of the function sort by creation", - description = "First check if project exist and then return a list of all version of the function sort by creation)" + summary = "Retrieve all versions of the function sort by creation", + description = "First check if project exist and then return a list of all version of the function sort by creation)" ) @GetMapping(path = "/functions/{name}", produces = "application/json; charset=UTF-8") public ResponseEntity> getAllFunctions( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + Pageable pageable ) { return ResponseEntity.ok( - this.functionContextService.getByProjectNameAndFunctionName(filter, project, name, pageable) + this.functionContextService.getByProjectNameAndFunctionName(filter, project, name, pageable) ); } @Operation( - summary = "Retrive a specific function version given the function uuid", - description = "First check if project exist and then return a specific version of the function identified by the uuid)" + summary = "Retrive a specific function version given the function uuid", + description = "First check if project exist and then return a specific version of the function identified by the uuid)" ) @GetMapping(path = "/functions/{name}/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getFunctionByUuid( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.functionContextService.getByProjectAndFunctionAndUuid(project, name, uuid)); } @Operation( - summary = "Retrive the latest version of an function", - description = "First check if project exist and then return the latest version of an function)" + summary = "Retrive the latest version of an function", + description = "First check if project exist and then return the latest version of an function)" ) @GetMapping(path = "/functions/{name}/latest", produces = "application/json; charset=UTF-8") public ResponseEntity getLatestFunctionByName( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name ) { return ResponseEntity.ok(this.functionContextService.getLatestByProjectNameAndFunctionName(project, name)); } @Operation( - summary = "Create an or update an function in a project context", - description = "First check if project exist, if function exist update one otherwise create a new version of the function" + summary = "Create an or update an function in a project context", + description = "First check if project exist, if function exist update one otherwise create a new version of the function" ) @PostMapping( - value = "/functions/{name}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/functions/{name}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createOrUpdateFunction( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @Valid @RequestBody Function functionDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @Valid @RequestBody Function functionDTO ) { return ResponseEntity.ok(this.functionContextService.createOrUpdateFunction(project, name, functionDTO)); } @Operation( - summary = "Update if exist an function in a project context", - description = "First check if project exist, if function exist update." + summary = "Update if exist an function in a project context", + description = "First check if project exist, if function exist update." ) @PutMapping( - value = "/functions/{name}/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/functions/{name}/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateUpdateFunction( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid, - @Valid @RequestBody Function functionDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid, + @Valid @RequestBody Function functionDTO ) { return ResponseEntity.ok(this.functionContextService.updateFunction(project, name, uuid, functionDTO)); } @Operation( - summary = "Delete a specific function version", - description = "First check if project exist, then delete a specific function version" + summary = "Delete a specific function version", + description = "First check if project exist, then delete a specific function version" ) @DeleteMapping(path = "/functions/{name}/{uuid}") public ResponseEntity deleteSpecificFunctionVersion( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid ) { // Get function Function function = this.functionContextService.getByUuid(project, uuid); @@ -171,27 +170,27 @@ public ResponseEntity deleteSpecificFunctionVersion( } @Operation( - summary = "Delete all version of an function", - description = "First check if project exist, then delete a specific function version" + summary = "Delete all version of an function", + description = "First check if project exist, then delete a specific function version" ) @DeleteMapping(path = "/functions/{name}") public ResponseEntity deleteFunction( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name ) { this.functionContextService.listByProjectNameAndFunctionName(project, name) - .forEach(function -> { - // Remove Task - List taskList = this.taskService.getTasksByFunction(TaskUtils.buildTaskString(function)); - //Delete all related object - taskList.forEach(task -> { - // remove run - this.runService.deleteRunByTaskId(task.getId()); - - // remove task - this.taskService.deleteTask(task.getId(), false); - }); + .forEach(function -> { + // Remove Task + List taskList = this.taskService.getTasksByFunction(TaskUtils.buildTaskString(function)); + //Delete all related object + taskList.forEach(task -> { + // remove run + this.runService.deleteRunByTaskId(task.getId()); + + // remove task + this.taskService.deleteTask(task.getId(), false); }); + }); return ResponseEntity.ok(this.functionContextService.deleteAllFunctionVersions(project, name)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/RunContextController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/RunContextController.java index 2da1d50a..fc4e0aec 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/RunContextController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/RunContextController.java @@ -8,6 +8,7 @@ import it.smartcommunitylabdhub.core.annotations.ApiVersion; import it.smartcommunitylabdhub.core.services.context.interfaces.RunContextService; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -16,8 +17,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @ApiVersion("v1") @Validated @@ -26,74 +25,73 @@ public class RunContextController extends AbstractContextController { @Autowired RunContextService RunContextService; - @Autowired RunService runService; @Operation( - summary = "Create a Run in a project context", - description = "First check if project exist and then create the Run for the project (context)" + summary = "Create a Run in a project context", + description = "First check if project exist and then create the Run for the project (context)" ) @PostMapping( - value = "/runs", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/runs", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createRun(@ValidateField @PathVariable String project, @Valid @RequestBody Run RunDTO) { return ResponseEntity.ok(this.RunContextService.createRun(project, RunDTO)); } @Operation( - summary = "Retrive only the latest version of all Run", - description = "First check if project exist and then return a list of Runs related with the project)" + summary = "Retrive only the latest version of all Run", + description = "First check if project exist and then return a list of Runs related with the project)" ) @GetMapping(path = "/runs", produces = "application/json; charset=UTF-8") public ResponseEntity> getLatestRuns( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + Pageable pageable ) { return ResponseEntity.ok(this.RunContextService.getAllRunsByProjectName(filter, project, pageable)); } @Operation( - summary = "Retrieve a specific Run given the Run uuid", - description = "First check if project exist and then return a specific version of the Run identified by the uuid)" + summary = "Retrieve a specific Run given the Run uuid", + description = "First check if project exist and then return a specific version of the Run identified by the uuid)" ) @GetMapping(path = "/runs/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getRunByUuid( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.RunContextService.getByProjectAndRunUuid(project, uuid)); } @Operation( - summary = "Update if exist a Run in a project context", - description = "First check if project exist, if Run exist update." + summary = "Update if exist a Run in a project context", + description = "First check if project exist, if Run exist update." ) @PutMapping( - value = "/runs/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/runs/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateUpdateRun( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String uuid, - @Valid @RequestBody Run RunDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String uuid, + @Valid @RequestBody Run RunDTO ) { return ResponseEntity.ok(this.RunContextService.updateRun(project, uuid, RunDTO)); } @Operation( - summary = "Delete a specific Run version", - description = "First check if project exist, then delete a specific Run version" + summary = "Delete a specific Run version", + description = "First check if project exist, then delete a specific Run version" ) @DeleteMapping(path = "/runs/{uuid}") public ResponseEntity deleteSpecificRunVersion( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String uuid ) { // Remove Run and return return ResponseEntity.ok(this.RunContextService.deleteSpecificRunVersion(project, uuid)); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/SecretContextController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/SecretContextController.java index d2d84d1c..65948ec6 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/SecretContextController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/SecretContextController.java @@ -8,6 +8,7 @@ import it.smartcommunitylabdhub.core.annotations.ApiVersion; import it.smartcommunitylabdhub.core.services.context.interfaces.SecretContextService; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -16,8 +17,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @ApiVersion("v1") @Validated @@ -31,71 +30,71 @@ public class SecretContextController extends AbstractContextController { RunService runService; @Operation( - summary = "Create a secret in a project context", - description = "First check if project exist and then create the secret for the project (context)" + summary = "Create a secret in a project context", + description = "First check if project exist and then create the secret for the project (context)" ) @PostMapping( - value = "/secrets", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/secrets", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createSecret( - @ValidateField @PathVariable String project, - @Valid @RequestBody Secret secretDTO + @ValidateField @PathVariable String project, + @Valid @RequestBody Secret secretDTO ) { return ResponseEntity.ok(this.secretContextService.createSecret(project, secretDTO)); } @Operation( - summary = "Retrive only the latest version of all secret", - description = "First check if project exist and then return a list of secrets related with the project)" + summary = "Retrive only the latest version of all secret", + description = "First check if project exist and then return a list of secrets related with the project)" ) @GetMapping(path = "/secrets", produces = "application/json; charset=UTF-8") public ResponseEntity> getLatestSecrets( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + Pageable pageable ) { return ResponseEntity.ok(this.secretContextService.getAllSecretsByProjectName(filter, project, pageable)); } @Operation( - summary = "Retrieve a specific secret given the secret uuid", - description = "First check if project exist and then return a specific version of the secret identified by the uuid)" + summary = "Retrieve a specific secret given the secret uuid", + description = "First check if project exist and then return a specific version of the secret identified by the uuid)" ) @GetMapping(path = "/secrets/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getSecretByUuid( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.secretContextService.getByProjectAndSecretUuid(project, uuid)); } @Operation( - summary = "Update if exist a secret in a project context", - description = "First check if project exist, if secret exist update." + summary = "Update if exist a secret in a project context", + description = "First check if project exist, if secret exist update." ) @PutMapping( - value = "/secrets/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/secrets/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateUpdateSecret( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String uuid, - @Valid @RequestBody Secret secretDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String uuid, + @Valid @RequestBody Secret secretDTO ) { return ResponseEntity.ok(this.secretContextService.updateSecret(project, uuid, secretDTO)); } @Operation( - summary = "Delete a specific secret version", - description = "First check if project exist, then delete a specific secret version" + summary = "Delete a specific secret version", + description = "First check if project exist, then delete a specific secret version" ) @DeleteMapping(path = "/secrets/{uuid}") public ResponseEntity deleteSpecificSecretVersion( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String uuid ) { // Remove secret and return return ResponseEntity.ok(this.secretContextService.deleteSpecificSecretVersion(project, uuid)); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/TaskContextController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/TaskContextController.java index b5709530..9a85b857 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/TaskContextController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/TaskContextController.java @@ -8,6 +8,7 @@ import it.smartcommunitylabdhub.core.annotations.ApiVersion; import it.smartcommunitylabdhub.core.services.context.interfaces.TaskContextService; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -16,8 +17,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @ApiVersion("v1") @Validated @@ -27,76 +26,75 @@ public class TaskContextController extends AbstractContextController { @Autowired TaskContextService taskContextService; - @Autowired RunService runService; @Operation( - summary = "Create a task in a project context", - description = "First check if project exist and then create the task for the project (context)" + summary = "Create a task in a project context", + description = "First check if project exist and then create the task for the project (context)" ) @PostMapping( - value = "/tasks", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/tasks", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createTask( - @ValidateField @PathVariable String project, - @Valid @RequestBody Task taskDTO + @ValidateField @PathVariable String project, + @Valid @RequestBody Task taskDTO ) { return ResponseEntity.ok(this.taskContextService.createTask(project, taskDTO)); } @Operation( - summary = "Retrive only the latest version of all task", - description = "First check if project exist and then return a list of tasks related with the project)" + summary = "Retrive only the latest version of all task", + description = "First check if project exist and then return a list of tasks related with the project)" ) @GetMapping(path = "/tasks", produces = "application/json; charset=UTF-8") public ResponseEntity> getLatestTasks( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + Pageable pageable ) { return ResponseEntity.ok(this.taskContextService.getAllTasksByProjectName(filter, project, pageable)); } @Operation( - summary = "Retrieve a specific task given the task uuid", - description = "First check if project exist and then return a specific version of the task identified by the uuid)" + summary = "Retrieve a specific task given the task uuid", + description = "First check if project exist and then return a specific version of the task identified by the uuid)" ) @GetMapping(path = "/tasks/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getTaskByUuid( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.taskContextService.getByProjectAndTaskUuid(project, uuid)); } @Operation( - summary = "Update if exist a task in a project context", - description = "First check if project exist, if task exist update." + summary = "Update if exist a task in a project context", + description = "First check if project exist, if task exist update." ) @PutMapping( - value = "/tasks/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/tasks/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateUpdateTask( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String uuid, - @Valid @RequestBody Task taskDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String uuid, + @Valid @RequestBody Task taskDTO ) { return ResponseEntity.ok(this.taskContextService.updateTask(project, uuid, taskDTO)); } @Operation( - summary = "Delete a specific task version", - description = "First check if project exist, then delete a specific task version" + summary = "Delete a specific task version", + description = "First check if project exist, then delete a specific task version" ) @DeleteMapping(path = "/tasks/{uuid}") public ResponseEntity deleteSpecificTaskVersion( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String uuid ) { // Remove task and return return ResponseEntity.ok(this.taskContextService.deleteSpecificTaskVersion(project, uuid)); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/WorkflowContextController.java b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/WorkflowContextController.java index 837f3844..c6dad7cb 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/WorkflowContextController.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/controllers/v1/context/WorkflowContextController.java @@ -7,6 +7,7 @@ import it.smartcommunitylabdhub.core.annotations.ApiVersion; import it.smartcommunitylabdhub.core.services.context.interfaces.WorkflowContextService; import jakarta.validation.Valid; +import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -15,8 +16,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import java.util.Map; - @RestController @ApiVersion("v1") @Validated @@ -27,131 +26,131 @@ public class WorkflowContextController extends AbstractContextController { WorkflowContextService workflowContextService; @Operation( - summary = "Create an workflow in a project context", - description = "First check if project exist and then create the workflow for the project (context)" + summary = "Create an workflow in a project context", + description = "First check if project exist and then create the workflow for the project (context)" ) @PostMapping( - value = "/workflows", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/workflows", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createWorkflow( - @ValidateField @PathVariable String project, - @Valid @RequestBody Workflow workflowDTO + @ValidateField @PathVariable String project, + @Valid @RequestBody Workflow workflowDTO ) { return ResponseEntity.ok(this.workflowContextService.createWorkflow(project, workflowDTO)); } @Operation( - summary = "Retrive only the latest version of all workflow", - description = "First check if project exist and then return a list of the latest version of each workflow related to a project)" + summary = "Retrive only the latest version of all workflow", + description = "First check if project exist and then return a list of the latest version of each workflow related to a project)" ) @GetMapping(path = "/workflows", produces = "application/json; charset=UTF-8") public ResponseEntity> getLatestWorkflows( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + Pageable pageable ) { return ResponseEntity.ok(this.workflowContextService.getLatestByProjectName(filter, project, pageable)); } @Operation( - summary = "Retrieve all versions of the workflow sort by creation", - description = "First check if project exist and then return a list of all version of the workflow sort by creation)" + summary = "Retrieve all versions of the workflow sort by creation", + description = "First check if project exist and then return a list of all version of the workflow sort by creation)" ) @GetMapping(path = "/workflows/{name}", produces = "application/json; charset=UTF-8") public ResponseEntity> getAllWorkflows( - @RequestParam Map filter, - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - Pageable pageable + @RequestParam Map filter, + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + Pageable pageable ) { return ResponseEntity.ok( - this.workflowContextService.getByProjectNameAndWorkflowName(filter, project, name, pageable) + this.workflowContextService.getByProjectNameAndWorkflowName(filter, project, name, pageable) ); } @Operation( - summary = "Retrive a specific workflow version given the workflow uuid", - description = "First check if project exist and then return a specific version of the workflow identified by the uuid)" + summary = "Retrive a specific workflow version given the workflow uuid", + description = "First check if project exist and then return a specific version of the workflow identified by the uuid)" ) @GetMapping(path = "/workflows/{name}/{uuid}", produces = "application/json; charset=UTF-8") public ResponseEntity getWorkflowByUuid( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.workflowContextService.getByProjectAndWorkflowAndUuid(project, name, uuid)); } @Operation( - summary = "Retrive the latest version of an workflow", - description = "First check if project exist and then return the latest version of an workflow)" + summary = "Retrive the latest version of an workflow", + description = "First check if project exist and then return the latest version of an workflow)" ) @GetMapping(path = "/workflows/{name}/latest", produces = "application/json; charset=UTF-8") public ResponseEntity getLatestWorkflowByName( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name ) { return ResponseEntity.ok(this.workflowContextService.getLatestByProjectNameAndWorkflowName(project, name)); } @Operation( - summary = "Create an or update an workflow in a project context", - description = "First check if project exist, if workflow exist update one otherwise create a new version of the workflow" + summary = "Create an or update an workflow in a project context", + description = "First check if project exist, if workflow exist update one otherwise create a new version of the workflow" ) @PostMapping( - value = "/workflows/{name}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/workflows/{name}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity createOrUpdateWorkflow( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @Valid @RequestBody Workflow workflowDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @Valid @RequestBody Workflow workflowDTO ) { return ResponseEntity.ok(this.workflowContextService.createOrUpdateWorkflow(project, name, workflowDTO)); } @Operation( - summary = "Update if exist an workflow in a project context", - description = "First check if project exist, if workflow exist update." + summary = "Update if exist an workflow in a project context", + description = "First check if project exist, if workflow exist update." ) @PutMapping( - value = "/workflows/{name}/{uuid}", - consumes = {MediaType.APPLICATION_JSON_VALUE, "application/x-yaml"}, - produces = "application/json; charset=UTF-8" + value = "/workflows/{name}/{uuid}", + consumes = { MediaType.APPLICATION_JSON_VALUE, "application/x-yaml" }, + produces = "application/json; charset=UTF-8" ) public ResponseEntity updateUpdateWorkflow( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid, - @Valid @RequestBody Workflow workflowDTO + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid, + @Valid @RequestBody Workflow workflowDTO ) { return ResponseEntity.ok(this.workflowContextService.updateWorkflow(project, name, uuid, workflowDTO)); } @Operation( - summary = "Delete a specific workflow version", - description = "First check if project exist, then delete a specific workflow version" + summary = "Delete a specific workflow version", + description = "First check if project exist, then delete a specific workflow version" ) @DeleteMapping(path = "/workflows/{name}/{uuid}") public ResponseEntity deleteSpecificWorkflowVersion( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name, - @ValidateField @PathVariable String uuid + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name, + @ValidateField @PathVariable String uuid ) { return ResponseEntity.ok(this.workflowContextService.deleteSpecificWorkflowVersion(project, name, uuid)); } @Operation( - summary = "Delete all version of an workflow", - description = "First check if project exist, then delete a specific workflow version" + summary = "Delete all version of an workflow", + description = "First check if project exist, then delete a specific workflow version" ) @DeleteMapping(path = "/workflows/{name}") public ResponseEntity deleteWorkflow( - @ValidateField @PathVariable String project, - @ValidateField @PathVariable String name + @ValidateField @PathVariable String project, + @ValidateField @PathVariable String name ) { return ResponseEntity.ok(this.workflowContextService.deleteAllWorkflowVersions(project, name)); } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/models/queries/filters/entities/SecretEntityFilter.java b/application/src/main/java/it/smartcommunitylabdhub/core/models/queries/filters/entities/SecretEntityFilter.java index d8482a45..54462bc4 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/models/queries/filters/entities/SecretEntityFilter.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/models/queries/filters/entities/SecretEntityFilter.java @@ -16,7 +16,6 @@ @Setter public class SecretEntityFilter extends BaseEntityFilter implements SpecificationFilter { - @Override public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) { Predicate predicate = criteriaBuilder.conjunction(); @@ -36,10 +35,10 @@ public Predicate toPredicate(Root root, CriteriaQuery query, Cr if (getCreatedDate() != null) { DateUtils.DateInterval dateInterval = DateUtils.parseDateIntervalFromTimestamps(getCreatedDate(), true); predicate = - criteriaBuilder.and( - predicate, - criteriaBuilder.between(root.get("created"), dateInterval.startDate(), dateInterval.endDate()) - ); + criteriaBuilder.and( + predicate, + criteriaBuilder.between(root.get("created"), dateInterval.startDate(), dateInterval.endDate()) + ); } return predicate; diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/services/RunServiceImpl.java b/application/src/main/java/it/smartcommunitylabdhub/core/services/RunServiceImpl.java index e4595ab7..ef69d93d 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/services/RunServiceImpl.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/services/RunServiceImpl.java @@ -26,6 +26,11 @@ import it.smartcommunitylabdhub.core.models.queries.filters.entities.RunEntityFilter; import it.smartcommunitylabdhub.core.repositories.RunRepository; import jakarta.transaction.Transactional; +import java.util.Map; +import java.util.Optional; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Page; @@ -35,12 +40,6 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import java.util.Map; -import java.util.Optional; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; - @Service @Transactional public class RunServiceImpl extends AbstractSpecificationService implements RunService { @@ -83,9 +82,9 @@ public Page getRuns(Map filter, Pageable pageable) { runEntityFilter.setKind(filter.get("kind")); runEntityFilter.setCreatedDate(filter.get("created")); Optional stateOptional = Stream - .of(RunState.values()) - .filter(state -> state.name().equals(filter.get("state"))) - .findAny(); + .of(RunState.values()) + .filter(state -> state.name().equals(filter.get("state"))) + .findAny(); runEntityFilter.setState(stateOptional.map(Enum::name).orElse(null)); Specification specification = createSpecification(filter, runEntityFilter); @@ -93,15 +92,15 @@ public Page getRuns(Map filter, Pageable pageable) { Page runPage = this.runRepository.findAll(specification, pageable); return new PageImpl<>( - runPage.getContent().stream().map(run -> runDTOBuilder.build(run)).collect(Collectors.toList()), - pageable, - runPage.getTotalElements() + runPage.getContent().stream().map(run -> runDTOBuilder.build(run)).collect(Collectors.toList()), + pageable, + runPage.getTotalElements() ); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -109,15 +108,15 @@ public Page getRuns(Map filter, Pageable pageable) { @Override public Run getRun(String uuid) { return runRepository - .findById(uuid) - .map(run -> runDTOBuilder.build(run)) - .orElseThrow(() -> - new CoreException( - ErrorList.RUN_NOT_FOUND.getValue(), - ErrorList.RUN_NOT_FOUND.getReason(), - HttpStatus.NOT_FOUND - ) - ); + .findById(uuid) + .map(run -> runDTOBuilder.build(run)) + .orElseThrow(() -> + new CoreException( + ErrorList.RUN_NOT_FOUND.getValue(), + ErrorList.RUN_NOT_FOUND.getReason(), + HttpStatus.NOT_FOUND + ) + ); } @Override @@ -127,9 +126,9 @@ public boolean deleteRun(String uuid, Boolean cascade) { return true; } catch (Exception e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "cannot delete artifact", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "cannot delete artifact", + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -141,9 +140,9 @@ public boolean deleteRunByTaskId(String uuid) { return true; } catch (Exception e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "cannot delete artifact", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "cannot delete artifact", + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -151,28 +150,28 @@ public boolean deleteRunByTaskId(String uuid) { @Override public Run save(Run runDTO) { return Optional - .of(this.runRepository.saveAndFlush(runEntityBuilder.build(runDTO))) - .map(run -> runDTOBuilder.build(run)) - .orElseThrow(() -> new CoreException("RunSaveError", "Problem while saving the run.", HttpStatus.NOT_FOUND) - ); + .of(this.runRepository.saveAndFlush(runEntityBuilder.build(runDTO))) + .map(run -> runDTOBuilder.build(run)) + .orElseThrow(() -> new CoreException("RunSaveError", "Problem while saving the run.", HttpStatus.NOT_FOUND) + ); } @Override public Run updateRun(Run runDTO, String uuid) { if (!runDTO.getId().equals(uuid)) { throw new CoreException( - ErrorList.RUN_NOT_MATCH.getValue(), - ErrorList.RUN_NOT_MATCH.getReason(), - HttpStatus.NOT_FOUND + ErrorList.RUN_NOT_MATCH.getValue(), + ErrorList.RUN_NOT_MATCH.getReason(), + HttpStatus.NOT_FOUND ); } final RunEntity run = runRepository.findById(uuid).orElse(null); if (run == null) { throw new CoreException( - ErrorList.RUN_NOT_FOUND.getValue(), - ErrorList.RUN_NOT_FOUND.getReason(), - HttpStatus.NOT_FOUND + ErrorList.RUN_NOT_FOUND.getValue(), + ErrorList.RUN_NOT_FOUND.getReason(), + HttpStatus.NOT_FOUND ); } @@ -182,9 +181,9 @@ public Run updateRun(Run runDTO, String uuid) { return runDTOBuilder.build(runUpdated); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -197,100 +196,102 @@ public Run createRun(Run runDTO) { // Check if run already exist with the passed uuid if (runRepository.existsById(Optional.ofNullable(runDTO.getId()).orElse(""))) { throw new CoreException( - ErrorList.DUPLICATE_RUN.getValue(), - ErrorList.DUPLICATE_RUN.getReason(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.DUPLICATE_RUN.getValue(), + ErrorList.DUPLICATE_RUN.getReason(), + HttpStatus.INTERNAL_SERVER_ERROR ); } // Retrieve task return Optional - .ofNullable(this.taskService.getTask(runBaseSpec.getTaskId())) - .map(taskDTO -> { - - TaskBaseSpec taskBaseSpec = specRegistry.createSpec( - taskDTO.getKind(), - EntityName.TASK, - taskDTO.getSpec() - ); + .ofNullable(this.taskService.getTask(runBaseSpec.getTaskId())) + .map(taskDTO -> { + TaskBaseSpec taskBaseSpec = specRegistry.createSpec( + taskDTO.getKind(), + EntityName.TASK, + taskDTO.getSpec() + ); - // Parse task to get accessor - TaskAccessor taskAccessor = TaskUtils.parseTask(taskBaseSpec.getFunction()); - - return Optional - .ofNullable(functionService.getFunction(taskAccessor.getVersion())) - .map(functionDTO -> { - // Update spec object for run - runDTO.setProject(taskAccessor.getProject()); - - // Check weather the run has local set to True in that case return - // immediately the run without invoke the execution. - Supplier result = () -> - Optional - .of(runBaseSpec.getLocalExecution()) // if true save and return - .filter(value -> value.equals(true)) - .map(value -> { - // Save the run and return immediately - RunEntity run = runRepository.saveAndFlush(runEntityBuilder.build(runDTO)); - return runDTOBuilder.build(run); - }) - // exec run and return run dto - .orElseGet(() -> { - // Retrieve Runtime and build run - Runtime runtime = - runtimeFactory.getRuntime(taskAccessor.getRuntime()); - - // Build RunSpec using Runtime now if wrong type is passed to a specific runtime - // an exception occur! for. - RunBaseSpec runSpecBuilt = runtime.build( - specRegistry.createSpec( - functionDTO.getKind(), - EntityName.FUNCTION, - functionDTO.getSpec() - ), - taskBaseSpec, - runBaseSpec, - taskDTO.getKind() - ); - - // Update run spec - runDTO.setSpec(runSpecBuilt.toMap()); - - // Update run state to BUILT - runDTO.getStatus().put("state", RunState.BUILT.toString()); - - // Save Run - RunEntity run = runRepository.saveAndFlush(runEntityBuilder.build(runDTO)); - - // Create Runnable - Runnable runnable = runtime.run(runDTOBuilder.build(run)); - - // Store runnable - runnableStoreService.store(runnable.getId(), runnable); - - // Dispatch Runnable - eventPublisher.publishEvent(runnable); - - // Return saved run - return runDTOBuilder.build(run); - }); - - return result.get(); - }) - .orElseThrow(() -> - new CoreException( - ErrorList.FUNCTION_NOT_FOUND.getValue(), - ErrorList.FUNCTION_NOT_FOUND.getReason(), - HttpStatus.NOT_FOUND - ) - ); - }) - .orElseThrow(() -> + // Parse task to get accessor + TaskAccessor taskAccessor = TaskUtils.parseTask(taskBaseSpec.getFunction()); + + return Optional + .ofNullable(functionService.getFunction(taskAccessor.getVersion())) + .map(functionDTO -> { + // Update spec object for run + runDTO.setProject(taskAccessor.getProject()); + + // Check weather the run has local set to True in that case return + // immediately the run without invoke the execution. + Supplier result = () -> + Optional + .of(runBaseSpec.getLocalExecution()) // if true save and return + .filter(value -> value.equals(true)) + .map(value -> { + // Save the run and return immediately + RunEntity run = runRepository.saveAndFlush(runEntityBuilder.build(runDTO)); + return runDTOBuilder.build(run); + }) + // exec run and return run dto + .orElseGet(() -> { + // Retrieve Runtime and build run + Runtime< + ? extends FunctionBaseSpec, + ? extends RunBaseSpec, + ? extends Runnable + > runtime = runtimeFactory.getRuntime(taskAccessor.getRuntime()); + + // Build RunSpec using Runtime now if wrong type is passed to a specific runtime + // an exception occur! for. + RunBaseSpec runSpecBuilt = runtime.build( + specRegistry.createSpec( + functionDTO.getKind(), + EntityName.FUNCTION, + functionDTO.getSpec() + ), + taskBaseSpec, + runBaseSpec, + taskDTO.getKind() + ); + + // Update run spec + runDTO.setSpec(runSpecBuilt.toMap()); + + // Update run state to BUILT + runDTO.getStatus().put("state", RunState.BUILT.toString()); + + // Save Run + RunEntity run = runRepository.saveAndFlush(runEntityBuilder.build(runDTO)); + + // Create Runnable + Runnable runnable = runtime.run(runDTOBuilder.build(run)); + + // Store runnable + runnableStoreService.store(runnable.getId(), runnable); + + // Dispatch Runnable + eventPublisher.publishEvent(runnable); + + // Return saved run + return runDTOBuilder.build(run); + }); + + return result.get(); + }) + .orElseThrow(() -> new CoreException( - ErrorList.RUN_NOT_FOUND.getValue(), - ErrorList.RUN_NOT_FOUND.getReason(), - HttpStatus.NOT_FOUND + ErrorList.FUNCTION_NOT_FOUND.getValue(), + ErrorList.FUNCTION_NOT_FOUND.getReason(), + HttpStatus.NOT_FOUND ) - ); + ); + }) + .orElseThrow(() -> + new CoreException( + ErrorList.RUN_NOT_FOUND.getValue(), + ErrorList.RUN_NOT_FOUND.getReason(), + HttpStatus.NOT_FOUND + ) + ); } } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/ArtifactContextServiceImpl.java b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/ArtifactContextServiceImpl.java index f4d97ac7..f8eab3f3 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/ArtifactContextServiceImpl.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/ArtifactContextServiceImpl.java @@ -12,6 +12,10 @@ import it.smartcommunitylabdhub.core.repositories.ArtifactRepository; import it.smartcommunitylabdhub.core.services.context.interfaces.ArtifactContextService; import jakarta.transaction.Transactional; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -20,16 +24,11 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - @Service @Transactional public class ArtifactContextServiceImpl - extends ContextService - implements ArtifactContextService { + extends ContextService + implements ArtifactContextService { @Autowired ArtifactRepository artifactRepository; @@ -58,22 +57,22 @@ public Artifact createArtifact(String projectName, Artifact artifactDTO) { // Check if artifact already exist if exist throw exception otherwise create a // new one ArtifactEntity artifact = (ArtifactEntity) Optional - .ofNullable(artifactDTO.getId()) - .flatMap(id -> - artifactRepository - .findById(id) - .map(a -> { - throw new CustomException( - "The project already contains an artifact with the specified UUID.", - null - ); - }) - ) - .orElseGet(() -> { - // Build an artifact and store it in the database - ArtifactEntity newArtifact = artifactEntityBuilder.build(artifactDTO); - return artifactRepository.saveAndFlush(newArtifact); - }); + .ofNullable(artifactDTO.getId()) + .flatMap(id -> + artifactRepository + .findById(id) + .map(a -> { + throw new CustomException( + "The project already contains an artifact with the specified UUID.", + null + ); + }) + ) + .orElseGet(() -> { + // Build an artifact and store it in the database + ArtifactEntity newArtifact = artifactEntityBuilder.build(artifactDTO); + return artifactRepository.saveAndFlush(newArtifact); + }); // Return artifact DTO return artifactDTOBuilder.build(artifact, artifact.getEmbedded()); @@ -91,30 +90,30 @@ public Page getLatestByProjectName(Map filter, String artifactEntityFilter.setName(filter.get("name")); artifactEntityFilter.setKind(filter.get("kind")); Optional stateOptional = Stream - .of(State.values()) - .filter(state -> state.name().equals(filter.get("state"))) - .findAny(); + .of(State.values()) + .filter(state -> state.name().equals(filter.get("state"))) + .findAny(); artifactEntityFilter.setState(stateOptional.map(Enum::name).orElse(null)); Specification specification = createSpecification(filter, artifactEntityFilter) - .and(CommonSpecification.latestByProject(projectName)); + .and(CommonSpecification.latestByProject(projectName)); Page artifactPage = artifactRepository.findAll( - Specification - .where(specification) - .and((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("project"), projectName)), - pageable + Specification + .where(specification) + .and((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("project"), projectName)), + pageable ); return new PageImpl<>( - artifactPage - .getContent() - .stream() - .map(artifact -> artifactDTOBuilder.build(artifact, artifact.getEmbedded())) - .collect(Collectors.toList()), - pageable, - artifactPage.getTotalElements() + artifactPage + .getContent() + .stream() + .map(artifact -> artifactDTOBuilder.build(artifact, artifact.getEmbedded())) + .collect(Collectors.toList()), + pageable, + artifactPage.getTotalElements() ); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); @@ -123,10 +122,10 @@ public Page getLatestByProjectName(Map filter, String @Override public Page getByProjectNameAndArtifactName( - Map filter, - String projectName, - String artifactName, - Pageable pageable + Map filter, + String projectName, + String artifactName, + Pageable pageable ) { try { checkContext(projectName); @@ -134,36 +133,36 @@ public Page getByProjectNameAndArtifactName( artifactEntityFilter.setCreatedDate(filter.get("created")); artifactEntityFilter.setKind(filter.get("kind")); Optional stateOptional = Stream - .of(State.values()) - .filter(state -> state.name().equals(filter.get("state"))) - .findAny(); + .of(State.values()) + .filter(state -> state.name().equals(filter.get("state"))) + .findAny(); artifactEntityFilter.setState(stateOptional.map(Enum::name).orElse(null)); Specification specification = createSpecification(filter, artifactEntityFilter); Page artifactPage = artifactRepository.findAll( - Specification - .where(specification) - .and((root, query, criteriaBuilder) -> - criteriaBuilder.and( - criteriaBuilder.equal(root.get("project"), projectName), - criteriaBuilder.equal(root.get("name"), artifactName) - ) - ), - pageable + Specification + .where(specification) + .and((root, query, criteriaBuilder) -> + criteriaBuilder.and( + criteriaBuilder.equal(root.get("project"), projectName), + criteriaBuilder.equal(root.get("name"), artifactName) + ) + ), + pageable ); return new PageImpl<>( - artifactPage - .getContent() - .stream() - .map(artifact -> { - return artifactDTOBuilder.build(artifact, artifact.getEmbedded()); - }) - .collect(Collectors.toList()), - pageable, - artifactPage.getTotalElements() + artifactPage + .getContent() + .stream() + .map(artifact -> { + return artifactDTOBuilder.build(artifact, artifact.getEmbedded()); + }) + .collect(Collectors.toList()), + pageable, + artifactPage.getTotalElements() ); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); @@ -177,8 +176,8 @@ public Artifact getByProjectAndArtifactAndUuid(String projectName, String artifa checkContext(projectName); return this.artifactRepository.findByProjectAndNameAndId(projectName, artifactName, uuid) - .map(artifact -> artifactDTOBuilder.build(artifact, artifact.getEmbedded())) - .orElseThrow(() -> new CustomException("The artifact does not exist.", null)); + .map(artifact -> artifactDTOBuilder.build(artifact, artifact.getEmbedded())) + .orElseThrow(() -> new CustomException("The artifact does not exist.", null)); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } @@ -191,8 +190,8 @@ public Artifact getLatestByProjectNameAndArtifactName(String projectName, String checkContext(projectName); return this.artifactRepository.findLatestArtifactByProjectAndName(projectName, artifactName) - .map(artifact -> artifactDTOBuilder.build(artifact, artifact.getEmbedded())) - .orElseThrow(() -> new CustomException("The artifact does not exist.", null)); + .map(artifact -> artifactDTOBuilder.build(artifact, artifact.getEmbedded())) + .orElseThrow(() -> new CustomException("The artifact does not exist.", null)); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } @@ -208,8 +207,8 @@ public Artifact createOrUpdateArtifact(String projectName, String artifactName, } if (!artifactName.equals(artifactDTO.getName())) { throw new CustomException( - "Trying to create/update an artifact with name different from the one passed in the request.", - null + "Trying to create/update an artifact with name different from the one passed in the request.", + null ); } @@ -219,29 +218,29 @@ public Artifact createOrUpdateArtifact(String projectName, String artifactName, // Check if artifact already exist if exist throw exception otherwise create a // new one ArtifactEntity artifact = Optional - .ofNullable(artifactDTO.getId()) - .flatMap(id -> { - Optional optionalArtifact = artifactRepository.findById(id); - if (optionalArtifact.isPresent()) { - ArtifactEntity existingArtifact = optionalArtifact.get(); - - // Update the existing artifact version - final ArtifactEntity artifactUpdated = artifactEntityBuilder.update( - existingArtifact, - artifactDTO - ); - return Optional.of(this.artifactRepository.saveAndFlush(artifactUpdated)); - } else { - // Build a new artifact and store it in the database - ArtifactEntity newArtifact = artifactEntityBuilder.build(artifactDTO); - return Optional.of(artifactRepository.saveAndFlush(newArtifact)); - } - }) - .orElseGet(() -> { + .ofNullable(artifactDTO.getId()) + .flatMap(id -> { + Optional optionalArtifact = artifactRepository.findById(id); + if (optionalArtifact.isPresent()) { + ArtifactEntity existingArtifact = optionalArtifact.get(); + + // Update the existing artifact version + final ArtifactEntity artifactUpdated = artifactEntityBuilder.update( + existingArtifact, + artifactDTO + ); + return Optional.of(this.artifactRepository.saveAndFlush(artifactUpdated)); + } else { // Build a new artifact and store it in the database ArtifactEntity newArtifact = artifactEntityBuilder.build(artifactDTO); - return artifactRepository.saveAndFlush(newArtifact); - }); + return Optional.of(artifactRepository.saveAndFlush(newArtifact)); + } + }) + .orElseGet(() -> { + // Build a new artifact and store it in the database + ArtifactEntity newArtifact = artifactEntityBuilder.build(artifactDTO); + return artifactRepository.saveAndFlush(newArtifact); + }); // Return artifact DTO return artifactDTOBuilder.build(artifact, artifact.getEmbedded()); @@ -260,20 +259,20 @@ public Artifact updateArtifact(String projectName, String artifactName, String u } if (!uuid.equals(artifactDTO.getId())) { throw new CustomException( - "Trying to update an artifact with an ID different from the one passed in the request.", - null + "Trying to update an artifact with an ID different from the one passed in the request.", + null ); } // Check project context checkContext(artifactDTO.getProject()); ArtifactEntity artifact = - this.artifactRepository.findById(artifactDTO.getId()) - .map(a -> { - // Update the existing artifact version - return artifactEntityBuilder.update(a, artifactDTO); - }) - .orElseThrow(() -> new CustomException("The artifact does not exist.", null)); + this.artifactRepository.findById(artifactDTO.getId()) + .map(a -> { + // Update the existing artifact version + return artifactEntityBuilder.update(a, artifactDTO); + }) + .orElseThrow(() -> new CustomException("The artifact does not exist.", null)); // Return artifact DTO return artifactDTOBuilder.build(artifact, artifact.getEmbedded()); @@ -291,9 +290,9 @@ public Boolean deleteSpecificArtifactVersion(String projectName, String artifact return true; } throw new CoreException( - "ArtifactNotFound", - "The artifact you are trying to delete does not exist.", - HttpStatus.NOT_FOUND + "ArtifactNotFound", + "The artifact you are trying to delete does not exist.", + HttpStatus.NOT_FOUND ); } catch (Exception e) { throw new CoreException("InternalServerError", "cannot delete artifact", HttpStatus.INTERNAL_SERVER_ERROR); @@ -309,9 +308,9 @@ public Boolean deleteAllArtifactVersions(String projectName, String artifactName return true; } throw new CoreException( - "ArtifactNotFound", - "The artifacts you are trying to delete does not exist.", - HttpStatus.NOT_FOUND + "ArtifactNotFound", + "The artifacts you are trying to delete does not exist.", + HttpStatus.NOT_FOUND ); } catch (Exception e) { throw new CoreException("InternalServerError", "cannot delete artifact", HttpStatus.INTERNAL_SERVER_ERROR); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/DataItemContextServiceImpl.java b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/DataItemContextServiceImpl.java index 6a4e47a0..1b302a5a 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/DataItemContextServiceImpl.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/DataItemContextServiceImpl.java @@ -12,6 +12,10 @@ import it.smartcommunitylabdhub.core.repositories.DataItemRepository; import it.smartcommunitylabdhub.core.services.context.interfaces.DataItemContextService; import jakarta.transaction.Transactional; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -20,16 +24,11 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - @Service @Transactional public class DataItemContextServiceImpl - extends ContextService - implements DataItemContextService { + extends ContextService + implements DataItemContextService { @Autowired DataItemRepository dataItemRepository; @@ -58,22 +57,22 @@ public DataItem createDataItem(String projectName, DataItem dataItemDTO) { // Check if dataItem already exist if exist throw exception otherwise create a // new one DataItemEntity dataItem = (DataItemEntity) Optional - .ofNullable(dataItemDTO.getId()) - .flatMap(id -> - dataItemRepository - .findById(id) - .map(a -> { - throw new CustomException( - "The project already contains an dataItem with the specified UUID.", - null - ); - }) - ) - .orElseGet(() -> { - // Build an dataItem and store it in the database - DataItemEntity newDataItem = dataItemEntityBuilder.build(dataItemDTO); - return dataItemRepository.saveAndFlush(newDataItem); - }); + .ofNullable(dataItemDTO.getId()) + .flatMap(id -> + dataItemRepository + .findById(id) + .map(a -> { + throw new CustomException( + "The project already contains an dataItem with the specified UUID.", + null + ); + }) + ) + .orElseGet(() -> { + // Build an dataItem and store it in the database + DataItemEntity newDataItem = dataItemEntityBuilder.build(dataItemDTO); + return dataItemRepository.saveAndFlush(newDataItem); + }); // Return dataItem DTO return dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded()); @@ -92,32 +91,32 @@ public Page getLatestByProjectName(Map filter, String dataItemEntityFilter.setKind(filter.get("kind")); Optional stateOptional = Stream - .of(State.values()) - .filter(state -> state.name().equals(filter.get("state"))) - .findAny(); + .of(State.values()) + .filter(state -> state.name().equals(filter.get("state"))) + .findAny(); dataItemEntityFilter.setState(stateOptional.map(Enum::name).orElse(null)); Specification specification = createSpecification(filter, dataItemEntityFilter) - .and(CommonSpecification.latestByProject(projectName)); + .and(CommonSpecification.latestByProject(projectName)); Page dataItemPage = dataItemRepository.findAll( - Specification - .where(specification) - .and((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("project"), projectName)), - pageable + Specification + .where(specification) + .and((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("project"), projectName)), + pageable ); return new PageImpl<>( - dataItemPage - .getContent() - .stream() - .map(dataItem -> { - return dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded()); - }) - .collect(Collectors.toList()), - pageable, - dataItemPage.getTotalElements() + dataItemPage + .getContent() + .stream() + .map(dataItem -> { + return dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded()); + }) + .collect(Collectors.toList()), + pageable, + dataItemPage.getTotalElements() ); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); @@ -126,10 +125,10 @@ public Page getLatestByProjectName(Map filter, String @Override public Page getByProjectNameAndDataItemName( - Map filter, - String projectName, - String dataItemName, - Pageable pageable + Map filter, + String projectName, + String dataItemName, + Pageable pageable ) { try { checkContext(projectName); @@ -137,36 +136,36 @@ public Page getByProjectNameAndDataItemName( dataItemEntityFilter.setCreatedDate(filter.get("created")); dataItemEntityFilter.setKind(filter.get("kind")); Optional stateOptional = Stream - .of(State.values()) - .filter(state -> state.name().equals(filter.get("state"))) - .findAny(); + .of(State.values()) + .filter(state -> state.name().equals(filter.get("state"))) + .findAny(); dataItemEntityFilter.setState(stateOptional.map(Enum::name).orElse(null)); Specification specification = createSpecification(filter, dataItemEntityFilter); Page dataItemPage = dataItemRepository.findAll( - Specification - .where(specification) - .and((root, query, criteriaBuilder) -> - criteriaBuilder.and( - criteriaBuilder.equal(root.get("project"), projectName), - criteriaBuilder.equal(root.get("name"), dataItemName) - ) - ), - pageable + Specification + .where(specification) + .and((root, query, criteriaBuilder) -> + criteriaBuilder.and( + criteriaBuilder.equal(root.get("project"), projectName), + criteriaBuilder.equal(root.get("name"), dataItemName) + ) + ), + pageable ); return new PageImpl<>( - dataItemPage - .getContent() - .stream() - .map(dataItem -> { - return dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded()); - }) - .collect(Collectors.toList()), - pageable, - dataItemPage.getTotalElements() + dataItemPage + .getContent() + .stream() + .map(dataItem -> { + return dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded()); + }) + .collect(Collectors.toList()), + pageable, + dataItemPage.getTotalElements() ); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); @@ -180,8 +179,8 @@ public DataItem getByProjectAndDataItemAndUuid(String projectName, String dataIt checkContext(projectName); return this.dataItemRepository.findByProjectAndNameAndId(projectName, dataItemName, uuid) - .map(dataItem -> dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded())) - .orElseThrow(() -> new CustomException("The dataItem does not exist.", null)); + .map(dataItem -> dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded())) + .orElseThrow(() -> new CustomException("The dataItem does not exist.", null)); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } @@ -194,8 +193,8 @@ public DataItem getLatestByProjectNameAndDataItemName(String projectName, String checkContext(projectName); return this.dataItemRepository.findLatestDataItemByProjectAndName(projectName, dataItemName) - .map(dataItem -> dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded())) - .orElseThrow(() -> new CustomException("The dataItem does not exist.", null)); + .map(dataItem -> dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded())) + .orElseThrow(() -> new CustomException("The dataItem does not exist.", null)); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } @@ -211,8 +210,8 @@ public DataItem createOrUpdateDataItem(String projectName, String dataItemName, } if (!dataItemName.equals(dataItemDTO.getName())) { throw new CustomException( - "Trying to create/update an dataItem with name different from the one passed in the request.", - null + "Trying to create/update an dataItem with name different from the one passed in the request.", + null ); } @@ -222,29 +221,29 @@ public DataItem createOrUpdateDataItem(String projectName, String dataItemName, // Check if dataItem already exist if exist throw exception otherwise create a // new one DataItemEntity dataItem = Optional - .ofNullable(dataItemDTO.getId()) - .flatMap(id -> { - Optional optionalDataItem = dataItemRepository.findById(id); - if (optionalDataItem.isPresent()) { - DataItemEntity existingDataItem = optionalDataItem.get(); - - // Update the existing dataItem version - final DataItemEntity dataItemUpdated = dataItemEntityBuilder.update( - existingDataItem, - dataItemDTO - ); - return Optional.of(this.dataItemRepository.saveAndFlush(dataItemUpdated)); - } else { - // Build a new dataItem and store it in the database - DataItemEntity newDataItem = dataItemEntityBuilder.build(dataItemDTO); - return Optional.of(dataItemRepository.saveAndFlush(newDataItem)); - } - }) - .orElseGet(() -> { + .ofNullable(dataItemDTO.getId()) + .flatMap(id -> { + Optional optionalDataItem = dataItemRepository.findById(id); + if (optionalDataItem.isPresent()) { + DataItemEntity existingDataItem = optionalDataItem.get(); + + // Update the existing dataItem version + final DataItemEntity dataItemUpdated = dataItemEntityBuilder.update( + existingDataItem, + dataItemDTO + ); + return Optional.of(this.dataItemRepository.saveAndFlush(dataItemUpdated)); + } else { // Build a new dataItem and store it in the database DataItemEntity newDataItem = dataItemEntityBuilder.build(dataItemDTO); - return dataItemRepository.saveAndFlush(newDataItem); - }); + return Optional.of(dataItemRepository.saveAndFlush(newDataItem)); + } + }) + .orElseGet(() -> { + // Build a new dataItem and store it in the database + DataItemEntity newDataItem = dataItemEntityBuilder.build(dataItemDTO); + return dataItemRepository.saveAndFlush(newDataItem); + }); // Return dataItem DTO return dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded()); @@ -263,20 +262,20 @@ public DataItem updateDataItem(String projectName, String dataItemName, String u } if (!uuid.equals(dataItemDTO.getId())) { throw new CustomException( - "Trying to update an dataItem with an ID different from the one passed in the request.", - null + "Trying to update an dataItem with an ID different from the one passed in the request.", + null ); } // Check project context checkContext(dataItemDTO.getProject()); DataItemEntity dataItem = - this.dataItemRepository.findById(dataItemDTO.getId()) - .map(a -> { - // Update the existing dataItem version - return dataItemEntityBuilder.update(a, dataItemDTO); - }) - .orElseThrow(() -> new CustomException("The dataItem does not exist.", null)); + this.dataItemRepository.findById(dataItemDTO.getId()) + .map(a -> { + // Update the existing dataItem version + return dataItemEntityBuilder.update(a, dataItemDTO); + }) + .orElseThrow(() -> new CustomException("The dataItem does not exist.", null)); // Return dataItem DTO return dataItemDTOBuilder.build(dataItem, dataItem.getEmbedded()); @@ -294,9 +293,9 @@ public Boolean deleteSpecificDataItemVersion(String projectName, String dataItem return true; } throw new CoreException( - "DataItemNotFound", - "The dataItem you are trying to delete does not exist.", - HttpStatus.NOT_FOUND + "DataItemNotFound", + "The dataItem you are trying to delete does not exist.", + HttpStatus.NOT_FOUND ); } catch (Exception e) { throw new CoreException("InternalServerError", "cannot delete dataItem", HttpStatus.INTERNAL_SERVER_ERROR); @@ -312,9 +311,9 @@ public Boolean deleteAllDataItemVersions(String projectName, String dataItemName return true; } throw new CoreException( - "DataItemNotFound", - "The dataItems you are trying to delete does not exist.", - HttpStatus.NOT_FOUND + "DataItemNotFound", + "The dataItems you are trying to delete does not exist.", + HttpStatus.NOT_FOUND ); } catch (Exception e) { throw new CoreException("InternalServerError", "cannot delete dataItem", HttpStatus.INTERNAL_SERVER_ERROR); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/FunctionContextServiceImpl.java b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/FunctionContextServiceImpl.java index dcbf8bb8..b235d1e6 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/FunctionContextServiceImpl.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/FunctionContextServiceImpl.java @@ -17,6 +17,11 @@ import it.smartcommunitylabdhub.core.repositories.TaskRepository; import it.smartcommunitylabdhub.core.services.context.interfaces.FunctionContextService; import jakarta.transaction.Transactional; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -25,17 +30,11 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - @Service @Transactional public class FunctionContextServiceImpl - extends ContextService - implements FunctionContextService { + extends ContextService + implements FunctionContextService { @Autowired FunctionRepository functionRepository; @@ -70,30 +69,30 @@ public Function createFunction(String projectName, Function functionDTO) { // Check if function already exist if exist throw exception otherwise create a // new one FunctionEntity function = (FunctionEntity) Optional - .ofNullable(functionDTO.getId()) - .flatMap(id -> - functionRepository - .findById(id) - .map(a -> { - throw new CustomException( - "The project already contains an function with the specified UUID.", - null - ); - }) - ) - .orElseGet(() -> { - // Build an function and store it in the database - FunctionEntity newFunction = functionEntityBuilder.build(functionDTO); - return functionRepository.saveAndFlush(newFunction); - }); + .ofNullable(functionDTO.getId()) + .flatMap(id -> + functionRepository + .findById(id) + .map(a -> { + throw new CustomException( + "The project already contains an function with the specified UUID.", + null + ); + }) + ) + .orElseGet(() -> { + // Build an function and store it in the database + FunctionEntity newFunction = functionEntityBuilder.build(functionDTO); + return functionRepository.saveAndFlush(newFunction); + }); // Return function DTO return functionDTOBuilder.build(function, function.getEmbedded()); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -103,25 +102,25 @@ public Function getByUuid(String projectName, String uuid) { checkContext(projectName); return functionRepository - .findById(uuid) - .map(function -> { - try { - return functionDTOBuilder.build(function, function.getEmbedded()); - } catch (CustomException e) { - throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR - ); - } - }) - .orElseThrow(() -> - new CoreException( - ErrorList.FUNCTION_NOT_FOUND.getValue(), - ErrorList.FUNCTION_NOT_FOUND.getReason(), - HttpStatus.NOT_FOUND - ) - ); + .findById(uuid) + .map(function -> { + try { + return functionDTOBuilder.build(function, function.getEmbedded()); + } catch (CustomException e) { + throw new CoreException( + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR + ); + } + }) + .orElseThrow(() -> + new CoreException( + ErrorList.FUNCTION_NOT_FOUND.getValue(), + ErrorList.FUNCTION_NOT_FOUND.getReason(), + HttpStatus.NOT_FOUND + ) + ); } @Override @@ -134,46 +133,46 @@ public Page getLatestByProjectName(Map filter, String functionEntityFilter.setKind(filter.get("kind")); Optional stateOptional = Stream - .of(State.values()) - .filter(state -> state.name().equals(filter.get("state"))) - .findAny(); + .of(State.values()) + .filter(state -> state.name().equals(filter.get("state"))) + .findAny(); functionEntityFilter.setState(stateOptional.map(Enum::name).orElse(null)); Specification specification = createSpecification(filter, functionEntityFilter) - .and(CommonSpecification.latestByProject(projectName)); + .and(CommonSpecification.latestByProject(projectName)); Page functionPage = functionRepository.findAll( - Specification - .where(specification) - .and((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("project"), projectName)), - pageable + Specification + .where(specification) + .and((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("project"), projectName)), + pageable ); return new PageImpl<>( - functionPage - .getContent() - .stream() - .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) - .collect(Collectors.toList()), - pageable, - functionPage.getTotalElements() + functionPage + .getContent() + .stream() + .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) + .collect(Collectors.toList()), + pageable, + functionPage.getTotalElements() ); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @Override public Page getByProjectNameAndFunctionName( - Map filter, - String projectName, - String functionName, - Pageable pageable + Map filter, + String projectName, + String functionName, + Pageable pageable ) { try { checkContext(projectName); @@ -181,40 +180,40 @@ public Page getByProjectNameAndFunctionName( functionEntityFilter.setCreatedDate(filter.get("created")); functionEntityFilter.setKind(filter.get("kind")); Optional stateOptional = Stream - .of(State.values()) - .filter(state -> state.name().equals(filter.get("state"))) - .findAny(); + .of(State.values()) + .filter(state -> state.name().equals(filter.get("state"))) + .findAny(); functionEntityFilter.setState(stateOptional.map(Enum::name).orElse(null)); Specification specification = createSpecification(filter, functionEntityFilter); Page functionPage = functionRepository.findAll( - Specification - .where(specification) - .and((root, query, criteriaBuilder) -> - criteriaBuilder.and( - criteriaBuilder.equal(root.get("project"), projectName), - criteriaBuilder.equal(root.get("name"), functionName) - ) - ), - pageable + Specification + .where(specification) + .and((root, query, criteriaBuilder) -> + criteriaBuilder.and( + criteriaBuilder.equal(root.get("project"), projectName), + criteriaBuilder.equal(root.get("name"), functionName) + ) + ), + pageable ); return new PageImpl<>( - functionPage - .getContent() - .stream() - .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) - .collect(Collectors.toList()), - pageable, - functionPage.getTotalElements() + functionPage + .getContent() + .stream() + .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) + .collect(Collectors.toList()), + pageable, + functionPage.getTotalElements() ); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -225,14 +224,14 @@ public List listByProjectNameAndFunctionName(String projectName, Strin checkContext(projectName); return this.functionRepository.findAllByProjectAndNameOrderByCreatedDesc(projectName, functionName) - .stream() - .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) - .toList(); + .stream() + .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) + .toList(); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -244,13 +243,13 @@ public Function getByProjectAndFunctionAndUuid(String projectName, String functi checkContext(projectName); return this.functionRepository.findByProjectAndNameAndId(projectName, functionName, uuid) - .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) - .orElseThrow(() -> new CustomException(ErrorList.FUNCTION_NOT_FOUND.getReason(), null)); + .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) + .orElseThrow(() -> new CustomException(ErrorList.FUNCTION_NOT_FOUND.getReason(), null)); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -262,13 +261,13 @@ public Function getLatestByProjectNameAndFunctionName(String projectName, String checkContext(projectName); return this.functionRepository.findLatestFunctionByProjectAndName(projectName, functionName) - .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) - .orElseThrow(() -> new CustomException(ErrorList.FUNCTION_NOT_FOUND.getReason(), null)); + .map(function -> functionDTOBuilder.build(function, function.getEmbedded())) + .orElseThrow(() -> new CustomException(ErrorList.FUNCTION_NOT_FOUND.getReason(), null)); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -283,8 +282,8 @@ public Function createOrUpdateFunction(String projectName, String functionName, } if (!functionName.equals(functionDTO.getName())) { throw new CustomException( - "Trying to create/update an function with name different from the one passed in the request.", - null + "Trying to create/update an function with name different from the one passed in the request.", + null ); } @@ -294,37 +293,37 @@ public Function createOrUpdateFunction(String projectName, String functionName, // Check if function already exist if exist throw exception otherwise create a // new one FunctionEntity function = Optional - .ofNullable(functionDTO.getId()) - .flatMap(id -> { - Optional optionalFunction = functionRepository.findById(id); - if (optionalFunction.isPresent()) { - FunctionEntity existingFunction = optionalFunction.get(); - - // Update the existing function version - final FunctionEntity functionUpdated = functionEntityBuilder.update( - existingFunction, - functionDTO - ); - return Optional.of(this.functionRepository.saveAndFlush(functionUpdated)); - } else { - // Build a new function and store it in the database - FunctionEntity newFunction = functionEntityBuilder.build(functionDTO); - return Optional.of(functionRepository.saveAndFlush(newFunction)); - } - }) - .orElseGet(() -> { + .ofNullable(functionDTO.getId()) + .flatMap(id -> { + Optional optionalFunction = functionRepository.findById(id); + if (optionalFunction.isPresent()) { + FunctionEntity existingFunction = optionalFunction.get(); + + // Update the existing function version + final FunctionEntity functionUpdated = functionEntityBuilder.update( + existingFunction, + functionDTO + ); + return Optional.of(this.functionRepository.saveAndFlush(functionUpdated)); + } else { // Build a new function and store it in the database FunctionEntity newFunction = functionEntityBuilder.build(functionDTO); - return functionRepository.saveAndFlush(newFunction); - }); + return Optional.of(functionRepository.saveAndFlush(newFunction)); + } + }) + .orElseGet(() -> { + // Build a new function and store it in the database + FunctionEntity newFunction = functionEntityBuilder.build(functionDTO); + return functionRepository.saveAndFlush(newFunction); + }); // Return function DTO return functionDTOBuilder.build(function, function.getEmbedded()); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -339,27 +338,27 @@ public Function updateFunction(String projectName, String functionName, String u } if (!uuid.equals(functionDTO.getId())) { throw new CustomException( - "Trying to update an function with an ID different from the one passed in the request.", - null + "Trying to update an function with an ID different from the one passed in the request.", + null ); } // Check project context checkContext(functionDTO.getProject()); FunctionEntity function = - this.functionRepository.findById(functionDTO.getId()) - .map(a -> // Update the existing function version - functionEntityBuilder.update(a, functionDTO) - ) - .orElseThrow(() -> new CustomException("The function does not exist.", null)); + this.functionRepository.findById(functionDTO.getId()) + .map(a -> // Update the existing function version + functionEntityBuilder.update(a, functionDTO) + ) + .orElseThrow(() -> new CustomException("The function does not exist.", null)); // Return function DTO return functionDTOBuilder.build(function, function.getEmbedded()); } catch (CustomException e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - e.getMessage(), - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + e.getMessage(), + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -388,15 +387,15 @@ public Boolean deleteSpecificFunctionVersion(String projectName, String function return true; } throw new CoreException( - ErrorList.FUNCTION_NOT_FOUND.getValue(), - ErrorList.FUNCTION_NOT_FOUND.getReason(), - HttpStatus.NOT_FOUND + ErrorList.FUNCTION_NOT_FOUND.getValue(), + ErrorList.FUNCTION_NOT_FOUND.getReason(), + HttpStatus.NOT_FOUND ); } catch (Exception e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "cannot delete function", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "cannot delete function", + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -408,34 +407,34 @@ public Boolean deleteAllFunctionVersions(String projectName, String functionName if (functionRepository.existsByProjectAndName(projectName, functionName)) { // Cascade delete listByProjectNameAndFunctionName(projectName, functionName) - .forEach(function -> { - // Remove Task - List taskList = - this.taskRepository.findByFunction(TaskUtils.buildTaskString(function)); - //Delete all related object - taskList.forEach(task -> { - // remove run - this.runRepository.deleteByTaskId(task.getId()); - - // remove task - this.taskRepository.deleteById(task.getId()); - }); + .forEach(function -> { + // Remove Task + List taskList = + this.taskRepository.findByFunction(TaskUtils.buildTaskString(function)); + //Delete all related object + taskList.forEach(task -> { + // remove run + this.runRepository.deleteByTaskId(task.getId()); + + // remove task + this.taskRepository.deleteById(task.getId()); }); + }); this.functionRepository.deleteByProjectAndName(projectName, functionName); return true; } throw new CoreException( - ErrorList.FUNCTION_NOT_FOUND.getValue(), - ErrorList.FUNCTION_NOT_FOUND.getReason(), - HttpStatus.NOT_FOUND + ErrorList.FUNCTION_NOT_FOUND.getValue(), + ErrorList.FUNCTION_NOT_FOUND.getReason(), + HttpStatus.NOT_FOUND ); } catch (Exception e) { throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "cannot delete function", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "cannot delete function", + HttpStatus.INTERNAL_SERVER_ERROR ); } } diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/SecretContextServiceImpl.java b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/SecretContextServiceImpl.java index 1c754d9a..35da26ec 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/SecretContextServiceImpl.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/SecretContextServiceImpl.java @@ -13,6 +13,10 @@ import it.smartcommunitylabdhub.core.repositories.SecretRepository; import it.smartcommunitylabdhub.core.services.context.interfaces.SecretContextService; import jakarta.transaction.Transactional; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -21,14 +25,11 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - @Service @Transactional -public class SecretContextServiceImpl extends ContextService implements SecretContextService { +public class SecretContextServiceImpl + extends ContextService + implements SecretContextService { @Autowired SecretRepository secretRepository; @@ -113,7 +114,11 @@ public Page getAllSecretsByProjectName(Map filter, Strin ); return new PageImpl<>( - secretPage.getContent().stream().map(secret -> secretDTOBuilder.build(secret, secret.getEmbedded())).collect(Collectors.toList()), + secretPage + .getContent() + .stream() + .map(secret -> secretDTOBuilder.build(secret, secret.getEmbedded())) + .collect(Collectors.toList()), pageable, secretPage.getTotalElements() ); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/WorkflowContextServiceImpl.java b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/WorkflowContextServiceImpl.java index 2bf2576e..618688c0 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/WorkflowContextServiceImpl.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/WorkflowContextServiceImpl.java @@ -12,6 +12,10 @@ import it.smartcommunitylabdhub.core.repositories.WorkflowRepository; import it.smartcommunitylabdhub.core.services.context.interfaces.WorkflowContextService; import jakarta.transaction.Transactional; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -20,16 +24,11 @@ import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; -import java.util.stream.Stream; - @Service @Transactional public class WorkflowContextServiceImpl - extends ContextService - implements WorkflowContextService { + extends ContextService + implements WorkflowContextService { @Autowired WorkflowRepository workflowRepository; @@ -58,22 +57,22 @@ public Workflow createWorkflow(String projectName, Workflow workflowDTO) { // Check if workflow already exist if exist throw exception otherwise create a // new one WorkflowEntity workflow = (WorkflowEntity) Optional - .ofNullable(workflowDTO.getId()) - .flatMap(id -> - workflowRepository - .findById(id) - .map(a -> { - throw new CustomException( - "The project already contains an workflow with the specified UUID.", - null - ); - }) - ) - .orElseGet(() -> { - // Build an workflow and store it in the database - WorkflowEntity newWorkflow = workflowEntityBuilder.build(workflowDTO); - return workflowRepository.saveAndFlush(newWorkflow); - }); + .ofNullable(workflowDTO.getId()) + .flatMap(id -> + workflowRepository + .findById(id) + .map(a -> { + throw new CustomException( + "The project already contains an workflow with the specified UUID.", + null + ); + }) + ) + .orElseGet(() -> { + // Build an workflow and store it in the database + WorkflowEntity newWorkflow = workflowEntityBuilder.build(workflowDTO); + return workflowRepository.saveAndFlush(newWorkflow); + }); // Return workflow DTO return workflowDTOBuilder.build(workflow, workflow.getEmbedded()); @@ -92,32 +91,32 @@ public Page getLatestByProjectName(Map filter, String workflowEntityFilter.setKind(filter.get("kind")); Optional stateOptional = Stream - .of(State.values()) - .filter(state -> state.name().equals(filter.get("state"))) - .findAny(); + .of(State.values()) + .filter(state -> state.name().equals(filter.get("state"))) + .findAny(); workflowEntityFilter.setState(stateOptional.map(Enum::name).orElse(null)); Specification specification = createSpecification(filter, workflowEntityFilter) - .and(CommonSpecification.latestByProject(projectName)); + .and(CommonSpecification.latestByProject(projectName)); Page workflowPage = workflowRepository.findAll( - Specification - .where(specification) - .and((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("project"), projectName)), - pageable + Specification + .where(specification) + .and((root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("project"), projectName)), + pageable ); return new PageImpl<>( - workflowPage - .getContent() - .stream() - .map(workflow -> { - return workflowDTOBuilder.build(workflow, workflow.getEmbedded()); - }) - .collect(Collectors.toList()), - pageable, - workflowPage.getTotalElements() + workflowPage + .getContent() + .stream() + .map(workflow -> { + return workflowDTOBuilder.build(workflow, workflow.getEmbedded()); + }) + .collect(Collectors.toList()), + pageable, + workflowPage.getTotalElements() ); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); @@ -126,10 +125,10 @@ public Page getLatestByProjectName(Map filter, String @Override public Page getByProjectNameAndWorkflowName( - Map filter, - String projectName, - String workflowName, - Pageable pageable + Map filter, + String projectName, + String workflowName, + Pageable pageable ) { try { checkContext(projectName); @@ -137,36 +136,36 @@ public Page getByProjectNameAndWorkflowName( workflowEntityFilter.setCreatedDate(filter.get("created")); workflowEntityFilter.setKind(filter.get("kind")); Optional stateOptional = Stream - .of(State.values()) - .filter(state -> state.name().equals(filter.get("state"))) - .findAny(); + .of(State.values()) + .filter(state -> state.name().equals(filter.get("state"))) + .findAny(); workflowEntityFilter.setState(stateOptional.map(Enum::name).orElse(null)); Specification specification = createSpecification(filter, workflowEntityFilter); Page workflowPage = workflowRepository.findAll( - Specification - .where(specification) - .and((root, query, criteriaBuilder) -> - criteriaBuilder.and( - criteriaBuilder.equal(root.get("project"), projectName), - criteriaBuilder.equal(root.get("name"), workflowName) - ) - ), - pageable + Specification + .where(specification) + .and((root, query, criteriaBuilder) -> + criteriaBuilder.and( + criteriaBuilder.equal(root.get("project"), projectName), + criteriaBuilder.equal(root.get("name"), workflowName) + ) + ), + pageable ); return new PageImpl<>( - workflowPage - .getContent() - .stream() - .map(workflow -> { - return workflowDTOBuilder.build(workflow, workflow.getEmbedded()); - }) - .collect(Collectors.toList()), - pageable, - workflowPage.getTotalElements() + workflowPage + .getContent() + .stream() + .map(workflow -> { + return workflowDTOBuilder.build(workflow, workflow.getEmbedded()); + }) + .collect(Collectors.toList()), + pageable, + workflowPage.getTotalElements() ); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); @@ -180,8 +179,8 @@ public Workflow getByProjectAndWorkflowAndUuid(String projectName, String workfl checkContext(projectName); return this.workflowRepository.findByProjectAndNameAndId(projectName, workflowName, uuid) - .map(workflow -> workflowDTOBuilder.build(workflow, workflow.getEmbedded())) - .orElseThrow(() -> new CustomException("The workflow does not exist.", null)); + .map(workflow -> workflowDTOBuilder.build(workflow, workflow.getEmbedded())) + .orElseThrow(() -> new CustomException("The workflow does not exist.", null)); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } @@ -194,8 +193,8 @@ public Workflow getLatestByProjectNameAndWorkflowName(String projectName, String checkContext(projectName); return this.workflowRepository.findLatestWorkflowByProjectAndName(projectName, workflowName) - .map(workflow -> workflowDTOBuilder.build(workflow, workflow.getEmbedded())) - .orElseThrow(() -> new CustomException("The workflow does not exist.", null)); + .map(workflow -> workflowDTOBuilder.build(workflow, workflow.getEmbedded())) + .orElseThrow(() -> new CustomException("The workflow does not exist.", null)); } catch (CustomException e) { throw new CoreException("InternalServerError", e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); } @@ -211,8 +210,8 @@ public Workflow createOrUpdateWorkflow(String projectName, String workflowName, } if (!workflowName.equals(workflowDTO.getName())) { throw new CustomException( - "Trying to create/update an workflow with name different from the one passed in the request.", - null + "Trying to create/update an workflow with name different from the one passed in the request.", + null ); } @@ -222,29 +221,29 @@ public Workflow createOrUpdateWorkflow(String projectName, String workflowName, // Check if workflow already exist if exist throw exception otherwise create a // new one WorkflowEntity workflow = Optional - .ofNullable(workflowDTO.getId()) - .flatMap(id -> { - Optional optionalWorkflow = workflowRepository.findById(id); - if (optionalWorkflow.isPresent()) { - WorkflowEntity existingWorkflow = optionalWorkflow.get(); - - // Update the existing workflow version - final WorkflowEntity workflowUpdated = workflowEntityBuilder.update( - existingWorkflow, - workflowDTO - ); - return Optional.of(this.workflowRepository.saveAndFlush(workflowUpdated)); - } else { - // Build a new workflow and store it in the database - WorkflowEntity newWorkflow = workflowEntityBuilder.build(workflowDTO); - return Optional.of(workflowRepository.saveAndFlush(newWorkflow)); - } - }) - .orElseGet(() -> { + .ofNullable(workflowDTO.getId()) + .flatMap(id -> { + Optional optionalWorkflow = workflowRepository.findById(id); + if (optionalWorkflow.isPresent()) { + WorkflowEntity existingWorkflow = optionalWorkflow.get(); + + // Update the existing workflow version + final WorkflowEntity workflowUpdated = workflowEntityBuilder.update( + existingWorkflow, + workflowDTO + ); + return Optional.of(this.workflowRepository.saveAndFlush(workflowUpdated)); + } else { // Build a new workflow and store it in the database WorkflowEntity newWorkflow = workflowEntityBuilder.build(workflowDTO); - return workflowRepository.saveAndFlush(newWorkflow); - }); + return Optional.of(workflowRepository.saveAndFlush(newWorkflow)); + } + }) + .orElseGet(() -> { + // Build a new workflow and store it in the database + WorkflowEntity newWorkflow = workflowEntityBuilder.build(workflowDTO); + return workflowRepository.saveAndFlush(newWorkflow); + }); // Return workflow DTO return workflowDTOBuilder.build(workflow, workflow.getEmbedded()); @@ -263,20 +262,20 @@ public Workflow updateWorkflow(String projectName, String workflowName, String u } if (!uuid.equals(workflowDTO.getId())) { throw new CustomException( - "Trying to update an workflow with an ID different from the one passed in the request.", - null + "Trying to update an workflow with an ID different from the one passed in the request.", + null ); } // Check project context checkContext(workflowDTO.getProject()); WorkflowEntity workflow = - this.workflowRepository.findById(workflowDTO.getId()) - .map(a -> { - // Update the existing workflow version - return workflowEntityBuilder.update(a, workflowDTO); - }) - .orElseThrow(() -> new CustomException("The workflow does not exist.", null)); + this.workflowRepository.findById(workflowDTO.getId()) + .map(a -> { + // Update the existing workflow version + return workflowEntityBuilder.update(a, workflowDTO); + }) + .orElseThrow(() -> new CustomException("The workflow does not exist.", null)); // Return workflow DTO return workflowDTOBuilder.build(workflow, workflow.getEmbedded()); @@ -294,9 +293,9 @@ public Boolean deleteSpecificWorkflowVersion(String projectName, String workflow return true; } throw new CoreException( - "WorkflowNotFound", - "The workflow you are trying to delete does not exist.", - HttpStatus.NOT_FOUND + "WorkflowNotFound", + "The workflow you are trying to delete does not exist.", + HttpStatus.NOT_FOUND ); } catch (Exception e) { throw new CoreException("InternalServerError", "cannot delete workflow", HttpStatus.INTERNAL_SERVER_ERROR); @@ -312,9 +311,9 @@ public Boolean deleteAllWorkflowVersions(String projectName, String workflowName return true; } throw new CoreException( - "WorkflowNotFound", - "The workflows you are trying to delete does not exist.", - HttpStatus.NOT_FOUND + "WorkflowNotFound", + "The workflows you are trying to delete does not exist.", + HttpStatus.NOT_FOUND ); } catch (Exception e) { throw new CoreException("InternalServerError", "cannot delete workflow", HttpStatus.INTERNAL_SERVER_ERROR); diff --git a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/interfaces/SecretContextService.java b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/interfaces/SecretContextService.java index b0c31a1d..66452267 100644 --- a/application/src/main/java/it/smartcommunitylabdhub/core/services/context/interfaces/SecretContextService.java +++ b/application/src/main/java/it/smartcommunitylabdhub/core/services/context/interfaces/SecretContextService.java @@ -1,11 +1,10 @@ package it.smartcommunitylabdhub.core.services.context.interfaces; import it.smartcommunitylabdhub.commons.models.entities.secret.Secret; +import java.util.Map; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; -import java.util.Map; - public interface SecretContextService { Secret createSecret(String projectName, Secret secretDTO); diff --git a/application/src/test/java/it/smartcommunitylabdhub/core/ConvertFunctionTests.java b/application/src/test/java/it/smartcommunitylabdhub/core/ConvertFunctionTests.java index 8af97918..9fb91422 100644 --- a/application/src/test/java/it/smartcommunitylabdhub/core/ConvertFunctionTests.java +++ b/application/src/test/java/it/smartcommunitylabdhub/core/ConvertFunctionTests.java @@ -1,8 +1,9 @@ package it.smartcommunitylabdhub.core; +import it.smartcommunitylabdhub.core.models.converters.ConversionUtils; +import it.smartcommunitylabdhub.core.models.converters.interfaces.Converter; import java.util.ArrayList; import java.util.List; - import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -10,9 +11,6 @@ import org.mockito.MockitoAnnotations; import org.springframework.boot.test.context.SpringBootTest; -import it.smartcommunitylabdhub.core.models.converters.ConversionUtils; -import it.smartcommunitylabdhub.core.models.converters.interfaces.Converter; - @SpringBootTest class ConvertFunctionTests { @@ -31,8 +29,9 @@ void testConvert() { // Perform the conversion Integer output = ConversionUtils.convert( - input, // Source object // Mocked CommandFactory instance - "integer"); + input, // Source object // Mocked CommandFactory instance + "integer" + ); // Assert the output is of type Integer Assertions.assertEquals(Integer.class, output.getClass()); @@ -43,9 +42,7 @@ void testConvert() { void testReverse() { Integer input = 1; - String output = ConversionUtils.reverse( - input, - "integer"); + String output = ConversionUtils.reverse(input, "integer"); // Assert that result is equal to integer. Assertions.assertEquals(String.class, output.getClass()); @@ -58,13 +55,11 @@ void testListConvert() { strings.add("1"); strings.add("2"); - List integers = (List) ConversionUtils.convertIterable(strings, "integer", - Integer.class); + List integers = (List) ConversionUtils.convertIterable(strings, "integer", Integer.class); Assertions.assertEquals(2, integers.size()); // Assert the size of the converted list Assertions.assertEquals(1, integers.get(0)); // Assert the first element in the list Assertions.assertEquals(2, integers.get(1)); // Assert the second element in the list - } @Test @@ -73,14 +68,10 @@ void testListRevert() { integers.add(1); integers.add(2); - List strings = (List) ConversionUtils.reverseIterable( - integers, - "integer", - String.class); + List strings = (List) ConversionUtils.reverseIterable(integers, "integer", String.class); Assertions.assertEquals(2, strings.size()); // Assert the size of the converted list Assertions.assertEquals(String.class, strings.get(0).getClass()); // Assert the first element in the list Assertions.assertEquals(String.class, strings.get(1).getClass()); // Assert the second element in the list - } } diff --git a/application/src/test/java/it/smartcommunitylabdhub/core/CoreApplicationTests.java b/application/src/test/java/it/smartcommunitylabdhub/core/CoreApplicationTests.java index 43d00052..e8e765f9 100644 --- a/application/src/test/java/it/smartcommunitylabdhub/core/CoreApplicationTests.java +++ b/application/src/test/java/it/smartcommunitylabdhub/core/CoreApplicationTests.java @@ -6,8 +6,6 @@ @SpringBootTest class CoreApplicationTests { - @Test - void contextLoads() { - } - + @Test + void contextLoads() {} } diff --git a/application/src/test/java/it/smartcommunitylabdhub/core/K8sSecretHelperTests.java b/application/src/test/java/it/smartcommunitylabdhub/core/K8sSecretHelperTests.java index 1fbf70c6..b4a322ac 100644 --- a/application/src/test/java/it/smartcommunitylabdhub/core/K8sSecretHelperTests.java +++ b/application/src/test/java/it/smartcommunitylabdhub/core/K8sSecretHelperTests.java @@ -1,100 +1,95 @@ package it.smartcommunitylabdhub.core; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.kubernetes.client.openapi.ApiException; +import it.smartcommunitylabdhub.framework.k8s.kubernetes.K8sSecretHelper; import java.util.Collections; import java.util.HashMap; import java.util.Map; - import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import io.kubernetes.client.openapi.ApiException; -import it.smartcommunitylabdhub.framework.k8s.kubernetes.K8sSecretHelper; - -import static org.junit.jupiter.api.Assertions.assertEquals; - @SpringBootTest class K8sSecretHelperTests { - @Autowired - private K8sSecretHelper helper; + @Autowired + private K8sSecretHelper helper; - @Test - void readNamespacedSecret() throws ApiException { - try { + @Test + void readNamespacedSecret() throws ApiException { + try { helper.deleteSecret("test"); + } catch (ApiException e) {} + + Map data = null; + try { + data = helper.getSecretData("test"); } catch (ApiException e) { + e.printStackTrace(); } - - Map data = null; - try { - data = helper.getSecretData("test"); - } catch (ApiException e) { - e.printStackTrace(); - } - assertEquals(data, null); - } + assertEquals(data, null); + } - @Test - void createSecret() { - try { + @Test + void createSecret() { + try { helper.deleteSecret("test"); - } catch (ApiException e) { - } + } catch (ApiException e) {} - // create - Map data = new HashMap<>(); - data.put("mykey", "myvalue"); - try { + // create + Map data = new HashMap<>(); + data.put("mykey", "myvalue"); + try { helper.storeSecretData("test", data); } catch (Exception e) { e.printStackTrace(); } - // read created - Map readData = null; + // read created + Map readData = null; try { readData = helper.getSecretData("test"); } catch (ApiException e) { e.printStackTrace(); } - assertEquals(data, readData); + assertEquals(data, readData); - data.put("mykey2", "myvalue2"); - try { + data.put("mykey2", "myvalue2"); + try { helper.storeSecretData("test", data); readData = helper.getSecretData("test"); } catch (Exception e) { e.printStackTrace(); } - assertEquals(data.get("mykey2"), readData.get("mykey2")); - assertEquals(data.get("mykey"), readData.get("mykey")); + assertEquals(data.get("mykey2"), readData.get("mykey2")); + assertEquals(data.get("mykey"), readData.get("mykey")); - data.put("mykey", "myvalue3"); - try { + data.put("mykey", "myvalue3"); + try { helper.storeSecretData("test", data); readData = helper.getSecretData("test"); } catch (Exception e) { e.printStackTrace(); } - assertEquals(data.get("mykey2"), readData.get("mykey2")); - assertEquals(data.get("mykey"), readData.get("mykey")); + assertEquals(data.get("mykey2"), readData.get("mykey2")); + assertEquals(data.get("mykey"), readData.get("mykey")); - try { - helper.deleteSecretKeys("test", Collections.singleton("mykey2")); + try { + helper.deleteSecretKeys("test", Collections.singleton("mykey2")); readData = helper.getSecretData("test"); } catch (Exception e) { e.printStackTrace(); } - assertEquals(null, readData.get("mykey2")); - } + assertEquals(null, readData.get("mykey2")); + } - @AfterEach - public void cleanUp() throws ApiException { - try { + @AfterEach + public void cleanUp() throws ApiException { + try { helper.deleteSecret("test"); - } catch (ApiException e) { - } - } + } catch (ApiException e) {} + } } diff --git a/application/src/test/java/it/smartcommunitylabdhub/core/KanikoImageBuilderTest.java b/application/src/test/java/it/smartcommunitylabdhub/core/KanikoImageBuilderTest.java index 78d4c591..c0ab3226 100644 --- a/application/src/test/java/it/smartcommunitylabdhub/core/KanikoImageBuilderTest.java +++ b/application/src/test/java/it/smartcommunitylabdhub/core/KanikoImageBuilderTest.java @@ -4,17 +4,15 @@ import it.smartcommunitylabdhub.framework.k8s.kubernetes.kaniko.DockerBuildConfig; import it.smartcommunitylabdhub.framework.k8s.kubernetes.kaniko.JobBuildConfig; import it.smartcommunitylabdhub.framework.k8s.kubernetes.kaniko.KanikoImageBuilder; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.context.SpringBootTest; - import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest public class KanikoImageBuilderTest { @@ -44,8 +42,6 @@ public class KanikoImageBuilderTest { @Test void testBuildDockerImage() throws IOException { - - String basePath = Paths.get(System.getProperty("user.dir")).getParent().toString(); // Create a sample DockerBuildConfiguration @@ -55,19 +51,20 @@ void testBuildDockerImage() throws IOException { dockerBuildConfig.setSharedData("https://www.dwsamplefiles.com/?dl_id=557"); dockerBuildConfig.setBaseImage("openjdk:11"); dockerBuildConfig - .addCommand("WORKDIR /app") - .addCommand("COPY . /app") - .addCommand("RUN javac ./HelloWorld.java"); + .addCommand("WORKDIR /app") + .addCommand("COPY . /app") + .addCommand("RUN javac ./HelloWorld.java"); dockerBuildConfig.setEntrypointCommand("\"java\", \"HelloWorld\""); - JobBuildConfig jobBuildConfig = JobBuildConfig.builder() - .type("function") - .name("testfunction") - .uuid(UUID.randomUUID().toString()).build(); + JobBuildConfig jobBuildConfig = JobBuildConfig + .builder() + .type("function") + .name("testfunction") + .uuid(UUID.randomUUID().toString()) + .build(); // Invoke the buildDockerImage method CompletableFuture kaniko = KanikoImageBuilder.buildDockerImage(client, dockerBuildConfig, jobBuildConfig); kaniko.join(); - } } diff --git a/application/src/test/java/it/smartcommunitylabdhub/core/PersonSerializationTest.java b/application/src/test/java/it/smartcommunitylabdhub/core/PersonSerializationTest.java index d37a8e19..bee85353 100644 --- a/application/src/test/java/it/smartcommunitylabdhub/core/PersonSerializationTest.java +++ b/application/src/test/java/it/smartcommunitylabdhub/core/PersonSerializationTest.java @@ -1,16 +1,15 @@ package it.smartcommunitylabdhub.core; +import static org.junit.jupiter.api.Assertions.assertEquals; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import org.junit.jupiter.api.Test; - import java.io.IOException; - -import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; public class PersonSerializationTest { @@ -37,6 +36,7 @@ public void testPersonSerialization() throws IOException { } public static class Person { + private String name; private int age; @@ -59,6 +59,7 @@ public void setAge(int age) { } public abstract static class PersonMixin { + @JsonValue abstract String serializePerson(); @@ -70,6 +71,7 @@ public abstract static class PersonMixin { } public static class CustomAgeSerializer extends StdSerializer { + public CustomAgeSerializer() { this(null); } @@ -79,7 +81,11 @@ public CustomAgeSerializer(Class t) { } @Override - public void serialize(Integer age, com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializerProvider) throws IOException { + public void serialize( + Integer age, + com.fasterxml.jackson.core.JsonGenerator jsonGenerator, + com.fasterxml.jackson.databind.SerializerProvider serializerProvider + ) throws IOException { // Perform custom calculation or transformation on the age before serialization int modifiedAge = age * 2; diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sDeploymentFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sDeploymentFramework.java index 6be36138..4d725db4 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sDeploymentFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sDeploymentFramework.java @@ -233,60 +233,62 @@ public void execute(K8sDeploymentRunnable runnable) throws CoreException { log.info("Dbt Kubernetes Listener [" + threadName + "] " + deploymentName + "@" + namespace); // Define a function with parameters - Function>, Void>>> checkDeploymentStatus = - dName -> - cName -> - fMachine -> { - try { - V1Deployment v1Deployment = appsV1Api.readNamespacedDeployment(dName, namespace, null); - V1DeploymentStatus v1DeploymentStatus = v1Deployment.getStatus(); - - assert v1DeploymentStatus != null; - Objects - .requireNonNull(v1DeploymentStatus.getConditions()) - .forEach(v -> log.info(v.getStatus())); - // // Check the Deployment status - // if (Objects.requireNonNull(v1DeploymentStatus).getReadyReplicas() != null - // && !fMachine.getCurrentState().equals(RunState.COMPLETED)) { - // - // - // // Deployment has completed successfully - // log.info("Deployment completed successfully."); - // // Update state machine and update runDTO - // fMachine.goToState(RunState.COMPLETED); - // Run runDTO = runService.getRun(runnable.getId()); - // runDTO.getStatus().put("state", fsm.getCurrentState().name()); - // runService.updateRun(runDTO, runDTO.getId()); - // - // // Log pod status - // logPod(dName, cName, namespace, runnable); - // // Delete job and pod - // //deleteAssociatedPodAndJob(dName, namespace, runnable); - // - // } else if (Objects.requireNonNull(v1DeploymentStatus).getFailed() != null) { - // // Deployment has failed delete job and pod - // //deleteAssociatedPodAndJob(dName, namespace, runnable); - // - // } else if (v1DeploymentStatus.getActive() != null && v1DeploymentStatus.getActive() > 0) { - // if (!fMachine.getCurrentState().equals(RunState.RUNNING)) { - // fMachine.goToState(RunState.READY); - // fMachine.goToState(RunState.RUNNING); - // } - // log.warn("Deployment is running..."); - // logPod(dName, cName, namespace, runnable); - // } else { - // String v1JobStatusString = JacksonMapper.CUSTOM_OBJECT_MAPPER.writeValueAsString(v1DeploymentStatus); - // log.warn("Deployment is in an unknown state : " + v1JobStatusString); - // writeLog(runnable, v1JobStatusString); - // } - - } catch (ApiException | CoreException e) { - deleteAssociatedPodAndJob(dName, namespace, runnable); - throw new StopPoller(e.getMessage()); - } + Function< + String, + Function>, Void>> + > checkDeploymentStatus = dName -> + cName -> + fMachine -> { + try { + V1Deployment v1Deployment = appsV1Api.readNamespacedDeployment(dName, namespace, null); + V1DeploymentStatus v1DeploymentStatus = v1Deployment.getStatus(); + + assert v1DeploymentStatus != null; + Objects + .requireNonNull(v1DeploymentStatus.getConditions()) + .forEach(v -> log.info(v.getStatus())); + // // Check the Deployment status + // if (Objects.requireNonNull(v1DeploymentStatus).getReadyReplicas() != null + // && !fMachine.getCurrentState().equals(RunState.COMPLETED)) { + // + // + // // Deployment has completed successfully + // log.info("Deployment completed successfully."); + // // Update state machine and update runDTO + // fMachine.goToState(RunState.COMPLETED); + // Run runDTO = runService.getRun(runnable.getId()); + // runDTO.getStatus().put("state", fsm.getCurrentState().name()); + // runService.updateRun(runDTO, runDTO.getId()); + // + // // Log pod status + // logPod(dName, cName, namespace, runnable); + // // Delete job and pod + // //deleteAssociatedPodAndJob(dName, namespace, runnable); + // + // } else if (Objects.requireNonNull(v1DeploymentStatus).getFailed() != null) { + // // Deployment has failed delete job and pod + // //deleteAssociatedPodAndJob(dName, namespace, runnable); + // + // } else if (v1DeploymentStatus.getActive() != null && v1DeploymentStatus.getActive() > 0) { + // if (!fMachine.getCurrentState().equals(RunState.RUNNING)) { + // fMachine.goToState(RunState.READY); + // fMachine.goToState(RunState.RUNNING); + // } + // log.warn("Deployment is running..."); + // logPod(dName, cName, namespace, runnable); + // } else { + // String v1JobStatusString = JacksonMapper.CUSTOM_OBJECT_MAPPER.writeValueAsString(v1DeploymentStatus); + // log.warn("Deployment is in an unknown state : " + v1JobStatusString); + // writeLog(runnable, v1JobStatusString); + // } + + } catch (ApiException | CoreException e) { + deleteAssociatedPodAndJob(dName, namespace, runnable); + throw new StopPoller(e.getMessage()); + } - return null; - }; + return null; + }; // Using the step method with explicit arguments pollingService.createPoller( diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sJobFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sJobFramework.java index bb93255a..bc95765a 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sJobFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sJobFramework.java @@ -219,55 +219,57 @@ public void execute(K8sJobRunnable runnable) throws CoreException { log.info("Dbt Kubernetes Listener [" + threadName + "] " + jobName + "@" + namespace); // Define a function with parameters - Function>, Void>>> checkJobStatus = - jName -> - cName -> - fMachine -> { - try { - V1Job v1Job = batchV1Api.readNamespacedJob(jName, namespace, null); - V1JobStatus v1JobStatus = v1Job.getStatus(); - - // Check the Job status - if ( - Objects.requireNonNull(v1JobStatus).getSucceeded() != null && - !fMachine.getCurrentState().equals(RunState.COMPLETED) - ) { - // Job has completed successfully - log.info("Job completed successfully."); - // Update state machine and update runDTO - fMachine.goToState(RunState.COMPLETED); - Run runDTO = runService.getRun(runnable.getId()); - runDTO.getStatus().put("state", fsm.getCurrentState().name()); - runService.updateRun(runDTO, runDTO.getId()); - - // Log pod status - logPod(jName, cName, namespace, runnable); - // Delete job and pod - deleteAssociatedPodAndJob(jName, namespace, runnable); - } else if (Objects.requireNonNull(v1JobStatus).getFailed() != null) { - // Job has failed delete job and pod - deleteAssociatedPodAndJob(jName, namespace, runnable); - } else if (v1JobStatus.getActive() != null && v1JobStatus.getActive() > 0) { - if (!fMachine.getCurrentState().equals(RunState.RUNNING)) { - fMachine.goToState(RunState.READY); - fMachine.goToState(RunState.RUNNING); - } - log.warn("Job is running..."); - logPod(jName, cName, namespace, runnable); - } else { - String v1JobStatusString = JacksonMapper.CUSTOM_OBJECT_MAPPER.writeValueAsString( - v1JobStatus - ); - log.warn("Job is in an unknown state : " + v1JobStatusString); - writeLog(runnable, v1JobStatusString); - } - } catch (ApiException | JsonProcessingException | CoreException e) { + Function< + String, + Function>, Void>> + > checkJobStatus = jName -> + cName -> + fMachine -> { + try { + V1Job v1Job = batchV1Api.readNamespacedJob(jName, namespace, null); + V1JobStatus v1JobStatus = v1Job.getStatus(); + + // Check the Job status + if ( + Objects.requireNonNull(v1JobStatus).getSucceeded() != null && + !fMachine.getCurrentState().equals(RunState.COMPLETED) + ) { + // Job has completed successfully + log.info("Job completed successfully."); + // Update state machine and update runDTO + fMachine.goToState(RunState.COMPLETED); + Run runDTO = runService.getRun(runnable.getId()); + runDTO.getStatus().put("state", fsm.getCurrentState().name()); + runService.updateRun(runDTO, runDTO.getId()); + + // Log pod status + logPod(jName, cName, namespace, runnable); + // Delete job and pod + deleteAssociatedPodAndJob(jName, namespace, runnable); + } else if (Objects.requireNonNull(v1JobStatus).getFailed() != null) { + // Job has failed delete job and pod deleteAssociatedPodAndJob(jName, namespace, runnable); - throw new StopPoller(e.getMessage()); + } else if (v1JobStatus.getActive() != null && v1JobStatus.getActive() > 0) { + if (!fMachine.getCurrentState().equals(RunState.RUNNING)) { + fMachine.goToState(RunState.READY); + fMachine.goToState(RunState.RUNNING); + } + log.warn("Job is running..."); + logPod(jName, cName, namespace, runnable); + } else { + String v1JobStatusString = JacksonMapper.CUSTOM_OBJECT_MAPPER.writeValueAsString( + v1JobStatus + ); + log.warn("Job is in an unknown state : " + v1JobStatusString); + writeLog(runnable, v1JobStatusString); } + } catch (ApiException | JsonProcessingException | CoreException e) { + deleteAssociatedPodAndJob(jName, namespace, runnable); + throw new StopPoller(e.getMessage()); + } - return null; - }; + return null; + }; // Using the step method with explicit arguments pollingService.createPoller( diff --git a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sServeFramework.java b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sServeFramework.java index ae0326d8..9bf9e3fe 100644 --- a/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sServeFramework.java +++ b/modules/framework-k8s/src/main/java/it/smartcommunitylabdhub/framework/k8s/infrastructure/K8sServeFramework.java @@ -253,60 +253,62 @@ public void execute(K8sServeRunnable runnable) throws CoreException { log.info("Dbt Kubernetes Listener [" + threadName + "] " + deploymentName + "@" + namespace); // Define a function with parameters - Function>, Void>>> checkServeStatus = - dName -> - cName -> - fMachine -> { - try { - V1Deployment v1Deployment = appsV1Api.readNamespacedDeployment(dName, namespace, null); - V1DeploymentStatus v1DeploymentStatus = v1Deployment.getStatus(); - - assert v1DeploymentStatus != null; - Objects - .requireNonNull(v1DeploymentStatus.getConditions()) - .forEach(v -> log.info(v.getStatus())); - // // Check the Serve status - // if (Objects.requireNonNull(v1ServeStatus).getReadyReplicas() != null - // && !fMachine.getCurrentState().equals(RunState.COMPLETED)) { - // - // - // // Serve has completed successfully - // log.info("Serve completed successfully."); - // // Update state machine and update runDTO - // fMachine.goToState(RunState.COMPLETED); - // Run runDTO = runService.getRun(runnable.getId()); - // runDTO.getStatus().put("state", fsm.getCurrentState().name()); - // runService.updateRun(runDTO, runDTO.getId()); - // - // // Log pod status - // logPod(dName, cName, namespace, runnable); - // // Delete job and pod - // //deleteAssociatedPodAndJob(dName, namespace, runnable); - // - // } else if (Objects.requireNonNull(v1ServeStatus).getFailed() != null) { - // // Serve has failed delete job and pod - // //deleteAssociatedPodAndJob(dName, namespace, runnable); - // - // } else if (v1ServeStatus.getActive() != null && v1ServeStatus.getActive() > 0) { - // if (!fMachine.getCurrentState().equals(RunState.RUNNING)) { - // fMachine.goToState(RunState.READY); - // fMachine.goToState(RunState.RUNNING); - // } - // log.warn("Serve is running..."); - // logPod(dName, cName, namespace, runnable); - // } else { - // String v1JobStatusString = JacksonMapper.CUSTOM_OBJECT_MAPPER.writeValueAsString(v1ServeStatus); - // log.warn("Serve is in an unknown state : " + v1JobStatusString); - // writeLog(runnable, v1JobStatusString); - // } - - } catch (ApiException | CoreException e) { - deleteAssociatedPodAndJob(dName, namespace, runnable); - throw new StopPoller(e.getMessage()); - } + Function< + String, + Function>, Void>> + > checkServeStatus = dName -> + cName -> + fMachine -> { + try { + V1Deployment v1Deployment = appsV1Api.readNamespacedDeployment(dName, namespace, null); + V1DeploymentStatus v1DeploymentStatus = v1Deployment.getStatus(); + + assert v1DeploymentStatus != null; + Objects + .requireNonNull(v1DeploymentStatus.getConditions()) + .forEach(v -> log.info(v.getStatus())); + // // Check the Serve status + // if (Objects.requireNonNull(v1ServeStatus).getReadyReplicas() != null + // && !fMachine.getCurrentState().equals(RunState.COMPLETED)) { + // + // + // // Serve has completed successfully + // log.info("Serve completed successfully."); + // // Update state machine and update runDTO + // fMachine.goToState(RunState.COMPLETED); + // Run runDTO = runService.getRun(runnable.getId()); + // runDTO.getStatus().put("state", fsm.getCurrentState().name()); + // runService.updateRun(runDTO, runDTO.getId()); + // + // // Log pod status + // logPod(dName, cName, namespace, runnable); + // // Delete job and pod + // //deleteAssociatedPodAndJob(dName, namespace, runnable); + // + // } else if (Objects.requireNonNull(v1ServeStatus).getFailed() != null) { + // // Serve has failed delete job and pod + // //deleteAssociatedPodAndJob(dName, namespace, runnable); + // + // } else if (v1ServeStatus.getActive() != null && v1ServeStatus.getActive() > 0) { + // if (!fMachine.getCurrentState().equals(RunState.RUNNING)) { + // fMachine.goToState(RunState.READY); + // fMachine.goToState(RunState.RUNNING); + // } + // log.warn("Serve is running..."); + // logPod(dName, cName, namespace, runnable); + // } else { + // String v1JobStatusString = JacksonMapper.CUSTOM_OBJECT_MAPPER.writeValueAsString(v1ServeStatus); + // log.warn("Serve is in an unknown state : " + v1JobStatusString); + // writeLog(runnable, v1JobStatusString); + // } + + } catch (ApiException | CoreException e) { + deleteAssociatedPodAndJob(dName, namespace, runnable); + throw new StopPoller(e.getMessage()); + } - return null; - }; + return null; + }; // Using the step method with explicit arguments pollingService.createPoller( diff --git a/modules/fsm/src/test/java/it/smartcommunitylabdhub/fsm/StateMachineTest.java b/modules/fsm/src/test/java/it/smartcommunitylabdhub/fsm/StateMachineTest.java index 0d4f8749..047c76ed 100644 --- a/modules/fsm/src/test/java/it/smartcommunitylabdhub/fsm/StateMachineTest.java +++ b/modules/fsm/src/test/java/it/smartcommunitylabdhub/fsm/StateMachineTest.java @@ -9,148 +9,113 @@ @SpringBootTest public class StateMachineTest { - // some method definition - - @Test - public void fsm() { - // Create the state machine - - State> state1 = new State<>(); - State> state2 = new State<>(); - State> state3 = new State<>(); - State> state4 = new State<>(); - State> errorState = new State<>(); // Error - // state - - // Create the initial state and context - String initialState = "State1"; - Map initialContext = new HashMap<>(); - - // Create the state machine using the builder - StateMachine.Builder> builder = - StateMachine - .>builder( - initialState, - Optional.of(initialContext) - ) - .withState("State1", state1) - .withState("State2", state2) - .withState("State3", state3) - .withState("State4", state4) - .withErrorState("ErrorState", errorState) - .withStateChangeListener((newState, context) -> - System.out.println( - "State Change Listener: " + newState + ", context: " + context - ) + // some method definition + + @Test + public void fsm() { + // Create the state machine + + State> state1 = new State<>(); + State> state2 = new State<>(); + State> state3 = new State<>(); + State> state4 = new State<>(); + State> errorState = new State<>(); // Error + // state + + // Create the initial state and context + String initialState = "State1"; + Map initialContext = new HashMap<>(); + + // Create the state machine using the builder + StateMachine.Builder> builder = StateMachine + .>builder(initialState, Optional.of(initialContext)) + .withState("State1", state1) + .withState("State2", state2) + .withState("State3", state3) + .withState("State4", state4) + .withErrorState("ErrorState", errorState) + .withStateChangeListener((newState, context) -> + System.out.println("State Change Listener: " + newState + ", context: " + context) + ); + + // Define transactions for state 1 + state1.addTransaction(new Transaction<>("Event1", "State2", context -> true)); + + // Define transactions for state 2 + state2.addTransaction(new Transaction<>("Event2", "State3", context -> true)); + + // Define transactions for state 3 + state3.addTransaction(new Transaction<>("Event3", "State4", context -> true)); + + // Define transactions for state 4 + state4.addTransaction(new Transaction<>("Event4", "State1", context -> true)); + + // Set internal logic for state 1 + state1.setInternalLogic((context, stateMachine) -> { + System.out.println("Executing internal logic of State1 with context: " + context); + context.put("value", 1); + return Optional.of("State1 Result"); + }); + + // Set internal logic for state 2 + state2.setInternalLogic((context, stateMachine) -> { + System.out.println("Executing internal logic of State2 with context: " + context); + context.put("value", 2); + return Optional.of("State2 Result"); + }); + + // Set internal logic for state 3 + state3.setInternalLogic((context, stateMachine) -> { + System.out.println("Executing internal logic of State3 with context: " + context); + context.put("value", 3); + return Optional.of("State3 Result"); + }); + + // Set internal logic for state 4 + state4.setInternalLogic((context, stateMachine) -> { + System.out.println("Executing internal logic of State4 with context: " + context); + context.put("value", 4); + return Optional.of("State4 Result"); + }); + + // Set internal logic for the error state + errorState.setInternalLogic((context, stateMachine) -> { + System.out.println("Error state reached. context: " + context); + // Handle error logic here + return Optional.empty(); // No result for error state + }); + + // Add event listeners + builder.withEventListener("Event1", context -> System.out.println("Event1 Listener: context: " + context)); + builder.withEventListener("Event2", context -> System.out.println("Event2 Listener: context: " + context)); + builder.withEventListener("Event3", context -> System.out.println("Event3 Listener: context: " + context)); + builder.withEventListener("Event4", context -> System.out.println("Event4 Listener: context: " + context)); + + builder.withExitAction( + "State1", + context -> { + System.out.println("exit action for state 1"); + } ); - // Define transactions for state 1 - state1.addTransaction( - new Transaction<>("Event1", "State2", context -> true) - ); - - // Define transactions for state 2 - state2.addTransaction( - new Transaction<>("Event2", "State3", context -> true) - ); - - // Define transactions for state 3 - state3.addTransaction( - new Transaction<>("Event3", "State4", context -> true) - ); - - // Define transactions for state 4 - state4.addTransaction( - new Transaction<>("Event4", "State1", context -> true) - ); - - // Set internal logic for state 1 - state1.setInternalLogic((context, stateMachine) -> { - System.out.println( - "Executing internal logic of State1 with context: " + context - ); - context.put("value", 1); - return Optional.of("State1 Result"); - }); - - // Set internal logic for state 2 - state2.setInternalLogic((context, stateMachine) -> { - System.out.println( - "Executing internal logic of State2 with context: " + context - ); - context.put("value", 2); - return Optional.of("State2 Result"); - }); - - // Set internal logic for state 3 - state3.setInternalLogic((context, stateMachine) -> { - System.out.println( - "Executing internal logic of State3 with context: " + context - ); - context.put("value", 3); - return Optional.of("State3 Result"); - }); - - // Set internal logic for state 4 - state4.setInternalLogic((context, stateMachine) -> { - System.out.println( - "Executing internal logic of State4 with context: " + context - ); - context.put("value", 4); - return Optional.of("State4 Result"); - }); - - // Set internal logic for the error state - errorState.setInternalLogic((context, stateMachine) -> { - System.out.println("Error state reached. context: " + context); - // Handle error logic here - return Optional.empty(); // No result for error state - }); - - // Add event listeners - builder.withEventListener( - "Event1", - context -> System.out.println("Event1 Listener: context: " + context) - ); - builder.withEventListener( - "Event2", - context -> System.out.println("Event2 Listener: context: " + context) - ); - builder.withEventListener( - "Event3", - context -> System.out.println("Event3 Listener: context: " + context) - ); - builder.withEventListener( - "Event4", - context -> System.out.println("Event4 Listener: context: " + context) - ); - - builder.withExitAction( - "State1", - context -> { - System.out.println("exit action for state 1"); - } - ); - - // Build the state machine - StateMachine> stateMachine = - builder.build(); - - // Trigger events to test the state machine - stateMachine.goToState("State2"); - stateMachine.goToState("State3"); - stateMachine.goToState("State4"); - // try { - // String ser = stateMachine.serialize(); - - // System.out.println(ser); - - // StateMachine> stateMachine2 = - // StateMachine.deserialize(ser); - // System.out.println("Deserialize"); - // } catch (Exception e) { - // System.out.println(e.getMessage()); - // } - - } + // Build the state machine + StateMachine> stateMachine = builder.build(); + + // Trigger events to test the state machine + stateMachine.goToState("State2"); + stateMachine.goToState("State3"); + stateMachine.goToState("State4"); + // try { + // String ser = stateMachine.serialize(); + + // System.out.println(ser); + + // StateMachine> stateMachine2 = + // StateMachine.deserialize(ser); + // System.out.println("Deserialize"); + // } catch (Exception e) { + // System.out.println(e.getMessage()); + // } + + } } diff --git a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/ContainerRuntime.java b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/ContainerRuntime.java index 9189a792..eee78a21 100644 --- a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/ContainerRuntime.java +++ b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/ContainerRuntime.java @@ -49,25 +49,21 @@ public class ContainerRuntime implements Runtime { TaskDeploySpec taskDeploySpec = specRegistry.createSpec( - "container+deploy", - EntityName.TASK, - taskSpec.toMap() + "container+deploy", + EntityName.TASK, + taskSpec.toMap() ); - RunContainerSpec runRunSpec = specRegistry.createSpec( - "container+run", - EntityName.RUN, - runSpec.toMap() - ); + RunContainerSpec runRunSpec = specRegistry.createSpec("container+run", EntityName.RUN, runSpec.toMap()); /** * As an alternative, you can use the code below to retrieve the correct builder. @@ -85,17 +81,9 @@ public RunContainerSpec build( return builder.build(funSpec, taskDeploySpec, runRunSpec); } case "container+job" -> { - TaskJobSpec taskJobSpec = specRegistry.createSpec( - "container+job", - EntityName.TASK, - taskSpec.toMap() - ); + TaskJobSpec taskJobSpec = specRegistry.createSpec("container+job", EntityName.TASK, taskSpec.toMap()); - RunContainerSpec runRunSpec = specRegistry.createSpec( - "container+run", - EntityName.RUN, - runSpec.toMap() - ); + RunContainerSpec runRunSpec = specRegistry.createSpec("container+run", EntityName.RUN, runSpec.toMap()); /** * As an alternative, you can use the code below to retrieve the correct builder. @@ -114,16 +102,12 @@ public RunContainerSpec build( } case "container+serve" -> { TaskServeSpec taskServeSpec = specRegistry.createSpec( - "container+serve", - EntityName.TASK, - taskSpec.toMap() + "container+serve", + EntityName.TASK, + taskSpec.toMap() ); - RunContainerSpec runRunSpec = specRegistry.createSpec( - "container+run", - EntityName.RUN, - runSpec.toMap() - ); + RunContainerSpec runRunSpec = specRegistry.createSpec("container+run", EntityName.RUN, runSpec.toMap()); /** * As an alternative, you can use the code below to retrieve the correct builder. @@ -141,9 +125,9 @@ public RunContainerSpec build( return builder.build(funSpec, taskServeSpec, runRunSpec); } default -> throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "Kind not recognized. Cannot retrieve the right builder or specialize Spec for Run and Task.", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "Kind not recognized. Cannot retrieve the right builder or specialize Spec for Run and Task.", + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -159,24 +143,24 @@ public Runnable run(Run runDTO) { return switch (runAccessor.getTask()) { case "deploy" -> new ContainerDeployRunner( - runContainerSpec.getFuncSpec(), - secretService.groupSecrets(runDTO.getProject(), runContainerSpec.getTaskDeploySpec().getSecrets()) + runContainerSpec.getFuncSpec(), + secretService.groupSecrets(runDTO.getProject(), runContainerSpec.getTaskDeploySpec().getSecrets()) ) - .produce(runDTO); + .produce(runDTO); case "job" -> new ContainerJobRunner( - runContainerSpec.getFuncSpec(), - secretService.groupSecrets(runDTO.getProject(), runContainerSpec.getTaskJobSpec().getSecrets()) + runContainerSpec.getFuncSpec(), + secretService.groupSecrets(runDTO.getProject(), runContainerSpec.getTaskJobSpec().getSecrets()) ) - .produce(runDTO); + .produce(runDTO); case "serve" -> new ContainerServeRunner( - runContainerSpec.getFuncSpec(), - secretService.groupSecrets(runDTO.getProject(), runContainerSpec.getTaskServeSpec().getSecrets()) + runContainerSpec.getFuncSpec(), + secretService.groupSecrets(runDTO.getProject(), runContainerSpec.getTaskServeSpec().getSecrets()) ) - .produce(runDTO); + .produce(runDTO); default -> throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "Kind not recognized. Cannot retrieve the right Runner", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "Kind not recognized. Cannot retrieve the right Runner", + HttpStatus.INTERNAL_SERVER_ERROR ); }; } diff --git a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/function/FunctionContainerSpec.java b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/function/FunctionContainerSpec.java index cae8ca1a..bf94f98f 100644 --- a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/function/FunctionContainerSpec.java +++ b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/function/FunctionContainerSpec.java @@ -6,19 +6,14 @@ import it.smartcommunitylabdhub.commons.models.entities.function.specs.FunctionBaseSpec; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import jakarta.validation.constraints.NotBlank; -import lombok.Getter; -import lombok.Setter; - import java.util.List; import java.util.Map; +import lombok.Getter; +import lombok.Setter; @Getter @Setter -@SpecType( - kind = "container", - entity = EntityName.FUNCTION, - factory = FunctionContainerSpec.class -) +@SpecType(kind = "container", entity = EntityName.FUNCTION, factory = FunctionContainerSpec.class) public class FunctionContainerSpec extends FunctionBaseSpec { @NotBlank @@ -34,8 +29,8 @@ public class FunctionContainerSpec extends FunctionBaseSpec { @Override public void configure(Map data) { FunctionContainerSpec functionContainerSpec = JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue( - data, - FunctionContainerSpec.class + data, + FunctionContainerSpec.class ); this.setCommand(functionContainerSpec.getCommand()); diff --git a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/run/RunContainerSpec.java b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/run/RunContainerSpec.java index cb01d14f..7d604f0b 100644 --- a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/run/RunContainerSpec.java +++ b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/run/RunContainerSpec.java @@ -9,9 +9,8 @@ import it.smartcommunitylabdhub.runtime.container.models.specs.task.TaskDeploySpec; import it.smartcommunitylabdhub.runtime.container.models.specs.task.TaskJobSpec; import it.smartcommunitylabdhub.runtime.container.models.specs.task.TaskServeSpec; -import lombok.*; - import java.util.Map; +import lombok.*; @Getter @Setter @@ -36,8 +35,8 @@ public class RunContainerSpec extends RunBaseSpec { @Override public void configure(Map data) { RunContainerSpec runContainerSpec = JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue( - data, - RunContainerSpec.class + data, + RunContainerSpec.class ); this.setTaskJobSpec(runContainerSpec.getTaskJobSpec()); diff --git a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskDeploySpec.java b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskDeploySpec.java index 157f8086..6b4b4419 100644 --- a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskDeploySpec.java +++ b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskDeploySpec.java @@ -4,11 +4,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.framework.k8s.base.K8sTaskBaseSpec; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "container+deploy", entity = EntityName.TASK, factory = TaskDeploySpec.class) diff --git a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskJobSpec.java b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskJobSpec.java index c53e89a8..77eeb8e7 100644 --- a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskJobSpec.java +++ b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskJobSpec.java @@ -4,11 +4,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.framework.k8s.base.K8sTaskBaseSpec; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "container+job", entity = EntityName.TASK, factory = TaskJobSpec.class) diff --git a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskServeSpec.java b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskServeSpec.java index 3947cb7e..ab784d03 100644 --- a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskServeSpec.java +++ b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/models/specs/task/TaskServeSpec.java @@ -3,11 +3,10 @@ import it.smartcommunitylabdhub.commons.annotations.common.SpecType; import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "container+serve", entity = EntityName.TASK, factory = TaskServeSpec.class) diff --git a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerDeployRunner.java b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerDeployRunner.java index 985e15f9..20cb58d5 100644 --- a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerDeployRunner.java +++ b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerDeployRunner.java @@ -9,7 +9,6 @@ import it.smartcommunitylabdhub.runtime.container.ContainerRuntime; import it.smartcommunitylabdhub.runtime.container.models.specs.function.FunctionContainerSpec; import it.smartcommunitylabdhub.runtime.container.models.specs.run.RunContainerSpec; - import java.util.*; /** @@ -40,35 +39,35 @@ public K8sDeploymentRunnable produce(Run runDTO) { runContainerSpec.configure(runDTO.getSpec()); RunFieldAccessor runDefaultFieldAccessor = RunFieldAccessor.with( - JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) + JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) ); List coreEnvList = new ArrayList<>( - List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) + List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) ); Optional.ofNullable(runContainerSpec.getTaskDeploySpec().getEnvs()).ifPresent(coreEnvList::addAll); K8sDeploymentRunnable k8sDeploymentRunnable = K8sDeploymentRunnable - .builder() - .runtime(ContainerRuntime.RUNTIME) //TODO: delete accessor. - .task(TASK) - .image(functionContainerSpec.getImage()) - .state(runDefaultFieldAccessor.getState()) - .resources(runContainerSpec.getTaskDeploySpec().getResources()) - .nodeSelector(runContainerSpec.getTaskDeploySpec().getNodeSelector()) - .volumes(runContainerSpec.getTaskDeploySpec().getVolumes()) - .secrets(groupedSecrets) - .envs(coreEnvList) - .build(); + .builder() + .runtime(ContainerRuntime.RUNTIME) //TODO: delete accessor. + .task(TASK) + .image(functionContainerSpec.getImage()) + .state(runDefaultFieldAccessor.getState()) + .resources(runContainerSpec.getTaskDeploySpec().getResources()) + .nodeSelector(runContainerSpec.getTaskDeploySpec().getNodeSelector()) + .volumes(runContainerSpec.getTaskDeploySpec().getVolumes()) + .secrets(groupedSecrets) + .envs(coreEnvList) + .build(); Optional - .ofNullable(functionContainerSpec.getArgs()) - .ifPresent(args -> - k8sDeploymentRunnable.setArgs( - args.stream().filter(Objects::nonNull).map(Object::toString).toArray(String[]::new) - ) - ); + .ofNullable(functionContainerSpec.getArgs()) + .ifPresent(args -> + k8sDeploymentRunnable.setArgs( + args.stream().filter(Objects::nonNull).map(Object::toString).toArray(String[]::new) + ) + ); Optional.ofNullable(functionContainerSpec.getEntrypoint()).ifPresent(k8sDeploymentRunnable::setEntrypoint); diff --git a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerJobRunner.java b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerJobRunner.java index b29547dc..5af13ada 100644 --- a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerJobRunner.java +++ b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerJobRunner.java @@ -9,7 +9,6 @@ import it.smartcommunitylabdhub.runtime.container.ContainerRuntime; import it.smartcommunitylabdhub.runtime.container.models.specs.function.FunctionContainerSpec; import it.smartcommunitylabdhub.runtime.container.models.specs.run.RunContainerSpec; - import java.util.*; /** diff --git a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerServeRunner.java b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerServeRunner.java index e4dee3c6..9be4b5c4 100644 --- a/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerServeRunner.java +++ b/modules/runtime-container/src/main/java/it/smartcommunitylabdhub/runtime/container/runners/ContainerServeRunner.java @@ -9,7 +9,6 @@ import it.smartcommunitylabdhub.runtime.container.ContainerRuntime; import it.smartcommunitylabdhub.runtime.container.models.specs.function.FunctionContainerSpec; import it.smartcommunitylabdhub.runtime.container.models.specs.run.RunContainerSpec; - import java.util.*; /** @@ -37,34 +36,34 @@ public K8sServeRunnable produce(Run runDTO) { runContainerSpec.configure(runDTO.getSpec()); RunFieldAccessor runDefaultFieldAccessor = RunFieldAccessor.with( - JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) + JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) ); List coreEnvList = new ArrayList<>( - List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) + List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) ); Optional.ofNullable(runContainerSpec.getTaskServeSpec().getEnvs()).ifPresent(coreEnvList::addAll); K8sServeRunnable k8sServeRunnable = K8sServeRunnable - .builder() - .runtime(ContainerRuntime.RUNTIME) - .task(TASK) - .image(functionContainerSpec.getImage()) - .state(runDefaultFieldAccessor.getState()) - .resources(runContainerSpec.getTaskServeSpec().getResources()) - .nodeSelector(runContainerSpec.getTaskServeSpec().getNodeSelector()) - .volumes(runContainerSpec.getTaskServeSpec().getVolumes()) - .secrets(groupedSecrets) - .envs(coreEnvList) - .build(); + .builder() + .runtime(ContainerRuntime.RUNTIME) + .task(TASK) + .image(functionContainerSpec.getImage()) + .state(runDefaultFieldAccessor.getState()) + .resources(runContainerSpec.getTaskServeSpec().getResources()) + .nodeSelector(runContainerSpec.getTaskServeSpec().getNodeSelector()) + .volumes(runContainerSpec.getTaskServeSpec().getVolumes()) + .secrets(groupedSecrets) + .envs(coreEnvList) + .build(); Optional - .ofNullable(functionContainerSpec.getArgs()) - .ifPresent(args -> - k8sServeRunnable.setArgs( - args.stream().filter(Objects::nonNull).map(Object::toString).toArray(String[]::new) - ) - ); + .ofNullable(functionContainerSpec.getArgs()) + .ifPresent(args -> + k8sServeRunnable.setArgs( + args.stream().filter(Objects::nonNull).map(Object::toString).toArray(String[]::new) + ) + ); Optional.ofNullable(functionContainerSpec.getEntrypoint()).ifPresent(k8sServeRunnable::setEntrypoint); diff --git a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/DbtRuntime.java b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/DbtRuntime.java index ae664293..be29d1ae 100644 --- a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/DbtRuntime.java +++ b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/DbtRuntime.java @@ -44,9 +44,9 @@ public RunDbtSpec build(FunctionDbtSpec funSpec, TaskBaseSpec taskSpec, RunBaseS // Retrieve builder using task kind if (kind.equals("dbt+transform")) { TaskTransformSpec taskTransformSpec = specRegistry.createSpec( - "dbt+transform", - EntityName.TASK, - taskSpec.toMap() + "dbt+transform", + EntityName.TASK, + taskSpec.toMap() ); RunDbtSpec runDbtSpec = specRegistry.createSpec("dbt+run", EntityName.RUN, runSpec.toMap()); @@ -68,9 +68,9 @@ public RunDbtSpec build(FunctionDbtSpec funSpec, TaskBaseSpec taskSpec, RunBaseS } throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "Kind not recognized. Cannot retrieve the right builder or specialize Spec for Run and Task.", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "Kind not recognized. Cannot retrieve the right builder or specialize Spec for Run and Task.", + HttpStatus.INTERNAL_SERVER_ERROR ); } @@ -99,8 +99,8 @@ public K8sJobRunnable run(Run runDTO) { runDbtSpec.configure(runDTO.getSpec()); DbtTransformRunner runner = new DbtTransformRunner( - image, - secretService.groupSecrets(runDTO.getProject(), runDbtSpec.getTaskSpec().getSecrets()) + image, + secretService.groupSecrets(runDTO.getProject(), runDbtSpec.getTaskSpec().getSecrets()) ); return runner.produce(runDTO); diff --git a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/function/FunctionDbtSpec.java b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/function/FunctionDbtSpec.java index 481bcc83..6d0f82b4 100644 --- a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/function/FunctionDbtSpec.java +++ b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/function/FunctionDbtSpec.java @@ -4,11 +4,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.models.entities.function.specs.FunctionBaseSpec; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "dbt", entity = EntityName.FUNCTION, factory = FunctionDbtSpec.class) diff --git a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/run/RunDbtSpec.java b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/run/RunDbtSpec.java index 23c004a6..97cffca5 100644 --- a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/run/RunDbtSpec.java +++ b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/run/RunDbtSpec.java @@ -7,9 +7,8 @@ import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.runtime.dbt.models.specs.function.FunctionDbtSpec; import it.smartcommunitylabdhub.runtime.dbt.models.specs.task.TaskTransformSpec; -import lombok.*; - import java.util.Map; +import lombok.*; @Getter @Setter diff --git a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/task/TaskTransformSpec.java b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/task/TaskTransformSpec.java index 8790b34c..922cf642 100644 --- a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/task/TaskTransformSpec.java +++ b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/models/specs/task/TaskTransformSpec.java @@ -4,11 +4,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.framework.k8s.base.K8sTaskBaseSpec; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "dbt+transform", entity = EntityName.TASK, factory = TaskTransformSpec.class) @@ -17,8 +16,8 @@ public class TaskTransformSpec extends K8sTaskBaseSpec { @Override public void configure(Map data) { TaskTransformSpec taskTransformSpec = JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue( - data, - TaskTransformSpec.class + data, + TaskTransformSpec.class ); super.configure(data); diff --git a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/runners/DbtTransformRunner.java b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/runners/DbtTransformRunner.java index 75b4d32c..89d08375 100644 --- a/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/runners/DbtTransformRunner.java +++ b/modules/runtime-dbt/src/main/java/it/smartcommunitylabdhub/runtime/dbt/runners/DbtTransformRunner.java @@ -8,7 +8,6 @@ import it.smartcommunitylabdhub.framework.k8s.runnables.K8sJobRunnable; import it.smartcommunitylabdhub.runtime.dbt.DbtRuntime; import it.smartcommunitylabdhub.runtime.dbt.models.specs.run.RunDbtSpec; - import java.util.*; /** @@ -38,30 +37,30 @@ public K8sJobRunnable produce(Run runDTO) { runDbtSpec.configure(runDTO.getSpec()); RunFieldAccessor runDefaultFieldAccessor = RunFieldAccessor.with( - JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) + JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) ); List coreEnvList = new ArrayList<>( - List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) + List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) ); - + Optional.ofNullable(runDbtSpec.getTaskSpec().getEnvs()).ifPresent(coreEnvList::addAll); //TODO: Create runnable using information from Run completed spec. K8sJobRunnable k8sJobRunnable = K8sJobRunnable - .builder() - .runtime(DbtRuntime.RUNTIME) - .task(TASK) - .image(image) - .command("python") - .args(List.of("wrapper.py").toArray(String[]::new)) - .resources(runDbtSpec.getTaskSpec().getResources()) - .nodeSelector(runDbtSpec.getTaskSpec().getNodeSelector()) - .volumes(runDbtSpec.getTaskSpec().getVolumes()) - .secrets(groupedSecrets) - .envs(coreEnvList) - .state(runDefaultFieldAccessor.getState()) - .build(); + .builder() + .runtime(DbtRuntime.RUNTIME) + .task(TASK) + .image(image) + .command("python") + .args(List.of("wrapper.py").toArray(String[]::new)) + .resources(runDbtSpec.getTaskSpec().getResources()) + .nodeSelector(runDbtSpec.getTaskSpec().getNodeSelector()) + .volumes(runDbtSpec.getTaskSpec().getVolumes()) + .secrets(groupedSecrets) + .envs(coreEnvList) + .state(runDefaultFieldAccessor.getState()) + .build(); k8sJobRunnable.setId(runDTO.getId()); k8sJobRunnable.setProject(runDTO.getProject()); diff --git a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/MlrunRuntime.java b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/MlrunRuntime.java index c1b337c9..05fded63 100644 --- a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/MlrunRuntime.java +++ b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/MlrunRuntime.java @@ -64,9 +64,9 @@ public RunMlrunSpec build(FunctionMlrunSpec funSpec, TaskBaseSpec taskSpec, RunB } throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "Kind not recognized. Cannot retrieve the right builder or specialize Spec for Run and Task.", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "Kind not recognized. Cannot retrieve the right builder or specialize Spec for Run and Task.", + HttpStatus.INTERNAL_SERVER_ERROR ); } @@ -95,8 +95,8 @@ public K8sJobRunnable run(Run runDTO) { runRunSpec.configure(runDTO.getSpec()); MlrunMlrunRunner runner = new MlrunMlrunRunner( - image, - secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskSpec().getSecrets()) + image, + secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskSpec().getSecrets()) ); return runner.produce(runDTO); diff --git a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/function/FunctionMlrunSpec.java b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/function/FunctionMlrunSpec.java index 950b4b7d..4eaeb1d6 100644 --- a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/function/FunctionMlrunSpec.java +++ b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/function/FunctionMlrunSpec.java @@ -4,12 +4,11 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.models.entities.function.specs.FunctionBaseSpec; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; -import lombok.Getter; -import lombok.Setter; - import java.io.Serializable; import java.util.List; import java.util.Map; +import lombok.Getter; +import lombok.Setter; @Getter @Setter @@ -25,8 +24,8 @@ public class FunctionMlrunSpec extends FunctionBaseSpec { @Override public void configure(Map data) { FunctionMlrunSpec functionMlrunSpec = JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue( - data, - FunctionMlrunSpec.class + data, + FunctionMlrunSpec.class ); this.setImage(functionMlrunSpec.getImage()); diff --git a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/run/RunMlrunSpec.java b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/run/RunMlrunSpec.java index a5f073c1..c4cf1cd9 100644 --- a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/run/RunMlrunSpec.java +++ b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/run/RunMlrunSpec.java @@ -7,9 +7,8 @@ import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.runtime.mlrun.models.specs.function.FunctionMlrunSpec; import it.smartcommunitylabdhub.runtime.mlrun.models.specs.task.TaskMlrunSpec; -import lombok.*; - import java.util.Map; +import lombok.*; @Getter @Setter diff --git a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/task/TaskMlrunSpec.java b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/task/TaskMlrunSpec.java index 3eb5ae00..a9c9c724 100644 --- a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/task/TaskMlrunSpec.java +++ b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/models/specs/task/TaskMlrunSpec.java @@ -4,11 +4,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.framework.k8s.base.K8sTaskBaseSpec; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "mlrun+mlrun", entity = EntityName.TASK, factory = TaskMlrunSpec.class) diff --git a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/runners/MlrunMlrunRunner.java b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/runners/MlrunMlrunRunner.java index 9782d1e1..6249805f 100644 --- a/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/runners/MlrunMlrunRunner.java +++ b/modules/runtime-mlrun/src/main/java/it/smartcommunitylabdhub/runtime/mlrun/runners/MlrunMlrunRunner.java @@ -8,7 +8,6 @@ import it.smartcommunitylabdhub.framework.k8s.runnables.K8sJobRunnable; import it.smartcommunitylabdhub.runtime.mlrun.MlrunRuntime; import it.smartcommunitylabdhub.runtime.mlrun.models.specs.run.RunMlrunSpec; - import java.util.*; /** @@ -37,30 +36,30 @@ public K8sJobRunnable produce(Run runDTO) { runMlrunSpec.configure(runDTO.getSpec()); RunFieldAccessor runDefaultFieldAccessor = RunFieldAccessor.with( - JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) + JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) ); List coreEnvList = new ArrayList<>( - List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) + List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) ); Optional.ofNullable(runMlrunSpec.getTaskSpec().getEnvs()).ifPresent(coreEnvList::addAll); //TODO: Create runnable using information from Run completed spec. K8sJobRunnable k8sJobRunnable = K8sJobRunnable - .builder() - .runtime(MlrunRuntime.RUNTIME) - .task(TASK) - .image(image) - .command("python") - .args(List.of("wrapper.py").toArray(String[]::new)) - .resources(runMlrunSpec.getTaskSpec().getResources()) - .nodeSelector(runMlrunSpec.getTaskSpec().getNodeSelector()) - .volumes(runMlrunSpec.getTaskSpec().getVolumes()) - .secrets(groupedSecrets) - .envs(coreEnvList) - .state(runDefaultFieldAccessor.getState()) - .build(); + .builder() + .runtime(MlrunRuntime.RUNTIME) + .task(TASK) + .image(image) + .command("python") + .args(List.of("wrapper.py").toArray(String[]::new)) + .resources(runMlrunSpec.getTaskSpec().getResources()) + .nodeSelector(runMlrunSpec.getTaskSpec().getNodeSelector()) + .volumes(runMlrunSpec.getTaskSpec().getVolumes()) + .secrets(groupedSecrets) + .envs(coreEnvList) + .state(runDefaultFieldAccessor.getState()) + .build(); k8sJobRunnable.setId(runDTO.getId()); k8sJobRunnable.setProject(runDTO.getProject()); diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/NefertemRuntime.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/NefertemRuntime.java index a7aa2872..026b2c56 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/NefertemRuntime.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/NefertemRuntime.java @@ -48,10 +48,10 @@ public class NefertemRuntime implements Runtime { NefertemValidateBuilder builder = new NefertemValidateBuilder(); return builder.build( - funSpec, - specRegistry.createSpec("nefertem+validate", EntityName.TASK, taskSpec.toMap()), - specRegistry.createSpec("nefertem+run", EntityName.RUN, runSpec.toMap()) + funSpec, + specRegistry.createSpec("nefertem+validate", EntityName.TASK, taskSpec.toMap()), + specRegistry.createSpec("nefertem+run", EntityName.RUN, runSpec.toMap()) ); } case "nefertem+metric" -> { NefertemMetricBuilder builder = new NefertemMetricBuilder(); return builder.build( - funSpec, - specRegistry.createSpec("nefertem+metric", EntityName.TASK, taskSpec.toMap()), - specRegistry.createSpec("nefertem+run", EntityName.RUN, runSpec.toMap()) + funSpec, + specRegistry.createSpec("nefertem+metric", EntityName.TASK, taskSpec.toMap()), + specRegistry.createSpec("nefertem+run", EntityName.RUN, runSpec.toMap()) ); } case "nefertem+profile" -> { NefertemProfileBuilder builder = new NefertemProfileBuilder(); return builder.build( - funSpec, - specRegistry.createSpec("nefertem+profile", EntityName.TASK, taskSpec.toMap()), - specRegistry.createSpec("nefertem+run", EntityName.RUN, runSpec.toMap()) + funSpec, + specRegistry.createSpec("nefertem+profile", EntityName.TASK, taskSpec.toMap()), + specRegistry.createSpec("nefertem+run", EntityName.RUN, runSpec.toMap()) ); } default -> throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "Kind not recognized. Cannot retrieve the right builder or specialize Spec for Run and Task.", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "Kind not recognized. Cannot retrieve the right builder or specialize Spec for Run and Task.", + HttpStatus.INTERNAL_SERVER_ERROR ); } } @@ -141,29 +141,29 @@ public K8sJobRunnable run(Run runDTO) { return switch (runAccessor.getTask()) { case "infer" -> new NefertemInferRunner( - image, - secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskInferSpec().getSecrets()) + image, + secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskInferSpec().getSecrets()) ) - .produce(runDTO); + .produce(runDTO); case "validate" -> new NefertemValidateRunner( - image, - secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskValidateSpec().getSecrets()) + image, + secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskValidateSpec().getSecrets()) ) - .produce(runDTO); + .produce(runDTO); case "profile" -> new NefertemProfileRunner( - image, - secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskProfileSpec().getSecrets()) + image, + secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskProfileSpec().getSecrets()) ) - .produce(runDTO); + .produce(runDTO); case "metric" -> new NefertemMetricRunner( - image, - secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskMetricSpec().getSecrets()) + image, + secretService.groupSecrets(runDTO.getProject(), runRunSpec.getTaskMetricSpec().getSecrets()) ) - .produce(runDTO); + .produce(runDTO); default -> throw new CoreException( - ErrorList.INTERNAL_SERVER_ERROR.getValue(), - "Kind not recognized. Cannot retrieve the right Runner", - HttpStatus.INTERNAL_SERVER_ERROR + ErrorList.INTERNAL_SERVER_ERROR.getValue(), + "Kind not recognized. Cannot retrieve the right Runner", + HttpStatus.INTERNAL_SERVER_ERROR ); }; } diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/function/FunctionNefertemSpec.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/function/FunctionNefertemSpec.java index b2d25558..4080af25 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/function/FunctionNefertemSpec.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/function/FunctionNefertemSpec.java @@ -5,11 +5,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.models.entities.function.specs.FunctionBaseSpec; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; -import lombok.Getter; -import lombok.Setter; - import java.util.List; import java.util.Map; +import lombok.Getter; +import lombok.Setter; @Getter @Setter @@ -26,8 +25,8 @@ public class FunctionNefertemSpec extends FunctionBaseSpec { @Override public void configure(Map data) { FunctionNefertemSpec functionNefertemSpec = JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue( - data, - FunctionNefertemSpec.class + data, + FunctionNefertemSpec.class ); this.setConstraints(functionNefertemSpec.getConstraints()); diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/run/RunNefertemSpec.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/run/RunNefertemSpec.java index b0209922..26ecd12c 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/run/RunNefertemSpec.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/run/RunNefertemSpec.java @@ -10,9 +10,8 @@ import it.smartcommunitylabdhub.runtime.nefertem.models.specs.task.TaskMetricSpec; import it.smartcommunitylabdhub.runtime.nefertem.models.specs.task.TaskProfileSpec; import it.smartcommunitylabdhub.runtime.nefertem.models.specs.task.TaskValidateSpec; -import lombok.*; - import java.util.Map; +import lombok.*; @Getter @Setter diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskInferSpec.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskInferSpec.java index fa17f1bf..88b02c76 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskInferSpec.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskInferSpec.java @@ -5,11 +5,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.framework.k8s.base.K8sTaskBaseSpec; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "nefertem+infer", entity = EntityName.TASK, factory = TaskInferSpec.class) diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskMetricSpec.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskMetricSpec.java index 7386a335..29191337 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskMetricSpec.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskMetricSpec.java @@ -5,11 +5,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.framework.k8s.base.K8sTaskBaseSpec; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "nefertem+metric", entity = EntityName.TASK, factory = TaskMetricSpec.class) diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskProfileSpec.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskProfileSpec.java index 922dcbe5..9a1ce573 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskProfileSpec.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskProfileSpec.java @@ -5,11 +5,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.framework.k8s.base.K8sTaskBaseSpec; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "nefertem+profile", entity = EntityName.TASK, factory = TaskProfileSpec.class) diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskValidateSpec.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskValidateSpec.java index 1bbc2a7e..025a98cf 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskValidateSpec.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/models/specs/task/TaskValidateSpec.java @@ -5,11 +5,10 @@ import it.smartcommunitylabdhub.commons.infrastructure.enums.EntityName; import it.smartcommunitylabdhub.commons.utils.jackson.JacksonMapper; import it.smartcommunitylabdhub.framework.k8s.base.K8sTaskBaseSpec; +import java.util.Map; import lombok.Getter; import lombok.Setter; -import java.util.Map; - @Getter @Setter @SpecType(kind = "nefertem+validate", entity = EntityName.TASK, factory = TaskValidateSpec.class) @@ -28,8 +27,8 @@ public class TaskValidateSpec extends K8sTaskBaseSpec { @Override public void configure(Map data) { TaskValidateSpec taskValidateSpec = JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue( - data, - TaskValidateSpec.class + data, + TaskValidateSpec.class ); this.setFramework(taskValidateSpec.getFramework()); diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemInferRunner.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemInferRunner.java index f2accaff..3703d884 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemInferRunner.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemInferRunner.java @@ -8,7 +8,6 @@ import it.smartcommunitylabdhub.framework.k8s.runnables.K8sJobRunnable; import it.smartcommunitylabdhub.runtime.nefertem.NefertemRuntime; import it.smartcommunitylabdhub.runtime.nefertem.models.specs.run.RunNefertemSpec; - import java.util.*; /** @@ -37,30 +36,30 @@ public K8sJobRunnable produce(Run runDTO) { runNefertemSpec.configure(runDTO.getSpec()); RunFieldAccessor runDefaultFieldAccessor = RunFieldAccessor.with( - JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) + JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) ); List coreEnvList = new ArrayList<>( - List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) + List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) ); Optional.ofNullable(runNefertemSpec.getTaskInferSpec().getEnvs()).ifPresent(coreEnvList::addAll); //TODO: Create runnable using information from Run completed spec. K8sJobRunnable k8sJobRunnable = K8sJobRunnable - .builder() - .runtime(NefertemRuntime.RUNTIME) - .task(TASK) - .image(image) - .command("python") - .args(List.of("wrapper.py").toArray(String[]::new)) - .resources(runNefertemSpec.getTaskInferSpec().getResources()) - .nodeSelector(runNefertemSpec.getTaskInferSpec().getNodeSelector()) - .volumes(runNefertemSpec.getTaskInferSpec().getVolumes()) - .secrets(groupedSecrets) - .envs(coreEnvList) - .state(runDefaultFieldAccessor.getState()) - .build(); + .builder() + .runtime(NefertemRuntime.RUNTIME) + .task(TASK) + .image(image) + .command("python") + .args(List.of("wrapper.py").toArray(String[]::new)) + .resources(runNefertemSpec.getTaskInferSpec().getResources()) + .nodeSelector(runNefertemSpec.getTaskInferSpec().getNodeSelector()) + .volumes(runNefertemSpec.getTaskInferSpec().getVolumes()) + .secrets(groupedSecrets) + .envs(coreEnvList) + .state(runDefaultFieldAccessor.getState()) + .build(); k8sJobRunnable.setId(runDTO.getId()); k8sJobRunnable.setProject(runDTO.getProject()); diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemMetricRunner.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemMetricRunner.java index a8b927b0..ae176db5 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemMetricRunner.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemMetricRunner.java @@ -8,7 +8,6 @@ import it.smartcommunitylabdhub.framework.k8s.runnables.K8sJobRunnable; import it.smartcommunitylabdhub.runtime.nefertem.NefertemRuntime; import it.smartcommunitylabdhub.runtime.nefertem.models.specs.run.RunNefertemSpec; - import java.util.*; /** @@ -38,30 +37,30 @@ public K8sJobRunnable produce(Run runDTO) { runNefertemSpec.configure(runDTO.getSpec()); RunFieldAccessor runDefaultFieldAccessor = RunFieldAccessor.with( - JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) + JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) ); List coreEnvList = new ArrayList<>( - List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) + List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) ); - + Optional.ofNullable(runNefertemSpec.getTaskMetricSpec().getEnvs()).ifPresent(coreEnvList::addAll); //TODO: Create runnable using information from Run completed spec. K8sJobRunnable k8sJobRunnable = K8sJobRunnable - .builder() - .runtime(NefertemRuntime.RUNTIME) - .task(TASK) - .image(image) - .command("python") - .args(List.of("wrapper.py").toArray(String[]::new)) - .resources(runNefertemSpec.getTaskMetricSpec().getResources()) - .nodeSelector(runNefertemSpec.getTaskMetricSpec().getNodeSelector()) - .volumes(runNefertemSpec.getTaskMetricSpec().getVolumes()) - .secrets(groupedSecrets) - .envs(coreEnvList) - .state(runDefaultFieldAccessor.getState()) - .build(); + .builder() + .runtime(NefertemRuntime.RUNTIME) + .task(TASK) + .image(image) + .command("python") + .args(List.of("wrapper.py").toArray(String[]::new)) + .resources(runNefertemSpec.getTaskMetricSpec().getResources()) + .nodeSelector(runNefertemSpec.getTaskMetricSpec().getNodeSelector()) + .volumes(runNefertemSpec.getTaskMetricSpec().getVolumes()) + .secrets(groupedSecrets) + .envs(coreEnvList) + .state(runDefaultFieldAccessor.getState()) + .build(); k8sJobRunnable.setId(runDTO.getId()); k8sJobRunnable.setProject(runDTO.getProject()); diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemProfileRunner.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemProfileRunner.java index 4d64ea8f..d3a2158e 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemProfileRunner.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemProfileRunner.java @@ -8,7 +8,6 @@ import it.smartcommunitylabdhub.framework.k8s.runnables.K8sJobRunnable; import it.smartcommunitylabdhub.runtime.nefertem.NefertemRuntime; import it.smartcommunitylabdhub.runtime.nefertem.models.specs.run.RunNefertemSpec; - import java.util.*; /** @@ -38,30 +37,30 @@ public K8sJobRunnable produce(Run runDTO) { runNefertemSpec.configure(runDTO.getSpec()); RunFieldAccessor runDefaultFieldAccessor = RunFieldAccessor.with( - JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) + JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) ); List coreEnvList = new ArrayList<>( - List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) + List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) ); Optional.ofNullable(runNefertemSpec.getTaskProfileSpec().getEnvs()).ifPresent(coreEnvList::addAll); //TODO: Create runnable using information from Run completed spec. K8sJobRunnable k8sJobRunnable = K8sJobRunnable - .builder() - .runtime(NefertemRuntime.RUNTIME) - .task(TASK) - .image(image) - .command("python") - .args(List.of("wrapper.py").toArray(String[]::new)) - .resources(runNefertemSpec.getTaskProfileSpec().getResources()) - .nodeSelector(runNefertemSpec.getTaskProfileSpec().getNodeSelector()) - .volumes(runNefertemSpec.getTaskProfileSpec().getVolumes()) - .secrets(groupedSecrets) - .envs(coreEnvList) - .state(runDefaultFieldAccessor.getState()) - .build(); + .builder() + .runtime(NefertemRuntime.RUNTIME) + .task(TASK) + .image(image) + .command("python") + .args(List.of("wrapper.py").toArray(String[]::new)) + .resources(runNefertemSpec.getTaskProfileSpec().getResources()) + .nodeSelector(runNefertemSpec.getTaskProfileSpec().getNodeSelector()) + .volumes(runNefertemSpec.getTaskProfileSpec().getVolumes()) + .secrets(groupedSecrets) + .envs(coreEnvList) + .state(runDefaultFieldAccessor.getState()) + .build(); k8sJobRunnable.setId(runDTO.getId()); k8sJobRunnable.setProject(runDTO.getProject()); diff --git a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemValidateRunner.java b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemValidateRunner.java index 68021088..bce1729c 100644 --- a/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemValidateRunner.java +++ b/modules/runtime-nefertem/src/main/java/it/smartcommunitylabdhub/runtime/nefertem/runners/NefertemValidateRunner.java @@ -8,7 +8,6 @@ import it.smartcommunitylabdhub.framework.k8s.runnables.K8sJobRunnable; import it.smartcommunitylabdhub.runtime.nefertem.NefertemRuntime; import it.smartcommunitylabdhub.runtime.nefertem.models.specs.run.RunNefertemSpec; - import java.util.*; /** @@ -37,30 +36,30 @@ public K8sJobRunnable produce(Run runDTO) { runNefertemSpec.configure(runDTO.getSpec()); RunFieldAccessor runDefaultFieldAccessor = RunFieldAccessor.with( - JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) + JacksonMapper.CUSTOM_OBJECT_MAPPER.convertValue(runDTO, JacksonMapper.typeRef) ); List coreEnvList = new ArrayList<>( - List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) + List.of(new CoreEnv("PROJECT_NAME", runDTO.getProject()), new CoreEnv("RUN_ID", runDTO.getId())) ); Optional.ofNullable(runNefertemSpec.getTaskValidateSpec().getEnvs()).ifPresent(coreEnvList::addAll); //TODO: Create runnable using information from Run completed spec. K8sJobRunnable k8sJobRunnable = K8sJobRunnable - .builder() - .runtime(NefertemRuntime.RUNTIME) - .task(TASK) - .image(image) - .command("python") - .args(List.of("wrapper.py").toArray(String[]::new)) - .resources(runNefertemSpec.getTaskValidateSpec().getResources()) - .nodeSelector(runNefertemSpec.getTaskValidateSpec().getNodeSelector()) - .volumes(runNefertemSpec.getTaskValidateSpec().getVolumes()) - .secrets(groupedSecrets) - .envs(coreEnvList) - .state(runDefaultFieldAccessor.getState()) - .build(); + .builder() + .runtime(NefertemRuntime.RUNTIME) + .task(TASK) + .image(image) + .command("python") + .args(List.of("wrapper.py").toArray(String[]::new)) + .resources(runNefertemSpec.getTaskValidateSpec().getResources()) + .nodeSelector(runNefertemSpec.getTaskValidateSpec().getNodeSelector()) + .volumes(runNefertemSpec.getTaskValidateSpec().getVolumes()) + .secrets(groupedSecrets) + .envs(coreEnvList) + .state(runDefaultFieldAccessor.getState()) + .build(); k8sJobRunnable.setId(runDTO.getId()); k8sJobRunnable.setProject(runDTO.getProject());