aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/filters/CMSOContainerFilters.java141
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/filters/CmsoClientFilters.java86
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/model/ApprovalType.java109
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/model/ChangeManagementChangeWindow.java158
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java373
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java681
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmQueryParameters.java412
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleService.java72
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleServiceImpl.java80
-rw-r--r--cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizerCallback.java (renamed from cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOptimizerCallback.java)130
10 files changed, 701 insertions, 1541 deletions
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/filters/CMSOContainerFilters.java b/cmso-service/src/main/java/org/onap/optf/cmso/filters/CMSOContainerFilters.java
deleted file mode 100644
index 8b37a71..0000000
--- a/cmso-service/src/main/java/org/onap/optf/cmso/filters/CMSOContainerFilters.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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.filters;
-
-import java.io.IOException;
-import java.util.UUID;
-
-import javax.annotation.Priority;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.container.ContainerResponseContext;
-import javax.ws.rs.container.ContainerResponseFilter;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.ext.Provider;
-
-import org.onap.observations.Mdc;
-import org.onap.observations.Observation;
-import org.onap.optf.cmso.common.LogMessages;
-import org.onap.optf.cmso.filters.MessageHeaders.HeadersEnum;
-import org.springframework.stereotype.Component;
-
-@Priority(1)
-@Provider
-@Component
-public class CMSOContainerFilters implements ContainerRequestFilter, ContainerResponseFilter {
-
-
- @Context
- private HttpServletRequest servletRequest;
-
- @Override
- public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
- throws IOException {
- try {
- Mdc.auditEnd(requestContext, responseContext);
- Observation.report(LogMessages.INCOMING_MESSAGE_RESPONSE,
- requestContext.getMethod(),
- requestContext.getUriInfo().getPath().toString(),
- responseContext.getStatusInfo().toString());
- MultivaluedMap<String, String> reqHeaders = requestContext.getHeaders();
- MultivaluedMap<String, Object> respHeaders = responseContext.getHeaders();
- String minorVersion = (String) reqHeaders.getFirst(HeadersEnum.MinorVersion.toString());
- respHeaders.add(HeadersEnum.MinorVersion.toString(), minorVersion);
- respHeaders.add(HeadersEnum.LatestVersion.toString(), MessageHeaders.latestVersion);
- respHeaders.add(HeadersEnum.PatchVersion.toString(), MessageHeaders.patchVersion);
-
- } catch (Exception e) {
- if (e instanceof WebApplicationException) {
- Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage());
- } else {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage());
- }
- }
- }
-
- @Override
- public void filter(ContainerRequestContext requestContext) throws IOException {
- try {
- // On the way in
- Mdc.auditStart(requestContext, servletRequest);
- Observation.report(LogMessages.INCOMING_MESSAGE,
- requestContext.getMethod(),
- requestContext.getUriInfo().getPath().toString());
-
- String majorVersion = requestContext.getUriInfo().getPath();
- if (majorVersion != null) {
-
- if (majorVersion.startsWith("dispatch/"))
- return;
- majorVersion = majorVersion.replaceAll("/.*$", "");
- }
- if (!MessageHeaders.validateMajorVersion(majorVersion)) {
- ResponseBuilder builder = null;
- String response = "Unsupported Major version";
- builder = Response.status(Response.Status.NOT_FOUND).entity(response);
- throw new WebApplicationException(builder.build());
- }
- MultivaluedMap<String, String> headers = requestContext.getHeaders();
- String transactionId = (String) headers.getFirst(HeadersEnum.TransactionID.toString());
- if (transactionId == null) {
- transactionId = UUID.randomUUID().toString();
- headers.add(HeadersEnum.TransactionID.toString(), transactionId);
- }
- String minorVersion = (String) headers.getFirst(HeadersEnum.MinorVersion.toString());
- if (minorVersion == null) {
- minorVersion = MessageHeaders.supportedMajorVersions.get(majorVersion);
- headers.add(HeadersEnum.MinorVersion.toString(), minorVersion);
- }
- if (!MessageHeaders.validateMajorMinorVersion(majorVersion, minorVersion)) {
- ResponseBuilder builder = null;
- String response = "Unsupported API version";
- builder = Response.status(Response.Status.NOT_FOUND).entity(response);
- throw new WebApplicationException(builder.build());
-
- }
- } catch (Exception e) {
- if (e instanceof WebApplicationException) {
- Observation.report(LogMessages.EXPECTED_EXCEPTION, e.getMessage());
- throw e;
- } else {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.getMessage());
- }
- }
-
- }
-
-}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/filters/CmsoClientFilters.java b/cmso-service/src/main/java/org/onap/optf/cmso/filters/CmsoClientFilters.java
new file mode 100644
index 0000000..00b8fe5
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/filters/CmsoClientFilters.java
@@ -0,0 +1,86 @@
+/*
+ * 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.filters;
+
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import java.io.IOException;
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.client.ClientResponseContext;
+import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.core.MultivaluedMap;
+import org.onap.observations.Mdc;
+import org.onap.observations.Observation;
+import org.onap.optf.cmso.common.LogMessages;
+import org.onap.optf.cmso.filters.MessageHeaders.HeadersEnum;
+import org.slf4j.MDC;
+import org.springframework.stereotype.Component;
+
+// @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
+@Component
+public class CmsoClientFilters implements ClientRequestFilter, ClientResponseFilter {
+
+ private static EELFLogger log = EELFManager.getInstance().getLogger(CmsoClientFilters.class);
+ private static String appId = "cmso";
+
+ @Override
+ public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
+ // On the way back
+ Mdc.metricEnd(responseContext);
+ Mdc.setCaller(17);
+ Observation.report(LogMessages.OUTGOING_MESSAGE_RETURNED,
+ requestContext.getMethod(),
+ requestContext.getUri().getPath().toString(),
+ responseContext.getStatusInfo().toString());
+ }
+
+ @Override
+ public void filter(ClientRequestContext requestContext) throws IOException {
+ // On the way out
+ Mdc.metricStart(requestContext);
+ Mdc.setCaller(17);
+ Observation.report(LogMessages.OUTGOING_MESSAGE,
+ requestContext.getMethod(),
+ requestContext.getUri().getPath().toString());
+ MultivaluedMap<String, Object> headers = requestContext.getHeaders();
+
+ String transactionId = (String) headers.getFirst(MessageHeaders.HeadersEnum.TransactionID.toString());
+ String mdcId = MDC.get(MDC_KEY_REQUEST_ID);
+ if (transactionId == null || transactionId.equals(""))
+ if (mdcId != null)
+ headers.add(HeadersEnum.TransactionID.toString(), mdcId);
+ headers.add(HeadersEnum.FromAppID.toString(), appId);
+ }
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/model/ApprovalType.java b/cmso-service/src/main/java/org/onap/optf/cmso/model/ApprovalType.java
index 6009040..677f5ce 100644
--- a/cmso-service/src/main/java/org/onap/optf/cmso/model/ApprovalType.java
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/model/ApprovalType.java
@@ -1,39 +1,33 @@
/*
- * 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.model;
import java.io.Serializable;
import java.util.UUID;
-
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@@ -42,7 +36,7 @@ import javax.persistence.Table;
/**
* The persistent class for the approval_types database table.
- *
+ *
*/
@Entity
@Table(name = "APPROVAL_TYPES")
@@ -63,39 +57,82 @@ public class ApprovalType implements Serializable {
@Column(name = "domain")
private String domain;
+ /**
+ * Instantiates a new approval type.
+ */
public ApprovalType() {}
+ /**
+ * Gets the uuid.
+ *
+ * @return the uuid
+ */
public UUID getUuid() {
- return uuid;
- }
+ return uuid;
+ }
- public void setUuid(UUID uuid) {
- this.uuid = uuid;
- }
+ /**
+ * Sets the uuid.
+ *
+ * @param uuid the new uuid
+ */
+ public void setUuid(UUID uuid) {
+ this.uuid = uuid;
+ }
- public Integer getApprovalCount() {
+ /**
+ * Gets the approval count.
+ *
+ * @return the approval count
+ */
+ public Integer getApprovalCount() {
return this.approvalCount;
}
+ /**
+ * Sets the approval count.
+ *
+ * @param approvalCount the new approval count
+ */
public void setApprovalCount(Integer approvalCount) {
this.approvalCount = approvalCount;
}
+ /**
+ * Gets the approval type.
+ *
+ * @return the approval type
+ */
public String getApprovalType() {
return this.approvalType;
}
+ /**
+ * Sets the approval type.
+ *
+ * @param approvalType the new approval type
+ */
public void setApprovalType(String approvalType) {
this.approvalType = approvalType;
}
+ /**
+ * Gets the domain.
+ *
+ * @return the domain
+ */
public String getDomain() {
return domain;
}
+ /**
+ * Sets the domain.
+ *
+ * @param domain the new domain
+ */
public void setDomain(String domain) {
this.domain = domain;
}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/model/ChangeManagementChangeWindow.java b/cmso-service/src/main/java/org/onap/optf/cmso/model/ChangeManagementChangeWindow.java
index 210e61a..f0b1da1 100644
--- a/cmso-service/src/main/java/org/onap/optf/cmso/model/ChangeManagementChangeWindow.java
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/model/ChangeManagementChangeWindow.java
@@ -1,57 +1,48 @@
/*
- * 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.model;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.UUID;
-
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Transient;
-
import org.joda.time.format.ISODateTimeFormat;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-import io.swagger.annotations.ApiModel;
-import io.swagger.annotations.ApiModelProperty;
-
/**
* The persistent class for the change_management_change_windows database table.
- *
+ *
*/
@Entity
@Table(name = "CHANGE_MANAGEMENT_CHANGE_WINDOWS")
@@ -86,59 +77,124 @@ public class ChangeManagementChangeWindow implements Serializable {
@Column(name = "change_management_group_uuid")
private UUID changeManagementGroupUuid;
+ /**
+ * Instantiates a new change management change window.
+ */
public ChangeManagementChangeWindow() {}
+ /**
+ * Gets the finish time.
+ *
+ * @return the finish time
+ */
public String getFinishTime() {
- if (finishTimeMillis != null)
+ if (finishTimeMillis != null) {
return ISODateTimeFormat.dateTimeNoMillis().print(this.finishTimeMillis);
+ }
return null;
}
+ /**
+ * Sets the finish time.
+ *
+ * @param finishTime the new finish time
+ */
public void setFinishTime(String finishTime) {}
+ /**
+ * Gets the start time.
+ *
+ * @return the start time
+ */
public String getStartTime() {
- if (startTimeMillis != null)
+ if (startTimeMillis != null) {
return ISODateTimeFormat.dateTimeNoMillis().print(this.startTimeMillis);
+ }
return null;
}
+ /**
+ * Sets the start time.
+ *
+ * @param startTime the new start time
+ */
public void setStartTime(String startTime) {}
+ /**
+ * Gets the uuid.
+ *
+ * @return the uuid
+ */
public UUID getUuid() {
- return uuid;
- }
+ return uuid;
+ }
- public void setUuid(UUID uuid) {
- this.uuid = uuid;
- }
+ /**
+ * Sets the uuid.
+ *
+ * @param uuid the new uuid
+ */
+ public void setUuid(UUID uuid) {
+ this.uuid = uuid;
+ }
- public UUID getChangeManagementGroupUuid() {
- return changeManagementGroupUuid;
- }
+ /**
+ * Gets the change management group uuid.
+ *
+ * @return the change management group uuid
+ */
+ public UUID getChangeManagementGroupUuid() {
+ return changeManagementGroupUuid;
+ }
- public void setChangeManagementGroupUuid(UUID changeManagementGroupUuid) {
- this.changeManagementGroupUuid = changeManagementGroupUuid;
- }
+ /**
+ * Sets the change management group uuid.
+ *
+ * @param changeManagementGroupUuid the new change management group uuid
+ */
+ public void setChangeManagementGroupUuid(UUID changeManagementGroupUuid) {
+ this.changeManagementGroupUuid = changeManagementGroupUuid;
+ }
- public Long getFinishTimeMillis() {
+ /**
+ * Gets the finish time millis.
+ *
+ * @return the finish time millis
+ */
+ public Long getFinishTimeMillis() {
return finishTimeMillis;
}
+ /**
+ * Sets the finish time millis.
+ *
+ * @param finishTimeMillis the new finish time millis
+ */
public void setFinishTimeMillis(Long finishTimeMillis) {
this.finishTimeMillis = finishTimeMillis;
}
+ /**
+ * Gets the start time millis.
+ *
+ * @return the start time millis
+ */
public Long getStartTimeMillis() {
return startTimeMillis;
}
+ /**
+ * Sets the start time millis.
+ *
+ * @param startTimeMillis the new start time millis
+ */
public void setStartTimeMillis(Long startTimeMillis) {
this.startTimeMillis = startTimeMillis;
}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java b/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java
deleted file mode 100644
index a773798..0000000
--- a/cmso-service/src/main/java/org/onap/optf/cmso/optimizer/CMSOptimizerClient.java
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * 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;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ws.rs.ProcessingException;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.ResponseProcessingException;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import org.onap.observations.Mdc;
-import org.onap.observations.Observation;
-import org.onap.optf.cmso.common.BasicAuthenticatorFilter;
-import org.onap.optf.cmso.common.CMSStatusEnum;
-import org.onap.optf.cmso.common.LogMessages;
-import org.onap.optf.cmso.common.PropertiesManagement;
-import org.onap.optf.cmso.filters.CMSOClientFilters;
-import org.onap.optf.cmso.model.Schedule;
-import org.onap.optf.cmso.model.dao.ScheduleDAO;
-import org.onap.optf.cmso.optimizer.bean.CMOptimizerRequest;
-import org.onap.optf.cmso.optimizer.bean.CMRequestInfo;
-import org.onap.optf.cmso.optimizer.bean.CMSchedulingInfo;
-import org.onap.optf.cmso.optimizer.bean.CMVnfDetails;
-import org.onap.optf.cmso.service.rs.models.CMSInfo;
-import org.onap.optf.cmso.service.rs.models.ChangeWindowMessage;
-import org.onap.optf.cmso.service.rs.models.HealthCheckComponent;
-import org.onap.optf.cmso.service.rs.models.VnfDetailsMessage;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
-@Component
-public class CMSOptimizerClient {
- private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
-
- @Autowired
- ScheduleDAO scheduleDAO;
-
- @Autowired
- Environment env;
-
- @Autowired
- PropertiesManagement pm;
-
- public boolean scheduleOptimization(UUID uuid) {
- Map<String, String> mdcSave = Mdc.save();
- try {
- String optimizerurl = env.getProperty("cmso.optimizer.url");
- String optimizercallbackurl = env.getProperty("cmso.optimizer.callbackurl");
- String username = env.getProperty("mechid.user");
- Integer maxAttempts = env.getProperty("cmso.optimizer.maxAttempts", Integer.class, 20);
-
- // Ensure that only one cmso is requsting this call to optimizer
- Schedule schedule = scheduleDAO.lockOne(uuid);
- if (!schedule.getStatus().equals(CMSStatusEnum.PendingSchedule.toString()))
- return false;
-
- String password = pm.getProperty("mechid.pass", "");
- //
- // Only 'successfully' process one schedule per invocation
- // If a schedule attemp fails and it could be because of the data in the
- // message, try the next one. We don't want bad data to
- //
- if (schedule.getOptimizerAttemptsToSchedule() >= maxAttempts) {
- schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
- schedule.setOptimizerMessage("Maximum number of attempts exceeded " + maxAttempts);
- updateScheduleStatus(schedule);
- return true;
- }
- CMOptimizerRequest cmReq = new CMOptimizerRequest();
- try {
- CMSInfo info = reconstituteMessage(schedule);
- if (info == null) {
- return true;
- }
- buildRequest(cmReq, info, schedule, optimizercallbackurl);
- } catch (Exception e) {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
- schedule.setOptimizerMessage("Unexpected exception: " + e.getMessage());
- updateScheduleStatus(schedule);
- return true;
- }
-
- // This service will call SNIO for each PendingOptimiztion
- // If the request is successfully scheduled in optimizer, status will be
- // updated to OptimizationInProgress.
- Client client = ClientBuilder.newClient();
- client.register(new BasicAuthenticatorFilter(username, password));
- client.register(new CMSOClientFilters());
- WebTarget optimizerTarget = client.target(optimizerurl);
- Invocation.Builder invocationBuilder = optimizerTarget.request(MediaType.APPLICATION_JSON);
- try {
- //
- // First, push OptimizationInProgress to the DB (flush()) assuming a 202 status,
- // in case the optimizer callback is received prior to the
- // commit of this transaction.
- // optimizer Callback will throw an error if it receives a response in the incorrect
- // state.
- //
- schedule.setOptimizerTransactionId(cmReq.getRequestInfo().getTransactionId());
- schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
- schedule.setStatus(CMSStatusEnum.OptimizationInProgress.toString());
- updateScheduleStatus(schedule);
- debug.debug("optimizer url / user: " + optimizerurl + " / " + username);
- debug.debug("optimizer Request: " + new ObjectMapper().writeValueAsString(cmReq));
- Observation.report(LogMessages.OPTIMIZER_REQUEST, "Begin", schedule.getScheduleId(), optimizerurl);
- Response response = invocationBuilder.post(Entity.json(cmReq));
- Observation.report(LogMessages.OPTIMIZER_REQUEST, "End", schedule.getScheduleId(), optimizerurl);
- switch (response.getStatus()) {
- case 202:
- debug.debug("Successfully scheduled optimization: " + schedule.getScheduleId());
- // Scheduled with optimizer
- break;
- case 400: // Bad request
- {
- schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
- schedule.setOptimizerStatus("HTTP Status: " + response.getStatus());
- String message = response.readEntity(String.class);
- schedule.setOptimizerMessage(message);
- schedule.setStatus(CMSStatusEnum.ScheduleFailed.toString());
- // Need to understand the cause of this error. May be teh same as optimizer
- // down.
- int tries = schedule.getOptimizerAttemptsToSchedule();
- tries++;
- schedule.setOptimizerAttemptsToSchedule(tries);
- updateScheduleStatus(schedule);
- Observation.report(LogMessages.OPTIMIZER_EXCEPTION, message);
- return true;
- }
-
- case 500:
- default: {
- String message = response.readEntity(String.class);
- // SHould probably track the number of retries.
- schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
- int tries = schedule.getOptimizerAttemptsToSchedule();
- tries++;
- schedule.setStatus(CMSStatusEnum.ScheduleFailed.toString());
- schedule.setOptimizerAttemptsToSchedule(tries);
- schedule.setOptimizerMessage(message);
- updateScheduleStatus(schedule);
- /// Got processing error response
- // may be transient, wait for next cycle.
- Observation.report(LogMessages.OPTIMIZER_EXCEPTION, message);
- // Wait until next cycle and try again.
- return false;
- }
-
- }
- //
- return true;
- } catch (ResponseProcessingException e) {
- schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
- schedule.setOptimizerStatus("Failed to parse optimizer response");
- schedule.setStatus(CMSStatusEnum.ScheduleFailed.toString());
- // Need to understand the cause of this error. May be teh same as optimizer down.
- int tries = schedule.getOptimizerAttemptsToSchedule();
- tries++;
- schedule.setOptimizerAttemptsToSchedule(tries);
- updateScheduleStatus(schedule);
- // Getting invalid response from optimizer.
- // May be data related.
- Observation.report(LogMessages.OPTIMIZER_EXCEPTION, e, e.getMessage());
- return false;
-
- } catch (ProcessingException e) {
- // Don't track number of retries on IO error (optimizer is down)
- schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
- schedule.setStatus(CMSStatusEnum.PendingSchedule.toString());
- updateScheduleStatus(schedule);
- /// Cannot connect to optimizer
- Observation.report(LogMessages.OPTIMIZER_EXCEPTION, e, e.getMessage());
- // Wait until next cycle
- return false;
- }
- } catch (Exception e) {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
-
- } finally {
- Mdc.restore(mdcSave);
- }
- return false;
- }
-
- private void buildRequest(CMOptimizerRequest cmReq, CMSInfo info, Schedule schedule, String optimizercallbackurl) {
-
- // TODO: Need to get optimizer to accept ChangeManagementSchedulingInfo
- // This is to support 1707 optimizer interface
- CMRequestInfo reqInfo = cmReq.getRequestInfo();
- CMSchedulingInfo schInfo = cmReq.getSchedulingInfo();
-
- UUID uuid = UUID.randomUUID();
- reqInfo.setCallbackUrl(optimizercallbackurl);
- reqInfo.setOptimizer(new String[] {"scheduling"});
- reqInfo.setTransactionId(schedule.getOptimizerTransactionId());
- reqInfo.setRequestId("CM-" + uuid.toString());
- reqInfo.setSourceId("cmso");
-
- String[] policyArray = new String[1];
- policyArray[0] = info.getPolicyId();
- schInfo.setPolicyId(policyArray);
- schInfo.setAdditionalDurationInSecs(info.getAdditionalDurationInSeconds());
- schInfo.setConcurrencyLimit(info.getConcurrencyLimit());
- schInfo.setNormalDurationInSecs(info.getNormalDurationInSeconds());
- schInfo.setScheduleId(schedule.getScheduleId());
- List<CMVnfDetails> list = new ArrayList<CMVnfDetails>();
- String startTime = "";
- String endTime = "";
-
- for (VnfDetailsMessage vnf : info.getVnfDetails()) {
- String groupId = vnf.getGroupId();
- for (String node : vnf.getNode()) {
- CMVnfDetails d = new CMVnfDetails(vnf.getGroupId());
- d.setNode(node);
- list.add(d);
- }
- if (startTime.equals("")) {
- // Only supporting 1 CW for 1710
- ChangeWindowMessage cw = vnf.getChangeWindow().get(0);
- startTime = cw.getStartTime();
- endTime = cw.getEndTime();
- }
- }
- schInfo.setStartTime(startTime);
- schInfo.setEndTime(endTime);
- schInfo.setVnfDetails(list.toArray(new CMVnfDetails[list.size()]));
-
- }
-
- private CMSInfo reconstituteMessage(Schedule schedule) {
- String request = schedule.getScheduleInfo();
- ObjectMapper om = new ObjectMapper();
- try {
- CMSInfo info = om.readValue(request, CMSInfo.class);
- return info;
- } catch (Exception e) {
- // Parsing should work here because this was a toString on the original object.
- // We may have an issue when upgrading....
- // Perhaps We create ChangeManagementSchedulingInfoV1, ...V2, etc.
- // ANd try them one after another....
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, "Unable to parse message. Format changed?");
- schedule.setOptimizerStatus("Failed to parse optimizer request");
- schedule.setOptimizerDateTimeMillis(System.currentTimeMillis());
- schedule.setStatus(CMSStatusEnum.OptimizationFailed.toString());
- scheduleDAO.save(schedule);
- }
- return null;
- }
-
- @Transactional
- public void updateScheduleStatus(Schedule schedule) {
- scheduleDAO.save(schedule);
-
- }
-
- public HealthCheckComponent healthCheck() {
- Map<String, String> mdcSave = Mdc.save();
- HealthCheckComponent hcc = new HealthCheckComponent();
- hcc.setName("OPtimizer Interface");
- String optimizerurl = env.getProperty("cmso.optimizer.url");
- String optimizercallbackurl = env.getProperty("cmso.optimizer.callbackurl");
- String username = env.getProperty("mechid.user");
- String password = pm.getProperty("mechid.pass", "");
- hcc.setUrl(optimizerurl);
- try {
- UUID uuid = UUID.randomUUID();
- // Build a bogus request should fail policy validation
- CMRequestInfo requestInfo = new CMRequestInfo();
- CMSchedulingInfo schedulingInfo = new CMSchedulingInfo();
- CMOptimizerRequest cmReq = new CMOptimizerRequest();
- cmReq.setRequestInfo(requestInfo);
- cmReq.setSchedulingInfo(schedulingInfo);
- requestInfo.setCallbackUrl("http://callbackurl.onap.org:8080/healthcheck");
- requestInfo.setOptimizer(new String[] {"scheduling"});
- requestInfo.setTransactionId(uuid.toString());
- requestInfo.setRequestId("CM-" + uuid.toString());
- requestInfo.setSourceId("cmso");
- schedulingInfo.setAdditionalDurationInSecs(10);
- schedulingInfo.setConcurrencyLimit(10);
- schedulingInfo.setNormalDurationInSecs(10);
- schedulingInfo.setPolicyId(new String[] {"healthcheck"});
- schedulingInfo.setScheduleId(uuid.toString());
- CMVnfDetails details = new CMVnfDetails();
- details.setGroupId("");
- details.setNode("healtcheck");
- schedulingInfo.setVnfDetails(new CMVnfDetails[] {details});
- schedulingInfo.setStartTime("2017-12-11T15:23:24Z");
- schedulingInfo.setEndTime("2017-12-11T22:23:24Z");
-
- Client client = ClientBuilder.newClient();
- client.register(new BasicAuthenticatorFilter(username, password));
- client.register(new CMSOClientFilters());
-
- WebTarget optimizerTarget = client.target(optimizerurl);
- Invocation.Builder invocationBuilder = optimizerTarget.request(MediaType.APPLICATION_JSON);
- debug.debug("Optimizer url / user: " + optimizerurl + " / " + username);
- Observation.report(LogMessages.OPTIMIZER_REQUEST, "Begin", "healthcheck", optimizerurl);
- Response response = invocationBuilder.post(Entity.json(cmReq));
- Observation.report(LogMessages.OPTIMIZER_REQUEST, "End", "healthcheck", optimizerurl);
- String message = response.getStatus() + ":" + response.readEntity(String.class);
- switch (response.getStatus()) {
- case 202:
- debug.debug("Successful optimizer healthcheck");
- hcc.setHealthy(true);
- break;
- case 400:
- // Expecting policy not found.
- if (message.contains("Cannot fetch policy")) {
- debug.debug("Successful optimizer healthcheck");
- hcc.setHealthy(true);
- hcc.setStatus("OK");
- } else {
- hcc.setStatus(message);
- }
- break;
- default:
- hcc.setStatus(message);
- break;
- }
- } catch (Exception e) {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e.toString());
- hcc.setStatus(e.toString());
- } finally {
- Mdc.restore(mdcSave);
- }
- return hcc;
-
- }
-}
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
deleted file mode 100644
index cc304db..0000000
--- a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CMSOServiceImpl.java
+++ /dev/null
@@ -1,681 +0,0 @@
-/*
- * 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.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.observations.Observation;
-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.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 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) {
-
- Observation.report(LogMessages.SEARCH_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), uri.toString(), "");
- Response response = null;
- List<Schedule> schedules = new ArrayList<Schedule>();
- try {
- debug.debug("Timezone={}", TimeZone.getDefault());
- StringBuilder where = new StringBuilder();
- int maxRows = 0;
- //MultivaluedMap<String, String> qp = uri.getQueryParameters();
- // 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().getUuid()).orElse(null);
- if (s != null) {
- schedules.add(s);
- if (includeDetails) {
- List<ChangeManagementGroup> groups = cmGroupDAO.findBySchedulesID(s.getUuid());
- s.setGroups(groups);
- for (ChangeManagementGroup g : groups) {
- List<ChangeManagementSchedule> cmSchedules =
- cmScheduleDAO.findByChangeManagementGroupId(g.getUuid());
- g.setChangeManagementSchedules(cmSchedules);
- }
- }
- }
- }
- response = Response.ok(schedules.toArray(new Schedule[schedules.size()])).build();
- } catch (CMSException e) {
- Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
- } catch (Exception e) {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.serverError().build();
- }
-
- Observation.report(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) {
- Observation.report(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);
-
- // 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) {
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
- } catch (Exception e) {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- response = Response.serverError().build();
- }
- Observation.report(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 = CMSOOptimizerCallbackImpl.convertISODate(cw.getStartTime(), "startTime");
- DateTime end = CMSOOptimizerCallbackImpl.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) {
- Observation.report(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.setUuid(UUID.randomUUID());
- cmg.setSchedulesUuid(schedule.getUuid());
- 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.setUuid(UUID.randomUUID());
- cmcw.setChangeManagementGroupUuid(cmg.getUuid());
- DateTime start = CMSOOptimizerCallbackImpl.convertISODate(cw.getStartTime(), "startTime");
- DateTime end = CMSOOptimizerCallbackImpl.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.setUuid(UUID.randomUUID());
- cms.setChangeManagementGroupUuid(cmg.getUuid());
- 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.setUuid(UUID.randomUUID());
- cmg.setSchedulesUuid(schedule.getUuid());
- 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.setUuid(UUID.randomUUID());
- cms.setChangeManagementGroupUuid(cmg.getUuid());
- cms.setVnfName(vnf);
- cms.setStatus(CMSStatusEnum.PendingApproval.toString());
- cmScheduleDAO.save(cms);
- }
- schedule.setStatus(CMSStatusEnum.PendingApproval.toString());
- scheduleDAO.save(schedule);
- }
- }
-
- private void deleteChangeManagement(Schedule schedule) throws CMSException {
- List<ChangeManagementGroup> cmgs = cmGroupDAO.findBySchedulesID(schedule.getUuid());
-
- for (ChangeManagementGroup cmg : cmgs) {
- List<ChangeManagementSchedule> schedules = cmScheduleDAO.findByChangeManagementGroupId(cmg.getUuid());
- 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) {
- Observation.report(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) {
- Response response = null;
- Observation.report(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();
- Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
- } catch (Exception e) {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- response = Response.serverError().build();
- }
- Observation.report(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;
- Observation.report(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) {
- Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
- } catch (Exception e) {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.serverError().build();
- }
- Observation.report(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;
- Observation.report(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();
- Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
- } catch (Exception e) {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- response = Response.serverError().build();
- }
- Observation.report(LogMessages.APPROVE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId, "");
- return response;
- }
-
- private void processApproveScheduleRequest(Schedule s, ApprovalMessage approval, List<DomainData> domainData)
- throws CMSException {
- s = scheduleDAO.lockOne(s.getUuid());
- 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.getUuid());
- for (ChangeManagementGroup group : groups) {
-
- List<ChangeManagementSchedule> schedules = cmScheduleDAO.findByChangeManagementGroupId(group.getUuid());
- 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.getUuid());
- for (ChangeManagementGroup group : groups) {
- List<ChangeManagementSchedule> schedules = cmScheduleDAO.findByChangeManagementGroupId(group.getUuid());
- 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) {
-
- Response response = null;
- Observation.report(LogMessages.SEARCH_SCHEDULE_REQUEST_DETAILS, "Received", request.getRemoteAddr(),
- uri.getRequestUri().getQuery());
- List<CmDetailsMessage> schedules = new ArrayList<CmDetailsMessage>();
-
- try {
- debug.debug("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<UUID, Schedule> scheduleMap = new HashMap<UUID, 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) {
- Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
- } catch (Exception e) {
- Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
- response = Response.serverError().build();
- }
- Observation.report(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<UUID, 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.getSchedulesUuid())) {
- Schedule schedule = scheduleDAO.findById(cms.getSchedulesUuid()).orElse(null);
- if (schedule != null) {
- // DO not innclude in the results
- schedule.setScheduleInfo(null);
- // schedule.setSchedule(null);
- scheduleMap.put(cms.getSchedulesUuid(), schedule);
- }
- }
- if (scheduleMap.containsKey(cms.getSchedulesUuid())) {
- msg.setScheduleRequest(scheduleMap.get(cms.getSchedulesUuid()));
- }
- return msg;
- }
-
-}
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
index 9877d33..2e9ade3 100644
--- 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
@@ -1,33 +1,28 @@
/*
- * 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;
@@ -41,182 +36,213 @@ import org.onap.optf.cmso.common.LogMessages;
import org.onap.optf.cmso.common.exceptions.CMSException;
import org.onap.optf.cmso.model.DomainData;
+/**
+ * The Class CmQueryParameters.
+ */
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"),
- ;
+ /**
+ * The Enum QueryColumns.
+ */
+ 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 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;
- }
+ 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;
- }
+ /**
+ * Gets the query column.
+ *
+ * @param urlName the url name
+ * @return the query column
+ */
+ 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);
- }
+ /**
+ * Builds the clause.
+ *
+ * @param urlName the url name
+ * @param values the values
+ * @return the string
+ * @throws CMSException the CMS exception
+ */
+ 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 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 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 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 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);
- }
+ 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();
- // }
- //
- // }
+ // 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/CmsoOptimizedScheduleService.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleService.java
new file mode 100644
index 0000000..9874ea8
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleService.java
@@ -0,0 +1,72 @@
+/*
+ * 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 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.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.optf.cmso.common.CMSRequestError;
+import org.onap.optf.cmso.service.rs.models.v2.OptimizedScheduleMessage;
+
+@Api("CMSO Optimized Schedule API")
+@Path("/{apiVersion}")
+@Produces({MediaType.APPLICATION_JSON})
+public interface CmsoOptimizedScheduleService {
+
+ // ******************************************************************
+ @POST
+ @Path("/schedules/optimized/{scheduleId}")
+ @Produces({MediaType.APPLICATION_JSON})
+ @ApiOperation(value = "", notes = "Creates a request for an optimized schedule")
+ @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")
+ OptimizedScheduleMessage scheduleMessage);
+
+
+}
diff --git a/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleServiceImpl.java b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleServiceImpl.java
new file mode 100644
index 0000000..377c250
--- /dev/null
+++ b/cmso-service/src/main/java/org/onap/optf/cmso/service/rs/CmsoOptimizedScheduleServiceImpl.java
@@ -0,0 +1,80 @@
+/*
+ * 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.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 org.onap.observations.Observation;
+import org.onap.optf.cmso.common.LogMessages;
+import org.onap.optf.cmso.common.exceptions.CMSException;
+import org.onap.optf.cmso.service.rs.models.v2.OptimizedScheduleMessage;
+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;
+
+@Controller
+public class CmsoOptimizedScheduleServiceImpl extends CommonServiceImpl implements CmsoOptimizedScheduleService {
+ private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
+
+ @Autowired
+ Environment env;
+
+
+ @Context
+ HttpServletRequest request;
+
+ @Override
+ @Transactional
+ public Response createScheduleRequest(String apiVersion, String scheduleId,
+ OptimizedScheduleMessage scheduleMessage) {
+ Observation.report(LogMessages.CREATE_SCHEDULE_REQUEST, "Received", request.getRemoteAddr(), scheduleId,
+ scheduleMessage.toString());
+ Response response = null;
+ try {
+ createSchedule(scheduleMessage, scheduleId, request);
+ response = Response.accepted().build();
+ } catch (CMSException e) {
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ Observation.report(LogMessages.EXPECTED_EXCEPTION, e, e.getMessage());
+ response = Response.status(e.getStatus()).entity(e.getRequestError()).build();
+ } catch (Exception e) {
+ Observation.report(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+ response = Response.serverError().build();
+ }
+ Observation.report(LogMessages.CREATE_SCHEDULE_REQUEST, "Returned", request.getRemoteAddr(), scheduleId,
+ response.getStatusInfo().toString());
+ return response;
+ }
+
+
+}
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/CmsoOptimizerCallback.java
index cc2785e..d6cefb6 100644
--- 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/CmsoOptimizerCallback.java
@@ -1,66 +1,64 @@
-/*
- * 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.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.MediaType;
-import javax.ws.rs.core.Response;
-
-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("CMSO Optimized Schedule 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);
-
-}
+/*
+ * 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 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.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.onap.optf.cmso.optimizer.bean.CMOptimizerResponse;
+
+@Api("CMSO Optimized Schedule API")
+@Path("/{apiVersion}")
+@Produces({MediaType.APPLICATION_JSON})
+public interface CmsoOptimizerCallback {
+
+ // ******************************************************************
+ @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);
+
+}