aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamaPrasad Amaranarayana (ra5425) <ra5425@att.com>2018-09-19 18:34:31 -0400
committerRamaPrasad Amaranarayana (ra5425) <ra5425@att.com>2018-09-19 18:38:15 -0400
commit3732a8d3365e0fe0c0d3cf98e9c6653dbee277ef (patch)
treeec8504cf4378970788281c50d5225735362abf87
parentcf53acb09d7638676caf94beb685f8845d9940e4 (diff)
Change Management Schedule Optimization
Adding CMSO Service Common Utilities and Table Model Dao Files for Change Management Schedule Optimization Change-Id: I18ee4e1d37b3b5d2284cfda4971b3066c52684c2 Issue-ID: OPTFRA-353 Signed-off-by: RamaPrasad Amaranarayana (ra5425) <ra5425@att.com>
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/ApprovalStatusEnum.java47
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/ApprovalTypesEnum.java46
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java95
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java80
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/CMSStatusEnum.java102
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/CmHelpers.java59
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/DomainsEnum.java36
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/LogMessages.java151
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/Mdc.java382
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java130
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSAlreadyExistsException.java43
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java73
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSNotFoundException.java44
13 files changed, 1288 insertions, 0 deletions
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/ApprovalStatusEnum.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/ApprovalStatusEnum.java
new file mode 100644
index 0000000..0069f26
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/ApprovalStatusEnum.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+public enum ApprovalStatusEnum {
+ Accepted("Accepted"), Rejected("Rejected"),;
+
+ private final String text;
+
+ private ApprovalStatusEnum(String text) {
+ this.text = text;
+ }
+
+ public String toString() {
+ return text;
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/ApprovalTypesEnum.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/ApprovalTypesEnum.java
new file mode 100644
index 0000000..927dbf1
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/ApprovalTypesEnum.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+public enum ApprovalTypesEnum {
+ Tier2("Tier 2"),;
+
+ private final String text;
+
+ private ApprovalTypesEnum(String text) {
+ this.text = text;
+ }
+
+ public String toString() {
+ return text;
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java
new file mode 100644
index 0000000..25b6583
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/BasicAuthenticatorFilter.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.xml.bind.DatatypeConverter;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class BasicAuthenticatorFilter implements ClientRequestFilter {
+ private static EELFLogger log = EELFManager.getInstance().getLogger(BasicAuthenticatorFilter.class);
+ private final String user;
+ private final String password;
+
+ public BasicAuthenticatorFilter(String user, String password) {
+ this.user = user;
+ this.password = password;
+ log.info("user: " + user + " pass:" + password);
+ }
+
+ @Override
+ public void filter(ClientRequestContext requestContext) throws IOException {
+ MultivaluedMap<String, Object> headers = requestContext.getHeaders();
+ final String basicAuthentication = getBasicAuthentication();
+ headers.add("Authorization", basicAuthentication);
+ }
+
+ private String getBasicAuthentication() {
+ String token = this.user + ":" + this.password;
+ try {
+ return "Basic " + DatatypeConverter.printBase64Binary(token.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException ex) {
+ throw new IllegalStateException("Cannot encode with UTF-8", ex);
+ }
+ }
+
+ public static String getUser(HttpServletRequest request) {
+ String user = "";
+ String header = request.getHeader("Authorization");
+ if (header != null) {
+ String[] auth = header.split("Basic ");
+ if (auth.length == 2) {
+ String token = getToken(auth[1]);
+ if (token.contains(":")) {
+ String[] tokens = token.split(":");
+ user = tokens[0];
+ }
+ }
+ }
+ return user;
+ }
+
+ private static String getToken(String auth) {
+ try {
+ String token = new String(DatatypeConverter.parseBase64Binary(auth));
+ return token;
+ } catch (Exception e) {
+ return auth;
+ }
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java
new file mode 100644
index 0000000..161fe9b
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/CMSRequestError.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class CMSRequestError implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(CMSRequestError.class);
+ @JsonProperty
+ RequestError requestError;
+
+ public CMSRequestError(String messageId, String text, List<String> variables) {
+ requestError = new RequestError(messageId, text, variables);
+ }
+
+ public CMSRequestError(String messageId, String text) {
+ requestError = new RequestError(messageId, text, new ArrayList<String>());
+ }
+
+ public class RequestError {
+ @JsonProperty
+ private String messageId;
+ @JsonProperty
+ private String text;
+ @JsonProperty
+ private List<String> variables;
+
+ private RequestError(String messageId, String text, List<String> variables) {
+ this.messageId = "Scheduler." + messageId;
+ this.text = text;
+ this.variables = variables;
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append(messageId).append(":").append(text).append(":").append(variables);
+ return sb.toString();
+
+ }
+ }
+
+ public String toString() {
+ return requestError.toString();
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/CMSStatusEnum.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/CMSStatusEnum.java
new file mode 100644
index 0000000..de1e701
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/CMSStatusEnum.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+public enum CMSStatusEnum {
+ PendingSchedule("Pending Schedule",
+ "Schedule request as been accepted. Pending determination of recommended schedule."), SchedulingFailed(
+ "Scheduling Failed", "Failed to determine recommended schedule."), ScheduleFailed("Schedule Failed",
+ "Determination of recommended schedule failed."), OptimizationInProgress(
+ "Optimization In Progress",
+ "Determination of recommended schedule is in progress."), PendingApproval(
+ "Pending Approval",
+ "Pending approval of the recommended schedule."), OptimizationFailed(
+ "Optimization Failed",
+ "Unable to determine recommended schedule."), Accepted("Accepted",
+ "Recommended schedule has been accepted."), Scheduled(
+ "Scheduled",
+ "All approvals received. Recommended schedule is pending execution."), ScheduledImmediate(
+ "Scheduled Immediate",
+ "All approvals received. Event is scheduled for immediate execution."), Triggered(
+ "Triggered",
+ "Scheduled event has been triggered."), ApprovalRejected(
+ "Approval Rejected",
+ "Recommended schedule has been rejected."), PastDue(
+ "Past due",
+ "Scheduled event time has passed. Queued event was not dispatched."), Error(
+ "Error",
+ "Attempt to displatch event failed."), Failed(
+ "Failed",
+ "Triggered event reported a failure."), Rejected(
+ "Rejected",
+ "Recommended schedule has been rejected."), NotificationsInitiated(
+ "Notifications Initiated",
+ "Notifications of scheduled events has been initiated."), Completed(
+ "Completed",
+ "Notification of all scheduled events have been sent."), CompletedWithError(
+ "Completed with error(s)",
+ "All scheduled events have completed, some with errors."), Deleted(
+ "Deleted",
+ "Schedule deleted prior to acceptance or after execution."), Cancelled(
+ "Cancelled",
+ "Scheduled event cancelled before execution."),;
+
+ private final String text;
+ private final String description;
+
+ private CMSStatusEnum(String text, String description) {
+ this.text = text;
+ this.description = description;
+ }
+
+ public String toString() {
+ return text;
+ }
+
+ public CMSStatusEnum fromString(String text) {
+ for (CMSStatusEnum e : CMSStatusEnum.values())
+ if (e.text.equals(text))
+ return e;
+ return null;
+ }
+
+ // To include in the AID.
+ public static void main(String argv[]) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("<html><body><table border=\"1\">\n");
+ for (CMSStatusEnum v : CMSStatusEnum.values())
+ sb.append("<tr><td>").append(v.text).append("</td><td>").append(v.description).append("</td></tr>\n");
+ sb.append("</table></body></html>\n");
+ System.out.println(sb.toString());
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/CmHelpers.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/CmHelpers.java
new file mode 100644
index 0000000..832acb7
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/CmHelpers.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+import java.util.List;
+import org.onap.optf.cmso.model.DomainData;
+import org.onap.optf.cmso.model.Schedule;
+import org.onap.optf.cmso.service.rs.models.CmDomainDataEnum;
+
+/**
+ * Collection of commann static helper methods for CHangeManagement
+ *
+ * @author jf9860
+ *
+ */
+public class CmHelpers {
+
+ public static String getDomainData(Schedule schedule, CmDomainDataEnum key) {
+ return getDomainData(schedule.getDomainData(), key);
+ }
+
+ public static String getDomainData(List<DomainData> domainData, CmDomainDataEnum key) {
+ for (DomainData map : domainData) {
+ if (map.getName().equals(key.toString()))
+ return map.getValue();
+ }
+ return null;
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/DomainsEnum.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/DomainsEnum.java
new file mode 100644
index 0000000..cd6af4c
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/DomainsEnum.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+public enum DomainsEnum {
+ ChangeManagement,
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/LogMessages.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/LogMessages.java
new file mode 100644
index 0000000..6026bc4
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/LogMessages.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResolvableErrorEnum;
+import com.att.eelf.i18n.EELFResourceManager;
+
+public enum LogMessages implements EELFResolvableErrorEnum {
+
+ // Let developer provide the initial properties here.
+ // We can merge them to logmessages.properties when we need to.
+ SEARCH_SCHEDULE_REQUEST_DETAILS("Search Schedule Request Details {0} from {1}: {2}"), SEARCH_SCHEDULE_REQUEST(
+ "Search Schedule Request {0} from {1}: {2} : {3}"), CREATE_SCHEDULE_REQUEST(
+ "Create Schedule Request {0} from {1}: {2} : {3}"), DELETE_SCHEDULE_REQUEST(
+ "Delete Schedule Request {0} from {1}: {2} : {3}"), GET_SCHEDULE_REQUEST_INFO(
+ "Get Schedule Request Info {0} from {1}: {2} : {3}"), PROCESS_OPTIMIZER_CALLBACK(
+ "Change management optimizer callback {0} from {1}: {2} "), APPROVE_SCHEDULE_REQUEST(
+ "Approve Schedule Request {0} from {1}: {2} : {3}"), SCHEDULE_ALREADY_EXISTS(
+ "Schedule already exists domain={0} schedule id={1}"), SCHEDULE_NOT_FOUND(
+ "Schedule not found domain={0} schedule id={1}"), INVALID_ATTRIBUTE(
+ "Invalid attribute {0}={1}"), MISSING_REQUIRED_ATTRIBUTE(
+ "Missing required attribute '{0}'"), INVALID_REQUEST(
+ "The input data structure is incorrect"), REQUEST_TIMED_OUT(
+ "Request timed out."), UNEXPECTED_EXCEPTION(
+ "Unexpected exception encountered during processing. Please contact support : {0}"), AUTHORIZATION_FAILED(
+ "Authorization Failed"), UNDEFINED_DOMAIN_DATA_ATTRIBUTE(
+ "Domain data attribute not defined domain={0} name={1} value={2}"), UNDEFINED_FILTER_ATTRIBUTE(
+ "Undefined filter attribute {0}"), INVALID_DATE_FILTER(
+ "Invalid date filter provided {0}=(1}"), OPTIMIZER_QUARTZ_JOB(
+ "Quartz scheduling of OptimizerQuartzJob: {0}"), OPTIMIZER_EXCEPTION(
+ "Exception making client call to optimizer {0}"), OPTIMIZER_CALLBACK_STATE_ERROR(
+ "Optimizer callback on schedule in invalid state. Should be {0} but was {1}."), CHANGE_MANAGEMENT_GROUP_NOT_FOUND(
+ "ChangeManagementGroup not found on optimizer callback scheduleId={0} groupId={1}"), UNABLE_TO_ALLOCATE_VNF_TIMESLOTS(
+ "Unable to allocate VNF timeslots with Optimizer results startTime={0}, latestStartTime={1}, totalDuration={2}, concurrency={3} nvfs={4}"), UNABLE_TO_LOCATE_SCHEDULE_DETAIL(
+ "Unable to locate ChangeManagementSchedule for VNF. scheduleId={0}, groupId={1}, vnfName={2}"), CM_JOB(
+ "Quartz scheduling of CmJob: {0}"), CM_QUARTZ_JOB(
+ "Quartz scheduling of CmQuartzJob: {0}"), NOT_PENDING_APPROVAL(
+ "Approval request received for schedule that is not in Pending Approval state: domain={0} scheduleId={1} state={3}"), SCHEDULE_PAST_DUE(
+ "Attempt to dispatch an event that is Past due scheduleId={0}, vnf={1}, now={2}, startTime={3}"), MSO_POLLING_MISSING_SCHEDULE(
+ "Attempt to poll MSO for request id {1} for missing ChangeManagementSchedule id={0}"), MSO_STATUS_JOB(
+ "Polling MSO {0} for requestId={1} for id={2}"), UNEXPECTED_RESPONSE(
+ "Unexpected response from {0} HTTP Status={1} : {2}"), SCHEDULE_STATUS_JOB(
+ "Quartz scheduling of ScheduleStatusJob: {0}"), CM_TICKET_NOT_APPROVED(
+ "Attempt to dispatch a change management event that has no TM Ticket approved. scheduleId={0} VNF Name={1} TM ChangeId={2} Status={3} Approval Status={4}"), MULTIPLE_GROUPS_NOT_SUPPORTED(
+ "Multiple groups not supported on immediate requests"), TM_CREATE_CHANGE_RECORD(
+ "TM Create Change Record:{0} : Schedule ID: {1}"), TM_LIST(
+ "TM list:{0} : URL : {1}"), TM_API(
+ "TM API Call: URL : {0}"), UNABLE_TO_CREATE_CHANGE_TICKET(
+ "Unable to create change ticket in TM: Schedule ID: {0} : Reason : {1}"), TM_UPDATE_CHECKLIST(
+ "TM Fetch Checklist:{0} : Schedule ID: {1} : Change Id : {2} : URL : {3}"), OPTIMIZER_REQUEST(
+ "Optimi Request:{0} : Schedule ID: {1} : URL : {2}"), TM_CLOSE_CHANGE_RECORD(
+ "TM Close Change Record:{0} : Schedule ID: {1} : Change Id : {2}"), UNABLE_TO_CLOSE_CHANGE_TICKET(
+ "Unable to close change ticket in TM: Schedule ID: {0} : changeid: {1} : Reason: {2}"), CANNOT_CANCEL_IN_PROGRESS(
+ "Cannot delete/cancel a schedule with events in progress."), UNABLE_TO_PARSE_SCHEDULING_INFO(
+ "Cannot parse scheduling info."), UNABLE_TO_LOCATE_CHANGE_RECORD(
+ "Unable to locate TM change record {2} to check status before displacth of {1} for schedulId={0}"), INVALID_CHANGE_WINDOW(
+ "Change window end time {1} must be after start time {0}"), NODE_LIST_CONTAINS_EMTPY_NODE(
+ "vnfDetails node list contains at least one empty node."), SO_API(
+ "SO Poll Request {0}"), EXPECTED_EXCEPTION(
+ "Expected exception encountered during processing. Make Sonar happy: {0}"), TM_UPDATE_CHANGE_RECORD(
+ "TM Update Change Record:{0} : Schedule ID: {1} : Change Id : {2} : URL : {3}"), UNABLE_TO_UPDATE_CHANGE_TICKET(
+ "Unable to update change ticket in TM: Schedule ID: {0} : changeid: {1} : Reason: {2}"),;
+
+ private final String defaultId;
+ private final String defaultMessage;
+ private final String defaultResolution;
+ private final String defaultAction;
+
+ private LogMessages(String message) {
+ defaultMessage = message;
+ this.defaultId = this.name();
+ this.defaultResolution = "No resolution needed";
+ this.defaultAction = "No action is required";
+ }
+
+ private LogMessages(String message, String id, String resolution, String action) {
+ defaultMessage = message;
+ this.defaultId = id;
+ this.defaultResolution = resolution;
+ this.defaultAction = action;
+ }
+
+ 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();
+ }
+
+ public static void main(String argv[]) {
+ System.out.println(LogMessages.CREATE_SCHEDULE_REQUEST.genProperties());
+ try {
+ Files.write(Paths.get("src/main/resources/logmessages.properties"),
+ LogMessages.CREATE_SCHEDULE_REQUEST.genProperties().getBytes());
+ } catch (IOException e) {
+ EELFManager.getInstance().getDebugLogger().debug("Failed to update properties file.", e);
+
+ }
+
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/Mdc.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/Mdc.java
new file mode 100644
index 0000000..30451b5
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/Mdc.java
@@ -0,0 +1,382 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+import static com.att.eelf.configuration.Configuration.MDC_BEGIN_TIMESTAMP;
+import static com.att.eelf.configuration.Configuration.MDC_ELAPSED_TIME;
+import static com.att.eelf.configuration.Configuration.MDC_END_TIMESTAMP;
+import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+import static com.att.eelf.configuration.Configuration.MDC_PARTNER_NAME;
+import static com.att.eelf.configuration.Configuration.MDC_REMOTE_HOST;
+import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_CODE;
+import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_DESC;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
+import static com.att.eelf.configuration.Configuration.MDC_STATUS_CODE;
+import static com.att.eelf.configuration.Configuration.MDC_TARGET_ENTITY;
+import static com.att.eelf.configuration.Configuration.MDC_TARGET_SERVICE_NAME;
+import java.net.InetAddress;
+import java.net.URI;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+import org.onap.optf.cmso.filters.MessageHeaders;
+import org.quartz.JobExecutionContext;
+import org.slf4j.MDC;
+import com.att.eelf.utils.Stopwatch;
+
+/**
+ * ECOMP EELF logging MDC fields not defined in the MDC Configuration (i.e.
+ * MDC_ALERT_SEVERITY)
+ **/
+public class Mdc {
+ public enum Enum {
+ // BeginTimestamp,
+ // EndTimeStamp,
+ // RequestId,
+ // ServiceInstanceId,
+ VirtualServerName,
+ // ServiceName,
+ // PartnerName,
+ // StatusCOde,
+ // ResponseCode,
+ // ResponseDescription,
+ // InstanceUUID,
+ // AlertSeverity,
+ // ServerIPAddress,
+ // ElapsedTime,
+ // ServerFQDN,
+ // RemoteHost,
+ ClassName, Unused,
+ // ProcessKey,
+ CustomField1, CustomField2, CustomField3, CustomField4,
+ // TargetVirtualEntity,
+ // TargetEntity,
+ // TargetServiceName,
+ ErrorCode, ErrorDescription, Timer,
+ }
+
+ public static void begin(HttpServletRequest request, String requestId) {
+ MDC.clear();
+ Stopwatch.start();
+ // MDC.put(MDC_ALERT_SEVERITY, "");
+ MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
+ // MDC.put(MDC_ELAPSED_TIME, String.valueOf(Stopwatch.getDuration()));
+ // MDC.put(MDC_END_TIMESTAMP, "");
+ MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
+ // MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ setRequestId(request, requestId);
+ // MDC.put(MDC_PROCESS_KEY, "");
+ MDC.put(MDC_REMOTE_HOST, request.getRemoteHost());
+ // MDC.put(MDC_RESPONSE_CODE, "");
+ // MDC.put(MDC_RESPONSE_DESC, "");
+ // MDC.put(MDC_SERVICE_NAME, "");
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ } catch (Exception e) {
+ MDC.put(MDC_SERVER_FQDN, e.getMessage());
+ }
+ try {
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ MDC.put(MDC_SERVER_FQDN, e.getMessage());
+ }
+ MDC.put(MDC_SERVICE_INSTANCE_ID, "UNKNOWN");
+ MDC.put(MDC_SERVICE_NAME, "ecomp-cmso");
+ // MDC.put(MDC_STATUS_CODE, "");
+ setPartherTargetFromUri(request.getRequestURL().toString());
+ // Override partner hostname with username
+ MDC.put(MDC_PARTNER_NAME, BasicAuthenticatorFilter.getUser(request));
+ // MDC.put(MDC_TARGET_ENTITY, "");
+ // MDC.put(MDC_TARGET_SERVICE_NAME, "");
+ // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
+ MDC.put(Enum.ClassName.name(), getCaller(3));
+ // MDC.put(MdcEnum.CustomField1.name(), "");
+ // MDC.put(MdcEnum.CustomField2.name(), "");
+ // MDC.put(MdcEnum.CustomField3.name(), "");
+ // MDC.put(MdcEnum.CustomField4.name(), "");
+ // MDC.put(MdcEnum.ErrorCode.name(), "");
+ // MDC.put(MdcEnum.ErrorDescription.name(), "");
+ // MDC.put(MdcEnum.Timer.name(), "");
+ // MDC.put(MdcEnum.Unused.name(), "");
+ // MDC.put(MdcEnum.VirtualServerName.name(), "");
+
+ }
+
+ private static void setRequestId(HttpServletRequest request, String requestId) {
+
+ String transactionId = request.getHeader(MessageHeaders.HeadersEnum.TransactionID.toString());
+ if (transactionId == null) {
+ transactionId = requestId;
+ }
+ if (transactionId == null)
+ transactionId = "Unknown";
+ MDC.put(MDC_KEY_REQUEST_ID, transactionId);
+ }
+
+ public static void end(Response response) {
+ Stopwatch.stop();
+ // MDC.put(MDC_ALERT_SEVERITY, "");
+ // MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new
+ // Date()));
+ MDC.put(MDC_ELAPSED_TIME, String.valueOf(Stopwatch.getDuration()));
+ MDC.put(MDC_END_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
+ // MDC.put(MDC_INSTANCE_UUID, "");
+ // MDC.put(MDC_KEY_REQUEST_ID, "");
+ // MDC.put(MDC_PARTNER_NAME, "");
+ // MDC.put(MDC_PROCESS_KEY, "");
+ // MDC.put(MDC_REMOTE_HOST, "");
+ MDC.put(MDC_RESPONSE_CODE, String.valueOf(response.getStatus()));
+ MDC.put(MDC_RESPONSE_DESC, response.getStatusInfo().getReasonPhrase());
+ // MDC.put(MDC_SERVICE_NAME, "");
+ // MDC.put(MDC_SERVER_FQDN, "");
+ // MDC.put(MDC_SERVER_IP_ADDRESS, "");
+ // MDC.put(MDC_SERVICE_INSTANCE_ID, "");
+ // MDC.put(MDC_SERVICE_NAME, "");
+ MDC.put(MDC_STATUS_CODE, "COMPLETE");
+ if (response.getStatus() == 500)
+ MDC.put(MDC_STATUS_CODE, "ERROR");
+ // MDC.put(MDC_TARGET_ENTITY, "");
+ // MDC.put(MDC_TARGET_SERVICE_NAME, "");
+ // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
+ MDC.put(Enum.ClassName.name(), getCaller(3));
+ // MDC.put(MdcEnum.CustomField1.name(), "");
+ // MDC.put(MdcEnum.CustomField2.name(), "");
+ // MDC.put(MdcEnum.CustomField3.name(), "");
+ // MDC.put(MdcEnum.CustomField4.name(), "");
+ // MDC.put(MdcEnum.ErrorCode.name(), "");
+ // MDC.put(MdcEnum.ErrorDescription.name(), "");
+ // MDC.put(MdcEnum.Timer.name(), "");
+ // MDC.put(MdcEnum.Unused.name(), "");
+ // MDC.put(MdcEnum.VirtualServerName.name(), "");
+
+ }
+
+ public static String getCaller(int back) {
+ StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
+ return stackTraceElements[back].getClassName() + "." + stackTraceElements[back].getMethodName();
+ }
+
+ public static void quartzJobBegin(JobExecutionContext context) {
+ MDC.clear();
+ Stopwatch.start();
+ // MDC.put(MDC_ALERT_SEVERITY, "");
+ MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
+ // MDC.put(MDC_ELAPSED_TIME, String.valueOf(Stopwatch.getDuration()));
+ // MDC.put(MDC_END_TIMESTAMP, "");
+ MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
+ // MDC.put(MDC_KEY_REQUEST_ID);
+ // MDC.put(MDC_PARTNER_NAME, request.getRemoteUser());
+ // MDC.put(MDC_PROCESS_KEY, "");
+ // MDC.put(MDC_REMOTE_HOST, request.getRemoteHost());
+ // MDC.put(MDC_RESPONSE_CODE, "");
+ // MDC.put(MDC_RESPONSE_DESC, "");
+ // MDC.put(MDC_SERVICE_NAME, "");
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ } catch (Exception e) {
+ MDC.put(MDC_SERVER_FQDN, e.getMessage());
+ }
+ try {
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ MDC.put(MDC_SERVER_FQDN, e.getMessage());
+ }
+ MDC.put(MDC_SERVICE_INSTANCE_ID, "UNKNOWN");
+ MDC.put(MDC_SERVICE_NAME, "ecomp-cmso");
+ // MDC.put(MDC_STATUS_CODE, "");
+ // MDC.put(MDC_TARGET_ENTITY, "");
+ // MDC.put(MDC_TARGET_SERVICE_NAME, "");
+ // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
+ MDC.put(Enum.ClassName.name(), getCaller(3));
+ // MDC.put(MdcEnum.CustomField1.name(), "");
+ // MDC.put(MdcEnum.CustomField2.name(), "");
+ // MDC.put(MdcEnum.CustomField3.name(), "");
+ // MDC.put(MdcEnum.CustomField4.name(), "");
+ // MDC.put(MdcEnum.ErrorCode.name(), "");
+ // MDC.put(MdcEnum.ErrorDescription.name(), "");
+ // MDC.put(MdcEnum.Timer.name(), "");
+ // MDC.put(MdcEnum.Unused.name(), "");
+ // MDC.put(MdcEnum.VirtualServerName.name(), "");
+
+ }
+
+ public static void quartzJobEnd(JobExecutionContext context) {
+ Stopwatch.stop();
+ // MDC.put(MDC_ALERT_SEVERITY, "");
+ MDC.put(MDC_END_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
+ MDC.put(MDC_ELAPSED_TIME, String.valueOf(Stopwatch.getDuration()));
+ // MDC.put(MDC_START_TIMESTAMP, "");
+ // MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
+ // MDC.put(MDC_KEY_REQUEST_ID);
+ // MDC.put(MDC_PARTNER_NAME, request.getRemoteUser());
+ // MDC.put(MDC_PROCESS_KEY, "");
+ // MDC.put(MDC_REMOTE_HOST, request.getRemoteHost());
+ // MDC.put(MDC_RESPONSE_CODE, "");
+ // MDC.put(MDC_RESPONSE_DESC, "");
+ // MDC.put(MDC_SERVICE_NAME, "");
+ // try{ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName()); }
+ // catch (Exception e){ MDC.put(MDC_SERVER_FQDN, e.getMessage());}
+ // try{ MDC.put(MDC_SERVER_IP_ADDRESS,
+ // InetAddress.getLocalHost().getHostAddress()); } catch (Exception e){
+ // MDC.put(MDC_SERVER_FQDN, e.getMessage());}
+ // MDC.put(MDC_SERVICE_INSTANCE_ID, "UNKNOWN");
+ // MDC.put(MDC_SERVICE_NAME, "ecomp-cmso");
+ // MDC.put(MDC_STATUS_CODE, "");
+ // MDC.put(MDC_TARGET_ENTITY, "");
+ // MDC.put(MDC_TARGET_SERVICE_NAME, "");
+ // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
+ MDC.put(Enum.ClassName.name(), getCaller(3));
+ // MDC.put(MdcEnum.CustomField1.name(), "");
+ // MDC.put(MdcEnum.CustomField2.name(), "");
+ // MDC.put(MdcEnum.CustomField3.name(), "");
+ // MDC.put(MdcEnum.CustomField4.name(), "");
+ // MDC.put(MdcEnum.ErrorCode.name(), "");
+ // MDC.put(MdcEnum.ErrorDescription.name(), "");
+ // MDC.put(MdcEnum.Timer.name(), "");
+ // MDC.put(MdcEnum.Unused.name(), "");
+ // MDC.put(MdcEnum.VirtualServerName.name(), "");
+
+ }
+
+ public static Map<String, String> save() {
+ Map<String, String> save = MDC.getCopyOfContextMap();
+ return save;
+ }
+
+ public static void restore(Map<String, String> mdcSave) {
+ MDC.clear();
+ for (String name : mdcSave.keySet())
+ MDC.put(name, mdcSave.get(name));
+ }
+
+ public static void metricStart(String requestId, String url) {
+ MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
+ // MDC.put(MDC_ELAPSED_TIME, String.valueOf(Stopwatch.getDuration()));
+ // MDC.put(MDC_END_TIMESTAMP, "");
+ // MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
+ // MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ // MDC.put(MDC_PARTNER_NAME, invocationBuilder.ge.getRemoteUser());
+ // MDC.put(MDC_PROCESS_KEY, "");
+ // MDC.put(MDC_REMOTE_HOST, request.getRemoteHost());
+ // MDC.put(MDC_RESPONSE_CODE, "");
+ // MDC.put(MDC_RESPONSE_DESC, "");
+ // MDC.put(MDC_SERVICE_NAME, "");
+ // try{ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName()); }
+ // catch (Exception e){ MDC.put(MDC_SERVER_FQDN, e.getMessage());}
+ // try{ MDC.put(MDC_SERVER_IP_ADDRESS,
+ // InetAddress.getLocalHost().getHostAddress()); } catch (Exception e){
+ // MDC.put(MDC_SERVER_FQDN, e.getMessage());}
+ // MDC.put(MDC_SERVICE_INSTANCE_ID, "UNKNOWN");
+ // MDC.put(MDC_SERVICE_NAME, "ecomp-cmso");
+ // MDC.put(MDC_STATUS_CODE, "");
+ setPartherTargetFromUri(url);
+ // MDC.put(MDC_TARGET_ENTITY, "");
+ // MDC.put(MDC_TARGET_SERVICE_NAME, "");
+ // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
+ MDC.put(Enum.ClassName.name(), getCaller(3));
+ // MDC.put(MdcEnum.CustomField1.name(), "");
+ // MDC.put(MdcEnum.CustomField2.name(), "");
+ // MDC.put(MdcEnum.CustomField3.name(), "");
+ // MDC.put(MdcEnum.CustomField4.name(), "");
+ // MDC.put(MdcEnum.ErrorCode.name(), "");
+ // MDC.put(MdcEnum.ErrorDescription.name(), "");
+ // MDC.put(MdcEnum.Timer.name(), "");
+ // MDC.put(MdcEnum.Unused.name(), "");
+ // MDC.put(MdcEnum.VirtualServerName.name(), "");
+
+ }
+
+ public static void metricEnd(Response response) {
+
+ // MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
+ try {
+ Long then = Stopwatch.isoFormatter.parse(MDC.get(MDC_BEGIN_TIMESTAMP)).getTime();
+ Long now = System.currentTimeMillis();
+ MDC.put(MDC_ELAPSED_TIME, String.valueOf(now - then));
+ } catch (Exception e) {
+ MDC.put(MDC_ELAPSED_TIME, "");
+ }
+ MDC.put(MDC_END_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
+
+ // MDC.put(MDC_INSTANCE_UUID, UUID.randomUUID().toString());
+ // MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ // MDC.put(MDC_PARTNER_NAME, invocationBuilder.ge.getRemoteUser());
+ // MDC.put(MDC_PROCESS_KEY, "");
+ // MDC.put(MDC_REMOTE_HOST, response.getLocation().toString());
+ MDC.put(MDC_RESPONSE_CODE, String.valueOf(response.getStatus()));
+ MDC.put(MDC_RESPONSE_DESC, response.getStatusInfo().getReasonPhrase());
+ // MDC.put(MDC_SERVICE_NAME, "");
+ // try{ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName()); }
+ // catch (Exception e){ MDC.put(MDC_SERVER_FQDN, e.getMessage());}
+ // try{ MDC.put(MDC_SERVER_IP_ADDRESS,
+ // InetAddress.getLocalHost().getHostAddress()); } catch (Exception e){
+ // MDC.put(MDC_SERVER_FQDN, e.getMessage());}
+ // MDC.put(MDC_SERVICE_INSTANCE_ID, "UNKNOWN");
+ // MDC.put(MDC_SERVICE_NAME, "ecomp-cmso");
+ MDC.put(MDC_STATUS_CODE, "COMPLETE");
+ if (response.getStatus() == 500)
+ MDC.put(MDC_STATUS_CODE, "ERROR");
+ // MDC.put(MDC_TARGET_ENTITY, "");
+ // MDC.put(MDC_TARGET_SERVICE_NAME, "");
+ // MDC.put(MDC_TARGET_VIRTUAL_ENTITY, "");
+ MDC.put(Enum.ClassName.name(), getCaller(3));
+ // MDC.put(MdcEnum.CustomField1.name(), "");
+ // MDC.put(MdcEnum.CustomField2.name(), "");
+ // MDC.put(MdcEnum.CustomField3.name(), "");
+ // MDC.put(MdcEnum.CustomField4.name(), "");
+ // MDC.put(MdcEnum.ErrorCode.name(), "");
+ // MDC.put(MdcEnum.ErrorDescription.name(), "");
+ // MDC.put(MdcEnum.Timer.name(), "");
+ // MDC.put(MdcEnum.Unused.name(), "");
+ // MDC.put(MdcEnum.VirtualServerName.name(), "");
+
+ }
+
+ private static void setPartherTargetFromUri(String url) {
+ try {
+ URI uri = new URI(url);
+ MDC.put(MDC_PARTNER_NAME, uri.getHost());
+ MDC.put(MDC_TARGET_ENTITY, uri.getScheme() + "://" + uri.getHost() + ":" + uri.getPort());
+ MDC.put(MDC_TARGET_SERVICE_NAME, uri.getPath());
+ } catch (Exception e) {
+ MDC.put(MDC_PARTNER_NAME, "UNKNOWN");
+ MDC.put(MDC_TARGET_ENTITY, "UNKNOWN");
+ MDC.put(MDC_TARGET_SERVICE_NAME, url);
+ }
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java
new file mode 100644
index 0000000..4514a57
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/PropertiesManagement.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common;
+
+import java.io.UnsupportedEncodingException;
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import javax.xml.bind.DatatypeConverter;
+import org.apache.commons.codec.binary.Base64;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+@Component
+public class PropertiesManagement {
+
+ private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
+ private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();
+
+ private final static String algorithm = "AES";
+ private final static String cipherMode = "CBC";
+ private final static String paddingScheme = "PKCS5Padding";
+ private final static String transformation = algorithm + "/" + cipherMode + "/" + paddingScheme;
+
+ private static final String initVector = "ONAPCMSOVECTORIV"; // 16 bytes IV
+
+ @Autowired
+ Environment env;
+
+ public String getProperty(String key, String defaultValue) {
+ String value = env.getProperty(key, defaultValue);
+ value = getDecryptedValue(value);
+ return value;
+ }
+
+ public static String getDecryptedValue(String value) {
+ if (value.startsWith("enc:")) {
+ String secret = getSecret();
+ value = decrypt(secret, initVector, value.substring(4));
+ }
+ return value;
+ }
+
+ public static String getEncryptedValue(String value) {
+ String secret = getSecret();
+ value = encrypt(secret, initVector, value);
+ return value;
+ }
+
+ private static final String encrypt(String key, String initVector, String value) {
+ try {
+ IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
+ SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
+ Cipher cipher = Cipher.getInstance(transformation);
+ cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
+ byte[] encrypted = cipher.doFinal(value.getBytes());
+ return Base64.encodeBase64String(encrypted);
+ } catch (Exception ex) {
+ errors.error("Unexpected exception {0}", ex.getMessage());
+ debug.debug("Unexpected exception", ex);
+ }
+
+ return null;
+ }
+
+ private static final String decrypt(String key, String initVector, String encrypted) {
+ try {
+ IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8"));
+ SecretKeySpec skeySpec = new SecretKeySpec(key.getBytes("UTF-8"), "AES");
+ Cipher cipher = Cipher.getInstance(transformation);
+ cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
+ byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));
+ return new String(original);
+ } catch (Exception ex) {
+ errors.error("Unexpected exception {0}", ex.getMessage());
+ debug.debug("Unexpected exception", ex);
+ }
+ return null;
+ }
+
+ private static String getSecret() {
+ return "ONAPCMSOSECRETIV";
+ }
+
+ public static void main(String[] args) {
+ try {
+ String pass = getDecryptedValue("enc:bfodXf8qRfCqMvlxVBYNWQ==");
+ //System.out.println("Decrypt - "+pass);
+ pass = getEncryptedValue("cmso@onap.org");
+ //System.out.println("Encrypt - "+pass);
+ //System.out.println(DatatypeConverter.printBase64Binary("cmso@onap.org:cmso@onap.org".getBytes("UTF-8")));
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSAlreadyExistsException.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSAlreadyExistsException.java
new file mode 100644
index 0000000..d461e4f
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSAlreadyExistsException.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common.exceptions;
+
+import javax.ws.rs.core.Response.Status;
+import org.onap.optf.cmso.common.LogMessages;
+
+public class CMSAlreadyExistsException extends CMSException {
+ private static final long serialVersionUID = 1L;
+
+ public CMSAlreadyExistsException(String... args) {
+ super(Status.CONFLICT, LogMessages.SCHEDULE_ALREADY_EXISTS, args);
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java
new file mode 100644
index 0000000..c49d02f
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSException.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common.exceptions;
+
+import java.util.ArrayList;
+import java.util.List;
+import javax.ws.rs.core.Response.Status;
+import org.onap.optf.cmso.common.CMSRequestError;
+import org.onap.optf.cmso.common.LogMessages;
+import com.att.eelf.i18n.EELFResourceManager;
+
+public class CMSException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ protected CMSRequestError requestError = null;
+ private List<String> variables = new ArrayList<String>();
+ protected LogMessages messageCode;
+ protected Status status;
+
+ public CMSException(Status status, LogMessages messageCode, String... args) {
+ super(EELFResourceManager.format(messageCode, args));
+ this.status = status;
+ this.messageCode = messageCode;
+ for (String arg : args)
+ variables.add(arg);
+ requestError = new CMSRequestError(messageCode.name(), getMessage(), variables);
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public LogMessages getMessageCode() {
+ return messageCode;
+ }
+
+ public String[] getVariables() {
+ return variables.toArray(new String[variables.size()]);
+ }
+
+ public CMSRequestError getRequestError() {
+ return requestError;
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSNotFoundException.java b/cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSNotFoundException.java
new file mode 100644
index 0000000..2a46e21
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/common/exceptions/CMSNotFoundException.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2017-2018 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.cmso.common.exceptions;
+
+import javax.ws.rs.core.Response.Status;
+import org.onap.optf.cmso.common.LogMessages;
+
+public class CMSNotFoundException extends CMSException {
+ private static final long serialVersionUID = 1L;
+
+ public CMSNotFoundException(String... args) {
+ super(Status.NOT_FOUND, LogMessages.SCHEDULE_NOT_FOUND, args);
+ }
+
+}