From 4f82c56ca62b266d007f240c7b57d11cadd5f0b3 Mon Sep 17 00:00:00 2001 From: "Smokowski, Steven" Date: Tue, 18 Jun 2019 17:04:18 -0400 Subject: support no payload for alacarte deletes Swap to using HTTP Enumerations rather than ints Add Unit Tests to Service Instances endpoint Add Vnf Tests remove Abstract class Clean up usage of abstract classes Fix volume and module bean wiring issues Add logic to find create request if cloud not in AAI Updated network to take in version pathparam Additonal refactor of the endpoints Add missing license headers to all files Clean up public variable usage, move to protected Change-Id: Icdbdf78aa6c8af7a30fdff8a5805103f8df9364d Issue-ID: SO-2032 Signed-off-by: Benjamin, Max (mb388a) --- .../apihandler/filters/ResponseUpdateFilter.java | 103 +++++++++++++++++++++ .../so/apihandler/filters/ResponseUpdater.java | 34 +++++++ .../org/onap/so/apihandlerinfra/ModelType.java | 28 ------ .../exceptions/DuplicateRequestException.java | 1 + .../exceptions/RecipeNotFoundException.java | 1 + 5 files changed, 139 insertions(+), 28 deletions(-) create mode 100644 mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdateFilter.java create mode 100644 mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdater.java delete mode 100644 mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/ModelType.java (limited to 'mso-api-handlers/mso-api-handler-common/src/main/java/org') diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdateFilter.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdateFilter.java new file mode 100644 index 0000000000..eb52625bb6 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdateFilter.java @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandler.filters; + +import java.io.IOException; +import java.sql.Timestamp; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.Provider; +import javax.ws.rs.ext.Providers; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.apihandlerinfra.Status; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.serviceinstancebeans.RequestError; +import org.onap.so.serviceinstancebeans.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +@Provider +@ResponseUpdater +public class ResponseUpdateFilter implements ContainerResponseFilter { + + protected static Logger logger = LoggerFactory.getLogger(ResponseUpdateFilter.class); + + @Context + private HttpServletRequest httpServletRequest; + + @Context + private Providers providers; + + @Autowired + protected RequestsDbClient infraActiveRequestsClient; + + @Override + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) + throws IOException { + try { + logger.info("updating requests status"); + updateRequestDBToFailed(responseContext); + } catch (Exception e) { + logger.warn("Error in outgoing JAX-RS Inteceptor updating request db to failed", e); + } + } + + private void updateRequestDBToFailed(ContainerResponseContext responseContext) { + String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID); + if (requestId != null && !Response.Status.Family.familyOf(responseContext.getStatus()) + .equals(Response.Status.Family.SUCCESSFUL)) { + InfraActiveRequests currentRequest = infraActiveRequestsClient.getInfraActiveRequestbyRequestId(requestId); + if (currentRequest != null) { + Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); + RequestError error; + try { + error = (RequestError) responseContext.getEntity(); + } catch (Exception e) { + logger.warn("Error Casting Entity to Request Error, generating unknown Error", e); + error = new RequestError(); + ServiceException serviceException = new ServiceException(); + serviceException.setText("Unknown Error Occured during processing"); + error.setServiceException(serviceException); + } + if (error.getServiceException() != null && error.getServiceException().getText() != null + && !error.getServiceException().getText().isEmpty()) { + currentRequest.setStatusMessage(error.getServiceException().getText()); + } else { + currentRequest.setStatusMessage("Unknown Error Occured during processing"); + } + currentRequest.setRequestStatus(Status.FAILED.toString()); + currentRequest.setEndTime(endTimeStamp); + currentRequest.setProgress(100L); + infraActiveRequestsClient.updateInfraActiveRequests(currentRequest); + } + } + } +} + diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdater.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdater.java new file mode 100644 index 0000000000..eb2dad03f3 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdater.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandler.filters; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import javax.ws.rs.NameBinding; + + +@NameBinding +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD}) +public @interface ResponseUpdater { +} diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/ModelType.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/ModelType.java deleted file mode 100644 index 0c10599a52..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/ModelType.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.apihandlerinfra; - -/* - * Enum for Status values returned by API Handler to Tail-F - */ -public enum ModelType { - service, vnf, vfModule, volumeGroup, network -} diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/DuplicateRequestException.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/DuplicateRequestException.java index 21e9b44b19..42198e2d0c 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/DuplicateRequestException.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/DuplicateRequestException.java @@ -30,6 +30,7 @@ public class DuplicateRequestException extends ApiException { } + public static class Builder extends ApiException.Builder { diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/RecipeNotFoundException.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/RecipeNotFoundException.java index 620103be4e..3b62e318e4 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/RecipeNotFoundException.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/RecipeNotFoundException.java @@ -27,6 +27,7 @@ public class RecipeNotFoundException extends ApiException { super(builder); } + public static class Builder extends ApiException.Builder { -- cgit 1.2.3-korg