diff options
Diffstat (limited to 'plugins')
5 files changed, 28 insertions, 31 deletions
diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java index 59d3efc8..b50d6ff3 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/file/FilePolicyForwarder.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Intel Crop. All rights reserved. - * Modifications Copyright (C) 2020 AT&T Inc. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,12 +21,10 @@ package org.onap.policy.distribution.forwarding.file; -import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.InvalidPathException; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; import org.onap.policy.common.parameters.ParameterService; @@ -53,7 +51,7 @@ public class FilePolicyForwarder implements PolicyForwarder { public void configure(final String parameterGroupName) { fileForwarderParameters = ParameterService.get(parameterGroupName); try { - final Path path = Paths.get(fileForwarderParameters.getPath()); + final var path = Paths.get(fileForwarderParameters.getPath()); if (!path.toFile().exists()) { Files.createDirectories(path); } @@ -87,8 +85,8 @@ public class FilePolicyForwarder implements PolicyForwarder { */ private void forwardPolicy(final ToscaPolicy pol) throws PolicyForwardingException { final String name = pol.getName(); - final Path path = Paths.get(fileForwarderParameters.getPath(), name); - try (BufferedWriter writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { + final var path = Paths.get(fileForwarderParameters.getPath(), name); + try (var writer = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { writer.write("policyName: " + name); if (fileForwarderParameters.isVerbose()) { writer.newLine(); diff --git a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java index d45b07f6..b6f41fbf 100644 --- a/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java +++ b/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/lifecycle/api/LifecycleApiPolicyForwarder.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2020-2021 AT&T Inc. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,6 @@ package org.onap.policy.distribution.forwarding.lifecycle.api; -import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -87,7 +86,7 @@ public class LifecycleApiPolicyForwarder implements PolicyForwarder { Response policyCreated = null; try { if (entity instanceof ToscaServiceTemplate) { - final ToscaServiceTemplate toscaServiceTemplate = (ToscaServiceTemplate) entity; + final var toscaServiceTemplate = (ToscaServiceTemplate) entity; if (null != toscaServiceTemplate.getPolicyTypes() && !toscaServiceTemplate.getPolicyTypes().isEmpty()) { createPolicyType(toscaServiceTemplate); } @@ -123,13 +122,13 @@ public class LifecycleApiPolicyForwarder implements PolicyForwarder { } private Response deployPolicy(final ToscaServiceTemplate toscaServiceTemplate) throws PolicyForwardingException { - final PdpDeployPolicies pdpPolicies = new PdpDeployPolicies(); + final var pdpPolicies = new PdpDeployPolicies(); final List<ToscaConceptIdentifierOptVersion> policyIdentifierList = new ArrayList<>(); for (final Map<String, ToscaPolicy> policyMap : toscaServiceTemplate.getToscaTopologyTemplate().getPolicies()) { final String policyId = policyMap.entrySet().iterator().next().getValue().getMetadata().get("policy-id"); final String policyVersion = policyMap.entrySet().iterator().next().getValue().getMetadata().get("policy-version"); - final ToscaConceptIdentifierOptVersion toscaPolicyIdentifier = + final var toscaPolicyIdentifier = new ToscaConceptIdentifierOptVersion(policyId, policyVersion); policyIdentifierList.add(toscaPolicyIdentifier); } @@ -141,7 +140,7 @@ public class LifecycleApiPolicyForwarder implements PolicyForwarder { throws PolicyForwardingException { Response response = null; try { - response = getHttpClient(wantApi).post(path, entity, ImmutableMap.of(HttpHeaders.ACCEPT, + response = getHttpClient(wantApi).post(path, entity, Map.of(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON, HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)); if (response.getStatus() / 100 != 2) { LOGGER.error( diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java index 4703725d..af30c1f1 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/decoding/policy/file/PolicyDecoderFileInCsarToPolicy.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2020-2021 AT&T Inc. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,7 +74,7 @@ public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, Tosc public Collection<ToscaEntity> decode(final Csar csar) throws PolicyDecodingException { final Collection<ToscaEntity> policyList = new ArrayList<>(); - try (ZipFile zipFile = new ZipFile(csar.getCsarPath())) { + try (var zipFile = new ZipFile(csar.getCsarPath())) { final Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { // @@ -121,7 +121,7 @@ public class PolicyDecoderFileInCsarToPolicy implements PolicyDecoder<Csar, Tosc // // Now ensure that there is no path injection // - Path path = Path.of(csarPath, entryName).normalize(); + var path = Path.of(csarPath, entryName).normalize(); // // Throw an exception if path is outside the csar // diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java index d405f0ad..be27657c 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/file/FileSystemReceptionHandler.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Intel Corp. All rights reserved. * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,9 +61,9 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler { try { final FileSystemReceptionHandlerConfigurationParameterGroup handlerParameters = ParameterService.get(parameterGroupName); - final FileClientHandler fileClientHandler = + final var fileClientHandler = new FileClientHandler(this, handlerParameters.getWatchPath(), handlerParameters.getMaxThread()); - final Thread fileWatcherThread = new Thread(fileClientHandler); + final var fileWatcherThread = new Thread(fileClientHandler); fileWatcherThread.start(); } catch (final Exception ex) { LOGGER.error("FileSystemReceptionHandler initialization failed", ex); @@ -93,8 +93,8 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler { * @param watchPath Path to watch */ public void initFileWatcher(final String watchPath, final int maxThread) throws IOException { - try (final WatchService watcher = FileSystems.getDefault().newWatchService()) { - final Path dir = Paths.get(watchPath); + try (final var watcher = FileSystems.getDefault().newWatchService()) { + final var dir = Paths.get(watchPath); dir.register(watcher, ENTRY_CREATE); LOGGER.debug("Watch Service registered for dir: {}", dir.getFileName()); startWatchService(watcher, dir, maxThread); @@ -161,7 +161,7 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler { */ protected void createPolicyInputAndCallHandler(final String fileName) { try { - final Csar csarObject = new Csar(fileName); + final var csarObject = new Csar(fileName); DistributionStatisticsManager.updateTotalDownloadCount(); inputReceived(csarObject); DistributionStatisticsManager.updateDownloadSuccessCount(); @@ -174,10 +174,10 @@ public class FileSystemReceptionHandler extends AbstractReceptionHandler { } private void waitForFileToBeReady(final String fullFilePath) throws InterruptedException { - boolean flag = true; + var flag = true; while (flag) { TimeUnit.MILLISECONDS.sleep(100); - try (ZipFile zipFile = new ZipFile(fullFilePath)) { + try (var zipFile = new ZipFile(fullFilePath)) { flag = false; } catch (final IOException exp) { LOGGER.error("file is not ready for reading, wait for sometime and try again", exp); diff --git a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java index df968f99..23fbca59 100644 --- a/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java +++ b/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. - * Copyright (C) 2020 AT&T Inc. + * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -192,14 +192,14 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo * @param notificationData the notification from SDC */ public void processCsarServiceArtifacts(final INotificationData notificationData) { - boolean artifactsProcessedSuccessfully = true; + var artifactsProcessedSuccessfully = true; DistributionStatisticsManager.updateTotalDistributionCount(); for (final IArtifactInfo artifact : notificationData.getServiceArtifacts()) { try { final IDistributionClientDownloadResult resultArtifact = downloadTheArtifact(artifact, notificationData); - final Path filePath = writeArtifactToFile(artifact, resultArtifact); - final Csar csarObject = new Csar(filePath.toString()); + final var filePath = writeArtifactToFile(artifact, resultArtifact); + final var csarObject = new Csar(filePath.toString()); inputReceived(csarObject); sendDistributionStatus(DistributionStatusType.DEPLOY, artifact.getArtifactURL(), notificationData.getDistributionID(), DistributionStatusEnum.DEPLOY_OK, null); @@ -262,8 +262,8 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo final IDistributionClientDownloadResult resultArtifact) throws ArtifactDownloadException { try { final byte[] payloadBytes = resultArtifact.getArtifactPayload(); - final File tempArtifactFile = File.createTempFile(artifact.getArtifactName(), ".csar"); - try (FileOutputStream fileOutputStream = new FileOutputStream(tempArtifactFile)) { + final var tempArtifactFile = File.createTempFile(artifact.getArtifactName(), ".csar"); + try (var fileOutputStream = new FileOutputStream(tempArtifactFile)) { fileOutputStream.write(payloadBytes, 0, payloadBytes.length); return tempArtifactFile.toPath(); } @@ -315,7 +315,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo clientResult = distributionClient.sendDeploymentStatus(message); } } - final StringBuilder loggerMessage = new StringBuilder(); + final var loggerMessage = new StringBuilder(); loggerMessage.append("distribution status to SDC with values - ").append("DistributionId") .append(distributionId).append(" Artifact: ").append(artifactUrl).append(" StatusType: ") .append(statusType.name()).append(" Status: ").append(status.name()); @@ -351,7 +351,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo clientResult = distributionClient.sendComponentDoneStatus(message, errorReason); } - final StringBuilder loggerMessage = new StringBuilder(); + final var loggerMessage = new StringBuilder(); loggerMessage.append("component done status to SDC with values - ").append("DistributionId") .append(distributionId).append(" Status: ").append(status.name()); if (errorReason != null) { |