Merge pull request #276 from bsinno/fix_remove_unnecessary_save

Removed unnecessary target info startus persistence.
This commit is contained in:
Kai Zimmermann
2016-08-24 09:05:26 +02:00
committed by GitHub
5 changed files with 49 additions and 50 deletions

View File

@@ -243,12 +243,16 @@ public class AmqpConfiguration {
/**
* Create amqp handler service bean.
*
* @param amqpMessageDispatcherService
* to sending events to DMF client
*
* @return handler service bean
*/
@Bean
public AmqpMessageHandlerService amqpMessageHandlerService() {
return new AmqpMessageHandlerService(rabbitTemplate());
public AmqpMessageHandlerService amqpMessageHandlerService(
final AmqpMessageDispatcherService amqpMessageDispatcherService) {
return new AmqpMessageHandlerService(rabbitTemplate(), amqpMessageDispatcherService);
}
/**

View File

@@ -74,8 +74,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.context.SecurityContextImpl;
import org.springframework.web.util.UriComponentsBuilder;
import com.google.common.eventbus.EventBus;
/**
*
* {@link AmqpMessageHandlerService} handles all incoming AMQP messages for the
@@ -86,6 +84,8 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
private static final Logger LOG = LoggerFactory.getLogger(AmqpMessageHandlerService.class);
private final AmqpMessageDispatcherService amqpMessageDispatcherService;
@Autowired
private ControllerManagement controllerManagement;
@@ -95,9 +95,6 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
@Autowired
private ArtifactManagement artifactManagement;
@Autowired
private EventBus eventBus;
@Autowired
@Qualifier(CacheConstants.DOWNLOAD_ID_CACHE)
private Cache cache;
@@ -116,9 +113,13 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
*
* @param defaultTemplate
* the configured amqp template.
* @param amqpMessageDispatcherService
* to sending events to DMF client
*/
public AmqpMessageHandlerService(final RabbitTemplate defaultTemplate) {
public AmqpMessageHandlerService(final RabbitTemplate defaultTemplate,
final AmqpMessageDispatcherService amqpMessageDispatcherService) {
super(defaultTemplate);
this.amqpMessageDispatcherService = amqpMessageDispatcherService;
}
/**
@@ -353,9 +354,9 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
final List<SoftwareModule> softwareModuleList = controllerManagement
.findSoftwareModulesByDistributionSet(distributionSet);
final String targetSecurityToken = systemSecurityContext.runAsSystem(() -> target.getSecurityToken());
eventBus.post(new TargetAssignDistributionSetEvent(target.getOptLockRevision(), target.getTenant(),
target.getControllerId(), action.getId(), softwareModuleList, target.getTargetInfo().getAddress(),
targetSecurityToken));
amqpMessageDispatcherService.targetAssignDistributionSet(new TargetAssignDistributionSetEvent(
target.getOptLockRevision(), target.getTenant(), target.getControllerId(), action.getId(),
softwareModuleList, target.getTargetInfo().getAddress(), targetSecurityToken));
}
@@ -386,6 +387,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
final Action action = checkActionExist(message, actionUpdateStatus);
final ActionStatus actionStatus = createActionStatus(message, actionUpdateStatus, action);
updateLastPollTime(action.getTarget());
switch (actionUpdateStatus.getActionStatus()) {
case DOWNLOAD:
@@ -423,6 +425,10 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
}
}
private void updateLastPollTime(final Target target) {
controllerManagement.updateTargetStatus(target.getTargetInfo(), null, System.currentTimeMillis(), null);
}
private ActionStatus createActionStatus(final Message message, final ActionUpdateStatus actionUpdateStatus,
final Action action) {
final ActionStatus actionStatus = entityFactory.generateActionStatus();
@@ -509,10 +515,6 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
this.cache = cache;
}
void setEventBus(final EventBus eventBus) {
this.eventBus = eventBus;
}
void setEntityFactory(final EntityFactory entityFactory) {
this.entityFactory = entityFactory;
}

View File

@@ -74,7 +74,8 @@ public class AmqpControllerAuthenticationTest {
messageConverter = new Jackson2JsonMessageConverter();
final RabbitTemplate rabbitTemplate = mock(RabbitTemplate.class);
when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate);
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate,
mock(AmqpMessageDispatcherService.class));
authenticationManager = new AmqpControllerAuthentfication();
authenticationManager.setControllerManagement(mock(ControllerManagement.class));

View File

@@ -51,6 +51,7 @@ import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.LocalArtifact;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.TargetInfo;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
import org.eclipse.hawkbit.security.SystemSecurityContext;
import org.junit.Before;
@@ -69,8 +70,6 @@ import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.cache.Cache;
import org.springframework.http.HttpStatus;
import com.google.common.eventbus.EventBus;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@@ -86,6 +85,9 @@ public class AmqpMessageHandlerServiceTest {
private MessageConverter messageConverter;
@Mock
private AmqpMessageDispatcherService amqpMessageDispatcherServiceMock;
@Mock
private ControllerManagement controllerManagementMock;
@@ -107,9 +109,6 @@ public class AmqpMessageHandlerServiceTest {
@Mock
private HostnameResolver hostnameResolverMock;
@Mock
private EventBus eventBus;
@Mock
private RabbitTemplate rabbitTemplate;
@@ -120,13 +119,12 @@ public class AmqpMessageHandlerServiceTest {
public void before() throws Exception {
messageConverter = new Jackson2JsonMessageConverter();
when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter);
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate);
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate, amqpMessageDispatcherServiceMock);
amqpMessageHandlerService.setControllerManagement(controllerManagementMock);
amqpMessageHandlerService.setAuthenticationManager(authenticationManagerMock);
amqpMessageHandlerService.setArtifactManagement(artifactManagementMock);
amqpMessageHandlerService.setCache(cacheMock);
amqpMessageHandlerService.setHostnameResolver(hostnameResolverMock);
amqpMessageHandlerService.setEventBus(eventBus);
amqpMessageHandlerService.setEntityFactory(entityFactoryMock);
amqpMessageHandlerService.setSystemSecurityContext(systemSecurityContextMock);
@@ -134,7 +132,7 @@ public class AmqpMessageHandlerServiceTest {
@Test
@Description("Tests not allowed content-type in message")
public void testWrongContentType() {
public void wrongContentType() {
final MessageProperties messageProperties = new MessageProperties();
messageProperties.setContentType("xml");
final Message message = new Message(new byte[0], messageProperties);
@@ -147,7 +145,7 @@ public class AmqpMessageHandlerServiceTest {
@Test
@Description("Tests the creation of a target/thing by calling the same method that incoming RabbitMQ messages would access.")
public void testCreateThing() {
public void createThing() {
final String knownThingId = "1";
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED);
messageProperties.setHeader(MessageHeaderKey.THING_ID, "1");
@@ -168,7 +166,7 @@ public class AmqpMessageHandlerServiceTest {
@Test
@Description("Tests the creation of a thing without a 'reply to' header in message.")
public void testCreateThingWitoutReplyTo() {
public void createThingWitoutReplyTo() {
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED, null);
messageProperties.setHeader(MessageHeaderKey.THING_ID, "1");
final Message message = messageConverter.toMessage("", messageProperties);
@@ -184,7 +182,7 @@ public class AmqpMessageHandlerServiceTest {
@Test
@Description("Tests the creation of a target/thing without a thingID by calling the same method that incoming RabbitMQ messages would access.")
public void testCreateThingWithoutID() {
public void createThingWithoutID() {
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED);
final Message message = messageConverter.toMessage(new byte[0], messageProperties);
try {
@@ -197,7 +195,7 @@ public class AmqpMessageHandlerServiceTest {
@Test
@Description("Tests the call of the same method that incoming RabbitMQ messages would access with an unknown message type.")
public void testUnknownMessageType() {
public void unknownMessageType() {
final String type = "bumlux";
final MessageProperties messageProperties = createMessageProperties(MessageType.THING_CREATED);
messageProperties.setHeader(MessageHeaderKey.THING_ID, "");
@@ -213,7 +211,7 @@ public class AmqpMessageHandlerServiceTest {
@Test
@Description("Tests a invalid message without event topic")
public void testInvalidEventTopic() {
public void invalidEventTopic() {
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
final Message message = new Message(new byte[0], messageProperties);
try {
@@ -241,7 +239,7 @@ public class AmqpMessageHandlerServiceTest {
@Test
@Description("Tests the update of an action of a target without a exist action id")
public void testUpdateActionStatusWithoutActionId() {
public void updateActionStatusWithoutActionId() {
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
final ActionUpdateStatus actionUpdateStatus = new ActionUpdateStatus();
@@ -259,7 +257,7 @@ public class AmqpMessageHandlerServiceTest {
@Test
@Description("Tests the update of an action of a target without a exist action id")
public void testUpdateActionStatusWithoutExistActionId() {
public void updateActionStatusWithoutExistActionId() {
final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT);
messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name());
final ActionUpdateStatus actionUpdateStatus = createActionUpdateStatus(ActionStatus.DOWNLOAD);
@@ -384,9 +382,13 @@ public class AmqpMessageHandlerServiceTest {
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, "vHost");
// verify
verify(controllerManagementMock).updateTargetStatus(Matchers.any(TargetInfo.class),
Matchers.isNull(TargetUpdateStatus.class), Matchers.isNotNull(Long.class), Matchers.isNull(URI.class));
final ArgumentCaptor<TargetAssignDistributionSetEvent> captorTargetAssignDistributionSetEvent = ArgumentCaptor
.forClass(TargetAssignDistributionSetEvent.class);
verify(eventBus, times(1)).post(captorTargetAssignDistributionSetEvent.capture());
verify(amqpMessageDispatcherServiceMock, times(1))
.targetAssignDistributionSet(captorTargetAssignDistributionSetEvent.capture());
final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = captorTargetAssignDistributionSetEvent
.getValue();

View File

@@ -299,8 +299,6 @@ public class JpaControllerManagement implements ControllerManagement {
case CANCELED:
case WARNING:
case RUNNING:
handleIntermediateFeedback(mergedAction, mergedTarget);
break;
default:
break;
}
@@ -312,16 +310,6 @@ public class JpaControllerManagement implements ControllerManagement {
return actionRepository.save(mergedAction);
}
private void handleIntermediateFeedback(final JpaAction mergedAction, final JpaTarget mergedTarget) {
// we change the target state only if the action is still running
// otherwise this is considered as late feedback that does not have
// an impact on the state anymore.
if (mergedAction.isActive()) {
DeploymentHelper.updateTargetInfo(mergedTarget, TargetUpdateStatus.PENDING, false, targetInfoRepository,
entityManager);
}
}
private void handleErrorOnAction(final JpaAction mergedAction, final JpaTarget mergedTarget) {
mergedAction.setActive(false);
mergedAction.setStatus(Status.ERROR);
@@ -349,15 +337,17 @@ public class JpaControllerManagement implements ControllerManagement {
action.setStatus(Status.FINISHED);
final JpaTargetInfo targetInfo = (JpaTargetInfo) target.getTargetInfo();
final JpaDistributionSet ds = (JpaDistributionSet) entityManager.merge(action.getDistributionSet());
targetInfo.setInstalledDistributionSet(ds);
if (target.getAssignedDistributionSet() != null && targetInfo.getInstalledDistributionSet() != null && target
.getAssignedDistributionSet().getId().equals(targetInfo.getInstalledDistributionSet().getId())) {
targetInfo.setInstallationDate(System.currentTimeMillis());
// check if the assigned set is equal to the installed set (not
// necessarily the case as another update might be pending already).
if (target.getAssignedDistributionSet() != null && target.getAssignedDistributionSet().getId()
.equals(targetInfo.getInstalledDistributionSet().getId())) {
targetInfo.setUpdateStatus(TargetUpdateStatus.IN_SYNC);
targetInfo.setInstallationDate(System.currentTimeMillis());
} else {
targetInfo.setUpdateStatus(TargetUpdateStatus.PENDING);
targetInfo.setInstallationDate(System.currentTimeMillis());
}
targetInfoRepository.save(targetInfo);
entityManager.detach(ds);
}