/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021,2023 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.clamp.acm.participant.intermediary.parameters.ParticipantParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
/**
private static final Logger LOGGER = LoggerFactory.getLogger(MessageSender.class);
private final ParticipantHandler participantHandler;
- private ScheduledExecutorService timerPool;
+ private final ScheduledExecutorService timerPool;
+ private final long interval;
/**
* Constructor, set the publisher.
// Kick off the timer
timerPool = makeTimerPool();
- var interval = parameters.getIntermediaryParameters().getReportingTimeIntervalMs();
+ interval = parameters.getIntermediaryParameters().getReportingTimeIntervalMs();
+ }
+
+ @EventListener
+ public void handleContextRefreshEvent(ContextRefreshedEvent ctxRefreshedEvent) {
timerPool.scheduleAtFixedRate(this, interval, interval, TimeUnit.MILLISECONDS);
}
import io.micrometer.core.annotation.Timed;
import java.util.List;
import javax.ws.rs.core.Response.Status;
+import lombok.Getter;
import org.onap.policy.clamp.acm.participant.intermediary.handler.Publisher;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck;
private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantMessagePublisher.class);
private static final String NOT_ACTIVE_TEXT = "Not Active!";
+ @Getter
private boolean active = false;
private TopicSinkClient topicSinkClient;
* Dispatch a heartbeat for this participant.
*/
public void sendHeartbeat() {
- publisher.sendHeartbeat(makeHeartbeat(false));
+ if (publisher.isActive()) {
+ publisher.sendHeartbeat(makeHeartbeat(false));
+ }
}
/**
var participantHandler = mock(ParticipantHandler.class);
var participantParameters = CommonTestData.getParticipantParameters();
var messageSender = new MessageSender(participantHandler, participantParameters);
+ messageSender.handleContextRefreshEvent(null);
messageSender.run();
assertFalse(messageSender.makeTimerPool().isTerminated());
messageSender.close();
}
-
}
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
when(cacheProvider.getAutomationCompositions()).thenReturn(CommonTestData.getTestAutomationCompositionMap());
var publisher = mock(ParticipantMessagePublisher.class);
+ when(publisher.isActive()).thenReturn(true);
var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
mock(AutomationCompositionOutHandler.class), publisher, cacheProvider);
participantHandler.sendHeartbeat();
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.NodeTemplateState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
"Automation composition state is still " + automationComposition.getDeployState());
}
+ if (DeployState.DELETING.equals(automationComposition.getDeployState())
+ && StateChangeResult.NO_ERROR.equals(automationComposition.getStateChangeResult())) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ "Automation composition state is still " + automationComposition.getDeployState());
+ }
if (automationComposition.getRestarting() != null) {
throw new PfModelRuntimeException(Status.BAD_REQUEST, "There is a restarting process, Delete not allowed");
}
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
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.AcInstanceStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
void testInstantiationDelete() {
var automationComposition =
InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Delete");
-
+ automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
var acProvider = mock(AutomationCompositionProvider.class);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var supervisionAcHandler = mock(SupervisionAcHandler.class);
assertThatDeleteThrownBy(automationComposition, DeployState.DEPLOYED, LockState.LOCKED);
assertThatDeleteThrownBy(automationComposition, DeployState.DEPLOYING, LockState.NONE);
assertThatDeleteThrownBy(automationComposition, DeployState.UNDEPLOYING, LockState.LOCKED);
+ assertThatDeleteThrownBy(automationComposition, DeployState.DELETING, LockState.NONE);
automationComposition.setDeployState(DeployState.UNDEPLOYED);
automationComposition.setLockState(LockState.NONE);