From 38f720752af4d4aad8c4e467a288d9048659f688 Mon Sep 17 00:00:00 2001 From: Rob Daugherty Date: Wed, 14 Mar 2018 02:07:32 -0400 Subject: AT&T 1712 and 1802 release code This is code from AT&T's 1712 and 1802 releases. Change-Id: Ie1e85851e94bc66c4d9514a0226c221939531a04 Issue-ID: SO-425 Signed-off-by: Rob Daugherty --- .../sdno/dmaap/SDNOHealthCheckDmaapConsumer.java | 161 +++++++++++++++++++++ .../sdno/dmaap/SDNOHealthCheckDmaapPublisher.java | 55 +++++++ 2 files changed, 216 insertions(+) create mode 100644 common/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java create mode 100644 common/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java (limited to 'common/src/main/java/org/openecomp/mso/client/sdno/dmaap') diff --git a/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java b/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java new file mode 100644 index 0000000000..59adeb2026 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapConsumer.java @@ -0,0 +1,161 @@ +/*- + * ============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 Optional getHost() { + return Optional.ofNullable(msoProperties.get("sdno.health-check.dmaap.subscriber.host")); + } + + @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 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 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 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 isAccepted(String json, String uuid) { + return JsonPathUtil.getInstance().locateResult(json, String.format("$.result-info[?(@.status=='ACCEPTED' && @.request-id=='%s')].code", uuid)); + } + + protected Optional 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 getStatusMessage(String json) { + return JsonPathUtil.getInstance().locateResult(json, "$." + healthDiagnosticPath + ".error-message"); + } + + @Override + public int getMaximumElapsedTime() { + return 300000; + } +} diff --git a/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java b/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java new file mode 100644 index 0000000000..ef19bb7921 --- /dev/null +++ b/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/SDNOHealthCheckDmaapPublisher.java @@ -0,0 +1,55 @@ +/*- + * ============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.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"); + } + + @Override + public Optional getHost() { + return Optional.ofNullable(msoProperties.get("sdno.health-check.dmaap.publisher.host")); + } + +} -- cgit 1.2.3-korg