import org.onap.so.logger.MsoLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
-import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
/**
* @param variables variables to inject into the process
* @param logMarker a marker for debug logging
* @return true if a process could be found, false if not
- * @throws Exception for correlation errors
*/
protected boolean correlate(String messageEventName, String correlationVariable,
- String correlationValue, Map<String, Object> variables, String logMarker)
- throws Exception {
+ String correlationValue, Map<String, Object> variables, String logMarker) {
try{
LOGGER.debug(logMarker + " Attempting to find process waiting"
+ " for " + messageEventName + " with " + correlationVariable
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.UUID;
import javax.ws.rs.Consumes;
public class WorkflowAsyncResource extends ProcessEngineAwareService {
private static final WorkflowContextHolder contextHolder = WorkflowContextHolder.getInstance();
-
-
- protected Optional<ProcessEngineServices> pes4junit = Optional.empty();
-
+
long workflowPollInterval=1000;
@Autowired
@Autowired
private WorkflowContextHolder workflowContext;
- public WorkflowProcessor getProcessor() {
- return processor;
- }
-
-
-
public void setProcessor(WorkflowProcessor processor) {
this.processor = processor;
}
throw new Exception("TimeOutOccured");
}
- private WorkflowResponse buildTimeoutResponse(String requestId) {
- WorkflowResponse response = new WorkflowResponse();
- response.setMessage("Fail");
- response.setResponse("Request timedout, request id:" + requestId);
- response.setMessageCode(500);
- return response;
- }
-
private WorkflowResponse buildUnkownError(String requestId,String error) {
WorkflowResponse response = new WorkflowResponse();
response.setMessage(error);
}
return value;
}
-
- // Note: the business key is used to identify the process in unit tests
- protected static String getBusinessKey(Map<String, Object> inputVariables) {
- return getOrCreate(inputVariables, "mso-business-key");
- }
protected static String getRequestId(Map<String, Object> inputVariables) {
return getOrCreate(inputVariables, "mso-request-id");
}
-
-
- protected void recordEvents(String processKey, WorkflowResponse response,
- long startTime) {
-
- msoLogger.recordMetricEvent ( startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- response.getMessage() + " for processKey: "
- + processKey + " with response: " + response.getResponse(), "BPMN", MDC.get(processKey), null);
-
- msoLogger.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
- response.getMessage() + "for processKey: " + processKey + " with response: " + response.getResponse());
-
- }
-
- protected static void setLogContext(String processKey,
- Map<String, Object> inputVariables) {
- MsoLogger.setServiceName("MSO." + processKey);
- if (inputVariables != null) {
- MsoLogger.setLogContext(getKeyValueFromInputVariables(inputVariables,"mso-request-id"), getKeyValueFromInputVariables(inputVariables,"serviceInstanceId"));
- }
- }
-
- protected static String getKeyValueFromInputVariables(Map<String,Object> inputVariables, String key) {
- if (inputVariables == null) {
- return "";
- }
-
- return Objects.toString(inputVariables.get(key), "N/A");
- }
-
protected boolean isProcessEnded(String processInstanceId) {
ProcessEngineServices pes = getProcessEngineServices();
return pes.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult() == null;
}
return inputVariables;
}
-
-
- protected long getWaitTime(Map<String, Object> inputVariables)
- {
-
- String timeout = Objects.toString(inputVariables.get("mso-service-request-timeout"), null);
-
- if (timeout != null) {
- try {
- return Long.parseLong(timeout)*1000;
- } catch (NumberFormatException nex) {
- msoLogger.debug("Invalid input for mso-service-request-timeout");
- }
- }
-
- return DEFAULT_WAIT_TIME;
- }
-
-
-
}
public class WorkflowProcessor extends ProcessEngineAwareService {
private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, WorkflowProcessor.class);
-
protected static final String logMarker = "[WRKFLOW-RESOURCE]";
- protected static final long DEFAULT_WAIT_TIME = 30000; //default wait time
@Async
- public void startProcess( String processKey, VariableMapImpl variableMap) throws InterruptedException
+ public void startProcess( String processKey, VariableMapImpl variableMap)
{
long startTime = System.currentTimeMillis();
throw new WorkflowProcessorException(workflowResponse);
}
}
-
- protected static String getKeyValueFromInputVariables(Map<String,Object> inputVariables, String key) {
- if (inputVariables == null) {
- return "";
- }
- return Objects.toString(inputVariables.get(key), "N/A");
- }
-
// Note: the business key is used to identify the process in unit tests
protected static String getBusinessKey(Map<String, Object> inputVariables) {
return getOrCreate(inputVariables, "mso-business-key");
}
- protected static String getRequestId(Map<String, Object> inputVariables) {
- return getOrCreate(inputVariables, "mso-request-id");
- }
protected static Map<String, Object> getInputVariables(VariableMapImpl variableMap) {
Map<String, Object> inputVariables = new HashMap<>();
}
return value;
}
-
- protected long getWaitTime(Map<String, Object> inputVariables)
- {
-
- String timeout = Objects.toString(inputVariables.get("mso-service-request-timeout"), null);
- if (timeout != null) {
- try {
- return Long.parseLong(timeout)*1000;
- } catch (NumberFormatException nex) {
- msoLogger.debug("Invalid input for mso-service-request-timeout");
- }
- }
-
- return DEFAULT_WAIT_TIME;
- }
}