diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra')
9 files changed, 123 insertions, 198 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandler/filters/RequestUriFilter.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandler/filters/RequestUriFilter.java deleted file mode 100644 index a3ff1ab95d..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandler/filters/RequestUriFilter.java +++ /dev/null @@ -1,61 +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.apihandler.filters; - -import java.io.IOException; -import java.net.URI; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.container.ContainerRequestFilter; -import javax.ws.rs.container.PreMatching; -import javax.ws.rs.core.UriInfo; -import org.onap.so.apihandlerinfra.Constants; - - -@PreMatching -public class RequestUriFilter implements ContainerRequestFilter { - - private String requestURI; - - @Override - public void filter(ContainerRequestContext context) throws IOException { - UriInfo uriInfo = context.getUriInfo(); - URI baseURI = uriInfo.getBaseUri(); - requestURI = uriInfo.getPath(); - - if (requestURI.contains("onap/so/infra/serviceInstances")) { - requestURI = requestURI.replaceFirst("serviceInstances", "serviceInstantiation"); - if (!requestURI.contains(Constants.SERVICE_INSTANCE_PATH)) { - // Adds /serviceInstances after the version provided in the URI - requestURI = new StringBuilder(requestURI) - .insert(requestURI.indexOf(Constants.SERVICE_INSTANTIATION_PATH) + 24, - Constants.SERVICE_INSTANCE_PATH) - .toString(); - } - requestURI = baseURI + requestURI; - URI uri = URI.create(requestURI); - context.setRequestUri(uri); - } - } - - public String getRequestUri() { - return requestURI; - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java index 00d36b3ff9..e162a67680 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java @@ -7,9 +7,9 @@ * 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. @@ -25,7 +25,6 @@ import javax.ws.rs.ApplicationPath; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.servlet.ServletProperties; import org.onap.so.apihandler.filters.RequestIdFilter; -import org.onap.so.apihandler.filters.RequestUriFilter; import org.onap.so.apihandlerinfra.exceptions.ApiExceptionMapper; import org.onap.so.apihandlerinfra.infra.rest.Network; import org.onap.so.apihandlerinfra.infra.rest.ServiceInstance; @@ -72,7 +71,6 @@ public class JerseyConfiguration extends ResourceConfig { register(SwaggerSerializers.class); register(ApiExceptionMapper.class); register(RuntimeExceptionMapper.class); - register(RequestUriFilter.class); register(RequestIdFilter.class); register(E2EServiceInstances.class); register(WorkflowSpecificationsHandler.class); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index b1d38983ec..9b72bdc608 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -444,7 +444,6 @@ public class ServiceInstances extends AbstractRestHandler { requestHandlerUtils.getRequestUri(requestContext, uriPrefix)); } - @DELETE @Path("/{version:[vV][5-7]}/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}") @Consumes(MediaType.APPLICATION_JSON) @@ -593,7 +592,6 @@ public class ServiceInstances extends AbstractRestHandler { requestHandlerUtils.getRequestUri(requestContext, uriPrefix)); } - @POST @Path("/{version:[vV][5-7]}/serviceInstances/{serviceInstanceId}/vnfs/{vnfInstanceId}/volumeGroups") @Consumes(MediaType.APPLICATION_JSON) @@ -766,6 +764,27 @@ public class ServiceInstances extends AbstractRestHandler { requestHandlerUtils.getRequestUri(requestContext, uriPrefix)); } + /** + * This method is used for POST a request to the BPEL client (BPMN). + * + * Convert the requestJson to ServiceInstanceRequest(sir), create the msoRequest object, check whether this request + * is already being processed in requestdb for duplicate check. + * + * Based on the alacarte flag, sir and msoRequest will do the recipe lookup from the service and servicerecipe table + * of catalogdb, and get the OrchestrationURI. + * + * If the present request is not the duplicate request then this request will be saved in the requestdb. and will + * POST a request to the BPMN engine at the OrchestrationURI fetched. + * + * @param requestJSON Json fetched as body in the API call + * @param action Type of action to be performed + * @param instanceIdMap Map of instance ids of service/vnf/vf/configuration etc.. + * @param version Supported version of API + * @param requestId Unique id for the request + * @param requestUri + * @return response object + * @throws ApiException + */ public Response serviceInstances(String requestJSON, Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri) throws ApiException { return serviceInstances(requestJSON, action, instanceIdMap, version, requestId, requestUri, null); @@ -877,6 +896,7 @@ public class ServiceInstances extends AbstractRestHandler { try { infraActiveRequestsClient.save(currentActiveReq); } catch (Exception e) { + logger.error("Exception occurred", e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); @@ -890,6 +910,7 @@ public class ServiceInstances extends AbstractRestHandler { aLaCarte = false; } + RequestClientParameter requestClientParameter = null; try { requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId) @@ -902,6 +923,7 @@ public class ServiceInstances extends AbstractRestHandler { .setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri) .setInstanceGroupId(instanceGroupId).build(); } catch (IOException e) { + logger.error("Exception occurred", e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); @@ -927,6 +949,21 @@ public class ServiceInstances extends AbstractRestHandler { return action; } + /** + * This method deletes the Instance Groups. + * + * This method will check whether the request is not duplicate in requestdb. if its not then will save as a new + * request. And will send a POST request to BEPL client to delete the Insatnce Groups. + * + * @param action + * @param instanceIdMap + * @param version + * @param requestId + * @param requestUri + * @param requestContext + * @return + * @throws ApiException + */ public Response deleteInstanceGroups(Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, ContainerRequestContext requestContext) throws ApiException { String instanceGroupId = instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID); @@ -980,6 +1017,7 @@ public class ServiceInstances extends AbstractRestHandler { try { infraActiveRequestsClient.save(currentActiveReq); } catch (Exception e) { + logger.error("Exception occurred", e); ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); @@ -992,6 +1030,7 @@ public class ServiceInstances extends AbstractRestHandler { .setRequestAction(action.toString()).setApiVersion(apiVersion).setALaCarte(aLaCarte) .setRequestUri(requestUri).setInstanceGroupId(instanceGroupId).build(); + return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope); } @@ -1005,7 +1044,8 @@ public class ServiceInstances extends AbstractRestHandler { protected RecipeLookupResult getServiceInstanceOrchestrationURI(ServiceInstancesRequest sir, Actions action, boolean alaCarteFlag, InfraActiveRequests currentActiveReq) throws ApiException { RecipeLookupResult recipeLookupResult = null; - // if the aLaCarte flag is set to TRUE, the API-H should choose the VID_DEFAULT recipe for the requested action + // if the aLaCarte flag is set to TRUE, the API-H should choose the VID_DEFAULT + // recipe for the requested action ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); // Query MSO Catalog DB @@ -1021,7 +1061,6 @@ public class ServiceInstances extends AbstractRestHandler { new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build(); @@ -1040,7 +1079,6 @@ public class ServiceInstances extends AbstractRestHandler { new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build(); @@ -1058,7 +1096,6 @@ public class ServiceInstances extends AbstractRestHandler { new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build(); @@ -1075,7 +1112,6 @@ public class ServiceInstances extends AbstractRestHandler { new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - RecipeNotFoundException recipeNotFoundExceptionException = new RecipeNotFoundException.Builder("Recipe could not be retrieved from catalog DB.", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).errorInfo(errorLoggerInfo) @@ -1125,7 +1161,8 @@ public class ServiceInstances extends AbstractRestHandler { } } - // if an aLaCarte flag was sent in the request, throw an error if the recipe was not found + // if an aLaCarte flag was sent in the request, throw an error if the recipe was + // not found RequestParameters reqParam = requestDetails.getRequestParameters(); if (reqParam != null && alaCarteFlag && recipe == null) { return null; @@ -1314,23 +1351,32 @@ public class ServiceInstances extends AbstractRestHandler { if (modelInfo.getModelType().equals(ModelType.vnf)) { // a. For a vnf request (only create, no update currently): - // i. (v3-v4) If modelInfo.modelCustomizationId is provided, use it to validate catalog DB has record in + // i. (v3-v4) If modelInfo.modelCustomizationId is provided, use it to validate + // catalog DB has record in // vnf_resource_customization.model_customization_uuid. - // ii. (v2-v4) If modelInfo.modelCustomizationId is NOT provided (because it is a pre-1702 ASDC model or + // ii. (v2-v4) If modelInfo.modelCustomizationId is NOT provided (because it is + // a pre-1702 ASDC model or // pre-v3), then modelInfo.modelCustomizationName must have // been provided (else create request should be rejected). APIH should use the - // relatedInstance.modelInfo[service].modelVersionId** + modelInfo[vnf].modelCustomizationName - // to “join�? service_to_resource_customizations with vnf_resource_customization to confirm a + // relatedInstance.modelInfo[service].modelVersionId** + + // modelInfo[vnf].modelCustomizationName + // to “join�? service_to_resource_customizations with + // vnf_resource_customization to confirm a // vnf_resource_customization.model_customization_uuid record exists. // **If relatedInstance.modelInfo[service].modelVersionId was not provided, use - // relatedInstance.modelInfo[service].modelInvariantId + modelVersion instead to lookup modelVersionId + // relatedInstance.modelInfo[service].modelInvariantId + modelVersion instead to + // lookup modelVersionId // (MODEL_UUID) in SERVICE table. - // iii. Regardless of how the value was provided/obtained above, APIH must always populate - // vnfModelCustomizationId in bpmnRequest. It would be assumed it was MSO generated + // iii. Regardless of how the value was provided/obtained above, APIH must + // always populate + // vnfModelCustomizationId in bpmnRequest. It would be assumed it was MSO + // generated // during 1707 data migration if VID did not provide it originally on request. - // iv. Note: continue to construct the “vnf-type�? value and pass to BPMN (must still be populated + // iv. Note: continue to construct the “vnf-type�? value and pass to BPMN + // (must still be populated // in A&AI). - // 1. If modelCustomizationName is NOT provided on a vnf/vfModule request, use modelCustomizationId to + // 1. If modelCustomizationName is NOT provided on a vnf/vfModule request, use + // modelCustomizationId to // look it up in our catalog to construct vnf-type value to pass to BPMN. VnfResource vnfResource = null; @@ -1461,14 +1507,13 @@ public class ServiceInstances extends AbstractRestHandler { throw new ValidationException("vfModuleCustomization"); } else if (vfModule == null && vfmc != null) { vfModule = vfmc.getVfModule(); // can't be null as vfModuleModelUUID is not-null property in - // VfModuleCustomization table + // VfModuleCustomization table } if (modelInfo.getModelVersionId() == null) { modelInfo.setModelVersionId(vfModule.getModelUUID()); } - recipe = catalogDbClient.getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction( vfModule.getModelUUID(), vnfComponentType, action.toString()); if (recipe == null) { @@ -1531,7 +1576,6 @@ public class ServiceInstances extends AbstractRestHandler { return new RecipeLookupResult(vnfRecipe.getOrchestrationUri(), vnfRecipe.getRecipeTimeout()); } - private RecipeLookupResult getNetworkUri(ServiceInstancesRequest sir, Actions action) throws ValidationException { String defaultNetworkType = requestHandlerUtils.getDefaultModel(sir); @@ -1571,7 +1615,6 @@ public class ServiceInstances extends AbstractRestHandler { return recipe != null ? new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout()) : null; } - private Response configurationRecipeLookup(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri) throws ApiException { String serviceInstanceId; @@ -1610,7 +1653,6 @@ public class ServiceInstances extends AbstractRestHandler { referencesResponse.setRequestId(requestId); serviceResponse.setRequestReferences(referencesResponse); - String orchestrationUri = env.getProperty(CommonConstants.ALACARTE_ORCHESTRATION); String timeOut = env.getProperty(CommonConstants.ALACARTE_RECIPE_TIMEOUT); @@ -1622,7 +1664,6 @@ public class ServiceInstances extends AbstractRestHandler { new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND, ErrorCode.DataError) .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - ValidateException validateException = new ValidateException.Builder(error, HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR).errorInfo(errorLoggerInfo).build(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java index e11732ddc4..20e27a5265 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/handler/AbstractRestHandler.java @@ -111,7 +111,7 @@ public abstract class AbstractRestHandler { String instanceName, String requestScope, InfraActiveRequests currentActiveReq) throws ApiException { InfraActiveRequests dup = null; try { - if (!(instanceName == null && requestScope.equals("service") && (action == Action.createInstance + if (!(instanceName == null && "service".equals(requestScope) && (action == Action.createInstance || action == Action.activateInstance || action == Action.assignInstance))) { dup = infraActiveRequestsClient.checkInstanceNameDuplicate(instanceIdMap, instanceName, requestScope); } @@ -175,7 +175,7 @@ public abstract class AbstractRestHandler { selfLinkUrl = Optional.of(new URL(aUrl.getProtocol(), aUrl.getHost(), aUrl.getPort(), selfLinkPath)); } catch (Exception e) { selfLinkUrl = Optional.empty(); // ignore - logger.error(e.getMessage()); + logger.error("Exception in buildSelfLinkUrl", e); } return selfLinkUrl; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java index efdc52b837..6449b0bb75 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/TenantIsolationRequest.java @@ -92,6 +92,7 @@ public class TenantIsolationRequest { requestJSON = mapper.writeValueAsString(request.getRequestDetails()); } catch (JsonProcessingException e) { + logger.error("Exception in JSON processing", e); throw new ValidationException("Parse ServiceInstanceRequest to JSON string", true); } @@ -325,6 +326,7 @@ public class TenantIsolationRequest { orchestrationFilterParams.put(queryParam, value); } } catch (Exception e) { + logger.error("Exception in getOrchestrationFilters", e); throw new ValidationException(e.getMessage(), true); } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java index b5ba9281a6..18ca6d3086 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java @@ -50,12 +50,19 @@ public class SDCClientHelper { private static Logger logger = LoggerFactory.getLogger(SDCClientHelper.class); private static final String SDC_CONTENT_TYPE = "application/json"; private static final String SDC_ACCEPT_TYPE = "application/json"; - private static String PARTIAL_SDC_URI = "/sdc/v1/catalog/services/"; + private static final String PARTIAL_SDC_URI = "/sdc/v1/catalog/services/"; - private static String MESSAGE_UNDEFINED_ERROR = "Undefined Error Message!"; - private static String MESSAGE_UNEXPECTED_FORMAT = "Unexpected response format from SDC."; + private static final String MESSAGE_UNDEFINED_ERROR = "Undefined Error Message!"; + private static final String MESSAGE_UNEXPECTED_FORMAT = "Unexpected response format from SDC."; private final HttpClientFactory httpClientFactory = new HttpClientFactory(); + private static final String STATUS_CODE = "statusCode"; + private static final String MESSAGE = "message"; + private static final String MESSAGE_ID = "messageId"; + private static final String REQUEST_ERROR = "requestError"; + private static final String SERVICE_EXCEPTION = "serviceException"; + private static final String POLICY_EXCEPTION = "policyException"; + @Value("${mso.sdc.endpoint}") private String sdcEndpoint; @Value("${mso.sdc.activate.userid}") @@ -89,12 +96,11 @@ public class SDCClientHelper { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcesssError) .build(); - ValidateException validateException = new ValidateException.Builder( + + throw new ValidateException.Builder( " SDC credentials 'mso.sdc.client.auth' not setup in properties file!", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo) .build(); - - throw validateException; } URL url = new URL(urlString); @@ -114,12 +120,12 @@ public class SDCClientHelper { sdcResponseJsonObj = enhanceJsonResponse(new JSONObject(responseData), statusCode); } catch (Exception ex) { - logger.debug("calling SDC Exception message: {}", ex.getMessage()); + logger.debug("calling SDC Exception message:", ex); String errorMessage = " Encountered Error while calling SDC POST Activate. " + ex.getMessage(); logger.debug(errorMessage); - sdcResponseJsonObj.put("statusCode", String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); - sdcResponseJsonObj.put("messageId", ""); - sdcResponseJsonObj.put("message", errorMessage); + sdcResponseJsonObj.put(STATUS_CODE, String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); + sdcResponseJsonObj.put(MESSAGE_ID, ""); + sdcResponseJsonObj.put(MESSAGE, errorMessage); } return sdcResponseJsonObj; @@ -139,11 +145,9 @@ public class SDCClientHelper { ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcesssError) .build(); - ValidateException validateException = - new ValidateException.Builder("Bad request could not post payload", HttpStatus.SC_BAD_REQUEST, - ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build(); - throw validateException; + throw new ValidateException.Builder("Bad request could not post payload", HttpStatus.SC_BAD_REQUEST, + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build(); } } @@ -154,7 +158,7 @@ public class SDCClientHelper { * @param statusCode - int * @return enhancedAsdcResponseJsonObj - JSONObject object */ - public JSONObject enhanceJsonResponse(JSONObject sdcResponseJsonObj, int statusCode) throws JSONException { + public JSONObject enhanceJsonResponse(JSONObject sdcResponseJsonObj, int statusCode) { JSONObject enhancedAsdcResponseJsonObj = new JSONObject(); @@ -163,31 +167,31 @@ public class SDCClientHelper { if (statusCode == Response.Status.ACCEPTED.getStatusCode()) { // Accepted enhancedAsdcResponseJsonObj.put("distributionId", sdcResponseJsonObj.get("distributionId")); - enhancedAsdcResponseJsonObj.put("statusCode", Integer.toString(statusCode)); - enhancedAsdcResponseJsonObj.put("messageId", ""); - enhancedAsdcResponseJsonObj.put("message", "Success"); + enhancedAsdcResponseJsonObj.put(STATUS_CODE, Integer.toString(statusCode)); + enhancedAsdcResponseJsonObj.put(MESSAGE_ID, ""); + enhancedAsdcResponseJsonObj.put(MESSAGE, "Success"); } else { // error - if (sdcResponseJsonObj.has("requestError")) { - JSONObject requestErrorObj = sdcResponseJsonObj.getJSONObject("requestError"); - if (sdcResponseJsonObj.getJSONObject("requestError").has("serviceException")) { - message = requestErrorObj.getJSONObject("serviceException").getString("text"); - messageId = requestErrorObj.getJSONObject("serviceException").getString("messageId"); + if (sdcResponseJsonObj.has(REQUEST_ERROR)) { + JSONObject requestErrorObj = sdcResponseJsonObj.getJSONObject(REQUEST_ERROR); + if (sdcResponseJsonObj.getJSONObject(REQUEST_ERROR).has(SERVICE_EXCEPTION)) { + message = requestErrorObj.getJSONObject(SERVICE_EXCEPTION).getString("text"); + messageId = requestErrorObj.getJSONObject(SERVICE_EXCEPTION).getString(MESSAGE_ID); } - if (sdcResponseJsonObj.getJSONObject("requestError").has("policyException")) { - message = requestErrorObj.getJSONObject("policyException").getString("text"); - messageId = requestErrorObj.getJSONObject("policyException").getString("messageId"); + if (sdcResponseJsonObj.getJSONObject(REQUEST_ERROR).has(POLICY_EXCEPTION)) { + message = requestErrorObj.getJSONObject(POLICY_EXCEPTION).getString("text"); + messageId = requestErrorObj.getJSONObject(POLICY_EXCEPTION).getString(MESSAGE_ID); } - enhancedAsdcResponseJsonObj.put("statusCode", Integer.toString(statusCode)); - enhancedAsdcResponseJsonObj.put("messageId", messageId); - enhancedAsdcResponseJsonObj.put("message", message); + enhancedAsdcResponseJsonObj.put(STATUS_CODE, Integer.toString(statusCode)); + enhancedAsdcResponseJsonObj.put(MESSAGE_ID, messageId); + enhancedAsdcResponseJsonObj.put(MESSAGE, message); } else { // unexpected format - enhancedAsdcResponseJsonObj.put("statusCode", + enhancedAsdcResponseJsonObj.put(STATUS_CODE, String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode())); - enhancedAsdcResponseJsonObj.put("messageId", MESSAGE_UNDEFINED_ERROR); - enhancedAsdcResponseJsonObj.put("message", MESSAGE_UNEXPECTED_FORMAT); + enhancedAsdcResponseJsonObj.put(MESSAGE_ID, MESSAGE_UNDEFINED_ERROR); + enhancedAsdcResponseJsonObj.put(MESSAGE, MESSAGE_UNEXPECTED_FORMAT); } } return enhancedAsdcResponseJsonObj; @@ -214,7 +218,7 @@ public class SDCClientHelper { * @return String json * @throws JSONException */ - public String buildJsonWorkloadContext(String workloadContext) throws JSONException { + public String buildJsonWorkloadContext(String workloadContext) { return new JSONObject().put("workloadContext", workloadContext).toString(); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java index 3005abaf9b..3226a0c313 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironment.java @@ -61,16 +61,14 @@ public class ActivateVnfStatusOperationalEnvironment { private OperationalEnvServiceModelStatus queryServiceModelResponse = null; private boolean isOverallSuccess = false; - private final int RETRY_COUNT_ZERO = 0; - private final String ERROR_REASON_ABORTED = "ABORTED"; - private final String RECOVERY_ACTION_RETRY = "RETRY"; - private final String RECOVERY_ACTION_ABORT = "ABORT"; - private final String RECOVERY_ACTION_SKIP = "SKIP"; - private final String DISTRIBUTION_STATUS_OK = DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString(); - private final String DISTRIBUTION_STATUS_ERROR = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString(); - private final String DISTRIBUTION_STATUS_SENT = "SENT"; - - private final String MESSAGE_UNDEFINED_ID = "Undefined Error Message!"; + private static final int RETRY_COUNT_ZERO = 0; + private static final String ERROR_REASON_ABORTED = "ABORTED"; + private static final String RECOVERY_ACTION_RETRY = "RETRY"; + private static final String RECOVERY_ACTION_ABORT = "ABORT"; + private static final String RECOVERY_ACTION_SKIP = "SKIP"; + private static final String DISTRIBUTION_STATUS_OK = DistributionStatus.DISTRIBUTION_COMPLETE_OK.toString(); + private static final String DISTRIBUTION_STATUS_ERROR = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString(); + private static final String DISTRIBUTION_STATUS_SENT = "SENT"; @Autowired private ActivateVnfDBHelper dbHelper; @@ -130,6 +128,7 @@ public class ActivateVnfStatusOperationalEnvironment { } } catch (Exception e) { + logger.error("Exception in execute", e); requestDb.updateInfraFailureCompletion(e.getMessage(), this.origRequestId, this.queryServiceModelResponse.getVnfOperationalEnvId()); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandler/filters/RequestUriFilterTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandler/filters/RequestUriFilterTest.java deleted file mode 100644 index 276b438529..0000000000 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandler/filters/RequestUriFilterTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2018 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 static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import java.io.IOException; -import java.net.URI; -import javax.ws.rs.container.ContainerRequestContext; -import javax.ws.rs.core.UriInfo; -import org.junit.Test; -import org.onap.so.apihandlerinfra.BaseTest; - - - -public class RequestUriFilterTest extends BaseTest { - - @Test - public void filterTest() throws IOException { - RequestUriFilter URIFilter = new RequestUriFilter(); - URI baseURI = URI.create("http://localhost:58879/"); - String requestURI = "onap/so/infra/serviceInstances/v5"; - - ContainerRequestContext mockContext = mock(ContainerRequestContext.class); - UriInfo mockInfo = mock(UriInfo.class); - - when(mockContext.getUriInfo()).thenReturn(mockInfo); - when(mockInfo.getBaseUri()).thenReturn(baseURI); - when(mockInfo.getPath()).thenReturn(requestURI); - - - URIFilter.filter(mockContext); - assertEquals("http://localhost:58879/onap/so/infra/serviceInstantiation/v5/serviceInstances", - URIFilter.getRequestUri()); - } -} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index a79aeb2bd7..48a5343104 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -7,9 +7,9 @@ * 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. @@ -285,14 +285,13 @@ public class ServiceInstancesTest extends BaseTest { requestReferences.setInstanceId("1882939"); requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); - uri = servInstanceUriPrev7 + "v5"; + uri = servInstanceuri + "v5"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstancePrev7.json"), uri, HttpMethod.POST, headers); // then - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + assertEquals(404, response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); - assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test @@ -896,7 +895,7 @@ public class ServiceInstancesTest extends BaseTest { ResponseEntity<String> response = sendRequest(inputStream("/VnfWithServiceRelatedInstanceFail.json"), uri, HttpMethod.POST); - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + assertEquals(404, response.getStatusCode().value()); } @Test @@ -2248,14 +2247,12 @@ public class ServiceInstancesTest extends BaseTest { requestReferences.setInstanceId("1882939"); requestReferences.setRequestSelfLink(createExpectedSelfLink("v5", "32807a28-1a14-4b88-b7b3-2950918aa76d")); expectedResponse.setRequestReferences(requestReferences); - uri = servInstanceUriPrev7 + "v5"; + uri = servInstanceuri + "v5"; ResponseEntity<String> response = sendRequest(inputStream("/MacroServiceInstance.json"), uri, HttpMethod.POST, headers); // then - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); - ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); - assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); + assertEquals(404, response.getStatusCode().value()); } @Test |