blob: df173c002dad66d04b70c3f8a777e54112e493c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package org.onap.so.openstack.utils;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.db.request.beans.RequestProcessingData;
import org.onap.so.db.request.client.RequestsDbClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.woorea.openstack.heat.model.Stack;
@Component
public class StackStatusHandler {
private static final Logger logger = LoggerFactory.getLogger(StackStatusHandler.class);
private static final ObjectMapper mapper = new ObjectMapper();
@Autowired
private RequestsDbClient requestDBClient;
@Async
public void updateStackStatus(Stack stack) {
try {
String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
String stackStatus = mapper.writeValueAsString(stack);
RequestProcessingData requestProcessingData =
requestDBClient.getRequestProcessingDataBySoRequestIdAndNameAndGrouping(requestId, stack.getId(),
stack.getStackName());
if (requestProcessingData == null) {
requestProcessingData = new RequestProcessingData();
requestProcessingData.setGroupingId(stack.getId());
requestProcessingData.setName(stack.getStackName());
requestProcessingData.setTag("StackInformation");
requestProcessingData.setSoRequestId(requestId);
requestProcessingData.setValue(stackStatus);
requestDBClient.saveRequestProcessingData(requestProcessingData);
} else {
requestProcessingData.setValue(stackStatus);
requestDBClient.updateRequestProcessingData(requestProcessingData);
}
} catch (Exception e) {
logger.warn("Error adding stack status to request database", e);
}
}
}
|