diff options
author | 2019-11-22 18:06:08 -0500 | |
---|---|---|
committer | 2019-11-26 21:32:38 +0000 | |
commit | 341db21b2ac0a14a1ed2b8bf7930914dda054bfe (patch) | |
tree | 113bba965b06cfe3a8af3a0a527d1a41c9faf0f9 /ms/sdclistener/application/src/main | |
parent | d274e5fc552cf9ae25500f504f0434981cf3accf (diff) |
Formatting Code base with ktlint
No Business logic change, just the code format.
Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3
To format run: mvn process-sources -P format
Issue-ID: CCSDK-1947
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331
Diffstat (limited to 'ms/sdclistener/application/src/main')
16 files changed, 126 insertions, 72 deletions
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 253b576d2..2ec241d75 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 @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener; import org.springframework.boot.SpringApplication; @@ -25,4 +26,5 @@ public class SdcListenerApplication { public static void main(String[] args) { SpringApplication.run(SdcListenerApplication.class, 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 06e2a0342..686f0aa10 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 @@ -13,13 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener; -import java.util.List; import org.onap.sdc.api.consumer.IConfiguration; import org.springframework.beans.factory.annotation.Value; 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. @@ -139,5 +141,6 @@ public class SdcListenerConfiguration implements IConfiguration { public Boolean isUseHttpsWithDmaap() { return isUseHttpsWithDmaap; } + } 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 d5f156e55..f379e60a6 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 @@ -13,14 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener; -import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS; -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.List; -import java.util.Objects; import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto; import org.onap.ccsdk.cds.sdclistener.service.ListenerService; import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus; @@ -40,6 +35,14 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Component; +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Objects; + +import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS; + @ConfigurationProperties("listenerservice") @Component @ComponentScan("org.onap.ccsdk.cds.cdssdclistener.dto") @@ -70,13 +73,13 @@ public class SdcListenerNotificationCallback implements INotificationCallback { private void processNotification(INotificationData notificationData) { final IDistributionClient distributionClient = sdcListenerDto.getDistributionClient(); notificationData.getServiceArtifacts() - .forEach(artifactInfo -> downloadCsarArtifacts(artifactInfo, distributionClient)); + .forEach(artifactInfo -> downloadCsarArtifacts(artifactInfo, distributionClient)); } /** * 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) { @@ -93,14 +96,14 @@ 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()); + result.getDistributionActionResult()); listenerStatus - .sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_ERROR, errorMessage, - url, NotificationType.DOWNLOAD); + .sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_ERROR, errorMessage, + url, NotificationType.DOWNLOAD); LOGGER.error(errorMessage); } else { listenerStatus.sendResponseBackToSdc(distributionId, DistributionStatusEnum.DOWNLOAD_OK, null, url, - NotificationType.DOWNLOAD); + NotificationType.DOWNLOAD); LOGGER.info("Trying to write CSAR artifact to file with URL {} and UUID {}", url, id); processCsarArtifact(result); } @@ -128,4 +131,5 @@ public class SdcListenerNotificationCallback implements INotificationCallback { listenerService.saveBluePrintToCdsDatabase(cbaArchivePath, sdcListenerDto.getManagedChannelForGrpc()); } + } diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/actuator/indicator/SDCListenerCustomIndicator.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/actuator/indicator/SDCListenerCustomIndicator.java index 11fd2c24c..1a5bafcc8 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/actuator/indicator/SDCListenerCustomIndicator.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/actuator/indicator/SDCListenerCustomIndicator.java @@ -16,7 +16,6 @@ package org.onap.ccsdk.cds.sdclistener.actuator.indicator; - import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthApiResponse; import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.domain.HealthCheckStatus; import org.onap.ccsdk.cds.blueprintsprocessor.healthapi.service.health.SDCListenerHealthCheck; @@ -24,25 +23,28 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health.Builder; import org.springframework.stereotype.Component; + /** * Health Indicator for SDCListener. + * * @author Shaaban Ebrahim * @version 1.0 */ @Component public class SDCListenerCustomIndicator extends AbstractHealthIndicator { - @Autowired - private SDCListenerHealthCheck sDCListenerHealthCheck; + @Autowired + private SDCListenerHealthCheck sDCListenerHealthCheck; - @Override - protected void doHealthCheck(Builder builder) { - HealthApiResponse healthAPIResponse = sDCListenerHealthCheck.retrieveEndpointExecutionStatus(); - if (healthAPIResponse.getStatus() == HealthCheckStatus.UP) { - builder.up(); - } else { - builder.down(); + @Override + protected void doHealthCheck(Builder builder) { + HealthApiResponse healthAPIResponse = sDCListenerHealthCheck.retrieveEndpointExecutionStatus(); + if (healthAPIResponse.getStatus() == HealthCheckStatus.UP) { + builder.up(); + } else { + builder.down(); + } + builder.withDetail("Services", healthAPIResponse.getChecks()); } - builder.withDetail("Services", healthAPIResponse.getChecks()); - } + } 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 b981b806c..5389dccc0 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 @@ -13,10 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.client; -import io.grpc.*; +import io.grpc.CallOptions; +import io.grpc.Channel; +import io.grpc.ClientCall; +import io.grpc.ClientInterceptor; +import io.grpc.ForwardingClientCall; +import io.grpc.Metadata; import io.grpc.Metadata.Key; +import io.grpc.MethodDescriptor; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @@ -36,7 +43,7 @@ public class SdcListenerAuthClientInterceptor implements ClientInterceptor { CallOptions callOptions, Channel channel) { Key<String> authHeader = Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER); return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>( - channel.newCall(methodDescriptor, callOptions)) { + channel.newCall(methodDescriptor, callOptions)) { @Override public void start(Listener<RespT> responseListener, Metadata headers) { headers.put(authHeader, basicAuth); @@ -44,4 +51,5 @@ public class SdcListenerAuthClientInterceptor implements ClientInterceptor { } }; } + } 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 973f950bc..030200924 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 @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.client; -import java.util.Optional; import org.onap.ccsdk.cds.sdclistener.SdcListenerConfiguration; -import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto; import org.onap.ccsdk.cds.sdclistener.SdcListenerNotificationCallback; +import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto; import org.onap.ccsdk.cds.sdclistener.exceptions.SdcListenerException; import org.onap.sdc.api.IDistributionClient; import org.onap.sdc.api.results.IDistributionClientResult; @@ -32,6 +32,8 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; +import java.util.Optional; + @Component @ComponentScan("org.onap.ccsdk.cds.cdssdclistener.dto") public class SdcListenerClient { @@ -57,7 +59,7 @@ public class SdcListenerClient { LOG.info("Initialize the SDC distribution client"); distributionClient = Optional.of(DistributionClientFactory.createDistributionClient()) - .orElseThrow(() -> new SdcListenerException("Could not able to create SDC Distribution client")); + .orElseThrow(() -> new SdcListenerException("Could not able to create SDC Distribution client")); listenerDto.setManagedChannelForGrpc(); @@ -70,7 +72,7 @@ public class SdcListenerClient { private void startSdcClientBasedOnTheResult(IDistributionClientResult result) throws SdcListenerException { if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { throw new SdcListenerException( - "SDC distribution client init failed with reason:" + result.getDistributionMessageResult()); + "SDC distribution client init failed with reason:" + result.getDistributionMessageResult()); } LOG.info("Initialization of the SDC distribution client is complete"); @@ -80,7 +82,7 @@ public class SdcListenerClient { if (!result.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { throw new SdcListenerException( - "Startup of the SDC distribution client failed with reason: " + result.getDistributionMessageResult()); + "Startup of the SDC distribution client failed with reason: " + result.getDistributionMessageResult()); } } @@ -89,7 +91,8 @@ public class SdcListenerClient { IDistributionClientResult status = this.distributionClient.stop(); if (status.getDistributionActionResult().equals(DistributionActionResultEnum.SUCCESS)) { throw new SdcListenerException( - "Failed to close the SDC distribution client due to : " + status.getDistributionMessageResult()); + "Failed to close the SDC distribution client due to : " + status.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 44245752f..39d03c5bd 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 @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.controller; import org.springframework.http.MediaType; @@ -31,4 +32,5 @@ public class HealthCheck { 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 a59022c3f..19e700153 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 @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.dto; import io.grpc.ManagedChannel; @@ -61,9 +62,9 @@ public class SdcListenerDto { public void setManagedChannelForGrpc() { managedChannel = ManagedChannelBuilder.forAddress(grpcAddress, grpcPort) - .usePlaintext() - .intercept(sdcListenerAuthClientInterceptor) - .build(); + .usePlaintext() + .intercept(sdcListenerAuthClientInterceptor) + .build(); } public ManagedChannel getManagedChannelForGrpc() { @@ -77,4 +78,5 @@ public class SdcListenerDto { public void setArtifactUrl(String artifactUrl) { this.artifactUrl = artifactUrl; } + } 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 23f669f1e..458d667f3 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 @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.exceptions; public class SdcListenerException extends Exception { @@ -26,9 +27,10 @@ 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 96b2ff081..584713a50 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 @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.handler; import io.grpc.ManagedChannel; @@ -37,8 +38,9 @@ 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 */ public Status sendRequest(BluePrintUploadInput request, ManagedChannel managedChannel) { @@ -61,4 +63,5 @@ public class BluePrintProcesssorHandler implements AutoCloseable { } LOGGER.info("Stopping GRPC connection to CDS backend"); } + } 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 bc72c8f98..9f0acd544 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 @@ -13,35 +13,38 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.service; import io.grpc.ManagedChannel; -import java.nio.file.Path; import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import java.nio.file.Path; + 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); + void saveBluePrintToCdsDatabase(Path path, ManagedChannel managedChannel); /** * 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 1937af75c..810f131df 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 @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.service; import com.google.protobuf.ByteString; @@ -38,7 +39,11 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; -import java.io.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -101,16 +106,16 @@ 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); + .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); + 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); + artifactUrl, SDC_LISTENER_COMPONENT); LOGGER.error(errorMessage); } } @@ -121,7 +126,7 @@ public class ListenerServiceImpl implements ListenerService { File targetZipFile = new File(targetLocation.toString()); try { - if (! targetZipFile.createNewFile()) { + if (!targetZipFile.createNewFile()) { LOGGER.warn("Overwriting zip file {}", targetLocation); } } catch (IOException e) { @@ -129,7 +134,7 @@ public class ListenerServiceImpl implements ListenerService { } try (InputStream inputStream = zipFile.getInputStream(entry); OutputStream out = new FileOutputStream( - targetZipFile)) { + targetZipFile)) { IOUtils.copy(inputStream, out); LOGGER.info("Successfully store the CBA archive {} at this location", targetZipFile); } catch (Exception e) { @@ -194,20 +199,20 @@ 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()); + responseStatus.getErrorMessage()); listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl, - SDC_LISTENER_COMPONENT); + SDC_LISTENER_COMPONENT); LOGGER.error(errorMessage); } else { LOGGER.info(responseStatus.getMessage()); listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_OK, null, artifactUrl, - SDC_LISTENER_COMPONENT); + SDC_LISTENER_COMPONENT); } } catch (Exception e) { final String errorMessage = format("Failure due to %s", e.getMessage()); listenerStatus.sendResponseBackToSdc(distributionId, COMPONENT_DONE_ERROR, errorMessage, artifactUrl, - SDC_LISTENER_COMPONENT); + SDC_LISTENER_COMPONENT); LOGGER.error(errorMessage); } }); @@ -236,4 +241,5 @@ public class ListenerServiceImpl implements ListenerService { private String getArtifactUrl() { return sdcListenerDto.getArtifactUrl(); } + } diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java index 4f31003b0..488c44602 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/status/ComponentStatusMessage.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.status; import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; import org.onap.sdc.api.consumer.IDistributionStatusMessage; import org.onap.sdc.utils.DistributionStatusEnum; -public class ComponentStatusMessage implements IComponentDoneStatusMessage, IDistributionStatusMessage { +public class ComponentStatusMessage implements IComponentDoneStatusMessage, IDistributionStatusMessage { private String componentName; @@ -94,4 +95,5 @@ public class ComponentStatusMessage implements IComponentDoneStatusMessage, IDi public void setArtifactUrl(String artifactUrl) { this.artifactUrl = artifactUrl; } + } 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 a8e60c29a..a24c0ddad 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 @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.status; -import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS; -import java.util.Objects; import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto; import org.onap.ccsdk.cds.sdclistener.util.BuilderUtil; import org.onap.sdc.api.IDistributionClient; @@ -32,6 +31,10 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.ComponentScan; import org.springframework.stereotype.Component; +import java.util.Objects; + +import static org.onap.sdc.utils.DistributionActionResultEnum.SUCCESS; + @Component @ConfigurationProperties("listenerservice") @ComponentScan("org.onap.ccsdk.cds.cdssdclistener.dto") @@ -46,44 +49,47 @@ public class SdcListenerStatus { @Autowired private SdcListenerDto sdcListenerDto; + 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); + COMPONENT_NAME); if (errorReason == null) { checkResponseStatusFromSdc(distributionClient.sendComponentDoneStatus(componentStatusMessage)); } else { checkResponseStatusFromSdc( - distributionClient.sendComponentDoneStatus(componentStatusMessage, errorReason)); + distributionClient.sendComponentDoneStatus(componentStatusMessage, errorReason)); } break; case DOWNLOAD: IDistributionStatusMessage downloadStatusMessage = buildStatusMessage(distributionID, status, url, - null); + null); if (errorReason == null) { checkResponseStatusFromSdc(distributionClient.sendDownloadStatus(downloadStatusMessage)); } else { checkResponseStatusFromSdc( - distributionClient.sendDownloadStatus(downloadStatusMessage, errorReason)); + distributionClient.sendDownloadStatus(downloadStatusMessage, errorReason)); } default: break; @@ -91,7 +97,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); @@ -105,9 +111,10 @@ public class SdcListenerStatus { private void checkResponseStatusFromSdc(IDistributionClientResult result) { if (!Objects.equals(result.getDistributionActionResult(), SUCCESS)) { LOGGER.error("SDC failed to receive the response from cds-sdc listener due to {}", - result.getDistributionMessageResult()); + result.getDistributionMessageResult()); } else { LOGGER.info("SDC successfully received the response"); } } + } diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/util/BuilderUtil.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/util/BuilderUtil.java index a5c4a5c16..992843468 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/util/BuilderUtil.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/util/BuilderUtil.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.util; import java.util.function.Consumer; @@ -38,4 +39,5 @@ public class BuilderUtil<T> { public T create() { return object; } + } 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 42b795634..f1c1c735d 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 @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.ccsdk.cds.sdclistener.util; import org.apache.commons.io.FileUtils; @@ -54,18 +55,20 @@ public final class FileUtil { * Extract files from the given path * * @param path where files reside. + * * @return list of files. */ public static List<File> getFilesFromDisk(Path path) { 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); } return new ArrayList<>(); } + } |