Remove Rollout(Group) builders (#2603)
* Fix entityManager.merge for ds and sm Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> * Remove Rollout(Group) builders Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> * Remove EntityFactory Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com> --------- Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -39,14 +39,14 @@ import org.eclipse.hawkbit.dmf.json.model.DmfUpdateMode;
|
||||
import org.eclipse.hawkbit.im.authentication.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.ConfirmationManagement;
|
||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.UpdateMode;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionStatusCreate.ActionStatusCreateBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionProperties;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
@@ -81,7 +81,6 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
|
||||
private final AmqpMessageDispatcherService amqpMessageDispatcherService;
|
||||
private final ConfirmationManagement confirmationManagement;
|
||||
private final EntityFactory entityFactory;
|
||||
private final TenantConfigurationManagement tenantConfigurationManagement;
|
||||
private final SystemSecurityContext systemSecurityContext;
|
||||
private ControllerManagement controllerManagement;
|
||||
@@ -92,7 +91,6 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
* @param rabbitTemplate for converting messages
|
||||
* @param amqpMessageDispatcherService to sending events to DMF client
|
||||
* @param controllerManagement for target repo access
|
||||
* @param entityFactory to create entities
|
||||
* @param systemSecurityContext the system Security Context
|
||||
* @param tenantConfigurationManagement the tenant configuration Management
|
||||
* @param confirmationManagement the confirmation management
|
||||
@@ -100,13 +98,11 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
public AmqpMessageHandlerService(
|
||||
final RabbitTemplate rabbitTemplate,
|
||||
final AmqpMessageDispatcherService amqpMessageDispatcherService,
|
||||
final ControllerManagement controllerManagement, final EntityFactory entityFactory,
|
||||
final SystemSecurityContext systemSecurityContext,
|
||||
final ControllerManagement controllerManagement, final SystemSecurityContext systemSecurityContext,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement, final ConfirmationManagement confirmationManagement) {
|
||||
super(rabbitTemplate);
|
||||
this.amqpMessageDispatcherService = amqpMessageDispatcherService;
|
||||
this.controllerManagement = controllerManagement;
|
||||
this.entityFactory = entityFactory;
|
||||
this.systemSecurityContext = systemSecurityContext;
|
||||
this.tenantConfigurationManagement = tenantConfigurationManagement;
|
||||
this.confirmationManagement = confirmationManagement;
|
||||
@@ -459,14 +455,15 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
} else if (actionUpdateStatus.getActionStatus() == DmfActionStatus.DENIED) {
|
||||
updatedAction = confirmationManagement.denyAction(action.getId(), actionUpdateStatus.getCode(), messages);
|
||||
} else {
|
||||
final ActionStatusCreate actionStatus = entityFactory.actionStatus().create(action.getId()).status(status).messages(messages);
|
||||
final ActionStatusCreateBuilder actionStatus = ActionStatusCreate.builder()
|
||||
.actionId(action.getId()).status(status).messages(messages);
|
||||
Optional.ofNullable(actionUpdateStatus.getCode()).ifPresent(code -> {
|
||||
actionStatus.code(code);
|
||||
actionStatus.message("Device reported status code: " + code);
|
||||
actionStatus.messages(List.of("Device reported status code: " + code));
|
||||
});
|
||||
updatedAction = Status.CANCELED == status || Status.CANCEL_REJECTED == status
|
||||
? controllerManagement.addCancelActionStatus(actionStatus)
|
||||
: controllerManagement.addUpdateActionStatus(actionStatus);
|
||||
? controllerManagement.addCancelActionStatus(actionStatus.build())
|
||||
: controllerManagement.addUpdateActionStatus(actionStatus.build());
|
||||
}
|
||||
|
||||
if (shouldTargetProceed(updatedAction) || actionUpdateStatus.getActionStatus() == DmfActionStatus.CONFIRMED) {
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.eclipse.hawkbit.repository.ConfirmationManagement;
|
||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
@@ -220,7 +219,6 @@ public class DmfApiConfiguration {
|
||||
* @param rabbitTemplate for converting messages
|
||||
* @param amqpMessageDispatcherService to sending events to DMF client
|
||||
* @param controllerManagement for target repo access
|
||||
* @param entityFactory to create entities
|
||||
* @return handler service bean
|
||||
*/
|
||||
@Bean
|
||||
@@ -228,13 +226,12 @@ public class DmfApiConfiguration {
|
||||
public AmqpMessageHandlerService amqpMessageHandlerService(
|
||||
final RabbitTemplate rabbitTemplate,
|
||||
final AmqpMessageDispatcherService amqpMessageDispatcherService,
|
||||
final ControllerManagement controllerManagement, final EntityFactory entityFactory,
|
||||
final SystemSecurityContext systemSecurityContext,
|
||||
final ControllerManagement controllerManagement, final SystemSecurityContext systemSecurityContext,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement,
|
||||
final ConfirmationManagement confirmationManagement) {
|
||||
return new AmqpMessageHandlerService(
|
||||
rabbitTemplate, amqpMessageDispatcherService, controllerManagement,
|
||||
entityFactory, systemSecurityContext, tenantConfigurationManagement, confirmationManagement);
|
||||
systemSecurityContext, tenantConfigurationManagement, confirmationManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,14 +37,9 @@ import org.eclipse.hawkbit.dmf.json.model.DmfCreateThing;
|
||||
import org.eclipse.hawkbit.dmf.json.model.DmfUpdateMode;
|
||||
import org.eclipse.hawkbit.repository.ConfirmationManagement;
|
||||
import org.eclipse.hawkbit.repository.ControllerManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.UpdateMode;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.ActionProperties;
|
||||
@@ -96,8 +91,6 @@ class AmqpMessageHandlerServiceTest {
|
||||
@Mock
|
||||
private ConfirmationManagement confirmationManagementMock;
|
||||
@Mock
|
||||
private EntityFactory entityFactoryMock;
|
||||
@Mock
|
||||
private TenantConfigurationManagement tenantConfigurationManagement;
|
||||
@Mock
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
@@ -137,7 +130,7 @@ class AmqpMessageHandlerServiceTest {
|
||||
final SystemSecurityContext systemSecurityContext = new SystemSecurityContext(tenantAware);
|
||||
|
||||
amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate, amqpMessageDispatcherServiceMock,
|
||||
controllerManagementMock, entityFactoryMock, systemSecurityContext, tenantConfigurationManagement,
|
||||
controllerManagementMock, systemSecurityContext, tenantConfigurationManagement,
|
||||
confirmationManagementMock);
|
||||
}
|
||||
|
||||
@@ -439,12 +432,6 @@ class AmqpMessageHandlerServiceTest {
|
||||
final Message message = createMessage(actionUpdateStatus, messageProperties);
|
||||
final Action action = mock(Action.class);
|
||||
when(action.getId()).thenReturn(2L);
|
||||
final ActionStatusBuilder builder = mock(ActionStatusBuilder.class);
|
||||
final ActionStatusCreate create = mock(ActionStatusCreate.class);
|
||||
when(builder.create(2L)).thenReturn(create);
|
||||
when(create.status(any())).thenReturn(create);
|
||||
when(create.messages(any())).thenReturn(create);
|
||||
when(entityFactoryMock.actionStatus()).thenReturn(builder);
|
||||
|
||||
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.of(action));
|
||||
when(controllerManagementMock.addUpdateActionStatus(any())).thenThrow(new AssignmentQuotaExceededException());
|
||||
@@ -464,12 +451,6 @@ class AmqpMessageHandlerServiceTest {
|
||||
final Action action = createActionWithTarget(22L);
|
||||
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.of(action));
|
||||
when(controllerManagementMock.addUpdateActionStatus(any())).thenReturn(action);
|
||||
final ActionStatusBuilder builder = mock(ActionStatusBuilder.class);
|
||||
final ActionStatusCreate create = mock(ActionStatusCreate.class);
|
||||
when(builder.create(22L)).thenReturn(create);
|
||||
when(create.status(any())).thenReturn(create);
|
||||
when(create.messages(any())).thenReturn(create);
|
||||
when(entityFactoryMock.actionStatus()).thenReturn(builder);
|
||||
// for the test the same action can be used
|
||||
when(controllerManagementMock.findActiveActionWithHighestWeight(any())).thenReturn(Optional.of(action));
|
||||
|
||||
@@ -502,8 +483,6 @@ class AmqpMessageHandlerServiceTest {
|
||||
final Action action = createActionWithTarget(22L);
|
||||
when(controllerManagementMock.findActionWithDetails(anyLong())).thenReturn(Optional.of(action));
|
||||
when(controllerManagementMock.addUpdateActionStatus(any())).thenReturn(action);
|
||||
final ActionStatusBuilder builder = new JpaActionStatusBuilder();
|
||||
when(entityFactoryMock.actionStatus()).thenReturn(builder);
|
||||
// for the test the same action can be used
|
||||
when(controllerManagementMock.findActiveActionWithHighestWeight(any())).thenReturn(Optional.of(action));
|
||||
|
||||
@@ -517,16 +496,6 @@ class AmqpMessageHandlerServiceTest {
|
||||
|
||||
// test
|
||||
amqpMessageHandlerService.onMessage(message, MessageType.EVENT.name(), TENANT, VIRTUAL_HOST);
|
||||
|
||||
final ArgumentCaptor<ActionStatusCreate> actionPropertiesCaptor = ArgumentCaptor.forClass(ActionStatusCreate.class);
|
||||
|
||||
verify(controllerManagementMock, times(1)).addUpdateActionStatus(actionPropertiesCaptor.capture());
|
||||
|
||||
final JpaActionStatus jpaActionStatus = (JpaActionStatus) actionPropertiesCaptor.getValue().build();
|
||||
assertThat(jpaActionStatus.getCode()).as("Action status for reported code is missing").contains(12);
|
||||
assertThat(jpaActionStatus.getMessages())
|
||||
.as("Action status message for reported code is missing")
|
||||
.contains("Device reported status code: 12");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user