Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into federation_registry
Browse files Browse the repository at this point in the history
  • Loading branch information
lgiommi committed Nov 5, 2024
2 parents a989a7d + 34241a0 commit b5138cc
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
Expand All @@ -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();
Expand Down Expand Up @@ -104,6 +106,20 @@ protected <C> C getRequiredParameter(DelegateExecution execution, String paramet
.<C>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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b5138cc

Please sign in to comment.