aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRamaPrasad Amaranarayana (ra5425) <ra5425@att.com>2018-09-19 18:39:39 -0400
committerRamaPrasad Amaranarayana (ra5425) <ra5425@att.com>2018-09-19 18:39:39 -0400
commitf88bb867f7d6c1a5483b67e4e595d382f3e8351b (patch)
tree131f318998b9921555d2dce3f049e6ad69cd607f
parentc47d835762dfd4423ab77d3c525a2c541af6b36e (diff)
Change Management Schedule Optimization
Adding CMSO Service Code for Change Management Schedule Optimization Change-Id: I83f029c02d990ce607493bf1c008b24a70e804c2 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/service/rs/AdminTool.java66
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminToolImpl.java66
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/BaseSchedulerServiceImpl.java226
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSCallbackImpl.java268
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOService.java206
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java743
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java68
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmQueryParameters.java230
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheck.java69
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheckImpl.java121
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ApprovalMessage.java106
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CMSInfo.java119
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CMSMessage.java73
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ChangeWindowMessage.java80
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CmDetailsMessage.java67
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CmDomainDataEnum.java46
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/HealthCheckComponent.java92
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/HealthCheckMessage.java108
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ScheduleMessage.java124
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/VnfDetailsMessage.java92
20 files changed, 2970 insertions, 0 deletions
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminTool.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminTool.java
new file mode 100644
index 0000000..801986c
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminTool.java
@@ -0,0 +1,66 @@
+/*
+ * 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.service.rs;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+@Api
+@Path("/{apiVersion}")
+@Produces({MediaType.APPLICATION_JSON})
+public interface AdminTool {
+
+ // ******************************************************************
+ @GET
+ @Path("/admin/{id}")
+ @Produces({MediaType.TEXT_PLAIN})
+ @ApiOperation(value = "", notes = "Returns encrypted value of id.", response = String.class)
+ @ApiResponses(
+ value = {@ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 400, message = "Request failed")})
+ public Response exec(@ApiParam(value = "v1|v2") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+ @ApiParam(value = "Identifier", allowMultiple = true) @PathParam("id") String id, @Context UriInfo uri,
+ @Context HttpServletRequest request);
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminToolImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminToolImpl.java
new file mode 100644
index 0000000..9f1a4d5
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminToolImpl.java
@@ -0,0 +1,66 @@
+/*
+ * 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.service.rs;
+
+import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.onap.optf.cmso.common.Mdc;
+import org.onap.optf.cmso.common.PropertiesManagement;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+@Controller
+public class AdminToolImpl implements AdminTool {
+ private static EELFLogger log = EELFManager.getInstance().getLogger(AdminToolImpl.class);
+ private static EELFLogger audit = EELFManager.getInstance().getAuditLogger();
+
+ @Autowired
+ PropertiesManagement pm;
+
+ @Override
+ public Response exec(String apiVersion, String id, UriInfo uri, HttpServletRequest request) {
+ Mdc.begin(request, UUID.randomUUID().toString());
+ log.info("AdminTool.exec entered");
+ if (id.length() < 4)
+ return Response.ok("").build();
+ String encrypted = pm.getEncryptedValue(id);
+ Response response = Response.ok(encrypted).build();
+ Mdc.end(response);
+ audit.info("AdminTool");
+ return response;
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/BaseSchedulerServiceImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/BaseSchedulerServiceImpl.java
new file mode 100644
index 0000000..8dbafbc
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/BaseSchedulerServiceImpl.java
@@ -0,0 +1,226 @@
+/*
+ * 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.service.rs;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.ws.rs.core.Response.Status;
+import org.onap.optf.cmso.common.ApprovalStatusEnum;
+import org.onap.optf.cmso.common.CMSStatusEnum;
+import org.onap.optf.cmso.common.LogMessages;
+import org.onap.optf.cmso.common.exceptions.CMSAlreadyExistsException;
+import org.onap.optf.cmso.common.exceptions.CMSException;
+import org.onap.optf.cmso.common.exceptions.CMSNotFoundException;
+import org.onap.optf.cmso.model.ApprovalType;
+import org.onap.optf.cmso.model.DomainData;
+import org.onap.optf.cmso.model.Schedule;
+import org.onap.optf.cmso.model.ScheduleApproval;
+import org.onap.optf.cmso.model.dao.ApprovalTypeDAO;
+import org.onap.optf.cmso.model.dao.DomainDataDAO;
+import org.onap.optf.cmso.model.dao.ScheduleApprovalDAO;
+import org.onap.optf.cmso.model.dao.ScheduleDAO;
+import org.onap.optf.cmso.service.rs.models.ApprovalMessage;
+import org.onap.optf.cmso.service.rs.models.ScheduleMessage;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+@Controller
+public class BaseSchedulerServiceImpl {
+ private static EELFLogger log = EELFManager.getInstance().getLogger(BaseSchedulerServiceImpl.class);
+
+ @Autowired
+ protected ScheduleDAO scheduleDAO;
+
+ @Autowired
+ DomainDataDAO domainDataDAO;
+
+ @Autowired
+ ApprovalTypeDAO approvalTypeDAO;
+
+ @Autowired
+ ScheduleApprovalDAO scheduleApprovalDAO;
+
+ protected Schedule validateAndAddScheduleRequest(ScheduleMessage scheduleMessage, List<DomainData> domainData)
+ throws CMSException {
+ messageValidations(scheduleMessage);
+ Schedule s = scheduleDAO.findByDomainScheduleID(scheduleMessage.getDomain(), scheduleMessage.getScheduleId());
+
+ if (s != null) {
+ throw new CMSAlreadyExistsException(scheduleMessage.getDomain(), scheduleMessage.getScheduleId());
+ }
+ s = new Schedule();
+ s.setUserId(scheduleMessage.getUserId());
+ s.setCreateDateTimeMillis(System.currentTimeMillis());
+ s.setDomain(scheduleMessage.getDomain());
+ s.setScheduleId(scheduleMessage.getScheduleId());
+ s.setOptimizerTransactionId(s.getScheduleId()); // No reason these cannot be the same as
+ // these
+ // are 1<=>1 at this
+ // point.
+ s.setScheduleName(scheduleMessage.getScheduleName());
+ s.setScheduleInfo(scheduleMessage.getSchedulingInfo().toString());
+ s.setStatus(CMSStatusEnum.PendingSchedule.toString());
+ scheduleDAO.save(s);
+ for (DomainData dd : domainData) {
+ s.addDomainData(dd);
+ domainDataDAO.save(dd);
+ }
+ scheduleDAO.save(s);
+ return s;
+ }
+
+ private void messageValidations(ScheduleMessage scheduleMessage) throws CMSException {
+ if (scheduleMessage.getScheduleName() == null || scheduleMessage.getScheduleName().equals("")) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE, "schedulerName", "");
+ }
+ if (scheduleMessage.getUserId() == null || scheduleMessage.getUserId().equals("")) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE, "userId", "");
+ }
+ }
+
+ protected void deleteScheduleRequest(String domain, String scheduleId) throws CMSException {
+ Schedule s = scheduleDAO.findByDomainScheduleID(domain, scheduleId);
+ if (s == null) {
+ throw new CMSNotFoundException(domain, scheduleId);
+ }
+ CMSStatusEnum currentStatus = CMSStatusEnum.Completed.fromString(s.getStatus());
+ s.setDeleteDateTimeMillis(System.currentTimeMillis());
+ switch (currentStatus) {
+ case Scheduled:
+ // TODO CLose all tickets....
+ s.setStatus(CMSStatusEnum.Cancelled.toString());
+ break;
+ case NotificationsInitiated:
+ throw new CMSException(Status.NOT_ACCEPTABLE, LogMessages.CANNOT_CANCEL_IN_PROGRESS);
+ default:
+ s.setStatus(CMSStatusEnum.Deleted.toString());
+ }
+ scheduleDAO.save(s);
+ }
+
+ protected Schedule processApproval(Schedule s, String domain, ApprovalMessage approvalMessage) throws CMSException {
+ String scheduleId = s.getScheduleId();
+ ApprovalType approvalType =
+ approvalTypeDAO.findByDomainAndType(domain, approvalMessage.getApprovalType().toString());
+ if (approvalType == null) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "approvalType",
+ approvalMessage.getApprovalType().toString());
+ }
+
+ if (!s.getStatus().equals(CMSStatusEnum.PendingApproval.toString())) {
+ throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.NOT_PENDING_APPROVAL, domain, scheduleId,
+ s.getStatus());
+ }
+ if (approvalMessage.getApprovalUserId() == null || approvalMessage.getApprovalUserId().equals("")) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE, "userId");
+ }
+ ScheduleApproval sa = null;
+ // only 1 approval per user....
+ if (s.getScheduleApprovals() != null) {
+ for (ScheduleApproval scheduleApproval : s.getScheduleApprovals()) {
+ if (scheduleApproval.getUserId().equals(approvalMessage.getApprovalUserId())
+ && scheduleApproval.getApprovalTypeId().equals(approvalType.getId())) {
+ sa = scheduleApproval;
+ }
+ }
+ }
+ if (sa == null) {
+ sa = new ScheduleApproval();
+ sa.setSchedule(s);
+ sa.setApprovalTypeId(approvalType.getId());
+ sa.setUserId(approvalMessage.getApprovalUserId());
+ }
+ // Ignore what time is on the message
+ sa.setApprovalDateTimeMillis(System.currentTimeMillis());
+ sa.setStatus(approvalMessage.getApprovalStatus().toString());
+ sa.setSchedule(s);
+ s.addScheduleApproval(sa);
+ scheduleDAO.save(s);
+ if (sa.getStatus().equals(ApprovalStatusEnum.Rejected.toString())) {
+ s.setStatus(CMSStatusEnum.Rejected.toString());
+ } else {
+ if (allApprovalsReceived(s, sa))
+ s.setStatus(CMSStatusEnum.Accepted.toString());
+ }
+ scheduleDAO.save(s);
+ return s;
+ }
+
+ private boolean allApprovalsReceived(Schedule schedule, ScheduleApproval sa) {
+ Map<Integer, Integer> requiredApprovalsByType = new HashMap<Integer, Integer>(); // Approval
+ // countdown
+ Map<Integer, ApprovalType> approvalsByType = new HashMap<Integer, ApprovalType>(); // Just
+ // for
+ // logging
+
+ List<ApprovalType> approvalTypes = approvalTypeDAO.findByDomain(schedule.getDomain());
+ for (ApprovalType at : approvalTypes) {
+ Integer type = at.getId();
+ Integer count = at.getApprovalCount();
+ requiredApprovalsByType.put(type, count);
+ approvalsByType.put(at.getId(), at);
+ }
+
+ // Account for approvals so far
+ List<ScheduleApproval> existingApprovals = schedule.getScheduleApprovals();
+ if (existingApprovals == null) {
+ // This is necessary when doing automatic approvals because
+ // the schedule will not return the approvals here
+ existingApprovals = new ArrayList<ScheduleApproval>();
+ existingApprovals.add(sa);
+ }
+ for (ScheduleApproval approval : existingApprovals) {
+ if (approval.getStatus().equals(ApprovalStatusEnum.Accepted.toString())) {
+ Integer remaining = requiredApprovalsByType.get(approval.getApprovalTypeId());
+ if (remaining != null) {
+ remaining = remaining - 1;
+ requiredApprovalsByType.put(approval.getApprovalTypeId(), remaining);
+ } else {
+ log.warn("Ignored Unidentified approval type {0} for domain {1}", approval.getApprovalTypeId(),
+ schedule.getDomain());
+ }
+ }
+ }
+ for (Integer id : requiredApprovalsByType.keySet()) {
+ Integer remaining = requiredApprovalsByType.get(id);
+ if (remaining > 0) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSCallbackImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSCallbackImpl.java
new file mode 100644
index 0000000..9fb8a96
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSCallbackImpl.java
@@ -0,0 +1,268 @@
+/*
+ * 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.service.rs;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.transaction.Transactional;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
+import org.joda.time.DateTime;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.ISODateTimeFormat;
+import org.onap.optf.cmso.common.CMSStatusEnum;
+import org.onap.optf.cmso.common.DomainsEnum;
+import org.onap.optf.cmso.common.LogMessages;
+import org.onap.optf.cmso.common.Mdc;
+import org.onap.optf.cmso.common.exceptions.CMSException;
+import org.onap.optf.cmso.common.exceptions.CMSNotFoundException;
+import org.onap.optf.cmso.model.ChangeManagementGroup;
+import org.onap.optf.cmso.model.ChangeManagementSchedule;
+import org.onap.optf.cmso.model.Schedule;
+import org.onap.optf.cmso.model.dao.ChangeManagementChangeWindowDAO;
+import org.onap.optf.cmso.model.dao.ChangeManagementDetailDAO;
+import org.onap.optf.cmso.model.dao.ChangeManagementGroupDAO;
+import org.onap.optf.cmso.model.dao.ChangeManagementScheduleDAO;
+import org.onap.optf.cmso.optimizer.bean.CMOptimizerResponse;
+import org.onap.optf.cmso.optimizer.bean.CMSchedule;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@Controller
+public class CMSCallbackImpl extends BaseSchedulerServiceImpl implements CMSOptimizerCallback {
+ private static EELFLogger log = EELFManager.getInstance().getLogger(CMSCallbackImpl.class);
+ private static EELFLogger metrics = EELFManager.getInstance().getMetricsLogger();
+ private static EELFLogger audit = EELFManager.getInstance().getAuditLogger();
+ private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
+ private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();
+
+ @Autowired
+ ChangeManagementScheduleDAO cmScheduleDAO;
+
+ @Autowired
+ ChangeManagementGroupDAO cmGroupDAO;
+
+ @Autowired
+ ChangeManagementChangeWindowDAO cmChangeWindowDAO;
+
+ @Autowired
+ ChangeManagementDetailDAO cmDetailsDAO;
+
+ @Override
+ @Transactional
+ public Response sniroCallback(String apiVersion, CMOptimizerResponse sniroResponse, UriInfo uri,
+ HttpServletRequest request) {
+ Response response = null;
+ Mdc.begin(request, sniroResponse.getTransactionId());
+ log.info(LogMessages.PROCESS_OPTIMIZER_CALLBACK, "Received", request.getRemoteAddr(), "");
+ log.info(LogMessages.OPTIMIZER_REQUEST, "Callback received", sniroResponse.getTransactionId(),
+ uri.getAbsolutePath().toString());
+ try {
+ // Note that transaction ID and schedule ID are currently the same value.
+
+ String transactionId = sniroResponse.getTransactionId();
+
+ // Synchronize this with transaction that scheduled the SNIRO optimization
+ // to ensure status updates are properly ordered.
+ // This is necessary only in the race condition where SNIRO callback comes
+ // before the SNIRO response is processed and the scheduling transaction is
+ // still in flight.
+ // Note that this may happen in loopback mode, but is not likely to happen with
+ // real SNIRO unless SNIRO changes to be synchronous and the callback comes before
+ // the response.
+ // If this lock times out, the schedule will remain in 'Optimization In
+ // Progress' and never complete.
+ Schedule schedule = scheduleDAO.lockOneByTransactionId(transactionId);
+
+ if (schedule == null) {
+ throw new CMSNotFoundException(DomainsEnum.ChangeManagement.toString(),
+ "(OptimizerTransactionID=" + transactionId + ")");
+
+ }
+ CMSStatusEnum status = CMSStatusEnum.PendingApproval.fromString(schedule.getStatus());
+ debug.debug("Status at time of SNIRO callback is " + status.toString());
+ switch (status) {
+ // PendingSchedule may be a valid status in the cases where SNIRO async call
+ // returns before
+ // We have committed the OptimizationInProgress status
+ // The dispatch logic ensures that we only every dispatch once.
+ case OptimizationInProgress:
+ processSniroResponse(sniroResponse, schedule);
+ scheduleDAO.save(schedule);
+ response = Response.ok().build();
+ break;
+ default:
+ throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.OPTIMIZER_CALLBACK_STATE_ERROR,
+ CMSStatusEnum.OptimizationInProgress.toString(), schedule.getStatus().toString());
+ }
+ } catch (CMSException e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
+ } catch (Exception e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ response = Response.serverError().entity(e.getMessage()).build();
+ } finally {
+ }
+ Mdc.end(response);
+ log.info(LogMessages.OPTIMIZER_REQUEST, "Callback completed", sniroResponse.getTransactionId(),
+ uri.getAbsolutePath().toString());
+ audit.info(LogMessages.PROCESS_OPTIMIZER_CALLBACK, "Returned", request.getRemoteAddr(),
+ response.getStatusInfo().toString());
+ metrics.info(LogMessages.PROCESS_OPTIMIZER_CALLBACK, "Returned", request.getRemoteAddr(),
+ response.getStatusInfo().toString());
+ return response;
+ }
+
+ private void processSniroResponse(CMOptimizerResponse sniroResponse, Schedule schedule) {
+ try {
+ schedule.setOptimizerReturnDateTimeMillis(System.currentTimeMillis());
+ schedule.setOptimizerStatus(sniroResponse.getRequestState());
+ schedule.setOptimizerMessage(sniroResponse.getDescription());
+ String scheduleId = sniroResponse.getScheduleId();
+ ObjectMapper om = new ObjectMapper();
+ CMSchedule[] scheduleArray = sniroResponse.getSchedule();
+ if (scheduleArray != null && scheduleArray.length > 0) {
+ String scheduleString = om.writeValueAsString(scheduleArray);
+ schedule.setSchedule(scheduleString);
+ log.debug("scheduleId={0} schedule={1}", scheduleId, scheduleString);
+ for (CMSchedule sniroSchedule : sniroResponse.getSchedule()) {
+ String groupId = sniroSchedule.getGroupId();
+ DateTime finishTime = convertDate(sniroSchedule.getFinishTime(), "finishTime");
+ DateTime latestInstanceStartTime =
+ convertDate(sniroSchedule.getLatestInstanceStartTime(), "latestInstanceStartTime");
+ DateTime startTime = convertDate(sniroSchedule.getStartTime(), "startTime");
+ ChangeManagementGroup group = cmGroupDAO.findOneBySchedulesIDGroupID(schedule.getId(), groupId);
+ if (group == null) {
+ throw new CMSException(Status.PRECONDITION_FAILED,
+ LogMessages.CHANGE_MANAGEMENT_GROUP_NOT_FOUND, schedule.getScheduleId(), groupId);
+ }
+ group.setStartTimeMillis(startTime.getMillis());
+ group.setFinishTimeMillis(finishTime.getMillis());
+ group.setLastInstanceStartTimeMillis(latestInstanceStartTime.getMillis());
+ cmGroupDAO.save(group);
+ long totalDuration =
+ (group.getAdditionalDurationInSecs() + group.getNormalDurationInSecs()) * 1000l;
+ Map<String, Map<String, Long>> startAndFinishTimeMap = new HashMap<String, Map<String, Long>>();
+ makeMap(startTime.getMillis(), latestInstanceStartTime.getMillis(), group.getConcurrencyLimit(),
+ totalDuration, sniroSchedule.getNode(), startAndFinishTimeMap);
+ for (String node : sniroSchedule.getNode()) {
+ processNode(schedule, group, node, startAndFinishTimeMap);
+ }
+ }
+ schedule.setStatus(CMSStatusEnum.PendingApproval.toString());
+ } else {
+ debug.debug("scheduleId={0} schedule=null status={1} ", scheduleId, schedule.getOptimizerStatus());
+ schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
+ }
+ } catch (CMSException e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
+ schedule.setOptimizerStatus(e.getStatus().toString());
+ schedule.setOptimizerMessage(e.getLocalizedMessage());
+ } catch (Exception e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
+ schedule.setOptimizerStatus("Exception");
+ schedule.setOptimizerMessage(e.getLocalizedMessage());
+ }
+ }
+
+ public static void makeMap(Long startTime, Long latestInstanceStartTime, int concurrencyLimit, long totalDuration,
+ List<String> nodes, Map<String, Map<String, Long>> startAndFinishTimeMap) throws CMSException {
+ Long nextStartTime = null;
+ Long nextFinishTime = null;
+ for (int nodeNumber = 0; nodeNumber < nodes.size(); nodeNumber++) {
+ String node = nodes.get(nodeNumber);
+ if (nodeNumber % concurrencyLimit == 0) {
+ if (nodeNumber == 0)
+ nextStartTime = startTime;
+ else
+ nextStartTime = nextStartTime + totalDuration;
+ if (nextStartTime > latestInstanceStartTime) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.UNABLE_TO_ALLOCATE_VNF_TIMESLOTS,
+ startTime.toString(), latestInstanceStartTime.toString(), String.valueOf(totalDuration),
+ String.valueOf(concurrencyLimit), String.valueOf(nodes.size()));
+ }
+ nextFinishTime = nextStartTime + totalDuration;
+ }
+ Map<String, Long> map = new HashMap<String, Long>();
+ map.put("startTime", nextStartTime);
+ map.put("finishTime", nextFinishTime);
+ startAndFinishTimeMap.put(node, map);
+ }
+
+ }
+
+ private void processNode(Schedule schedule, ChangeManagementGroup group, String node,
+ Map<String, Map<String, Long>> startAndFinishTimeMap) throws CMSException {
+ Map<String, Long> map = startAndFinishTimeMap.get(node);
+ ChangeManagementSchedule detail = cmScheduleDAO.findOneByGroupIDAndVnfName(group.getId(), node);
+ if (detail == null) {
+ throw new CMSException(Status.NOT_FOUND, LogMessages.UNABLE_TO_LOCATE_SCHEDULE_DETAIL,
+ schedule.getScheduleId(), group.getGroupId(), node);
+ }
+ detail.setStartTimeMillis(map.get("startTime"));
+ detail.setFinishTimeMillis(map.get("finishTime"));
+ detail.setVnfId("");
+ detail.setStatus(CMSStatusEnum.PendingApproval.toString());
+ cmScheduleDAO.save(detail);
+ }
+
+ public static DateTime convertDate(String utcDate, String attrName) throws CMSException {
+ try {
+ DateTime dateTime = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZoneUTC().parseDateTime(utcDate);
+ if (dateTime != null)
+ return dateTime;
+ } catch (Exception e) {
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, attrName, utcDate);
+ }
+
+ public static DateTime convertISODate(String utcDate, String attrName) throws CMSException {
+ try {
+ DateTime dateTime = ISODateTimeFormat.dateTimeParser().parseDateTime(utcDate);
+ if (dateTime != null)
+ return dateTime;
+ } catch (Exception e) {
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, attrName, utcDate);
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOService.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOService.java
new file mode 100644
index 0000000..97bb78e
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOService.java
@@ -0,0 +1,206 @@
+/*
+ * 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.service.rs;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.onap.optf.cmso.common.CMSRequestError;
+import org.onap.optf.cmso.model.Schedule;
+import org.onap.optf.cmso.service.rs.models.ApprovalMessage;
+import org.onap.optf.cmso.service.rs.models.CMSMessage;
+import org.onap.optf.cmso.service.rs.models.CmDetailsMessage;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+@Api
+@Path("/{apiVersion}")
+@Produces({MediaType.APPLICATION_JSON})
+public interface CMSOService {
+ // ******************************************************************
+ @GET
+ @Path("/schedules")
+ @Produces({MediaType.APPLICATION_JSON})
+ @ApiOperation(value = "", notes = "Returns a list of Scheduler Requests based upon the filter criteria.",
+ response = Schedule.class, responseContainer = "List")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"),
+ @ApiResponse(code = 404, message = "No records found", response = CMSRequestError.class),
+ @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})
+ public Response searchScheduleRequests(
+ @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+ @DefaultValue(value = "false") @ApiParam(
+ value = "Include details") @QueryParam("includeDetails") Boolean includeDetails,
+ @ApiParam(value = "Schedule identifier", allowMultiple = true) @QueryParam("scheduleId") String scheduleId,
+ @ApiParam(value = "Schedule name", allowMultiple = true) @QueryParam("scheduleName") String scheduleName,
+ @ApiParam(value = "SCheduler creator User id of ",
+ allowMultiple = true) @QueryParam("userId") String userId,
+ @ApiParam(value = "Schedule status", allowMultiple = true) @QueryParam("status") String status,
+ @ApiParam(value = "Creation date and time (<low date>[,<hi date>])",
+ allowMultiple = true) @QueryParam("createDateTime") String createDateTime,
+ @ApiParam(value = "Optimizer status",
+ allowMultiple = true) @QueryParam("optimizerStatus") String optimizerStatus,
+ @ApiParam(value = "Workflow", allowMultiple = true) @QueryParam("WorkflowName") String workflowName,
+ @Context UriInfo uri, @Context HttpServletRequest request);
+
+ // ******************************************************************
+ @POST
+ @Path("/schedules/{scheduleId}")
+ @Produces({MediaType.APPLICATION_JSON})
+ @ApiOperation(value = "", notes = "Creates a schedule request for scheduleId")
+ @ApiResponses(
+ value = {@ApiResponse(code = 202, message = "Schedule request accepted for optimization."),
+ @ApiResponse(code = 409, message = "Schedule request already exists for this schedule id.",
+ response = CMSRequestError.class),
+ @ApiResponse(code = 500, message = "Unexpected Runtime error")})
+ public Response createScheduleRequest(
+ @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+ @ApiParam(
+ value = "Schedule id to uniquely identify the schedule request being created.") @PathParam("scheduleId") String scheduleId,
+ @ApiParam(
+ value = "Data for creating a schedule request for the given schedule id") CMSMessage scheduleMessage,
+ @Context HttpServletRequest request);
+
+ // ******************************************************************
+ @DELETE
+ @Path("/schedules/{scheduleId}")
+ @Produces({MediaType.APPLICATION_JSON})
+ @ApiOperation(value = "", notes = "Cancels the schedule request for scheduleId")
+ @ApiResponses(value = {@ApiResponse(code = 204, message = "Delete successful"),
+ @ApiResponse(code = 404, message = "No record found", response = CMSRequestError.class),
+ @ApiResponse(code = 500, message = "Unexpected Runtime error")})
+ public Response deleteScheduleRequest(
+ @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+ @ApiParam(
+ value = "Schedule id to uniquely identify the schedule request being deleted.") @PathParam("scheduleId") String scheduleId,
+ @Context HttpServletRequest request);
+
+ // ******************************************************************
+ @GET
+ @Path("/schedules/{scheduleId}")
+ @Produces({MediaType.APPLICATION_JSON})
+ @ApiOperation(value = "", notes = "Retrieve the schedule request for scheduleId", response = Schedule.class)
+ @ApiResponses(
+ value = {@ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "No record found"),
+ @ApiResponse(code = 500, message = "Unexpected Runtime error")})
+ public Response getScheduleRequestInfo(
+ @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+ @ApiParam(
+ value = "Schedule id to uniquely identify the schedule info being retrieved.") @PathParam("scheduleId") String scheduleId,
+ @Context HttpServletRequest request);
+
+ // ******************************************************************
+ @POST
+ @Path("/schedules/{scheduleId}/approvals")
+ @Produces({MediaType.APPLICATION_JSON})
+ @ApiOperation(value = "",
+ notes = "Adds an accept/reject approval status to the schedule request identified by scheduleId")
+ @ApiResponses(
+ value = {@ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 404, message = "No record found"),
+ @ApiResponse(code = 500, message = "Unexpected Runtime error")})
+ public Response approveScheduleRequest(
+ @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+ @ApiParam(
+ value = "Schedule id to uniquely identify the schedule request being accepted or rejected.") @PathParam("scheduleId") String scheduleId,
+ @ApiParam(value = "Accept or reject approval message") ApprovalMessage approval,
+ @Context HttpServletRequest request);
+
+ // ******************************************************************
+ @GET
+ @Path("/schedules/scheduleDetails")
+ @Produces({MediaType.APPLICATION_JSON})
+ @ApiOperation(value = "", notes = "Returns a list of Schedule request details based upon the filter criteria.",
+ response = CmDetailsMessage.class, responseContainer = "List")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"),
+ @ApiResponse(code = 404, message = "No records found", response = CMSRequestError.class),
+ @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})
+ public Response searchScheduleRequestDetails(
+ @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+ @ApiParam(value = "Schedule identifier",
+ allowMultiple = true) @QueryParam("request.scheduleId") String scheduleId,
+ @ApiParam(value = "Schedule name",
+ allowMultiple = true) @QueryParam("request.scheduleName") String scheduleName,
+ @ApiParam(value = "Scheduler creator User id of ",
+ allowMultiple = true) @QueryParam("request.userId") String userId,
+ @ApiParam(value = "Schedule status", allowMultiple = true) @QueryParam("request.status") String status,
+ @ApiParam(value = "Creation date and time (<low date>[,<hi date>])",
+ allowMultiple = true) @QueryParam("request.createDateTime") String createDateTime,
+ @ApiParam(value = "Optimizer status",
+ allowMultiple = true) @QueryParam("request.optimizerStatus") String optimizerStatus,
+ @ApiParam(value = "Request Approval user id",
+ allowMultiple = true) @QueryParam("request.approvalUserId") String requestApprovalUserId,
+ @ApiParam(value = "Request Approval status",
+ allowMultiple = true) @QueryParam("request.approvalStatus") String requestApprovalStatus,
+ @ApiParam(value = "Request Approval type",
+ allowMultiple = true) @QueryParam("request.approvalType") String requestApprovalType,
+ @ApiParam(value = "Workflow", allowMultiple = true) @QueryParam("WorkflowName") String workflowName,
+ @ApiParam(value = "VNF Name", allowMultiple = true) @QueryParam("vnfName") String vnfName,
+ @ApiParam(value = "VNF Id", allowMultiple = true) @QueryParam("vnfId") String vnfId,
+ @ApiParam(value = "VNF Status", allowMultiple = true) @QueryParam("vnfStatus") String vnfStatus,
+ // @ApiParam(value="VNF Schedule Id", allowMultiple=true) @QueryParam("vnfScheduleId")
+ // String
+ // vnfScheduleId,
+ @ApiParam(value = "Start time <low>,<high>",
+ allowMultiple = true) @QueryParam("startTime") String startTime,
+ @ApiParam(value = "Finish time <low>,<high>",
+ allowMultiple = true) @QueryParam("finishTime") String finishTime,
+ @ApiParam(value = "Last instance start time <low>,<high>",
+ allowMultiple = true) @QueryParam("lastInstanceTime") String lastInstanceTime,
+ @ApiParam(value = "TM Change Ticket Change Id",
+ allowMultiple = true) @QueryParam("tmChangeId") String tmChangeId,
+ // @ApiParam(value="Approval user id", allowMultiple=true) @QueryParam("approvalUserId")
+ // String approvalUserId,
+ // @ApiParam(value="Approval status", allowMultiple=true) @QueryParam("approvalStatus")
+ // String
+ // approvalStatus,
+ // @ApiParam(value="Approval type", allowMultiple=true) @QueryParam("approvalType")
+ // String
+ // approvalType,
+ @ApiParam(value = "Maximum number of schedules to return") @QueryParam("maxSchedules") Integer maxSchedules,
+ @ApiParam(value = "Return schedules > lastScheduleId") @QueryParam("lastScheduleId") String lastScheduleId,
+ @ApiParam(
+ value = "Return concurrencyLimit") @QueryParam("request.concurrencyLimit") Integer concurrencyLimit,
+ @Context UriInfo uri, @Context HttpServletRequest request);
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java
new file mode 100644
index 0000000..26d0fe5
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java
@@ -0,0 +1,743 @@
+/*
+ * 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.service.rs;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TimeZone;
+import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
+import org.joda.time.DateTime;
+import org.onap.optf.cmso.common.ApprovalStatusEnum;
+import org.onap.optf.cmso.common.ApprovalTypesEnum;
+import org.onap.optf.cmso.common.CMSStatusEnum;
+import org.onap.optf.cmso.common.DomainsEnum;
+import org.onap.optf.cmso.common.LogMessages;
+import org.onap.optf.cmso.common.Mdc;
+import org.onap.optf.cmso.common.exceptions.CMSException;
+import org.onap.optf.cmso.common.exceptions.CMSNotFoundException;
+import org.onap.optf.cmso.eventq.CMSQueueJob;
+import org.onap.optf.cmso.model.ChangeManagementChangeWindow;
+import org.onap.optf.cmso.model.ChangeManagementDetail;
+import org.onap.optf.cmso.model.ChangeManagementGroup;
+import org.onap.optf.cmso.model.ChangeManagementSchedule;
+import org.onap.optf.cmso.model.DomainData;
+import org.onap.optf.cmso.model.Schedule;
+import org.onap.optf.cmso.model.ScheduleQuery;
+import org.onap.optf.cmso.model.dao.ChangeManagementChangeWindowDAO;
+import org.onap.optf.cmso.model.dao.ChangeManagementDetailDAO;
+import org.onap.optf.cmso.model.dao.ChangeManagementGroupDAO;
+import org.onap.optf.cmso.model.dao.ChangeManagementScheduleDAO;
+import org.onap.optf.cmso.model.dao.ScheduleDAO;
+import org.onap.optf.cmso.model.dao.ScheduleQueryDAO;
+import org.onap.optf.cmso.service.rs.models.ApprovalMessage;
+import org.onap.optf.cmso.service.rs.models.CMSInfo;
+import org.onap.optf.cmso.service.rs.models.CMSMessage;
+import org.onap.optf.cmso.service.rs.models.ChangeWindowMessage;
+import org.onap.optf.cmso.service.rs.models.CmDetailsMessage;
+import org.onap.optf.cmso.service.rs.models.CmDomainDataEnum;
+import org.onap.optf.cmso.service.rs.models.VnfDetailsMessage;
+import org.onap.optf.cmso.ticketmgt.TmClient;
+import org.onap.optf.cmso.ticketmgt.bean.BuildCreateRequest;
+import org.onap.optf.cmso.ticketmgt.bean.TmApprovalStatusEnum;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Controller;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+@Controller
+public class CMSOServiceImpl extends BaseSchedulerServiceImpl implements CMSOService {
+ private static EELFLogger log = EELFManager.getInstance().getLogger(CMSOServiceImpl.class);
+ private static EELFLogger metrics = EELFManager.getInstance().getMetricsLogger();
+ private static EELFLogger audit = EELFManager.getInstance().getAuditLogger();
+ private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();
+ private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
+
+ @Autowired
+ CMSQueueJob qJob;
+
+ @Autowired
+ Environment env;
+
+ @Autowired
+ ChangeManagementScheduleDAO cmScheduleDAO;
+
+ @Autowired
+ ChangeManagementGroupDAO cmGroupDAO;
+
+ @Autowired
+ ChangeManagementChangeWindowDAO cmChangeWindowDAO;
+
+ @Autowired
+ ChangeManagementDetailDAO cmDetailsDAO;
+
+ @Autowired
+ ScheduleQueryDAO scheduleQueryDAO;
+
+ @Autowired
+ ScheduleDAO scheduleDAO;
+
+ @Autowired
+ TmClient tmClient;
+
+ @Autowired
+ BuildCreateRequest buildCreateRequest;
+
+ @Override
+ public Response searchScheduleRequests(String apiVersion, Boolean includeDetails, String scheduleId,
+ String scheduleName, String userId, String status, String createDateTime, String optimizerStatus,
+ String workflowName, UriInfo uri, HttpServletRequest request) {
+
+ Mdc.begin(request, UUID.randomUUID().toString());
+ log.info(LogMessages.SEARCH_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), uri.toString(), "");
+ Response response = null;
+ List<Schedule> schedules = new ArrayList<Schedule>();
+ try {
+ log.info("Timezone=" + TimeZone.getDefault());
+ MultivaluedMap<String, String> qp = uri.getQueryParameters();
+ StringBuilder where = new StringBuilder();
+ int maxRows = 0;
+ // buildWhere(qp, where);
+ List<ScheduleQuery> list = scheduleQueryDAO.searchSchedules(where.toString(), maxRows);
+ if (list == null || !list.iterator().hasNext()) {
+ throw new CMSException(Status.NOT_FOUND, LogMessages.SCHEDULE_NOT_FOUND,
+ DomainsEnum.ChangeManagement.toString(), scheduleId);
+ }
+ Iterator<ScheduleQuery> iter = list.iterator();
+ while (iter.hasNext()) {
+ Schedule s = scheduleDAO.findById(iter.next().getId()).orElse(null);
+ if (s != null) {
+ schedules.add(s);
+ if (includeDetails) {
+ List<ChangeManagementGroup> groups = cmGroupDAO.findBySchedulesID(s.getId());
+ s.setGroups(groups);
+ for (ChangeManagementGroup g : groups) {
+ List<ChangeManagementSchedule> cmSchedules =
+ cmScheduleDAO.findByChangeManagementGroupId(g.getId());
+ g.setChangeManagementSchedules(cmSchedules);
+ }
+ }
+ }
+ }
+ response = Response.ok(schedules.toArray(new Schedule[schedules.size()])).build();
+ } catch (CMSException e) {
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ log.info(e.getMessage());
+ response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
+ } catch (Exception e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ response = Response.serverError().build();
+ }
+
+ Mdc.end(response);
+ log.info(LogMessages.SEARCH_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), schedules.toString(),
+ response.getStatusInfo().toString());
+ audit.info(LogMessages.SEARCH_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), schedules.toString(),
+ response.getStatusInfo().toString());
+ metrics.info(LogMessages.SEARCH_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), schedules.toString(),
+ response.getStatusInfo().toString());
+ return response;
+ }
+
+ @Override
+ @Transactional
+ public Response createScheduleRequest(String apiVersion, String scheduleId, CMSMessage scheduleMessage,
+ HttpServletRequest request) {
+ Mdc.begin(request, scheduleId);
+ log.info(LogMessages.CREATE_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), scheduleId,
+ scheduleMessage.toString());
+ Response response = null;
+ try {
+ if (!scheduleMessage.getDomain().equals(DomainsEnum.ChangeManagement.toString())) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "domain",
+ scheduleMessage.getDomain());
+ }
+ if (scheduleMessage.getScheduleId() == null || !scheduleMessage.getScheduleId().equals(scheduleId)) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "schedulerId",
+ scheduleMessage.getScheduleId());
+ }
+ // Force the name to be = to the ID because there is no way fot the provide a
+ // name
+ scheduleMessage.setScheduleName(scheduleMessage.getScheduleId());
+
+ List<DomainData> domainData = validateDomainData(scheduleMessage);
+ boolean immediate = validate(scheduleMessage);
+ Schedule schedule = validateAndAddScheduleRequest(scheduleMessage, domainData);
+ if (immediate) {
+ createChangeManagementImmediate(schedule, scheduleMessage);
+
+ // *******************************************************************************************
+ // This flush does nothing because JPA is expecting
+ // JtaTransactionCoordinatorImpl
+ // rather than
+ // JdbcResourceLocalTransactionCoordinatorImpl
+ // (it does an instance of and JdbcResourceLocalTransactionCoordinatorImpl
+ // fails)
+ // SO the automatic approval and creation of tickets cannot
+ // rely retrieving the entities from the Schedule entity as the SQL has not yet
+ // executed.
+ // Under future flow, they can because the data is committed in a separate
+ // transaction
+ // Three choices
+ // 1. Pass domainData through all of the methods. ***
+ // 2. Re-structre the code to have @Transactionals which would break the top
+ // level rollback strategy
+ // 3. Debug JPA (Still worth doing, maybe some kind of goofy parameter.)
+ TransactionAspectSupport.currentTransactionStatus().flush();
+
+ // Create automatic approval
+ ApprovalMessage am = new ApprovalMessage();
+ am.setApprovalStatus(ApprovalStatusEnum.Accepted);
+ am.setApprovalType(ApprovalTypesEnum.Tier2);
+ am.setApprovalUserId(schedule.getUserId());
+ processApproveScheduleRequest(schedule, am, domainData);
+
+ } else {
+ createChangeManagement(schedule, scheduleMessage);
+ }
+ response = Response.accepted().build();
+ } catch (CMSException e) {
+ debug.debug(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ log.info(e.getMessage());
+ response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
+ Mdc.end(response);
+ audit.info(LogMessages.CREATE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId, "");
+ } catch (Exception e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ response = Response.serverError().build();
+ Mdc.end(response);
+ audit.info(LogMessages.CREATE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId, "");
+ }
+ Mdc.end(response);
+ log.info(LogMessages.CREATE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ audit.info(LogMessages.CREATE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ metrics.info(LogMessages.CREATE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ return response;
+ }
+
+ /**
+ * Returns whether this is an immediate request
+ */
+ private boolean validate(CMSMessage scheduleMessage) throws CMSException {
+ Set<String> groups = new HashSet<String>();
+ CMSInfo info = scheduleMessage.getSchedulingInfo();
+ if (info == null) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.UNABLE_TO_PARSE_SCHEDULING_INFO);
+ }
+
+ if (scheduleMessage.getSchedulingInfo().getAdditionalDurationInSeconds() == null)
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,
+ "additionalDurationInSeconds");
+ if (scheduleMessage.getSchedulingInfo().getNormalDurationInSeconds() == null)
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,
+ "normalDurationInSeconds");
+ if (scheduleMessage.getSchedulingInfo().getAdditionalDurationInSeconds() < 0)
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "additionalDurationInSeconds",
+ scheduleMessage.getSchedulingInfo().getAdditionalDurationInSeconds().toString());
+ if (scheduleMessage.getSchedulingInfo().getNormalDurationInSeconds() < 1)
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "normalDurationInSeconds",
+ scheduleMessage.getSchedulingInfo().getNormalDurationInSeconds().toString());
+ try {
+ for (VnfDetailsMessage vnfDetail : scheduleMessage.getSchedulingInfo().getVnfDetails()) {
+ if (vnfDetail.getChangeWindow() != null && vnfDetail.getChangeWindow().size() > 0) {
+ if (vnfDetail.getNode().size() == 0) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE, "node list");
+ }
+ for (String node : vnfDetail.getNode()) {
+ if (node.equals(""))
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.NODE_LIST_CONTAINS_EMTPY_NODE);
+ }
+ for (ChangeWindowMessage cw : vnfDetail.getChangeWindow()) {
+ if (cw.getStartTime() == null || cw.getStartTime().equals(""))
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,
+ "startTime");
+ if (cw.getEndTime() == null || cw.getEndTime().equals(""))
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,
+ "endTime");
+ DateTime start = CMSCallbackImpl.convertISODate(cw.getStartTime(), "startTime");
+ DateTime end = CMSCallbackImpl.convertISODate(cw.getEndTime(), "endTime");
+ if (!end.isAfter(start))
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_CHANGE_WINDOW,
+ cw.getStartTime(), cw.getEndTime());
+ }
+ if (scheduleMessage.getSchedulingInfo().getConcurrencyLimit() == null)
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,
+ "concurrencyLimit");
+ if (scheduleMessage.getSchedulingInfo().getConcurrencyLimit() < 1)
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "concurrencyLimit",
+ scheduleMessage.getSchedulingInfo().getConcurrencyLimit().toString());
+ if (scheduleMessage.getSchedulingInfo().getPolicyId() == null
+ || scheduleMessage.getSchedulingInfo().getPolicyId().equals(""))
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE, "policyId");
+ return false;
+ }
+ if (vnfDetail.getGroupId() == null || vnfDetail.getGroupId().equals(""))
+ groups.add("default");
+ else
+ groups.add(vnfDetail.getGroupId());
+ }
+ } catch (CMSException e) {
+ throw e;
+ } catch (Exception e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ throw new CMSException(Status.INTERNAL_SERVER_ERROR, LogMessages.UNEXPECTED_EXCEPTION, e.getMessage());
+ }
+ // If we got here, there are no change windows....
+ if (groups.size() > 1)
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MULTIPLE_GROUPS_NOT_SUPPORTED);
+ return true;
+
+ }
+
+ private void createChangeManagement(Schedule schedule, CMSMessage scheduleMessage) throws CMSException {
+ CMSInfo schedulingInfo = scheduleMessage.getSchedulingInfo();
+ for (VnfDetailsMessage vnfDetail : schedulingInfo.getVnfDetails()) {
+ ChangeManagementGroup cmg = new ChangeManagementGroup();
+ cmg.setSchedulesId(schedule.getId());
+ cmg.setGroupId("");
+ if (vnfDetail.getGroupId() != null)
+ cmg.setGroupId(vnfDetail.getGroupId());
+ cmg.setPolicyId(schedulingInfo.getPolicyId());
+ cmg.setNormalDurationInSecs(schedulingInfo.getNormalDurationInSeconds());
+ cmg.setAdditionalDurationInSecs(schedulingInfo.getAdditionalDurationInSeconds());
+ cmg.setConcurrencyLimit(schedulingInfo.getConcurrencyLimit());
+ cmGroupDAO.save(cmg);
+ for (ChangeWindowMessage cw : vnfDetail.getChangeWindow()) {
+ ChangeManagementChangeWindow cmcw = new ChangeManagementChangeWindow();
+ cmcw.setChangeManagementGroupsId(cmg.getId());
+ DateTime start = CMSCallbackImpl.convertISODate(cw.getStartTime(), "startTime");
+ DateTime end = CMSCallbackImpl.convertISODate(cw.getEndTime(), "startTime");
+ cmcw.setStartTimeMillis(start.getMillis());
+ cmcw.setFinishTimeMillis(end.getMillis());
+ cmChangeWindowDAO.save(cmcw);
+ }
+
+ for (String vnf : vnfDetail.getNode()) {
+ ChangeManagementSchedule cms = new ChangeManagementSchedule();
+ cms.setChangeManagementGroupsId(cmg.getId());
+ cms.setVnfName(vnf);
+ cms.setStatus(CMSStatusEnum.PendingSchedule.toString());
+ cmScheduleDAO.save(cms);
+ }
+ }
+ }
+
+ private void createChangeManagementImmediate(Schedule schedule, CMSMessage scheduleMessage) throws CMSException {
+ CMSInfo schedulingInfo = scheduleMessage.getSchedulingInfo();
+ for (VnfDetailsMessage vnfDetail : schedulingInfo.getVnfDetails()) {
+ ChangeManagementGroup cmg = new ChangeManagementGroup();
+ cmg.setSchedulesId(schedule.getId());
+ cmg.setGroupId("");
+ int duration = schedulingInfo.getNormalDurationInSeconds();
+ int backout = schedulingInfo.getAdditionalDurationInSeconds();
+ cmg.setStartTimeMillis(System.currentTimeMillis());
+ cmg.setFinishTimeMillis(System.currentTimeMillis() + ((duration * 1000) + (backout * 1000)));
+ cmg.setNormalDurationInSecs(duration);
+ cmg.setAdditionalDurationInSecs(backout);
+ if (vnfDetail.getGroupId() != null)
+ cmg.setGroupId(vnfDetail.getGroupId());
+ cmGroupDAO.save(cmg);
+ for (String vnf : vnfDetail.getNode()) {
+ ChangeManagementSchedule cms = new ChangeManagementSchedule();
+ cms.setChangeManagementGroupsId(cmg.getId());
+ cms.setVnfName(vnf);
+ cms.setStatus(CMSStatusEnum.PendingApproval.toString());
+ cmScheduleDAO.save(cms);
+ }
+ schedule.setStatus(CMSStatusEnum.PendingApproval.toString());
+ }
+ }
+
+ private void deleteChangeManagement(Schedule schedule) throws CMSException {
+ List<ChangeManagementGroup> cmgs = cmGroupDAO.findBySchedulesID(schedule.getId());
+
+ for (ChangeManagementGroup cmg : cmgs) {
+ List<ChangeManagementSchedule> schedules = cmScheduleDAO.findByChangeManagementGroupId(cmg.getId());
+ for (ChangeManagementSchedule s : schedules) {
+ CMSStatusEnum currentState = CMSStatusEnum.Completed.fromString(s.getStatus());
+ switch (currentState) {
+ case Scheduled:
+ if (s.getTmChangeId() != null && !s.getTmChangeId().equals(""))
+ tmClient.cancelTicket(schedule, s, s.getTmChangeId());
+ s.setStatus(CMSStatusEnum.Cancelled.toString());
+ break;
+ case Triggered:
+ // Too late...
+ break;
+ default:
+ s.setStatus(CMSStatusEnum.Deleted.toString());
+ }
+ cmScheduleDAO.save(s);
+ }
+ }
+
+ }
+
+ private List<DomainData> validateDomainData(CMSMessage scheduleMessage) throws CMSException {
+ List<Map<String, String>> domainData = scheduleMessage.getDomainData();
+ List<DomainData> domainDataList = new ArrayList<DomainData>();
+ Set<String> requiredFields = new HashSet<String>();
+ for (CmDomainDataEnum req : CmDomainDataEnum.values()) {
+ if (req.isRequired())
+ requiredFields.add(req.name());
+ }
+ for (Map<String, String> nameValue : domainData) {
+ for (String name : nameValue.keySet()) {
+ String value = nameValue.get(name);
+ // Save for later validation
+ DomainData dd = new DomainData();
+ dd.setName(name);
+ dd.setValue(value);
+ domainDataList.add(dd);
+ requiredFields.remove(name);
+ try {
+ CmDomainDataEnum.valueOf(name);
+ } catch (Exception e) {
+ log.warn(LogMessages.UNDEFINED_DOMAIN_DATA_ATTRIBUTE, DomainsEnum.ChangeManagement.name(), name,
+ value);
+ }
+ }
+ }
+ if (requiredFields.size() > 0) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE,
+ requiredFields.toString());
+ }
+ return domainDataList;
+
+ }
+
+ @Override
+ @Transactional
+ public Response deleteScheduleRequest(String apiVersion, String scheduleId, HttpServletRequest request) {
+ Mdc.begin(request, scheduleId);
+ Response response = null;
+ log.info(LogMessages.DELETE_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), scheduleId, "");
+ try {
+ Schedule schedule = scheduleDAO.findByDomainScheduleID(DomainsEnum.ChangeManagement.toString(), scheduleId);
+ if (schedule == null) {
+ throw new CMSNotFoundException(DomainsEnum.ChangeManagement.toString(), scheduleId);
+ }
+ deleteChangeManagement(schedule);
+ deleteScheduleRequest(DomainsEnum.ChangeManagement.toString(), scheduleId);
+ response = Response.noContent().build();
+ } catch (CMSException e) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ log.info(e.getMessage());
+ response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
+ } catch (Exception e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ response = Response.serverError().build();
+ }
+ Mdc.end(response);
+ log.info(LogMessages.DELETE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ audit.info(LogMessages.DELETE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ metrics.info(LogMessages.DELETE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ return response;
+ }
+
+ @Override
+ public Response getScheduleRequestInfo(String apiVersion, String scheduleId, HttpServletRequest request) {
+ Response response = null;
+ Mdc.begin(request, scheduleId);
+ log.info(LogMessages.GET_SCHEDULE_REQUEST_INFO, "Received", request.getRemoteAddr(), scheduleId, "");
+ Schedule schedule = null;
+ try {
+ schedule = scheduleDAO.findByDomainScheduleID(DomainsEnum.ChangeManagement.toString(), scheduleId);
+ if (schedule == null) {
+ throw new CMSException(Status.NOT_FOUND, LogMessages.SCHEDULE_NOT_FOUND,
+ DomainsEnum.ChangeManagement.toString(), scheduleId);
+ }
+ response = Response.ok().entity(schedule).build();
+ } catch (CMSException e) {
+ log.info(e.getMessage());
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
+ } catch (Exception e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ response = Response.serverError().build();
+ }
+ Mdc.end(response);
+ audit.info(LogMessages.GET_SCHEDULE_REQUEST_INFO, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ metrics.info(LogMessages.GET_SCHEDULE_REQUEST_INFO, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ log.info(LogMessages.GET_SCHEDULE_REQUEST_INFO, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ return response;
+ }
+
+ @Override
+ @Transactional
+ public Response approveScheduleRequest(String apiVersion, String scheduleId, ApprovalMessage approval,
+ HttpServletRequest request) {
+ Response response = null;
+ Mdc.begin(request, scheduleId);
+ log.info(LogMessages.APPROVE_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), scheduleId,
+ approval.toString());
+ try {
+ String domain = DomainsEnum.ChangeManagement.toString();
+ Schedule s = scheduleDAO.findByDomainScheduleID(domain, scheduleId);
+ if (s == null) {
+ throw new CMSNotFoundException(domain, scheduleId);
+ }
+ processApproveScheduleRequest(s, approval, s.getDomainData());
+ response = Response.noContent().build();
+ } catch (CMSException e) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ log.info(e.getMessage());
+ response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
+ } catch (Exception e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ response = Response.serverError().build();
+ }
+ Mdc.end(response);
+ log.info(LogMessages.APPROVE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId, "");
+ audit.info(LogMessages.APPROVE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ metrics.info(LogMessages.APPROVE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ return response;
+ }
+
+ private void processApproveScheduleRequest(Schedule s, ApprovalMessage approval, List<DomainData> domainData)
+ throws CMSException {
+ s = scheduleDAO.lockOne(s.getId());
+ String domain = DomainsEnum.ChangeManagement.toString();
+ processApproval(s, domain, approval);
+ if (s.getStatus().equals(CMSStatusEnum.Accepted.toString())) {
+ openTickets(s, domainData);
+ }
+ if (s.getStatus().equals(CMSStatusEnum.Rejected.toString())) {
+ updateChangeManagementSchedules(s, CMSStatusEnum.ApprovalRejected);
+ }
+ }
+
+ private void openTickets(Schedule s, List<DomainData> domainData) throws CMSException {
+ debug.debug("Entered openTickets scheduleId=" + s.getScheduleId());
+
+ Integer max_vnfs_per_ticket = env.getProperty("tm.vnfs.per.ticket", Integer.class, 1);
+
+ List<ChangeManagementGroup> groups = cmGroupDAO.findBySchedulesID(s.getId());
+ for (ChangeManagementGroup group : groups) {
+
+ List<ChangeManagementSchedule> schedules = cmScheduleDAO.findByChangeManagementGroupId(group.getId());
+ List<List<ChangeManagementSchedule>> ticketList = new ArrayList<List<ChangeManagementSchedule>>();
+ List<ChangeManagementSchedule> current = null;
+ for (ChangeManagementSchedule cms : schedules) {
+ if (current == null || current.size() == max_vnfs_per_ticket) {
+ current = new ArrayList<ChangeManagementSchedule>();
+ ticketList.add(current);
+ }
+ current.add(cms);
+ }
+ for (List<ChangeManagementSchedule> list : ticketList) {
+ openTicketForList(s, group, list, domainData);
+ }
+ }
+ debug.debug("Exited openTickets scheduleId=" + s.getScheduleId());
+ }
+
+ private void openTicketForList(Schedule schedule, ChangeManagementGroup group, List<ChangeManagementSchedule> list,
+ List<DomainData> domainData) throws CMSException {
+ List<String> vnfNames = new ArrayList<>();
+ for (ChangeManagementSchedule cms : list) {
+ vnfNames.add(cms.getVnfName());
+ }
+
+ debug.debug(
+ "Calling createChangeTicket scheduleId=" + schedule.getScheduleId() + ", group=" + group.getGroupId(),
+ ", vnfNames=" + vnfNames);
+ String changeId = tmClient.createChangeTicket(schedule, group, vnfNames, domainData);
+
+ // Pre-approve the ticket
+ for (ChangeManagementSchedule cms : list) {
+ cms.getTmApprovalStatus();
+ cms.setTmChangeId(changeId);
+ cms.setTmApprovalStatus(TmApprovalStatusEnum.Approved.toString());
+ // cms.setStatus(CMSStatusEnum.PendingApproval.toString());
+ if (cms.getStartTimeMillis() == null)
+ cms.setStatus(CMSStatusEnum.ScheduledImmediate.toString());
+ else
+ cms.setStatus(CMSStatusEnum.Scheduled.toString());
+ cmScheduleDAO.save(cms);
+ }
+ schedule.setStatus(CMSStatusEnum.Scheduled.toString());
+ scheduleDAO.save(schedule);
+ }
+
+ private void updateChangeManagementSchedules(Schedule s, CMSStatusEnum approvalrejected) {
+ debug.debug("Entered updateChangeManagementSchedules");
+ List<ChangeManagementGroup> groups = cmGroupDAO.findBySchedulesID(s.getId());
+ for (ChangeManagementGroup group : groups) {
+ List<ChangeManagementSchedule> schedules = cmScheduleDAO.findByChangeManagementGroupId(group.getId());
+ for (ChangeManagementSchedule schedule : schedules) {
+ schedule.setStatus(approvalrejected.toString());
+ cmScheduleDAO.save(schedule);
+ }
+ }
+ debug.debug("Exited updateChangeManagementSchedules");
+ }
+
+ @Override
+ public Response searchScheduleRequestDetails(String apiVersion, String scheduleId, String scheduleName,
+ String userId, String status, String createDateTime, String optimizerStatus, String requestApprovalUserId,
+ String requestApprovalStatus, String requestApprovalType, String workflowName, String vnfName, String vnfId,
+ String vnfStatus,
+ // String vnfScheduleId,
+ String startTime, String finishTime, String lastInstanceTime, String tmChangeId,
+ // String approvalUserId,
+ // String approvalStatus,
+ // String approvalType,
+ Integer maxSchedules, String lastScheduleId, Integer concurrencyLimit, UriInfo uri,
+ HttpServletRequest request) {
+
+ Mdc.begin(request, UUID.randomUUID().toString());
+ Response response = null;
+ log.info(LogMessages.SEARCH_SCHEDULE_REQUEST_DETAILS, "Received", request.getRemoteAddr(),
+ uri.getRequestUri().getQuery());
+ List<CmDetailsMessage> schedules = new ArrayList<CmDetailsMessage>();
+
+ try {
+ log.info("Timezone=" + TimeZone.getDefault());
+ MultivaluedMap<String, String> qp = uri.getQueryParameters();
+ StringBuilder where = new StringBuilder();
+ int maxRows = 0;
+ if (maxSchedules != null && maxSchedules > 0)
+ maxRows = maxSchedules;
+ buildWhere(qp, where);
+ List<ChangeManagementDetail> list = cmDetailsDAO.searchScheduleDetails(where.toString(), maxRows);
+ if (list == null || !list.iterator().hasNext()) {
+ throw new CMSException(Status.NOT_FOUND, LogMessages.SCHEDULE_NOT_FOUND,
+ DomainsEnum.ChangeManagement.toString(), scheduleId);
+ }
+ Iterator<ChangeManagementDetail> iter = list.iterator();
+ Map<Integer, Schedule> scheduleMap = new HashMap<Integer, Schedule>();
+ while (iter.hasNext()) {
+ ChangeManagementDetail cms = iter.next();
+ CmDetailsMessage msg = buildResponse(cms, scheduleMap);
+ schedules.add(msg);
+ }
+ response = Response.ok(schedules.toArray(new CmDetailsMessage[schedules.size()])).build();
+ } catch (CMSException e) {
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ log.info(e.getMessage());
+ response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
+ } catch (Exception e) {
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ response = Response.serverError().build();
+ }
+ Mdc.end(response);
+ log.info(LogMessages.SEARCH_SCHEDULE_REQUEST_DETAILS, "Returned", request.getRemoteAddr(),
+ response.getStatusInfo().toString());
+ audit.info(LogMessages.SEARCH_SCHEDULE_REQUEST_DETAILS, "Returned", request.getRemoteAddr(),
+ response.getStatusInfo().toString());
+ metrics.info(LogMessages.SEARCH_SCHEDULE_REQUEST_DETAILS, "Returned", request.getRemoteAddr(),
+ response.getStatusInfo().toString());
+ return response;
+
+ }
+
+ private void buildWhere(MultivaluedMap<String, String> qp, StringBuilder where) throws CMSException {
+ String delim = " where ";
+ for (String urlName : qp.keySet()) {
+ List<String> values = qp.get(urlName);
+ String clause = CmQueryParameters.buildClause(urlName, values);
+ if (clause != null && !clause.equals("")) {
+ where.append(delim).append("\n").append(clause).append("\n");
+ delim = "AND";
+ }
+ }
+
+ }
+
+ private CmDetailsMessage buildResponse(ChangeManagementDetail cms, Map<Integer, Schedule> scheduleMap) {
+ CmDetailsMessage msg = new CmDetailsMessage();
+ msg.setVnfId(cms.getVnfId());
+ msg.setVnfName(cms.getVnfName());
+ msg.setStatus(cms.getStatus());
+ msg.setTmChangeId(cms.getTmChangeId());
+ msg.setFinishTimeMillis(cms.getFinishTimeMillis());
+ msg.setStartTimeMillis(cms.getStartTimeMillis());
+ msg.setLastInstanceStartTimeMillis(cms.getLastInstanceStartTimeMillis());
+ msg.setGroupId(cms.getGroupId());
+ msg.setPolicyId(cms.getPolicyId());
+ msg.setTmApprovalStatus(cms.getTmApprovalStatus());
+ msg.setTmStatus(cms.getTmStatus());
+ msg.setStatusMessage(cms.getStatusMessage());
+ msg.setDispatchTimeMillis(cms.getDispatchTimeMillis());
+ msg.setExecutionCompletedTimeMillis(cms.getExecutionCompletedTimeMillis());
+ msg.setMsoMessage(cms.getMsoMessage());
+ msg.setMsoRequestId(cms.getMsoRequestId());
+ msg.setMsoStatus(cms.getMsoStatus());
+ msg.setMsoTimeMillis(cms.getMsoTimeMillis());
+ if (!scheduleMap.containsKey(cms.getSchedulesId())) {
+ Schedule schedule = scheduleDAO.findById(cms.getSchedulesId()).orElse(null);
+ if (schedule != null) {
+ // DO not innclude in the results
+ schedule.setScheduleInfo(null);
+ // schedule.setSchedule(null);
+ scheduleMap.put(cms.getSchedulesId(), schedule);
+ }
+ }
+ if (scheduleMap.containsKey(cms.getSchedulesId())) {
+ msg.setScheduleRequest(scheduleMap.get(cms.getSchedulesId()));
+ }
+ return msg;
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java
new file mode 100644
index 0000000..99b4970
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java
@@ -0,0 +1,68 @@
+/*
+ * 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.service.rs;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.onap.optf.cmso.optimizer.bean.CMOptimizerResponse;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+@Api
+@Path("/{apiVersion}")
+@Produces({MediaType.APPLICATION_JSON})
+public interface CMSOptimizerCallback {
+
+ // ******************************************************************
+ @POST
+ @Path("/optimizerCallback")
+ @Produces({MediaType.APPLICATION_JSON})
+ @ApiOperation(value = "", notes = "Processes optimizer results callback to a Pending Optimization schedule.")
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"),
+ @ApiResponse(code = 500, message = "Unexpected Runtime error", response = Exception.class)})
+ public Response sniroCallback(
+ @ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+ @ApiParam(value = "Return schedules > lastScheduleId") CMOptimizerResponse reponse, @Context UriInfo uri,
+ @Context HttpServletRequest request);
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmQueryParameters.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmQueryParameters.java
new file mode 100644
index 0000000..1a9c29d
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmQueryParameters.java
@@ -0,0 +1,230 @@
+/*
+ * 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.service.rs;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import javax.ws.rs.core.Response.Status;
+import org.joda.time.DateTime;
+import org.joda.time.format.ISODateTimeFormat;
+import org.onap.optf.cmso.common.LogMessages;
+import org.onap.optf.cmso.common.exceptions.CMSException;
+import org.onap.optf.cmso.model.DomainData;
+
+public class CmQueryParameters {
+
+ public enum QueryColumns {
+ RequestScheduleId("request.scheduleId", String.class, "ss.schedule_id"), RequestScheduleName(
+ "request.scheduleName", String.class,
+ "ss.schedule_name"), RequestUserId("request.userId", String.class, "ss.user_id"), RequestStatus(
+ "request.status", String.class, "ss.status"), RequestCreateDateTime("request.createDateTime",
+ Date.class, "ss.create_date_time"), RequestOptimizerStatus("request.optimizerStatus",
+ String.class, "ss.optimizer_status"), RequestApprovalUserId(
+ "request.approvalUserId", String.class,
+ "sa.user_id"), RequestApprovalStatus("request.approvalStatus",
+ String.class, "sa.status"), RequestApprovalType(
+ "request.approvalType", String.class,
+ "at.approval_type"), WorkflowName("WorkflowName",
+ DomainData.class,
+ "dd.value"), vnfName("vnfName", String.class,
+ "s.vnf_name"), vnfId("vnfId",
+ String.class,
+ "s.vnf_id"), vnfStatus(
+ "vnfStatus",
+ String.class,
+ "s.vnf_status"),
+ // vnfScheduleId("vnfScheduleId", String.class, "s.id"),
+ startTime("startTime", Date.class, "s.start_time"), finishTime("finishTime", Date.class,
+ "s.finish_ime"), lastInstanceTime("lastInstanceTime", Date.class, "g.last_instance_time"), tmChangeId(
+ "tmChangeId", String.class, "s.tm_change_id"), concurrenyLimit("request.concurrencyLimit",
+ Integer.class, "g.concurrency_limit"),
+ // approvalUserId("approvalUserId", String.class, "approvalUserId"),
+ // approvalStatus("approvalStatus", String.class, "approvalStatus"),
+ // approvalType("approvalType", String.class, "approvalType"),
+ ;
+
+ private final String urlName;
+ private final Class<?> type;
+ private final String col;
+
+ private QueryColumns(String urlName, Class<?> type, String col) {
+ this.urlName = urlName;
+ this.type = type;
+ this.col = col;
+ }
+
+ }
+
+ public static QueryColumns getQueryColumn(String urlName) {
+ for (QueryColumns qc : QueryColumns.values()) {
+ if (qc.urlName.equals(urlName))
+ return qc;
+ }
+ return null;
+ }
+
+ public static String buildClause(String urlName, List<String> values) throws CMSException {
+ QueryColumns qc = getQueryColumn(urlName);
+ if (qc == null) {
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.UNDEFINED_FILTER_ATTRIBUTE, urlName);
+ }
+ if (qc.type == Date.class) {
+ return formatDate(urlName, values, qc);
+ }
+ if (qc.type == DomainData.class) {
+ return formatDomainData(urlName, values, qc);
+ }
+ return formatString(urlName, values, qc);
+ }
+
+ private static String formatString(String urlName, List<String> values, QueryColumns qc) {
+ StringBuilder clause = new StringBuilder();
+ List<String> likes = new ArrayList<String>();
+ List<String> in = new ArrayList<String>();
+ for (String value : values) {
+ if (value.contains("%"))
+ likes.add(value);
+ else
+ in.add(value);
+ }
+ String delim = "(";
+ if (in.size() > 0) {
+ clause.append(delim).append(qc.col).append(" in ('");
+ String inDelim = "";
+ for (String value : in) {
+ clause.append(inDelim).append(value).append("'");
+ inDelim = ", '";
+ }
+ clause.append(") ");
+ delim = " OR ";
+ }
+ if (likes.size() > 0) {
+ for (String value : likes) {
+ clause.append(delim).append(qc.col).append(" like '").append(value).append("'");
+ delim = " OR ";
+ }
+ }
+ if (!delim.equals("("))
+ clause.append(")");
+ return clause.toString();
+ }
+
+ private static String formatDomainData(String urlName, List<String> values, QueryColumns qc) {
+ StringBuilder clause = new StringBuilder();
+ String delim = "(";
+ if (values.size() > 0) {
+ for (String value : values) {
+ clause.append(delim).append(" (dd.name = '").append(qc.urlName).append("' AND dd.value = '")
+ .append(value).append("')");
+ delim = " OR ";
+ }
+ }
+ if (!delim.equals("("))
+ clause.append(")");
+ return clause.toString();
+ }
+
+ private static String formatDate(String urlName, List<String> values, QueryColumns qc) throws CMSException {
+ List<String> clauses = new ArrayList<String>();
+ for (String value : values) {
+ String dates[] = value.split(",");
+ switch (dates.length) {
+ case 2:
+ formatDatePair(qc, dates[0].trim(), dates[1].trim(), clauses);
+ break;
+ case 1:
+ formatDatePair(qc, dates[0].trim(), "", clauses);
+ break;
+ default:
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_DATE_FILTER, urlName, value);
+ }
+ }
+ StringBuilder clause = new StringBuilder();
+ String delim = "(";
+ for (String c : clauses) {
+ clause.append(delim).append(c);
+ delim = " OR ";
+ }
+ if (!delim.equals(")")) {
+ clause.append(")");
+ }
+ return clause.toString();
+ }
+
+ private static void formatDatePair(QueryColumns qc, String lowDate, String highDate, List<String> clauses)
+ throws CMSException {
+ StringBuilder clause = new StringBuilder();
+ DateTime date1 = null;
+ DateTime date2 = null;
+ if (!lowDate.equals(""))
+ date1 = convertDate(lowDate, qc.urlName);
+ if (!highDate.equals(""))
+ date2 = convertDate(highDate, qc.urlName);
+ String delim = "(";
+ if (date1 != null) {
+ clause.append(delim).append(qc.col).append(" >= ").append(date1.getMillis());
+ delim = " AND ";
+ }
+ if (date2 != null) {
+ clause.append(delim).append(qc.col).append(" <= ").append(date2.getMillis());
+ delim = " AND ";
+ }
+ if (!delim.equals(")")) {
+ clause.append(")\n");
+ clauses.add(clause.toString());
+ }
+ }
+
+ private static DateTime convertDate(String utcDate, String urlName) throws CMSException {
+ DateTime dateTime = ISODateTimeFormat.dateTimeParser().parseDateTime(utcDate);
+ if (dateTime != null)
+ return dateTime;
+ throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_DATE_FILTER, urlName, utcDate);
+ }
+
+ // public static void main(String argv[])
+ // {
+ // List<String> values = new ArrayList<String>();
+ // values.add("2017-07-08T11:12:13Z,2017-07-08T11:12:13Z");
+ // values.add("2017-07-09T11:12:13Z,2017-07-09T11:12:13Z");
+ // values.add(",2017-07-09T11:12:13Z");
+ // values.add(" 2017-07-09T11:12:13Z");
+ // try {
+ // System.out.println(buildClause("request.createDateTime", values));
+ // } catch (SchedulerException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ //
+ // }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheck.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheck.java
new file mode 100644
index 0000000..edc2c96
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheck.java
@@ -0,0 +1,69 @@
+/*
+ * 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.service.rs;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.onap.optf.cmso.service.rs.models.HealthCheckMessage;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+
+@Api
+@Path("/{apiVersion}")
+@Produces({MediaType.APPLICATION_JSON})
+public interface HealthCheck {
+
+ // ******************************************************************
+ @GET
+ @Path("/health")
+ @Produces({MediaType.APPLICATION_JSON})
+ @ApiOperation(value = "", notes = "Returns health status of server.", response = HealthCheckMessage.class)
+ @ApiResponses(value = {@ApiResponse(code = 200, message = "OK"),
+ @ApiResponse(code = 400, message = "Not healthy", response = HealthCheckMessage.class)})
+ public Response healthCheck(@ApiParam(value = "v1") @PathParam("apiVersion") @DefaultValue("v1") String apiVersion,
+ @DefaultValue(value = "true") @ApiParam(value = "Check Interfaces",
+ allowMultiple = true) @QueryParam("checkInterfaces") Boolean checkInterfaces,
+ @Context UriInfo uri, @Context HttpServletRequest request);
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheckImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheckImpl.java
new file mode 100644
index 0000000..f994dc8
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/HealthCheckImpl.java
@@ -0,0 +1,121 @@
+/*
+ * 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.service.rs;
+
+import java.util.List;
+import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.onap.optf.cmso.common.Mdc;
+import org.onap.optf.cmso.model.ApprovalType;
+import org.onap.optf.cmso.model.dao.ApprovalTypeDAO;
+import org.onap.optf.cmso.optimizer.CMSOptimizerClient;
+import org.onap.optf.cmso.service.rs.models.HealthCheckComponent;
+import org.onap.optf.cmso.service.rs.models.HealthCheckMessage;
+import org.onap.optf.cmso.sostatus.MsoStatusClient;
+import org.onap.optf.cmso.ticketmgt.TmClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Controller;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+@Controller
+public class HealthCheckImpl implements HealthCheck {
+ private static EELFLogger log = EELFManager.getInstance().getLogger(HealthCheckImpl.class);
+ private static EELFLogger audit = EELFManager.getInstance().getAuditLogger();
+
+ @Autowired
+ TmClient tmClient;
+
+ @Autowired
+ CMSOptimizerClient sniroClient;
+
+ @Autowired
+ ApprovalTypeDAO approvalTypeDAO;
+
+ @Autowired
+ Environment env;
+
+ @Autowired
+ MsoStatusClient msoStatusClient;
+
+ @Override
+ public Response healthCheck(String apiVersion, Boolean checkInterfaces, UriInfo uri, HttpServletRequest request) {
+ Mdc.begin(request, UUID.randomUUID().toString());
+ log.info("Entered healthcheck");
+ Response response = null;
+ HealthCheckMessage hc = new HealthCheckMessage();
+ hc.setHealthy(true);
+
+ if (checkInterfaces) {
+ addToHealthCheckMessage(hc, tmClient.healthCheck());
+ addToHealthCheckMessage(hc, sniroClient.healthCheck());
+ addToHealthCheckMessage(hc, msoStatusClient.healthCheck());
+ }
+ addToHealthCheckMessage(hc, this.healthCheck());
+
+ if (hc.getHealthy())
+ response = Response.ok().entity(hc).build();
+ else
+ response = Response.status(Response.Status.BAD_REQUEST).entity(hc).build();
+ Mdc.end(response);
+ audit.info("Healthcheck healthy={0}", hc.getHealthy().toString());
+ return response;
+ }
+
+ private void addToHealthCheckMessage(HealthCheckMessage hc, HealthCheckComponent hcc) {
+ if (!hcc.getHealthy())
+ hc.setHealthy(false);
+
+ hc.setHostname(System.getenv("HOSTNAME"));
+ hc.addComponent(hcc);
+ }
+
+ public HealthCheckComponent healthCheck() {
+ HealthCheckComponent hcc = new HealthCheckComponent();
+ hcc.setName("Scheduler Database");
+ String url = env.getProperty("spring.datasource.url");
+ hcc.setUrl(url);
+ try {
+ List<ApprovalType> approvalTypes = approvalTypeDAO.findByDomain("HealthCheck");
+ hcc.setHealthy(true);
+ hcc.setStatus("OK");
+ } catch (Exception e) {
+ hcc.setStatus(e.getMessage());
+
+ }
+ return hcc;
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ApprovalMessage.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ApprovalMessage.java
new file mode 100644
index 0000000..0d43799
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ApprovalMessage.java
@@ -0,0 +1,106 @@
+/*
+ * 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.service.rs.models;
+
+import java.io.Serializable;
+import java.sql.Timestamp;
+import org.onap.optf.cmso.common.ApprovalStatusEnum;
+import org.onap.optf.cmso.common.ApprovalTypesEnum;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * The persistent class for the approval_types database table.
+ *
+ */
+@ApiModel(value = "Schedule Approval Request", description = "Request to accept or reject an optimized time slot.")
+public class ApprovalMessage implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(ApprovalMessage.class);
+
+ @ApiModelProperty(value = "ATTUID of the user accepting/rejecting the time slot.")
+ private String approvalUserId;
+
+ @ApiModelProperty(value = "Approval status.")
+ private ApprovalStatusEnum approvalStatus;
+
+ @ApiModelProperty(value = "Type of approval.", allowableValues = "Tier 2")
+ private ApprovalTypesEnum approvalType;
+
+ private Timestamp approvalDateTime;
+
+ public String getApprovalUserId() {
+ return approvalUserId;
+ }
+
+ public void setApprovalUserId(String approvalUserId) {
+ this.approvalUserId = approvalUserId;
+ }
+
+ public ApprovalStatusEnum getApprovalStatus() {
+ return approvalStatus;
+ }
+
+ public void setApprovalStatus(ApprovalStatusEnum approvalStatus) {
+ this.approvalStatus = approvalStatus;
+ }
+
+ public ApprovalTypesEnum getApprovalType() {
+ return approvalType;
+ }
+
+ public void setApprovalType(ApprovalTypesEnum approvalType) {
+ this.approvalType = approvalType;
+ }
+
+ public Timestamp getApprovalDateTime() {
+ return approvalDateTime;
+ }
+
+ public void setApprovalDateTime(Timestamp approvalDateTime) {
+ this.approvalDateTime = approvalDateTime;
+ }
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CMSInfo.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CMSInfo.java
new file mode 100644
index 0000000..1f7e317
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CMSInfo.java
@@ -0,0 +1,119 @@
+/*
+ * 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.service.rs.models;
+
+import java.io.Serializable;
+import java.util.List;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * The persistent class for the approval_types database table.
+ *
+ */
+@ApiModel(value = "Change Management Scheduling Info", description = "Details of schedule being requested")
+public class CMSInfo implements Serializable {
+ private static EELFLogger log = EELFManager.getInstance().getLogger(CMSInfo.class);
+
+ private static final long serialVersionUID = 1L;
+
+ @ApiModelProperty(value = "Expected duration (in seconds) of a successful execution of a single VNF change.")
+ private Integer normalDurationInSeconds;
+
+ @ApiModelProperty(
+ value = "Additional duration (in seconds) to be added to support backout of an unsuccessful VNF change.")
+ private Integer additionalDurationInSeconds;
+
+ @ApiModelProperty(value = "Maximum number of VNF changes to schedule concurrently")
+ private Integer concurrencyLimit;
+
+ @ApiModelProperty(
+ value = "Name of schedule optimization policy used by the change management cmso optimizer to determine available time slot")
+ private String policyId;
+
+ @ApiModelProperty(value = "Lists of the VNFs to be changed and the desired change windows")
+ private List<VnfDetailsMessage> vnfDetails;
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+
+ public Integer getNormalDurationInSeconds() {
+ return normalDurationInSeconds;
+ }
+
+ public void setNormalDurationInSeconds(Integer normalDurationInSeconds) {
+ this.normalDurationInSeconds = normalDurationInSeconds;
+ }
+
+ public Integer getAdditionalDurationInSeconds() {
+ return additionalDurationInSeconds;
+ }
+
+ public void setAdditionalDurationInSeconds(Integer additionalDurationInSeconds) {
+ this.additionalDurationInSeconds = additionalDurationInSeconds;
+ }
+
+ public Integer getConcurrencyLimit() {
+ return concurrencyLimit;
+ }
+
+ public void setConcurrencyLimit(Integer concurrencyLimit) {
+ this.concurrencyLimit = concurrencyLimit;
+ }
+
+ public String getPolicyId() {
+ return policyId;
+ }
+
+ public void setPolicyId(String policyId) {
+ this.policyId = policyId;
+ }
+
+ public List<VnfDetailsMessage> getVnfDetails() {
+ return vnfDetails;
+ }
+
+ public void setVnfDetails(List<VnfDetailsMessage> vnfDetails) {
+ this.vnfDetails = vnfDetails;
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CMSMessage.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CMSMessage.java
new file mode 100644
index 0000000..afa4c44
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CMSMessage.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.service.rs.models;
+
+import java.io.Serializable;
+import org.onap.optf.cmso.common.LogMessages;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModel;
+
+/**
+ * The persistent class for the approval_types database table.
+ *
+ */
+@ApiModel
+public class CMSMessage extends ScheduleMessage implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();
+ private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
+
+ private CMSInfo schedulingInfo;
+
+ @Override
+ public CMSInfo getSchedulingInfo() {
+ // TODO Auto-generated method stub
+ return schedulingInfo;
+ }
+
+ @Override
+ public void setSchedulingInfo(Object info) {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ String jsonString = mapper.writeValueAsString(info);
+ schedulingInfo = mapper.readValue(jsonString, CMSInfo.class);
+ } catch (Exception e) {
+ debug.debug(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ }
+
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ChangeWindowMessage.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ChangeWindowMessage.java
new file mode 100644
index 0000000..58aaa2e
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ChangeWindowMessage.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.service.rs.models;
+
+import java.io.Serializable;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(value = "Change Window",
+ description = "Time window within which the scheduler optimizer can schedule the changes for the group of NVFs")
+public class ChangeWindowMessage implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(ChangeWindowMessage.class);
+
+ @ApiModelProperty(value = "Earliest time that a set of changes may begin.")
+ private String startTime;
+
+ @ApiModelProperty(value = "Latest time by which all changes must be completed")
+ private String endTime;
+
+ public String getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(String startTime) {
+ this.startTime = startTime;
+ }
+
+ public String getEndTime() {
+ return endTime;
+ }
+
+ public void setEndTime(String endTime) {
+ this.endTime = endTime;
+ }
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CmDetailsMessage.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CmDetailsMessage.java
new file mode 100644
index 0000000..b021af9
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CmDetailsMessage.java
@@ -0,0 +1,67 @@
+/*
+ * 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.service.rs.models;
+
+import java.io.Serializable;
+import java.util.List;
+import org.onap.optf.cmso.model.ChangeManagementDetail;
+import org.onap.optf.cmso.model.Schedule;
+import io.swagger.annotations.ApiModel;
+
+/**
+ * The persistent class for the change_management_groups database table.
+ *
+ */
+@ApiModel
+public class CmDetailsMessage extends ChangeManagementDetail implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ private Schedule scheduleRequest;
+ private List<ApprovalMessage> approvals;
+
+ public Schedule getScheduleRequest() {
+ return scheduleRequest;
+ }
+
+ public void setScheduleRequest(Schedule scheduleRequest) {
+ this.scheduleRequest = scheduleRequest;
+ }
+
+ public List<ApprovalMessage> getApprovals() {
+ return approvals;
+ }
+
+ public void setApprovals(List<ApprovalMessage> approvals) {
+ this.approvals = approvals;
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CmDomainDataEnum.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CmDomainDataEnum.java
new file mode 100644
index 0000000..675a8d9
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/CmDomainDataEnum.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.service.rs.models;
+
+public enum CmDomainDataEnum {
+ WorkflowName(true), CallbackUrl(true), ServiceType(false), VnfType(false), SubscriberName(false), CallbackData(
+ true),;
+ private final Boolean required;
+
+ private CmDomainDataEnum(boolean required) {
+ this.required = required;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/HealthCheckComponent.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/HealthCheckComponent.java
new file mode 100644
index 0000000..47d8d57
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/HealthCheckComponent.java
@@ -0,0 +1,92 @@
+/*
+ * 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.service.rs.models;
+
+import java.io.Serializable;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModel;
+
+@ApiModel
+public class HealthCheckComponent implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(HealthCheckComponent.class);
+
+ private String name;
+ private String url;
+ private String status;
+ private Boolean healthy = false;
+
+ public Boolean getHealthy() {
+ return healthy;
+ }
+
+ public void setHealthy(Boolean healthy) {
+ this.healthy = healthy;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public String getStatus() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/HealthCheckMessage.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/HealthCheckMessage.java
new file mode 100644
index 0000000..02cc65f
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/HealthCheckMessage.java
@@ -0,0 +1,108 @@
+/*
+ * 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.service.rs.models;
+
+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.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModel;
+
+@ApiModel
+public class HealthCheckMessage implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(HealthCheckMessage.class);
+
+ private Boolean healthy = false;
+ private String buildInfo = "";
+ private String currentTime = "";
+ private String hostname = "";
+
+ private List<HealthCheckComponent> components = new ArrayList<HealthCheckComponent>();
+
+ public Boolean getHealthy() {
+ return healthy;
+ }
+
+ public void setHealthy(Boolean healthy) {
+ this.healthy = healthy;
+ }
+
+ public String getBuildInfo() {
+ return buildInfo;
+ }
+
+ public void setBuildInfo(String buildInfo) {
+ this.buildInfo = buildInfo;
+ }
+
+ public String getCurrentTime() {
+ return currentTime;
+ }
+
+ public void setCurrentTime(String currentTime) {
+ this.currentTime = currentTime;
+ }
+
+ public String getHostname() {
+ return hostname;
+ }
+
+ public void setHostname(String hostname) {
+ this.hostname = hostname;
+ }
+
+ public List<HealthCheckComponent> getComponents() {
+ return components;
+ }
+
+ public void setComponents(List<HealthCheckComponent> components) {
+ this.components = components;
+ }
+
+ public void addComponent(HealthCheckComponent components) {
+ this.components.add(components);
+ }
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ScheduleMessage.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ScheduleMessage.java
new file mode 100644
index 0000000..a89e818
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/ScheduleMessage.java
@@ -0,0 +1,124 @@
+/*
+ * 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.service.rs.models;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * The persistent class for the approval_types database table.
+ *
+ */
+@ApiModel(value = "Schedule Request", description = "Request to schedule VNF change management workflow(s).")
+public abstract class ScheduleMessage implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(ScheduleMessage.class);
+
+ public abstract Object getSchedulingInfo();
+
+ public abstract void setSchedulingInfo(Object info);
+
+ // public abstract void setSchedulingInfo(Object schedulingInfo);
+
+ @ApiModelProperty(value = "Schedule domain : ChangeManagement")
+ private String domain;
+
+ @ApiModelProperty(value = "Schedule id that must be unique within the domain. Use of UUID is highly recommended.")
+ private String scheduleId;
+
+ @ApiModelProperty(value = "User provided name of the schedule (deaults to scheduleId")
+ private String scheduleName;
+
+ @ApiModelProperty(value = "ATTUID of the user requesting the schedule.")
+ private String userId;
+
+ @ApiModelProperty(value = "Domain data as name value/pairs. (i.e. CallbackUrl, CallbackData, WorkflowName)")
+ private List<Map<String, String>> domainData;
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ public String getScheduleId() {
+ return scheduleId;
+ }
+
+ public void setScheduleId(String scheduleId) {
+ this.scheduleId = scheduleId;
+ }
+
+ public String getScheduleName() {
+ return scheduleName;
+ }
+
+ public void setScheduleName(String scheduleName) {
+ this.scheduleName = scheduleName;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public List<Map<String, String>> getDomainData() {
+ return domainData;
+ }
+
+ public void setDomainData(List<Map<String, String>> domainData) {
+ this.domainData = domainData;
+ }
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/VnfDetailsMessage.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/VnfDetailsMessage.java
new file mode 100644
index 0000000..b1dde5d
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/models/VnfDetailsMessage.java
@@ -0,0 +1,92 @@
+/*
+ * 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.service.rs.models;
+
+import java.io.Serializable;
+import java.util.List;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel(value = "VNF Details", description = "Details and scheduling criteria for the VNFs to be changed.")
+public class VnfDetailsMessage implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private static EELFLogger log = EELFManager.getInstance().getLogger(VnfDetailsMessage.class);
+
+ @ApiModelProperty(value = "Name of the list of VNFs to be changed as a group")
+ private String groupId;
+
+ @ApiModelProperty(value = "Lists of the VNF names to be changed")
+ private List<String> node;
+
+ @ApiModelProperty(
+ value = "Lists of desired change windows that the optimizer can select from. (Only 1 change window supported at this time)")
+ private List<ChangeWindowMessage> changeWindow;
+
+ public String getGroupId() {
+ return groupId;
+ }
+
+ public void setGroupId(String groupId) {
+ this.groupId = groupId;
+ }
+
+ public List<String> getNode() {
+ return node;
+ }
+
+ public void setNode(List<String> node) {
+ this.node = node;
+ }
+
+ public List<ChangeWindowMessage> getChangeWindow() {
+ return changeWindow;
+ }
+
+ public void setChangeWindow(List<ChangeWindowMessage> changeWindow) {
+ this.changeWindow = changeWindow;
+ }
+
+ public String toString() {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(this);
+ } catch (JsonProcessingException e) {
+ log.debug("Error in toString()", e);
+ }
+ return "";
+ }
+
+}