1 package org.openecomp.mso.client.sdno;
3 import java.io.FileNotFoundException;
4 import java.io.IOException;
5 import java.util.Optional;
7 import org.openecomp.mso.client.dmaap.Consumer;
8 import org.openecomp.mso.client.dmaap.DmaapConsumer;
9 import org.openecomp.mso.client.dmaap.DmaapPublisher;
10 import org.openecomp.mso.client.exceptions.SDNOException;
11 import org.openecomp.mso.jsonpath.JsonPathUtil;
13 public class SDNOValidatorImpl implements SDNOValidator, Consumer {
15 private final static String aafUserName = "something";
16 private final static String clientName = "MSO";
17 private final static String healthDiagnosticPath = "body.output.response-healthdiagnostic";
18 private final static String producerFilePath = "";
20 private boolean continuePolling = true;
22 public void healthDiagnostic(String vnfName, String uuid) {
25 //Call SDNO for Health Diagnostic
26 //create producer file for MRClient https://wiki.web.att.com/display/MessageRouter/DMaaP_MR_JavaReferenceClient
27 // final MRBatchingPublisher pub = MRClientFactory.createBatchingPublisher(producerFilePath);
28 // pub.send("Mypartitionkey",JSON.toString(object));
29 //create consumer file for MRClient https://wiki.web.att.com/display/MessageRouter/DMaaP_MR_JavaReferenceClient
30 //check for error in subscription feed filter via jsonpath
31 //block and continue to poll waiting for response
34 protected SDNO buildRequestDiagnostic(String vnfName, String uuid, String oamIp) {
36 Input input = new Input();
37 SDNO parentRequest = new SDNO();
38 Body body = new Body();
39 parentRequest.setBody(body);
40 parentRequest.setNodeType("vPE");
41 parentRequest.setOperation("health-diagnostic");
45 RequestHealthDiagnostic request = new RequestHealthDiagnostic();
46 request.setRequestClientName(clientName);
47 request.setRequestNodeName(vnfName);
48 request.setRequestNodeIp(oamIp); //generic-vnf oam ip
49 request.setRequestUserId(aafUserName); //mech id?
50 request.setRequestId(uuid); //something to identify this request by for polling
52 input.setRequestHealthDiagnostic(request);
56 protected void submitRequest(String json) throws FileNotFoundException, IOException, InterruptedException {
57 DmaapPublisher publisher = new DmaapPublisher(this.producerFilePath);
60 protected boolean pollForResponse(DmaapConsumer consumer, String uuid) throws Exception {
62 return consumer.consume(this);
66 public boolean continuePolling() {
67 return continuePolling;
71 public void stopProcessingMessages() {
72 continuePolling = false;
75 public void processMessage(String message) throws Exception {
76 if (isHealthDiagnostic(message, this.getRequestId())) {
77 if (!healthDiagnosticSuccessful(message)) {
78 Optional<String> statusMessage = this.getStatusMessage(message);
79 if (statusMessage.isPresent()) {
80 throw new SDNOException(statusMessage.get());
82 throw new SDNOException();
85 stopProcessingMessages();
91 public boolean isAccepted(String message) {
92 if (isResultInfo(message)) {
93 Optional<String> code = isAccepted(message, this.getRequestId());
94 if (code.isPresent()) {
95 if ("202".equals(code.get())) {
98 //TODO check other statuses 400 and 500
109 public String getRequestId() {
113 protected Optional<String> isAccepted(String json, String uuid) {
114 return JsonPathUtil.getInstance().locateResult(json, String.format("$.result-info[?(@.status=='ACCEPTED' && @.request-id=='%s')].code", uuid));
117 protected boolean isResultInfo(String json) {
118 return JsonPathUtil.getInstance().pathExists(json, "$[?(@.result-info)]");
121 protected boolean isHealthDiagnostic(String json, String uuid) {
122 return JsonPathUtil.getInstance().pathExists(json, String.format("$[?(@.result-info.request-id=='%s')].%s", uuid, healthDiagnosticPath));
125 protected boolean healthDiagnosticSuccessful(String json) {
126 return JsonPathUtil.getInstance().pathExists(json, "$." + healthDiagnosticPath + "[?(@.response-status=='Success')]");
129 protected Optional<String> getStatusMessage(String json) {
130 return JsonPathUtil.getInstance().locateResult(json, "$." + healthDiagnosticPath + ".response-details-json");