diff options
Diffstat (limited to 'ms/sdclistener')
26 files changed, 174 insertions, 220 deletions
diff --git a/ms/sdclistener/application/pom.xml b/ms/sdclistener/application/pom.xml index a44816af8..cffed58f7 100644 --- a/ms/sdclistener/application/pom.xml +++ b/ms/sdclistener/application/pom.xml @@ -20,16 +20,15 @@ <parent> <groupId>org.onap.ccsdk.cds.sdclistener</groupId> - <artifactId>parent</artifactId> - <version>1.0.0-SNAPSHOT</version> + <artifactId>sdclistener-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> <relativePath>../parent</relativePath> </parent> - <artifactId>application</artifactId> - <version>1.0.0-SNAPSHOT</version> + <artifactId>sdclistener-application</artifactId> <packaging>jar</packaging> - <name>SDC Listener Application</name> + <name>MS SDC Listener - Application</name> <properties> <protobuf.version>3.6.1</protobuf.version> @@ -53,11 +52,10 @@ <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor.modules</groupId> <artifactId>health-api-common</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>${ccsdk.cds.version}</version> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> @@ -71,18 +69,18 @@ <groupId>org.onap.sdc.sdc-distribution-client</groupId> <artifactId>sdc-distribution-client</artifactId> </dependency> - <dependency> <groupId>org.jmockit</groupId> <artifactId>jmockit</artifactId> + <version>${jmockit.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jacorb</groupId> + <artifactId>jacorb-omgapi</artifactId> + <version>3.8</version> <scope>test</scope> </dependency> - <dependency> - <groupId>org.jacorb</groupId> - <artifactId>jacorb-omgapi</artifactId> - <version>3.8</version> - <scope>test</scope> - </dependency> <!-- GRPC Dependencies --> <dependency> <groupId>io.grpc</groupId> @@ -118,42 +116,12 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor.modules</groupId> <artifactId>blueprint-proto</artifactId> </dependency> - <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> </dependency> </dependencies> - - <build> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <executions> - <execution> - <id>default-test</id> - <phase>test</phase> - <goals> - <goal>test</goal> - </goals> - <configuration> - <argLine>-Djdk.attach.allowAttachSelf=true ${surefireArgLine}</argLine> - <excludes> - <exclude>**/IT*.java</exclude> - </excludes> - </configuration> - </execution> - </executions> - <configuration> - <argLine>${surefireArgLine}</argLine> - <excludes> - <exclude>**/IT*.java</exclude> - </excludes> - </configuration> - </plugin> - </plugins> - </build> </project> diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerApplication.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerApplication.java index 04cbebe7a..6795e8b31 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerApplication.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerApplication.java @@ -23,7 +23,7 @@ import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @EnableConfigurationProperties(SdcListenerConfiguration.class) -@ComponentScan(basePackages = {"org.onap.ccsdk.cds.blueprintsprocessor.healthapi","org.onap.ccsdk.cds.sdclistener"}) +@ComponentScan(basePackages = {"org.onap.ccsdk.cds.blueprintsprocessor.healthapi", "org.onap.ccsdk.cds.sdclistener"}) public class SdcListenerApplication { public static void main(String[] args) { diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfiguration.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfiguration.java index 686f0aa10..5caac6a5a 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfiguration.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfiguration.java @@ -23,8 +23,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import java.util.List; /** - * In order to initiate a SDC distribution client we need to supply some pre-configuration values that - * distribution client needs. + * In order to initiate a SDC distribution client we need to supply some pre-configuration values that distribution + * client needs. */ @ConfigurationProperties("listenerservice") public class SdcListenerConfiguration implements IConfiguration { diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java index f379e60a6..b8868325a 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java @@ -79,7 +79,7 @@ public class SdcListenerNotificationCallback implements INotificationCallback { /** * Download the TOSCA CSAR artifact and process it. * - * @param info - Artifact information + * @param info - Artifact information * @param distributionClient - SDC distribution client */ private void downloadCsarArtifacts(IArtifactInfo info, IDistributionClient distributionClient) { @@ -97,9 +97,8 @@ public class SdcListenerNotificationCallback implements INotificationCallback { if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) { final String errorMessage = String.format("Failed to download the artifact from : %s due to %s ", url, result.getDistributionActionResult()); - listenerStatus - .sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_ERROR, errorMessage, - url, NotificationType.DOWNLOAD); + listenerStatus.sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_ERROR, + errorMessage, url, NotificationType.DOWNLOAD); LOGGER.error(errorMessage); } else { listenerStatus.sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_OK, null, url, @@ -122,7 +121,7 @@ public class SdcListenerNotificationCallback implements INotificationCallback { if (!csarFiles.isEmpty()) { final String archivePath = cbaArchivePath.toString(); - //Extract CBA archive from CSAR package and store it into local disk + // Extract CBA archive from CSAR package and store it into local disk csarFiles.forEach(file -> listenerService.extractBluePrint(file.getAbsolutePath(), archivePath)); csarFiles.forEach(file -> FileUtil.deleteFile(file, csarArchivePath.toString())); } else { diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/client/SdcListenerAuthClientInterceptor.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/client/SdcListenerAuthClientInterceptor.java index 5389dccc0..5748eda18 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/client/SdcListenerAuthClientInterceptor.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/client/SdcListenerAuthClientInterceptor.java @@ -40,7 +40,7 @@ public class SdcListenerAuthClientInterceptor implements ClientInterceptor { @Override public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> methodDescriptor, - CallOptions callOptions, Channel channel) { + CallOptions callOptions, Channel channel) { Key<String> authHeader = Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER); return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>( channel.newCall(methodDescriptor, callOptions)) { diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/client/SdcListenerClient.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/client/SdcListenerClient.java index 030200924..2d8c1fe04 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/client/SdcListenerClient.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/client/SdcListenerClient.java @@ -81,8 +81,8 @@ public class SdcListenerClient { result = this.distributionClient.start(); if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { - throw new SdcListenerException( - "Startup of the SDC distribution client failed with reason: " + result.getDistributionMessageResult()); + throw new SdcListenerException("Startup of the SDC distribution client failed with reason: " + + result.getDistributionMessageResult()); } } diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/controller/HealthCheck.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/controller/HealthCheck.java index 39d03c5bd..b0f8a12e4 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/controller/HealthCheck.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/controller/HealthCheck.java @@ -28,8 +28,7 @@ import reactor.core.publisher.Mono; public class HealthCheck { @RequestMapping(path = "/healthcheck", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody - Mono<String> ping() { + public @ResponseBody Mono<String> ping() { return Mono.just("{\"status\":\"UP\"}"); } diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDto.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDto.java index 19e700153..3ce826ce6 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDto.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDto.java @@ -61,10 +61,8 @@ public class SdcListenerDto { } public void setManagedChannelForGrpc() { - managedChannel = ManagedChannelBuilder.forAddress(grpcAddress, grpcPort) - .usePlaintext() - .intercept(sdcListenerAuthClientInterceptor) - .build(); + managedChannel = ManagedChannelBuilder.forAddress(grpcAddress, grpcPort).usePlaintext() + .intercept(sdcListenerAuthClientInterceptor).build(); } public ManagedChannel getManagedChannelForGrpc() { diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/exceptions/SdcListenerException.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/exceptions/SdcListenerException.java index 458d667f3..bc7b57193 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/exceptions/SdcListenerException.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/exceptions/SdcListenerException.java @@ -27,7 +27,7 @@ public class SdcListenerException extends Exception { /** * @param message The message to dump - * @param cause The Throwable cause object + * @param cause The Throwable cause object */ public SdcListenerException(final String message, final Throwable cause) { super(message, cause); diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcesssorHandler.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcesssorHandler.java index 584713a50..b80dd260d 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcesssorHandler.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcesssorHandler.java @@ -38,7 +38,7 @@ public class BluePrintProcesssorHandler implements AutoCloseable { /** * Sending CBA archive to CDS backend to store into its Database. * - * @param request BluePrintManagementInput object holds CBA archive, its version and blueprints. + * @param request BluePrintManagementInput object holds CBA archive, its version and blueprints. * @param managedChannel - ManagedChannel object helps to access the server or application end point. * * @return A response object diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerService.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerService.java index 9f0acd544..5fa3fb327 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerService.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerService.java @@ -27,14 +27,14 @@ public interface ListenerService { * Get the controller blueprint archive from CSAR package. * * @param csarArchivePath The path where CSAR archive is stored. - * @param cbaArchivePath The destination path where CBA will be stored. + * @param cbaArchivePath The destination path where CBA will be stored. */ void extractBluePrint(String csarArchivePath, String cbaArchivePath); /** * Store the Zip file into CDS database. * - * @param path path where zip file exists. + * @param path path where zip file exists. * @param managedChannel To access the blueprint processor application end point */ void saveBluePrintToCdsDatabase(Path path, ManagedChannel managedChannel); @@ -42,7 +42,7 @@ public interface ListenerService { /** * Extract and store the csar package to local disk. * - * @param result - IDistributionClientDownloadResult contains payload. + * @param result - IDistributionClientDownloadResult contains payload. * @param csarArchivePath The destination path where CSAR will be stored. */ void extractCsarAndStore(IDistributionClientDownloadResult result, Path csarArchivePath); diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java index 19a62fb1d..ee27a9475 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java @@ -81,7 +81,8 @@ public class ListenerServiceImpl implements ListenerService { @Value("${listenerservice.config.grpcPort}") private int grpcPort; - private static final String CBA_ZIP_PATH = "Artifacts/[a-zA-Z0-9-_.]+/Deployment/CONTROLLER_BLUEPRINT_ARCHIVE/[a-zA-Z0-9-_.()]+[.]zip"; + private static final String CBA_ZIP_PATH = + "Artifacts/[a-zA-Z0-9-_.]+/Deployment/CONTROLLER_BLUEPRINT_ARCHIVE/[a-zA-Z0-9-_.()]+[.]zip"; private static final int SUCCESS_CODE = 200; private static final Logger LOGGER = LoggerFactory.getLogger(ListenerServiceImpl.class); @@ -105,17 +106,17 @@ public class ListenerServiceImpl implements ListenerService { } if (validPathCount == 0) { - LOGGER - .info("CBA archive doesn't exist in the CSAR Package or it doesn't exist as per the given path {}", - CBA_ZIP_PATH); - listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_OK, null, - artifactUrl, SDC_LISTENER_COMPONENT); + LOGGER.info( + "CBA archive doesn't exist in the CSAR Package or it doesn't exist as per the given path {}", + CBA_ZIP_PATH); + listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_OK, null, artifactUrl, + SDC_LISTENER_COMPONENT); } } catch (Exception e) { final String errorMessage = format("Failed to extract blueprint %s", e.getMessage()); - listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, - artifactUrl, SDC_LISTENER_COMPONENT); + listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl, + SDC_LISTENER_COMPONENT); LOGGER.error(errorMessage); } } @@ -133,8 +134,8 @@ public class ListenerServiceImpl implements ListenerService { LOGGER.error("Could not able to create file {}", targetZipFile, e); } - try (InputStream inputStream = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream( - targetZipFile)) { + try (InputStream inputStream = zipFile.getInputStream(entry); + OutputStream out = new FileOutputStream(targetZipFile)) { IOUtils.copy(inputStream, out); LOGGER.info("Successfully store the CBA archive {} at this location", targetZipFile); } catch (Exception e) { @@ -200,8 +201,8 @@ public class ListenerServiceImpl implements ListenerService { if (responseStatus.getCode() != SUCCESS_CODE) { final String errorMessage = format("Failed to store the CBA archive into CDS DB due to %s", responseStatus.getErrorMessage()); - listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl, - SDC_LISTENER_COMPONENT); + listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, + artifactUrl, SDC_LISTENER_COMPONENT); LOGGER.error(errorMessage); } else { LOGGER.info(responseStatus.getMessage()); @@ -223,15 +224,11 @@ public class ListenerServiceImpl implements ListenerService { FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build(); FileUtil.deleteFile(file, path); return BluePrintUploadInput.newBuilder() - .setCommonHeader(CommonHeader.newBuilder() - .setRequestId(UUID.randomUUID().toString()) - .setSubRequestId(UUID.randomUUID().toString()) - .setOriginatorId("SDC-LISTENER") - .build()) - .setActionIdentifiers(ActionIdentifiers.newBuilder() - .setActionName(UploadAction.PUBLISH.toString()).build()) - .setFileChunk(fileChunk) - .build(); + .setCommonHeader(CommonHeader.newBuilder().setRequestId(UUID.randomUUID().toString()) + .setSubRequestId(UUID.randomUUID().toString()).setOriginatorId("SDC-LISTENER").build()) + .setActionIdentifiers( + ActionIdentifiers.newBuilder().setActionName(UploadAction.PUBLISH.toString()).build()) + .setFileChunk(fileChunk).build(); } private String getDistributionId() { diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java index a24c0ddad..16cc2f32d 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/SdcListenerStatus.java @@ -51,27 +51,26 @@ public class SdcListenerStatus { public enum NotificationType { - DOWNLOAD, - SDC_LISTENER_COMPONENT; + DOWNLOAD, SDC_LISTENER_COMPONENT; } /** * Send the component status back to SDC. * * @param distributionID SDC Distribution ID - * @param status Distribution status - * @param errorReason Reason of failure if present - * @param url Artifact URL - * @param type - NotificationType(Download or Component) + * @param status Distribution status + * @param errorReason Reason of failure if present + * @param url Artifact URL + * @param type - NotificationType(Download or Component) */ public void sendResponseBackToSdc(String distributionID, DistributionStatusEnum status, String errorReason, - String url, NotificationType type) { + String url, NotificationType type) { final IDistributionClient distributionClient = sdcListenerDto.getDistributionClient(); switch (type) { case SDC_LISTENER_COMPONENT: - IComponentDoneStatusMessage componentStatusMessage = buildStatusMessage(distributionID, status, url, - COMPONENT_NAME); + IComponentDoneStatusMessage componentStatusMessage = + buildStatusMessage(distributionID, status, url, COMPONENT_NAME); if (errorReason == null) { checkResponseStatusFromSdc(distributionClient.sendComponentDoneStatus(componentStatusMessage)); @@ -82,8 +81,8 @@ public class SdcListenerStatus { break; case DOWNLOAD: - IDistributionStatusMessage downloadStatusMessage = buildStatusMessage(distributionID, status, url, - null); + IDistributionStatusMessage downloadStatusMessage = + buildStatusMessage(distributionID, status, url, null); if (errorReason == null) { checkResponseStatusFromSdc(distributionClient.sendDownloadStatus(downloadStatusMessage)); @@ -97,7 +96,7 @@ public class SdcListenerStatus { } private ComponentStatusMessage buildStatusMessage(String distributionId, DistributionStatusEnum status, String url, - String componentName) { + String componentName) { return new BuilderUtil<>(new ComponentStatusMessage()).build(builder -> { builder.setDistributionID(distributionId); builder.setStatus(status); diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/util/FileUtil.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/util/FileUtil.java index f1c1c735d..d8e75e260 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/util/FileUtil.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/util/FileUtil.java @@ -62,9 +62,7 @@ public final class FileUtil { try (Stream<Path> fileTree = walk(path)) { // Get the list of files from the path - return fileTree.filter(Files :: isRegularFile) - .map(Path :: toFile) - .collect(Collectors.toList()); + return fileTree.filter(Files::isRegularFile).map(Path::toFile).collect(Collectors.toList()); } catch (IOException e) { LOGGER.error("Failed to find the file due to", e); } diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerClientTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerClientTest.java index e08b6134c..9f0840987 100644 --- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerClientTest.java +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerClientTest.java @@ -22,9 +22,7 @@ import mockit.Mock; import mockit.MockUp; import mockit.Tested; import mockit.VerificationsInOrder; -import mockit.integration.junit4.JMockit; import org.junit.Test; -import org.junit.runner.RunWith; import org.onap.ccsdk.cds.sdclistener.client.SdcListenerClient; import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto; import org.onap.ccsdk.cds.sdclistener.exceptions.SdcListenerException; @@ -34,7 +32,6 @@ import org.onap.sdc.impl.DistributionClientFactory; import org.onap.sdc.impl.DistributionClientResultImpl; import org.onap.sdc.utils.DistributionActionResultEnum; -@RunWith(JMockit.class) public class SdcListenerClientTest { @Tested @@ -42,11 +39,11 @@ public class SdcListenerClientTest { @Test public void testInitCdsClientSuccesfully(@Injectable IDistributionClient distributionClient, - @Injectable SdcListenerConfiguration configuration, - @Injectable SdcListenerNotificationCallback notification, - @Injectable SdcListenerDto sdcListenerDto) throws SdcListenerException { + @Injectable SdcListenerConfiguration configuration, + @Injectable SdcListenerNotificationCallback notification, @Injectable SdcListenerDto sdcListenerDto) + throws SdcListenerException { - //Arrange + // Arrange new MockUp<DistributionClientFactory>() { @Mock public IDistributionClient createDistributionClient() { @@ -54,24 +51,30 @@ public class SdcListenerClientTest { } }; - new Expectations() {{ - distributionClient.init(configuration, notification); - result = getResult(); - }}; + new Expectations() { + { + distributionClient.init(configuration, notification); + result = getResult(); + } + }; - new Expectations() {{ - distributionClient.start(); - result = getResult(); - }}; + new Expectations() { + { + distributionClient.start(); + result = getResult(); + } + }; // Act sdcListenerClient.initSdcClient(); // Verify - new VerificationsInOrder() {{ - distributionClient.init(configuration, notification); - distributionClient.start(); - }}; + new VerificationsInOrder() { + { + distributionClient.init(configuration, notification); + distributionClient.start(); + } + }; } public IDistributionClientResult getResult() { diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDtoTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDtoTest.java index 1f4ba81f7..f27b22ce6 100644 --- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDtoTest.java +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/dto/SdcListenerDtoTest.java @@ -35,6 +35,7 @@ * * */ + package org.onap.ccsdk.cds.sdclistener.dto; import org.junit.Test; @@ -49,7 +50,7 @@ import org.onap.ccsdk.cds.sdclistener.client.SdcListenerAuthClientInterceptor; import static org.junit.Assert.assertEquals; @RunWith(SpringRunner.class) -@EnableConfigurationProperties({SdcListenerDto.class,SdcListenerAuthClientInterceptor.class}) +@EnableConfigurationProperties({SdcListenerDto.class, SdcListenerAuthClientInterceptor.class}) @SpringBootTest(classes = {SdcListenerDtoTest.class}) public class SdcListenerDtoTest { diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/exceptions/SdcListenerExceptionTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/exceptions/SdcListenerExceptionTest.java index 72f0ef289..6f08f0b90 100644 --- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/exceptions/SdcListenerExceptionTest.java +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/exceptions/SdcListenerExceptionTest.java @@ -35,16 +35,18 @@ * * */ + package org.onap.ccsdk.cds.sdclistener.exceptions; import org.junit.Test; import static org.junit.Assert.assertEquals; + public class SdcListenerExceptionTest { @Test public void testConstructor() { - final String s1="Exception occured"; - SdcListenerException sle=new SdcListenerException(s1); - assertEquals(sle.getMessage(),"Exception occured"); + final String s1 = "Exception occured"; + SdcListenerException sle = new SdcListenerException(s1); + assertEquals(sle.getMessage(), "Exception occured"); } } diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcessorHandlerTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcessorHandlerTest.java index 8a4bb2224..7cde45d9e 100644 --- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcessorHandlerTest.java +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcessorHandlerTest.java @@ -73,7 +73,7 @@ public class BluePrintProcessorHandlerTest { final BluePrintManagementServiceImplBase serviceImplBase = new BluePrintManagementServiceImplBase() { @Override public void uploadBlueprint(BluePrintUploadInput request, - StreamObserver<BluePrintManagementOutput> responseObserver) { + StreamObserver<BluePrintManagementOutput> responseObserver) { responseObserver.onNext(getBluePrintManagementOutput()); responseObserver.onCompleted(); } @@ -83,8 +83,8 @@ public class BluePrintProcessorHandlerTest { String serverName = InProcessServerBuilder.generateName(); // Create a server, add service, start, and register. - grpcCleanup.register( - InProcessServerBuilder.forName(serverName).addService(serviceImplBase).directExecutor().build().start()); + grpcCleanup.register(InProcessServerBuilder.forName(serverName).addService(serviceImplBase).directExecutor() + .build().start()); // Create a client channel. channel = grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()); @@ -109,20 +109,16 @@ public class BluePrintProcessorHandlerTest { FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build(); return BluePrintUploadInput.newBuilder() - .setCommonHeader(CommonHeader.newBuilder() - .setRequestId(UUID.randomUUID().toString()) - .setSubRequestId(UUID.randomUUID().toString()) - .setOriginatorId("SDC-LISTENER") - .build()) - .setActionIdentifiers(ActionIdentifiers.newBuilder() - .setActionName(UploadAction.PUBLISH.toString()).build()) + .setCommonHeader(CommonHeader.newBuilder().setRequestId(UUID.randomUUID().toString()) + .setSubRequestId(UUID.randomUUID().toString()).setOriginatorId("SDC-LISTENER").build()) + .setActionIdentifiers( + ActionIdentifiers.newBuilder().setActionName(UploadAction.PUBLISH.toString()).build()) .setFileChunk(fileChunk).build(); } private BluePrintManagementOutput getBluePrintManagementOutput() { return BluePrintManagementOutput.newBuilder() - .setStatus(Status.newBuilder().setMessage(SUCCESS_MSG).setCode(200).build()) - .build(); + .setStatus(Status.newBuilder().setMessage(SUCCESS_MSG).setCode(200).build()).build(); } } diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java index 5d25ac2bf..4179ccab0 100644 --- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java @@ -50,15 +50,15 @@ import static org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.Notificati import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK; @RunWith(SpringRunner.class) -@EnableConfigurationProperties({SdcListenerAuthClientInterceptor.class, - BluePrintProcesssorHandler.class, SdcListenerDto.class, ListenerServiceImpl.class, SdcListenerStatus.class, - SdcListenerConfiguration.class}) +@EnableConfigurationProperties({SdcListenerAuthClientInterceptor.class, BluePrintProcesssorHandler.class, + SdcListenerDto.class, ListenerServiceImpl.class, SdcListenerStatus.class, SdcListenerConfiguration.class}) @SpringBootTest(classes = {ListenerServiceImplTest.class}) public class ListenerServiceImplTest { private static final String CSAR_SAMPLE = "src/test/resources/service-ServicePnfTest-csar.csar"; private static final String WRONG_CSAR_SAMPLE = "src/test/resources/wrong_csar_pattern.csar"; - private static final String CBA_ZIP_PATH = "Artifacts/[a-zA-Z0-9-_.]+/Deployment/CONTROLLER_BLUEPRINT_ARCHIVE/[a-zA-Z0-9-_.()]+[.]zip"; + private static final String CBA_ZIP_PATH = + "Artifacts/[a-zA-Z0-9-_.]+/Deployment/CONTROLLER_BLUEPRINT_ARCHIVE/[a-zA-Z0-9-_.()]+[.]zip"; private static final String ZIP_FILE = ".zip"; private static final String CSAR_FILE = ".csar"; private static final String DISTRIBUTION_ID = "1"; @@ -104,15 +104,15 @@ public class ListenerServiceImplTest { // Arrange Mockito.when(listenerDto.getDistributionId()).thenReturn(DISTRIBUTION_ID); Mockito.when(listenerDto.getArtifactUrl()).thenReturn(URL); - Mockito.doCallRealMethod().when(status) - .sendResponseBackToSdc(DISTRIBUTION_ID, COMPONENT_DONE_OK, null, URL, SDC_LISTENER_COMPONENT); + Mockito.doCallRealMethod().when(status).sendResponseBackToSdc(DISTRIBUTION_ID, COMPONENT_DONE_OK, null, URL, + SDC_LISTENER_COMPONENT); // Act listenerService.extractBluePrint(WRONG_CSAR_SAMPLE, tempDirectoryPath.toString()); // Verify - Mockito.verify(status) - .sendResponseBackToSdc(DISTRIBUTION_ID, COMPONENT_DONE_OK, null, URL, SDC_LISTENER_COMPONENT); + Mockito.verify(status).sendResponseBackToSdc(DISTRIBUTION_ID, COMPONENT_DONE_OK, null, URL, + SDC_LISTENER_COMPONENT); } @Test @@ -129,12 +129,7 @@ public class ListenerServiceImplTest { } private String checkFileExists(Path path) throws IOException { - return Files.walk(path) - .filter(Files :: isRegularFile) - .map(Path :: toFile) - .findAny() - .get() - .getName(); + return Files.walk(path).filter(Files::isRegularFile).map(Path::toFile).findAny().get().getName(); } public byte[] convertFileToByteArray(File file) { @@ -146,11 +141,10 @@ public class ListenerServiceImplTest { return null; } - public class DistributionClientDownloadResultStubImpl extends DistributionClientResultStubImpl implements - IDistributionClientDownloadResult { + public class DistributionClientDownloadResultStubImpl extends DistributionClientResultStubImpl + implements IDistributionClientDownloadResult { - public DistributionClientDownloadResultStubImpl() { - } + public DistributionClientDownloadResultStubImpl() {} public byte[] getArtifactPayload() { File file = Paths.get(CSAR_SAMPLE).toFile(); diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessageTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessageTest.java index 898596dfa..c9abfe622 100644 --- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessageTest.java +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessageTest.java @@ -1,3 +1,19 @@ +/* + * Copyright © 2020 AT&T. + * + * 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. + */ + package org.onap.ccsdk.cds.sdclistener.status; import org.junit.Test; @@ -11,7 +27,7 @@ import static org.junit.Assert.assertEquals; @RunWith(SpringRunner.class) @SpringBootTest(classes = {ComponentStatusMessageTest.class}) public class ComponentStatusMessageTest { - ComponentStatusMessage componentStatusMsg= new ComponentStatusMessage(); + ComponentStatusMessage componentStatusMsg = new ComponentStatusMessage(); @Test public void testComponentStatusMessage() { diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/util/FileUtilTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/util/FileUtilTest.java index a43e8c072..c368329e4 100644 --- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/util/FileUtilTest.java +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/util/FileUtilTest.java @@ -35,6 +35,7 @@ * * */ + package org.onap.ccsdk.cds.sdclistener.util; import org.junit.Test; @@ -58,25 +59,25 @@ import static org.junit.Assert.*; @SpringBootTest(classes = {FileUtilTest.class}) public class FileUtilTest { - FileUtil fs; + FileUtil fs; @Test public void testDeleteFile() throws IOException { File tempFile = File.createTempFile("tempFile", ".txt"); -// System.out.println(tempFile.getRoot()); - fs.deleteFile(tempFile,tempFile.getAbsolutePath()); + // System.out.println(tempFile.getRoot()); + fs.deleteFile(tempFile, tempFile.getAbsolutePath()); assertFalse(tempFile.exists()); } @Test - public void testGetFilesFromDisk() throws IOException{ + public void testGetFilesFromDisk() throws IOException { - Path resourceDirectory = Paths.get("src","test","resources"); - int totalfile=resourceDirectory.getNameCount(); - List fileList=fs.getFilesFromDisk(resourceDirectory); + Path resourceDirectory = Paths.get("src", "test", "resources"); + int totalfile = resourceDirectory.getNameCount(); + List fileList = fs.getFilesFromDisk(resourceDirectory); assertNotNull(fileList); - assertEquals(fileList.size(),totalfile); + assertEquals(fileList.size(), totalfile); } diff --git a/ms/sdclistener/distribution/pom.xml b/ms/sdclistener/distribution/pom.xml index ec02cfb5c..e9f5b949e 100755 --- a/ms/sdclistener/distribution/pom.xml +++ b/ms/sdclistener/distribution/pom.xml @@ -20,15 +20,15 @@ <parent> <groupId>org.onap.ccsdk.cds.sdclistener</groupId> - <artifactId>parent</artifactId> - <version>1.0.0-SNAPSHOT</version> + <artifactId>sdclistener-parent</artifactId> + <version>1.1.0-SNAPSHOT</version> <relativePath>../parent</relativePath> </parent> - <artifactId>distribution</artifactId> + <artifactId>sdclistener-distribution</artifactId> <packaging>pom</packaging> - <name>SDC Listener Distribution</name> + <name>MS SDC Listener - Distribution</name> <properties> <assembly.id>maven</assembly.id> @@ -37,16 +37,12 @@ <image.name>onap/ccsdk-sdclistener</image.name> <!--disabled for now to mirror #85964 https://gerrit.onap.org/r/#/c/85964/2/ms/command-executor/pom.xml--> <!--<docker.buildArg.https_proxy>${https_proxy}</docker.buildArg.https_proxy>--> - <docker.push.phase>deploy</docker.push.phase> - <docker.verbose>true</docker.verbose> - <ccsdk.project.version>${project.version}</ccsdk.project.version> - <ccsdk.build.timestamp>${maven.build.timestamp}</ccsdk.build.timestamp> </properties> <dependencies> <dependency> <groupId>org.onap.ccsdk.cds.sdclistener</groupId> - <artifactId>application</artifactId> + <artifactId>sdclistener-application</artifactId> </dependency> </dependencies> @@ -144,7 +140,7 @@ <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> - <version>0.26.1</version> + <version>0.34.0</version> <inherited>false</inherited> <configuration> <images> @@ -161,18 +157,12 @@ </build> </image> </images> - <verbose>true</verbose> + <verbose>${docker.verbose}</verbose> + <skipPush>${docker.skip.push}</skipPush> </configuration> <executions> <execution> - <id>generate-images</id> - <phase>package</phase> - <goals> - <goal>build</goal> - </goals> - </execution> - <execution> - <id>push-images</id> + <id>build-push-images</id> <phase>${docker.push.phase}</phase> <goals> <goal>build</goal> diff --git a/ms/sdclistener/distribution/src/main/docker/Dockerfile b/ms/sdclistener/distribution/src/main/docker/Dockerfile index 41622fae1..b89cbc7ec 100755 --- a/ms/sdclistener/distribution/src/main/docker/Dockerfile +++ b/ms/sdclistener/distribution/src/main/docker/Dockerfile @@ -1,19 +1,18 @@ -FROM openjdk:8-jdk-alpine +FROM onap/ccsdk-alpine-j11-image:1.0.1 -RUN addgroup -S -g 1000 onap && adduser -S onap -u 1000 -G onap +USER root # add entrypoint -COPY startService.sh /startService.sh -RUN chown onap:onap /startService.sh -RUN chmod 751 /startService.sh +COPY startService.sh /opt/app/onap/sdc-listener/startService.sh # add application COPY @project.build.finalName@-@assembly.id@.tar.gz /source.tar.gz + RUN tar -xzf /source.tar.gz -C /tmp \ && cp -rf /tmp/@project.build.finalName@/opt / \ && rm -rf /source.tar.gz \ - && rm -rf /tmp/@project.build.finalName@ - -RUN mkdir -p /opt/app/onap/cds-sdc-listener -RUN chown onap:onap /opt -R + && rm -rf /tmp/@project.build.finalName@ \ + && mkdir -p /opt/app/onap/cds-sdc-listener \ + && chown onap:onap /opt -R \ + && chmod 755 /opt/app/onap/sdc-listener/startService.sh USER onap -ENTRYPOINT /startService.sh +ENTRYPOINT /opt/app/onap/sdc-listener/startService.sh diff --git a/ms/sdclistener/distribution/src/main/docker/startService.sh b/ms/sdclistener/distribution/src/main/docker/startService.sh index 7ad6171b8..7ad6171b8 100644..100755 --- a/ms/sdclistener/distribution/src/main/docker/startService.sh +++ b/ms/sdclistener/distribution/src/main/docker/startService.sh diff --git a/ms/sdclistener/parent/pom.xml b/ms/sdclistener/parent/pom.xml index ea67d1b95..b1ba9e946 100755 --- a/ms/sdclistener/parent/pom.xml +++ b/ms/sdclistener/parent/pom.xml @@ -23,15 +23,14 @@ <parent> <groupId>org.onap.ccsdk.cds</groupId> <artifactId>sdclistener</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> </parent> <groupId>org.onap.ccsdk.cds.sdclistener</groupId> - <artifactId>parent</artifactId> + <artifactId>sdclistener-parent</artifactId> <packaging>pom</packaging> - <name>SDC Listener Parent</name> - <description>SDC Listener Parent</description> + <name>MS SDC Listener - Parent</name> <properties> <eelf.version>1.0.0</eelf.version> @@ -42,7 +41,7 @@ <dmaap.client.version>1.1.5</dmaap.client.version> <mockkserver.version>5.5.1</mockkserver.version> <sdc-distribution-client.version>1.4.0</sdc-distribution-client.version> - <jmockit.version>1.19</jmockit.version> + <jmockit.version>1.49</jmockit.version> <reactorcore.version>3.2.6.RELEASE</reactorcore.version> </properties> @@ -78,8 +77,7 @@ <artifactId>commons-compress</artifactId> <version>1.15</version> </dependency> - - <dependency> + <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>${guava.version}</version> @@ -127,7 +125,7 @@ <version>${protobuff.java.utils.version}</version> </dependency> <dependency> - <groupId>org.onap.ccsdk.cds.blueprintsprocessor</groupId> + <groupId>org.onap.ccsdk.cds.blueprintsprocessor.modules</groupId> <artifactId>blueprint-proto</artifactId> <version>${project.version}</version> <exclusions> @@ -155,7 +153,7 @@ <!-- SDC Distribution client dependency --> <dependency> <groupId>org.onap.ccsdk.cds.sdclistener</groupId> - <artifactId>application</artifactId> + <artifactId>sdclistener-application</artifactId> <version>${project.version}</version> </dependency> <dependency> @@ -170,11 +168,15 @@ <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.5.1</version> + <artifactId>maven-surefire-plugin</artifactId> + <version>${maven-surefire-plugin.version}</version> <configuration> - <source>${maven.compiler.source}</source> - <target>${maven.compiler.target}</target> + <!-- Sets the VM argument line used when unit tests are run. --> + <argLine>-javaagent:"${settings.localRepository}"/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar</argLine> + <!-- Excludes integration tests when unit tests are run. --> + <excludes> + <exclude>**/IT*.java</exclude> + </excludes> </configuration> </plugin> </plugins> diff --git a/ms/sdclistener/pom.xml b/ms/sdclistener/pom.xml index d89eb14a3..3b7e8a41b 100644 --- a/ms/sdclistener/pom.xml +++ b/ms/sdclistener/pom.xml @@ -20,16 +20,15 @@ <parent> <groupId>org.onap.ccsdk.cds</groupId> - <artifactId>ms</artifactId> - <version>1.0.0-SNAPSHOT</version> + <artifactId>cds-ms</artifactId> + <version>1.1.0-SNAPSHOT</version> <relativePath>..</relativePath> </parent> <artifactId>sdclistener</artifactId> <packaging>pom</packaging> - <name>SDC Listener Root</name> - <description>SDC Listener Root</description> + <name>MS SDC Listener (Root)</name> <modules> <module>parent</module> @@ -39,13 +38,6 @@ <properties> <service.name>sdclistener</service.name> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <maven.build.timestamp.format>yyyyMMdd'T'HHmmss'Z'</maven.build.timestamp.format> - <build.number>${maven.build.timestamp}</build.number> - <java.version>1.8</java.version> - <maven.compiler.target>1.8</maven.compiler.target> - <maven.compiler.source>1.8</maven.compiler.source> - <ccsdk.project.version>${project.version}</ccsdk.project.version> + </properties> </project> |