diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common/src/main/java/org/onap')
-rw-r--r-- | mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdateFilter.java | 103 | ||||
-rw-r--r-- | mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdater.java (renamed from mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/ModelType.java) | 20 | ||||
-rw-r--r-- | mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/DuplicateRequestException.java | 1 | ||||
-rw-r--r-- | mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/RecipeNotFoundException.java | 1 |
4 files changed, 118 insertions, 7 deletions
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/apihandlerinfra/ModelType.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/filters/ResponseUpdater.java index 0c10599a52..eb2dad03f3 100644 --- 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/apihandler/filters/ResponseUpdater.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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. @@ -18,11 +18,17 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.apihandlerinfra; +package org.onap.so.apihandler.filters; -/* - * Enum for Status values returned by API Handler to Tail-F - */ -public enum ModelType { - service, vnf, vfModule, volumeGroup, network +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/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<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<Builder> { |