diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno')
9 files changed, 240 insertions, 113 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNOValidator.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNOValidator.java index eb18e10bc3..c746c0d448 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNOValidator.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNOValidator.java @@ -32,6 +32,6 @@ public interface SDNOValidator { * @throws IOException * @throws Exception */ - public void healthDiagnostic(String vnfName, String uuid) throws IOException, Exception; + public void healthDiagnostic(String vnfId, String requestingUserId) throws IOException, Exception; } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNOValidatorImpl.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNOValidatorImpl.java index 92a00eee65..bdb4aa94ee 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNOValidatorImpl.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNOValidatorImpl.java @@ -30,7 +30,7 @@ import org.openecomp.mso.client.dmaap.DmaapPublisher; import org.openecomp.mso.client.exceptions.SDNOException; import org.openecomp.mso.jsonpath.JsonPathUtil; -public class SDNOValidatorImpl implements SDNOValidator, Consumer { +public class SDNOValidatorImpl implements SDNOValidator { private final static String aafUserName = "something"; private final static String clientName = "MSO"; @@ -51,103 +51,4 @@ public class SDNOValidatorImpl implements SDNOValidator, Consumer { //block and continue to poll waiting for response } - protected SDNO buildRequestDiagnostic(String vnfName, String uuid, String oamIp) { - - Input input = new Input(); - SDNO parentRequest = new SDNO(); - Body body = new Body(); - parentRequest.setBody(body); - parentRequest.setNodeType("vPE"); - parentRequest.setOperation("health-diagnostic"); - - body.setInput(input); - - RequestHealthDiagnostic request = new RequestHealthDiagnostic(); - request.setRequestClientName(clientName); - request.setRequestNodeName(vnfName); - request.setRequestNodeIp(oamIp); //generic-vnf oam ip - request.setRequestUserId(aafUserName); //mech id? - request.setRequestId(uuid); //something to identify this request by for polling - - input.setRequestHealthDiagnostic(request); - - return parentRequest; - } - protected void submitRequest(String json) throws FileNotFoundException, IOException, InterruptedException { - DmaapPublisher publisher = new DmaapPublisher(this.producerFilePath); - publisher.send(json); - } - protected boolean pollForResponse(DmaapConsumer consumer, String uuid) throws Exception { - this.uuid = uuid; - return consumer.consume(this); - } - - @Override - public boolean continuePolling() { - return continuePolling; - } - - @Override - public void stopProcessingMessages() { - continuePolling = false; - } - @Override - public void processMessage(String message) throws Exception { - if (isHealthDiagnostic(message, this.getRequestId())) { - if (!healthDiagnosticSuccessful(message)) { - Optional<String> statusMessage = this.getStatusMessage(message); - if (statusMessage.isPresent()) { - throw new SDNOException(statusMessage.get()); - } else { - throw new SDNOException(); - } - } else { - stopProcessingMessages(); - } - } - } - - @Override - public boolean isAccepted(String message) { - if (isResultInfo(message)) { - Optional<String> code = isAccepted(message, this.getRequestId()); - if (code.isPresent()) { - if ("202".equals(code.get())) { - return true; - } else { - //TODO check other statuses 400 and 500 - } - } else { - //TODO throw error - } - } - - return false; - } - - @Override - public String getRequestId() { - return uuid; - } - - protected Optional<String> isAccepted(String json, String uuid) { - return JsonPathUtil.getInstance().locateResult(json, String.format("$.result-info[?(@.status=='ACCEPTED' && @.request-id=='%s')].code", uuid)); - } - - protected boolean isResultInfo(String json) { - return JsonPathUtil.getInstance().pathExists(json, "$[?(@.result-info)]"); - } - - protected boolean isHealthDiagnostic(String json, String uuid) { - return JsonPathUtil.getInstance().pathExists(json, String.format("$[?(@.result-info.request-id=='%s')].%s", uuid, healthDiagnosticPath)); - } - - protected boolean healthDiagnosticSuccessful(String json) { - return JsonPathUtil.getInstance().pathExists(json, "$." + healthDiagnosticPath + "[?(@.response-status=='Success')]"); - } - - protected Optional<String> getStatusMessage(String json) { - return JsonPathUtil.getInstance().locateResult(json, "$." + healthDiagnosticPath + ".response-details-json"); - } - } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/Body.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/Body.java index 2db4dea069..cc8ce81dec 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/Body.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/Body.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.client.sdno; +package org.openecomp.mso.client.sdno.beans; import java.io.Serializable; import java.util.HashMap; @@ -41,7 +41,7 @@ public class Body implements Serializable @JsonProperty("input") private Input input; @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<>(); + private Map<String, Object> additionalProperties = new HashMap<String, Object>(); private final static long serialVersionUID = 9101706044452851559L; @JsonProperty("input") diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/Input.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/Input.java index 25eb2ed270..7b9bf6f2c7 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/Input.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/Input.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.client.sdno; +package org.openecomp.mso.client.sdno.beans; import java.io.Serializable; import java.util.HashMap; @@ -33,15 +33,17 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ - "request-healthdiagnostic" + "request-healthdiagnostic", + "request-hd-custom" }) public class Input implements Serializable { @JsonProperty("request-healthdiagnostic") private RequestHealthDiagnostic RequestHealthDiagnostic; + @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<>(); + private Map<String, Object> additionalProperties = new HashMap<String, Object>(); private final static long serialVersionUID = 7155546785389227528L; @JsonProperty("request-healthdiagnostic") diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/RequestHealthDiagnostic.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/RequestHealthDiagnostic.java index b1ed77b513..104dbb7ee6 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/RequestHealthDiagnostic.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/RequestHealthDiagnostic.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.client.sdno; +package org.openecomp.mso.client.sdno.beans; import java.io.Serializable; import java.util.HashMap; @@ -59,7 +59,7 @@ public class RequestHealthDiagnostic implements Serializable @JsonProperty("health-diagnostic-code") private String healthDiagnosticCode; @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<>(); + private Map<String, Object> additionalProperties = new HashMap<String, Object>(); private final static long serialVersionUID = 1166788526178388021L; @JsonProperty("request-client-name") diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/ResultInfo.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/ResultInfo.java index 0997b2df90..4d029cb8cb 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/ResultInfo.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/ResultInfo.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.client.sdno; +package org.openecomp.mso.client.sdno.beans; import java.util.HashMap; import java.util.Map; @@ -51,7 +51,7 @@ private String requestId; @JsonProperty("status") private String status; @JsonIgnore -private Map<String, Object> additionalProperties = new HashMap<>(); +private Map<String, Object> additionalProperties = new HashMap<String, Object>(); @JsonProperty("client-name") public String getClientName() { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNO.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/SDNO.java index caa3ff58e9..4edd54ca09 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/SDNO.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/beans/SDNO.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.client.sdno; +package org.openecomp.mso.client.sdno.beans; import java.io.Serializable; import java.util.HashMap; @@ -34,6 +34,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({ "operation", + "nodeLoc", "nodeType", "body" }) @@ -42,12 +43,14 @@ public class SDNO implements Serializable @JsonProperty("operation") private String operation; + @JsonProperty("nodeLoc") + private String nodeLoc; @JsonProperty("nodeType") private String nodeType; @JsonProperty("body") private Body body; @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<>(); + private Map<String, Object> additionalProperties = new HashMap<String, Object>(); private final static long serialVersionUID = -5303297382564282650L; @JsonProperty("operation") @@ -59,8 +62,23 @@ public class SDNO implements Serializable public void setOperation(String operation) { this.operation = operation; } + + @JsonProperty("nodeLoc") + public String getNodeLoc() { + return nodeLoc; + } + + @JsonProperty("nodeLoc") + public void setNodeLoc(String nodeLoc) { + this.nodeLoc = nodeLoc; + } + + public SDNO withNodeLoc(String nodeLoc) { + this.nodeLoc = nodeLoc; + return this; + } - public SDNO withOperation(String operation) { + public SDNO withOperation(String operation) { this.operation = operation; return this; } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java new file mode 100644 index 0000000000..f23d882b53 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java @@ -0,0 +1,156 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.sdno.dmaap; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Optional; + +import org.openecomp.mso.client.dmaap.DmaapConsumer; +import org.openecomp.mso.client.exceptions.SDNOException; +import org.openecomp.mso.jsonpath.JsonPathUtil; + +public class SDNOHealthCheckDmaapConsumer extends DmaapConsumer { + + private final String uuid; + private boolean continuePolling = true; + private final static String healthDiagnosticPath = "body.output.*"; + + public SDNOHealthCheckDmaapConsumer() throws FileNotFoundException, IOException { + this("none"); + } + + public SDNOHealthCheckDmaapConsumer(String uuid) throws FileNotFoundException, IOException { + super(); + this.uuid = uuid; + } + + @Override + public String getUserName() { + return msoProperties.get("sdno.health-check.dmaap.username"); + } + + @Override + public String getPassword() { + return msoProperties.get("sdno.health-check.dmaap.password"); + } + + @Override + public String getTopic() { + return msoProperties.get("sdno.health-check.dmaap.subscriber.topic"); + } + + @Override + public boolean continuePolling() { + return continuePolling; + } + + @Override + public void stopProcessingMessages() { + continuePolling = false; + } + @Override + public void processMessage(String message) throws Exception { + if (isHealthDiagnostic(message, this.getRequestId())) { + if (!healthDiagnosticSuccessful(message)) { + Optional<String> statusMessage = this.getStatusMessage(message); + if (statusMessage.isPresent()) { + throw new SDNOException("failed with message " + statusMessage.get()); + } else { + throw new SDNOException("failed with no status message"); + } + } else { + auditLogger.info("successful health diagnostic found for request: " + this.getRequestId()); + stopProcessingMessages(); + } + } + } + + @Override + public boolean isAccepted(String message) { + if (isResultInfo(message)) { + Optional<String> code = isAccepted(message, this.getRequestId()); + if (code.isPresent()) { + if ("202".equals(code.get())) { + return true; + } else { + //TODO check other statuses 400 and 500 + } + } else { + //TODO throw error + } + } + + return false; + } + + @Override + public boolean isFailure(String message) { + if (isResultInfo(message)) { + Optional<String> code = isFailure(message, this.getRequestId()); + if (code.isPresent()) { + if ("500".equals(code.get())) { + return true; + } else { + //TODO check other statuses 400 and 500 + } + } else { + //TODO throw error + } + } + + return false; + } + + @Override + public String getRequestId() { + return uuid; + } + + protected Optional<String> isAccepted(String json, String uuid) { + return JsonPathUtil.getInstance().locateResult(json, String.format("$.result-info[?(@.status=='ACCEPTED' && @.request-id=='%s')].code", uuid)); + } + + protected Optional<String> isFailure(String json, String uuid) { + return JsonPathUtil.getInstance().locateResult(json, String.format("$.result-info[?(@.status=='FAILURE' && @.request-id=='%s')].code", uuid)); + } + + protected boolean isResultInfo(String json) { + return JsonPathUtil.getInstance().pathExists(json, "$[?(@.result-info)]"); + } + + protected boolean isHealthDiagnostic(String json, String uuid) { + return JsonPathUtil.getInstance().pathExists(json, String.format("$[?(@.result-info.request-id=='%s')].%s", uuid, healthDiagnosticPath)); + } + + protected boolean healthDiagnosticSuccessful(String json) { + return JsonPathUtil.getInstance().pathExists(json, "$." + healthDiagnosticPath + "[?(@.response-status=='Success')]"); + } + + protected Optional<String> getStatusMessage(String json) { + return JsonPathUtil.getInstance().locateResult(json, "$." + healthDiagnosticPath + ".error-message"); + } + + @Override + public int getMaximumElapsedTime() { + return 300000; + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java new file mode 100644 index 0000000000..73f06b8e58 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.client.sdno.dmaap; + +import java.io.FileNotFoundException; +import java.io.IOException; + +import org.openecomp.mso.client.dmaap.DmaapPublisher; + +public class SDNOHealthCheckDmaapPublisher extends DmaapPublisher { + + public SDNOHealthCheckDmaapPublisher() throws FileNotFoundException, IOException { + super(); + } + + @Override + public String getUserName() { + return msoProperties.get("sdno.health-check.dmaap.username"); + } + + @Override + public String getPassword() { + return msoProperties.get("sdno.health-check.dmaap.password"); + } + + @Override + public String getTopic() { + return msoProperties.get("sdno.health-check.dmaap.publisher.topic"); + } + + +} |