Commit 17 for Create Optimized Sched API 42/83242/2
authorJerry Flood <jflood@att.com>
Mon, 25 Mar 2019 16:28:31 +0000 (12:28 -0400)
committerJerry Flood <jflood@att.com>
Tue, 26 Mar 2019 11:00:27 +0000 (07:00 -0400)
Multiple commits required due to commit size limitation.

Change-Id: I13ee156d9f4e9c5e6d55f0e0dcdef94cc3f6a1b0
Issue-ID: OPTFRA-458
Signed-off-by: Jerry Flood <jflood@att.com>
cmso-service/src/main/java/org/onap/optf/cmso/test/loopback/TicketMgtLoopbackServiceImpl.java
cmso-service/src/main/java/org/onap/optf/cmso/ticketmgt/TmClient.java
cmso-service/src/main/java/org/onap/optf/cmso/ticketmgt/TmEndpoints.java

index 1c87f66..4fd3914 100644 (file)
@@ -1,36 +1,35 @@
 /*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ *\r
+ *\r
+ * Unless otherwise specified, all documentation contained herein is licensed under the Creative\r
+ * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * https://creativecommons.org/licenses/by/4.0/\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, documentation distributed under the\r
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\r
+ * express or implied. See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
+ */\r
 \r
 package org.onap.optf.cmso.test.loopback;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import com.fasterxml.jackson.databind.node.ObjectNode;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 import javax.ws.rs.core.Response;\r
@@ -42,16 +41,10 @@ import org.onap.optf.cmso.ticketmgt.bean.TmStatusEnum;
 import org.springframework.beans.factory.annotation.Autowired;\r
 import org.springframework.core.env.Environment;\r
 import org.springframework.stereotype.Controller;\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-import com.fasterxml.jackson.databind.JsonNode;\r
