summaryrefslogtreecommitdiffstats
path: root/cmso-ticketmgt/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'cmso-ticketmgt/src/main/java/org')
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/common/Availability.java35
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/common/LogMessages.java207
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOClientFilters.java92
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOContainerFilters.java142
4 files changed, 476 insertions, 0 deletions
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/common/Availability.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/common/Availability.java
new file mode 100644
index 0000000..15d8c5c
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/common/Availability.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ *
+ * Copyright © 2019 AT&T Intellectual Property.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ ******************************************************************************/
+package org.onap.optf.ticketmgt.common;
+
+public enum Availability {
+full, partial, unavailable
+}
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/common/LogMessages.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/common/LogMessages.java
new file mode 100644
index 0000000..f16c94c
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/common/LogMessages.java
@@ -0,0 +1,207 @@
+/*******************************************************************************
+ *
+ * Copyright © 2019 AT&T Intellectual Property.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ ******************************************************************************/
+
+
+package org.onap.optf.ticketmgt.common;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.log4j.Level;
+import org.onap.observations.ObservationInterface;
+
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+
+public enum LogMessages implements ObservationInterface {
+
+ FETCH_TICKET("Fetch ticket {0} : {1}: {2} : {3}", Status.OK, Level.INFO),
+ CREATE_TICKET("Create Ticket {0} : {1}: {2} : {3}", Status.OK, Level.INFO),
+ CANCEL_TICKET("Cancel ticket {0} : {1}: {2} : {3}", Status.OK, Level.INFO),
+ UPDATE_TICKET("Update ticket {0} : {1}: {2} : {3}", Status.OK, Level.INFO),
+ GET_ACTIVE_TICKETS("Get active tickets {0} : {1}: {2} : {3}", Status.OK, Level.INFO),
+ SEARCH_TICKETS("Search tickets {0} : {1}: {2} : {3}", Status.OK, Level.INFO),
+
+ TICKET_NOT_FOUND("Ticket not found id={0}", Status.NOT_FOUND, Level.INFO),
+ INVALID_ATTRIBUTE("Invalid attribute {0}={1}", Status.BAD_REQUEST, Level.INFO),
+ MISSING_REQUIRED_ATTRIBUTE("Missing required attribute '{0}'", Status.BAD_REQUEST, Level.INFO),
+ INVALID_REQUEST("The input data structure is incorrect", Status.BAD_REQUEST, Level.INFO),
+ REQUEST_TIMED_OUT("Request timed out.", Status.INTERNAL_SERVER_ERROR, Level.ERROR),
+ UNEXPECTED_EXCEPTION("Unexpected exception encountered during processing. Please contact support : {0}", Status.INTERNAL_SERVER_ERROR, Level.ERROR),
+
+ UNDEFINED_FILTER_ATTRIBUTE("Undefined filter attribute {0}", Status.BAD_REQUEST, Level.INFO),
+ INVALID_DATE_FILTER("Invalid date filter provided {0}=(1}", Status.BAD_REQUEST, Level.INFO),
+
+ INCOMING_MESSAGE("Incoming message method={0} path={1}", Status.OK, Level.INFO, true, false),
+ INCOMING_MESSAGE_RESPONSE("Message response method={0} path={1} status={2}", Status.OK, Level.INFO, true, false),
+ OUTGOING_MESSAGE("Outgoing message method={0} path={1}", Status.OK, Level.INFO, true, false),
+ OUTGOING_MESSAGE_RETURNED("Outgoing message returned method={0} path={1} status={2}", Status.OK, Level.INFO, true, false),
+
+ UNEXPECTED_RESPONSE("Unexpected response from {0} HTTP Status={1} : {2}", Status.OK, Level.INFO),
+ INVALID_CHANGE_WINDOW("Change window end time {1} must be after start time {0}", Status.OK, Level.INFO),
+ EXPECTED_EXCEPTION("Expected exception encountered during processing. {0}", Status.OK, Level.INFO),
+ UNABLE_TO_UPDATE_TICKET("Unable to update change ticket in TM: Schedule ID: {0} : changeid: {1} : Reason: {2}", Status.OK, Level.INFO),
+ UNAUTHORIZED("Authorization failed.", Status.FORBIDDEN, Level.INFO),
+ UNAUTHENTICATED("Authentication failed.", Status.UNAUTHORIZED, Level.INFO),
+
+ ;
+ private final String defaultId;
+ private final String defaultMessage;
+ private final String defaultResolution;
+ private final String defaultAction;
+
+ private final Status status;
+ private final Level level;
+ private final Boolean audit;
+ private final Boolean metric;
+
+
+ private LogMessages(String message, Status code, Level l)
+ {
+ defaultMessage = message;
+ level=l;
+ status = code;
+ this.defaultId = this.name();
+ this.defaultResolution = "No resolution needed";
+ this.defaultAction = "No action is required";
+ this.audit = false;
+ this.metric = false;
+ }
+
+ private LogMessages(String message, Status code, Level l, Boolean audit, Boolean metric)
+ {
+ defaultMessage = message;
+ level=l;
+ status = code;
+ this.audit = audit;
+ this.metric = metric;
+ this.defaultId = this.name();
+ this.defaultResolution = "No resolution needed";
+ this.defaultAction = "No action is required";
+ }
+
+ private LogMessages(String message, Status code, Level l, String id, String resolution, String action)
+ {
+ level=l;
+ status = code;
+ defaultMessage = message;
+ this.defaultId = id;
+ this.defaultResolution = resolution;
+ this.defaultAction = action;
+ this.audit = false;
+ this.metric = false;
+ }
+
+ static {
+ EELFResourceManager.loadMessageBundle("logmessages");
+ }
+
+ public String genProperties()
+ {
+ // Use this to regenerate properties file. The desire to change messages without updating code is
+ // well understood, but the developer should be able to code the defaults without having to update 2 different files and
+ // get it wrong.
+ StringBuilder sb = new StringBuilder();
+ sb.append("# Generated from ").append(this.getClass().getName()).append("\n");
+ for (LogMessages lm : values())
+ {
+ sb.append(lm.name());
+ sb.append(" ").append(lm.defaultId);
+ sb.append("|").append(lm.defaultMessage);
+ sb.append("|").append(lm.defaultResolution);
+ sb.append("|").append(lm.defaultAction);
+ sb.append("\n");
+ }
+ return sb.toString();
+ }
+
+
+ // interface methods
+ @Override
+ public Level getLevel() {return level;}
+ @Override
+ public String getMessage() {return defaultMessage;}
+ @Override
+ public Status getStatus() {return status;}
+ @Override
+ public Enum<?> getValue() {return this;}
+ @Override
+ public String getDomain() {return this.getClass().getSimpleName();}
+ @Override
+ public Boolean getAudit() { return audit; }
+ @Override
+ public Boolean getMetric() { return metric; }
+
+ public static void main(String argv[])
+ {
+ System.out.println(LogMessages.UNEXPECTED_EXCEPTION.genProperties());
+ try
+ {
+ Files.write(Paths.get("src/main/resources/logmessages.properties"), LogMessages.UNEXPECTED_EXCEPTION.genProperties().getBytes());
+ }
+ catch (IOException e)
+ {
+ EELFManager.getInstance().getDebugLogger().debug("Failed to update properties file.", e);
+
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append("<html><body><h1>Cell Site Selection Scheduler mS Observations</h1>\n<table border=\"1\">\n<tr>");
+ sb.append("<td>Code</td> ");
+ sb.append("<td>Log Level</td> ");
+ sb.append("<td>Message</td> ");
+ sb.append("</tr>\n");
+ for (LogMessages m : LogMessages.values())
+ {
+ if (m.level == Level.ERROR || m.level == Level.WARN || m.level == Level.FATAL)
+ {
+ sb.append("<tr>");
+ sb.append("<td>").append(m.name()).append("</td> ");
+ sb.append("<td>").append(m.level).append("</td> ");
+ sb.append("<td>").append(m.defaultMessage).append("</td> ");
+ sb.append("</tr>\n");
+ }
+ }
+ try
+ {
+ Files.write(Paths.get("logmessages.html"), sb.toString().getBytes());
+ }
+ catch (IOException e)
+ {
+ EELFManager.getInstance().getDebugLogger().debug("Failed to update properties html file.", e);
+
+ }
+
+ }
+
+}
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOClientFilters.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOClientFilters.java
new file mode 100644
index 0000000..c42b253
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOClientFilters.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright © 2017-2019 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+
+package org.onap.optf.ticketmgt.filters;
+
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+
+import java.io.IOException;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.client.ClientResponseContext;
+import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.onap.observations.Mdc;
+import org.onap.observations.MessageHeaders;
+import org.onap.observations.MessageHeaders.HeadersEnum;
+import org.onap.observations.Observation;
+import org.onap.optf.ticketmgt.common.LogMessages;
+import org.onap.optf.ticketmgt.service.rs.TicketManagementImpl;
+import org.slf4j.MDC;
+import org.springframework.stereotype.Component;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+// @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
+@Component
+public class CMSOClientFilters implements ClientRequestFilter, ClientResponseFilter {
+
+ private static EELFLogger log = EELFManager.getInstance().getLogger(TicketManagementImpl.class);
+ private static String appId = "cmso";
+
+ @Override
+ public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
+ // On the way back
+ Mdc.metricEnd(responseContext);
+ Mdc.setCaller(17);
+ Observation.report(LogMessages.OUTGOING_MESSAGE_RETURNED,
+ requestContext.getMethod(),
+ requestContext.getUri().getPath().toString(),
+ responseContext.getStatusInfo().toString());
+ }
+
+ @Override
+ public void filter(ClientRequestContext requestContext) throws IOException {
+ // On the way out
+ Mdc.metricStart(requestContext);
+ Mdc.setCaller(17);
+ Observation.report(LogMessages.OUTGOING_MESSAGE,
+ requestContext.getMethod(),
+ requestContext.getUri().getPath().toString());
+ MultivaluedMap<String, Object> headers = requestContext.getHeaders();
+
+ String transactionId = (String) headers.getFirst(MessageHeaders.HeadersEnum.TransactionID.toString());
+ String mdcId = MDC.get(MDC_KEY_REQUEST_ID);
+ if (transactionId == null || transactionId.equals(""))
+ if (mdcId != null)
+ headers.add(HeadersEnum.TransactionID.toString(), mdcId);
+ headers.add(HeadersEnum.FromAppID.toString(), appId);
+ }
+
+}
diff --git a/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOContainerFilters.java b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOContainerFilters.java
new file mode 100644
index 0000000..a8f08b3
--- /dev/null
+++ b/cmso-ticketmgt/src/main/java/org/onap/optf/ticketmgt/filters/CMSOContainerFilters.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2017-2019 AT&T Intellectual Property.
+ * Modifications Copyright © 2018 IBM.
+ *
+ * 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.
+ *
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+*/
+
+package org.onap.optf.ticketmgt.filters;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import javax.annotation.Priority;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.ext.Provider;
+
+import org.onap.observations.Mdc;
+import org.onap.observations.MessageHeaders;
+import org.onap.observations.MessageHeaders.HeadersEnum;
+import org.onap.observations.Observation;
+import org.onap.optf.ticketmgt.common.LogMessages;
+import org.springframework.stereotype.Component;
+
+@Priority(1)
+@Provider
+@Component
+public class CMSOContainerFilters implements ContainerRequestFilter, ContainerResponseFilter {
+
+
+ @Context
+ private HttpServletRequest servletRequest;
+
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
+ throws IOException {
+ try {
+ Mdc.auditEnd(requestContext, responseContext);
+ Observation.report(LogMessages.INCOMING_MESSAGE_RESPONSE,
+ requestContext.getMethod(),
+ requestContext.getUriInfo().getPath().toString(),
+ responseContext.getStatusInfo().toString());
+ MultivaluedMap<String, String> reqHeaders = requestContext.getHeaders();
+ MultivaluedMap<String, Object> respHeaders = responseContext.getHeaders();
+ String minorVersion = (String) reqHeaders.getFirst(HeadersEnum.MinorVersion.toString());
+ respHeaders.add(HeadersEnum.MinorVersion.toString(), minorVersion);
+ respHeaders.add(HeadersEnum.LatestVersion.toString(), MessageHeaders.latestVersion);
+ respHeaders.add(HeadersEnum.PatchVersion.toString(), MessageHeaders.patchVersion);
+
+ } catch (Exception e) {
+ if (e instanceof WebApplicationException) {
+ Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage());
+ } else {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage());
+ }
+ }
+ }
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+ try {
+ // On the way in
+ Mdc.auditStart(requestContext, servletRequest);
+ Observation.report(LogMessages.INCOMING_MESSAGE,
+ requestContext.getMethod(),
+ requestContext.getUriInfo().getPath().toString());
+
+ String majorVersion = requestContext.getUriInfo().getPath();
+ if (majorVersion != null) {
+
+ if (majorVersion.startsWith("dispatch/"))
+ return;
+ majorVersion = majorVersion.replaceAll("/.*$", "");
+ }
+ if (!MessageHeaders.validateMajorVersion(majorVersion)) {
+ ResponseBuilder builder = null;
+ String response = "Unsupported Major version";
+ builder = Response.status(Response.Status.NOT_FOUND).entity(response);
+ throw new WebApplicationException(builder.build());
+ }
+ MultivaluedMap<String, String> headers = requestContext.getHeaders();
+ String transactionId = (String) headers.getFirst(HeadersEnum.TransactionID.toString());
+ if (transactionId == null) {
+ transactionId = UUID.randomUUID().toString();
+ headers.add(HeadersEnum.TransactionID.toString(), transactionId);
+ }
+ String minorVersion = (String) headers.getFirst(HeadersEnum.MinorVersion.toString());
+ if (minorVersion == null) {
+ minorVersion = MessageHeaders.supportedMajorVersions.get(majorVersion);
+ headers.add(HeadersEnum.MinorVersion.toString(), minorVersion);
+ }
+ if (!MessageHeaders.validateMajorMinorVersion(majorVersion, minorVersion)) {
+ ResponseBuilder builder = null;
+ String response = "Unsupported API version";
+ builder = Response.status(Response.Status.NOT_FOUND).entity(response);
+ throw new WebApplicationException(builder.build());
+
+ }
+ } catch (Exception e) {
+ if (e instanceof WebApplicationException) {
+ Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage());
+ throw e;
+ } else {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage());
+ }
+ }
+
+ }
+
+}