@ToString
public class ControlLoopElementAck {
+ // State of the controlLoopElement
+ private ControlLoopState state;
+
// Result: Success/Fail.
private Boolean result;
// Message indicating reason for failure
private String message;
-
}
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
*/
private ToscaConceptIdentifier participantId;
+ /**
+ * Participant State, or {@code null} for messages from participants.
+ */
+ private ParticipantState state;
+
/**
* Constructor for instantiating a participant ack message class.
*
this.messageType = source.messageType;
this.participantType = source.participantType;
this.participantId = source.participantId;
+ this.state = source.state;
}
/**
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementAck;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
orig.setControlLoopId(id);
orig.setParticipantId(id);
orig.setParticipantType(id);
- var clElementResult = new ControlLoopElementAck(true, "ControlLoopElement result");
+ var clElementResult = new ControlLoopElementAck(ControlLoopState.UNINITIALISED,
+ true, "ControlLoopElement result");
final var controlLoopResultMap = Map.of(UUID.randomUUID(), clElementResult);
orig.setControlLoopResultMap(controlLoopResultMap);
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @param newState the state to which the control loop element is changing to
*/
@Override
- public void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState,
+ public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId,
+ UUID controlLoopElementId, ControlLoopState currentState,
ControlLoopOrderedState newState) {
switch (newState) {
case UNINITIALISED:
var loop = clampClient.getstatus(LOOP);
if (loop != null) {
clampClient.undeploy(LOOP);
- intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState,
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState,
ControlLoopState.UNINITIALISED, ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
}
break;
case PASSIVE:
- intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.PASSIVE,
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.PASSIVE,
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
break;
case RUNNING:
- intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.RUNNING,
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.RUNNING,
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
break;
default:
* @throws PfModelException in case of an exception
*/
@Override
- public void controlLoopElementUpdate(ControlLoopElement element, ToscaNodeTemplate nodeTemplate)
- throws PfModelException {
+ public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId,
+ ControlLoopElement element, ToscaNodeTemplate nodeTemplate)
+ throws PfModelException {
try {
var loop = getStatus();
loop = getStatus();
String status = ClampHttpClient.getStatusCode(loop);
if (MICROSERVICE_INSTALLED_SUCCESSFULLY.equals(status)) {
- intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(),
- ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE);
+ intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(),
+ element.getOrderedState(), ControlLoopState.PASSIVE,
+ ParticipantMessageType.CONTROL_LOOP_UPDATE);
deployedFlag = true;
break;
}
}
if (!deployedFlag) {
LOGGER.warn("DCAE is not deployed properly, ClElement state will be UNINITIALISED2PASSIVE");
- intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(),
- ControlLoopState.UNINITIALISED2PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE);
+ intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(),
+ element.getOrderedState(), ControlLoopState.UNINITIALISED2PASSIVE,
+ ParticipantMessageType.CONTROL_LOOP_UPDATE);
}
}
} catch (PfModelException e) {
controlLoopElementHandler.setIntermediaryApi(intermediaryApi);
UUID controlLoopElementId = UUID.randomUUID();
- controlLoopElementHandler.controlLoopElementStateChange(controlLoopElementId, ControlLoopState.PASSIVE,
+ controlLoopElementHandler.controlLoopElementStateChange(TestListenerUtils.getControlLoopId(),
+ controlLoopElementId, ControlLoopState.PASSIVE,
ControlLoopOrderedState.UNINITIALISED);
verify(clampClient).undeploy(LOOP);
element.setOrderedState(ControlLoopOrderedState.PASSIVE);
final ToscaServiceTemplate controlLoopDefinition = new ToscaServiceTemplate();
- controlLoopElementHandler.controlLoopElementUpdate(element,
+ controlLoopElementHandler.controlLoopElementUpdate(TestListenerUtils.getControlLoopId(), element,
controlLoopDefinition.getToscaTopologyTemplate().getNodeTemplates()
.get("org.onap.domain.pmsh.PMSH_DCAEMicroservice"));
element.setOrderedState(ControlLoopOrderedState.PASSIVE);
ToscaServiceTemplate controlLoopDefinition = new ToscaServiceTemplate();
- controlLoopElementHandler.controlLoopElementUpdate(element,
+ controlLoopElementHandler.controlLoopElementUpdate(TestListenerUtils.getControlLoopId(), element,
controlLoopDefinition.getToscaTopologyTemplate().getNodeTemplates()
.get("org.onap.domain.pmsh.PMSH_DCAEMicroservice"));
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) {
- if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
ControlLoopElement clElement = new ControlLoopElement();
clElement.setId(UUID.randomUUID());
ToscaConceptIdentifier clParticipantType;
return clUpdateMsg;
}
+ private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
+ ToscaServiceTemplate toscaServiceTemplate) {
+ if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
+ return true;
+ } else {
+ var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
+ if (nodeType != null) {
+ var derivedFrom = nodeType.getDerivedFrom();
+ if (derivedFrom != null) {
+ return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
+ }
+ }
+ }
+ return false;
+ }
+
private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement,
List<ParticipantUpdates> participantUpdates) {
if (participantUpdates.isEmpty()) {
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
ToscaConceptIdentifier clParticipantType;
try {
clParticipantType = CODER.decode(
return participantDefinition;
}
+ public static ToscaConceptIdentifier getControlLoopId() {
+ return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ }
+
/**
* Method to create a deep copy of ControlLoopUpdateMsg.
*
* @throws PfModelException in case of a model exception
*/
@Override
- public void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState,
- ControlLoopOrderedState newState) throws PfModelException {
+ public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId, UUID controlLoopElementId,
+ ControlLoopState currentState, ControlLoopOrderedState newState) throws PfModelException {
// Implementation not needed for http participant
}
* @param nodeTemplate toscaNodeTemplate
*/
@Override
- public void controlLoopElementUpdate(ControlLoopElement element, ToscaNodeTemplate nodeTemplate) {
+ public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element,
+ ToscaNodeTemplate nodeTemplate) {
try {
var configRequest = CODER.convert(nodeTemplate.getProperties(), ConfigRequest.class);
Set<ConstraintViolation<ConfigRequest>> violations = Validation.buildDefaultValidatorFactory()
serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
assertDoesNotThrow(() -> controlLoopElementHandler
- .controlLoopElementUpdate(element, nodeTemplatesMap.get(HTTP_CONTROL_LOOP_ELEMENT)));
+ .controlLoopElementUpdate(commonTestData.getControlLoopId(), element,
+ nodeTemplatesMap.get(HTTP_CONTROL_LOOP_ELEMENT)));
}
}
);
}
+ /**
+ * Get controlloop id.
+ * @return ToscaConceptIdentifier controlLoopId
+ */
+ public ToscaConceptIdentifier getControlLoopId() {
+ return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ }
+
/**
* Get headers for config request.
* @return Map of headers
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @param newState the state to which the control loop element is changing to
*/
@Override
- public synchronized void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState,
- ControlLoopOrderedState newState) {
+ public synchronized void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId,
+ UUID controlLoopElementId, ControlLoopState currentState, ControlLoopOrderedState newState) {
switch (newState) {
case UNINITIALISED:
ChartInfo chart = chartMap.get(controlLoopElementId);
LOGGER.info("Helm deployment to be deleted {} ", chart.getReleaseName());
try {
chartService.uninstallChart(chart);
- intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState,
- ControlLoopState.UNINITIALISED, ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.UNINITIALISED,
+ ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
chartMap.remove(controlLoopElementId);
podStatusMap.remove(chart.getReleaseName());
} catch (ServiceException se) {
}
break;
case PASSIVE:
- intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.PASSIVE,
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.PASSIVE,
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
break;
case RUNNING:
- intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.RUNNING,
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.RUNNING,
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
break;
default:
* @throws PfModelException in case of an exception
*/
@Override
- public synchronized void controlLoopElementUpdate(ControlLoopElement element,
- ToscaNodeTemplate nodeTemplate) throws PfModelException {
+ public synchronized void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId,
+ ControlLoopElement element, ToscaNodeTemplate nodeTemplate) throws PfModelException {
@SuppressWarnings("unchecked")
Map<String, Object> chartData =
(Map<String, Object>) nodeTemplate.getProperties().get("chart");
import org.onap.policy.clamp.controlloop.participant.kubernetes.exception.ServiceException;
import org.onap.policy.clamp.controlloop.participant.kubernetes.models.ChartInfo;
import org.onap.policy.clamp.controlloop.participant.kubernetes.models.ChartList;
+import org.onap.policy.clamp.controlloop.participant.kubernetes.parameters.CommonTestData;
import org.onap.policy.clamp.controlloop.participant.kubernetes.service.ChartService;
import org.onap.policy.clamp.controlloop.participant.kubernetes.utils.TestUtils;
import org.onap.policy.common.utils.coder.Coder;
private static ToscaServiceTemplate toscaServiceTemplate;
private static final String K8S_CONTROL_LOOP_ELEMENT =
"org.onap.domain.database.PMSH_K8SMicroserviceControlLoopElement";
-
+ private CommonTestData commonTestData = new CommonTestData();
@InjectMocks
@Spy
doNothing().when(chartService).uninstallChart(charts.get(0));
- controlLoopElementHandler.controlLoopElementStateChange(controlLoopElementId1, ControlLoopState.PASSIVE,
- ControlLoopOrderedState.UNINITIALISED);
+ controlLoopElementHandler.controlLoopElementStateChange(commonTestData.getControlLoopId(),
+ controlLoopElementId1, ControlLoopState.PASSIVE, ControlLoopOrderedState.UNINITIALISED);
doThrow(new ServiceException("Error uninstalling the chart")).when(chartService)
.uninstallChart(charts.get(0));
assertDoesNotThrow(() -> controlLoopElementHandler
- .controlLoopElementStateChange(controlLoopElementId1, ControlLoopState.PASSIVE,
- ControlLoopOrderedState.UNINITIALISED));
+ .controlLoopElementStateChange(commonTestData.getControlLoopId(), controlLoopElementId1,
+ ControlLoopState.PASSIVE, ControlLoopOrderedState.UNINITIALISED));
assertDoesNotThrow(() -> controlLoopElementHandler
- .controlLoopElementStateChange(controlLoopElementId1, ControlLoopState.PASSIVE,
- ControlLoopOrderedState.RUNNING));
+ .controlLoopElementStateChange(commonTestData.getControlLoopId(), controlLoopElementId1,
+ ControlLoopState.PASSIVE, ControlLoopOrderedState.RUNNING));
}
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- controlLoopElementHandler.controlLoopElementUpdate(element, nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT));
+ controlLoopElementHandler.controlLoopElementUpdate(commonTestData.getControlLoopId(), element,
+ nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT));
assertThat(controlLoopElementHandler.getChartMap()).hasSize(1).containsKey(elementId1);
UUID elementId2 = UUID.randomUUID();
element.setId(elementId2);
- controlLoopElementHandler.controlLoopElementUpdate(element, nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT));
+ controlLoopElementHandler.controlLoopElementUpdate(commonTestData.getControlLoopId(), element,
+ nodeTemplatesMap.get(K8S_CONTROL_LOOP_ELEMENT));
assertThat(controlLoopElementHandler.getChartMap().containsKey(elementId2)).isFalse();
}
topicParams.setServers(Arrays.asList("localhost"));
return topicParams;
}
+
+ /**
+ * Get controlloop id.
+ * @return ToscaConceptIdentifier controlLoopId
+ */
+ public ToscaConceptIdentifier getControlLoopId() {
+ return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ }
}
import org.onap.policy.clamp.controlloop.participant.policy.client.PolicyApiHttpClient;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
* @throws PfModelException in case of an exception
*/
@Override
- public void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState,
+ public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId,
+ UUID controlLoopElementId, ControlLoopState currentState,
ControlLoopOrderedState newState) throws PfModelException {
switch (newState) {
case UNINITIALISED:
try {
- deletePolicyData(controlLoopElementId, newState);
+ deletePolicyData(controlLoopId, controlLoopElementId, newState);
} catch (PfModelRuntimeException e) {
LOGGER.debug("Deleting policy data failed", e);
}
break;
case PASSIVE:
- intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.PASSIVE,
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.PASSIVE,
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
break;
case RUNNING:
- intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.RUNNING,
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.RUNNING,
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
break;
default:
}
}
- private void deletePolicyData(UUID controlLoopElementId, ControlLoopOrderedState newState) {
+ private void deletePolicyData(ToscaConceptIdentifier controlLoopId,
+ UUID controlLoopElementId, ControlLoopOrderedState newState) {
// Delete all policies of this controlLoop from policy framework
for (Entry<String, String> policy : policyMap.entrySet()) {
apiHttpClient.deletePolicy(policy.getKey(), policy.getValue());
apiHttpClient.deletePolicyType(policyType.getKey(), policyType.getValue());
}
policyTypeMap.clear();
- intermediaryApi.updateControlLoopElementState(controlLoopElementId, newState, ControlLoopState.UNINITIALISED,
+ intermediaryApi.updateControlLoopElementState(controlLoopId,
+ controlLoopElementId, newState, ControlLoopState.UNINITIALISED,
ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE);
}
* @throws PfModelException in case of an exception
*/
@Override
- public void controlLoopElementUpdate(ControlLoopElement element, ToscaNodeTemplate clElementDefinition)
+ public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element,
+ ToscaNodeTemplate clElementDefinition)
throws PfModelException {
- intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(),
+ intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), element.getOrderedState(),
ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_UPDATE);
ToscaServiceTemplate controlLoopDefinition = element.getToscaServiceTemplateFragment();
if (controlLoopDefinition.getToscaTopologyTemplate() != null) {
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) {
- if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
ControlLoopElement clElement = new ControlLoopElement();
clElement.setId(UUID.randomUUID());
ToscaConceptIdentifier clParticipantType;
return clUpdateMsg;
}
+ private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
+ ToscaServiceTemplate toscaServiceTemplate) {
+ if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
+ return true;
+ } else {
+ var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
+ if (nodeType != null) {
+ var derivedFrom = nodeType.getDerivedFrom();
+ if (derivedFrom != null) {
+ return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
+ }
+ }
+ }
+ return false;
+ }
+
private static void populateToscaNodeTemplateFragment(ControlLoopElement clElement,
ToscaServiceTemplate toscaServiceTemplate) {
ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
ToscaConceptIdentifier clParticipantType;
try {
clParticipantType = CODER.decode(
*/
public TypedSimpleResponse<ControlLoopElement> updateControlLoopElement(ControlLoopElement element) {
TypedSimpleResponse<ControlLoopElement> response = new TypedSimpleResponse<>();
- response.setResponse(intermediaryApi.updateControlLoopElementState(element.getId(), element.getOrderedState(),
- element.getState(), ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE));
+ response.setResponse(intermediaryApi.updateControlLoopElementState(null, element.getId(),
+ element.getOrderedState(), element.getState(), ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE));
return response;
}
Map<String, ToscaNodeTemplate> nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : nodeTemplatesMap.entrySet()) {
- if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
ControlLoopElement clElement = new ControlLoopElement();
clElement.setId(UUID.randomUUID());
ToscaConceptIdentifier clParticipantType;
return clUpdateMsg;
}
+ private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
+ ToscaServiceTemplate toscaServiceTemplate) {
+ if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
+ return true;
+ } else {
+ var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
+ if (nodeType != null) {
+ var derivedFrom = nodeType.getDerivedFrom();
+ if (derivedFrom != null) {
+ return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
+ }
+ }
+ }
+ return false;
+ }
+
private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement,
List<ParticipantUpdates> participantUpdates) {
if (participantUpdates.isEmpty()) {
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
ToscaConceptIdentifier clParticipantType;
try {
clParticipantType = CODER.decode(
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
/**
* @param newState the state to which the control loop element is changing to
* @throws PfModelException in case of a model exception
*/
- public void controlLoopElementStateChange(UUID controlLoopElementId, ControlLoopState currentState,
- ControlLoopOrderedState newState) throws PfModelException;
+ public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId, UUID controlLoopElementId,
+ ControlLoopState currentState, ControlLoopOrderedState newState) throws PfModelException;
/**
* Handle an update on a control loop element.
* @param controlLoopElementDefinition toscaNodeTemplate
* @throws PfModelException from Policy framework
*/
- public void controlLoopElementUpdate(ControlLoopElement element,
+ public void controlLoopElementUpdate(ToscaConceptIdentifier controlLoopId, ControlLoopElement element,
ToscaNodeTemplate controlLoopElementDefinition) throws PfModelException;
/**
* @param newState the state of the control loop element
* @return ControlLoopElement updated control loop element
*/
- ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState currentState,
+ ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId,
+ UUID id, ControlLoopOrderedState currentState,
ControlLoopState newState, ParticipantMessageType messageType);
/**
}
@Override
- public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState currentState,
+ public ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId,
+ UUID id, ControlLoopOrderedState currentState,
ControlLoopState newState, ParticipantMessageType messageType) {
- return participantHandler.getControlLoopHandler().updateControlLoopElementState(id, currentState, newState);
+ return participantHandler.getControlLoopHandler().updateControlLoopElementState(controlLoopId,
+ id, currentState, newState);
}
@Override
import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener;
import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantMessagePublisher;
import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
* @param newState the ordered state
* @return controlLoopElement the updated controlloop element
*/
- public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState orderedState,
+ public ControlLoopElement updateControlLoopElementState(ToscaConceptIdentifier controlLoopId,
+ UUID id, ControlLoopOrderedState orderedState,
ControlLoopState newState) {
if (id == null) {
}
ControlLoopElement clElement = elementsOnThisParticipant.get(id);
+ for (var controlLoop : controlLoopMap.values()) {
+ var element = controlLoop.getElements().get(id);
+ if (element != null) {
+ element.setState(newState);
+ }
+ }
+
if (clElement != null) {
var controlLoopStateChangeAck =
new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK);
controlLoopStateChangeAck.setParticipantId(participantId);
controlLoopStateChangeAck.setParticipantType(participantType);
+ controlLoopStateChangeAck.setControlLoopId(controlLoopId);
clElement.setOrderedState(orderedState);
clElement.setState(newState);
controlLoopStateChangeAck.getControlLoopResultMap().put(clElement.getId(),
- new ControlLoopElementAck(true, "Control loop element {} state changed to {}\", id, newState)"));
+ new ControlLoopElementAck(newState, true,
+ "Control loop element {} state changed to {}\", id, newState)"));
LOGGER.debug("Control loop element {} state changed to {}", id, newState);
controlLoopStateChangeAck.setMessage("ControlLoopElement state changed to {} " + newState);
controlLoopStateChangeAck.setResult(true);
return;
}
+ if (updateMsg.getParticipantUpdatesList().isEmpty()) {
+ LOGGER.warn("No ControlLoopElement updates in message {}", updateMsg.getControlLoopId());
+ return;
+ }
+
List<ControlLoopElement> clElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList());
try {
ToscaNodeTemplate clElementNodeTemplate = getClElementNodeTemplate(
clElementDefinitions, element.getDefinition());
for (ControlLoopElementListener clElementListener : listeners) {
- clElementListener.controlLoopElementUpdate(element, clElementNodeTemplate);
+ clElementListener.controlLoopElementUpdate(updateMsg.getControlLoopId(),
+ element, clElementNodeTemplate);
}
}
} catch (PfModelException e) {
for (ControlLoopElementListener clElementListener : listeners) {
try {
for (ControlLoopElement element : controlLoop.getElements().values()) {
- clElementListener.controlLoopElementStateChange(element.getId(), element.getState(), orderedState);
+ clElementListener.controlLoopElementStateChange(controlLoop.getDefinition(),
+ element.getId(), element.getState(), orderedState);
}
} catch (PfModelException e) {
LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition());
} else {
// This message is to decommision the controlloop
clElementDefsOnThisParticipant.clear();
+ this.state = ParticipantState.TERMINATED;
}
sendParticipantUpdateAck(participantUpdateMsg.getMessageId());
}
participantUpdateAck.setResult(true);
participantUpdateAck.setParticipantId(participantId);
participantUpdateAck.setParticipantType(participantType);
-
+ participantUpdateAck.setState(state);
publisher.sendParticipantUpdateAck(participantUpdateAck);
}
package org.onap.policy.clamp.controlloop.runtime.supervision;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
import javax.ws.rs.core.Response;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementAck;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
@MessageIntercept
public void handleParticipantMessage(ParticipantUpdateAck participantUpdateAckMessage) {
LOGGER.debug("Participant Update Ack received {}", participantUpdateAckMessage);
+ try {
+ var participantList =
+ participantProvider.getParticipants(participantUpdateAckMessage.getParticipantId().getName(),
+ participantUpdateAckMessage.getParticipantId().getVersion());
+
+ if (participantList != null) {
+ for (Participant participant : participantList) {
+ participant.setParticipantState(participantUpdateAckMessage.getState());
+ }
+ participantProvider.updateParticipants(participantList);
+ } else {
+ LOGGER.warn("Participant not found in database {}", participantUpdateAckMessage.getParticipantId());
+ }
+ } catch (PfModelException pfme) {
+ LOGGER.warn("Model exception occured {}", participantUpdateAckMessage.getParticipantId());
+ }
}
/**
@MessageIntercept
public void handleControlLoopUpdateAckMessage(ControlLoopAck controlLoopAckMessage) {
LOGGER.debug("ControlLoop Update Ack message received {}", controlLoopAckMessage);
+ setClElementStateInDb(controlLoopAckMessage);
}
/**
@MessageIntercept
public void handleControlLoopStateChangeAckMessage(ControlLoopAck controlLoopAckMessage) {
LOGGER.debug("ControlLoop StateChange Ack message received {}", controlLoopAckMessage);
+ setClElementStateInDb(controlLoopAckMessage);
+ }
+
+ private void setClElementStateInDb(ControlLoopAck controlLoopAckMessage) {
+ if (controlLoopAckMessage.getControlLoopResultMap() != null) {
+ try {
+ var controlLoop = controlLoopProvider.getControlLoop(controlLoopAckMessage.getControlLoopId());
+ if (controlLoop != null) {
+ var updated = updateState(controlLoop, controlLoopAckMessage
+ .getControlLoopResultMap().entrySet());
+ if (updated) {
+ controlLoopProvider.updateControlLoop(controlLoop);
+ }
+ } else {
+ LOGGER.warn("ControlLoop not found in database {}", controlLoopAckMessage.getControlLoopId());
+ }
+ } catch (PfModelException pfme) {
+ LOGGER.warn("Model exception occured {}", controlLoopAckMessage.getControlLoopId());
+ }
+ }
+ }
+
+ private boolean updateState(ControlLoop controlLoop, Set<Map.Entry<UUID, ControlLoopElementAck>>
+ controlLoopResultSet) {
+ var updated = false;
+ for (var clElementAck : controlLoopResultSet) {
+ var element = controlLoop.getElements().get(clElementAck.getKey());
+ if (element != null) {
+ element.setState(clElementAck.getValue().getState());
+ updated = true;
+ }
+ }
+ return updated;
}
/**
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate()
.getNodeTemplates().entrySet()) {
- if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
ToscaConceptIdentifier clParticipantType;
try {
clParticipantType =
participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList);
return participantDefinition;
}
+
+ private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
+ ToscaServiceTemplate toscaServiceTemplate) {
+ if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
+ return true;
+ } else {
+ var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
+ if (nodeType != null) {
+ var derivedFrom = nodeType.getDerivedFrom();
+ if (derivedFrom != null) {
+ return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
+ }
+ }
+ }
+ return false;
+ }
}
List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>();
for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry :
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().entrySet()) {
- if (toscaInputEntry.getValue().getType().contains(CONTROL_LOOP_ELEMENT)) {
+ if (checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), toscaServiceTemplate)) {
ToscaConceptIdentifier clParticipantType;
try {
clParticipantType = CODER.decode(
}
}
+ private static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate,
+ ToscaServiceTemplate toscaServiceTemplate) {
+ if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) {
+ return true;
+ } else {
+ var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType());
+ if (nodeType != null) {
+ var derivedFrom = nodeType.getDerivedFrom();
+ if (derivedFrom != null) {
+ return derivedFrom.contains(CONTROL_LOOP_ELEMENT) ? true : false;
+ }
+ }
+ }
+ return false;
+ }
+
private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey,
ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) {
participantUpdateAckMsg.setMessage("ParticipantUpdateAck message");
participantUpdateAckMsg.setResponseTo(UUID.randomUUID());
participantUpdateAckMsg.setResult(true);
+ participantUpdateAckMsg.setParticipantId(getParticipantId());
+ participantUpdateAckMsg.setParticipantType(getParticipantType());
synchronized (lockit) {
ParticipantUpdateAckListener participantUpdateAckListener =