-import com.fasterxml.jackson.databind.node.ObjectNode;\r
 \r
 @Controller\r
 public class TicketMgtLoopbackServiceImpl implements TicketMgtLoopbackService {\r
-    private static EELFLogger log = EELFManager.getInstance().getLogger(TicketMgtLoopbackServiceImpl.class);\r
     private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();\r
-    private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();\r
 \r
     @Autowired\r
     Environment env;\r
index c3b9be8..c8cae12 100644 (file)
@@ -1,36 +1,37 @@
 /*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ *\r
+ *\r
+ * Unless otherwise specified, all documentation contained herein is licensed under the Creative\r
+ * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * https://creativecommons.org/licenses/by/4.0/\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, documentation distributed under the\r
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\r
+ * express or implied. See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
+ */\r
 \r
 package org.onap.optf.cmso.ticketmgt;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.fasterxml.jackson.databind.node.ArrayNode;\r
+import com.fasterxml.jackson.databind.node.ObjectNode;\r
 import java.net.UnknownHostException;\r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
@@ -38,7 +39,6 @@ import java.util.Iterator;
 import java.util.List;\r
 import java.util.Map;\r
 import java.util.UUID;\r
-\r
 import javax.ws.rs.ProcessingException;\r
 import javax.ws.rs.client.Client;\r
 import javax.ws.rs.client.ClientBuilder;\r
@@ -48,7 +48,6 @@ import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.MediaType;\r
 import javax.ws.rs.core.Response;\r
 import javax.ws.rs.core.Response.Status;\r
-\r
 import org.apache.commons.text.StringSubstitutor;\r
 import org.joda.time.format.ISODateTimeFormat;\r
 import org.onap.observations.Mdc;\r
@@ -58,7 +57,7 @@ import org.onap.optf.cmso.common.CmHelpers;
 import org.onap.optf.cmso.common.LogMessages;\r
 import org.onap.optf.cmso.common.PropertiesManagement;\r
 import org.onap.optf.cmso.common.exceptions.CMSException;\r
-import org.onap.optf.cmso.filters.CMSOClientFilters;\r
+import org.onap.optf.cmso.filters.CmsoClientFilters;\r
 import org.onap.optf.cmso.model.ChangeManagementGroup;\r
 import org.onap.optf.cmso.model.ChangeManagementSchedule;\r
 import org.onap.optf.cmso.model.DomainData;\r
@@ -76,13 +75,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.env.Environment;\r
 import org.springframework.stereotype.Component;\r
 \r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-import com.fasterxml.jackson.databind.JsonNode;\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
-import com.fasterxml.jackson.databind.node.ArrayNode;\r
-import com.fasterxml.jackson.databind.node.ObjectNode;\r
-\r
+/**\r
+ * The Class TmClient.\r
+ */\r
 @Component\r
 public class TmClient {\r
     private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();\r
@@ -94,7 +89,7 @@ public class TmClient {
     PropertiesManagement pm;\r
 \r
     @Autowired\r
-    ChangeManagementScheduleDAO cmScheduleDAO;\r
+    ChangeManagementScheduleDAO cmScheduleDao;\r
 \r
     @Autowired\r
     BuildCreateRequest buildCreateRequest;\r
@@ -102,8 +97,18 @@ public class TmClient {
     @Autowired\r
     TmEndpoints tmEndpoints;\r
 \r
+    /**\r
+     * Creates the change ticket.\r
+     *\r
+     * @param schedule the schedule\r
+     * @param group the group\r
+     * @param vnfNames the vnf names\r
+     * @param domainData the domain data\r
+     * @return the string\r
+     * @throws CMSException the CMS exception\r
+     */\r
     public String createChangeTicket(Schedule schedule, ChangeManagementGroup group, List<String> vnfNames,\r
-            List<DomainData> domainData) throws CMSException {\r
+                    List<DomainData> domainData) throws CMSException {\r
 \r
         String changeId = "";\r
         String workflowName = CmHelpers.getDomainData(domainData, CmDomainDataEnum.WorkflowName);\r
@@ -115,15 +120,34 @@ public class TmClient {
         return changeId;\r
     }\r
 \r
+    /**\r
+     * Close ticket.\r
+     *\r
+     * @param schedule the schedule\r
+     * @param group the group\r
+     * @param cmSchedules the cm schedules\r
+     * @param changeId the change id\r
+     * @param closureCode the closure code\r
+     * @param closingComments the closing comments\r
+     * @throws CMSException the CMS exception\r
+     */\r
     public void closeTicket(Schedule schedule, ChangeManagementGroup group, List<ChangeManagementSchedule> cmSchedules,\r
-            String changeId, ClosureCode closureCode, String closingComments) throws CMSException {\r
+                    String changeId, ClosureCode closureCode, String closingComments) throws CMSException {\r
         Map<String, Object> variables =\r
-                getCloseVariables(schedule, group, cmSchedules, changeId, closureCode, closingComments);\r
+                        getCloseVariables(schedule, group, cmSchedules, changeId, closureCode, closingComments);\r
         JsonNode closeChangeRecord = buildCreateRequest.createCloseCancelChangeRecord(variables);\r
         debug.debug("closeChangeRecord=" + closeChangeRecord.toString());\r
         postCloseChangeTicket(closeChangeRecord, schedule.getScheduleId(), changeId);\r
     }\r
 \r
+    /**\r
+     * Cancel ticket.\r
+     *\r
+     * @param schedule the schedule\r
+     * @param cms the cms\r
+     * @param changeId the change id\r
+     * @throws CMSException the CMS exception\r
+     */\r
     public void cancelTicket(Schedule schedule, ChangeManagementSchedule cms, String changeId) throws CMSException {\r
         Map<String, Object> variables = getCancelVariables(schedule, changeId);\r
         JsonNode cancelChangeRecord = buildCreateRequest.createCancelChangeRecord(variables);\r
@@ -131,6 +155,14 @@ public class TmClient {
         postCloseChangeTicket(cancelChangeRecord, schedule.getScheduleId(), changeId);\r
     }\r
 \r
+    /**\r
+     * Update ticket.\r
+     *\r
+     * @param schedule the schedule\r
+     * @param cms the cms\r
+     * @param changeId the change id\r
+     * @throws CMSException the CMS exception\r
+     */\r
     public void updateTicket(Schedule schedule, ChangeManagementSchedule cms, String changeId) throws CMSException {\r
         Map<String, Object> variables = getUpdateVariables(schedule, changeId);\r
         JsonNode updateChangeRecord = buildCreateRequest.createUpdateChangeRecord(variables);\r
@@ -138,6 +170,12 @@ public class TmClient {
         postUpdateChangeTicket(updateChangeRecord, schedule.getScheduleId(), changeId);\r
     }\r
 \r
+    /**\r
+     * Gets the change ticket.\r
+     *\r
+     * @param changeId the change id\r
+     * @return the change ticket\r
+     */\r
     public TmChangeInfo getChangeTicket(String changeId) {\r
         Map<String, String> mdcSave = Mdc.save();\r
         try {\r
@@ -155,7 +193,7 @@ public class TmClient {
                     break;\r
                 default: {\r
                     Observation.report(LogMessages.UNEXPECTED_RESPONSE, "TM", String.valueOf(response.getStatus()),\r
-                            response.toString());\r
+                                    response.toString());\r
                 }\r
             }\r
         } catch (Exception e) {\r
@@ -167,29 +205,37 @@ public class TmClient {
     }\r
 \r
     private Map<String, Object> getCloseVariables(Schedule schedule, ChangeManagementGroup group,\r
-            List<ChangeManagementSchedule> cmSchedules, String changeId, ClosureCode closureCode,\r
-            String closingComments) {\r
+                    List<ChangeManagementSchedule> cmSchedules, String changeId, ClosureCode closureCode,\r
+                    String closingComments) {\r
         String requesterId = schedule.getUserId();\r
-        Map<String, Object> variables = new HashMap<String, Object>();\r
-        if (requesterId.length() > Variables.requesterId.getMaxLength())\r
+        if (requesterId.length() > Variables.requesterId.getMaxLength()) {\r
             requesterId = requesterId.substring(0, Variables.requesterId.getMaxLength());\r
+        }\r
         long actualStartDate = 0;\r
         long actualEndDate = 0;\r
         for (ChangeManagementSchedule cms : cmSchedules) {\r
-            if (cms.getDispatchTimeMillis() != null)\r
-                if (actualStartDate == 0 || cms.getDispatchTimeMillis() < actualStartDate)\r
+            if (cms.getDispatchTimeMillis() != null) {\r
+                if (actualStartDate == 0 || cms.getDispatchTimeMillis() < actualStartDate) {\r
                     actualStartDate = cms.getDispatchTimeMillis();\r
-            if (cms.getExecutionCompletedTimeMillis() != null)\r
-                if (cms.getExecutionCompletedTimeMillis() > actualEndDate)\r
+                }\r
+            }\r
+            if (cms.getExecutionCompletedTimeMillis() != null) {\r
+                if (cms.getExecutionCompletedTimeMillis() > actualEndDate) {\r
                     actualEndDate = cms.getExecutionCompletedTimeMillis();\r
+                }\r
+            }\r
         }\r
         if (closureCode != ClosureCode.Successful) {\r
-            if (actualEndDate == 0)\r
+            if (actualEndDate == 0) {\r
                 actualEndDate = System.currentTimeMillis();\r
-            if (actualStartDate == 0)\r
+            }\r
+            if (actualStartDate == 0) {\r
                 actualStartDate = actualEndDate - 1000;\r
+            }\r
 \r
         }\r
+        Map<String, Object> variables = new HashMap<String, Object>();\r
+\r
         variables.put(Variables.status.toString(), "Closed");\r
         variables.put(Variables.requesterId.toString(), requesterId);\r
         variables.put(Variables.actualStartDate.toString(), actualStartDate / 1000);\r
@@ -203,8 +249,9 @@ public class TmClient {
     private Map<String, Object> getCancelVariables(Schedule schedule, String changeId) {\r
         String requesterId = schedule.getUserId();\r
         Map<String, Object> variables = new HashMap<String, Object>();\r
-        if (requesterId.length() > Variables.requesterId.getMaxLength())\r
+        if (requesterId.length() > Variables.requesterId.getMaxLength()) {\r
             requesterId = requesterId.substring(0, Variables.requesterId.getMaxLength());\r
+        }\r
         variables.put(Variables.requesterId.toString(), requesterId);\r
         variables.put(Variables.changeId.toString(), changeId);\r
         return variables;\r
@@ -213,15 +260,16 @@ public class TmClient {
     private Map<String, Object> getUpdateVariables(Schedule schedule, String changeId) {\r
         String requesterId = schedule.getUserId();\r
         Map<String, Object> variables = new HashMap<String, Object>();\r
-        if (requesterId.length() > Variables.requesterId.getMaxLength())\r
+        if (requesterId.length() > Variables.requesterId.getMaxLength()) {\r
             requesterId = requesterId.substring(0, Variables.requesterId.getMaxLength());\r
+        }\r
         variables.put(Variables.requesterId.toString(), requesterId);\r
         variables.put(Variables.changeId.toString(), changeId);\r
         return variables;\r
     }\r
 \r
     private void postCloseChangeTicket(JsonNode closeChangeRecord, String scheduleId, String changeId)\r
-            throws CMSException {\r
+                    throws CMSException {\r
         Map<String, String> mdcSave = Mdc.save();\r
         try {\r
             Response response = null;\r
@@ -241,24 +289,24 @@ public class TmClient {
                     debug.debug("response=" + respString);\r
                     if (!isAlreadyClosed(respString)) {\r
                         Observation.report(LogMessages.UNEXPECTED_RESPONSE, "vTM", String.valueOf(response.getStatus()),\r
-                                response.toString() + " : " + respString);\r
+                                        response.toString() + " : " + respString);\r
                         throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.UNABLE_TO_CLOSE_CHANGE_TICKET,\r
-                                scheduleId, changeId, respString);\r
+                                        scheduleId, changeId, respString);\r
                     }\r
                 }\r
                     break;\r
                 default: {\r
                     String message = response.readEntity(String.class);\r
                     Observation.report(LogMessages.UNEXPECTED_RESPONSE, "vTM", String.valueOf(response.getStatus()),\r
-                            response.toString() + " : " + message);\r
+                                    response.toString() + " : " + message);\r
                     throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.UNABLE_TO_CLOSE_CHANGE_TICKET,\r
-                            scheduleId, changeId, message);\r
+                                    scheduleId, changeId, message);\r
                 }\r
             }\r
         } catch (ProcessingException e) {\r
             Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
             throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.UNABLE_TO_CLOSE_CHANGE_TICKET, scheduleId,\r
-                    changeId, e.toString());\r
+                            changeId, e.toString());\r
         } finally {\r
             Mdc.restore(mdcSave);\r
         }\r
@@ -300,36 +348,38 @@ public class TmClient {
     }\r
 \r
     private Map<String, Object> getVariables(Schedule schedule, ChangeManagementGroup group, List<String> vnfNames,\r
-            List<DomainData> domainData) {\r
-        Long plannedStartDate = group.getStartTimeMillis();\r
-        Long plannedEndDate = group.getFinishTimeMillis();\r
-        Long validationStartTime = plannedStartDate + group.getNormalDurationInSecs();\r
-        Long backoutStartTime = plannedEndDate - group.getAdditionalDurationInSecs();\r
+                    List<DomainData> domainData) {\r
         String requesterId = schedule.getUserId();\r
         Map<String, Object> variables = new HashMap<String, Object>();\r
 \r
         String vnfList = vnfNames.toString();\r
-        if (vnfList.length() > Variables.vnfList.getMaxLength())\r
+        if (vnfList.length() > Variables.vnfList.getMaxLength()) {\r
             vnfList = vnfList.substring(0, Variables.vnfList.getMaxLength());\r
-        if (requesterId.length() > Variables.requesterId.getMaxLength())\r
+        }\r
+        if (requesterId.length() > Variables.requesterId.getMaxLength()) {\r
             requesterId = requesterId.substring(0, Variables.requesterId.getMaxLength());\r
+        }\r
 \r
         variables.put(Variables.vnfList.toString(), vnfList);\r
         variables.put(Variables.vnfName.toString(), vnfNames.get(0));\r
         variables.put(Variables.requesterId.toString(), requesterId);\r
+        Long plannedStartDate = group.getStartTimeMillis();\r
+        Long plannedEndDate = group.getFinishTimeMillis();\r
         variables.put(Variables.plannedStartDate.toString(), plannedStartDate / 1000);\r
         variables.put(Variables.plannedEndDate.toString(), plannedEndDate / 1000);\r
+        Long validationStartTime = plannedStartDate + group.getNormalDurationInSecs();\r
+        Long backoutStartTime = plannedEndDate - group.getAdditionalDurationInSecs();\r
         variables.put(Variables.validationStartTime.toString(), validationStartTime / 1000);\r
         variables.put(Variables.backoutStartTime.toString(), backoutStartTime / 1000);\r
         // These will be display UTC -\r
         variables.put(Variables.validationStartTimeDisplay.toString(),\r
-                ISODateTimeFormat.dateTimeNoMillis().print(validationStartTime));\r
+                        ISODateTimeFormat.dateTimeNoMillis().print(validationStartTime));\r
         variables.put(Variables.backoutStartTimeDisplay.toString(),\r
-                ISODateTimeFormat.dateTimeNoMillis().print(backoutStartTime));\r
+                        ISODateTimeFormat.dateTimeNoMillis().print(backoutStartTime));\r
         variables.put(Variables.plannedStartTimeDisplay.toString(),\r
-                ISODateTimeFormat.dateTimeNoMillis().print(plannedStartDate));\r
+                        ISODateTimeFormat.dateTimeNoMillis().print(plannedStartDate));\r
         variables.put(Variables.plannedEndTimeDisplay.toString(),\r
-                ISODateTimeFormat.dateTimeNoMillis().print(plannedEndDate));\r
+                        ISODateTimeFormat.dateTimeNoMillis().print(plannedEndDate));\r
 \r
         // Ticket field values can be passed in via the DomainData\r
         JsonNode defaultValues = buildCreateRequest.getYaml("DefaultChangeTicketProperties");\r
@@ -384,24 +434,24 @@ public class TmClient {
                         }\r
                     } else {\r
                         Observation.report(LogMessages.UNEXPECTED_RESPONSE, "vTM", String.valueOf(response.getStatus()),\r
-                                response.toString() + " : " + "Response is empty");\r
+                                        response.toString() + " : " + "Response is empty");\r
                         throw new CMSException(Status.EXPECTATION_FAILED, LogMessages.UNABLE_TO_CREATE_CHANGE_TICKET,\r
-                                scheduleId, "Response is empty");\r
+                                        scheduleId, "Response is empty");\r
                     }\r
                 }\r
                     break;\r
                 default: {\r
                     String message = response.readEntity(String.class);\r
                     Observation.report(LogMessages.UNEXPECTED_RESPONSE, "vTM", String.valueOf(response.getStatus()),\r
-                            response.toString() + " : " + message);\r
+                                    response.toString() + " : " + message);\r
                     throw new CMSException(Status.EXPECTATION_FAILED, LogMessages.UNABLE_TO_CREATE_CHANGE_TICKET,\r
-                            scheduleId, message);\r
+                                    scheduleId, message);\r
                 }\r
             }\r
         } catch (ProcessingException e) {\r
             Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
             throw new CMSException(Status.EXPECTATION_FAILED, LogMessages.UNABLE_TO_CREATE_CHANGE_TICKET, scheduleId,\r
-                    e.toString());\r
+                            e.toString());\r
         } finally {\r
             Mdc.restore(mdcSave);\r
         }\r
