@NonNull
private ParticipantState participantState = ParticipantState.ON_LINE;
+ // last time ACM-R has received a status message from participant replica
@NonNull
private String lastMsg;
return result.toAuthorative();
}
- /**
- * Updates an existing participant.
- *
- * @param participant participant to update
- * @return the participant updated
- */
- public Participant updateParticipant(@NonNull final Participant participant) {
- var result = participantRepository
- .save(ProviderUtils.getJpaAndValidate(participant, JpaParticipant::new, "participant"));
-
- // Return the saved participant
- return result.toAuthorative();
- }
-
/**
* Delete a participant.
*
-public class ParticipantSyncTest {
+class ParticipantSyncTest {
@Test
void testCopyConstructor() throws CoderException {
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
-import org.onap.policy.clamp.models.acm.utils.TimestampHelper;
class JpaParticipantReplicaTest {
assertThat(savedParticipant).usingRecursiveComparison().isEqualTo(inputParticipants.get(0));
}
- @Test
- void testParticipantUpdate() {
- var participantRepository = mock(ParticipantRepository.class);
- var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
- var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
-
- var participantProvider = new ParticipantProvider(participantRepository,
- automationCompositionElementRepository, nodeTemplateStateRepository,
- mock(ParticipantReplicaRepository.class));
-
- assertThatThrownBy(() -> participantProvider.updateParticipant(null)).hasMessageMatching(LIST_IS_NULL);
-
- when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0));
-
- var updatedParticipant = participantProvider.updateParticipant(inputParticipants.get(0));
- updatedParticipant.setParticipantId(inputParticipants.get(0).getParticipantId());
- assertThat(updatedParticipant).usingRecursiveComparison().isEqualTo(inputParticipants.get(0));
- }
-
@Test
void testGetAutomationCompositions() {
var participantRepository = mock(ParticipantRepository.class);
assertThrows(NullPointerException.class, () -> participantProvider.getParticipantById(null));
assertThrows(NullPointerException.class, () -> participantProvider.findParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.saveParticipant(null));
- assertThrows(NullPointerException.class, () -> participantProvider.updateParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null));
assertThrows(NullPointerException.class, () -> participantProvider.getAutomationCompositionElements(null));
assertThrows(NullPointerException.class, () -> participantProvider.getAcNodeTemplateStates(null));
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021,2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
var response = RestUtils.toSimpleResponse(ex);
- assertThat(response.getStatusCodeValue()).isEqualTo(STATUS_ERROR.getStatusCode());
+ assertThat(response.getStatusCode().value()).isEqualTo(STATUS_ERROR.getStatusCode());
assertThat(response.getBody()).isNotNull();
assertThat(response.getBody().getErrorDetails()).isEqualTo(MESSAGE_ERROR);
}
void testNow() {
assertThat(TimestampHelper.nowTimestamp()).isNotNull();
assertThat(TimestampHelper.now()).isNotNull();
- assertThat(TimestampHelper.nowEpochMilli()).isNotNull();
+ assertThat(TimestampHelper.nowEpochMilli()).isNotZero();
}
@Test
package org.onap.policy.clamp.acm.participant.intermediary.api;
-import java.util.List;
import java.util.Map;
import java.util.UUID;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
public record CompositionDto(UUID compositionId,
import java.util.Map;
import java.util.UUID;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
-import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
public record InstanceElementDto(UUID instanceId, UUID elementId, ToscaServiceTemplate toscaServiceTemplateFragment,
import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus;
import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatusReq;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
-import org.onap.policy.common.utils.coder.CoderException;
class ParticipantCommTest {
@Test
- void participantListenerTest() throws CoderException {
+ void participantListenerTest() {
var participantHandler = mock(ParticipantHandler.class);
var participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler);
}
@Test
- void messageSenderTest() throws CoderException {
+ void messageSenderTest() {
var participantHandler = mock(ParticipantHandler.class);
var participantParameters = CommonTestData.getParticipantParameters();
var messageSender = new MessageSender(participantHandler, participantParameters);
import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRestart;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-public class AcDefinitionHandlerTest {
+class AcDefinitionHandlerTest {
@Test
void handleComposiotPrimeTest() {
import java.util.List;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantStatusReqListener;
-import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantSyncListener;
import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatusReq;
-import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantSync;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
package org.onap.policy.clamp.acm.runtime.config.messaging;
-import java.util.List;
-import org.onap.policy.clamp.acm.runtime.main.parameters.Topics;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
/**
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@Override
public ResponseEntity<ParticipantInformation> getParticipant(UUID participantId, UUID requestId) {
- ParticipantInformation participantInformation = acmParticipantProvider
- .getParticipantById(participantId);
+ var participantInformation = acmParticipantProvider.getParticipantById(participantId);
return ResponseEntity.ok().body(participantInformation);
}
@Override
public ResponseEntity<List<ParticipantInformation>> queryParticipants(String name, String version,
UUID requestId) {
- List<ParticipantInformation> participantInformationList = acmParticipantProvider.getAllParticipants();
+ var participantInformationList = acmParticipantProvider.getAllParticipants();
return ResponseEntity.ok().body(participantInformationList);
}
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
LOGGER.debug("Requesting Participant Status Now ParticipantStatusReq");
participantStatusReqPublisher.send(participantId);
participant.setParticipantState(ParticipantState.OFF_LINE);
- participantProvider.updateParticipant(participant);
+ participantProvider.saveParticipant(participant);
}
/**
if ((now - lastMsg) > maxWaitMs) {
LOGGER.debug("report Participant OFF_LINE {}", id);
participant.setParticipantState(ParticipantState.OFF_LINE);
- participantProvider.updateParticipant(participant);
+ participantProvider.saveParticipant(participant);
}
}
}
if (participantOpt.isPresent()) {
var participant = participantOpt.get();
participant.setParticipantState(ParticipantState.OFF_LINE);
- participantProvider.updateParticipant(participant);
+ participantProvider.saveParticipant(participant);
}
participantDeregisterAckPublisher.send(participantDeregisterMsg.getMessageId());
package org.onap.policy.clamp.acm.runtime.supervision.comm;
import jakarta.ws.rs.core.Response.Status;
-import java.util.List;
-import java.util.Optional;
import org.onap.policy.clamp.acm.runtime.config.messaging.Publisher;
-import org.onap.policy.clamp.acm.runtime.main.parameters.Topics;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantAckMessage;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
package org.onap.policy.clamp.acm.runtime.supervision.comm;
import jakarta.ws.rs.core.Response.Status;
-import java.util.List;
-import java.util.Optional;
import org.onap.policy.clamp.acm.runtime.config.messaging.Publisher;
-import org.onap.policy.clamp.acm.runtime.main.parameters.Topics;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessage;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 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 org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023-2024 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 org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfModelException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
@Test
void testQueryParticipant() {
participantProvider.saveParticipant(inputParticipants.get(0));
- UUID participantId = participantProvider.getParticipants().get(0).getParticipantId();
+ var participantId = participantProvider.getParticipants().get(0).getParticipantId();
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + participantId);
- var response = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
- var entityList = response.readEntity(ParticipantInformation.class);
- assertNotNull(entityList);
+ try (var response = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ var entityList = response.readEntity(ParticipantInformation.class);
+ assertNotNull(entityList);
+ }
}
@Test
void testBadQueryParticipant() {
participantProvider.saveParticipant(inputParticipants.get(0));
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + UUID.randomUUID());
- var response = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ try (var response = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
}
@Test
void getAllParticipants() {
- inputParticipants.forEach(p -> {
- participantProvider.saveParticipant(p);
- });
+ inputParticipants.forEach(p -> participantProvider.saveParticipant(p));
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT);
- var response = invocationBuilder.buildGet().invoke();
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
- List<ParticipantInformation> entityList = response.readEntity(new GenericType<>() {});
- assertThat(entityList).isNotEmpty();
- var participantIds = entityList.stream().map(ParticipantInformation::getParticipant)
- .map(Participant::getParticipantId).collect(Collectors.toSet());
- inputParticipants.forEach(p -> {
- assertThat(participantIds).contains(p.getParticipantId());
- });
+ try (var response = invocationBuilder.buildGet().invoke()) {
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ List<ParticipantInformation> entityList = response.readEntity(new GenericType<>() {});
+ assertThat(entityList).isNotEmpty();
+ var participantIds =
+ entityList.stream().map(ParticipantInformation::getParticipant).map(Participant::getParticipantId)
+ .collect(Collectors.toSet());
+ inputParticipants.forEach(p -> assertThat(participantIds).contains(p.getParticipantId()));
+ }
}
@Test
- void testOrderParticipantReport() throws PfModelException {
+ void testOrderParticipantReport() {
participantProvider.saveParticipant(inputParticipants.get(0));
- UUID participantId = participantProvider.getParticipants().get(0).getParticipantId();
+ var participantId = participantProvider.getParticipants().get(0).getParticipantId();
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT
+ "/"
+ participantId);
- var response = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
- +
- "", MediaType.APPLICATION_JSON));
- assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
+ try (var response = invocationBuilder.header("Content-Length", 0)
+ .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
+ }
}
@Test
- void testBadOrderParticipantReport() throws PfModelException {
+ void testBadOrderParticipantReport() {
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT
+ "/"
+ UUID.randomUUID());
- var response = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
- +
- "", MediaType.APPLICATION_JSON));
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ try (var response = invocationBuilder.header("Content-Length", 0)
+ .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
+ }
}
@Test
participantProvider.saveParticipant(p);
});
var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT);
- var response = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
- +
- "", MediaType.APPLICATION_JSON));
- assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
+ try (var response = invocationBuilder.header("Content-Length", 0)
+ .put(Entity.entity("", MediaType.APPLICATION_JSON))) {
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
+ }
}
}
handler.handleParticipantMessage(participantDeregisterMessage);
- verify(participantProvider).updateParticipant(any());
+ verify(participantProvider).saveParticipant(any());
verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId());
}
participant.setParticipantState(ParticipantState.OFF_LINE);
supervisionScanner.run();
- verify(participantProvider, times(0)).updateParticipant(any());
+ verify(participantProvider, times(0)).saveParticipant(any());
participant.setParticipantState(ParticipantState.ON_LINE);
supervisionScanner.run();
- verify(participantProvider, times(1)).updateParticipant(any());
+ verify(participantProvider, times(1)).saveParticipant(any());
}
}
import static org.mockito.Mockito.when;
import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
-import org.onap.policy.clamp.acm.runtime.main.parameters.Topics;
import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler;
acDeregisterAckPublisher.stop();
}
+ @Test
void testSendParticipantDeregisterAckNoActive() {
var acDeregisterAckPublisher = new ParticipantDeregisterAckPublisher();
assertThatThrownBy(() -> acDeregisterAckPublisher.send(new ParticipantDeregisterAck()))