From 42232be81bfd5cddabc42af9a79ec0abdb89e6be Mon Sep 17 00:00:00 2001 From: Jerry Flood Date: Mon, 25 Mar 2019 12:25:07 -0400 Subject: Commit 9 for Create Optimized Sched API Multiple commits required due to commit size limitation. Change-Id: I146a9dc65738e9dea7850b3accf5d88ce44ea90f Issue-ID: OPTFRA-458 Signed-off-by: Jerry Flood --- .../cmso/optimizer/model/OptimizerRequest.java | 164 ++++++++++++++++++++ .../cmso/optimizer/model/OptimizerResponse.java | 105 +++++++++++++ .../optimizer/model/OptimizerScheduleInfo.java | 82 ++++++++++ .../cmso/optimizer/model/ScheduledElement.java | 127 ++++++++++++++++ .../cmso/optimizer/model/UnScheduledElement.java | 103 +++++++++++++ .../org/onap/optf/cmso/service/rs/AdminTool.java | 11 +- .../onap/optf/cmso/service/rs/AdminToolImpl.java | 29 ++-- .../cmso/service/rs/BaseSchedulerServiceImpl.java | 169 ++++++++++----------- 8 files changed, 681 insertions(+), 109 deletions(-) create mode 100644 cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerRequest.java create mode 100644 cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerResponse.java create mode 100644 cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerScheduleInfo.java create mode 100644 cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/ScheduledElement.java create mode 100644 cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/UnScheduledElement.java (limited to 'cmso-service/src/main/java/org/onap') diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerRequest.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerRequest.java new file mode 100644 index 0000000..058d8c1 --- /dev/null +++ b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerRequest.java @@ -0,0 +1,164 @@ +/* + * Copyright © 2017-2019 AT&T Intellectual Property. Modifications Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed under the Creative + * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except + * in compliance with the License. You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.optf.cmso.optimizer.model; + +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; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import org.onap.optf.cmso.service.rs.models.v2.ChangeWindow; +import org.onap.optf.cmso.service.rs.models.v2.ElementInfo; +import org.onap.optf.cmso.service.rs.models.v2.NameValue; +import org.onap.optf.cmso.service.rs.models.v2.PolicyInfo; + +@ApiModel(value = "Optimizer Request", + description = "Request to provide an \"conflict free\" schedule for passed elements.") +public class OptimizerRequest implements Serializable { + private static final long serialVersionUID = 1L; + private static EELFLogger log = EELFManager.getInstance().getLogger(OptimizerRequest.class); + + @ApiModelProperty(value = "Unique Id of the request") + private String requestId; + + @ApiModelProperty(value = "Concurrency limit for this request") + private Integer concurrencyLimit; + + @ApiModelProperty(value = "Expected duration of normal change") + private Integer normalDuration; + + @ApiModelProperty(value = "Additional duration for failed change") + private Integer additionalDuration; + + @ApiModelProperty(value = "Implementation specific name value pairs.") + private List commonData; + + @ApiModelProperty(value = "Lists of desired change windows to schedule the elements.") + private List changeWindows = new ArrayList<>(); + + @ApiModelProperty(value = "List of the elements to schedule.") + private List elements = new ArrayList<>(); + + @ApiModelProperty(value = "List of the policies to control optimization.") + private List policies = new ArrayList<>(); + + public String getRequestId() { + return requestId; + } + + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + + public List getPolicies() { + return policies; + } + + + public void setPolicies(List policies) { + this.policies = policies; + } + + + public List getCommonData() { + return commonData; + } + + + public void setCommonData(List commonData) { + this.commonData = commonData; + } + + + public List getElements() { + return elements; + } + + + public void setElements(List elements) { + this.elements = elements; + } + + + public List getChangeWindows() { + return changeWindows; + } + + + public void setChangeWindows(List changeWindows) { + this.changeWindows = changeWindows; + } + + + public Integer getConcurrencyLimit() { + return concurrencyLimit; + } + + + public void setConcurrencyLimit(Integer concurrencyLimit) { + this.concurrencyLimit = concurrencyLimit; + } + + + public Integer getNormalDuration() { + return normalDuration; + } + + + public void setNormalDuration(Integer normalDuration) { + this.normalDuration = normalDuration; + } + + + public Integer getAdditionalDuration() { + return additionalDuration; + } + + + public void setAdditionalDuration(Integer additionalDuration) { + this.additionalDuration = additionalDuration; + } + + + @Override + 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/optimizer/model/OptimizerResponse.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerResponse.java new file mode 100644 index 0000000..9971595 --- /dev/null +++ b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerResponse.java @@ -0,0 +1,105 @@ +/* + * 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.optimizer.model; + +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; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@ApiModel(value = "Optimizer Response", description = "Response to optimizer request for the requested elements.") +public class OptimizerResponse implements Serializable { + private static final long serialVersionUID = 1L; + private static EELFLogger log = EELFManager.getInstance().getLogger(OptimizerResponse.class); + + public enum OptimizeScheduleStatus { + CREATED, PENDING_TOPOLOGY, PENDING_TICKETS, PENDING_OPTIMIZER, COMPLETED, FAILED, DELETED, + } + + @ApiModelProperty(value = "Unique Id of the request") + private String requestId; + + @ApiModelProperty(value = "Status of the optimization") + private OptimizeScheduleStatus status; + + @ApiModelProperty(value = "Message for failed optimization") + private String errorMessage; + + + @ApiModelProperty(value = "List of schedules returned by the optimizer.") + private List schedules = new ArrayList<>(); + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + + public List getSchedules() { + return schedules; + } + + public void setSchedules(List schedules) { + this.schedules = schedules; + } + + public OptimizeScheduleStatus getStatus() { + return status; + } + + public void setStatus(OptimizeScheduleStatus status) { + this.status = status; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + @Override + 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/optimizer/model/OptimizerScheduleInfo.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerScheduleInfo.java new file mode 100644 index 0000000..92ce981 --- /dev/null +++ b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/OptimizerScheduleInfo.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * + * Copyright © 2019 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed under the Creative + * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except + * in compliance with the License. You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package org.onap.optf.cmso.optimizer.model; + +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; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@ApiModel(value = "Optimizer Schedule Info", description = "Schedule Information returned from optimizer request.") +public class OptimizerScheduleInfo implements Serializable { + private static final long serialVersionUID = 1L; + private static EELFLogger log = EELFManager.getInstance().getLogger(OptimizerScheduleInfo.class); + + @ApiModelProperty(value = "Lists of elements with start times.") + private List scheduledElements = new ArrayList<>(); + + @ApiModelProperty(value = "Lists of elements that were not able to be scheduled.") + private List unScheduledElements = new ArrayList<>(); + + + public List getScheduledElements() { + return scheduledElements; + } + + + public void setScheduledElements(List scheduledElements) { + this.scheduledElements = scheduledElements; + } + + + public List getUnScheduledElements() { + return unScheduledElements; + } + + + public void setUnScheduledElements(List unScheduledElements) { + this.unScheduledElements = unScheduledElements; + } + + + @Override + 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/optimizer/model/ScheduledElement.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/ScheduledElement.java new file mode 100644 index 0000000..db92863 --- /dev/null +++ b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/ScheduledElement.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * + * Copyright © 2019 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed under the Creative + * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except + * in compliance with the License. You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package org.onap.optf.cmso.optimizer.model; + +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; +import java.io.Serializable; +import java.util.Date; +import org.springframework.format.annotation.DateTimeFormat; + +@ApiModel(value = "Scheduled Element", description = "Scheduled element returned by the optimizer.") +public class ScheduledElement implements Serializable { + private static final long serialVersionUID = 1L; + private static EELFLogger log = EELFManager.getInstance().getLogger(ScheduledElement.class); + + public enum ScheduleType { + UNKNOWN, GROUP_DISPATCH, INDIVIDUAL, + } + + @ApiModelProperty(value = "Element identifier") + private String elementId; + + @ApiModelProperty(value = "Group identifier") + private String groupId; + + private ScheduleType scheduleType = ScheduleType.UNKNOWN; + + @ApiModelProperty(value = "Earliest time for which changes may begin.") + @DateTimeFormat(pattern = "yyyy-MM-dd'T'hh:mm:ss'Z'") + private Date startTime; + + @ApiModelProperty(value = "Latest time by which all changes must be completed.") + @DateTimeFormat(pattern = "yyyy-MM-dd'T'hh:mm:ss'Z'") + private Date endTime; + + @ApiModelProperty(value = "Expected duration of change in seconds.") + private Long durationSeconds; + + public String getElementId() { + return elementId; + } + + public void setElementId(String elementId) { + this.elementId = elementId; + } + + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public ScheduleType getScheduleType() { + return scheduleType; + } + + public void setScheduleType(ScheduleType scheduleType) { + this.scheduleType = scheduleType; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getEndTime() { + return endTime; + } + + public void setEndTime(Date endTime) { + this.endTime = endTime; + } + + public Long getDurationSeconds() { + return durationSeconds; + } + + public void setDurationSeconds(Long durationSeconds) { + this.durationSeconds = durationSeconds; + } + + @Override + 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/optimizer/model/UnScheduledElement.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/UnScheduledElement.java new file mode 100644 index 0000000..be6e89d --- /dev/null +++ b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/model/UnScheduledElement.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * + * Copyright © 2019 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + * + * Unless otherwise specified, all documentation contained herein is licensed under the Creative + * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except + * in compliance with the License. You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package org.onap.optf.cmso.optimizer.model; + +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; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@ApiModel(value = "Unscheduled Element", description = "Scheduled element returned by the optimizer.") +public class UnScheduledElement implements Serializable { + private static final long serialVersionUID = 1L; + private static EELFLogger log = EELFManager.getInstance().getLogger(UnScheduledElement.class); + + public enum NotScheduledReason { + ConcurrencyConstraint, AvailabilityConstraint, Other, + } + + @ApiModelProperty(value = "Element identifier") + private String elementId; + + @ApiModelProperty(value = "Group identifier") + private String groupId; + + @ApiModelProperty(value = "List of reasons not able to schedule this element.") + private List notScheduledReaons = new ArrayList<>(); + + @ApiModelProperty(value = "List of messages not able to schedule this element.") + private List notScheduledMessages = new ArrayList<>(); + + public String getElementId() { + return elementId; + } + + public void setElementId(String elementId) { + this.elementId = elementId; + } + + public List getNotScheduledReaons() { + return notScheduledReaons; + } + + public void setNotScheduledReaons(List notScheduledReaons) { + this.notScheduledReaons = notScheduledReaons; + } + + public List getNotScheduledMessages() { + return notScheduledMessages; + } + + public void setNotScheduledMessages(List notScheduledMessages) { + this.notScheduledMessages = notScheduledMessages; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + @Override + 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/AdminTool.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/AdminTool.java index 10eedf8..6be8159 100644 --- 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 @@ -31,6 +31,11 @@ package org.onap.optf.cmso.service.rs; +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; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; @@ -39,12 +44,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -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("CMSO Administration") @Path("/{apiVersion}") @Produces({MediaType.APPLICATION_JSON}) 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 index 8ec4f4f..fa182b4 100644 --- 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 @@ -1,27 +1,27 @@ /* * Copyright © 2017-2019 AT&T Intellectual Property. * Modifications Copyright © 2018 IBM. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * - * + * + * * Unless otherwise specified, all documentation contained herein is licensed * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); * you may not use this documentation except in compliance with the License. * You may obtain a copy of the License at - * + * * https://creativecommons.org/licenses/by/4.0/ - * + * * Unless required by applicable law or agreed to in writing, documentation * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -31,28 +31,26 @@ package org.onap.optf.cmso.service.rs; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; - 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); - @Context + @Context UriInfo uri; - + @Context HttpServletRequest request; - + @Autowired PropertiesManagement pm; @@ -60,8 +58,9 @@ public class AdminToolImpl implements AdminTool { @Override public Response exec(String apiVersion, String id) { log.info("AdminTool.exec entered"); - if (id.length() < 4) + if (id.length() < 4) { return Response.ok("").build(); + } String encrypted = PropertiesManagement.getEncryptedValue(id); Response response = Response.ok(encrypted).build(); 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 index 787bd60..18678ff 100644 --- 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 @@ -1,44 +1,39 @@ /* - * 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 + * 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. - * - * - * 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 com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; - 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; @@ -54,13 +49,10 @@ 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.onap.optf.cmso.service.rs.models.v2.OptimizedScheduleMessage; 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); @@ -77,39 +69,39 @@ public class BaseSchedulerServiceImpl { @Autowired ScheduleApprovalDAO scheduleApprovalDAO; - protected Schedule validateAndAddScheduleRequest(ScheduleMessage scheduleMessage, List domainData) - throws CMSException { + protected Schedule validateAndAddScheduleRequest(OptimizedScheduleMessage scheduleMessage, + List domainData) throws CMSException { messageValidations(scheduleMessage); - Schedule s = scheduleDAO.findByDomainScheduleID(scheduleMessage.getDomain(), scheduleMessage.getScheduleId()); + Schedule sch = scheduleDAO.findByDomainScheduleID(scheduleMessage.getDomain(), scheduleMessage.getScheduleId()); - if (s != null) { + if (sch != null) { throw new CMSAlreadyExistsException(scheduleMessage.getDomain(), scheduleMessage.getScheduleId()); } - s = new Schedule(); - s.setUuid(UUID.randomUUID()); - 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.setOptimizerAttemptsToSchedule(0); - s.setScheduleInfo(scheduleMessage.getSchedulingInfo().toString()); - s.setStatus(CMSStatusEnum.PendingSchedule.toString()); - scheduleDAO.save(s); + sch = new Schedule(); + sch.setUuid(UUID.randomUUID()); + sch.setUserId(scheduleMessage.getUserId()); + sch.setCreateDateTimeMillis(System.currentTimeMillis()); + sch.setDomain(scheduleMessage.getDomain()); + sch.setScheduleId(scheduleMessage.getScheduleId()); + sch.setOptimizerTransactionId(sch.getScheduleId()); // No reason these cannot be the same as + // these + // are 1<=>1 at this + // point. + sch.setScheduleName(scheduleMessage.getScheduleName()); + sch.setOptimizerAttemptsToSchedule(0); + sch.setScheduleInfo(scheduleMessage.getSchedulingData().toString()); + sch.setStatus(CMSStatusEnum.PendingSchedule.toString()); + scheduleDAO.save(sch); for (DomainData dd : domainData) { - dd.setUuid(UUID.randomUUID()); - s.addDomainData(dd); + dd.setUuid(UUID.randomUUID()); + sch.addDomainData(dd); domainDataDAO.save(dd); } - scheduleDAO.save(s); - return s; + scheduleDAO.save(sch); + return sch; } - private void messageValidations(ScheduleMessage scheduleMessage) throws CMSException { + private void messageValidations(OptimizedScheduleMessage scheduleMessage) throws CMSException { if (scheduleMessage.getScheduleName() == null || scheduleMessage.getScheduleName().equals("")) { throw new CMSException(Status.BAD_REQUEST, LogMessages.MISSING_REQUIRED_ATTRIBUTE, "schedulerName", ""); } @@ -119,47 +111,48 @@ public class BaseSchedulerServiceImpl { } protected void deleteScheduleRequest(String domain, String scheduleId) throws CMSException { - Schedule s = scheduleDAO.findByDomainScheduleID(domain, scheduleId); - if (s == null) { + Schedule sch = scheduleDAO.findByDomainScheduleID(domain, scheduleId); + if (sch == null) { throw new CMSNotFoundException(domain, scheduleId); } - CMSStatusEnum currentStatus = CMSStatusEnum.Completed.fromString(s.getStatus()); - s.setDeleteDateTimeMillis(System.currentTimeMillis()); + CMSStatusEnum currentStatus = CMSStatusEnum.Completed.fromString(sch.getStatus()); + sch.setDeleteDateTimeMillis(System.currentTimeMillis()); switch (currentStatus) { case Scheduled: // TODO CLose all tickets.... - s.setStatus(CMSStatusEnum.Cancelled.toString()); + sch.setStatus(CMSStatusEnum.Cancelled.toString()); break; case NotificationsInitiated: throw new CMSException(Status.NOT_ACCEPTABLE, LogMessages.CANNOT_CANCEL_IN_PROGRESS); default: - s.setStatus(CMSStatusEnum.Deleted.toString()); + sch.setStatus(CMSStatusEnum.Deleted.toString()); } - scheduleDAO.save(s); + scheduleDAO.save(sch); } - protected Schedule processApproval(Schedule s, String domain, ApprovalMessage approvalMessage) throws CMSException { - String scheduleId = s.getScheduleId(); + protected Schedule processApproval(Schedule sch, String domain, ApprovalMessage approvalMessage) + throws CMSException { + String scheduleId = sch.getScheduleId(); ApprovalType approvalType = - approvalTypeDAO.findByDomainAndType(domain, approvalMessage.getApprovalType().toString()); + approvalTypeDAO.findByDomainAndType(domain, approvalMessage.getApprovalType().toString()); if (approvalType == null) { throw new CMSException(Status.BAD_REQUEST, LogMessages.INVALID_ATTRIBUTE, "approvalType", - approvalMessage.getApprovalType().toString()); + approvalMessage.getApprovalType().toString()); } - if (!s.getStatus().equals(CMSStatusEnum.PendingApproval.toString())) { + if (!sch.getStatus().equals(CMSStatusEnum.PendingApproval.toString())) { throw new CMSException(Status.PRECONDITION_FAILED, LogMessages.NOT_PENDING_APPROVAL, domain, scheduleId, - s.getStatus()); + sch.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 (sch.getScheduleApprovals() != null) { + for (ScheduleApproval scheduleApproval : sch.getScheduleApprovals()) { if (scheduleApproval.getUserId().equals(approvalMessage.getApprovalUserId()) - && scheduleApproval.getApprovalTypesUuid().equals(approvalType.getUuid())) { + && scheduleApproval.getApprovalTypesUuid().equals(approvalType.getUuid())) { sa = scheduleApproval; } } @@ -167,32 +160,33 @@ public class BaseSchedulerServiceImpl { if (sa == null) { sa = new ScheduleApproval(); sa.setUuid(UUID.randomUUID()); - sa.setSchedule(s); + sa.setSchedule(sch); sa.setApprovalTypesUuid(approvalType.getUuid()); 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); + sa.setSchedule(sch); + sch.addScheduleApproval(sa); + scheduleDAO.save(sch); if (sa.getStatus().equals(ApprovalStatusEnum.Rejected.toString())) { - s.setStatus(CMSStatusEnum.Rejected.toString()); + sch.setStatus(CMSStatusEnum.Rejected.toString()); } else { - if (allApprovalsReceived(s, sa)) - s.setStatus(CMSStatusEnum.Accepted.toString()); + if (allApprovalsReceived(sch, sa)) { + sch.setStatus(CMSStatusEnum.Accepted.toString()); + } } - scheduleDAO.save(s); - return s; + scheduleDAO.save(sch); + return sch; } private boolean allApprovalsReceived(Schedule schedule, ScheduleApproval sa) { Map requiredApprovalsByType = new HashMap<>(); // Approval - // countdown + // countdown Map approvalsByType = new HashMap<>(); // Just - // for - // logging + // for + // logging List approvalTypes = approvalTypeDAO.findByDomain(schedule.getDomain()); for (ApprovalType at : approvalTypes) { @@ -218,7 +212,7 @@ public class BaseSchedulerServiceImpl { requiredApprovalsByType.put(approval.getApprovalTypesUuid(), remaining); } else { log.warn("Ignored Unidentified approval type {0} for domain {1}", approval.getApprovalTypesUuid(), - schedule.getDomain()); + schedule.getDomain()); } } } @@ -230,5 +224,4 @@ public class BaseSchedulerServiceImpl { } return true; } - } -- cgit 1.2.3-korg