@@ -409,7 +459,7 @@ public class TmClient {
     }\r
 \r
     private String postUpdateChangeTicket(JsonNode updateChangeRecord, String scheduleId, String changeId)\r
-            throws CMSException {\r
+                    throws CMSException {\r
         Map<String, String> mdcSave = Mdc.save();\r
         try {\r
             String url = env.getProperty("vtm.url") + env.getProperty("vtm.updatePath");\r
@@ -429,50 +479,21 @@ public class TmClient {
                 default: {\r
                     String message = response.readEntity(String.class);\r
                     Observation.report(LogMessages.UNEXPECTED_RESPONSE, "vTM", String.valueOf(response.getStatus()),\r
-                            response.toString() + " : " + message);\r
+                                    response.toString() + " : " + message);\r
                     throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.UNABLE_TO_UPDATE_CHANGE_TICKET,\r
-                            scheduleId, changeId, message);\r
+                                    scheduleId, changeId, message);\r
                 }\r
             }\r
         } catch (ProcessingException e) {\r
             Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
             throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.UNABLE_TO_UPDATE_CHANGE_TICKET, scheduleId,\r
-                    changeId, e.toString());\r
+                            changeId, e.toString());\r
         } finally {\r
             Mdc.restore(mdcSave);\r
         }\r
         return changeId;\r
     }\r
 \r
