package org.onap.policy.clamp.models.acm.concepts;
+import java.util.UUID;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Class to represent a automation composition info instance.
@ToString
public class AutomationCompositionInfo {
- private ToscaConceptIdentifier automationCompositionId;
+ private UUID automationCompositionId;
private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED;
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 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 lombok.ToString;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementAck;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* Class to represent the AUTOMATION_COMPOSITION_ACK message that a participant sends
@ToString(callSuper = true)
public class AutomationCompositionAck extends ParticipantAckMessage {
- private ToscaConceptIdentifier automationCompositionId;
+ private UUID automationCompositionId;
private Integer startPhase;
// A map with AutomationCompositionElementID as its key, and a pair of result and message as value per
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* Automation Composition ID, or {@code null} for messages to participants.
*/
- private ToscaConceptIdentifier automationCompositionId;
+ private UUID automationCompositionId;
/**
* Constructor for instantiating a participant message class.
}
}
+ /**
+ * Find automation composition.
+ *
+ * @param instanceId the ID of the automation composition to get
+ * @return the automation composition found
+ */
+ @Transactional(readOnly = true)
+ public Optional<AutomationComposition> findAutomationComposition(final UUID instanceId) {
+ var result = automationCompositionRepository.findByInstanceId(instanceId.toString());
+ return result.stream().map(JpaAutomationComposition::toAuthorative).findFirst();
+ }
+
/**
* Find automation composition by automationCompositionId.
*
// verify with all values
var id = new ToscaConceptIdentifier("id", "1.2.3");
- orig.setAutomationCompositionId(id);
+ orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(id);
orig.setParticipantType(id);
var acElementResult = new AutomationCompositionElementAck(AutomationCompositionState.UNINITIALISED,
// verify with all values
ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
- orig.setAutomationCompositionId(id);
+ orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(id);
orig.setMessageId(UUID.randomUUID());
orig.setOrderedState(AutomationCompositionOrderedState.RUNNING);
var orig = new AutomationCompositionUpdate();
// verify with all values
- var id = new ToscaConceptIdentifier("id", "1.2.3");
- orig.setAutomationCompositionId(id);
+ orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(null);
orig.setMessageId(UUID.randomUUID());
orig.setTimestamp(Instant.ofEpochMilli(3000));
var acElement = new AutomationCompositionElement();
acElement.setId(UUID.randomUUID());
+ var id = new ToscaConceptIdentifier("id", "1.2.3");
acElement.setDefinition(id);
acElement.setDescription("Description");
acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
ToscaConceptIdentifier id = new ToscaConceptIdentifier();
id.setName("id");
id.setVersion("1.2.3");
- orig.setAutomationCompositionId(id);
+ orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(id);
orig.setParticipantType(id);
orig.setMessageId(UUID.randomUUID());
ToscaConceptIdentifier id = new ToscaConceptIdentifier();
id.setName("id");
id.setVersion("1.2.3");
- orig.setAutomationCompositionId(id);
+ orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(id);
orig.setParticipantType(id);
orig.setMessageId(UUID.randomUUID());
void testCopyConstructor() throws CoderException {
assertThatThrownBy(() -> new ParticipantStatus(null)).isInstanceOf(NullPointerException.class);
- final ParticipantStatus orig = new ParticipantStatus();
+ final var orig = new ParticipantStatus();
// verify with null values
assertEquals(removeVariableFields(orig.toString()),
removeVariableFields(new ParticipantStatus(orig).toString()));
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
- orig.setAutomationCompositionId(id);
+ var automationCompositionId = UUID.randomUUID();
+ orig.setAutomationCompositionId(automationCompositionId);
+ var id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setParticipantId(id);
ToscaConceptIdentifier type = new ToscaConceptIdentifier("type", "2.3.4");
orig.setParticipantType(type);
orig.setHealthStatus(ParticipantHealthStatus.HEALTHY);
orig.setTimestamp(Instant.ofEpochMilli(3000));
- AutomationCompositionInfo acInfo = getAutomationCompositionInfo(id);
+ var acInfo = getAutomationCompositionInfo(automationCompositionId);
orig.setAutomationCompositionInfoList(List.of(acInfo));
- ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition();
+ var participantDefinitionUpdate = new ParticipantDefinition();
participantDefinitionUpdate.setParticipantId(id);
participantDefinitionUpdate.setParticipantType(type);
- AutomationCompositionElementDefinition acDefinition = getAcElementDefinition(id);
+ var acDefinition = getAcElementDefinition(id);
participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition));
orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate));
assertSerializable(orig, ParticipantStatus.class);
}
- private AutomationCompositionInfo getAutomationCompositionInfo(ToscaConceptIdentifier id) {
- AutomationCompositionInfo acInfo = new AutomationCompositionInfo();
+ private AutomationCompositionInfo getAutomationCompositionInfo(UUID id) {
+ var acInfo = new AutomationCompositionInfo();
acInfo.setState(AutomationCompositionState.PASSIVE2RUNNING);
acInfo.setAutomationCompositionId(id);
}
private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) {
- ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate();
+ var toscaNodeTemplate = new ToscaNodeTemplate();
toscaNodeTemplate.setName("nodeTemplate");
toscaNodeTemplate.setDerivedFrom("parentNodeTemplate");
toscaNodeTemplate.setDescription("Description of nodeTemplate");
toscaNodeTemplate.setVersion("1.2.3");
- AutomationCompositionElementDefinition acDefinition = new AutomationCompositionElementDefinition();
+ var acDefinition = new AutomationCompositionElementDefinition();
acDefinition.setAcElementDefinitionId(id);
acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate);
- ToscaProperty property = new ToscaProperty();
+ var property = new ToscaProperty();
property.setName("test");
property.setType("testType");
- Map<String, ToscaProperty> commonPropertiesMap = Map.of("Prop1", property);
+ var commonPropertiesMap = Map.of("Prop1", property);
acDefinition.setCommonPropertiesMap(commonPropertiesMap);
return acDefinition;
}
ParticipantUpdate orig = new ParticipantUpdate();
// verify with all values
ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
- orig.setAutomationCompositionId(id);
+ orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(id);
orig.setParticipantType(id);
orig.setMessageId(UUID.randomUUID());
import java.lang.invoke.MethodHandles;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import java.util.UUID;
-import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.ValidationException;
import lombok.AccessLevel;
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;
import org.springframework.stereotype.Component;
/**
* Handle a automation composition element state change.
*
+ * @param automationCompositionId the ID of the automation composition
* @param automationCompositionElementId the ID of the automation composition element
* @param currentState the current state of the automation composition element
* @param newState the state to which the automation composition element is changing to
* @throws PfModelException in case of a model exception
*/
@Override
- public void automationCompositionElementStateChange(ToscaConceptIdentifier automationCompositionId,
+ public void automationCompositionElementStateChange(UUID automationCompositionId,
UUID automationCompositionElementId, AutomationCompositionState currentState,
AutomationCompositionOrderedState newState) throws A1PolicyServiceException {
switch (newState) {
case UNINITIALISED:
- ConfigurationEntity configurationEntity = configRequestMap.get(automationCompositionElementId);
+ var configurationEntity = configRequestMap.get(automationCompositionElementId);
if (configurationEntity != null && acA1PmsClient.isPmsHealthy()) {
acA1PmsClient.deleteService(configurationEntity.getPolicyServiceEntities());
configRequestMap.remove(automationCompositionElementId);
/**
* Callback method to handle an update on an automation composition element.
*
+ * @param automationCompositionId the ID of the automation composition
* @param element the information on the automation composition element
- * @param nodeTemplate toscaNodeTemplate
+ * @param properties properties Map
*/
@Override
- public void automationCompositionElementUpdate(ToscaConceptIdentifier automationCompositionId,
- AutomationCompositionElement element, ToscaNodeTemplate nodeTemplate) throws A1PolicyServiceException {
+ public void automationCompositionElementUpdate(UUID automationCompositionId,
+ AutomationCompositionElement element, Map<String, Object> properties) throws A1PolicyServiceException {
try {
- var configurationEntity = CODER.convert(nodeTemplate.getProperties(), ConfigurationEntity.class);
- Set<ConstraintViolation<ConfigurationEntity>> violations =
+ var configurationEntity = CODER.convert(properties, ConfigurationEntity.class);
+ var violations =
Validation.buildDefaultValidatorFactory().getValidator().validate(configurationEntity);
if (violations.isEmpty()) {
if (acA1PmsClient.isPmsHealthy()) {
import org.onap.policy.clamp.acm.participant.a1pms.utils.ToscaUtils;
import org.onap.policy.clamp.acm.participant.a1pms.webclient.AcA1PmsClient;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@InjectMocks
@Spy
private AutomationCompositionElementHandler automationCompositionElementHandler =
- new AutomationCompositionElementHandler(acA1PmsClient);
-
+ new AutomationCompositionElementHandler(acA1PmsClient);
private final CommonTestData commonTestData = new CommonTestData();
private static ToscaServiceTemplate serviceTemplate;
private static final String A1_AUTOMATION_COMPOSITION_ELEMENT =
- "org.onap.domain.database.A1PMSAutomationCompositionElement";
+ "org.onap.domain.database.A1PMSAutomationCompositionElement";
@BeforeAll
static void init() {
var element = commonTestData.getAutomationCompositionElement();
var automationCompositionElementId = element.getId();
- Map<String, ToscaNodeTemplate> nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler.automationCompositionElementUpdate(
- commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT));
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ automationCompositionElementHandler
+ .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.PASSIVE));
+ automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
+ AutomationCompositionOrderedState.PASSIVE));
assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.UNINITIALISED));
+ automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
+ AutomationCompositionOrderedState.UNINITIALISED));
assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementStateChange(
- automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.RUNNING));
+ automationCompositionId, automationCompositionElementId, AutomationCompositionState.PASSIVE,
+ AutomationCompositionOrderedState.RUNNING));
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
assertThrows(A1PolicyServiceException.class,
@Test
void test_AutomationCompositionElementUpdate() {
- AutomationCompositionElement element = commonTestData.getAutomationCompositionElement();
+ var element = commonTestData.getAutomationCompositionElement();
- Map<String, ToscaNodeTemplate> nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementUpdate(
- commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT)));
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ assertDoesNotThrow(() -> automationCompositionElementHandler
+ .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
}
@Test
void test_AutomationCompositionElementUpdateWithUnhealthyA1pms() {
- AutomationCompositionElement element = commonTestData.getAutomationCompositionElement();
+ var element = commonTestData.getAutomationCompositionElement();
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
- Map<String, ToscaNodeTemplate> nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- assertThrows(A1PolicyServiceException.class,
- () -> automationCompositionElementHandler.automationCompositionElementUpdate(
- commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT)));
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
+ .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
}
@Test
void test_AutomationCompositionElementUpdateWithInvalidConfiguration() {
- AutomationCompositionElement element = commonTestData.getAutomationCompositionElement();
-
- Map<String, ToscaNodeTemplate> nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- ToscaNodeTemplate toscaNodeTemplate = nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT);
- toscaNodeTemplate.setProperties(Map.of());
- assertThrows(A1PolicyServiceException.class,
- () -> automationCompositionElementHandler.automationCompositionElementUpdate(
- commonTestData.getAutomationCompositionId(), element, toscaNodeTemplate));
+ var element = commonTestData.getAutomationCompositionElement();
+ assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
+ .automationCompositionElementUpdate(commonTestData.getAutomationCompositionId(), element,
+ Map.of()));
}
}
public class CommonTestData {
private static final String TEST_KEY_NAME = "org.onap.domain.database.A1PMSAutomationCompositionElement";
+ private static final List<UUID> AC_ID_LIST = List.of(UUID.randomUUID(), UUID.randomUUID());
/**
* Get a automationComposition Element.
* @return automationCompositionElement object
*/
public AutomationCompositionElement getAutomationCompositionElement() {
- AutomationCompositionElement element = new AutomationCompositionElement();
+ var element = new AutomationCompositionElement();
element.setId(UUID.randomUUID());
element.setDefinition(new ToscaConceptIdentifier(TEST_KEY_NAME, "1.0.1"));
element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
/**
* Get automation composition id.
*
+ * @param instanceNo Identifier instance no
* @return ToscaConceptIdentifier automationCompositionId
*/
- public ToscaConceptIdentifier getAutomationCompositionId() {
+ public ToscaConceptIdentifier getA1PolicyServiceId(int instanceNo) {
+ return new ToscaConceptIdentifier("A1PMSInstance" + instanceNo, "1.0.0");
+ }
+
+ /**
+ * Get automation composition id.
+ *
+ * @return UUID automationCompositionId
+ */
+ public UUID getAutomationCompositionId() {
return getAutomationCompositionId(0);
}
/**
* Get automation composition id.
+ *
* @param instanceNo Identifier instance no
- * @return ToscaConceptIdentifier automationCompositionId
+ * @return UUID automationCompositionId
*/
- public ToscaConceptIdentifier getAutomationCompositionId(int instanceNo) {
- return new ToscaConceptIdentifier("A1PMSInstance" + instanceNo, "1.0.0");
+ public UUID getAutomationCompositionId(int instanceNo) {
+ return AC_ID_LIST.get(instanceNo);
}
-
/**
* Get valid policy entities.
+ *
* @return List of policy entities
*/
public List<A1PolicyServiceEntity> getValidPolicyEntities() {
- A1PolicyServiceEntity a1PolicyServiceEntity1 = new A1PolicyServiceEntity(getAutomationCompositionId(0),
+ var a1PolicyServiceEntity1 = new A1PolicyServiceEntity(getA1PolicyServiceId(0),
"testService1", "http://localhost", 0);
- A1PolicyServiceEntity a1PolicyServiceEntity2 = new A1PolicyServiceEntity(getAutomationCompositionId(1),
+ var a1PolicyServiceEntity2 = new A1PolicyServiceEntity(getA1PolicyServiceId(1),
"testService2", "http://127.0.0.1", 0);
return List.of(a1PolicyServiceEntity1, a1PolicyServiceEntity2);
}
import java.io.Closeable;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
import java.util.stream.Collectors;
-import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.ValidationException;
import lombok.Setter;
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;
import org.springframework.http.HttpStatus;
* @throws PfModelException in case of a model exception
*/
@Override
- public void automationCompositionElementStateChange(ToscaConceptIdentifier automationCompositionId,
+ public void automationCompositionElementStateChange(UUID automationCompositionId,
UUID automationCompositionElementId, AutomationCompositionState currentState,
AutomationCompositionOrderedState newState) {
switch (newState) {
/**
* Callback method to handle an update on a automation composition element.
*
+ * @param automationCompositionId the automationComposition Id
* @param element the information on the automation composition element
- * @param nodeTemplate toscaNodeTemplate
+ * @param properties properties Map
*/
@Override
- public void automationCompositionElementUpdate(ToscaConceptIdentifier automationCompositionId,
- AutomationCompositionElement element, ToscaNodeTemplate nodeTemplate) {
+ public void automationCompositionElementUpdate(UUID automationCompositionId,
+ AutomationCompositionElement element, Map<String, Object> properties) {
try {
- var configRequest = CODER.convert(nodeTemplate.getProperties(), ConfigRequest.class);
- Set<ConstraintViolation<ConfigRequest>> violations =
+ var configRequest = CODER.convert(properties, ConfigRequest.class);
+ var violations =
Validation.buildDefaultValidatorFactory().getValidator().validate(configRequest);
if (violations.isEmpty()) {
invokeHttpClient(configRequest);
- List<Pair<Integer, String>> failedResponseStatus = restResponseMap.values().stream()
+ var failedResponseStatus = restResponseMap.values().stream()
.filter(response -> !HttpStatus.valueOf(response.getKey())
.is2xxSuccessful()).collect(Collectors.toList());
if (failedResponseStatus.isEmpty()) {
*/
public void invokeHttpClient(ConfigRequest configRequest) throws ExecutionException, InterruptedException {
// Invoke runnable thread to execute https requests of all config entities
- Future<Map> result = executor.submit(new AcHttpClient(configRequest, restResponseMap), restResponseMap);
+ var result = executor.submit(new AcHttpClient(configRequest, restResponseMap), restResponseMap);
if (!result.get().isEmpty()) {
LOGGER.debug("Http Request Completed: {}", result.isDone());
}
import static org.mockito.Mockito.doNothing;
import java.io.IOException;
-import java.util.Map;
+import java.util.HashMap;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.participant.http.utils.CommonTestData;
import org.onap.policy.clamp.acm.participant.http.utils.ToscaUtils;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@Test
void test_AutomationCompositionElementUpdate() throws Exception {
doNothing().when(automationCompositionElementHandler).invokeHttpClient(any());
- AutomationCompositionElement element = commonTestData.getAutomationCompositionElement();
+ var element = commonTestData.getAutomationCompositionElement();
- Map<String, ToscaNodeTemplate> nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
+ var map = new HashMap<>(nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ map.putAll(element.getProperties());
assertDoesNotThrow(() -> automationCompositionElementHandler.automationCompositionElementUpdate(
- commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(HTTP_AUTOMATION_COMPOSITION_ELEMENT)));
+ commonTestData.getAutomationCompositionId(), element, map));
}
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
private static final String TEST_KEY_NAME =
"org.onap.domain.database.Http_PMSHMicroserviceAutomationCompositionElement";
+ public static final UUID AC_ID = UUID.randomUUID();
/**
* Get a automationComposition Element.
/**
* Get automation composition id.
*
- * @return ToscaConceptIdentifier automationCompositionId
+ * @return UUID automationCompositionId
*/
- public ToscaConceptIdentifier getAutomationCompositionId() {
- return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ public UUID getAutomationCompositionId() {
+ return AC_ID;
}
/**
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
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;
import org.springframework.beans.factory.annotation.Autowired;
* @param newState the state to which the automation composition element is changing to
*/
@Override
- public synchronized void automationCompositionElementStateChange(ToscaConceptIdentifier automationCompositionId,
+ public synchronized void automationCompositionElementStateChange(UUID automationCompositionId,
UUID automationCompositionElementId, AutomationCompositionState currentState,
AutomationCompositionOrderedState newState) {
switch (newState) {
case UNINITIALISED:
- ChartInfo chart = chartMap.get(automationCompositionElementId);
+ var chart = chartMap.get(automationCompositionElementId);
if (chart != null) {
LOGGER.info("Helm deployment to be deleted {} ", chart.getReleaseName());
try {
/**
* Callback method to handle an update on a automation composition element.
*
+ * @param automationCompositionId the automationComposition Id
* @param element the information on the automation composition element
- * @param nodeTemplate toscaNodeTemplate
+ * @param properties properties Map
* @throws PfModelException in case of an exception
*/
@Override
- public synchronized void automationCompositionElementUpdate(ToscaConceptIdentifier automationCompositionId,
- AutomationCompositionElement element, ToscaNodeTemplate nodeTemplate) throws PfModelException {
+ public synchronized void automationCompositionElementUpdate(UUID automationCompositionId,
+ AutomationCompositionElement element, Map<String, Object> properties) throws PfModelException {
@SuppressWarnings("unchecked")
- Map<String, Object> chartData = (Map<String, Object>) nodeTemplate.getProperties().get("chart");
+ var chartData = (Map<String, Object>) properties.get("chart");
LOGGER.info("Installation request received for the Helm Chart {} ", chartData);
try {
if (chartService.installChart(chartInfo)) {
chartMap.put(element.getId(), chartInfo);
- var config = CODER.convert(nodeTemplate.getProperties(),
- ThreadConfig.class);
+ var config = CODER.convert(properties, ThreadConfig.class);
checkPodStatus(automationCompositionId, element.getId(), chartInfo,
config.uninitializedToPassiveTimeout, config.podStatusCheckInterval);
}
*
* @param chart ChartInfo
*/
- public void checkPodStatus(ToscaConceptIdentifier automationCompositionId, UUID elementId,
+ public void checkPodStatus(UUID automationCompositionId, UUID elementId,
ChartInfo chart, int timeout, int podStatusCheckInterval) throws ExecutionException, InterruptedException {
// Invoke runnable thread to check pod status
- Future<String> result = executor.submit(new PodStatusValidator(chart, timeout,
+ var result = executor.submit(new PodStatusValidator(chart, timeout,
podStatusCheckInterval), "Done");
if (!result.get().isEmpty()) {
LOGGER.info("Pod Status Validator Completed: {}", result.isDone());
import java.io.File;
import java.io.IOException;
import java.util.List;
-import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
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.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@Test
void test_AutomationCompositionElementStateChange() throws ServiceException {
- UUID automationCompositionElementId1 = UUID.randomUUID();
- UUID automationCompositionElementId2 = UUID.randomUUID();
+ var automationCompositionElementId1 = UUID.randomUUID();
+ var automationCompositionElementId2 = UUID.randomUUID();
automationCompositionElementHandler.getChartMap().put(automationCompositionElementId1, charts.get(0));
automationCompositionElementHandler.getChartMap().put(automationCompositionElementId2, charts.get(1));
ExecutionException, InterruptedException {
doReturn(true).when(chartService).installChart(any());
doNothing().when(automationCompositionElementHandler).checkPodStatus(any(), any(), any(), anyInt(), anyInt());
- UUID elementId1 = UUID.randomUUID();
- AutomationCompositionElement element = new AutomationCompositionElement();
+ var elementId1 = UUID.randomUUID();
+ var element = new AutomationCompositionElement();
element.setId(elementId1);
element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1"));
element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- Map<String, ToscaNodeTemplate> nodeTemplatesMap =
+ var nodeTemplatesMap =
toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
automationCompositionElementHandler.automationCompositionElementUpdate(
commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT));
+ nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
assertThat(automationCompositionElementHandler.getChartMap()).hasSize(1).containsKey(elementId1);
doThrow(new ServiceException("Error installing the chart")).when(chartService).installChart(Mockito.any());
- UUID elementId2 = UUID.randomUUID();
+ var elementId2 = UUID.randomUUID();
element.setId(elementId2);
automationCompositionElementHandler.automationCompositionElementUpdate(
commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT));
+ nodeTemplatesMap.get(K8S_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
assertThat(automationCompositionElementHandler.getChartMap().containsKey(elementId2)).isFalse();
}
doReturn("Done").when(result).get();
doReturn(true).when(result).isDone();
var chartInfo = charts.get(0);
- ToscaConceptIdentifier automationCompositionId = new ToscaConceptIdentifier();
- AutomationCompositionElement element = new AutomationCompositionElement();
+ var automationCompositionId = UUID.randomUUID();
+ var element = new AutomationCompositionElement();
assertDoesNotThrow(
() -> automationCompositionElementHandler.checkPodStatus(automationCompositionId,
element.getId(), chartInfo, 1, 1));
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
+import java.util.UUID;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
public static final long TIME_INTERVAL = 2000;
public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
public static final Coder CODER = new StandardCoder();
-
+ private static final UUID AC_ID = UUID.randomUUID();
/**
* Get ParticipantK8sParameters.
/**
* Get automation composition id.
- * @return ToscaConceptIdentifier automationCompositionId
+ * @return UUID automationCompositionId
*/
- public ToscaConceptIdentifier getAutomationCompositionId() {
- return new ToscaConceptIdentifier("PMSHInstance0", "1.0.0");
+ public UUID getAutomationCompositionId() {
+ return AC_ID;
}
}
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.UUID;
import lombok.Setter;
import org.apache.http.HttpStatus;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
-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;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
* @param orderedState the state to which the automation composition element is changing to
*/
@Override
- public void automationCompositionElementStateChange(ToscaConceptIdentifier automationCompositionId,
+ public void automationCompositionElementStateChange(UUID automationCompositionId,
UUID automationCompositionElementId,
AutomationCompositionState currentState,
AutomationCompositionOrderedState orderedState) {
}
}
- private void deletePolicyData(ToscaConceptIdentifier automationCompositionId,
+ private void deletePolicyData(UUID automationCompositionId,
UUID automationCompositionElementId, AutomationCompositionOrderedState newState) {
// Delete all policies of this automationComposition from policy framework
- for (Entry<String, String> policy : policyMap.entrySet()) {
+ for (var policy : policyMap.entrySet()) {
apiHttpClient.deletePolicy(policy.getKey(), policy.getValue());
}
policyMap.clear();
// Delete all policy types of this automation composition from policy framework
- for (Entry<String, String> policyType : policyTypeMap.entrySet()) {
+ for (var policyType : policyTypeMap.entrySet()) {
apiHttpClient.deletePolicyType(policyType.getKey(), policyType.getValue());
}
policyTypeMap.clear();
}
- private void deployPolicies(ToscaConceptIdentifier automationCompositionId, UUID automationCompositionElementId,
+ private void deployPolicies(UUID automationCompositionId, UUID automationCompositionElementId,
AutomationCompositionOrderedState newState) {
var deployFailure = false;
// Deploy all policies of this automationComposition from Policy Framework
if (!policyMap.entrySet().isEmpty()) {
- for (Entry<String, String> policy : policyMap.entrySet()) {
+ for (var policy : policyMap.entrySet()) {
var deployPolicyResp = papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(),
DeploymentSubGroup.Action.POST).getStatus();
if (deployPolicyResp != HttpStatus.SC_ACCEPTED) {
private void undeployPolicies(UUID automationCompositionElementId) {
// Undeploy all policies of this automation composition from Policy Framework
if (!policyMap.entrySet().isEmpty()) {
- for (Entry<String, String> policy : policyMap.entrySet()) {
+ for (var policy : policyMap.entrySet()) {
papHttpClient.handlePolicyDeployOrUndeploy(policy.getKey(), policy.getValue(),
DeploymentSubGroup.Action.DELETE);
}
/**
* Callback method to handle an update on automation composition element.
*
+ * @param automationCompositionId the automationComposition Id
* @param element the information on the automation composition element
- * @param acElementDefinition toscaNodeTemplate
+ * @param properties properties Map
* @throws PfModelException in case of an exception
*/
@Override
- public void automationCompositionElementUpdate(ToscaConceptIdentifier automationCompositionId,
- AutomationCompositionElement element,
- ToscaNodeTemplate acElementDefinition)
- throws PfModelException {
+ public void automationCompositionElementUpdate(UUID automationCompositionId,
+ AutomationCompositionElement element, Map<String, Object> properties) throws PfModelException {
var createPolicyTypeResp = HttpStatus.SC_OK;
var createPolicyResp = HttpStatus.SC_OK;
- ToscaServiceTemplate automationCompositionDefinition = element.getToscaServiceTemplateFragment();
+ var automationCompositionDefinition = element.getToscaServiceTemplateFragment();
if (automationCompositionDefinition.getToscaTopologyTemplate() != null) {
if (automationCompositionDefinition.getPolicyTypes() != null) {
- for (ToscaPolicyType policyType : automationCompositionDefinition.getPolicyTypes().values()) {
+ for (var policyType : automationCompositionDefinition.getPolicyTypes().values()) {
policyTypeMap.put(policyType.getName(), policyType.getVersion());
}
LOGGER.info("Found Policy Types in automation composition definition: {} , Creating Policy Types",
createPolicyTypeResp = apiHttpClient.createPolicyType(automationCompositionDefinition).getStatus();
}
if (automationCompositionDefinition.getToscaTopologyTemplate().getPolicies() != null) {
- for (Map<String, ToscaPolicy> gotPolicyMap : automationCompositionDefinition.getToscaTopologyTemplate()
- .getPolicies()) {
+ for (var gotPolicyMap : automationCompositionDefinition.getToscaTopologyTemplate().getPolicies()) {
for (ToscaPolicy policy : gotPolicyMap.values()) {
policyMap.put(policy.getName(), policy.getVersion());
}
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
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.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
-
class AutomationCompositionElementHandlerTest {
private static final String ID_NAME = "org.onap.PM_CDS_Blueprint";
private static final String ID_VERSION = "1.0.1";
private static final UUID automationCompositionElementId = UUID.randomUUID();
- private static final ToscaConceptIdentifier automationCompositionId =
- new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
+ public static final UUID AC_ID = UUID.randomUUID();
+ private static final ToscaConceptIdentifier PARTICIPANT_ID = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
private PolicyApiHttpClient api = Mockito.mock(PolicyApiHttpClient.class);
- private PolicyPapHttpClient pap = Mockito.mock(PolicyPapHttpClient.class);
+ private PolicyPapHttpClient pap = Mockito.mock(PolicyPapHttpClient.class);
@Test
void testHandlerDoesNotThrowExceptions() {
- AutomationCompositionElementHandler handler = getTestingHandler();
-
- assertDoesNotThrow(() -> handler
- .automationCompositionElementStateChange(automationCompositionId,
- automationCompositionElementId,
- AutomationCompositionState.UNINITIALISED,
- AutomationCompositionOrderedState.PASSIVE));
-
- assertDoesNotThrow(() -> handler
- .automationCompositionElementStateChange(automationCompositionId,
- automationCompositionElementId,
- AutomationCompositionState.RUNNING,
- AutomationCompositionOrderedState.UNINITIALISED));
-
- assertDoesNotThrow(() -> handler
- .automationCompositionElementStateChange(automationCompositionId,
- automationCompositionElementId,
- AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.RUNNING));
+ var handler = getTestingHandler();
+
+ assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(AC_ID, automationCompositionElementId,
+ AutomationCompositionState.UNINITIALISED, AutomationCompositionOrderedState.PASSIVE));
+
+ assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(AC_ID, automationCompositionElementId,
+ AutomationCompositionState.RUNNING, AutomationCompositionOrderedState.UNINITIALISED));
+
+ assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(AC_ID, automationCompositionElementId,
+ AutomationCompositionState.PASSIVE, AutomationCompositionOrderedState.RUNNING));
}
private AutomationCompositionElementHandler getTestingHandler() {
private AutomationCompositionElement getTestingAcElement() {
var element = new AutomationCompositionElement();
- element.setDefinition(automationCompositionId);
+ element.setDefinition(PARTICIPANT_ID);
element.setDescription("Description");
element.setId(automationCompositionElementId);
element.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- element.setParticipantId(automationCompositionId);
+ element.setParticipantId(PARTICIPANT_ID);
element.setState(AutomationCompositionState.UNINITIALISED);
var template = new ToscaServiceTemplate();
template.setToscaTopologyTemplate(new ToscaTopologyTemplate());
doReturn(Response.ok().build()).when(api).createPolicy(any());
doReturn(Response.accepted().build()).when(pap).handlePolicyDeployOrUndeploy(any(), any(), any());
- AutomationCompositionElementHandler handler = getTestingHandler();
+ var handler = getTestingHandler();
var element = getTestingAcElement();
- var acElementDefinition = Mockito.mock(ToscaNodeTemplate.class);
-
- assertDoesNotThrow(() -> handler
- .automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
- assertDoesNotThrow(() -> handler
- .automationCompositionElementStateChange(automationCompositionId,
- automationCompositionElementId,
- AutomationCompositionState.PASSIVE,
- AutomationCompositionOrderedState.UNINITIALISED));
+ assertDoesNotThrow(() -> handler.automationCompositionElementUpdate(AC_ID, element, Map.of()));
+ assertDoesNotThrow(() -> handler.automationCompositionElementStateChange(AC_ID, automationCompositionElementId,
+ AutomationCompositionState.PASSIVE, AutomationCompositionOrderedState.UNINITIALISED));
- //Mock failure in policy deployment
+ // Mock failure in policy deployment
doReturn(Response.serverError().build()).when(pap).handlePolicyDeployOrUndeploy(any(), any(), any());
- assertDoesNotThrow(() -> handler
- .automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
+ assertDoesNotThrow(() -> handler.automationCompositionElementUpdate(AC_ID, element, Map.of()));
// Mock failure in policy type creation
doReturn(Response.serverError().build()).when(api).createPolicyType(any());
- assertDoesNotThrow(() -> handler
- .automationCompositionElementUpdate(automationCompositionId, element, acElementDefinition));
+ assertDoesNotThrow(() -> handler.automationCompositionElementUpdate(AC_ID, element, Map.of()));
}
}
package org.onap.policy.clamp.acm.participant.intermediary.api;
+import java.util.Map;
import java.util.UUID;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
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;
/**
* This interface is implemented by participant implementations to receive updates on automation composition elements.
* @param newState the state to which the automation composition element is changing to
* @throws PfModelException in case of a model exception
*/
- public void automationCompositionElementStateChange(ToscaConceptIdentifier automationCompositionId,
+ public void automationCompositionElementStateChange(UUID automationCompositionId,
UUID automationCompositionElementId, AutomationCompositionState currentState,
AutomationCompositionOrderedState newState) throws PfModelException;
/**
* Handle an update on a automation composition element.
*
+ * @param automationCompositionId the automationComposition Id
* @param element the information on the automation composition element
- * @param automationCompositionElementDefinition toscaNodeTemplate
+ * @param properties properties Map
* @throws PfModelException from Policy framework
*/
- public void automationCompositionElementUpdate(ToscaConceptIdentifier automationCompositionId,
- AutomationCompositionElement element, ToscaNodeTemplate automationCompositionElementDefinition)
- throws PfModelException;
+ public void automationCompositionElementUpdate(UUID automationCompositionId,
+ AutomationCompositionElement element, Map<String, Object> properties) throws PfModelException;
}
* @param newState the state of the automation composition element
* @return AutomationCompositionElement updated automation composition element
*/
- AutomationCompositionElement updateAutomationCompositionElementState(ToscaConceptIdentifier automationCompositionId,
+ AutomationCompositionElement updateAutomationCompositionElementState(UUID automationCompositionId,
UUID id, AutomationCompositionOrderedState currentState, AutomationCompositionState newState,
ParticipantMessageType messageType);
}
@Override
public AutomationCompositionElement updateAutomationCompositionElementState(
- ToscaConceptIdentifier automationCompositionId, UUID id, AutomationCompositionOrderedState currentState,
+ UUID automationCompositionId, UUID id, AutomationCompositionOrderedState currentState,
AutomationCompositionState newState, ParticipantMessageType messageType) {
return automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id,
currentState, newState);
package org.onap.policy.clamp.acm.participant.intermediary.handler;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
private final ParticipantMessagePublisher publisher;
@Getter
- private final Map<ToscaConceptIdentifier, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
+ private final Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
@Getter
private final Map<UUID, AutomationCompositionElement> elementsOnThisParticipant = new LinkedHashMap<>();
* @return automationCompositionElement the updated automation composition element
*/
public AutomationCompositionElement updateAutomationCompositionElementState(
- ToscaConceptIdentifier automationCompositionId, UUID id, AutomationCompositionOrderedState orderedState,
+ UUID automationCompositionId, UUID id, AutomationCompositionOrderedState orderedState,
AutomationCompositionState newState) {
if (id == null) {
}
automationComposition = new AutomationComposition();
- automationComposition.setName(updateMsg.getAutomationCompositionId().getName());
- automationComposition.setVersion(updateMsg.getAutomationCompositionId().getVersion());
+ automationComposition.setInstanceId(updateMsg.getAutomationCompositionId());
var acElements = storeElementsOnThisParticipant(updateMsg.getParticipantUpdatesList());
var acElementMap = prepareAcElementMap(acElements);
automationComposition.setElements(acElementMap);
private void handleAutomationCompositionElementUpdate(List<AutomationCompositionElement> acElements,
List<AutomationCompositionElementDefinition> acElementDefinitions, Integer startPhaseMsg,
- ToscaConceptIdentifier automationCompositionId) {
+ UUID automationCompositionId) {
try {
for (var element : acElements) {
var acElementNodeTemplate = getAcElementNodeTemplate(acElementDefinitions, element.getDefinition());
int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
if (startPhaseMsg.equals(startPhase)) {
for (var acElementListener : listeners) {
- acElementListener.automationCompositionElementUpdate(automationCompositionId, element,
- acElementNodeTemplate);
+ var map = new HashMap<>(acElementNodeTemplate.getProperties());
+ map.putAll(element.getProperties());
+ acElementListener.automationCompositionElementUpdate(automationCompositionId, element, map);
}
}
}
.filter(element -> !AutomationCompositionState.UNINITIALISED.equals(element.getState())).findAny()
.isEmpty();
if (isAllUninitialised) {
- automationCompositionMap.remove(automationComposition.getKey().asIdentifier());
+ automationCompositionMap.remove(automationComposition.getInstanceId());
automationComposition.getElements().values()
.forEach(element -> elementsOnThisParticipant.remove(element.getId()));
}
automationCompositionAck.setParticipantType(participantType);
automationCompositionAck.setMessage("Automation composition is already in state " + orderedState);
automationCompositionAck.setResult(false);
- automationCompositionAck.setAutomationCompositionId(automationComposition.getKey().asIdentifier());
+ automationCompositionAck.setAutomationCompositionId(automationComposition.getInstanceId());
publisher.sendAutomationCompositionAck(automationCompositionAck);
return;
}
for (var acElementListener : listeners) {
try {
acElementListener.automationCompositionElementStateChange(
- automationComposition.getKey().asIdentifier(), acElement.getId(), acElement.getState(),
+ automationComposition.getInstanceId(), acElement.getId(), acElement.getState(),
orderedState);
} catch (PfModelException e) {
LOGGER.debug("Automation composition element update failed {}",
- automationComposition.getKey().asIdentifier());
+ automationComposition.getInstanceId());
}
}
}
var idType = new ToscaConceptIdentifier(ID_NAME_TYPE, ID_VERSION_TYPE);
assertEquals(idType, element.getParticipantType());
- var acElement =
- apiImpl.updateAutomationCompositionElementState(id, uuid, AutomationCompositionOrderedState.UNINITIALISED,
- AutomationCompositionState.PASSIVE, ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
+ var acElement = apiImpl.updateAutomationCompositionElementState(UUID.randomUUID(), uuid,
+ AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE,
+ ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
assertEquals(AutomationCompositionOrderedState.UNINITIALISED, acElement.getOrderedState());
assertEquals(uuid, acElement.getId());
var element = new AutomationCompositionElement();
element.setId(elementId1);
element.setDefinition(
- new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "1.0.1"));
+ new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "1.0.1"));
element.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
var ach = commonTestData.getMockAutomationCompositionHandler();
assertNull(ach.updateAutomationCompositionElementState(null, null,
- AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE));
+ AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE));
assertNull(ach.updateAutomationCompositionElementState(null, id,
- AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE));
+ AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE));
}
@Test
var key = ach.getElementsOnThisParticipant().keySet().iterator().next();
var value = ach.getElementsOnThisParticipant().get(key);
assertEquals(AutomationCompositionState.UNINITIALISED, value.getState());
- ach.updateAutomationCompositionElementState(id, uuid, AutomationCompositionOrderedState.UNINITIALISED,
- AutomationCompositionState.PASSIVE);
+ ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, uuid,
+ AutomationCompositionOrderedState.UNINITIALISED, AutomationCompositionState.PASSIVE);
assertEquals(AutomationCompositionState.PASSIVE, value.getState());
ach.getAutomationCompositionMap().values().iterator().next().getElements().putIfAbsent(key, value);
- ach.updateAutomationCompositionElementState(id, key, AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.RUNNING);
+ ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key,
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.RUNNING);
assertEquals(AutomationCompositionState.RUNNING, value.getState());
ach.getElementsOnThisParticipant().remove(key, value);
ach.getAutomationCompositionMap().values().iterator().next().getElements().clear();
- assertNull(ach.updateAutomationCompositionElementState(id, key, AutomationCompositionOrderedState.PASSIVE,
- AutomationCompositionState.RUNNING));
+ assertNull(ach.updateAutomationCompositionElementState(CommonTestData.AC_ID_1, key,
+ AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.RUNNING));
}
var id = CommonTestData.getParticipantId();
var stateChange = getStateChange(id, uuid, AutomationCompositionOrderedState.RUNNING);
var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
- assertDoesNotThrow(
- () -> ach.handleAutomationCompositionStateChange(mock(AutomationCompositionStateChange.class), List.of()));
+ assertDoesNotThrow(() -> ach
+ .handleAutomationCompositionStateChange(mock(AutomationCompositionStateChange.class), List.of()));
ach.handleAutomationCompositionStateChange(stateChange, List.of());
var newid = new ToscaConceptIdentifier("id", "1.2.3");
- stateChange.setAutomationCompositionId(newid);
+ stateChange.setAutomationCompositionId(UUID.randomUUID());
stateChange.setParticipantId(newid);
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChange, List.of()));
var acd = new AutomationCompositionElementDefinition();
acd.setAcElementDefinitionId(id);
var updateMsg = new AutomationCompositionUpdate();
- updateMsg.setAutomationCompositionId(id);
+ updateMsg.setAutomationCompositionId(UUID.randomUUID());
updateMsg.setMessageId(uuid);
updateMsg.setParticipantId(id);
updateMsg.setStartPhase(0);
updateMsg.setStartPhase(0);
assertDoesNotThrow(() -> ach.handleAutomationCompositionUpdate(updateMsg, acElementDefinitions));
- updateMsg.setAutomationCompositionId(new ToscaConceptIdentifier("new", "0.0.1"));
+ updateMsg.setAutomationCompositionId(UUID.randomUUID());
updateMsg.setParticipantUpdatesList(List.of(mock(ParticipantUpdates.class)));
assertDoesNotThrow(() -> ach.handleAutomationCompositionUpdate(updateMsg, acElementDefinitions));
var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of());
var newid = new ToscaConceptIdentifier("id", "1.2.3");
- stateChangeUninitialised.setAutomationCompositionId(newid);
+ stateChangeUninitialised.setAutomationCompositionId(UUID.randomUUID());
stateChangeUninitialised.setParticipantId(newid);
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUninitialised, List.of()));
}
var ach = commonTestData.setTestAutomationCompositionHandler(id, uuid);
ach.handleAutomationCompositionStateChange(stateChangePassive, List.of());
var newid = new ToscaConceptIdentifier("id", "1.2.3");
- stateChangePassive.setAutomationCompositionId(newid);
+ stateChangePassive.setAutomationCompositionId(UUID.randomUUID());
stateChangePassive.setParticipantId(newid);
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangePassive, List.of()));
}
private AutomationCompositionStateChange getStateChange(ToscaConceptIdentifier id, UUID uuid,
- AutomationCompositionOrderedState state) {
+ AutomationCompositionOrderedState state) {
var stateChange = new AutomationCompositionStateChange();
- stateChange.setAutomationCompositionId(id);
+ stateChange.setAutomationCompositionId(UUID.randomUUID());
stateChange.setParticipantId(id);
stateChange.setMessageId(uuid);
stateChange.setOrderedState(state);
var participantHandler = commonTestData.getMockParticipantHandler();
var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
- participantUpdateMsg.setAutomationCompositionId(id);
+ participantUpdateMsg.setAutomationCompositionId(CommonTestData.AC_ID_1);
participantUpdateMsg.setParticipantId(id);
participantUpdateMsg.setParticipantType(id);
participantUpdateMsg.setMessageId(UUID.randomUUID());
@Test
void getAutomationCompositionInfoListTest() throws CoderException {
var participantHandler = commonTestData.getParticipantHandlerAutomationCompositions();
- var id = new ToscaConceptIdentifier(ID_NAME, ID_VERSION);
participantHandler.sendHeartbeat();
- assertEquals(id, participantHandler.makeHeartbeat(false)
+ assertEquals(CommonTestData.AC_ID_1, participantHandler.makeHeartbeat(false)
.getAutomationCompositionInfoList()
.get(0)
.getAutomationCompositionId());
public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
public static final Coder CODER = new StandardCoder();
private static final Object lockit = new Object();
+ public static final UUID AC_ID_0 = UUID.randomUUID();
+ public static final UUID AC_ID_1 = UUID.randomUUID();
/**
* Get ParticipantIntermediaryParameters.
public ParticipantIntermediaryParameters getParticipantIntermediaryParameters() {
try {
return CODER.convert(getIntermediaryParametersMap(PARTICIPANT_GROUP_NAME),
- ParticipantIntermediaryParameters.class);
+ ParticipantIntermediaryParameters.class);
} catch (final CoderException e) {
throw new RuntimeException("cannot create ParticipantSimulatorParameters from map", e);
}
public ParticipantHandler getParticipantHandlerAutomationCompositions() throws CoderException {
var automationCompositionHandler = Mockito.mock(AutomationCompositionHandler.class);
Mockito.doReturn(getTestAutomationCompositions()).when(automationCompositionHandler)
- .getAutomationCompositions();
+ .getAutomationCompositions();
Mockito.doReturn(getTestAutomationCompositionMap()).when(automationCompositionHandler)
- .getAutomationCompositionMap();
+ .getAutomationCompositionMap();
var publisher = new ParticipantMessagePublisher();
publisher.active(Collections.singletonList(Mockito.mock(TopicSink.class)));
var parameters = getParticipantParameters();
*
* @throws CoderException if there is an error with .json file.
*/
- public Map<ToscaConceptIdentifier, AutomationComposition> getTestAutomationCompositionMap() throws CoderException {
+ public Map<UUID, AutomationComposition> getTestAutomationCompositionMap() throws CoderException {
var automationCompositions = getTestAutomationCompositions();
var automationComposition = automationCompositions.getAutomationCompositionList().get(1);
- var id = getParticipantId();
- Map<ToscaConceptIdentifier, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
- automationCompositionMap.put(id, automationComposition);
+ Map<UUID, AutomationComposition> automationCompositionMap = new LinkedHashMap<>();
+ automationCompositionMap.put(automationComposition.getInstanceId(), automationComposition);
return automationCompositionMap;
}
* @throws CoderException if there is an error with .json file.
*/
public AutomationCompositions getTestAutomationCompositions() throws CoderException {
- return new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"),
- AutomationCompositions.class);
+ var automationCompositions = new StandardCoder().decode(
+ new File("src/test/resources/providers/TestAutomationCompositions.json"), AutomationCompositions.class);
+ automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_0);
+ automationCompositions.getAutomationCompositionList().get(1).setInstanceId(AC_ID_1);
+ return automationCompositions;
}
/**
* @return a map suitable for elementsOnThisParticipant
*/
public Map<UUID, AutomationCompositionElement> setAutomationCompositionElementTest(UUID uuid,
- ToscaConceptIdentifier id) {
+ ToscaConceptIdentifier id) {
var acElement = new AutomationCompositionElement();
acElement.setId(uuid);
acElement.setParticipantId(id);
* @return a AutomationCompositionHander with elements
*/
public AutomationCompositionHandler setTestAutomationCompositionHandler(ToscaConceptIdentifier id, UUID uuid)
- throws CoderException {
+ throws CoderException {
var ach = getMockAutomationCompositionHandler();
var key = getTestAutomationCompositionMap().keySet().iterator().next();
},
"709c62b3-8918-41b9-a747-e21eb79c6c22": {
"id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
- "definition": {
- "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement",
- "version": "1.2.3"
- },
+ "compositionId": "709c62b3-8918-41b9-a747-d21eb79c6c40",
"participantType": {
"name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant",
"version": "2.3.1"
description = "AUTOMATION_COMPOSITION_STATE_CHANGE messages published")
public void send(AutomationComposition automationComposition, int startPhase) {
var acsc = new AutomationCompositionStateChange();
- acsc.setAutomationCompositionId(automationComposition.getKey().asIdentifier());
+ acsc.setAutomationCompositionId(automationComposition.getInstanceId());
acsc.setMessageId(UUID.randomUUID());
acsc.setOrderedState(automationComposition.getOrderedState());
acsc.setStartPhase(startPhase);
public void send(AutomationComposition automationComposition, int startPhase) {
var automationCompositionUpdateMsg = new AutomationCompositionUpdate();
automationCompositionUpdateMsg.setStartPhase(startPhase);
- automationCompositionUpdateMsg.setAutomationCompositionId(automationComposition.getKey().asIdentifier());
+ automationCompositionUpdateMsg.setAutomationCompositionId(automationComposition.getInstanceId());
automationCompositionUpdateMsg.setMessageId(UUID.randomUUID());
automationCompositionUpdateMsg.setTimestamp(Instant.now());
var toscaServiceTemplate = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId());
class SupervisionHandlerTest {
private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json";
- private static final ToscaConceptIdentifier identifier = new ToscaConceptIdentifier("PMSHInstance0Crud", "1.0.1");
+ private static final UUID identifier = UUID.randomUUID();
private static final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("ParticipantId", "1.0.0");
private static final ToscaConceptIdentifier participantType =
new ToscaConceptIdentifier("ParticipantType", "1.0.0");