private Long pdpHeartbeatIntervalMs;
- /**
- * Policies that the PDP should deploy. This is a complete list, so PDPs should be
- * prepared to deploy new policies listed and undeploy policies that are no longer
- * listed. Note: this list may be empty, as a PDP may remain attached to a subgroup
- * even if all of the policies are removed from the subgroup.
- */
- private List<ToscaPolicy> policies = new LinkedList<>();
-
/**
* Policies that the PDP should deploy.
*/
this.description = source.description;
this.pdpHeartbeatIntervalMs = source.pdpHeartbeatIntervalMs;
- this.policies = (source.policies == null ? null
- : source.policies.stream().map(ToscaPolicy::new).collect(Collectors.toList()));
+ this.policiesToBeDeployed = (source.policiesToBeDeployed == null ? null
+ : source.policiesToBeDeployed.stream().map(ToscaPolicy::new).collect(Collectors.toList()));
+ this.policiesToBeUndeployed = (source.policiesToBeUndeployed == null ? null
+ : source.policiesToBeUndeployed.stream().map(ToscaConceptIdentifier::new).collect(Collectors.toList()));
}
}
* ONAP Policy Models
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.Arrays;
import java.util.List;
+import java.util.stream.Collectors;
import org.junit.Test;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
assertThatThrownBy(() -> new PdpUpdate(null)).isInstanceOf(NullPointerException.class);
PdpUpdate orig = new PdpUpdate();
- orig.setPolicies(null);
+ orig.setPoliciesToBeDeployed(null);
+ orig.setPoliciesToBeUndeployed(null);
// verify with null values
assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpUpdate(orig).toString()));
policy2.setVersion("4.5.6");
List<ToscaPolicy> policies = Arrays.asList(policy1, policy2);
- orig.setPolicies(policies);
+ orig.setPoliciesToBeDeployed(policies);
+ orig.setPoliciesToBeUndeployed(policies.stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList()));
PdpUpdate other = new PdpUpdate(orig);
assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
// ensure list and items are not the same object
- assertNotSame(other.getPolicies(), policies);
- assertNotSame(other.getPolicies().get(0), policies.get(0));
+ assertNotSame(other.getPoliciesToBeDeployed(), policies);
+ assertNotSame(other.getPoliciesToBeDeployed().get(0), policies.get(0));
+ assertNotSame(other.getPoliciesToBeUndeployed(), policies);
+ assertNotSame(other.getPoliciesToBeUndeployed().get(0), policies.get(0));
}
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.models.sim.pdp.handler;
+import java.util.ArrayList;
import java.util.List;
+import java.util.stream.Collectors;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.sim.pdp.PdpSimulatorConstants;
import org.onap.policy.models.sim.pdp.comm.PdpStatusPublisher;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
/**
* This class supports the handling of pdp update messages.
}
pdpStatusContext.setPdpGroup(pdpUpdateMsg.getPdpGroup());
pdpStatusContext.setPdpSubgroup(pdpUpdateMsg.getPdpSubgroup());
- pdpStatusContext
- .setPolicies(new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
- if (pdpStatusContext.getState().equals(PdpState.ACTIVE) && !pdpUpdateMsg.getPolicies().isEmpty()) {
+ @SuppressWarnings("unchecked")
+ List<ToscaPolicy> policies = Registry.getOrDefault(PdpSimulatorConstants.REG_PDP_TOSCA_POLICY_LIST,
+ List.class, new ArrayList<>());
+ policies.addAll(pdpUpdateMsg.getPoliciesToBeDeployed());
+ policies.removeIf(policy -> pdpUpdateMsg.getPoliciesToBeUndeployed().contains(policy.getIdentifier()));
+ pdpStatusContext.setPolicies(policies.stream().map(ToscaPolicy::getIdentifier)
+ .collect(Collectors.toList()));
+ if (pdpStatusContext.getState().equals(PdpState.ACTIVE)
+ && !pdpUpdateMsg.getPoliciesToBeDeployed().isEmpty()) {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp engine started and policies are running.");
}
- Registry.registerOrReplace(PdpSimulatorConstants.REG_PDP_TOSCA_POLICY_LIST, pdpUpdateMsg.getPolicies());
+ Registry.registerOrReplace(PdpSimulatorConstants.REG_PDP_TOSCA_POLICY_LIST, policies);
if (null == pdpResponseDetails) {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp update successful.");
return false;
}
- return null != pdpStatusContext.getPolicies() && new PdpMessageHandler()
- .getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()).equals(pdpStatusContext.getPolicies());
+ return null != pdpStatusContext.getPolicies() && (pdpStatusContext.getPolicies()
+ .containsAll(new PdpMessageHandler().getToscaPolicyIdentifiers(
+ pdpUpdateMsg.getPoliciesToBeDeployed()))) && pdpStatusContext.getPolicies()
+ .stream().noneMatch(pdpUpdateMsg.getPoliciesToBeUndeployed()::contains);
}
/**
toscaPolicy.setProperties(propertiesMap);
final List<ToscaPolicy> toscaPolicies = new ArrayList<>();
toscaPolicies.add(toscaPolicy);
- pdpUpdateMsg.setPolicies(toscaPolicies);
+ pdpUpdateMsg.setPoliciesToBeDeployed(toscaPolicies);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
return pdpUpdateMsg;
}
toscaPolicy.setProperties(propertiesMap);
final List<ToscaPolicy> toscaPolicies = new ArrayList<>();
toscaPolicies.add(toscaPolicy);
- pdpUpdateMsg.setPolicies(toscaPolicies);
+ pdpUpdateMsg.setPoliciesToBeDeployed(toscaPolicies);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
assertEquals(pdpStatus.getPdpGroup(), pdpUpdateMsg.getPdpGroup());
assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup());
assertEquals(pdpStatus.getPolicies(),
- new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
+ new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
}
}