2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.clamp.controlloop.runtime.instantiation;
24 import com.google.gson.Gson;
25 import com.google.gson.internal.LinkedTreeMap;
26 import com.google.gson.reflect.TypeToken;
27 import java.lang.reflect.Type;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.List;
34 import java.util.UUID;
35 import java.util.function.Function;
36 import java.util.function.UnaryOperator;
37 import java.util.stream.Collectors;
38 import java.util.stream.Stream;
39 import javax.ws.rs.core.Response;
40 import javax.ws.rs.core.Response.Status;
41 import lombok.AllArgsConstructor;
42 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
43 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
44 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
45 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
46 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
47 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
48 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant;
49 import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
50 import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
51 import org.onap.policy.clamp.controlloop.models.messages.rest.GenericNameVersion;
52 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopOrderStateResponse;
53 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopPrimed;
54 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopPrimedResponse;
55 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstancePropertiesResponse;
56 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand;
57 import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse;
58 import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
59 import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler;
60 import org.onap.policy.common.parameters.BeanValidationResult;
61 import org.onap.policy.common.parameters.ObjectValidationResult;
62 import org.onap.policy.common.parameters.ValidationResult;
63 import org.onap.policy.common.parameters.ValidationStatus;
64 import org.onap.policy.models.base.PfModelException;
65 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
66 import org.onap.policy.models.tosca.authorative.concepts.ToscaNameVersion;
67 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
68 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
69 import org.springframework.stereotype.Component;
72 * This class is dedicated to the Instantiation of Commissioned control loop.
76 public class ControlLoopInstantiationProvider {
77 private static final String CONTROL_LOOP_NODE_TYPE = "org.onap.policy.clamp.controlloop.ControlLoop";
78 private static final String CONTROL_LOOP_NODE_ELEMENT_TYPE = "ControlLoopElement";
79 private static final String PARTICIPANT_ID_PROPERTY_KEY = "participant_id";
80 private static final String PARTICIPANT_TYPE_PROPERTY_KEY = "participantType";
81 private static final String CL_ELEMENT_NAME = "name";
82 private static final String CL_ELEMENT_VERSION = "version";
83 private static final String INSTANCE_TEXT = "_Instance";
85 private static final Gson GSON = new Gson();
87 private final ControlLoopProvider controlLoopProvider;
88 private final CommissioningProvider commissioningProvider;
89 private final SupervisionHandler supervisionHandler;
90 private final ParticipantProvider participantProvider;
92 private static final Object lockit = new Object();
95 * Creates Instance Properties and Control Loop.
97 * @param serviceTemplate the service template
98 * @return the result of the instantiation operation
99 * @throws PfModelException on creation errors
101 public InstancePropertiesResponse createInstanceProperties(ToscaServiceTemplate serviceTemplate)
102 throws PfModelException {
104 String instanceName = generateSequentialInstanceName();
105 ControlLoop controlLoop = new ControlLoop();
106 Map<UUID, ControlLoopElement> controlLoopElements = new HashMap<>();
108 ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(null, null);
110 Map<String, ToscaNodeTemplate> persistedNodeTemplateMap =
111 toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
113 Map<String, ToscaNodeTemplate> nodeTemplates = deepCloneNodeTemplate(serviceTemplate);
115 nodeTemplates.forEach((key, template) -> {
116 ToscaNodeTemplate newNodeTemplate = new ToscaNodeTemplate();
117 String name = key + instanceName;
118 String version = template.getVersion();
119 String description = template.getDescription() + instanceName;
120 newNodeTemplate.setName(name);
121 newNodeTemplate.setVersion(version);
122 newNodeTemplate.setDescription(description);
123 newNodeTemplate.setProperties(new HashMap<>(template.getProperties()));
124 newNodeTemplate.setType(template.getType());
125 newNodeTemplate.setTypeVersion(template.getTypeVersion());
126 newNodeTemplate.setMetadata(template.getMetadata());
128 crateNewControlLoopInstance(instanceName, controlLoop, controlLoopElements, template, newNodeTemplate);
130 persistedNodeTemplateMap.put(name, newNodeTemplate);
133 ControlLoops controlLoops = new ControlLoops();
135 serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().putAll(persistedNodeTemplateMap);
137 controlLoop.setElements(controlLoopElements);
138 controlLoops.getControlLoopList().add(controlLoop);
140 return saveInstancePropertiesAndControlLoop(serviceTemplate, controlLoops);
144 * Deletes Instance Properties.
146 * @param name the name of the control loop to delete
147 * @param version the version of the control loop to delete
148 * @return the result of the deletion
149 * @throws PfModelException on deletion errors
151 public InstantiationResponse deleteInstanceProperties(String name, String version) throws PfModelException {
153 String instanceName = getInstancePropertyName(name, version);
155 Map<String, ToscaNodeTemplate> filteredToscaNodeTemplateMap = new HashMap<>();
157 ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(name, version);
159 toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach((key, nodeTemplate) -> {
160 if (!nodeTemplate.getName().contains(instanceName)) {
161 filteredToscaNodeTemplateMap.put(key, nodeTemplate);
165 List<ToscaNodeTemplate> filteredToscaNodeTemplateList = toscaServiceTemplate.getToscaTopologyTemplate()
166 .getNodeTemplates().values().stream()
167 .filter(nodeTemplate -> nodeTemplate.getName().contains(instanceName)).collect(Collectors.toList());
169 InstantiationResponse response = this.deleteControlLoop(name, version);
171 controlLoopProvider.deleteInstanceProperties(filteredToscaNodeTemplateMap, filteredToscaNodeTemplateList);
177 * Create control loops.
179 * @param controlLoops the control loop
180 * @return the result of the instantiation operation
181 * @throws PfModelException on creation errors
183 public InstantiationResponse createControlLoops(ControlLoops controlLoops) throws PfModelException {
185 synchronized (lockit) {
186 for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
187 var checkControlLoop = controlLoopProvider.getControlLoop(controlLoop.getKey().asIdentifier());
188 if (checkControlLoop != null) {
189 throw new PfModelException(Response.Status.BAD_REQUEST,
190 controlLoop.getKey().asIdentifier() + " already defined");
193 BeanValidationResult validationResult = validateControlLoops(controlLoops);
194 if (!validationResult.isValid()) {
195 throw new PfModelException(Response.Status.BAD_REQUEST, validationResult.getResult());
197 controlLoopProvider.createControlLoops(controlLoops.getControlLoopList());
200 var response = new InstantiationResponse();
201 response.setAffectedControlLoops(controlLoops.getControlLoopList().stream()
202 .map(cl -> cl.getKey().asIdentifier()).collect(Collectors.toList()));
208 * Update control loops.
210 * @param controlLoops the control loop
211 * @return the result of the instantiation operation
212 * @throws PfModelException on update errors
214 public InstantiationResponse updateControlLoops(ControlLoops controlLoops) throws PfModelException {
215 synchronized (lockit) {
216 BeanValidationResult validationResult = validateControlLoops(controlLoops);
217 if (!validationResult.isValid()) {
218 throw new PfModelException(Response.Status.BAD_REQUEST, validationResult.getResult());
220 controlLoopProvider.updateControlLoops(controlLoops.getControlLoopList());
223 var response = new InstantiationResponse();
224 response.setAffectedControlLoops(controlLoops.getControlLoopList().stream()
225 .map(cl -> cl.getKey().asIdentifier()).collect(Collectors.toList()));
231 * Validate ControlLoops.
233 * @param controlLoops ControlLoops to validate
234 * @return the result of validation
235 * @throws PfModelException if controlLoops is not valid
237 private BeanValidationResult validateControlLoops(ControlLoops controlLoops) throws PfModelException {
239 var result = new BeanValidationResult("ControlLoops", controlLoops);
241 for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
242 var subResult = new BeanValidationResult("entry " + controlLoop.getDefinition().getName(), controlLoop);
244 List<ToscaNodeTemplate> toscaNodeTemplates = commissioningProvider.getControlLoopDefinitions(
245 controlLoop.getDefinition().getName(), controlLoop.getDefinition().getVersion());
247 if (toscaNodeTemplates.isEmpty()) {
248 subResult.addResult(new ObjectValidationResult("ControlLoop", controlLoop.getDefinition().getName(),
249 ValidationStatus.INVALID, "Commissioned control loop definition not FOUND"));
250 } else if (toscaNodeTemplates.size() > 1) {
251 subResult.addResult(new ObjectValidationResult("ControlLoop", controlLoop.getDefinition().getName(),
252 ValidationStatus.INVALID, "Commissioned control loop definition not VALID"));
255 List<ToscaNodeTemplate> clElementDefinitions =
256 commissioningProvider.getControlLoopElementDefinitions(toscaNodeTemplates.get(0));
259 Map<String, ToscaConceptIdentifier> definitions = clElementDefinitions
261 .map(nodeTemplate -> nodeTemplate.getKey().asIdentifier())
262 .collect(Collectors.toMap(ToscaConceptIdentifier::getName, UnaryOperator.identity()));
265 for (ControlLoopElement element : controlLoop.getElements().values()) {
266 subResult.addResult(validateDefinition(definitions, element.getDefinition()));
269 result.addResult(subResult);
275 * Validate ToscaConceptIdentifier, checking if exist in ToscaConceptIdentifiers map.
277 * @param definitions map of all ToscaConceptIdentifiers
278 * @param definition ToscaConceptIdentifier to validate
279 * @return the validation result
281 private ValidationResult validateDefinition(Map<String, ToscaConceptIdentifier> definitions,
282 ToscaConceptIdentifier definition) {
283 var result = new BeanValidationResult("entry " + definition.getName(), definition);
284 ToscaConceptIdentifier identifier = definitions.get(definition.getName());
285 if (identifier == null) {
286 result.setResult(ValidationStatus.INVALID, "Not FOUND");
287 } else if (!identifier.equals(definition)) {
288 result.setResult(ValidationStatus.INVALID, "Version not matching");
290 return (result.isClean() ? null : result);
294 * Delete the control loop with the given name and version.
296 * @param name the name of the control loop to delete
297 * @param version the version of the control loop to delete
298 * @return the result of the deletion
299 * @throws PfModelException on deletion errors
301 public InstantiationResponse deleteControlLoop(String name, String version) throws PfModelException {
302 var response = new InstantiationResponse();
303 synchronized (lockit) {
304 List<ControlLoop> controlLoops = controlLoopProvider.getControlLoops(name, version);
305 if (controlLoops.isEmpty()) {
306 throw new PfModelException(Response.Status.NOT_FOUND, "Control Loop not found");
308 for (ControlLoop controlLoop : controlLoops) {
309 if (!ControlLoopState.UNINITIALISED.equals(controlLoop.getState())) {
310 throw new PfModelException(Response.Status.BAD_REQUEST,
311 "Control Loop State is still " + controlLoop.getState());
315 response.setAffectedControlLoops(Collections
316 .singletonList(controlLoopProvider.deleteControlLoop(name, version).getKey().asIdentifier()));
322 * Get the requested control loops.
324 * @param name the name of the control loop to get, null for all control loops
325 * @param version the version of the control loop to get, null for all control loops
326 * @return the control loops
327 * @throws PfModelException on errors getting control loops
329 public ControlLoops getControlLoops(String name, String version) throws PfModelException {
330 var controlLoops = new ControlLoops();
331 controlLoops.setControlLoopList(controlLoopProvider.getControlLoops(name, version));
337 * Issue a command to control loops, setting their ordered state.
339 * @param command the command to issue to control loops
340 * @return the result of the initiation command
341 * @throws PfModelException on errors setting the ordered state on the control loops
342 * @throws ControlLoopException on ordered state invalid
344 public InstantiationResponse issueControlLoopCommand(InstantiationCommand command)
345 throws ControlLoopException, PfModelException {
347 if (command.getOrderedState() == null) {
348 throw new ControlLoopException(Status.BAD_REQUEST, "ordered state invalid or not specified on command");
351 synchronized (lockit) {
352 var participants = participantProvider.getParticipants(null, null);
353 if (participants.isEmpty()) {
354 throw new ControlLoopException(Status.BAD_REQUEST, "No participants registered");
356 List<ControlLoop> controlLoops = new ArrayList<>(command.getControlLoopIdentifierList().size());
357 for (ToscaConceptIdentifier id : command.getControlLoopIdentifierList()) {
358 var controlLoop = controlLoopProvider.getControlLoop(id);
359 controlLoop.setCascadedOrderedState(command.getOrderedState());
360 controlLoops.add(controlLoop);
362 BeanValidationResult validationResult = validateIssueControlLoops(controlLoops, participants);
363 if (!validationResult.isValid()) {
364 throw new PfModelException(Response.Status.BAD_REQUEST, validationResult.getResult());
366 controlLoopProvider.updateControlLoops(controlLoops);
369 supervisionHandler.triggerControlLoopSupervision(command.getControlLoopIdentifierList());
370 var response = new InstantiationResponse();
371 response.setAffectedControlLoops(command.getControlLoopIdentifierList());
376 private BeanValidationResult validateIssueControlLoops(List<ControlLoop> controlLoops,
377 List<Participant> participants) {
378 var result = new BeanValidationResult("ControlLoops", controlLoops);
380 Map<ToscaConceptIdentifier, Participant> participantMap = participants.stream()
381 .collect(Collectors.toMap(participant -> participant.getKey().asIdentifier(), Function.identity()));
383 for (ControlLoop controlLoop : controlLoops) {
385 for (var element : controlLoop.getElements().values()) {
386 var subResult = new BeanValidationResult("entry " + element.getDefinition().getName(), element);
388 Participant p = participantMap.get(element.getParticipantId());
390 subResult.addResult(new ObjectValidationResult(CONTROL_LOOP_NODE_ELEMENT_TYPE,
391 element.getDefinition().getName(), ValidationStatus.INVALID,
392 "Participant with ID " + element.getParticipantId() + " is not registered"));
393 } else if (!p.getParticipantType().equals(element.getParticipantType())) {
394 subResult.addResult(new ObjectValidationResult(CONTROL_LOOP_NODE_ELEMENT_TYPE,
395 element.getDefinition().getName(), ValidationStatus.INVALID,
396 "Participant with ID " + element.getParticipantType() + " - " + element.getParticipantId()
397 + " is not registered"));
399 result.addResult(subResult);
408 * Gets a list of control loops with it's ordered state.
410 * @param name the name of the control loop to get, null for all control loops
411 * @param version the version of the control loop to get, null for all control loops
412 * @return a list of Instantiation Command
413 * @throws PfModelException on errors getting control loops
415 public ControlLoopOrderStateResponse getInstantiationOrderState(String name, String version)
416 throws PfModelException {
418 List<ControlLoop> controlLoops = controlLoopProvider.getControlLoops(name, version);
420 var response = new ControlLoopOrderStateResponse();
422 controlLoops.forEach(controlLoop -> {
423 var genericNameVersion = new GenericNameVersion();
424 genericNameVersion.setName(controlLoop.getName());
425 genericNameVersion.setVersion(controlLoop.getVersion());
426 response.getControlLoopIdentifierList().add(genericNameVersion);
433 * Saves Instance Properties and Control Loop.
434 * Gets a list of control loops which are primed or de-primed.
436 * @param name the name of the control loop to get, null for all control loops
437 * @param version the version of the control loop to get, null for all control loops
438 * @return a list of Instantiation Command
439 * @throws PfModelException on errors getting control loops
441 public ControlLoopPrimedResponse getControlLoopPriming(String name, String version) throws PfModelException {
443 List<ControlLoop> controlLoops = controlLoopProvider.getControlLoops(name, version);
445 var response = new ControlLoopPrimedResponse();
447 controlLoops.forEach(controlLoop -> {
448 var primed = new ControlLoopPrimed();
449 primed.setName(controlLoop.getName());
450 primed.setVersion(controlLoop.getVersion());
451 primed.setPrimed(controlLoop.getPrimed());
452 response.getPrimedControlLoopsList().add(primed);
459 * Creates instance element name.
461 * @param serviceTemplate the service template
462 * @param controlLoops a list of control loops
463 * @return the result of the instance properties and instantiation operation
464 * @throws PfModelException on creation errors
466 private InstancePropertiesResponse saveInstancePropertiesAndControlLoop(ToscaServiceTemplate serviceTemplate,
467 ControlLoops controlLoops) throws PfModelException {
469 var response = new InstancePropertiesResponse();
471 Map<String, ToscaNodeTemplate> toscaSavedNodeTemplate;
473 synchronized (lockit) {
474 for (ControlLoop controlLoop : controlLoops.getControlLoopList()) {
475 var checkControlLoop = controlLoopProvider.getControlLoop(controlLoop.getKey().asIdentifier());
476 if (checkControlLoop != null) {
477 throw new PfModelException(Response.Status.BAD_REQUEST,
478 "Control loop with id " + controlLoop.getKey().asIdentifier() + " already defined");
482 toscaSavedNodeTemplate = controlLoopProvider.saveInstanceProperties(serviceTemplate);
484 controlLoopProvider.createControlLoops(controlLoops.getControlLoopList());
488 List<ToscaConceptIdentifier> affectedControlLoops = controlLoops.getControlLoopList().stream()
489 .map(cl -> cl.getKey().asIdentifier()).collect(Collectors.toList());
491 List<ToscaConceptIdentifier> toscaAffectedProperties = toscaSavedNodeTemplate.values().stream()
492 .map(template -> template.getKey().asIdentifier()).collect(Collectors.toList());
494 response.setAffectedInstanceProperties(Stream.of(affectedControlLoops, toscaAffectedProperties)
495 .flatMap(Collection::stream).collect(Collectors.toList()));
501 * Crates a new Control Loop instance.
503 * @param instanceName Control Loop Instance name
504 * @param controlLoop empty Control Loop
505 * @param controlLoopElements new Control Loop Element map
506 * @param template original Cloned Tosca Node Template
507 * @param newNodeTemplate new Tosca Node Template
509 private void crateNewControlLoopInstance(String instanceName, ControlLoop controlLoop,
510 Map<UUID, ControlLoopElement> controlLoopElements, ToscaNodeTemplate template,
511 ToscaNodeTemplate newNodeTemplate) {
512 if (template.getType().equals(CONTROL_LOOP_NODE_TYPE)) {
513 controlLoop.setDefinition(getControlLoopDefinition(newNodeTemplate));
516 if (template.getType().contains(CONTROL_LOOP_NODE_ELEMENT_TYPE)) {
517 ControlLoopElement controlLoopElement = getControlLoopElement(newNodeTemplate);
518 controlLoopElements.put(controlLoopElement.getId(), controlLoopElement);
521 controlLoop.setName("PMSH" + instanceName);
522 controlLoop.setVersion(template.getVersion());
523 controlLoop.setDescription("PMSH control loop " + instanceName);
524 controlLoop.setState(ControlLoopState.UNINITIALISED);
525 controlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED);
529 * Get's the instance property name of the control loop.
531 * @param name the name of the control loop to get, null for all control loops
532 * @param version the version of the control loop to get, null for all control loops
533 * @return the instance name of the control loop instance properties
534 * @throws PfModelException on errors getting control loops
536 private String getInstancePropertyName(String name, String version) throws PfModelException {
537 List<String> toscaDefinitionsNames = controlLoopProvider.getControlLoops(name, version).stream()
538 .map(ControlLoop::getDefinition).map(ToscaNameVersion::getName).collect(Collectors.toList());
540 return toscaDefinitionsNames.stream().reduce("", (s1, s2) -> {
542 if (s2.contains(INSTANCE_TEXT)) {
543 String[] instances = s2.split(INSTANCE_TEXT);
545 return INSTANCE_TEXT + instances[1];
553 * Generates Instance Name in sequential order and return it to append to the Node Template Name.
555 * @return instanceName
557 private String generateSequentialInstanceName() {
558 List<ToscaNodeTemplate> nodeTemplates = controlLoopProvider.getNodeTemplates(null, null);
560 int instanceNumber = nodeTemplates.stream().map(ToscaNodeTemplate::getName)
561 .filter(name -> name.contains(INSTANCE_TEXT)).map(n -> {
562 String[] defNameArr = n.split(INSTANCE_TEXT);
564 return Integer.parseInt(defNameArr[1]);
565 }).reduce(0, Math::max);
567 return INSTANCE_TEXT + (instanceNumber + 1);
571 * Retrieves Control Loop Definition.
573 * @param template tosca node template
574 * @return control loop definition
576 private ToscaConceptIdentifier getControlLoopDefinition(ToscaNodeTemplate template) {
577 ToscaConceptIdentifier definition = new ToscaConceptIdentifier();
578 definition.setName(template.getName());
579 definition.setVersion(template.getVersion());
585 * Retrieves Control Loop Element.
587 * @param template tosca node template
588 * @return a control loop element
590 @SuppressWarnings("unchecked")
591 private ControlLoopElement getControlLoopElement(ToscaNodeTemplate template) {
592 ControlLoopElement controlLoopElement = new ControlLoopElement();
593 ToscaConceptIdentifier definition = new ToscaConceptIdentifier();
594 definition.setName(template.getName());
595 definition.setVersion(template.getVersion());
596 controlLoopElement.setDefinition(definition);
598 LinkedTreeMap<String, Object> participantId =
599 (LinkedTreeMap<String, Object>) template.getProperties().get(PARTICIPANT_ID_PROPERTY_KEY);
601 if (participantId != null) {
602 ToscaConceptIdentifier participantIdProperty = new ToscaConceptIdentifier();
603 participantIdProperty.setName(String.valueOf(participantId.get(CL_ELEMENT_NAME)));
604 participantIdProperty.setVersion(String.valueOf(participantId.get(CL_ELEMENT_VERSION)));
605 controlLoopElement.setParticipantId(participantIdProperty);
608 LinkedTreeMap<String, Object> participantType =
609 (LinkedTreeMap<String, Object>) template.getProperties().get(PARTICIPANT_TYPE_PROPERTY_KEY);
611 if (participantType != null) {
612 ToscaConceptIdentifier participantTypeProperty = new ToscaConceptIdentifier();
613 participantTypeProperty.setName(String.valueOf(participantType.get(CL_ELEMENT_NAME)));
614 participantTypeProperty.setVersion(participantType.get(CL_ELEMENT_VERSION).toString());
615 controlLoopElement.setParticipantType(participantTypeProperty);
618 return controlLoopElement;
622 * Deep clones ToscaNodeTemplate.
624 * @param serviceTemplate ToscaServiceTemplate
625 * @return a cloned Hash Map of ToscaNodeTemplate
627 private Map<String, ToscaNodeTemplate> deepCloneNodeTemplate(ToscaServiceTemplate serviceTemplate) {
628 String jsonString = GSON.toJson(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates());
630 Type type = new TypeToken<HashMap<String, ToscaNodeTemplate>>() {}.getType();
632 return GSON.fromJson(jsonString, type);