diff options
4 files changed, 72 insertions, 13 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java index 87e5a2f23e..60e9c3b30a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java @@ -518,20 +518,16 @@ public class RequestHandlerUtils extends AbstractRestHandler { } protected String setServiceInstanceId(String requestScope, ServiceInstancesRequest sir) { + String serviceInstanceId = null; if (sir.getServiceInstanceId() != null) { - return sir.getServiceInstanceId(); - } else if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) { - RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList(); - if (relatedInstances != null) { - for (RelatedInstanceList relatedInstanceList : relatedInstances) { - RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); - if (relatedInstance.getModelInfo().getModelType() == ModelType.service) { - return relatedInstance.getInstanceId(); - } - } + serviceInstanceId = sir.getServiceInstanceId(); + } else { + Optional<String> serviceInstanceIdForInstance = getServiceInstanceIdForInstanceGroup(requestScope, sir); + if (serviceInstanceIdForInstance.isPresent()) { + serviceInstanceId = serviceInstanceIdForInstance.get(); } } - return null; + return serviceInstanceId; } private String requestScopeFromUri(String requestUri) { @@ -916,6 +912,30 @@ public class RequestHandlerUtils extends AbstractRestHandler { return null; } + protected Optional<String> getServiceInstanceIdForValidationError(ServiceInstancesRequest sir, + HashMap<String, String> instanceIdMap, String requestScope) { + if (instanceIdMap != null && !instanceIdMap.isEmpty() && instanceIdMap.get("serviceInstanceId") != null) { + return Optional.of(instanceIdMap.get("serviceInstanceId")); + } else { + return getServiceInstanceIdForInstanceGroup(requestScope, sir); + } + } + + protected Optional<String> getServiceInstanceIdForInstanceGroup(String requestScope, ServiceInstancesRequest sir) { + if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) { + RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList(); + if (relatedInstances != null) { + for (RelatedInstanceList relatedInstanceList : relatedInstances) { + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + if (relatedInstance.getModelInfo().getModelType() == ModelType.service) { + return Optional.ofNullable(relatedInstance.getInstanceId()); + } + } + } + } + return Optional.empty(); + } + private RecipeLookupResult getDefaultVnfUri(ServiceInstancesRequest sir, Actions action) { String defaultSource = getDefaultModel(sir); VnfRecipe vnfRecipe = catalogDbClient.getFirstVnfRecipeByNfRoleAndAction(defaultSource, action.toString()); 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 107aa57974..2c8e92633c 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 @@ -829,7 +829,8 @@ public class ServiceInstances extends AbstractRestHandler { requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action); } catch (ApiException e) { msoRequest.createErrorRequestRecord(Status.FAILED, requestId, e.getMessage(), action, requestScope, - requestJSON, sir.getServiceInstanceId()); + requestJSON, requestHandlerUtils + .getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).orElse(null)); throw e; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java index 7f9ff98b19..2ba646fba0 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java @@ -39,6 +39,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.HashMap; import java.util.List; import javax.ws.rs.core.MediaType; import org.apache.http.HttpStatus; @@ -338,4 +339,34 @@ public class RequestHandlerUtilsTest extends BaseTest { assertEquals(expectedBasicAuth, basicAuth); } + @Test + public void getServiceInstanceIdForValidationErrorTest() { + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + String requestScope = "vnf"; + HashMap<String, String> instanceIdMap = new HashMap<String, String>(); + instanceIdMap.put("serviceInstanceId", "testServiceInstanceId"); + String serviceInstanceId = + requestHandlerUtils.getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).get(); + assertEquals("testServiceInstanceId", serviceInstanceId); + } + + @Test + public void getServiceInstanceIdForValidationErrorInstanceGroupTest() throws Exception { + ServiceInstancesRequest sir = + mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class); + String requestScope = "instanceGroup"; + String serviceInstanceId = + requestHandlerUtils.getServiceInstanceIdForValidationError(sir, null, requestScope).get(); + assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", serviceInstanceId); + } + + @Test + public void getServiceInstanceIdForInstanceGroupTest() throws Exception { + ServiceInstancesRequest sir = + mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class); + String requestScope = "instanceGroup"; + String serviceInstanceId = requestHandlerUtils.getServiceInstanceIdForInstanceGroup(requestScope, sir).get(); + assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", serviceInstanceId); + } + } diff --git a/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml b/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml index dd14091daf..e4be7094df 100644 --- a/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml +++ b/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml @@ -56,6 +56,12 @@ \t%thread \t%n" /> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>${errorPattern}</pattern> + </encoder> + </appender> + <appender name="Audit" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"> @@ -186,11 +192,12 @@ <appender-ref ref="asyncMetric" /> </logger> - <root level="WARN"> + <root level="INFO"> <appender-ref ref="asyncDebug" /> <appender-ref ref="asyncError" /> <appender-ref ref="asyncAudit" /> <appender-ref ref="asyncMetric" /> + <appender-ref ref="STDOUT" /> </root> </configuration>
\ No newline at end of file |