diff options
Diffstat (limited to 'mso-api-handlers')
14 files changed, 624 insertions, 54 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java index 0a60bff875..7ee8654013 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java @@ -299,6 +299,11 @@ public class OrchestrationRequests { ir.setVolumeGroupInstanceName(iar.getVolumeGroupName()); if(iar.getRequestorId() != null) ir.setRequestorId(iar.getRequestorId()); + if(iar.getInstanceGroupId() != null) + ir.setInstanceGroupId(iar.getInstanceGroupId()); + if(iar.getInstanceGroupName() != null) + ir.setInstanceGroupName(iar.getInstanceGroupName()); + request.setInstanceReferences(ir); @@ -335,21 +340,24 @@ public class OrchestrationRequests { } if(flowStatusMessage != null){ if(statusMessages != null){ - statusMessages = statusMessages + "/"; + statusMessages = statusMessages + " " + "FLOW STATUS: " + flowStatusMessage; + }else{ + statusMessages = "FLOW STATUS: " + flowStatusMessage; } - statusMessages = statusMessages + "FLOW STATUS: " + flowStatusMessage; } if(retryStatusMessage != null){ if(statusMessages != null){ - statusMessages = statusMessages + "/"; + statusMessages = statusMessages + " " + "RETRY STATUS: " + retryStatusMessage; + }else{ + statusMessages = "RETRY STATUS: " + retryStatusMessage; } - statusMessages = statusMessages + "RETRY STATUS: " + retryStatusMessage; } if(rollbackStatusMessage != null){ if(statusMessages != null){ - statusMessages = statusMessages + "/"; + statusMessages = statusMessages + " " + "ROLLBACK STATUS: " + rollbackStatusMessage; + }else{ + statusMessages = "ROLLBACK STATUS: " + rollbackStatusMessage; } - statusMessages = statusMessages + "ROLLBACK STATUS: " + rollbackStatusMessage; } if(statusMessages != null){ status.setStatusMessage(statusMessages); @@ -358,6 +366,10 @@ public class OrchestrationRequests { String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getEndTime()) + " GMT"; status.setFinishTime(endTimeStamp); } + if(iar.getModifyTime() != null){ + String timeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getModifyTime()) + " GMT"; + status.setTimeStamp(timeStamp); + } if(iar.getRequestStatus() != null){ 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 0cd5d8dcb7..676dca101b 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 @@ -692,7 +692,7 @@ public class ServiceInstances { sir = convertJsonToServiceInstanceRequest(requestJSON, action, startTime, sir, msoRequest, requestId, requestUri); String requestScope = deriveRequestScope(action, sir, requestUri); - InfraActiveRequests currentActiveReq = msoRequest.createRequestObject (sir, action, requestId, Status.PENDING, requestJSON, requestScope); + InfraActiveRequests currentActiveReq = msoRequest.createRequestObject (sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope); if(sir.getRequestDetails().getRequestParameters() != null){ aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte(); } @@ -705,7 +705,6 @@ public class ServiceInstances { String vnfType = msoRequest.getVnfType(sir,requestScope,action,requestVersion); String networkType = msoRequest.getNetworkType(sir,requestScope); String sdcServiceModelVersion = msoRequest.getSDCServiceModelVersion(sir); - String serviceInstanceType = msoRequest.getServiceInstanceType(sir,requestScope); String vfModuleType = msoRequest.getVfModuleType(sir,requestScope,action,requestVersion); if(requestScope.equalsIgnoreCase(ModelType.vnf.name()) && vnfType != null){ @@ -732,7 +731,7 @@ public class ServiceInstances { Boolean isBaseVfModule = false; RecipeLookupResult recipeLookupResult = getServiceInstanceOrchestrationURI(sir, action, alaCarteFlag, currentActiveReq); - + String serviceInstanceType = getServiceType(requestScope, sir, alaCarteFlag); ModelType modelType; ModelInfo modelInfo = sir.getRequestDetails().getModelInfo(); if (action == Action.applyUpdatedConfig || action == Action.inPlaceSoftwareUpdate) { @@ -820,7 +819,7 @@ public class ServiceInstances { .errorInfo(errorLoggerInfo).build(); } - if(!requestScope.equalsIgnoreCase(ModelType.service.name())){ + if(!requestScope.equalsIgnoreCase(ModelType.service.name()) && action != Action.recreateInstance){ aLaCarte = true; }else if(aLaCarte == null){ aLaCarte = false; @@ -864,7 +863,7 @@ public class ServiceInstances { sir.setInstanceGroupId(instanceGroupId); String requestScope = ModelType.instanceGroup.toString(); - InfraActiveRequests currentActiveReq = msoRequest.createRequestObject (sir, action, requestId, Status.PENDING, null, requestScope); + InfraActiveRequests currentActiveReq = msoRequest.createRequestObject (sir, action, requestId, Status.IN_PROGRESS, null, requestScope); setInstanceId(currentActiveReq, requestScope, null, instanceIdMap); try { validateHeaders(requestContext); @@ -1018,19 +1017,7 @@ public class ServiceInstances { .errorInfo(errorLoggerInfo).build(); updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage()); throw validateException; - } - - currentActiveReq.setRequestStatus(Status.IN_PROGRESS.name()); - setInstanceId(currentActiveReq, requestScope, jsonResponse.getRequestReferences().getInstanceId(), new HashMap<>()); - - try{ - infraActiveRequestsClient.save(currentActiveReq); - }catch(Exception e){ - ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, MsoLogger.ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); - throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e) - .errorInfo(errorLoggerInfo).build(); - } - + } return builder.buildResponse(HttpStatus.SC_ACCEPTED, requestClientParameter.getRequestId(), jsonResponse, requestClientParameter.getApiVersion()); } } @@ -1869,4 +1856,30 @@ public class ServiceInstances { } } } + protected String getServiceType(String requestScope, ServiceInstancesRequest sir, Boolean aLaCarteFlag){ + String serviceType = null; + if(requestScope.equalsIgnoreCase(ModelType.service.toString())){ + String defaultServiceModelName = getDefaultModel(sir); + org.onap.so.db.catalog.beans.Service serviceRecord; + if(aLaCarteFlag){ + serviceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName); + if(serviceRecord != null){ + serviceType = serviceRecord.getServiceType(); + } + }else{ + serviceRecord = catalogDbClient.getServiceByID(sir.getRequestDetails().getModelInfo().getModelVersionId()); + if(serviceRecord != null){ + serviceType = serviceRecord.getServiceType(); + }else{ + serviceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName); + if(serviceRecord != null){ + serviceType = serviceRecord.getServiceType(); + } + } + } + }else{ + serviceType = msoRequest.getServiceInstanceType(sir, requestScope); + } + return serviceType; + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java index f83e707258..60a05d74e5 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/GrmClientPropertiesImpl.java @@ -32,15 +32,14 @@ import org.springframework.context.ApplicationContext; public class GrmClientPropertiesImpl implements GRMProperties { private String grmEndpoint; - private String grmUsername; - private String grmPassword; + private String grmAuth; + private String grmKey; public GrmClientPropertiesImpl() { - ApplicationContext context = SpringContextHelper.getAppContext(); - + ApplicationContext context = SpringContextHelper.getAppContext(); grmEndpoint = context.getEnvironment().getProperty("mso.grm.endpoint"); - grmUsername = context.getEnvironment().getProperty("mso.grm.username"); - grmPassword = context.getEnvironment().getProperty("mso.grm.password"); + grmAuth = context.getEnvironment().getProperty("mso.grm.auth"); + grmKey = context.getEnvironment().getProperty("mso.msoKey"); } @Override @@ -59,13 +58,13 @@ public class GrmClientPropertiesImpl implements GRMProperties { } @Override - public String getUsername() { - return grmUsername; + public String getAuth() { + return grmAuth; } @Override - public String getPassword() { - return grmPassword; + public String getKey() { + return grmKey; } @Override 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 8a4d561fbd..4e8e9562ce 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 @@ -21,9 +21,6 @@ package org.onap.so.apihandlerinfra.tenantisolation.helpers; import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; @@ -36,6 +33,7 @@ import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; import org.onap.so.client.HttpClient; +import org.onap.so.client.HttpClientFactory; import org.onap.so.logger.MessageEnum; import org.onap.so.logger.MsoLogger; import org.onap.so.utils.CryptoUtils; @@ -53,6 +51,7 @@ public class SDCClientHelper { private static String MESSAGE_UNDEFINED_ERROR = "Undefined Error Message!"; private static String MESSAGE_UNEXPECTED_FORMAT = "Unexpected response format from SDC."; + private final HttpClientFactory httpClientFactory = new HttpClientFactory(); @Value("${mso.sdc.endpoint}") private String sdcEndpoint; @@ -91,7 +90,7 @@ public class SDCClientHelper { URL url = new URL(urlString); - HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.SDC); + HttpClient httpClient = httpClientFactory.newJsonClient(url, TargetEntity.SDC); httpClient.addBasicAuthHeader(sdcClientAuth, msoKey); Response apiResponse = setHttpPostResponse(httpClient, jsonPayload); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/RelatedInstancesValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/RelatedInstancesValidation.java index c4671aed3c..a6fdcc958d 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/RelatedInstancesValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/RelatedInstancesValidation.java @@ -133,7 +133,7 @@ public class RelatedInstancesValidation implements ValidationRule{ if(InstanceDirection.source.equals(relatedInstance.getInstanceDirection()) && relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)) { isSourceVnfPresent = true; } else if(InstanceDirection.destination.equals(relatedInstance.getInstanceDirection()) && - (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) || (relatedInstanceModelInfo.getModelType().equals(ModelType.pnf) && reqVersion == 6))) { + (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) || (relatedInstanceModelInfo.getModelType().equals(ModelType.pnf)))) { isDestinationVnfPresent = true; } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java index 58d6b7f1c7..4a6a59bebb 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java @@ -118,13 +118,41 @@ public class OrchestrationRequestsTest extends BaseTest { assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); assertThat(response.getBody(), - sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.requestStatus.finishTime")); + sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.requestStatus.finishTime") + .ignoring("request.requestStatus.timeStamp")); assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0)); assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0)); assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0)); assertEquals("00032ab7-na18-42e5-965d-8ea592502018", response.getHeaders().get("X-TransactionID").get(0)); } + + @Test + public void testGetOrchestrationRequestInstanceGroup() throws Exception { + setupTestGetOrchestrationRequestInstanceGroup(); + // TEST VALID REQUEST + GetOrchestrationResponse testResponse = new GetOrchestrationResponse(); + + Request request = ORCHESTRATION_LIST.getRequestList().get(8).getRequest(); + testResponse.setRequest(request); + String testRequestId = request.getRequestId(); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + HttpEntity<Request> entity = new HttpEntity<Request>(null, headers); + + UriComponentsBuilder builder = UriComponentsBuilder + .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId)); + + ResponseEntity<GetOrchestrationResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, + entity, GetOrchestrationResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), + sameBeanAs(testResponse).ignoring("request.startTime") + .ignoring("request.requestStatus.finishTime") + .ignoring("request.requestStatus.timeStamp")); + } @Test public void testGetOrchestrationRequestRequestDetails() throws Exception { @@ -149,7 +177,9 @@ public class OrchestrationRequestsTest extends BaseTest { assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); assertThat(response.getBody(), - sameBeanAs(testResponse).ignoring("request.startTime").ignoring("request.requestStatus.finishTime")); + sameBeanAs(testResponse).ignoring("request.startTime") + .ignoring("request.requestStatus.finishTime") + .ignoring("request.requestStatus.timeStamp")); assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0)); assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0)); assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); @@ -197,7 +227,9 @@ public class OrchestrationRequestsTest extends BaseTest { ResponseEntity<GetOrchestrationListResponse> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationListResponse.class); assertThat(response.getBody(), - sameBeanAs(testResponse).ignoring("requestList.request.startTime").ignoring("requestList.request.requestStatus.finishTime")); + sameBeanAs(testResponse).ignoring("requestList.request.startTime") + .ignoring("requestList.request.requestStatus.finishTime") + .ignoring("requestList.request.requestStatus.timeStamp")); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); assertEquals(requests.size(), response.getBody().getRequestList().size()); @@ -401,6 +433,17 @@ public class OrchestrationRequestsTest extends BaseTest { .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json")))) .withStatus(HttpStatus.SC_OK))); } + public void setupTestGetOrchestrationRequestInstanceGroup() throws Exception{ + //For testGetOrchestrationRequest + stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-na18-42e5-965d-8ea592502018")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json")))) + .withStatus(HttpStatus.SC_OK))); + stubFor(get(urlPathEqualTo("/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/")) + .withQueryParam("SO_REQUEST_ID", equalTo("00032ab7-na18-42e5-965d-8ea592502018")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/getRequestProcessingData.json")))) + .withStatus(HttpStatus.SC_OK))); + } private void setupTestGetOrchestrationRequestRequestDetails(String requestId, String status) throws Exception{ stubFor(get(urlPathEqualTo(getTestUrl(requestId))).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) 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 8d3649a65d..168df1903a 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 @@ -55,7 +55,9 @@ import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.logger.MsoLogger; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.RequestDetails; import org.onap.so.serviceinstancebeans.RequestError; +import org.onap.so.serviceinstancebeans.RequestInfo; import org.onap.so.serviceinstancebeans.RequestParameters; import org.onap.so.serviceinstancebeans.RequestReferences; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -70,6 +72,7 @@ import org.springframework.util.ResourceUtils; import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.http.Fault; @@ -2582,4 +2585,93 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } + @Test + public void setServiceTypeTestALaCarte() throws JsonProcessingException{ + String requestScope = ModelType.service.toString(); + Boolean aLaCarteFlag = true; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setSource("VID"); + requestDetails.setRequestInfo(requestInfo); + sir.setRequestDetails(requestDetails); + Service defaultService = new Service(); + defaultService.setServiceType("testServiceTypeALaCarte"); + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + String serviceType = servInstances.getServiceType(requestScope, sir, aLaCarteFlag); + assertEquals(serviceType, "testServiceTypeALaCarte"); + } + @Test + public void setServiceTypeTest() throws JsonProcessingException{ + String requestScope = ModelType.service.toString(); + Boolean aLaCarteFlag = false; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a"); + requestInfo.setSource("VID"); + requestDetails.setModelInfo(modelInfo); + requestDetails.setRequestInfo(requestInfo); + sir.setRequestDetails(requestDetails); + Service defaultService = new Service(); + defaultService.setServiceType("testServiceType"); + + stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + String serviceType = servInstances.getServiceType(requestScope, sir, aLaCarteFlag); + assertEquals(serviceType, "testServiceType"); + } + @Test + public void setServiceTypeTestDefault() throws JsonProcessingException{ + String requestScope = ModelType.service.toString(); + Boolean aLaCarteFlag = false; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelVersionId("0dd91181-49da-446b-b839-cd959a96f04a"); + requestInfo.setSource("VID"); + requestDetails.setModelInfo(modelInfo); + requestDetails.setRequestInfo(requestInfo); + sir.setRequestDetails(requestDetails); + Service defaultService = new Service(); + defaultService.setServiceType("testServiceType"); + + stubFor(get(urlMatching(".*/service/0dd91181-49da-446b-b839-cd959a96f04a")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_NOT_FOUND))); + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + String serviceType = servInstances.getServiceType(requestScope, sir, aLaCarteFlag); + assertEquals(serviceType, "testServiceType"); + } + @Test + public void setServiceTypeTestNetwork() throws JsonProcessingException{ + String requestScope = ModelType.network.toString(); + Boolean aLaCarteFlag = null; + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + RequestDetails requestDetails = new RequestDetails(); + RequestInfo requestInfo = new RequestInfo(); + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelName("networkModelName"); + requestInfo.setSource("VID"); + requestDetails.setModelInfo(modelInfo); + requestDetails.setRequestInfo(requestInfo); + sir.setRequestDetails(requestDetails); + + String serviceType = servInstances.getServiceType(requestScope, sir, aLaCarteFlag); + assertEquals(serviceType, "networkModelName"); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java new file mode 100644 index 0000000000..6555a9a66e --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/client/grm/GRMClientTest.java @@ -0,0 +1,172 @@ +/*- + * ============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.client.grm; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.matching; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.github.tomakehurst.wiremock.client.WireMock.verify; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +import java.io.File; +import java.nio.file.Files; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.apihandlerinfra.BaseTest; +import org.onap.so.apihandlerinfra.TestAppender; +import org.onap.so.client.grm.GRMClient; +import org.onap.so.client.grm.beans.ServiceEndPoint; +import org.onap.so.client.grm.beans.ServiceEndPointList; +import org.onap.so.client.grm.beans.ServiceEndPointLookupRequest; +import org.onap.so.client.grm.beans.ServiceEndPointRequest; +import org.onap.so.client.grm.exceptions.GRMClientCallFailed; +import org.slf4j.MDC; + +import ch.qos.logback.classic.spi.ILoggingEvent; + + +public class GRMClientTest extends BaseTest{ + + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private static final String uuidRegex = "(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-5][0-9a-f]{3}-?[089ab][0-9a-f]{3}-?[0-9a-f]{12}$"; + + @BeforeClass + public static void setUp() throws Exception { + System.setProperty("mso.config.path", "src/test/resources"); + } + + @Test + public void testFind() throws Exception { + TestAppender.events.clear(); + String endpoints = getFileContentsAsString("__files/grm/endpoints.json"); + stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) + .willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withBody(endpoints))); + + MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, "/test"); + GRMClient client = new GRMClient(); + ServiceEndPointList sel = client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); + List<ServiceEndPoint> list = sel.getServiceEndPointList(); + assertEquals(3, list.size()); + + boolean foundInvoke = false; + boolean foundInvokeReturn = false; + for(ILoggingEvent logEvent : TestAppender.events) + if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsClientLogging") && + logEvent.getMarker() != null && logEvent.getMarker().getName().equals("INVOKE") + ){ + Map<String,String> mdc = logEvent.getMDCPropertyMap(); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertEquals("GRM",mdc.get("TargetEntity")); + assertEquals("INPROGRESS",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + foundInvoke=true; + }else if(logEvent.getLoggerName().equals("org.onap.so.logging.jaxrs.filter.JaxRsClientLogging") && + logEvent.getMarker()!= null && logEvent.getMarker().getName().equals("INVOKE_RETURN")){ + Map<String,String> mdc = logEvent.getMDCPropertyMap(); + assertNotNull(mdc.get(ONAPLogConstants.MDCs.INVOCATION_ID)); + assertEquals("200",mdc.get(ONAPLogConstants.MDCs.RESPONSE_CODE)); + assertEquals("COMPLETED",mdc.get(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE)); + foundInvokeReturn=true; + } + + if(!foundInvoke) + fail("INVOKE Marker not found"); + + if(!foundInvokeReturn) + fail("INVOKE RETURN Marker not found"); + + verify(postRequestedFor(urlEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) + .withHeader(ONAPLogConstants.Headers.INVOCATION_ID.toString(), matching(uuidRegex)) + .withHeader(ONAPLogConstants.Headers.REQUEST_ID.toString(), matching(uuidRegex)) + .withHeader(ONAPLogConstants.Headers.PARTNER_NAME.toString(), equalTo("SO"))); + TestAppender.events.clear(); + } + + @Test + public void testFindFail() throws Exception { + stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/findRunning")) + .willReturn(aResponse() + .withStatus(400) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withBody(""))); + + GRMClient client = new GRMClient(); + thrown.expect(GRMClientCallFailed.class); + client.findRunningServices("TEST.ECOMP_PSL.*", 1, "TEST"); + } + + @Test + public void testAddFail() throws Exception { + stubFor(post(urlPathEqualTo("/GRMLWPService/v1/serviceEndPoint/add")) + .willReturn(aResponse() + .withStatus(404) + .withHeader("Content-Type", MediaType.APPLICATION_JSON) + .withBody("test"))); + ServiceEndPointRequest request = new ServiceEndPointRequest(); + GRMClient client = new GRMClient(); + thrown.expect(GRMClientCallFailed.class); + client.addServiceEndPoint(request); + } + + @Test + public void testBuildServiceEndPointLookupRequest() { + GRMClient client = new GRMClient(); + ServiceEndPointLookupRequest request = client.buildServiceEndPointlookupRequest("TEST.ECOMP_PSL.Inventory", 1, "DEV"); + assertEquals("TEST.ECOMP_PSL.Inventory", request.getServiceEndPoint().getName()); + assertEquals(Integer.valueOf(1), Integer.valueOf(request.getServiceEndPoint().getVersion().getMajor())); + assertEquals("DEV", request.getEnv()); + + } + + protected String getFileContentsAsString(String fileName) { + String content = ""; + try { + ClassLoader classLoader = this.getClass().getClassLoader(); + File file = new File(classLoader.getResource(fileName).getFile()); + content = new String(Files.readAllBytes(file.toPath())); + } + catch(Exception e) { + e.printStackTrace(); + System.out.println("Exception encountered reading " + fileName + ". Error: " + e.getMessage()); + } + return content; + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json index 051ac16d77..50654524f1 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationFilterResponse.json @@ -29,7 +29,8 @@ "requestState": "COMPLETE", "statusMessage": "STATUS: COMPLETED", "percentProgress": 100, - "finishTime": "Tue, 02 May 2017 06:33:34 GMT" + "finishTime": "Tue, 02 May 2017 06:33:34 GMT", + "timeStamp": "Fri, 01 Jul 2016 04:41:42 GMT" } } }, @@ -61,9 +62,10 @@ }, "requestStatus": { "requestState": "COMPLETE", - "statusMessage": "STATUS: Vf Module has been deleted successfully./FLOW STATUS: Building blocks 1 of 3 completed./ROLLBACK STATUS: Rollback has been completed successfully.", + "statusMessage": "STATUS: Vf Module has been deleted successfully. FLOW STATUS: Building blocks 1 of 3 completed. ROLLBACK STATUS: Rollback has been completed successfully.", "percentProgress": 100, - "finishTime": "Thu, 22 Dec 2016 08:30:28 GMT" + "finishTime": "Thu, 22 Dec 2016 08:30:28 GMT", + "timeStamp": "Thu, 22 Dec 2016 08:30:28 GMT" } } }, @@ -97,7 +99,8 @@ "requestState": "PENDING", "statusMessage": "STATUS: Vf Module deletion pending.", "percentProgress": 0, - "finishTime": "Thu, 22 Dec 2016 08:30:28 GMT" + "finishTime": "Thu, 22 Dec 2016 08:30:28 GMT", + "timeStamp": "Thu, 22 Dec 2016 08:30:28 GMT" } } }, @@ -181,7 +184,8 @@ "requestState": "UNLOCKED", "statusMessage": "STATUS: Vf Module deletion pending.", "percentProgress": 0, - "finishTime": "Thu, 22 Dec 2016 08:30:28 GMT" + "finishTime": "Thu, 22 Dec 2016 08:30:28 GMT", + "timeStamp": "Mon, 30 Jul 2018 06:09:01 GMT" } } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationList.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationList.json index d24b48ba29..ecbf7a92a4 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationList.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/OrchestrationList.json @@ -27,7 +27,8 @@ "requestStatus":{ "requestState":"COMPLETE", "statusMessage":"STATUS: Vf Module has been deleted successfully.", - "percentProgress":100 + "percentProgress":100, + "timeStamp": "Thu, 22 Dec 2016 08:30:28 GMT" } } }, @@ -57,8 +58,9 @@ }, "requestStatus":{ "requestState":"PENDING", - "statusMessage":"STATUS: Vf Module deletion pending./FLOW STATUS: Building blocks 1 of 3 completed./RETRY STATUS: Retry 2/5 will be started in 8 min./ROLLBACK STATUS: Rollback has been completed successfully.", - "percentProgress":0 + "statusMessage":"FLOW STATUS: Building blocks 1 of 3 completed. RETRY STATUS: Retry 2/5 will be started in 8 min. ROLLBACK STATUS: Rollback has been completed successfully.", + "percentProgress":0, + "timeStamp": "Thu, 22 Dec 2016 08:30:28 GMT" } } }, @@ -293,6 +295,37 @@ "statusMessage":"Error parsing request.\n\tNo valid instanceName is specified" } } + }, + { + "request":{ + "requestId":"00032ab7-na18-42e5-965d-8ea592502018", + "requestScope":"instanceGroup", + "requestType":"addMembers", + "requestDetails":{ + "modelInfo":{ + "modelType":"vfModule", + "modelName":"test::base::module-0" + }, + "requestInfo":{ + "source":"VID", + "suppressRollback":false + }, + "cloudConfiguration":{ + "tenantId":"6accefef3cb442ff9e644d589fb04107", + "lcpCloudRegionId":"n6" + } + }, + "instanceReferences":{ + "instanceGroupId": "00032ab7-na18-42e5-965d-8ea592502019", + "instanceGroupName": "testInstanceGroup" + }, + "requestStatus":{ + "requestState":"PENDING", + "statusMessage":"STATUS: Adding members. FLOW STATUS: Building blocks 1 of 3 completed. RETRY STATUS: Retry 2/5 will be started in 8 min. ROLLBACK STATUS: Rollback has been completed successfully.", + "percentProgress":0, + "timeStamp": "Thu, 22 Dec 2016 08:30:28 GMT" + } + } } ] -}
\ No newline at end of file +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationRequest.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationRequest.json index 97132fa037..8953dfdfe0 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationRequest.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationRequest.json @@ -2,7 +2,7 @@ "clientRequestId": "00032ab7-fake-42e5-965d-8ea592502018", "action": "deleteInstance", "requestStatus": "PENDING", - "statusMessage": "Vf Module deletion pending.", + "statusMessage": null, "progress": 0, "startTime": "2016-12-22T13:29:54.000+0000", "endTime": "2016-12-22T13:30:28.000+0000", diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json new file mode 100644 index 0000000000..e0ea6a805b --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getOrchestrationRequestInstanceGroup.json @@ -0,0 +1,59 @@ +{ + "clientRequestId": "00032ab7-fake-42e5-965d-8ea592502018", + "action": "addMembers", + "requestStatus": "PENDING", + "statusMessage": "Adding members.", + "progress": 0, + "startTime": "2016-12-22T13:29:54.000+0000", + "endTime": "2016-12-22T13:30:28.000+0000", + "source": "VID", + "vnfId": null, + "vnfName": null, + "vnfType": null, + "serviceType": null, + "aicNodeClli": null, + "tenantId": "6accefef3cb442ff9e644d589fb04107", + "provStatus": null, + "vnfParams": null, + "vnfOutputs": null, + "requestBody": "{\"requestDetails\": {\"modelInfo\":{\"modelType\":\"vfModule\",\"modelName\":\"test::base::module-0\"},\"requestInfo\":{\"source\":\"VID\"},\"cloudConfiguration\":{\"tenantId\":\"6accefef3cb442ff9e644d589fb04107\",\"lcpCloudRegionId\":\"n6\"}}}", + "responseBody": null, + "lastModifiedBy": "BPMN", + "modifyTime": "2016-12-22T13:30:28.000+0000", + "requestType": null, + "volumeGroupId": null, + "volumeGroupName": null, + "vfModuleId": null, + "vfModuleName": null, + "vfModuleModelName": "test::base::module-0", + "aaiServiceId": null, + "aicCloudRegion": "n6", + "callBackUrl": null, + "correlator": null, + "serviceInstanceId": null, + "serviceInstanceName": null, + "requestScope": "instanceGroup", + "requestAction": "addMembers", + "networkId": null, + "networkName": null, + "networkType": null, + "requestorId": null, + "configurationId": null, + "configurationName": null, + "operationalEnvId": null, + "operationalEnvName": null, + "rollbackStatusMessage": "Rollback has been completed successfully.", + "flowStatus": "Building blocks 1 of 3 completed.", + "retryStatusMessage": "Retry 2/5 will be started in 8 min.", + "requestURI": "00032ab7-na18-42e5-965d-8ea592502018", + "instanceGroupId": "00032ab7-na18-42e5-965d-8ea592502019", + "instanceGroupName": "testInstanceGroup", + "_links": { + "self": { + "href": "http://localhost:8087/infraActiveRequests/00032ab7-na18-42e5-965d-8ea592502018" + }, + "infraActiveRequests": { + "href": "http://localhost:8087/infraActiveRequests/00032ab7-na18-42e5-965d-8ea592502018" + } + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json new file mode 100644 index 0000000000..7e92c21c9e --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/grm/endpoints.json @@ -0,0 +1,145 @@ +{ + "serviceEndPointList": [ + { + "name": "dummy.pod.ns.dummy-pod3", + "version": { + "major": 1, + "minor": 0, + "patch": "0" + }, + "hostAddress": "192.168.120.218", + "listenPort": "32004", + "latitude": "37.7022", + "longitude": "121.9358", + "registrationTime": "2017-07-18T15:39:17.367+0000", + "expirationTime": "9999-10-09T15:39:17.368+0000", + "contextPath": "/", + "routeOffer": "DEFAULT", + "statusInfo": { + "status": "RUNNING" + }, + "eventStatusInfo": { + "status": "RUNNING" + }, + "validatorStatusInfo": { + "status": "RUNNING" + }, + "operationalInfo": { + "createdBy": "edge", + "updatedBy": "edge", + "createdTimestamp": "2017-07-18T15:39:17.367+0000", + "updatedTimestamp": "2017-07-18T15:39:17.367+0000" + }, + "protocol": "dummypod-port", + "properties": [ + { + "name": "Environment", + "value": "DEV" + }, + { + "name": "Kubernetes Namespace", + "value": "dummy-pod-ns" + }, + { + "name": "cpfrun_cluster_name", + "value": "CI-PDK1-TFINIT-CJ9125401" + } + ], + "disableType": [] + }, + { + "name": "dummy.pod.ns.dummy-pod3", + "version": { + "major": 1, + "minor": 0, + "patch": "0" + }, + "hostAddress": "192.168.120.22", + "listenPort": "32004", + "latitude": "1.0", + "longitude": "1.0", + "registrationTime": "2017-07-18T15:39:17.816+0000", + "expirationTime": "9999-10-09T15:39:17.817+0000", + "contextPath": "/", + "routeOffer": "DEFAULT", + "statusInfo": { + "status": "RUNNING" + }, + "eventStatusInfo": { + "status": "RUNNING" + }, + "validatorStatusInfo": { + "status": "RUNNING" + }, + "operationalInfo": { + "createdBy": "edge", + "updatedBy": "edge", + "createdTimestamp": "2017-07-18T15:39:17.816+0000", + "updatedTimestamp": "2017-07-18T15:39:17.816+0000" + }, + "protocol": "dummypod-port", + "properties": [ + { + "name": "Environment", + "value": "DEV" + }, + { + "name": "Kubernetes Namespace", + "value": "dummy-pod-ns" + }, + { + "name": "cpfrun_cluster_name", + "value": "CI-PDK1-TFINIT-CJ9125401" + } + ], + "disableType": [] + }, + { + "name": "dummy.pod.ns.dummy-pod1", + "version": { + "major": 1, + "minor": 0, + "patch": "0" + }, + "hostAddress": "192.168.120.218", + "listenPort": "32002", + "latitude": "1.0", + "longitude": "1.0", + "registrationTime": "2017-07-18T15:39:14.443+0000", + "expirationTime": "9999-10-09T15:39:14.453+0000", + "contextPath": "/", + "routeOffer": "DEFAULT", + "statusInfo": { + "status": "RUNNING" + }, + "eventStatusInfo": { + "status": "RUNNING" + }, + "validatorStatusInfo": { + "status": "RUNNING" + }, + "operationalInfo": { + "createdBy": "edge", + "updatedBy": "edge", + "createdTimestamp": "2017-07-18T15:39:14.443+0000", + "updatedTimestamp": "2017-07-18T15:39:14.443+0000" + }, + "protocol": "dummypod-port", + "properties": [ + { + "name": "Environment", + "value": "DEV" + }, + { + "name": "Kubernetes Namespace", + "value": "dummy-pod-ns" + }, + { + "name": "cpfrun_cluster_name", + "value": "CI-PDK1-TFINIT-CJ9125401" + } + ], + "disableType": [] + } + ] +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml index 6e1d6f3376..63eb0534ea 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/application-test.yaml @@ -70,8 +70,7 @@ mso: auth: 5E12ACACBD552A415E081E29F2C4772F9835792A51C766CCFDD7433DB5220B59969CB2798C grm: endpoint: http://localhost:${wiremock.server.port} - username: gmruser - password: test + auth: 6AAD26000E278148A0B987436D9696A5B2D99BBF0DC545F9E64D6DF05298FFA987A6CF565F6F274EBC085678 so: operational-environment: dmaap: |