Skip to content

Commit

Permalink
applied modifications on properties name and workflow_resource deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
candreac committed Nov 11, 2023
1 parent 1c3ec2d commit 400e112
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
import jakarta.ws.rs.FormParam;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterRestClient(configKey = "process-deploy")
public interface ProcessClient {
@POST
@Path("/api/v1/processes/deploy")
@Path("/api/v1/processes/deploy/{type}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
Uni<DeployResponseDto> deploy(@FormParam("url") String url);
Uni<DeployResponseDto> deploy(@FormParam("url") String url, @PathParam("type") String type);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package it.gov.pagopa.atmlayer.service.model.mapper;

import it.gov.pagopa.atmlayer.service.model.dto.WorkflowResourceCreationDto;
import it.gov.pagopa.atmlayer.service.model.entity.BpmnVersion;
import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource;
import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum;
import it.gov.pagopa.atmlayer.service.model.model.BpmnDTO;
import it.gov.pagopa.atmlayer.service.model.model.WorkflowResourceDTO;
import it.gov.pagopa.atmlayer.service.model.utils.BpmnUtils;
import org.mapstruct.Mapper;
Expand Down Expand Up @@ -33,7 +31,7 @@ public WorkflowResource toEntityCreation(WorkflowResourceCreationDto workflowCre

public abstract WorkflowResourceDTO toDTO(WorkflowResource workflowResource);

public List<WorkflowResourceDTO> toDTOList(List<WorkflowResource> list){
public List<WorkflowResourceDTO> toDTOList(List<WorkflowResource> list) {
return list.stream().map(this::toDTO).collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.gov.pagopa.atmlayer.service.model.model;

import it.gov.pagopa.atmlayer.service.model.enumeration.DeployableResourceType;
import it.gov.pagopa.atmlayer.service.model.enumeration.FunctionTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -33,6 +34,7 @@ public class WorkflowResourceDTO {
private String description;
private ResourceFileDTO resourceFile;
private String resource;
private DeployableResourceType resourceType;
private UUID deploymentId;
@Schema(description = "Creation Timestamp", format = "timestamp", pattern = "DD/MM/YYYY", example = "2023-11-03T14:18:36.635+00:00")
private Timestamp createdAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ObjectStoreProperties {

WorkflowResource workflowResource();

Html html();
Resource resource();

interface Bucket {
String name();
Expand All @@ -39,8 +39,8 @@ interface WorkflowResource {
String pathTemplate();
}

interface Html {
String pathTemplate();
interface Resource {
String pathTemplate();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class WorkflowResourceResource {

@GET
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<WorkflowResourceDTO>> getAllBpmn(){
public Uni<List<WorkflowResourceDTO>> getAll() {
return this.workflowResourceService.getAll()
.onItem()
.transform(Unchecked.function(list -> {
Expand Down Expand Up @@ -75,25 +75,28 @@ public Uni<WorkflowResourceDTO> getById(@PathParam("uuid") UUID id) {
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@NonBlocking
public Uni<WorkflowResourceDTO> createWorkflowResource(@RequestBody(required = true) @Valid WorkflowResourceCreationDto workflowResourceCreationDto) throws NoSuchAlgorithmException, IOException {
public Uni<WorkflowResourceDTO> create(@RequestBody(required = true) @Valid WorkflowResourceCreationDto workflowResourceCreationDto) throws NoSuchAlgorithmException, IOException {
WorkflowResource workflowResource = workflowResourceMapper.toEntityCreation(workflowResourceCreationDto);
return this.workflowResourceService.createWorkflowResource(workflowResource, workflowResourceCreationDto.getFile(), workflowResourceCreationDto.getFilename())
.onItem().transformToUni(bpmn -> Uni.createFrom().item(this.workflowResourceMapper.toDTO(bpmn)));
}

@POST
@Path("/deploy/{uuid}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Uni<WorkflowResourceDTO> deployBPMN(@PathParam("uuid") UUID uuid) {
return this.workflowResourceService.deploy(uuid)
.onItem().transformToUni(workflow -> Uni.createFrom().item(this.workflowResourceMapper.toDTO(workflow)));
public Uni<WorkflowResourceDTO> deploy(@PathParam("uuid") UUID uuid) {
return this.workflowResourceService.findById(uuid)
.onItem()
.transformToUni(resource -> this.workflowResourceService.deploy(resource))
.onItem().transformToUni(resourceDeployed -> Uni.createFrom().item(this.workflowResourceMapper.toDTO(resourceDeployed)));
}

@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{uuid}")
public Uni<Void> deleteBpmn(@PathParam("uuid") UUID uuid) {
public Uni<Void> delete(@PathParam("uuid") UUID uuid) {

return this.workflowResourceService.delete(uuid)
.onItem().ignore().andSwitchTo(Uni.createFrom().voidItem());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface WorkflowResourceService {

Uni<Optional<WorkflowResource>> findByDefinitionKey(String definitionKey);

Uni<WorkflowResource> deploy(UUID uuid);
Uni<WorkflowResource> deploy(Optional<WorkflowResource> optionalWorkflowResource);

Uni<WorkflowResource> saveAndUpload(WorkflowResource workflowResource, File file, String filename);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,14 @@ public Uni<BpmnVersion> deploy(BpmnVersionPK bpmnVersionPK) {
.onItem().transformToUni(x -> Uni.createFrom().failure(new AtmLayerException("Error in BPMN deploy. Fail to generate presigned URL", Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500)));
});
})
.onItem().transformToUni(presignedUrl -> {
return processClient.deploy(presignedUrl.toString())
.onFailure().recoverWithUni(failure -> {
log.error(failure.getMessage());
return this.setBpmnVersionStatus(bpmnVersionPK, StatusEnum.DEPLOY_ERROR)
.onItem().transformToUni(x -> Uni.createFrom().failure(new AtmLayerException("Error in BPMN deploy. Communication with Process Service failed", Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500)));
})
.onItem()
.transformToUni(response -> this.setDeployInfo(bpmnVersionPK, response));
});
.onItem().transformToUni(presignedUrl -> processClient.deploy(presignedUrl.toString(),DeployableResourceType.BPMN.name())
.onFailure().recoverWithUni(failure -> {
log.error(failure.getMessage());
return this.setBpmnVersionStatus(bpmnVersionPK, StatusEnum.DEPLOY_ERROR)
.onItem().transformToUni(x -> Uni.createFrom().failure(new AtmLayerException("Error in BPMN deploy. Communication with Process Service failed", Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500)));
})
.onItem()
.transformToUni(response -> this.setDeployInfo(bpmnVersionPK, response)));
}

@WithTransaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private String calculatePath(S3ResourceTypeEnum s3ResourceTypeEnum) {
valuesMap.put("RESOURCE_TYPE", s3ResourceTypeEnum.toString());
StringSubstitutor stringSubstitutor = new StringSubstitutor(valuesMap);
Optional<String> resourceEntityPathTemplateProps = Optional.ofNullable(
objectStoreProperties.html().pathTemplate());
objectStoreProperties.resource().pathTemplate());
String pathTemplate = null;
if (resourceEntityPathTemplateProps.isPresent() && StringUtils.isNotBlank(
resourceEntityPathTemplateProps.get())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
import it.gov.pagopa.atmlayer.service.model.entity.ResourceFile;
import it.gov.pagopa.atmlayer.service.model.entity.WorkflowResource;
import it.gov.pagopa.atmlayer.service.model.enumeration.AppErrorCodeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.DeployableResourceType;
import it.gov.pagopa.atmlayer.service.model.enumeration.S3ResourceTypeEnum;
import it.gov.pagopa.atmlayer.service.model.enumeration.StatusEnum;
import it.gov.pagopa.atmlayer.service.model.exception.AtmLayerException;
import it.gov.pagopa.atmlayer.service.model.repository.WorkflowResourceRepository;
import it.gov.pagopa.atmlayer.service.model.service.WorkflowResourceService;
Expand Down Expand Up @@ -92,7 +93,7 @@ public Uni<Optional<WorkflowResource>> findByDefinitionKey(String definitionKey)
}


private Uni<Boolean> checkWorkflowResourceFileExistence(UUID uuid) {
public Uni<Boolean> checkWorkflowResourceFileExistence(UUID uuid) {
return this.findById(uuid)
.onItem()
.transform(Unchecked.function(optionalWorkflowResource -> {
Expand Down Expand Up @@ -128,17 +129,15 @@ public Uni<WorkflowResource> setWorkflowResourceVersionStatus(UUID uuid, StatusE
}

@Override
public Uni<WorkflowResource> deploy(UUID uuid) {
return this.checkWorkflowResourceFileExistence(uuid)
.onItem()
.transformToUni(Unchecked.function(x -> {
if (!x) {
String errorMessage = "The referenced Workflow Resource file can not be deployed";
throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST,
AppErrorCodeEnum.WORKFLOW_RESOURCE_FILE_CANNOT_BE_DEPLOYED);
}
return this.setWorkflowResourceVersionStatus(uuid, StatusEnum.WAITING_DEPLOY);
}))
public Uni<WorkflowResource> deploy(Optional<WorkflowResource> optionalWorkflowResource) {
if (optionalWorkflowResource.isEmpty()) {
String errorMessage = "The referenced Workflow Resource file can not be deployed";
throw new AtmLayerException(errorMessage, Response.Status.BAD_REQUEST,
AppErrorCodeEnum.WORKFLOW_RESOURCE_FILE_CANNOT_BE_DEPLOYED);
}
UUID uuid = optionalWorkflowResource.get().getWorkflowResourceId();
DeployableResourceType resourceType = optionalWorkflowResource.get().getResourceType();
return this.setWorkflowResourceVersionStatus(uuid, StatusEnum.WAITING_DEPLOY)
.onItem()
.transformToUni(workflowWaiting -> {
ResourceFile resourceFile = workflowWaiting.getResourceFile();
Expand All @@ -155,16 +154,14 @@ public Uni<WorkflowResource> deploy(UUID uuid) {
.onItem().transformToUni(x -> Uni.createFrom().failure(new AtmLayerException("Error in Workflow Resource deploy. Fail to generate presigned URL", Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500)));
});
})
.onItem().transformToUni(presignedUrl -> {
return processClient.deploy(presignedUrl.toString())
.onFailure().recoverWithUni(failure -> {
log.error(failure.getMessage());
return this.setWorkflowResourceVersionStatus(uuid, StatusEnum.DEPLOY_ERROR)
.onItem().transformToUni(x -> Uni.createFrom().failure(new AtmLayerException("Error in Workflow Resource deploy. Communication with Process Service failed", Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500)));
})
.onItem()
.transformToUni(response -> this.setDeployInfo(uuid, response));
});
.onItem().transformToUni(presignedUrl -> processClient.deploy(presignedUrl.toString(), resourceType.name())
.onFailure().recoverWithUni(failure -> {
log.error(failure.getMessage());
return this.setWorkflowResourceVersionStatus(uuid, StatusEnum.DEPLOY_ERROR)
.onItem().transformToUni(x -> Uni.createFrom().failure(new AtmLayerException("Error in Workflow Resource deploy. Communication with Process Service failed", Response.Status.INTERNAL_SERVER_ERROR, ATMLM_500)));
})
.onItem()
.transformToUni(response -> this.setDeployInfo(uuid, response)));
}

@WithTransaction
Expand Down
6 changes: 2 additions & 4 deletions src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ quarkus.http.port=${SERVER_PORT:8086}
quarkus.datasource.db-kind=${MODEL_DB_TYPE:postgresql}
quarkus.datasource.username=${MODEL_DB_USERNAME:postgres}
quarkus.datasource.password=${MODEL_DB_PASSWORD:password}
quarkus.datasource.reactive.url=${MODEL_DB_URL:postgresql://localhost:5433/postgres?search_path=atm_layer_model}
quarkus.datasource.reactive.url=${MODEL_DB_URL:postgresql://localhost:5433/postgres?search_path=atm_layer_model_new}
quarkus.hibernate-orm.database.generation=${MODEL_DB_SCHEMA_UPDATE_TYPE:none}
quarkus.log.console.json=false
quarkus.console.color=true
Expand All @@ -26,8 +26,6 @@ object-store.bucket.region=${MODEL_OBJECT_STORE_REGION:eu-south-1}
object-store.bucket.access-key=${OBJECT_STORE_ACCESS_KEY_ID:admin123}
object-store.bucket.secret-key=${OBJECT_STORE_ACCESS_KEY_SECRET:admin123}
object-store.bucket.endpoint-override=http://127.0.0.1:9999
object-store.resource.path-template=${MODEL_OBJECT_STORE_HTML_TEMPLATE_PATH:/RESOURCE/files/[RESOURCE_TYPE]}
object-store.bpmn.path-template=${MODEL_OBJECT_STORE_BPMN_TEMPLATE_PATH:BPMN/files/UUID/[uuid]/VERSION/[version]}
object-store.workflow-resource.path-template=${MODEL_OBJECT_STORE_WORKFLOW_RESOURCE_TEMPLATE_PATH:WORKFLOW_RESOURCE/[RESOURCE_TYPE]/files/UUID/[uuid]}
quarkus.resteay-reactive.input-buffer-size=10000
object-store.dmn.path-template=${MODEL_OBJECT_STORE_DMN_TEMPLATE_PATH:WORKFLOW_RESOURCE/files/[RESOURCE_TYPE]/[uuid]}
object-store.html.path-template=${MODEL_OBJECT_STORE_HTML_TEMPLATE_PATH:/RESOURCE/files/[RESOURCE_TYPE]}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object-store.bucket.name=${MODEL_OBJECT_STORE_BUCKET_NAME:pagopa-dev-atm-layer-s
object-store.bucket.region=${MODEL_OBJECT_STORE_REGION:eu-south-1}
object-store.bpmn.path-template=${MODEL_OBJECT_STORE_BPMN_TEMPLATE_PATH:BPMN/files/UUID/[uuid]/VERSION/[version]}
object-store.workflow-resource.path-template=${MODEL_OBJECT_STORE_WORKFLOW_RESOURCE_TEMPLATE_PATH:WORKFLOW_RESOURCE/[RESOURCE_TYPE]/files/UUID/[uuid]}
object-store.html.path-template=${MODEL_OBJECT_STORE_HTML_TEMPLATE_PATH:/RESOURCE/files/[RESOURCE_TYPE]}
object-store.resource.path-template=${MODEL_OBJECT_STORE_RESOURCE_TEMPLATE_PATH:/RESOURCE/files/[RESOURCE_TYPE]}
quarkus.rest-client.process-deploy.url=${MODEL_PROCESS_BASE_PATH:http://pagopa-dev-atm-layer-wf-process.pagopa.svc.cluster.local:8080}


Expand Down
Loading

0 comments on commit 400e112

Please sign in to comment.