1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3 .. Copyright (c) Nordix Foundation. All rights reserved.
5 .. _acm-participant-guide-label:
7 Participant developer guide
8 ###########################
13 The ACM runtime delegates the user requests to the participants for performing the actual operations.
14 Hence the participant module in ACM is implemented adhering to a list of ACM protocols along with their own functional logic.
15 It works in a contract with the Participant Intermediary module for communicating with ACM-R.
16 This guide explains the design considerations for a new participant implementation in ACM.
18 Please refer the following section for a detailed understanding of Inbound and outbound messages a participant interacts with.
23 design-impl/participants/participants
25 Design considerations for a participant
26 ---------------------------------------
28 In ONAP, the ACM-runtime and participant modules are implemented in Java spring boot. The participant Intermediary module
29 which is added as a maven dependency to the participants has the default implementations available for listening the kafka
30 events coming in from the ACM-runtime, process them and delegate them to the appropriate handler class. Similarly the
31 Intermediary module also has the publisher class implementations for publishing events back from the participants to the ACM-runtime.
33 Hence the new participants has to have this Participant Intermediary module as a dependency and should:
35 * Configure SpringBoot to scan the components located into the package "org.onap.policy.clamp.acm.participant.intermediary".
36 * Implement the following interfaces from the Participant Intermediary.
37 * Provide the following mandatory properties in order to make the participant work in synchronisation with ACM-runtime.
39 The participant application should be provided with the following Intermediary parameter values in the application properties
40 and the same is configured for the 'ParticipantIntermediaryParameters' object in the code.
42 1. participantId - A unique participant UUID that is used by the runtime to identify the participant.
43 2. ReportingTimeIntervalMs - Time inertval the participant should report the status/heartbeat to the runtime.
44 3. clampAutomationCompositionTopics - This property takes in the kafka topic names and servers for the intermediary module to use.
45 These values should be provided for both source and sink configs. The following example shows the topic parameters set for using DMaap.
49 clampAutomationCompositionTopics:
52 topic: POLICY-ACRUNTIME-PARTICIPANT
54 - ${topicServer:localhost}
55 topicCommInfrastructure: dmaap
59 topic: POLICY-ACRUNTIME-PARTICIPANT
61 - ${topicServer:localhost}
62 topicCommInfrastructure: dmaap
64 4. participantSupportedElementTypes - This property takes a list of typeName and typeVersion fields to define the types of AC elements the participant deals with.
65 These are user defined name and version and the same should be defined for the AC elements that are included in the TOSCA based AC definitions.
69 participantSupportedElementTypes:
71 typeName: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement
74 Interfaces to Implement
75 -----------------------
76 AutomationCompositionElementListener:
77 Every participant should implement a handler class that implements the AutomationCompositionElementListener interface
78 from the Participant Intermediary. The intermediary listener class listens for the incoming events from the ACM-runtime
79 and invoke the handler class implementations for various operations. This class implements the methods for deploying,
80 undeploying, locking, unlocking , deleting, updating, priming, depriming requests that are coming from the ACM-runtime.
81 The methods are as follows.
85 1. void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException;
86 2. void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> inProperties) throws PfModelException;
87 3. void lock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException;
88 4. void unlock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException;
89 5. void delete(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException;
90 6. void update(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> inProperties) throws PfModelException;
91 7. void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) throws PfModelException;
92 8. void deprime(UUID compositionId) throws PfModelException;
93 9. void handleRestartComposition(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) throws PfModelException;
94 10. void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException;
96 These method from the interface are implemented independently as per the user requirement. These methods after handling the
97 appropriate requests should also invoke the intermediary's publisher apis to notify the ACM-runtime with the acknowledgement events.
99 ParticipantParameters:
100 Every participant should implement a properties class that contains the values of all Intermediary parameter properties.
101 This class implements the method getIntermediaryParameters that returns 'ParticipantIntermediaryParameters' object. The method is as follows.
105 ParticipantIntermediaryParameters getIntermediaryParameters()
110 ParticipantIntermediaryApi:
111 The participant intermediary api has the following methods that can be invoked from the participant for the following purposes.
113 #. The requested operations are completed in the handler class and the ACM-runtime needs to be notified.
114 #. Collect all instances data.
115 #. Send out Properties to ACM-runtime.
117 The methods are as follows:
119 This following method is invoked to update the AC element state after each operation is completed in the participant.
123 1. void updateAutomationCompositionElementState(UUID automationCompositionId, UUID elementId, DeployState deployState, LockState lockState, StateChangeResult stateChangeResult, String message);
124 2. Map<UUID, AutomationComposition> getAutomationCompositions();
125 3. void sendAcElementInfo(UUID automationCompositionId, UUID elementId, String useState, String operationalState, Map<String, Object> outProperties);
126 4. void updateCompositionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult, String message);
130 The 'In Properties' could be created or updated by ACM-runtime. Participants will receive that Properties during deploy and update events.
132 The 'Out Properties' could be created or updated by participants. ACM-runtime will receive that Properties during ParticipantStatus event.
133 The participant can trigger this event using the method sendAcElementInfo.
134 The 'useState' and 'operationalState' can be used as well.
136 Is allowed to the participant to read all In/Out Properties and state of all instances handled by the participant using the method getAutomationCompositions.
137 The following code is an example how to update the property 'myProperty' and send to ACM-runtime:
141 var automationCompositions = intermediaryApi.getAutomationCompositions();
142 var automationComposition = automationCompositions.get(automationCompositionId);
143 var acElement = automationComposition.getElements().get(elementId);
144 var outProperties = acElement.getOutProperties();
145 outProperties.put("myProperty", myProperty);
146 intermediaryApi.sendAcElementInfo(automationCompositionId, elementId, acElement.getUseState(), acElement.getOperationalState(), outProperties);
150 Restart methods handle the scenario when participant shut down and restart.
151 The method handleRestartComposition will be called for each composition and will be present the 'state' at the time the participant shut down.
152 The method handleRestartInstance will be called for each instance element and will be present the 'deployState' and the 'lockState' at the time the participant shut down.
154 In ONAP, the following participants are already implemented in java spring boot for various requirements. The maven modules
155 can be referred here:
157 * `HTTP participant <https://github.com/onap/policy-clamp/tree/master/participant/participant-impl/participant-impl-http>`_.
158 * `Kubernetes participant <https://github.com/onap/policy-clamp/tree/master/participant/participant-impl/participant-impl-kubernetes>`_.
159 * `Policy participant <https://github.com/onap/policy-clamp/tree/master/participant/participant-impl/participant-impl-policy>`_.
160 * `A1PMS participant <https://github.com/onap/policy-clamp/tree/master/participant/participant-impl/participant-impl-a1pms>`_.
161 * `Kserve participant <https://github.com/onap/policy-clamp/tree/master/participant/participant-impl/participant-impl-kserve>`_.
163 Example of Implementation
164 -------------------------
166 This following code is an example of My First Participant:
171 The Application class is configured to add the "org.onap.policy.clamp.acm.participant.intermediary" package in SpringBoot component scanning.
175 @SpringBootApplication
177 "org.onap.policy.clamp.acm.participant.myfirstparticipant",
178 "org.onap.policy.clamp.acm.participant.intermediary"
180 @ConfigurationPropertiesScan("org.onap.policy.clamp.acm.participant.myfirstparticipant.parameters")
181 public class MyFirstParticipantApplication {
183 public static void main(String[] args) {
184 SpringApplication.run(Application.class, args);
188 The Participant Parameters class implements the mandatory interface ParticipantParameters.
189 It could contains additional parameters.
196 @ConfigurationProperties(prefix = "participant")
197 public class ParticipantSimParameters implements ParticipantParameters {
200 private String myparameter;
204 private ParticipantIntermediaryParameters intermediaryParameters;
207 The following example shows the topic parameters and the additional 'myparameter'.
212 myparameter: my parameter
213 intermediaryParameters:
214 reportingTimeIntervalMs: 120000
215 description: Participant Description
216 participantId: 101c62b3-8918-41b9-a747-d21eb79c6c90
217 clampAutomationCompositionTopics:
219 - topic: POLICY-ACRUNTIME-PARTICIPANT
221 - ${topicServer:localhost}
222 topicCommInfrastructure: dmaap
225 - topic: POLICY-ACRUNTIME-PARTICIPANT
227 - ${topicServer:localhost}
228 topicCommInfrastructure: dmaap
229 participantSupportedElementTypes:
231 typeName: org.onap.policy.clamp.acm.MyFirstAutomationCompositionElement
235 The following example shows the Handler implementation and how could be the implemented the mandatory notifications.
240 @RequiredArgsConstructor
241 public class MyFirstAcElementHandler implements AutomationCompositionElementListener {
243 private final ParticipantIntermediaryApi intermediaryApi;
246 public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
247 throws PfModelException {
249 // TODO deploy process
251 if (isDeploySuccess()) {
252 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
253 DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
255 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
256 DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Deploy failed!");
261 public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException {
262 LOGGER.debug("undeploy call");
264 // TODO undeploy process
266 if (isUndeploySuccess()) {
267 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
268 automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
271 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
272 automationCompositionElementId, DeployState.DEPLOYED, null, StateChangeResult.FAILED,
278 public void lock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException {
282 if (isLockSuccess()) {
283 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
284 automationCompositionElementId, null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
286 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
287 automationCompositionElementId, null, LockState.UNLOCKED, StateChangeResult.FAILED, "Lock failed!");
292 public void unlock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException {
294 // TODO unlock process
296 if (isUnlockSuccess()) {
297 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
298 automationCompositionElementId, null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
300 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
301 automationCompositionElementId, null, LockState.LOCKED, StateChangeResult.FAILED, "Unlock failed!");
306 public void delete(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException {
308 // TODO delete process
310 if (isDeleteSuccess()) {
311 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
312 automationCompositionElementId, DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
314 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
315 automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
321 public void update(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
322 throws PfModelException {
324 // TODO update process
326 if (isUpdateSuccess()) {
327 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
328 DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Updated");
330 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
331 DeployState.DEPLOYED, null, StateChangeResult.FAILED, "Update failed!");
336 public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
337 throws PfModelException {
339 // TODO prime process
341 if (isPrimeSuccess()) {
342 intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR,
345 intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.FAILED,
351 public void deprime(UUID compositionId) throws PfModelException {
353 // TODO deprime process
355 if (isDeprimeSuccess()) {
356 intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
359 intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED,
366 public void handleRestartComposition(UUID compositionId,
367 List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state)
368 throws PfModelException {
372 prime(compositionId, elementDefinitionList);
376 // TODO restart process
378 deprime(compositionId);
382 // TODO restart process
384 intermediaryApi.updateCompositionState(compositionId, state, StateChangeResult.NO_ERROR, "Restarted");
389 public void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element,
390 Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException {
392 // TODO restart process
394 if (DeployState.DEPLOYING.equals(deployState)) {
395 deploy(automationCompositionId, element, properties);
398 if (DeployState.UNDEPLOYING.equals(deployState)) {
399 undeploy(automationCompositionId, element.getId());
402 if (DeployState.UPDATING.equals(deployState)) {
403 update(automationCompositionId, element, properties);
406 if (DeployState.DELETING.equals(deployState)) {
407 delete(automationCompositionId, element.getId());
410 if (LockState.LOCKING.equals(lockState)) {
411 lock(automationCompositionId, element.getId());
414 if (LockState.UNLOCKING.equals(lockState)) {
415 unlock(automationCompositionId, element.getId());
418 intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
419 deployState, lockState, StateChangeResult.NO_ERROR, "Restarted");