diff options
Diffstat (limited to 'main/src/main')
23 files changed, 121 insertions, 123 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/config/PapAafConfig.java b/main/src/main/java/org/onap/policy/pap/main/config/PapAafConfig.java index 4bbf29f6..f60728f0 100644 --- a/main/src/main/java/org/onap/policy/pap/main/config/PapAafConfig.java +++ b/main/src/main/java/org/onap/policy/pap/main/config/PapAafConfig.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.pap.main.config; -import javax.servlet.Filter; +import jakarta.servlet.Filter; import org.onap.policy.pap.main.rest.PapAafFilter; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; diff --git a/main/src/main/java/org/onap/policy/pap/main/config/WebSecurityConfig.java b/main/src/main/java/org/onap/policy/pap/main/config/WebSecurityConfig.java index 7d854598..181ea434 100644 --- a/main/src/main/java/org/onap/policy/pap/main/config/WebSecurityConfig.java +++ b/main/src/main/java/org/onap/policy/pap/main/config/WebSecurityConfig.java @@ -23,7 +23,9 @@ package org.onap.policy.pap.main.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.web.SecurityFilterChain; /** @@ -40,11 +42,9 @@ public class WebSecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http - .httpBasic() - .and() - .authorizeHttpRequests().anyRequest().authenticated() - .and() - .csrf().disable(); + .httpBasic(Customizer.withDefaults()) + .authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated()) + .csrf(AbstractHttpConfigurer::disable); return http.build(); } -}
\ No newline at end of file +} diff --git a/main/src/main/java/org/onap/policy/pap/main/exception/ServiceExceptionHandler.java b/main/src/main/java/org/onap/policy/pap/main/exception/ServiceExceptionHandler.java index 80887961..58876fc8 100644 --- a/main/src/main/java/org/onap/policy/pap/main/exception/ServiceExceptionHandler.java +++ b/main/src/main/java/org/onap/policy/pap/main/exception/ServiceExceptionHandler.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.pap.main.exception; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.core.Response; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java index ce7fdaa7..05144152 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ @@ -22,6 +22,7 @@ package org.onap.policy.pap.main.rest; +import jakarta.ws.rs.core.Response.Status; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -31,7 +32,6 @@ import java.util.Objects; import java.util.Set; import java.util.function.Consumer; import java.util.stream.Collectors; -import javax.ws.rs.core.Response.Status; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.parameters.ValidationStatus; @@ -84,7 +84,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { List<PdpSubGroup> subGroupsWithPolicies = groups.getGroups().parallelStream().flatMap(group -> group.getPdpSubgroups().parallelStream()) .filter(subGroup -> null != subGroup.getPolicies() && !subGroup.getPolicies().isEmpty()) - .collect(Collectors.toList()); + .toList(); if (!subGroupsWithPolicies.isEmpty()) { logger.warn( "Policies cannot be deployed during PdpGroup Create/Update operation. Ignoring the list of policies"); @@ -96,7 +96,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Creates or updates PDP groups. This is the method that does the actual work. * - * @param data session data + * @param data session data * @param groups PDP group configurations * @throws PfModelException if an error occurred */ @@ -134,7 +134,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Adds a new group. * - * @param data session data + * @param data session data * @param group the group to be added * @return the validation result * @throws PfModelException if an error occurred @@ -166,7 +166,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Performs additional validations of a group, but does not examine the subgroups. * - * @param group the group to be validated + * @param group the group to be validated * @param result the validation result */ private void validateGroupOnly(PdpGroup group, BeanValidationResult result) { @@ -174,24 +174,19 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { return; } - switch (group.getPdpGroupState()) { - case ACTIVE: - case PASSIVE: - break; - - default: - result.addResult("pdpGroupState", group.getPdpGroupState(), - ValidationStatus.INVALID, "must be null, ACTIVE, or PASSIVE"); - break; + PdpState pdpGroupState = group.getPdpGroupState(); + if (pdpGroupState != PdpState.ACTIVE && pdpGroupState != PdpState.PASSIVE) { + result.addResult("pdpGroupState", group.getPdpGroupState(), + ValidationStatus.INVALID, "must be null, ACTIVE, or PASSIVE"); } } /** * Updates an existing group. * - * @param data session data + * @param data session data * @param dbgroup the group, as it appears within the DB - * @param group the group to be added + * @param group the group to be added * @return the validation result * @throws PfModelException if an error occurred */ @@ -216,13 +211,12 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { } /** - * Updates a field, if the new value is different than the old value. + * Updates a field, if the new value is different from the old value. * * @param oldValue old value * @param newValue new value - * @param setter function to set the field to the new value - * @return {@code true} if the field was updated, {@code false} if it already matched - * the new value + * @param setter function to set the field to the new value + * @return {@code true} if the field was updated, {@code false} if it already matched the new value */ private <T> boolean updateField(T oldValue, T newValue, Consumer<T> setter) { if (oldValue == newValue) { @@ -240,15 +234,15 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Adds or updates subgroups within the group. * - * @param data session data + * @param data session data * @param dbgroup the group, as it appears within the DB - * @param group the group to be added - * @param result the validation result + * @param group the group to be added + * @param result the validation result * @return {@code true} if the DB group was modified, {@code false} otherwise * @throws PfModelException if an error occurred */ private boolean addOrUpdateSubGroups(SessionData data, PdpGroup dbgroup, PdpGroup group, - BeanValidationResult result) throws PfModelException { + BeanValidationResult result) throws PfModelException { // create a map of existing subgroups Map<String, PdpSubGroup> type2sub = new HashMap<>(); @@ -278,9 +272,9 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Notifies any PDPs whose subgroups are being removed. * - * @param data session data + * @param data session data * @param dbgroup the group, as it appears within the DB - * @param group the group being updated + * @param group the group being updated * @return {@code true} if a subgroup was removed, {@code false} otherwise * @throws PfModelException if an error occurred */ @@ -308,7 +302,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Notifies the PDPs that their subgroup is being removed. * - * @param data session data + * @param data session data * @param subgrp subgroup that is being removed */ private void notifyPdpsDelSubGroup(SessionData data, PdpSubGroup subgrp) { @@ -333,9 +327,9 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Tracks PDP responses when their subgroup is removed. * - * @param data session data + * @param data session data * @param pdpGroup PdpGroup name - * @param subgrp subgroup that is being removed + * @param subgrp subgroup that is being removed * @throws PfModelException if an error occurred */ private void trackPdpsDelSubGroup(SessionData data, String pdpGroup, PdpSubGroup subgrp) throws PfModelException { @@ -349,9 +343,9 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Adds a new subgroup. * - * @param data session data + * @param data session data * @param subgrp the subgroup to be added, updated to fully qualified versions upon - * return + * return * @return the validation result * @throws PfModelException if an error occurred */ @@ -368,12 +362,11 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Updates an existing subgroup. * - * @param dbsub the subgroup, from the DB - * @param subgrp the subgroup to be updated, updated to fully qualified versions upon - * return + * @param dbsub the subgroup, from the DB + * @param subgrp the subgroup to be updated, updated to fully qualified versions upon + * return * @param container container for additional validation results - * @return {@code true} if the subgroup content was changed, {@code false} if there - * were no changes + * @return {@code true} if the subgroup content was changed, {@code false} if there were no changes */ private boolean updateSubGroup(PdpSubGroup dbsub, PdpSubGroup subgrp, BeanValidationResult container) { @@ -399,9 +392,9 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Performs additional validations of a subgroup. * - * @param dbsub the subgroup, from the DB - * @param subgrp the subgroup to be validated, updated to fully qualified versions - * upon return + * @param dbsub the subgroup, from the DB + * @param subgrp the subgroup to be validated, updated to fully qualified versions + * upon return * @param container container for additional validation results * @return {@code true} if the subgroup is valid, {@code false} otherwise */ @@ -421,7 +414,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { /** * Performs validations of the supported policy types within a subgroup. * - * @param data session data + * @param data session data * @param subgrp the subgroup to be validated * @return the validation result * @throws PfModelException if an error occurred @@ -439,7 +432,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase { @Override protected Updater makeUpdater(SessionData data, ToscaPolicy policy, - ToscaConceptIdentifierOptVersion desiredPolicy) { + ToscaConceptIdentifierOptVersion desiredPolicy) { throw new UnsupportedOperationException("makeUpdater should not be invoked"); } } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java index 1a04e061..56126b90 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeleteProvider.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020-2021 Nordix Foundation. + * Modifications Copyright (C) 2020-2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,11 +22,11 @@ package org.onap.policy.pap.main.rest; +import jakarta.ws.rs.core.Response.Status; import java.util.Iterator; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; -import javax.ws.rs.core.Response.Status; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pdp.concepts.Pdp; import org.onap.policy.models.pdp.concepts.PdpGroup; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java index 7a3e3395..fa52650f 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2022 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020-2021 Nordix Foundation. + * Modifications Copyright (C) 2020-2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2021, 2023 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,6 +23,7 @@ package org.onap.policy.pap.main.rest; import com.google.gson.annotations.SerializedName; +import jakarta.ws.rs.core.Response.Status; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -31,7 +32,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import javax.ws.rs.core.Response.Status; import lombok.Getter; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.BeanValidator; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java index b1f7f665..648b56f1 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2021 Nordix Foundation. + * Copyright (C) 2019-2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ @@ -22,8 +22,8 @@ package org.onap.policy.pap.main.rest; +import jakarta.ws.rs.core.Response; import java.util.List; -import javax.ws.rs.core.Response; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java index 4da802df..02d27605 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020, 2022 Nordix Foundation. + * Copyright (C) 2019-2020, 2022-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved. * ================================================================================ @@ -22,6 +22,10 @@ package org.onap.policy.pap.main.rest; +import jakarta.annotation.PostConstruct; +import jakarta.annotation.PreDestroy; +import jakarta.ws.rs.core.Response; +import jakarta.ws.rs.core.Response.Status; import java.net.HttpURLConnection; import java.util.AbstractMap; import java.util.ArrayList; @@ -36,10 +40,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.regex.Pattern; import java.util.stream.Collectors; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.common.endpoints.http.client.HttpClient; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java index 9857883c..26234297 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java @@ -3,8 +3,8 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020-2022 Nordix Foundation. - * Modifications Copyright (C) 2020,2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2020-2023 Nordix Foundation. + * Modifications Copyright (C) 2020, 2022 Bell Canada. 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. @@ -22,8 +22,8 @@ package org.onap.policy.pap.main.rest; +import jakarta.ws.rs.core.Response.Status; import java.util.Collection; -import javax.ws.rs.core.Response.Status; import org.onap.policy.common.utils.services.Registry; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java index 4cea257f..81afda37 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java @@ -3,7 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2021-2022 Nordix Foundation. + * Modifications Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +31,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import lombok.Getter; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfModelException; @@ -123,14 +122,14 @@ public class SessionData { /** * Constructs the object. * - * @param user user triggering the request - * @param policyAuditService the policyAuditService + * @param user user triggering the request + * @param policyAuditService the policyAuditService * @param policyStatusService the policyStatusService - * @param pdpGroupService the pdpGroupService - * @param toscaService the toscaService + * @param pdpGroupService the pdpGroupService + * @param toscaService the toscaService */ public SessionData(String user, ToscaServiceTemplateService toscaService, PdpGroupService pdpGroupService, - PolicyStatusService policyStatusService, PolicyAuditService policyAuditService) { + PolicyStatusService policyStatusService, PolicyAuditService policyAuditService) { this.toscaService = toscaService; this.pdpGroupService = pdpGroupService; this.deployStatus = makeDeploymentStatus(policyStatusService); @@ -197,11 +196,11 @@ public class SessionData { /** * Sets the "version" in a policy filter. * - * @param filterBuilder filter builder whose version should be set + * @param filterBuilder filter builder whose version should be set * @param desiredVersion desired version */ private void setPolicyFilterVersion(ToscaTypedEntityFilterBuilder<ToscaPolicy> filterBuilder, - String desiredVersion) { + String desiredVersion) { if (desiredVersion == null) { // no version specified - get the latest @@ -239,7 +238,7 @@ public class SessionData { } logger.info("add update and state-change {} {} {} policies={}", update.getName(), update.getPdpGroup(), - update.getPdpSubgroup(), update.getPoliciesToBeDeployed().size()); + update.getPdpSubgroup(), update.getPoliciesToBeDeployed().size()); pdpRequests.put(update.getName(), Pair.of(update, change)); } @@ -250,7 +249,7 @@ public class SessionData { */ public void addUpdate(PdpUpdate update) { logger.info("add update {} {} {} policies={}", update.getName(), update.getPdpGroup(), update.getPdpSubgroup(), - update.getPoliciesToBeDeployed().size()); + update.getPoliciesToBeDeployed().size()); pdpRequests.compute(update.getName(), (name, data) -> Pair.of(update, (data == null ? null : data.getRight()))); } @@ -288,8 +287,8 @@ public class SessionData { * @return the PDP requests */ public List<PdpUpdate> getPdpUpdates() { - return pdpRequests.values().stream().filter(req -> req.getLeft() != null).map(Pair::getLeft) - .collect(Collectors.toList()); + return pdpRequests.values().stream().filter(req -> req.getLeft() != null) + .map(Pair::getLeft).toList(); } /** @@ -298,8 +297,8 @@ public class SessionData { * @return the PDP requests */ public List<PdpStateChange> getPdpStateChanges() { - return pdpRequests.values().stream().filter(req -> req.getRight() != null).map(Pair::getRight) - .collect(Collectors.toList()); + return pdpRequests.values().stream().filter(req -> req.getRight() != null) + .map(Pair::getRight).toList(); } /** @@ -377,15 +376,15 @@ public class SessionData { List<GroupData> data = type2groups.get(type); // NOSONAR if (data == null) { PdpGroupFilter filter = PdpGroupFilter.builder().policyTypeList(Collections.singletonList(type)) - .groupState(PdpState.ACTIVE).build(); + .groupState(PdpState.ACTIVE).build(); List<PdpGroup> groups = pdpGroupService.getFilteredPdpGroups(filter); - data = groups.stream().map(this::addGroup).collect(Collectors.toList()); + data = groups.stream().map(this::addGroup).toList(); type2groups.put(type, data); } - return data.stream().map(GroupData::getGroup).collect(Collectors.toList()); + return data.stream().map(GroupData::getGroup).toList(); } /** @@ -433,22 +432,22 @@ public class SessionData { */ public void updateDb(PolicyNotification notification) { // create new groups - List<GroupData> created = groupCache.values().stream().filter(GroupData::isNew).collect(Collectors.toList()); + List<GroupData> created = groupCache.values().stream().filter(GroupData::isNew).toList(); if (!created.isEmpty()) { if (logger.isInfoEnabled()) { created.forEach(group -> logger.info("creating DB group {}", group.getGroup().getName())); } - pdpGroupService.createPdpGroups(created.stream().map(GroupData::getGroup).collect(Collectors.toList())); + pdpGroupService.createPdpGroups(created.stream().map(GroupData::getGroup).toList()); } // update existing groups List<GroupData> updated = - groupCache.values().stream().filter(GroupData::isUpdated).collect(Collectors.toList()); + groupCache.values().stream().filter(GroupData::isUpdated).toList(); if (!updated.isEmpty()) { if (logger.isInfoEnabled()) { updated.forEach(group -> logger.info("updating DB group {}", group.getGroup().getName())); } - pdpGroupService.updatePdpGroups(updated.stream().map(GroupData::getGroup).collect(Collectors.toList())); + pdpGroupService.updatePdpGroups(updated.stream().map(GroupData::getGroup).toList()); } // send audits records to DB @@ -471,14 +470,14 @@ public class SessionData { /** * Adds policy deployment data. * - * @param policy policy being deployed - * @param pdps PDPs to which the policy is being deployed + * @param policy policy being deployed + * @param pdps PDPs to which the policy is being deployed * @param pdpGroup PdpGroup containing the PDP of interest - * @param pdpType PDP type (i.e., PdpSubGroup) containing the PDP of interest + * @param pdpType PDP type (i.e., PdpSubGroup) containing the PDP of interest * @throws PfModelException if an error occurred */ protected void trackDeploy(ToscaPolicy policy, Collection<String> pdps, String pdpGroup, String pdpType) - throws PfModelException { + throws PfModelException { ToscaConceptIdentifier policyId = policy.getIdentifier(); policiesToBeDeployed.put(policyId, policy); @@ -490,13 +489,13 @@ public class SessionData { * Adds policy undeployment data. * * @param policyId ID of the policy being undeployed - * @param pdps PDPs to which the policy is being undeployed + * @param pdps PDPs to which the policy is being undeployed * @param pdpGroup PdpGroup containing the PDP of interest - * @param pdpType PDP type (i.e., PdpSubGroup) containing the PDP of interest + * @param pdpType PDP type (i.e., PdpSubGroup) containing the PDP of interest * @throws PfModelException if an error occurred */ protected void trackUndeploy(ToscaConceptIdentifier policyId, Collection<String> pdps, String pdpGroup, - String pdpType) throws PfModelException { + String pdpType) throws PfModelException { policiesToBeUndeployed.add(policyId); addData(policyId, pdps, pdpGroup, pdpType, false); @@ -507,14 +506,14 @@ public class SessionData { * Adds policy deployment/undeployment data. * * @param policyId ID of the policy being deployed/undeployed - * @param pdps PDPs to which the policy is being deployed/undeployed - * @param deploy {@code true} if the policy is being deployed, {@code false} if undeployed + * @param pdps PDPs to which the policy is being deployed/undeployed + * @param deploy {@code true} if the policy is being deployed, {@code false} if undeployed * @param pdpGroup PdpGroup containing the PDP of interest - * @param pdpType PDP type (i.e., PdpSubGroup) containing the PDP of interest + * @param pdpType PDP type (i.e., PdpSubGroup) containing the PDP of interest * @throws PfModelException if an error occurred */ private void addData(ToscaConceptIdentifier policyId, Collection<String> pdps, String pdpGroup, String pdpType, - boolean deploy) throws PfModelException { + boolean deploy) throws PfModelException { // delete all records whose "deploy" flag is the opposite of what we want deployStatus.deleteDeployment(policyId, !deploy); diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupCreateOrUpdateControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupCreateOrUpdateControllerV1Stub.java index 81ab6366..1944955e 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupCreateOrUpdateControllerV1Stub.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupCreateOrUpdateControllerV1Stub.java @@ -20,8 +20,8 @@ package org.onap.policy.pap.main.rest.stub; +import jakarta.validation.Valid; import java.util.UUID; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import org.onap.policy.models.pap.concepts.PdpGroupUpdateResponse; import org.onap.policy.models.pdp.concepts.PdpGroups; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeployControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeployControllerV1Stub.java index f9ed98e4..0a790cc9 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeployControllerV1Stub.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupDeployControllerV1Stub.java @@ -20,8 +20,8 @@ package org.onap.policy.pap.main.rest.stub; +import jakarta.validation.Valid; import java.util.UUID; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import org.onap.policy.models.pap.concepts.PdpDeployPolicies; import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupStateChangeControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupStateChangeControllerV1Stub.java index dc4f236f..fcc2885a 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupStateChangeControllerV1Stub.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PdpGroupStateChangeControllerV1Stub.java @@ -20,9 +20,9 @@ package org.onap.policy.pap.main.rest.stub; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import java.util.UUID; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; import lombok.RequiredArgsConstructor; import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse; import org.onap.policy.models.pdp.enums.PdpState; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyAuditControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyAuditControllerV1Stub.java index b9f2c4e8..7710a370 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyAuditControllerV1Stub.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyAuditControllerV1Stub.java @@ -20,11 +20,11 @@ package org.onap.policy.pap.main.rest.stub; +import jakarta.validation.Valid; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import java.util.List; import java.util.UUID; -import javax.validation.Valid; -import javax.validation.constraints.Max; -import javax.validation.constraints.Min; import lombok.RequiredArgsConstructor; import org.onap.policy.models.pap.concepts.PolicyAudit; import org.onap.policy.pap.main.rest.PapRestControllerV1; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyStatusControllerV1Stub.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyStatusControllerV1Stub.java index 323320ab..c3175399 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyStatusControllerV1Stub.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/PolicyStatusControllerV1Stub.java @@ -20,8 +20,8 @@ package org.onap.policy.pap.main.rest.stub; +import jakarta.validation.Valid; import java.util.UUID; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import org.onap.policy.pap.main.rest.PapRestControllerV1; import org.onap.policy.pap.main.rest.PolicyStatusControllerV1Api; diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java index 8eb4aba3..04e05793 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java @@ -22,13 +22,12 @@ package org.onap.policy.pap.main.rest.stub; import com.google.gson.Gson; +import jakarta.servlet.http.HttpServletRequest; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.onap.policy.pap.main.rest.PapRestControllerV1; import org.slf4j.Logger; @@ -75,7 +74,7 @@ class StubUtils { final var resource = new ClassPathResource(PAP_DB); try (var inputStream = resource.getInputStream()) { final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); - var targetObject = Arrays.asList(JSON_TRANSLATOR.fromJson(string, clazz)); + var targetObject = List.of(JSON_TRANSLATOR.fromJson(string, clazz)); return new ResponseEntity<>(targetObject, HttpStatus.OK); } catch (IOException e) { log.error(SERIALIZE_RESPONSE_FAILURE_MSG, e); diff --git a/main/src/main/java/org/onap/policy/pap/main/service/PdpGroupService.java b/main/src/main/java/org/onap/policy/pap/main/service/PdpGroupService.java index 5f0520ff..09c9640f 100644 --- a/main/src/main/java/org/onap/policy/pap/main/service/PdpGroupService.java +++ b/main/src/main/java/org/onap/policy/pap/main/service/PdpGroupService.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +21,9 @@ package org.onap.policy.pap.main.service; +import jakarta.ws.rs.core.Response; import java.util.ArrayList; import java.util.List; -import javax.ws.rs.core.Response; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.onap.policy.common.parameters.BeanValidationResult; @@ -151,11 +152,12 @@ public class PdpGroupService { * @param pdpGroup the name of the pdpGroup to delete */ public void deletePdpGroup(String pdpGroup) { - try { - pdpGroupRepository.deleteById(new PfConceptKey(pdpGroup, "0.0.0")); - } catch (Exception exc) { + PfConceptKey groupKey = new PfConceptKey(pdpGroup, "0.0.0"); + if (pdpGroupRepository.existsById(groupKey)) { + pdpGroupRepository.deleteById(groupKey); + } else { String errorMessage = "delete of PDP group \"" + pdpGroup + "\" failed, PDP group does not exist"; - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage, exc); + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); } } diff --git a/main/src/main/java/org/onap/policy/pap/main/service/PolicyAuditService.java b/main/src/main/java/org/onap/policy/pap/main/service/PolicyAuditService.java index f582135d..bd9f6bc6 100644 --- a/main/src/main/java/org/onap/policy/pap/main/service/PolicyAuditService.java +++ b/main/src/main/java/org/onap/policy/pap/main/service/PolicyAuditService.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +21,11 @@ package org.onap.policy.pap.main.service; +import jakarta.ws.rs.core.Response; import java.time.Instant; import java.util.Date; import java.util.List; import java.util.stream.Collectors; -import javax.ws.rs.core.Response; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.onap.policy.common.parameters.BeanValidationResult; diff --git a/main/src/main/java/org/onap/policy/pap/main/service/PolicyStatusService.java b/main/src/main/java/org/onap/policy/pap/main/service/PolicyStatusService.java index 09870314..ac7830d2 100644 --- a/main/src/main/java/org/onap/policy/pap/main/service/PolicyStatusService.java +++ b/main/src/main/java/org/onap/policy/pap/main/service/PolicyStatusService.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +21,11 @@ package org.onap.policy.pap.main.service; +import jakarta.ws.rs.core.Response; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import javax.ws.rs.core.Response; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.onap.policy.common.parameters.BeanValidationResult; diff --git a/main/src/main/java/org/onap/policy/pap/main/service/ToscaNodeTemplateService.java b/main/src/main/java/org/onap/policy/pap/main/service/ToscaNodeTemplateService.java index 9b097ccb..091db0cc 100644 --- a/main/src/main/java/org/onap/policy/pap/main/service/ToscaNodeTemplateService.java +++ b/main/src/main/java/org/onap/policy/pap/main/service/ToscaNodeTemplateService.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP PAP * ================================================================================ - * Copyright (C) 2022, Nordix Foundation. All rights reserved. + * Copyright (C) 2022-2023 Nordix Foundation. 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. @@ -20,8 +20,8 @@ package org.onap.policy.pap.main.service; +import jakarta.ws.rs.core.Response; import java.util.Optional; -import javax.ws.rs.core.Response; import lombok.RequiredArgsConstructor; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelRuntimeException; diff --git a/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java b/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java index 77c01783..222f240c 100644 --- a/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java +++ b/main/src/main/java/org/onap/policy/pap/main/service/ToscaServiceTemplateService.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,13 +21,13 @@ package org.onap.policy.pap.main.service; +import jakarta.ws.rs.core.Response; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import javax.ws.rs.core.Response; import lombok.RequiredArgsConstructor; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapDatabaseInitializer.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapDatabaseInitializer.java index b2a42d9c..790d9517 100644 --- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapDatabaseInitializer.java +++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapDatabaseInitializer.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019, 2023 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. * ================================================================================ @@ -22,8 +22,8 @@ package org.onap.policy.pap.main.startstop; +import jakarta.annotation.PostConstruct; import java.util.List; -import javax.annotation.PostConstruct; import org.onap.policy.common.parameters.ValidationResult; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; diff --git a/main/src/main/resources/application.yaml b/main/src/main/resources/application.yaml index 4a7083a0..704306b5 100644 --- a/main/src/main/resources/application.yaml +++ b/main/src/main/resources/application.yaml @@ -90,5 +90,6 @@ management: base-path: / exposure: include: health, metrics, prometheus - path-mapping.metrics: plain-metrics - path-mapping.prometheus: metrics + path-mapping: + -metrics: plain-metrics + -prometheus: metrics |