-    private Response vtmPostOld(String url, Object request, String scheduleId) throws CMSException {\r
-        Response response = null;\r
-        try {\r
-            String user = env.getProperty("vtm.user");\r
-            String pass = pm.getProperty("vtm.pass", "");\r
-            // Cannot provide changeId. Interesting.\r
-            // This should be replaced by fetch\r
-            // For now, make a best effort to get the passed changeId\r
-\r
-            Client client = ClientBuilder.newClient();\r
-            client.register(new BasicAuthenticatorFilter(user, pass));\r
-            client.register(new CMSOClientFilters());\r
-            WebTarget target = client.target(url);\r
-            Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON);\r
-            ObjectMapper mapper = new ObjectMapper();\r
-            String jsonRequest = mapper.writeValueAsString(request);\r
-            debug.debug("vTM URL = " + url + " user=" + user + " : " + jsonRequest);\r
-            response = invocationBuilder.post(Entity.json(request));\r
-            // String message = response.readEntity(String.class);\r
-            // debug.debug("Return from " + url + " : " + response.toString() + "\n" +\r
-            // message);\r
-            debug.debug("Return from " + url + " : " + response.toString());\r
-        } catch (Exception e) {\r
-            Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.toString());\r
-            throw new CMSException(Status.INTERNAL_SERVER_ERROR, LogMessages.UNABLE_TO_CREATE_CHANGE_TICKET, scheduleId,\r
-                    e.getMessage());\r
-        }\r
-        return response;\r
-    }\r
 \r
     private Response tmPost(Endpoint ep, Object request, String scheduleId) throws CMSException {\r
         Response response = null;\r
@@ -488,7 +509,7 @@ public class TmClient {
 \r
                 Client client = ClientBuilder.newClient();\r
                 client.register(new BasicAuthenticatorFilter(user, pass));\r
-                client.register(new CMSOClientFilters());\r
+                client.register(new CmsoClientFilters());\r
                 WebTarget target = client.target(url);\r
                 Invocation.Builder invocationBuilder = target.request(MediaType.APPLICATION_JSON);\r
                 ObjectMapper mapper = new ObjectMapper();\r
@@ -503,25 +524,31 @@ public class TmClient {
             } catch (ProcessingException e) {\r
                 Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.toString());\r
                 url = tmEndpoints.getNextEndpoint(ep, endpoints);\r
-                if (url == null || !tryNextURL(e)) {\r
+                if (url == null || !tryNextUrl(e)) {\r
                     throw new CMSException(Status.INTERNAL_SERVER_ERROR, LogMessages.UNABLE_TO_CREATE_CHANGE_TICKET,\r
-                            scheduleId, e.getMessage());\r
+                                    scheduleId, e.getMessage());\r
                 }\r
             } catch (Exception e) {\r
                 Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.toString());\r
                 throw new CMSException(Status.INTERNAL_SERVER_ERROR, LogMessages.UNABLE_TO_CREATE_CHANGE_TICKET,\r
-                        scheduleId, e.getMessage());\r
+                                scheduleId, e.getMessage());\r
             }\r
         }\r
         return response;\r
     }\r
 \r
