Port mirroring 83/13783/2
authortalio <tali.orenbach@amdocs.com>
Wed, 20 Sep 2017 08:59:28 +0000 (11:59 +0300)
committerMichael Lando <ml636r@att.com>
Sat, 23 Sep 2017 17:09:12 +0000 (17:09 +0000)
Add migration for port mirroring

Issue - ID : SDC-351

Change-Id: I758e14e4acadfb4082ce7bf8df26da2e3fd0821d
Signed-off-by: talio <tali.orenbach@amdocs.com>
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/VendorSoftwareProducts.java
openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java
openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java
openecomp-be/tools/migration/resubmit.sh [new file with mode: 0644]

index 1a68d49..c51fcc4 100644 (file)
@@ -20,9 +20,6 @@
 
 package org.openecomp.sdcrests.vsp.rest;
 
-import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM;
-import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG;
-
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -35,8 +32,6 @@ import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDescriptionDto;
 import org.openecomp.sdcrests.vendorsoftwareproducts.types.validation.IsValidJson;
 import org.springframework.validation.annotation.Validated;
 
-import java.io.File;
-import java.io.IOException;
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 import javax.ws.rs.Consumes;
@@ -51,6 +46,11 @@ import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.IOException;
+
+import static org.openecomp.sdcrests.common.RestConstants.USER_ID_HEADER_PARAM;
+import static org.openecomp.sdcrests.common.RestConstants.USER_MISSING_ERROR_MSG;
 @Path("/v1.0/vendor-software-products")
 @Produces(MediaType.APPLICATION_JSON)
 @Consumes(MediaType.APPLICATION_JSON)
@@ -206,4 +206,20 @@ public interface VendorSoftwareProducts extends VspEntities {
                        @PathParam("versionId") String versionId,
                        @NotNull(message = USER_MISSING_ERROR_MSG) @HeaderParam(USER_ID_HEADER_PARAM)
                            String user);
+
+  @PUT
+  @Path("/reSubmitAll")
+  @ApiOperation(value = "Performs check out, check in and submit for ALL submitted VSPs", notes
+      = "Please note - only submitted VSPs will be processed")
+  Response reSubmitAll(@NotNull(message = USER_MISSING_ERROR_MSG)
+                       @HeaderParam(USER_ID_HEADER_PARAM) String user) throws IOException;
+
+  @PUT
+  @Path("/{vspId}/reSubmit")
+  @ApiOperation(value = "Performs check out, check in and submit for a specific Vendor Software " +
+      "Product")
+  Response reSubmit(@PathParam("vspId") String vspId,
+                    @NotNull(message = USER_MISSING_ERROR_MSG)
+                    @HeaderParam(USER_ID_HEADER_PARAM) String user)
+      throws IOException;
 }
index 0b73cbc..27d4405 100644 (file)
@@ -45,6 +45,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse;
 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
 import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
 import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
 import org.openecomp.sdc.versioning.types.VersionInfo;
 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
 import org.openecomp.sdcrests.vendorsoftwareproducts.types.*;
@@ -86,35 +87,35 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
   private ActivityLogManager activityLogManager =
       ActivityLogManagerFactory.getInstance().createInterface();
 
-    @Override
-    public Response createVsp(VspDescriptionDto vspDescriptionDto, String user) {
-        MdcUtil.initMdc(LoggerServiceName.Create_VSP.toString());
-        logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CREATE_VSP
-            + vspDescriptionDto.getName());
+  @Override
+  public Response createVsp(VspDescriptionDto vspDescriptionDto, String user) {
+    MdcUtil.initMdc(LoggerServiceName.Create_VSP.toString());
+    logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CREATE_VSP
+        + vspDescriptionDto.getName());
+
+    VspCreationDto vspCreationDto = null;
+    OnboardingMethod onboardingMethod = OnboardingMethod.valueOf(vspDescriptionDto.getOnboardingMethod());
+    if (onboardingMethod == null){
+      return handleUnkownOnboardingMethod();
+    }
+    switch (onboardingMethod) {
+      case NetworkPackage:
+      case Manual:
+        VspDetails vspDetails = new MapVspDescriptionDtoToVspDetails().
+            applyMapping(vspDescriptionDto, VspDetails.class);
 
-      VspCreationDto vspCreationDto = null;
-      OnboardingMethod onboardingMethod = OnboardingMethod.valueOf(vspDescriptionDto.getOnboardingMethod());
-      if (onboardingMethod == null){
-        return handleUnkownOnboardingMethod();
-      }
-      switch (onboardingMethod) {
-        case NetworkPackage:
-        case Manual:
-          VspDetails vspDetails = new MapVspDescriptionDtoToVspDetails().
-              applyMapping(vspDescriptionDto, VspDetails.class);
-
-          vspDetails = vendorSoftwareProductManager.createVsp(vspDetails, user);
-
-          MapVspDetailsToVspCreationDto mapping = new MapVspDetailsToVspCreationDto();
-          vspCreationDto = mapping.applyMapping(vspDetails, VspCreationDto.class);
-          break;
-        default:
-          return handleUnkownOnboardingMethod();
-      }
+        vspDetails = vendorSoftwareProductManager.createVsp(vspDetails, user);
 
-      return Response.ok(vspCreationDto).build();
+        MapVspDetailsToVspCreationDto mapping = new MapVspDetailsToVspCreationDto();
+        vspCreationDto = mapping.applyMapping(vspDetails, VspCreationDto.class);
+        break;
+      default:
+        return handleUnkownOnboardingMethod();
     }
 
