aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java46
-rw-r--r--common/src/test/java/org/openecomp/mso/entity/MsoRequestTest.java64
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Action.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java124
4 files changed, 233 insertions, 4 deletions
diff --git a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java
index d1c090dc9e..cf7e26c7b1 100644
--- a/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java
+++ b/adapters/mso-vnf-adapter/src/test/java/org/openecomp/mso/adapters/vnf/MsoVnfAdapterImplTest.java
@@ -23,6 +23,8 @@ package org.openecomp.mso.adapters.vnf;
import java.util.HashMap;
import java.util.Map;
import javax.xml.ws.Holder;
+
+import org.junit.Assert;
import org.junit.Test;
import org.openecomp.mso.adapters.vnf.MsoVnfAdapterImpl;
import org.openecomp.mso.entity.MsoRequest;
@@ -30,7 +32,49 @@ import org.openecomp.mso.openstack.beans.VnfRollback;
public class MsoVnfAdapterImplTest {
- @Test
+ MsoVnfAdapter msoVnfAdapter = new MsoVnfAdapterImpl();
+
+ @Test
+ public void updateVnf() throws Exception {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ msoVnfAdapter.updateVnf("cloudsite", "tenantid", "vfw", "v1", "test",
+ "update", "heatid", new HashMap<>(), msoRequest, new Holder<>(), new Holder<>());
+ Assert.assertTrue(true);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void queryVnfNullPoinerExceptionTest() throws Exception {
+ MsoRequest msoRequest = new MsoRequest();
+ msoRequest.setRequestId("12345");
+ msoRequest.setServiceInstanceId("12345");
+
+ msoVnfAdapter.queryVnf("cloudSiteId",
+ "tenantId",
+ "vnfName",
+ msoRequest,
+ new Holder<>(),
+ new Holder<>(),
+ new Holder<>(),
+ new Holder<>());
+ Assert.assertFalse(true);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void rollbackVnfCloudSiteInfoNotAvail() throws Exception {
+ VnfRollback rollback = new VnfRollback();
+ rollback.setVnfId("vnfid");
+ rollback.setVfModuleStackId("stackid");
+ rollback.setCloudSiteId("11234");
+ rollback.setTenantId("234");
+
+ msoVnfAdapter.rollbackVnf(rollback);
+ Assert.assertFalse(true);
+ }
+
+ @Test
public void healthCheckVNFTest() {
MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl();
instance.healthCheck();
diff --git a/common/src/test/java/org/openecomp/mso/entity/MsoRequestTest.java b/common/src/test/java/org/openecomp/mso/entity/MsoRequestTest.java
new file mode 100644
index 0000000000..a7fc7e223e
--- /dev/null
+++ b/common/src/test/java/org/openecomp/mso/entity/MsoRequestTest.java
@@ -0,0 +1,64 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Huawei 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.openecomp.mso.entity;
+
+import org.junit.Test;
+import org.openecomp.mso.openpojo.rules.HasToStringRule;
+import org.openecomp.mso.openpojo.rules.ToStringTester;
+
+import com.openpojo.reflection.PojoClass;
+import com.openpojo.reflection.PojoClassFilter;
+import com.openpojo.reflection.filters.FilterEnum;
+import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.rule.impl.GetterMustExistRule;
+import com.openpojo.validation.rule.impl.SetterMustExistRule;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+
+
+public class MsoRequestTest {
+
+ private PojoClassFilter filterTestClasses = new FilterTestClasses();
+
+ @Test
+ public void pojoStructure() {
+ test("org.openecomp.mso.entity");
+ }
+
+ private void test(String pojoPackage) {
+ Validator validator = ValidatorBuilder.create()
+ .with(new GetterMustExistRule())
+ .with(new SetterMustExistRule())
+ .with(new SetterTester())
+ .with(new GetterTester())
+ .build();
+ validator.validate(pojoPackage, new FilterPackageInfo(), new FilterEnum(), filterTestClasses);
+ }
+ private static class FilterTestClasses implements PojoClassFilter {
+ public boolean include(PojoClass pojoClass) {
+ return !pojoClass.getSourcePath().contains("/test-classes/");
+ }
+ }
+
+}
+
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Action.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Action.java
index 86cacb9d1c..8c99d067e9 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Action.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/Action.java
@@ -36,5 +36,6 @@ public enum Action {
addRelationships,
removeRelationships,
inPlaceSoftwareUpdate,
- applyUpdatedConfig
+ applyUpdatedConfig,
+ compareModel
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java
index c27e8277da..6d6227af37 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/E2EServiceInstances.java
@@ -50,6 +50,7 @@ import org.openecomp.mso.apihandler.common.ResponseHandler;
import org.openecomp.mso.apihandlerinfra.Messages;
import org.openecomp.mso.apihandlerinfra.MsoException;
import org.openecomp.mso.apihandlerinfra.MsoRequest;
+import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.CompareModelsRequest;
import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.DelE2ESvcResp;
import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceDeleteRequest;
import org.openecomp.mso.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest;
@@ -158,6 +159,125 @@ public class E2EServiceInstances {
@PathParam("operationId") String operationId) {
return getE2EServiceInstances(serviceId, operationId);
}
+
+ /**
+ * GET Requests for Comparing model of service instance with target version
+ */
+
+ @GET
+ @Path("/{version:[vV][3-5]}/{serviceId}/modeldifferences")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Find added and deleted resources of target model for the e2eserviceInstance on a given serviceId ", response = Response.class)
+ public Response compareModelwithTargetVersion(String request,
+ @PathParam("serviceId") String serviceId,
+ @PathParam("version") String version) {
+
+ instanceIdMap.put("serviceId", serviceId);
+
+ return compareModelwithTargetVersion(request, Action.compareModel, instanceIdMap, version);
+ }
+
+ private Response compareModelwithTargetVersion(String requestJSON, Action action,
+ HashMap<String, String> instanceIdMap, String version) {
+
+ String requestId = instanceIdMap.get("serviceId");
+ long startTime = System.currentTimeMillis();
+ msoLogger.debug("requestId is: " + requestId);
+
+ CompareModelsRequest e2eCompareModelReq = null;
+
+ MsoRequest msoRequest = new MsoRequest(requestId);
+
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ e2eCompareModelReq = mapper.readValue(requestJSON, CompareModelsRequest.class);
+
+ } catch (Exception e) {
+
+ msoLogger.debug("Mapping of request to JSON object failed : ", e);
+ Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST,
+ MsoException.ServiceException, "Mapping of request to JSON object failed. " + e.getMessage(),
+ ErrorNumbers.SVC_BAD_PARAMETER, null);
+ msoLogger.error(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
+ MsoLogger.ErrorCode.SchemaError, requestJSON, e);
+ msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.SchemaError,
+ "Mapping of request to JSON object failed");
+ msoLogger.debug("End of the transaction, the final response is: " + response.getEntity().toString());
+
+ return response;
+ }
+
+ Response returnResp = runCompareModelBPMWorkflow(e2eCompareModelReq, msoRequest, requestJSON, requestId,
+ startTime, action);
+
+ return returnResp;
+
+ }
+
+ private Response runCompareModelBPMWorkflow(CompareModelsRequest e2eCompareModelReq, MsoRequest msoRequest,
+ String requestJSON, String requestId, long startTime, Action action) {
+
+ // Define RecipeLookupResult info here instead of query DB for efficiency
+ String workflowUrl = "/mso/async/services/CompareModelofE2EServiceInstance";
+ int recipeTimeout = 180;
+
+ RequestClient requestClient = null;
+ HttpResponse response = null;
+
+ long subStartTime = System.currentTimeMillis();
+
+ try {
+ requestClient = RequestClientFactory.getRequestClient(workflowUrl, MsoPropertiesUtils.loadMsoProperties());
+
+ JSONObject jjo = new JSONObject(requestJSON);
+ String bpmnRequest = jjo.toString();
+
+ // Capture audit event
+ msoLogger.debug("MSO API Handler Posting call to BPEL engine for url: " + requestClient.getUrl());
+ String serviceId = instanceIdMap.get("serviceId");
+ String serviceType = e2eCompareModelReq.getServiceType();
+ response = requestClient.post(requestId, false, recipeTimeout, action.name(), serviceId, null, null, null,
+ null, null, serviceType, null, null, null, bpmnRequest, null);
+
+ msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
+ "Successfully received response from BPMN engine", "BPMN", workflowUrl, null);
+ } catch (Exception e) {
+ msoLogger.recordMetricEvent(subStartTime, MsoLogger.StatusCode.ERROR,
+ MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with BPMN engine", "BPMN",
+ workflowUrl, null);
+ Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
+ MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(),
+ ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
+ alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL,
+ Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_BPEL));
+ msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
+ MsoLogger.ErrorCode.AvailabilityError, "Exception while communicate with BPMN engine");
+ msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError,
+ "Exception while communicate with BPMN engine");
+ msoLogger.debug("End of the transaction, the final response is: " + resp.getEntity().toString());
+ return resp;
+ }
+
+ if (response == null) {
+ Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY,
+ MsoException.ServiceException, "bpelResponse is null", ErrorNumbers.SVC_NO_SERVER_RESOURCES, null);
+ msoLogger.error(MessageEnum.APIH_BPEL_COMMUNICATE_ERROR, MSO_PROP_APIHANDLER_INFRA, "", "",
+ MsoLogger.ErrorCode.BusinessProcesssError, "Null response from BPEL");
+ msoLogger.recordAuditEvent(startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.InternalError,
+ "Null response from BPMN");
+ msoLogger.debug(END_OF_THE_TRANSACTION + resp.getEntity().toString());
+ return resp;
+ }
+
+ ResponseHandler respHandler = new ResponseHandler(response, requestClient.getType());
+ int bpelStatus = respHandler.getStatus();
+ // String responseBody = respHandler.getResponseBody();
+ // CompareModelsResult modelDiffResponse = new CompareModelsResult();
+
+ return beplStatusUpdate(requestId, startTime, msoRequest, requestClient, respHandler, bpelStatus, action,
+ instanceIdMap);
+ }
private Response getE2EServiceInstances(String serviceId, String operationId) {
RequestsDatabase requestsDB = RequestsDatabase.getInstance();
@@ -814,8 +934,7 @@ public class E2EServiceInstances {
// BPMN accepted the request, the request is in progress
if (bpelStatus == HttpStatus.SC_ACCEPTED) {
String camundaJSONResponseBody = respHandler.getResponseBody();
- msoLogger
- .debug("Received from Camunda: " + camundaJSONResponseBody);
+ msoLogger.debug("Received from Camunda: " + camundaJSONResponseBody);
// currently only for delete case we update the status here
if (action == Action.deleteInstance) {
@@ -834,6 +953,7 @@ public class E2EServiceInstances {
+ bpelStatus);
}
}
+
msoLogger.recordAuditEvent(startTime,
MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc,
"BPMN accepted the request, the request is in progress");