diff --git a/src/main/java/it/reply/orchestrator/service/DeploymentServiceImpl.java b/src/main/java/it/reply/orchestrator/service/DeploymentServiceImpl.java index cbcf5c9dd8..c67742eecf 100644 --- a/src/main/java/it/reply/orchestrator/service/DeploymentServiceImpl.java +++ b/src/main/java/it/reply/orchestrator/service/DeploymentServiceImpl.java @@ -19,6 +19,7 @@ import alien4cloud.tosca.model.ArchiveRoot; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import it.reply.orchestrator.config.properties.OidcProperties; import it.reply.orchestrator.dal.entity.Deployment; import it.reply.orchestrator.dal.entity.OidcEntity; @@ -53,6 +54,7 @@ import it.reply.orchestrator.utils.MdcUtils; import it.reply.orchestrator.utils.ToscaConstants; import it.reply.orchestrator.utils.WorkflowConstants; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -240,7 +242,20 @@ public Deployment createDeployment(DeploymentRequest request, OidcEntity owner, deployment.setUserGroup(request.getUserGroup()); deployment = deploymentRepository.save(deployment); MdcUtils.setDeploymentId(deployment.getId()); - LOG.debug("Creating deployment with template\n{}", request.getTemplate()); + + // Print the submitted template and the parameters requested by the user for the deployment + LOG.info("Creating deployment with template\n{}", request.getTemplate()); + try { + ObjectNode mergedJson = objectMapper.createObjectNode(); + mergedJson.putPOJO("uuid", deployment.getId()); + mergedJson.putPOJO("user_group", request.getUserGroup()); + mergedJson.putPOJO("user_parameters", request.getParameters()); + String mergedString = objectMapper.writeValueAsString(mergedJson); + LOG.info(mergedString); + } catch (IOException e) { + e.getMessage(); + } + // Parse once, validate structure and user's inputs, replace user's input ArchiveRoot parsingResult = toscaService.prepareTemplate(request.getTemplate(), request.getParameters()); diff --git a/src/main/java/it/reply/orchestrator/service/commands/BaseJavaDelegate.java b/src/main/java/it/reply/orchestrator/service/commands/BaseJavaDelegate.java index f86b72cc90..c6e84235df 100644 --- a/src/main/java/it/reply/orchestrator/service/commands/BaseJavaDelegate.java +++ b/src/main/java/it/reply/orchestrator/service/commands/BaseJavaDelegate.java @@ -20,17 +20,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; - +import com.fasterxml.jackson.databind.node.ObjectNode; import it.reply.orchestrator.exception.service.BusinessWorkflowException; import it.reply.orchestrator.exception.service.WorkflowException; import it.reply.orchestrator.utils.MdcUtils; import it.reply.orchestrator.utils.WorkflowConstants.ErrorCode; import it.reply.orchestrator.utils.WorkflowUtil; - import java.util.Optional; - import lombok.extern.slf4j.Slf4j; - import org.flowable.bpmn.model.FlowElement; import org.flowable.common.engine.api.FlowableException; import org.flowable.engine.delegate.DelegateExecution; @@ -46,7 +43,9 @@ public abstract class BaseJavaDelegate implements JavaDelegate { @Override public final void execute(DelegateExecution execution) { String businessKey = execution.getProcessInstanceBusinessKey(); + String deploymentId = businessKey.substring(0, businessKey.indexOf(':')); MdcUtils.fromBusinessKey(businessKey); + ObjectNode logData = objectMapper.createObjectNode(); String taskName = Optional .ofNullable(execution.getCurrentFlowElement()) @@ -60,12 +59,15 @@ public final void execute(DelegateExecution execution) { } catch (BusinessWorkflowException ex) { LOG.error("Task {} - ENDED WITH ERROR:\n{}", taskName, getErrorMessagePrefix(), ex); WorkflowUtil.persistAndPropagateError(execution, ex); + logErrors(logData, ex, deploymentId); } catch (FlowableException | WorkflowException ex) { LOG.error("Task {} - ENDED WITH ERROR:\n{}", taskName, getErrorMessagePrefix(), ex); + logErrors(logData, ex, deploymentId); // Re-throw throw ex; } catch (RuntimeException ex) { LOG.error("Task {} - ENDED WITH ERROR:\n{}", taskName, getErrorMessagePrefix(), ex); + logErrors(logData, ex, deploymentId); throw new WorkflowException(ErrorCode.RUNTIME_ERROR, getErrorMessagePrefix(), ex); } finally { MdcUtils.clean(); @@ -104,6 +106,20 @@ protected C getRequiredParameter(DelegateExecution execution, String paramet .getOptionalParameter(execution, parameterName, clazz) .orElseThrow(() -> new IllegalArgumentException( "WF parameter with name <" + parameterName + "> not found")); + } + + private void logErrors(ObjectNode logData, Exception ex, String deploymentId) { + logData.put("uuid", deploymentId); + logData.put("status", "CREATE_FAILED"); + logData.put("status_reason", ex.toString()); + // Print information about the submission of the deployment + String jsonString = null; + try { + jsonString = objectMapper.writeValueAsString(logData); + LOG.info("Deployment in error. {}", jsonString); + } catch (JsonProcessingException e) { + LOG.error(e.getMessage()); + } } } diff --git a/src/main/java/it/reply/orchestrator/service/commands/FinalizeDeploy.java b/src/main/java/it/reply/orchestrator/service/commands/FinalizeDeploy.java index 90b28c01eb..d2b8a022c9 100644 --- a/src/main/java/it/reply/orchestrator/service/commands/FinalizeDeploy.java +++ b/src/main/java/it/reply/orchestrator/service/commands/FinalizeDeploy.java @@ -17,18 +17,35 @@ package it.reply.orchestrator.service.commands; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import it.reply.orchestrator.dto.deployment.DeploymentMessage; import it.reply.orchestrator.utils.WorkflowConstants; - +import lombok.extern.slf4j.Slf4j; import org.flowable.engine.delegate.DelegateExecution; import org.springframework.stereotype.Component; @Component(WorkflowConstants.Delegate.FINALIZE_DEPLOY) +@Slf4j public class FinalizeDeploy extends BaseDeployCommand { @Override public void execute(DelegateExecution execution, DeploymentMessage deploymentMessage) { getDeploymentProviderService(deploymentMessage).finalizeDeploy(deploymentMessage); + ObjectMapper objectMapper = new ObjectMapper(); + ObjectNode logData = objectMapper.createObjectNode(); + logData.put("uuid", deploymentMessage.getDeploymentId()); + logData.put("status", "CREATE_COMPLETE"); + + // Print information about the submission of the deployment + String jsonString = null; + try { + jsonString = objectMapper.writeValueAsString(logData); + LOG.info("Deployment completed successfully. {}", jsonString); + } catch (JsonProcessingException e) { + LOG.error(e.getMessage()); + } } @Override diff --git a/src/main/java/it/reply/orchestrator/service/commands/HandleError.java b/src/main/java/it/reply/orchestrator/service/commands/HandleError.java index 5b353f19c5..85dd17060d 100644 --- a/src/main/java/it/reply/orchestrator/service/commands/HandleError.java +++ b/src/main/java/it/reply/orchestrator/service/commands/HandleError.java @@ -19,9 +19,7 @@ import it.reply.orchestrator.service.deployment.providers.DeploymentStatusHelper; import it.reply.orchestrator.utils.WorkflowConstants; - import lombok.AllArgsConstructor; - import org.flowable.engine.delegate.DelegateExecution; import org.springframework.stereotype.Component; diff --git a/src/main/java/it/reply/orchestrator/service/deployment/providers/DeploymentStatusHelperImpl.java b/src/main/java/it/reply/orchestrator/service/deployment/providers/DeploymentStatusHelperImpl.java index f148eebaf2..5766a2e664 100644 --- a/src/main/java/it/reply/orchestrator/service/deployment/providers/DeploymentStatusHelperImpl.java +++ b/src/main/java/it/reply/orchestrator/service/deployment/providers/DeploymentStatusHelperImpl.java @@ -23,12 +23,9 @@ import it.reply.orchestrator.enums.NodeStates; import it.reply.orchestrator.enums.Status; import it.reply.orchestrator.enums.Task; - import java.util.Iterator; - import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; - import org.springframework.stereotype.Service; @Service diff --git a/src/main/java/it/reply/orchestrator/service/deployment/providers/ImServiceImpl.java b/src/main/java/it/reply/orchestrator/service/deployment/providers/ImServiceImpl.java index d46fe1f021..f2aa0a8bd4 100644 --- a/src/main/java/it/reply/orchestrator/service/deployment/providers/ImServiceImpl.java +++ b/src/main/java/it/reply/orchestrator/service/deployment/providers/ImServiceImpl.java @@ -18,7 +18,9 @@ package it.reply.orchestrator.service.deployment.providers; import alien4cloud.tosca.model.ArchiveRoot; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Strings; import com.google.common.collect.HashMultimap; import com.google.common.collect.Lists; @@ -526,6 +528,26 @@ public boolean doDeploy(DeploymentMessage deploymentMessage) { String imCustomizedTemplate = toscaService.serialize(ar); + ObjectMapper objectMapper = new ObjectMapper(); + + ObjectNode logData = objectMapper.createObjectNode(); + logData.put("uuid", uuid); + logData.put("deployment_type", + (ar.getArchive().getTags() != null && !ar.getArchive().getTags().isEmpty()) + ? ar.getArchive().getTags().get(0).getValue() + : null); + logData.put("provider_name", deployment.getCloudProviderName()); + logData.put("user_group", deployment.getUserGroup()); + + // Print information about the submission of the deployment + String jsonString = null; + try { + jsonString = objectMapper.writeValueAsString(logData); + LOG.info("Submission of deployment request to the IM. {}", jsonString); + } catch (JsonProcessingException e) { + LOG.error(e.getMessage()); + } + // Deploy on IM try { String infrastructureId = executeWithClientForResult(cloudProviderEndpoints,