-    private boolean tryNextURL(ProcessingException e) {\r
-        if (e.getCause() instanceof UnknownHostException)\r
+    private boolean tryNextUrl(ProcessingException exc) {\r
+        if (exc.getCause() instanceof UnknownHostException) {\r
             return true;\r
+        }\r
         return true;\r
     }\r
 \r
+    /**\r
+     * Health check.\r
+     *\r
+     * @return the health check component\r
+     */\r
     public HealthCheckComponent healthCheck() {\r
         // No op\r
         HealthCheckComponent hcc = new HealthCheckComponent();\r
index b72eef4..97e4538 100644 (file)
@@ -1,27 +1,27 @@
 /*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
+ * Copyright Â© 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright Â© 2018 IBM.\r
+ *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- * \r
+ *\r
  *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
+ *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * \r
- * \r
+ *\r
+ *\r
  * Unless otherwise specified, all documentation contained herein is licensed\r
  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
  * you may not use this documentation except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- * \r
+ *\r
  *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
+ *\r
  * Unless required by applicable law or agreed to in writing, documentation\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
@@ -31,6 +31,8 @@
 \r
 package org.onap.optf.cmso.ticketmgt;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 import java.util.List;\r
@@ -38,13 +40,10 @@ import java.util.Map;
 import org.springframework.beans.factory.annotation.Autowired;\r
 import org.springframework.core.env.Environment;\r
 import org.springframework.stereotype.Component;\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
 \r
 @Component\r
 public class TmEndpoints {\r
     private static EELFLogger log = EELFManager.getInstance().getLogger(TmEndpoints.class);\r
-    private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();\r
     private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();\r
 \r
     @Autowired\r
@@ -72,8 +71,15 @@ public class TmEndpoints {
 \r
     private boolean legacyLoaded = false;\r
     private Map<Endpoint, List<String>> endpointMap = new HashMap<>();\r
-    private Map<Endpoint, String> endpointMapOK = new HashMap<>();\r
+    private Map<Endpoint, String> endpointMapOk = new HashMap<>();\r
 \r
+    /**\r
+     * Gets the endpoint.\r
+     *\r
+     * @param ep the ep\r
+     * @param endpoints the endpoints\r
+     * @return the endpoint\r
+     */\r
     public String getEndpoint(Endpoint ep, List<String> endpoints) {\r
         loadLegacy();\r
         endpoints.clear();\r
@@ -82,11 +88,11 @@ public class TmEndpoints {
         if (endpoints.size() > 0) {\r
             // Make an attempt to return the most recent "working" endpoint.\r
             //\r
-            synchronized (endpointMapOK) {\r
-                endpoint = endpointMapOK.get(ep);\r
+            synchronized (endpointMapOk) {\r
+                endpoint = endpointMapOk.get(ep);\r
                 if (endpoint == null) {\r
                     endpoint = endpoints.get(0);\r
-                    endpointMapOK.put(ep, endpoint);\r
+                    endpointMapOk.put(ep, endpoint);\r
                 }\r
             }\r
             endpoints.remove(endpoint);\r
@@ -96,21 +102,29 @@ public class TmEndpoints {
 \r
     // Call this if the previous enpoint failed to connect.\r
     // An attempt to track the most recent "working" endpoint.\r
+    /**\r
+     * Gets the next endpoint.\r
+     *\r
+     * @param ep the ep\r
+     * @param endpoints the endpoints\r
+     * @return the next endpoint\r
+     */\r
     public String getNextEndpoint(Endpoint ep, List<String> endpoints) {\r
         String endpoint = null;\r
         if (endpoints.size() > 0) {\r
             endpoint = endpoints.remove(0);\r
-            synchronized (endpointMapOK) {\r
+            synchronized (endpointMapOk) {\r
                 // Let's hope this one works.\r
-                endpointMapOK.put(ep, endpoint);\r
+                endpointMapOk.put(ep, endpoint);\r
             }\r
         }\r
         return endpoint;\r
     }\r
 \r
     private synchronized void loadLegacy() {\r
-        if (legacyLoaded)\r
+        if (legacyLoaded) {\r
             return;\r
+        }\r
         log.info("Loading legacy endpoints");\r
         endpointMap = new HashMap<>();\r
         addToEndpointMap(Endpoint.CREATE);\r
@@ -128,6 +142,7 @@ public class TmEndpoints {
         list.add(env.getProperty(ep.toString()));\r
     }\r
 \r
+    @Override\r
     public String toString() {\r
         return endpointMap.toString();\r
     }\r