+    return Response.ok(vspCreationDto).build();
+  }
+
   private Response handleUnkownOnboardingMethod() {
     ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder
         .getInvalidOnboardingMethodErrorBuilder();
@@ -363,14 +364,14 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
         vendorSoftwareProductManager.getInformationArtifact(vspId,
             resolveVspVersion(vspId, versionId, user, VersionableEntityAction.Read), user);
 
-        Response.ResponseBuilder response = Response.ok(textInformationArtifact);
-        if (textInformationArtifact == null) {
-            return Response.status(Response.Status.NOT_FOUND).build();
-        }
-        response
-                .header("Content-Disposition", "attachment; filename=" + textInformationArtifact.getName());
-        return response.build();
+    Response.ResponseBuilder response = Response.ok(textInformationArtifact);
+    if (textInformationArtifact == null) {
+      return Response.status(Response.Status.NOT_FOUND).build();
     }
+    response
+        .header("Content-Disposition", "attachment; filename=" + textInformationArtifact.getName());
+    return response.build();
+  }
 
   public Response listCompute(String vspId, String version, String user) {
 
@@ -386,8 +387,69 @@ public class VendorSoftwareProductsImpl implements VendorSoftwareProducts {
     return Response.ok(results).build();
   }
 
-  private void printAuditForErrors(List<ErrorMessage> errorList, String vspId, String auditType) {
+  @Override
+  public Response reSubmitAll(String user) throws IOException {
+    MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Re_Submit_ALL_Final_VSPs.toString());
+    logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.RESUBMIT_ALL_FINAL_VSPS);
+
+
+    List<VersionedVendorSoftwareProductInfo> vspList =
+        vendorSoftwareProductManager.listVsps(null, user);
+
+    for (VersionedVendorSoftwareProductInfo versionVspInfo : vspList) {
+      String vspId = versionVspInfo.getVspDetails().getId();
+      if (versionVspInfo.getVersionInfo().getStatus().equals(VersionStatus.Final)) {
+        final Version latestFinalVersion =
+            getVersionInfo(vspId, VersionableEntityAction.Read, user).getLatestFinalVersion();
+        if (latestFinalVersion != null) {
+          reSubmit(vspId, user);
+        }
+      }
+    }
+
+    return Response.ok().build();
+  }
+
+  @Override
+  public Response reSubmit(String vspId, String user)
+      throws IOException {
+    MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Checkout_VSP.toString());
+    vendorSoftwareProductManager.checkout(vspId, user);
+    logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CHECK_OUT_VSP + vspId);
+
+    MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Checkin_VSP.toString());
+    vendorSoftwareProductManager.checkin(vspId, user);
+    logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CHECK_IN_VSP + vspId);
+
+    MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Submit_VSP.toString());
+    ValidationResponse validationResponse = vendorSoftwareProductManager.submit(vspId, user);
+    if (!validationResponse.isValid()) {
+      logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.SUBMIT_VSP_FAIL + vspId);
+      logAuditErrors(vspId, validationResponse);
+
+      return Response.status(Response.Status.EXPECTATION_FAILED).entity(
+          new MapValidationResponseToDto()
+              .applyMapping(validationResponse, ValidationResponseDto.class)).build();
+    }
+    logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.SUBMIT_VSP + vspId);
+
+
+    return Response.ok().build();
+  }
+
+  private void logAuditErrors(String vspId, ValidationResponse validationResponse) {
+    if (validationResponse.getVspErrors() != null) {
+      validationResponse.getVspErrors().forEach(errorCode -> logger.audit(AuditMessages
+          .AUDIT_MSG + String.format(SUBMIT_VSP_ERROR, errorCode.message(), vspId)));
+    }
+    if (validationResponse.getUploadDataErrors() != null) {
+      validationResponse.getUploadDataErrors().values().forEach(errorMessages
+          -> VendorSoftwareProductsImpl.printAuditForErrors(errorMessages, vspId,
+          SUBMIT_VSP_ERROR));
+    }
+  }
 
+  private static void printAuditForErrors(List<ErrorMessage> errorList, String vspId, String auditType) {
     errorList.forEach(errorMessage -> {
       if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) {
         logger.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(),
index 387b204..d562ae5 100644 (file)
@@ -15,6 +15,8 @@ public class AuditMessages {
   public static final String CREATE_VSP = "Create VSP. VSP Name: ";
   public static final String CHECK_IN_VSP = "Check in VSP. VSP Id: ";
   public static final String CHECK_OUT_VSP = "Check out VSP. VSP Id: ";
+  public static final String RESUBMIT_ALL_FINAL_VSPS = "Check out, check in and submit all " +
+      "submitted VSPs, see ids below ";
   public static final String SUBMIT_VSP = "Submit VSP. VSP Id: ";
   public static final String SUBMIT_VSP_FAIL = "Submit VSP failed!. VSP Id: ";
   public static final String SUBMIT_VSP_ERROR = "Submit VSP error: %s. VSP Id: %s";
diff --git a/openecomp-be/tools/migration/resubmit.sh b/openecomp-be/tools/migration/resubmit.sh
new file mode 100644 (file)
index 0000000..64164a3
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+###########################################################################################################
+# script name - resubmit.sh
+# run script - ./resubmit.sh
+# this script performs check out, check in, submit for all submitted Vendor Software Products
+# working vs. localhost
+###########################################################################################################
+
+
+# check out, check in, submit for all submitted Vendor Software Products
+curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" "http://localhost:8080/onboarding-api/v1.0/vendor-software-products/reSubmitAll"
+