aboutsummaryrefslogtreecommitdiffstats
path: root/participant/participant-impl
diff options
context:
space:
mode:
Diffstat (limited to 'participant/participant-impl')
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java47
-rwxr-xr-xparticipant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java135
-rw-r--r--participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java51
-rw-r--r--participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java105
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java61
-rwxr-xr-xparticipant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java51
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java47
-rw-r--r--participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java38
-rw-r--r--participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java58
-rw-r--r--participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java86
10 files changed, 609 insertions, 70 deletions
diff --git a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
index 8401b934b..665071bdf 100755
--- a/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-a1pms/src/main/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AutomationCompositionElementHandler.java
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.acm.participant.a1pms.handler;
import java.lang.invoke.MethodHandles;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.validation.Validation;
@@ -37,7 +38,11 @@ import org.onap.policy.clamp.acm.participant.a1pms.webclient.AcA1PmsClient;
import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -81,7 +86,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
acA1PmsClient.deleteService(configurationEntity.getPolicyServiceEntities());
configRequestMap.remove(automationCompositionElementId);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed");
+ automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+ "Undeployed");
} else {
LOGGER.warn("Failed to connect with A1PMS. Service configuration is: {}", configurationEntity);
throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE, "Unable to connect with A1PMS");
@@ -107,7 +113,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
configRequestMap.put(element.getId(), configurationEntity);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.DEPLOYED, null, "Deployed");
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
} else {
LOGGER.error("Failed to connect with A1PMS");
throw new A1PolicyServiceException(HttpStatus.SC_SERVICE_UNAVAILABLE,
@@ -121,4 +127,41 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
throw new A1PolicyServiceException(HttpStatus.SC_BAD_REQUEST, "Invalid Configuration", e);
}
}
+
+ @Override
+ public void lock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+ StateChangeResult.NO_ERROR, "Locked");
+ }
+
+ @Override
+ public void unlock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+ StateChangeResult.NO_ERROR, "Unlocked");
+ }
+
+ @Override
+ public void delete(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null,
+ StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Override
+ public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
+ throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Update not supported");
+ }
+
+ @Override
+ public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
+ throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+ }
+
+ @Override
+ public void deprime(UUID compositionId) throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
+ "Deprimed");
+ }
}
diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
index a39076697..77f41cb60 100755
--- a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/handler/AcElementHandlerTest.java
@@ -20,38 +20,35 @@
package org.onap.policy.clamp.acm.participant.a1pms.handler;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.util.List;
import java.util.Map;
+import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.mockito.InjectMocks;
-import org.mockito.Spy;
import org.onap.policy.clamp.acm.participant.a1pms.exception.A1PolicyServiceException;
import org.onap.policy.clamp.acm.participant.a1pms.utils.CommonTestData;
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.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
+import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-@ExtendWith(SpringExtension.class)
class AcElementHandlerTest {
private final AcA1PmsClient acA1PmsClient = mock(AcA1PmsClient.class);
- @InjectMocks
- @Spy
- private AutomationCompositionElementHandler automationCompositionElementHandler =
- new AutomationCompositionElementHandler(acA1PmsClient);
-
private final CommonTestData commonTestData = new CommonTestData();
private static ToscaServiceTemplate serviceTemplate;
@@ -65,57 +62,145 @@ class AcElementHandlerTest {
@BeforeEach
void startMocks() throws A1PolicyServiceException {
- automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.TRUE);
doNothing().when(acA1PmsClient).createService(any());
}
@Test
void test_automationCompositionElementStateChange() throws A1PolicyServiceException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+
var automationCompositionId = commonTestData.getAutomationCompositionId();
var element = commonTestData.getAutomationCompositionElement();
var automationCompositionElementId = element.getId();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- automationCompositionElementHandler.deploy(
- commonTestData.getAutomationCompositionId(), element,
+ automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
+ automationCompositionElementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
- assertDoesNotThrow(() -> automationCompositionElementHandler.undeploy(
- automationCompositionId, automationCompositionElementId));
+ automationCompositionElementHandler.undeploy(automationCompositionId, automationCompositionElementId);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
+ automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
- assertThrows(A1PolicyServiceException.class,
- () -> automationCompositionElementHandler.undeploy(
- automationCompositionId, automationCompositionElementId));
+ assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
+ .undeploy(automationCompositionId, automationCompositionElementId));
}
@Test
- void test_AutomationCompositionElementUpdate() {
+ void test_AutomationCompositionElementUpdate() throws A1PolicyServiceException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
var element = commonTestData.getAutomationCompositionElement();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- assertDoesNotThrow(() -> automationCompositionElementHandler.deploy(
- commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
+ automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
+ nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(
+ commonTestData.getAutomationCompositionId(), element.getId(), DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Deployed");
}
@Test
void test_AutomationCompositionElementUpdateWithUnhealthyA1pms() {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
var element = commonTestData.getAutomationCompositionElement();
when(acA1PmsClient.isPmsHealthy()).thenReturn(Boolean.FALSE);
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
assertThrows(A1PolicyServiceException.class,
- () -> automationCompositionElementHandler.deploy(
- commonTestData.getAutomationCompositionId(), element,
+ () -> automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(A1_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
}
@Test
void test_AutomationCompositionElementUpdateWithInvalidConfiguration() {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ automationCompositionElementHandler.setIntermediaryApi(mock(ParticipantIntermediaryApi.class));
var element = commonTestData.getAutomationCompositionElement();
assertThrows(A1PolicyServiceException.class, () -> automationCompositionElementHandler
.deploy(commonTestData.getAutomationCompositionId(), element, Map.of()));
}
+
+ @Test
+ void testLock() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionId = UUID.randomUUID();
+ var elementId = UUID.randomUUID();
+ automationCompositionElementHandler.lock(automationCompositionId, elementId);
+
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, elementId,
+ null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
+ }
+
+ @Test
+ void testUnlock() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionId = UUID.randomUUID();
+ var elementId = UUID.randomUUID();
+ automationCompositionElementHandler.unlock(automationCompositionId, elementId);
+
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, elementId,
+ null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
+ }
+
+ @Test
+ void testUpdate() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionId = UUID.randomUUID();
+ var element = commonTestData.getAutomationCompositionElement();
+ automationCompositionElementHandler.update(automationCompositionId, element, Map.of());
+
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId,
+ element.getId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Update not supported");
+ }
+
+ @Test
+ void testDelete() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var automationCompositionId = UUID.randomUUID();
+ var elementId = UUID.randomUUID();
+ automationCompositionElementHandler.delete(automationCompositionId, elementId);
+
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(automationCompositionId, elementId,
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Test
+ void testPrime() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var compositionId = UUID.randomUUID();
+ automationCompositionElementHandler.prime(compositionId, List.of());
+
+ verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED,
+ StateChangeResult.NO_ERROR, "Primed");
+ }
+
+ @Test
+ void testDeprime() throws PfModelException {
+ var automationCompositionElementHandler = new AutomationCompositionElementHandler(acA1PmsClient);
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ var compositionId = UUID.randomUUID();
+ automationCompositionElementHandler.deprime(compositionId);
+
+ verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
+ StateChangeResult.NO_ERROR, "Deprimed");
+ }
}
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
index f5fb03054..966aee971 100644
--- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/acm/participant/http/main/handler/AutomationCompositionElementHandler.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.participant.http.main.handler;
import java.io.Closeable;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@@ -41,7 +42,11 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationComposit
import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -78,7 +83,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
@Override
public void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) {
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, automationCompositionElementId,
- DeployState.UNDEPLOYED, null, "");
+ DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "");
}
/**
@@ -100,14 +105,15 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
.collect(Collectors.toList());
if (failedResponseStatus.isEmpty()) {
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.DEPLOYED, null, "Deployed");
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
} else {
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.UNDEPLOYED, null, "Error on Invoking the http request: " + failedResponseStatus);
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
+ "Error on Invoking the http request: " + failedResponseStatus);
}
} catch (AutomationCompositionException e) {
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.UNDEPLOYED, null, e.getMessage());
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, e.getMessage());
}
}
@@ -149,6 +155,43 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
}
}
+ @Override
+ public void lock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+ StateChangeResult.NO_ERROR, "Locked");
+ }
+
+ @Override
+ public void unlock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+ StateChangeResult.NO_ERROR, "Unlocked");
+ }
+
+ @Override
+ public void delete(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null,
+ StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Override
+ public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
+ throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Update not supported");
+ }
+
+ @Override
+ public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
+ throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+ }
+
+ @Override
+ public void deprime(UUID compositionId) throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
+ "Deprimed");
+ }
+
/**
* Closes this stream and releases any system resources associated
* with it. If the stream is already closed then invoking this
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
index b0e05d709..4dca5a58f 100644
--- a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/handler/AcElementHandlerTest.java
@@ -27,7 +27,9 @@ import static org.mockito.Mockito.verify;
import java.io.IOException;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.participant.http.main.handler.AutomationCompositionElementHandler;
import org.onap.policy.clamp.acm.participant.http.main.models.ConfigRequest;
@@ -35,7 +37,10 @@ import org.onap.policy.clamp.acm.participant.http.main.webclient.AcHttpClient;
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.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.models.base.PfModelException;
class AcElementHandlerTest {
@@ -56,7 +61,7 @@ class AcElementHandlerTest {
automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
automationCompositionElementHandler.undeploy(instanceId, acElementId);
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId,
- DeployState.UNDEPLOYED, null, "");
+ DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "");
}
}
@@ -72,7 +77,8 @@ class AcElementHandlerTest {
Map<String, Object> map = new HashMap<>();
automationCompositionElementHandler.deploy(instanceId, element, map);
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.UNDEPLOYED, null, "Constraint violations in the config request");
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
+ "Constraint violations in the config request");
}
}
@@ -89,7 +95,7 @@ class AcElementHandlerTest {
map.put("httpHeaders", 1);
automationCompositionElementHandler.deploy(instanceId, element, map);
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.UNDEPLOYED, null, "Error extracting ConfigRequest ");
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "Error extracting ConfigRequest ");
}
}
@@ -108,7 +114,98 @@ class AcElementHandlerTest {
automationCompositionElementHandler.deploy(instanceId, element, map);
verify(acHttpClient).run(any(ConfigRequest.class), anyMap());
verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, element.getId(),
- DeployState.DEPLOYED, null, "Deployed");
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
+ }
+ }
+
+ @Test
+ void testUpdate() throws Exception {
+ var instanceId = commonTestData.getAutomationCompositionId();
+ var element = commonTestData.getAutomationCompositionElement();
+ var acElementId = element.getId();
+
+ try (var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ automationCompositionElementHandler.update(instanceId, element, Map.of());
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId,
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Update not supported");
+ }
+ }
+
+ @Test
+ void testLock() throws Exception {
+ var instanceId = commonTestData.getAutomationCompositionId();
+ var acElementId = UUID.randomUUID();
+
+ try (var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ automationCompositionElementHandler.lock(instanceId, acElementId);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId, null,
+ LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
+ }
+ }
+
+ @Test
+ void testUnlock() throws Exception {
+ var instanceId = commonTestData.getAutomationCompositionId();
+ var acElementId = UUID.randomUUID();
+
+ try (var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ automationCompositionElementHandler.unlock(instanceId, acElementId);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId, null,
+ LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
+ }
+ }
+
+ @Test
+ void testDelete() throws Exception {
+ var instanceId = commonTestData.getAutomationCompositionId();
+ var acElementId = UUID.randomUUID();
+
+ try (var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+ automationCompositionElementHandler.delete(instanceId, acElementId);
+ verify(participantIntermediaryApi).updateAutomationCompositionElementState(instanceId, acElementId,
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ }
+ }
+
+ @Test
+ void testPrime() throws Exception {
+ var compositionId = UUID.randomUUID();
+
+ try (var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+
+ automationCompositionElementHandler.prime(compositionId, List.of());
+ verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.PRIMED,
+ StateChangeResult.NO_ERROR, "Primed");
+ }
+ }
+
+ @Test
+ void testDeprime() throws Exception {
+ var compositionId = UUID.randomUUID();
+
+ try (var automationCompositionElementHandler =
+ new AutomationCompositionElementHandler(mock(AcHttpClient.class))) {
+ var participantIntermediaryApi = mock(ParticipantIntermediaryApi.class);
+ automationCompositionElementHandler.setIntermediaryApi(participantIntermediaryApi);
+
+ automationCompositionElementHandler.deprime(compositionId);
+ verify(participantIntermediaryApi).updateCompositionState(compositionId, AcTypeState.COMMISSIONED,
+ StateChangeResult.NO_ERROR, "Deprimed");
}
}
}
diff --git a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
index 6fdb16e53..4d556579d 100755
--- a/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-kserve/src/main/java/org/onap/policy/clamp/acm/participant/kserve/handler/AutomationCompositionElementHandler.java
@@ -24,6 +24,7 @@ import io.kubernetes.client.openapi.ApiException;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
@@ -45,7 +46,11 @@ import org.onap.policy.clamp.acm.participant.kserve.k8s.KserveClient;
import org.onap.policy.clamp.acm.participant.kserve.models.ConfigurationEntity;
import org.onap.policy.clamp.acm.participant.kserve.models.KserveInferenceEntity;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -75,7 +80,6 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
@Getter(AccessLevel.PACKAGE)
private final Map<UUID, ConfigurationEntity> configRequestMap = new HashMap<>();
-
private static class ThreadConfig {
private int uninitializedToPassiveTimeout = 60;
@@ -93,7 +97,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
}
configRequestMap.remove(automationCompositionElementId);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed");
+ automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+ "Undeployed");
} catch (IOException | ApiException exception) {
LOGGER.warn("Deletion of Inference service failed", exception);
}
@@ -130,7 +135,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
if (isAllInferenceSvcDeployed) {
configRequestMap.put(element.getId(), configurationEntity);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.DEPLOYED, null, "Deployed");
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
} else {
LOGGER.error("Inference Service deployment failed");
}
@@ -152,19 +157,55 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
* Check the status of Inference Service.
*
* @param inferenceServiceName name of the inference service
- * @param namespace kubernetes namespace
- * @param timeout Inference service time check
- * @param statusCheckInterval Status check time interval
+ * @param namespace kubernetes namespace
+ * @param timeout Inference service time check
+ * @param statusCheckInterval Status check time interval
* @return status of the inference service
- * @throws ExecutionException Exception on execution
+ * @throws ExecutionException Exception on execution
* @throws InterruptedException Exception on inference service status check
*/
public boolean checkInferenceServiceStatus(String inferenceServiceName, String namespace, int timeout,
int statusCheckInterval) throws ExecutionException, InterruptedException {
// Invoke runnable thread to check pod status
- Future<String> result = executor.submit(
- new InferenceServiceValidator(inferenceServiceName, namespace, timeout, statusCheckInterval,
- kserveClient), "Done");
+ Future<String> result = executor.submit(new InferenceServiceValidator(inferenceServiceName, namespace, timeout,
+ statusCheckInterval, kserveClient), "Done");
return (!result.get().isEmpty()) && result.isDone();
}
+
+ @Override
+ public void lock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+ StateChangeResult.NO_ERROR, "Locked");
+ }
+
+ @Override
+ public void unlock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+ StateChangeResult.NO_ERROR, "Unlocked");
+ }
+
+ @Override
+ public void delete(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null,
+ StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Override
+ public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
+ throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Update not supported");
+ }
+
+ @Override
+ public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
+ throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+ }
+
+ @Override
+ public void deprime(UUID compositionId) throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
+ "Deprimed");
+ }
}
diff --git a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
index 63ad3ef14..38db1b8c1 100755
--- a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/handler/AcElementHandlerTest.java
@@ -31,6 +31,8 @@ import static org.mockito.Mockito.mock;
import io.kubernetes.client.openapi.ApiException;
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;
@@ -83,8 +85,8 @@ class AcElementHandlerTest {
@BeforeEach
void startMocks() throws ExecutionException, InterruptedException, IOException, ApiException {
doReturn(true).when(kserveClient).deployInferenceService(any(), any());
- doReturn(true).when(automationCompositionElementHandler)
- .checkInferenceServiceStatus(any(), any(), anyInt(), anyInt());
+ doReturn(true).when(automationCompositionElementHandler).checkInferenceServiceStatus(any(), any(), anyInt(),
+ anyInt());
}
@Test
@@ -93,7 +95,6 @@ class AcElementHandlerTest {
var element = commonTestData.getAutomationCompositionElement();
var automationCompositionElementId = element.getId();
-
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties());
@@ -108,11 +109,9 @@ class AcElementHandlerTest {
var element = commonTestData.getAutomationCompositionElement();
var nodeTemplatesMap = serviceTemplate.getToscaTopologyTemplate().getNodeTemplates();
- assertDoesNotThrow(
- () -> automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(), element,
- nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
- assertThat(automationCompositionElementHandler.getConfigRequestMap()).hasSize(1)
- .containsKey(element.getId());
+ assertDoesNotThrow(() -> automationCompositionElementHandler.deploy(commonTestData.getAutomationCompositionId(),
+ element, nodeTemplatesMap.get(KSERVE_AUTOMATION_COMPOSITION_ELEMENT).getProperties()));
+ assertThat(automationCompositionElementHandler.getConfigRequestMap()).hasSize(1).containsKey(element.getId());
doThrow(new ApiException("Error installing the inference service")).when(kserveClient)
.deployInferenceService(any(), any());
@@ -131,8 +130,40 @@ class AcElementHandlerTest {
doReturn(result).when(executor).submit(any(Runnable.class), any());
doReturn("Done").when(result).get();
doReturn(true).when(result).isDone();
+ assertDoesNotThrow(() -> automationCompositionElementHandler.checkInferenceServiceStatus("sklearn-iris",
+ "kserve-test", 1, 1));
+ }
+
+ @Test
+ void testUpdate() throws PfModelException {
+ var automationCompositionId = commonTestData.getAutomationCompositionId();
+ var element = commonTestData.getAutomationCompositionElement();
assertDoesNotThrow(
- () -> automationCompositionElementHandler.checkInferenceServiceStatus("sklearn-iris", "kserve-test", 1,
- 1));
+ () -> automationCompositionElementHandler.update(automationCompositionId, element, Map.of()));
+ }
+
+ @Test
+ void testLock() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.lock(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testUnlock() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.unlock(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testDelete() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.delete(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testPrime() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.prime(UUID.randomUUID(), List.of()));
+ }
+
+ @Test
+ void testDeprime() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.deprime(UUID.randomUUID()));
}
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
index 2f1abe1c0..95ff1e8c3 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandler.java
@@ -23,6 +23,7 @@ package org.onap.policy.clamp.acm.participant.kubernetes.handler;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@@ -40,7 +41,11 @@ import org.onap.policy.clamp.acm.participant.kubernetes.helm.PodStatusValidator;
import org.onap.policy.clamp.acm.participant.kubernetes.models.ChartInfo;
import org.onap.policy.clamp.acm.participant.kubernetes.service.ChartService;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -93,7 +98,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
try {
chartService.uninstallChart(chart);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed");
+ automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+ "Undeployed");
chartMap.remove(automationCompositionElementId);
podStatusMap.remove(chart.getReleaseName());
} catch (ServiceException se) {
@@ -148,7 +154,44 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
if (!result.get().isEmpty()) {
LOGGER.info("Pod Status Validator Completed: {}", result.isDone());
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, elementId,
- DeployState.DEPLOYED, null, "Deployed");
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
}
}
+
+ @Override
+ public void lock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+ StateChangeResult.NO_ERROR, "Locked");
+ }
+
+ @Override
+ public void unlock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+ StateChangeResult.NO_ERROR, "Unlocked");
+ }
+
+ @Override
+ public void delete(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null,
+ StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Override
+ public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
+ throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Update not supported");
+ }
+
+ @Override
+ public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
+ throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+ }
+
+ @Override
+ public void deprime(UUID compositionId) throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
+ "Deprimed");
+ }
}
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java
index ee0039c3f..d9702abc5 100644
--- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/handler/AutomationCompositionElementHandlerTest.java
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.doThrow;
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;
@@ -157,4 +158,41 @@ class AutomationCompositionElementHandlerTest {
() -> automationCompositionElementHandler.checkPodStatus(automationCompositionId,
element.getId(), chartInfo, 1, 1));
}
+
+ @Test
+ void testUpdate() throws PfModelException {
+ var elementId1 = UUID.randomUUID();
+ var element = new AcElementDeploy();
+ element.setId(elementId1);
+ element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1"));
+ element.setOrderedState(DeployOrder.DEPLOY);
+ var automationCompositionId = commonTestData.getAutomationCompositionId();
+ assertDoesNotThrow(
+ () -> automationCompositionElementHandler.update(automationCompositionId, element, Map.of()));
+ }
+
+ @Test
+ void testLock() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.lock(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testUnlock() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.unlock(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testDelete() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.delete(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testPrime() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.prime(UUID.randomUUID(), List.of()));
+ }
+
+ @Test
+ void testDeprime() throws PfModelException {
+ assertDoesNotThrow(() -> automationCompositionElementHandler.deprime(UUID.randomUUID()));
+ }
}
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
index 5eb997e52..0b8ffe2a3 100644
--- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
+++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandler.java
@@ -23,10 +23,10 @@
package org.onap.policy.clamp.acm.participant.policy.main.handler;
import java.util.ArrayList;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
import javax.ws.rs.core.Response.Status;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@@ -36,7 +36,11 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantInterme
import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient;
import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -54,7 +58,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandler.class);
- private final Map<UUID, ToscaServiceTemplate> serviceTemplateMap = new LinkedHashMap<>();
+ private final Map<UUID, ToscaServiceTemplate> serviceTemplateMap = new ConcurrentHashMap<>();
private final PolicyApiHttpClient apiHttpClient;
private final PolicyPapHttpClient papHttpClient;
@@ -74,7 +78,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
if (automationCompositionDefinition == null) {
LOGGER.debug("No policies to undeploy to {}", automationCompositionElementId);
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed");
+ automationCompositionElementId, DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR,
+ "Undeployed");
return;
}
var policyList = getPolicyList(automationCompositionDefinition);
@@ -82,8 +87,8 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
var policyTypeList = getPolicyTypeList(automationCompositionDefinition);
deletePolicyData(policyTypeList, policyList);
serviceTemplateMap.remove(automationCompositionElementId);
- intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.UNDEPLOYED, null, "Undeployed");
+ intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, automationCompositionElementId,
+ DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
}
private void deletePolicyData(List<ToscaConceptIdentifier> policyTypeList,
@@ -119,7 +124,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
intermediaryApi.sendAcElementInfo(automationCompositionId, automationCompositionElementId, "IDLE",
"ENABLED", Map.of());
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId,
- automationCompositionElementId, DeployState.DEPLOYED, null, "Deployed");
+ automationCompositionElementId, DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
} else {
throw new PfModelException(Status.BAD_REQUEST, "Deploy of Policy failed.");
}
@@ -155,7 +160,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
var automationCompositionDefinition = element.getToscaServiceTemplateFragment();
if (automationCompositionDefinition.getToscaTopologyTemplate() == null) {
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.UNDEPLOYED, null, "ToscaTopologyTemplate not defined");
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "ToscaTopologyTemplate not defined");
return;
}
serviceTemplateMap.put(element.getId(), automationCompositionDefinition);
@@ -177,7 +182,7 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
deployPolicies(policyList, automationCompositionId, element.getId());
} else {
intermediaryApi.updateAutomationCompositionElementState(automationCompositionId, element.getId(),
- DeployState.UNDEPLOYED, null,
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
"Creation of PolicyTypes/Policies failed. Policies will not be deployed.");
}
}
@@ -205,4 +210,41 @@ public class AutomationCompositionElementHandler implements AutomationCompositio
return policyList;
}
+
+ @Override
+ public void lock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED,
+ StateChangeResult.NO_ERROR, "Locked");
+ }
+
+ @Override
+ public void unlock(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED,
+ StateChangeResult.NO_ERROR, "Unlocked");
+ }
+
+ @Override
+ public void delete(UUID instanceId, UUID elementId) throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null,
+ StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Override
+ public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
+ throws PfModelException {
+ intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null,
+ StateChangeResult.NO_ERROR, "Update not supported");
+ }
+
+ @Override
+ public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
+ throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+ }
+
+ @Override
+ public void deprime(UUID compositionId) throws PfModelException {
+ intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
+ "Deprimed");
+ }
}
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
index 4cf5a5847..ec55c178f 100644
--- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
+++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/handler/AutomationCompositionElementHandlerTest.java
@@ -35,7 +35,10 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantInterme
import org.onap.policy.clamp.acm.participant.policy.client.PolicyApiHttpClient;
import org.onap.policy.clamp.acm.participant.policy.client.PolicyPapHttpClient;
import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -61,7 +64,7 @@ class AutomationCompositionElementHandlerTest {
handler.undeploy(AC_ID, automationCompositionElementId);
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
- DeployState.UNDEPLOYED, null, "Undeployed");
+ DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
}
private AcElementDeploy getTestingAcElement() {
@@ -93,11 +96,11 @@ class AutomationCompositionElementHandlerTest {
handler.deploy(AC_ID, getTestingAcElement(), Map.of());
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
- DeployState.DEPLOYED, null, "Deployed");
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Deployed");
handler.undeploy(AC_ID, automationCompositionElementId);
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
- DeployState.UNDEPLOYED, null, "Undeployed");
+ DeployState.UNDEPLOYED, null, StateChangeResult.NO_ERROR, "Undeployed");
}
@Test
@@ -111,7 +114,7 @@ class AutomationCompositionElementHandlerTest {
acElement.getToscaServiceTemplateFragment().setToscaTopologyTemplate(null);
handler.deploy(AC_ID, acElement, Map.of());
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
- DeployState.UNDEPLOYED, null, "ToscaTopologyTemplate not defined");
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, "ToscaTopologyTemplate not defined");
}
@Test
@@ -131,7 +134,7 @@ class AutomationCompositionElementHandlerTest {
// Mock failure in policy type creation
handler.deploy(AC_ID, element, Map.of());
verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
- DeployState.UNDEPLOYED, null,
+ DeployState.UNDEPLOYED, null, StateChangeResult.FAILED,
"Creation of PolicyTypes/Policies failed. Policies will not be deployed.");
}
@@ -151,4 +154,77 @@ class AutomationCompositionElementHandlerTest {
assertThatThrownBy(() -> handler.deploy(AC_ID, element, Map.of()))
.hasMessageMatching("Deploy of Policy failed.");
}
+
+ @Test
+ void testUpdate() throws Exception {
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class));
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ handler.setIntermediaryApi(intermediaryApi);
+
+ var acElement = getTestingAcElement();
+ acElement.getToscaServiceTemplateFragment().setToscaTopologyTemplate(null);
+ handler.update(AC_ID, acElement, Map.of());
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
+ DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Update not supported");
+ }
+
+ @Test
+ void testLock() throws Exception {
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class));
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ handler.setIntermediaryApi(intermediaryApi);
+
+ handler.lock(AC_ID, automationCompositionElementId);
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId, null,
+ LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
+ }
+
+ @Test
+ void testUnlock() throws Exception {
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class));
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ handler.setIntermediaryApi(intermediaryApi);
+
+ handler.unlock(AC_ID, automationCompositionElementId);
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId, null,
+ LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
+ }
+
+ @Test
+ void testDelete() throws Exception {
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class));
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ handler.setIntermediaryApi(intermediaryApi);
+
+ handler.delete(AC_ID, automationCompositionElementId);
+ verify(intermediaryApi).updateAutomationCompositionElementState(AC_ID, automationCompositionElementId,
+ DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
+ }
+
+ @Test
+ void testPrime() throws Exception {
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class));
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ handler.setIntermediaryApi(intermediaryApi);
+
+ handler.prime(AC_ID, List.of());
+ verify(intermediaryApi).updateCompositionState(AC_ID, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed");
+ }
+
+ @Test
+ void testDeprime() throws Exception {
+ var handler = new AutomationCompositionElementHandler(mock(PolicyApiHttpClient.class),
+ mock(PolicyPapHttpClient.class));
+ var intermediaryApi = mock(ParticipantIntermediaryApi.class);
+ handler.setIntermediaryApi(intermediaryApi);
+
+ handler.deprime(AC_ID);
+ verify(intermediaryApi).updateCompositionState(AC_ID, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR,
+ "Deprimed");
+ }
}