From 866bc721148ffda8cc9aec23db443551b7dcb905 Mon Sep 17 00:00:00 2001 From: Dennis Melzer Date: Thu, 3 Nov 2016 15:53:53 +0100 Subject: [PATCH] Feature horizontal scalability (#305) Signed-off-by: kaizimmerm --- README.md | 1 - examples/README.md | 3 +- examples/hawkbit-custom-theme-example/pom.xml | 10 - .../java/org/eclipse/hawkbit/app/MyUI.java | 22 +- examples/hawkbit-device-simulator/pom.xml | 4 +- .../hawkbit/simulator/event/InitUpdate.java | 3 - .../event/NextPollCounterUpdate.java | 5 +- .../hawkbit/simulator/ui/SimulatorView.java | 7 +- .../resources/application-cloud.properties | 1 - .../src/main/resources/logback-spring.xml | 11 +- examples/hawkbit-example-app/README.md | 42 +++ examples/hawkbit-example-app/pom.xml | 1 - .../java/org/eclipse/hawkbit/app/MyUI.java | 24 +- .../hawkbit-example-core-feign-client/pom.xml | 4 +- .../hawkbit-example-ddi-feign-client/pom.xml | 4 +- .../hawkbit-example-mgmt-feign-client/pom.xml | 5 +- examples/pom.xml | 20 +- hawkbit-autoconfigure/pom.xml | 18 +- .../cache/CacheAutoConfiguration.java | 60 ++++- .../autoconfigure/cache/CacheProperties.java | 54 ++++ .../DownloadIdCacheAutoConfiguration.java | 27 +- .../cache/RedisAutoConfiguration.java | 27 -- .../EventPublisherAutoConfiguration.java | 131 +++++++++ .../eventbus/EventBusAutoConfiguration.java | 66 ----- .../JpaRepositoryAutoConfiguration.java | 2 +- .../SecurityManagedConfiguration.java | 7 +- .../autoconfigure/ui/UIAutoConfiguration.java | 23 ++ .../web/WebMvcAutoConfiguration.java | 16 -- .../main/resources/META-INF/spring.factories | 3 +- .../main/resources/hawkbitdefaults.properties | 13 + hawkbit-cache-redis/pom.xml | 81 ------ .../hawkbit/cache/RedisConfiguration.java | 118 --------- .../hawkbit/cache/RedisProperties.java | 60 ----- .../hawkbit/cache/annotation/EnableRedis.java | 29 -- .../cache/eventbus/EventDistributor.java | 140 ---------- .../cache/eventbus/EventDistributorTest.java | 228 ---------------- .../cache/redis/RedisPropertiesTest.java | 36 --- hawkbit-core/pom.xml | 10 + .../hawkbit/cache/DefaultDownloadIdCache.java | 57 ++++ .../hawkbit/cache/DownloadArtifactCache.java | 7 +- .../hawkbit/cache/DownloadIdCache.java | 57 ++++ .../eclipse/hawkbit/cache/DownloadType.java | 3 - .../hawkbit/cache/TenancyCacheManager.java | 6 +- .../cache/TenantAwareCacheManager.java | 47 ++-- .../hawkbit/eventbus/DeadEventListener.java | 40 --- .../eventbus/EventBusSubscriberProcessor.java | 88 ------ .../hawkbit/eventbus/EventSubscriber.java | 39 --- .../event/AbstractDistributedEvent.java | 105 -------- .../hawkbit/eventbus/event/DefaultEvent.java | 44 --- .../eventbus/event/DistributedEvent.java | 23 -- .../hawkbit/eventbus/event/EntityEvent.java | 48 ---- .../eclipse/hawkbit/eventbus/event/Event.java | 32 --- .../hawkbit/eventbus/event/NodeAware.java | 52 ---- .../cache/DefaultDownloadIdCacheTest.java | 124 +++++++++ .../EventBusSubscriberProcessorTest.java | 75 ------ hawkbit-ddi-api/pom.xml | 4 - hawkbit-ddi-resource/pom.xml | 23 -- .../resource/DdiArtifactDownloadTest.java | 52 ++-- .../rest/resource/DdiCancelActionTest.java | 21 +- .../ddi/rest/resource/DdiConfigDataTest.java | 4 +- .../rest/resource/DdiDeploymentBaseTest.java | 21 +- .../rest/resource/DdiRootControllerTest.java | 13 +- .../resources/application-test.properties | 3 + .../src/test/resources/logback-spring.xml | 21 -- hawkbit-dmf-amqp/pom.xml | 6 +- .../AmqpAuthenticationMessageHandler.java | 8 +- .../hawkbit/amqp/AmqpConfiguration.java | 55 +++- .../amqp/AmqpMessageDispatcherService.java | 97 ++++--- .../amqp/AmqpMessageHandlerService.java | 27 +- .../AmqpControllerAuthenticationTest.java | 4 +- .../AmqpMessageDispatcherServiceTest.java | 87 ++++-- .../amqp/AmqpMessageHandlerServiceTest.java | 57 ++-- .../resources/application-test.properties | 4 +- hawkbit-dmf-api/pom.xml | 4 - .../HttpDownloadAuthenticationFilter.java | 12 +- hawkbit-mgmt-api/pom.xml | 5 - ...SystemTenantConfigurationValueRequest.java | 11 +- hawkbit-mgmt-resource/pom.xml | 31 +-- .../resource/MgmtDistributionSetMapper.java | 2 +- .../resource/MgmtDistributionSetResource.java | 2 +- .../rest/resource/MgmtDownloadResource.java | 20 +- .../rest/resource/MgmtSystemResource.java | 5 +- .../MgmtDistributionSetResourceTest.java | 10 +- .../MgmtDistributionSetTypeResourceTest.java | 14 +- .../resource/MgmtDownloadResourceTest.java | 9 +- .../resource/MgmtRolloutResourceTest.java | 36 +-- .../MgmtSoftwareModuleResourceTest.java | 34 +-- .../MgmtSoftwareModuleTypeResourceTest.java | 10 +- .../MgmtTargetFilterQueryResourceTest.java | 62 ++--- .../rest/resource/MgmtTargetResourceTest.java | 2 +- .../resources/application-test.properties | 5 +- .../src/test/resources/logback-spring.xml | 35 --- .../hawkbit-repository-api/pom.xml | 7 +- .../repository/ControllerManagement.java | 20 +- .../repository/DeploymentManagement.java | 1 + .../hawkbit/repository/RolloutManagement.java | 2 +- .../TenantConfigurationManagement.java | 13 +- .../repository}/event/CustomEvents.java | 2 +- .../repository/event/TenantAwareEvent.java | 18 +- .../remote/DistributionSetDeletedEvent.java | 40 +++ .../DistributionSetTagDeletedEvent.java | 41 +++ .../event/remote/DownloadProgressEvent.java | 48 ++++ .../event/remote/EventEntityManager.java | 32 +++ .../remote/EventEntityManagerHolder.java | 42 +++ .../event/remote/RemoteIdEvent.java | 47 ++++ .../event/remote/RemoteTenantAwareEvent.java | 52 ++++ .../TargetAssignDistributionSetEvent.java | 88 ++++++ .../event/remote/TargetDeletedEvent.java | 42 +++ .../event/remote/TargetTagDeletedEvent.java | 41 +++ .../remote/entity/ActionCreatedEvent.java | 38 +++ .../remote/entity/ActionUpdatedEvent.java | 38 +++ .../entity/CancelTargetAssignmentEvent.java | 52 ++++ .../entity/DistributionSetCreatedEvent.java | 40 +++ .../DistributionSetTagCreatedEvent.java | 21 +- .../DistributionSetTagUpdateEvent.java | 22 +- .../entity/DistributionSetUpdateEvent.java | 39 +++ .../remote/entity/RemoteEntityEvent.java | 85 ++++++ .../entity/RolloutGroupCreatedEvent.java | 48 ++++ .../entity/RolloutGroupUpdatedEvent.java | 39 +++ .../remote/entity/RolloutUpdatedEvent.java | 38 +++ .../remote/entity/TargetCreatedEvent.java | 39 +++ .../remote/entity/TargetTagCreatedEvent.java} | 19 +- .../remote/entity}/TargetTagUpdateEvent.java | 19 +- .../remote/entity/TargetUpdatedEvent.java | 40 +++ .../event/AbstractBaseEntityEvent.java | 57 ---- .../event/AbstractPropertyChangeEvent.java | 82 ------ .../eventbus/event/ActionCreatedEvent.java | 26 -- .../event/ActionPropertyChangeEvent.java | 29 -- .../event/CancelTargetAssignmentEvent.java | 63 ----- .../event/DistributionCreatedEvent.java | 28 -- .../event/DistributionDeletedEvent.java | 36 --- ...istributionSetTagAssigmentResultEvent.java | 50 ---- .../event/DistributionSetTagDeletedEvent.java | 31 --- .../event/DistributionSetUpdateEvent.java | 29 -- .../eventbus/event/DownloadProgressEvent.java | 67 ----- .../eventbus/event/RolloutChangeEvent.java | 40 --- .../event/RolloutGroupChangeEvent.java | 49 ---- .../event/RolloutGroupCreatedEvent.java | 69 ----- .../RolloutGroupPropertyChangeEvent.java | 32 --- .../event/RolloutPropertyChangeEvent.java | 30 --- .../TargetAssignDistributionSetEvent.java | 70 ----- .../eventbus/event/TargetCreatedEvent.java | 29 -- .../eventbus/event/TargetDeletedEvent.java | 41 --- .../eventbus/event/TargetInfoUpdateEvent.java | 78 ------ .../event/TargetTagAssigmentResultEvent.java | 49 ---- .../eventbus/event/TargetTagCreatedEvent.java | 31 --- .../eventbus/event/TargetUpdatedEvent.java | 31 --- .../repository/model/ActionStatus.java | 6 - .../DistributionSetAssignmentResult.java | 5 +- .../DistributionSetTagAssignmentResult.java | 18 +- .../model/TenantConfigurationValue.java | 9 +- .../model/InnerOuterDataReportSeries.java | 3 +- .../hawkbit-repository-core/pom.xml | 10 + .../event/BusProtoStuffMessageConverter.java | 108 ++++++++ .../{jpa => }/TimestampCalculator.java | 4 +- .../jpa/model/helper/EventBusHolder.java | 54 ---- .../model/helper/EventPublisherHolder.java | 53 ++++ .../model/helper/SystemManagementHolder.java | 2 +- .../TenantConfigurationManagementHolder.java | 2 +- .../rsql/VirtualPropertyResolver.java | 9 +- .../hawkbit-repository-jpa/pom.xml | 30 +-- .../RepositoryApplicationConfiguration.java | 64 +++-- .../jpa/JpaControllerManagement.java | 27 +- .../jpa/JpaDeploymentManagement.java | 60 ++--- .../jpa/JpaDistributionSetManagement.java | 37 +-- .../repository/jpa/JpaReportManagement.java | 91 +++---- .../repository/jpa/JpaRolloutManagement.java | 20 +- .../repository/jpa/JpaSoftwareManagement.java | 10 +- .../repository/jpa/JpaTagManagement.java | 50 ++-- .../repository/jpa/JpaTargetManagement.java | 44 +-- .../jpa/JpaTenantConfigurationManagement.java | 15 +- .../repository/jpa/RolloutRepository.java | 3 +- .../jpa/SoftwareModuleRepository.java | 4 +- .../repository/jpa/TargetInfoRepository.java | 2 - .../ExceptionMappingAspectHandler.java | 3 - .../repository/jpa/cache/CacheField.java | 41 --- .../repository/jpa/cache/CacheKeys.java | 56 ---- .../jpa/cache/CacheWriteNotify.java | 143 ---------- .../jpa/event/JpaEventEntityManager.java | 49 ++++ .../repository/jpa/eventbus/EventMerger.java | 193 -------------- .../jpa/model/AbstractJpaBaseEntity.java | 3 +- .../AbstractJpaTenantAwareBaseEntity.java | 2 +- .../jpa/model/CacheFieldEntityListener.java | 123 --------- .../repository/jpa/model/JpaAction.java | 14 +- .../repository/jpa/model/JpaActionStatus.java | 15 -- .../jpa/model/JpaDistributionSet.java | 49 ++-- .../repository/jpa/model/JpaRollout.java | 26 +- .../repository/jpa/model/JpaRolloutGroup.java | 10 +- .../repository/jpa/model/JpaTarget.java | 17 +- .../repository/jpa/model/JpaTargetInfo.java | 9 +- .../jpa/model/helper/CacheManagerHolder.java | 58 ---- .../helper/EntityPropertyChangeHelper.java | 44 --- .../repository/jpa/rsql/RSQLUtility.java | 1 + .../H2/V1_7_2__cascade_delete___H2.sql | 27 ++ ...1_9_0__add_rollout_groups_created___H2.sql | 2 + .../MYSQL/V1_7_2__cascade_delete___MYSQL.sql | 27 ++ ..._0__add_rollout_groups_created___MYSQL.sql | 2 + .../event/remote/AbstractRemoteEventTest.java | 91 +++++++ .../event/remote/RemoteIdEventTest.java | 82 ++++++ .../remote/RemoteTenantAwareEventTest.java | 89 +++++++ .../entity/AbstractRemoteEntityEventTest.java | 69 +++++ .../event/remote/entity/ActionEventTest.java | 53 ++++ .../entity/DistributionSetEventTest.java | 45 ++++ .../entity/DistributionSetTagEventTest.java | 44 +++ .../event/remote/entity/RolloutEventTest.java | 55 ++++ .../remote/entity/RolloutGroupEventTest.java | 69 +++++ .../event/remote/entity/TargetEventTest.java | 55 ++++ .../remote/entity/TargetTagEventTest.java | 44 +++ .../jpa/DeploymentManagementTest.java | 171 ++++++------ .../jpa/DistributionSetManagementTest.java | 2 +- .../repository/jpa/ReportManagementTest.java | 2 +- .../repository/jpa/TagManagementTest.java | 2 +- .../repository/jpa/TargetManagementTest.java | 2 +- .../TenantConfigurationManagementTest.java | 3 +- .../repository/jpa/cache/CacheKeysTest.java | 29 -- .../jpa/cache/CacheWriteNotifyTest.java | 73 ----- .../RepositoryEntityEventTest.java | 74 +++--- .../CacheFieldEntityListenerTest.java | 129 --------- .../repository/jpa/rsql/RSQLUtilityTest.java | 3 +- .../jpa/rsql/VirtualPropertyResolverTest.java | 3 +- .../resources/application-test.properties | 3 + .../src/test/resources/logback-spring.xml | 21 -- .../hawkbit-repository-test/pom.xml | 21 +- .../eclipse/hawkbit/TestConfiguration.java | 70 +++-- .../test/util/AbstractIntegrationTest.java | 14 +- .../util/JpaTestRepositoryManagement.java | 28 +- .../test/util/WithSpringAuthorityRule.java | 2 +- hawkbit-security-core/pom.xml | 1 - .../hawkbit/ui/DispatcherRunnable.java | 6 +- .../org/eclipse/hawkbit/ui/HawkbitUI.java | 16 +- .../artifacts/event/SoftwareModuleEvent.java | 6 +- .../event/SoftwareModuleTypeEvent.java | 2 +- .../event/UploadArtifactUIEvent.java | 2 +- .../ui/artifacts/event/UploadFileStatus.java | 41 ++- .../ui/artifacts/event/UploadStatusEvent.java | 2 +- .../upload/UploadConfirmationWindow.java | 34 +-- .../ui/common/AbstractAcceptCriteria.java | 4 +- .../hawkbit/ui/common/ConfirmationDialog.java | 2 +- .../AbstractTableDetailsLayout.java | 4 +- .../ui/common/table/AbstractTable.java | 2 +- ...ntityEvent.java => BaseUIEntityEvent.java} | 6 +- .../common/tagdetails/AbstractTagToken.java | 16 +- .../tagdetails/AbstractTargetTagToken.java | 4 +- .../tagdetails/DistributionTagToken.java | 21 +- .../ui/common/tagdetails/TargetTagToken.java | 24 +- .../dstable/DistributionSetDetails.java | 24 -- .../dstable/DistributionSetTable.java | 8 +- .../SoftwareModuleAssignmentDiscardEvent.java | 40 --- .../DistributionSetSelectTable.java | 8 +- .../filtermanagement/TargetFilterTable.java | 3 - .../management/dstable/DistributionTable.java | 8 +- .../event/DistributionTableEvent.java | 6 +- .../event/TargetAddUpdateWindowEvent.java | 4 +- .../ui/management/event/TargetTableEvent.java | 6 +- .../management/footer/CountMessageLabel.java | 4 +- .../ManangementConfirmationWindowLayout.java | 2 +- .../management/targettable/TargetTable.java | 36 +-- .../hawkbit/ui/menu/DashboardEvent.java | 4 +- .../CancelTargetAssignmentEventContainer.java | 2 +- .../ui/push/DelayedEventBusPushStrategy.java | 250 +++++++++++------- .../DistributionCreatedEventContainer.java | 12 +- .../DistributionDeletedEventContainer.java | 12 +- ...nSetTagAssignmentResultEventContainer.java | 32 --- ...stributionSetTagCreatedEventContainer.java | 2 +- ...stributionSetTagDeletedEventContainer.java | 2 +- ...stributionSetTagUpdatedEventContainer.java | 2 +- .../DistributionSetUpdatedEventContainer.java | 2 +- .../hawkbit/ui/push/EventContainer.java | 4 +- .../hawkbit/ui/push/HawkbitEventProvider.java | 47 ++-- .../ui/push/RolloutChangeEventContainer.java | 2 +- .../RolloutGroupChangeEventContainer.java | 2 +- .../ui/push/TargetCreatedEventContainer.java | 2 +- .../ui/push/TargetDeletedEventContainer.java | 2 +- .../push/TargetInfoUpdateEventContainer.java | 31 --- ...argetTagAssigmentResultEventContainer.java | 31 --- .../push/TargetTagCreatedEventContainer.java | 2 +- .../push/TargetTagDeletedEventContainer.java | 2 +- .../push/TargetTagUpdatedEventContainer.java | 2 +- .../ui/push/TargetUpdatedEventContainer.java | 2 +- .../hawkbit/ui/push/UIEventProvider.java | 4 +- .../ui/push/event/RolloutChangeEvent.java | 72 +++++ .../push/event/RolloutGroupChangeEvent.java | 90 +++++++ .../ui/push/event/TenantAwareUiEvent.java | 67 +++++ .../ui/rollout/rollout/RolloutListGrid.java | 2 +- .../rolloutgroup/RolloutGroupListGrid.java | 13 +- .../RolloutGroupTargetsCountLabelMessage.java | 2 +- pom.xml | 83 ++++-- 287 files changed, 4219 insertions(+), 5046 deletions(-) create mode 100644 hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheProperties.java delete mode 100644 hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/RedisAutoConfiguration.java create mode 100644 hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/event/EventPublisherAutoConfiguration.java delete mode 100644 hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/eventbus/EventBusAutoConfiguration.java delete mode 100644 hawkbit-cache-redis/pom.xml delete mode 100644 hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/RedisConfiguration.java delete mode 100644 hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/RedisProperties.java delete mode 100644 hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/annotation/EnableRedis.java delete mode 100644 hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/eventbus/EventDistributor.java delete mode 100644 hawkbit-cache-redis/src/test/java/org/eclipse/hawkbit/cache/eventbus/EventDistributorTest.java delete mode 100644 hawkbit-cache-redis/src/test/java/org/eclipse/hawkbit/cache/redis/RedisPropertiesTest.java create mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCache.java create mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadIdCache.java delete mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/DeadEventListener.java delete mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/EventBusSubscriberProcessor.java delete mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/EventSubscriber.java delete mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractDistributedEvent.java delete mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/DefaultEvent.java delete mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributedEvent.java delete mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityEvent.java delete mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/Event.java delete mode 100644 hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/NodeAware.java create mode 100644 hawkbit-core/src/test/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCacheTest.java delete mode 100644 hawkbit-core/src/test/java/org/eclipse/hawkbit/eventbus/EventBusSubscriberProcessorTest.java delete mode 100644 hawkbit-ddi-resource/src/test/resources/logback-spring.xml delete mode 100644 hawkbit-mgmt-resource/src/test/resources/logback-spring.xml rename {hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus => hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository}/event/CustomEvents.java (91%) rename hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/CacheConstants.java => hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/TenantAwareEvent.java (52%) create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DistributionSetDeletedEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DistributionSetTagDeletedEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DownloadProgressEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManager.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManagerHolder.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/RemoteIdEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetAssignDistributionSetEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetDeletedEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetTagDeletedEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionCreatedEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionUpdatedEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/CancelTargetAssignmentEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetCreatedEvent.java rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/{eventbus/event => event/remote/entity}/DistributionSetTagCreatedEvent.java (53%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/{eventbus/event => event/remote/entity}/DistributionSetTagUpdateEvent.java (51%) create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetUpdateEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RemoteEntityEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupCreatedEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupUpdatedEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutUpdatedEvent.java create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetCreatedEvent.java rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/{eventbus/event/TargetTagDeletedEvent.java => event/remote/entity/TargetTagCreatedEvent.java} (51%) rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/{eventbus/event => event/remote/entity}/TargetTagUpdateEvent.java (51%) create mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetUpdatedEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractBaseEntityEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionCreatedEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/CancelTargetAssignmentEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionCreatedEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionDeletedEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagAssigmentResultEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagDeletedEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetUpdateEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DownloadProgressEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutChangeEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupChangeEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupCreatedEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetAssignDistributionSetEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetCreatedEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetDeletedEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetInfoUpdateEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagAssigmentResultEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagCreatedEvent.java delete mode 100644 hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetUpdatedEvent.java rename hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/{ => model}/DistributionSetAssignmentResult.java (93%) create mode 100644 hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/event/BusProtoStuffMessageConverter.java rename hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/{jpa => }/TimestampCalculator.java (94%) delete mode 100644 hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java create mode 100644 hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventPublisherHolder.java rename hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/{jpa => }/model/helper/SystemManagementHolder.java (96%) rename hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/{jpa => }/model/helper/TenantConfigurationManagementHolder.java (95%) rename hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/{jpa => }/rsql/VirtualPropertyResolver.java (85%) delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotify.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/event/JpaEventEntityManager.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EntityPropertyChangeHelper.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_7_2__cascade_delete___H2.sql create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_9_0__add_rollout_groups_created___H2.sql create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_7_2__cascade_delete___MYSQL.sql create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_9_0__add_rollout_groups_created___MYSQL.sql create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/AbstractRemoteEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteIdEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/AbstractRemoteEntityEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetEventTest.java create mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagEventTest.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeysTest.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotifyTest.java rename hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/{eventbus => event}/RepositoryEntityEventTest.java (68%) delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java delete mode 100644 hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml rename hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/{BaseEntityEvent.java => BaseUIEntityEvent.java} (82%) delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/event/SoftwareModuleAssignmentDiscardEvent.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagAssignmentResultEventContainer.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetInfoUpdateEventContainer.java delete mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagAssigmentResultEventContainer.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangeEvent.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangeEvent.java create mode 100644 hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/TenantAwareUiEvent.java diff --git a/README.md b/README.md index 9a7a1c749..4db6e5b20 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,6 @@ $ java -jar ./examples/hawkbit-example-mgmt-simulator/target/hawkbit-example-mgm * `examples` : hawkBit examples * `hawkbit-artifact-repository-mongo` : Artifact repository implementation to mongoDB. * `hawkbit-autoconfigure` : Spring-boot auto-configuration. -* `hawkbit-cache-redis` : Spring cache manager configuration and implementation with redis, distributed cache and distributed events. * `hawkbit-core` : Core elements for internal interfaces and utility classes. * `hawkbit-ddi-api` : The hawkBit DDI API. * `hawkbit-ddi-dl-api` : The hawkBit DDI Download API. diff --git a/examples/README.md b/examples/README.md index 0aebbc117..5c60ec341 100644 --- a/examples/README.md +++ b/examples/README.md @@ -8,5 +8,4 @@ Example projects that show how _hawkBit_ can be used to create, run or access an - `hawkbit-example-core-feign-client` : Core resources for the client examples. - `hawkbit-example-ddi-feign-client` : Example _hawkBit_ DDI client based on the _hawkBit_ DDI API. - `hawkbit-example-mgmt-feign-client` : Example _hawkBit_ Management client based on the _hawkBit_ Management API -- `hawkbit-example-mgmt-simulator` : Example client simulation for the _hawkBit_ Management API based on Spring Boot and the hawkbit-example-mgmt-feign-client. - +- `hawkbit-example-mgmt-simulator` : Example client simulation for the _hawkBit_ Management API based on Spring Boot and the hawkbit-example-mgmt-feign-client. \ No newline at end of file diff --git a/examples/hawkbit-custom-theme-example/pom.xml b/examples/hawkbit-custom-theme-example/pom.xml index 875db18e3..b26e92366 100644 --- a/examples/hawkbit-custom-theme-example/pom.xml +++ b/examples/hawkbit-custom-theme-example/pom.xml @@ -93,16 +93,6 @@ org.springframework.boot spring-boot-starter - - - org.springframework.boot - spring-boot-starter-logging - - - - - org.springframework.boot - spring-boot-starter-log4j2 org.springframework.security diff --git a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyUI.java b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyUI.java index 916061adc..07e7b7f7c 100644 --- a/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyUI.java +++ b/examples/hawkbit-custom-theme-example/src/main/java/org/eclipse/hawkbit/app/MyUI.java @@ -8,14 +8,10 @@ package org.eclipse.hawkbit.app; * http://www.eclipse.org/legal/epl-v10.html */ -import java.util.concurrent.ScheduledExecutorService; - import org.eclipse.hawkbit.ui.HawkbitUI; -import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy; -import org.eclipse.hawkbit.ui.push.UIEventProvider; -import org.springframework.beans.factory.annotation.Autowired; +import org.eclipse.hawkbit.ui.push.EventPushStrategy; +import org.vaadin.spring.events.EventBus.SessionEventBus; -import com.google.common.eventbus.EventBus; import com.vaadin.annotations.Push; import com.vaadin.annotations.Theme; import com.vaadin.annotations.Title; @@ -39,9 +35,15 @@ public class MyUI extends HawkbitUI { private static final long serialVersionUID = 1L; - @Autowired - public MyUI(final ScheduledExecutorService executorService, final EventBus systemEventBus, - final org.vaadin.spring.events.EventBus.SessionEventBus eventBus, final UIEventProvider provider) { - super(new DelayedEventBusPushStrategy(executorService, eventBus, systemEventBus, provider)); + /** + * Constructor + * + * @param pushStrategy + * the push strategy + * @param eventBus + * the event bus + */ + public MyUI(final EventPushStrategy pushStrategy, final SessionEventBus eventBus) { + super(pushStrategy, eventBus); } } diff --git a/examples/hawkbit-device-simulator/pom.xml b/examples/hawkbit-device-simulator/pom.xml index 035bcebfc..3e66ea798 100644 --- a/examples/hawkbit-device-simulator/pom.xml +++ b/examples/hawkbit-device-simulator/pom.xml @@ -105,11 +105,11 @@ guava - com.netflix.feign + io.github.openfeign feign-jackson - com.netflix.feign + io.github.openfeign feign-core diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/InitUpdate.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/InitUpdate.java index 1cf6dbbda..16a967f89 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/InitUpdate.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/InitUpdate.java @@ -12,9 +12,6 @@ import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice; /** * Event description which indicates the initialization of an update. - * - * @author Michael Hirsch - * */ public class InitUpdate { diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/NextPollCounterUpdate.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/NextPollCounterUpdate.java index 5e98ebb64..7ed5e2cfc 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/NextPollCounterUpdate.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/event/NextPollCounterUpdate.java @@ -13,10 +13,7 @@ import java.util.Collection; import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice; /** - * Event description which indicates an poll time update. - * - * @author Michael Hirsch - * + * Event description which indicates a poll time update. */ public class NextPollCounterUpdate { diff --git a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java index 622a31b49..de0cbb1d0 100644 --- a/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java +++ b/examples/hawkbit-device-simulator/src/main/java/org/eclipse/hawkbit/simulator/ui/SimulatorView.java @@ -18,7 +18,6 @@ import org.eclipse.hawkbit.simulator.DeviceSimulatorRepository; import org.eclipse.hawkbit.simulator.SimulatedDeviceFactory; import org.eclipse.hawkbit.simulator.UpdateStatus.ResponseStatus; import org.eclipse.hawkbit.simulator.amqp.AmqpProperties; -import org.eclipse.hawkbit.simulator.amqp.SpSenderService; import org.eclipse.hawkbit.simulator.event.InitUpdate; import org.eclipse.hawkbit.simulator.event.NextPollCounterUpdate; import org.eclipse.hawkbit.simulator.event.ProgressUpdate; @@ -58,9 +57,6 @@ import com.vaadin.ui.renderers.ProgressBarRenderer; @SuppressWarnings("squid:MaximumInheritanceDepth") public class SimulatorView extends VerticalLayout implements View { - /** - * - */ private static final String HTML_SPAN = ";"; private static final String NEXT_POLL_COUNTER_SEC_COL = "nextPollCounterSec"; @@ -81,10 +77,9 @@ public class SimulatorView extends VerticalLayout implements View { private static final long serialVersionUID = 1L; - @Autowired - private transient SpSenderService spSenderService; @Autowired private transient DeviceSimulatorRepository repository; + @Autowired private transient SimulatedDeviceFactory deviceFactory; diff --git a/examples/hawkbit-device-simulator/src/main/resources/application-cloud.properties b/examples/hawkbit-device-simulator/src/main/resources/application-cloud.properties index 3e3edc90c..925eea1c8 100644 --- a/examples/hawkbit-device-simulator/src/main/resources/application-cloud.properties +++ b/examples/hawkbit-device-simulator/src/main/resources/application-cloud.properties @@ -14,7 +14,6 @@ security.user.password=${BASIC_PASSWORD:admin} security.user.role=USER security.require-ssl=false security.enable-csrf=false -security.basic.enabled=true security.basic.realm=DeviceSimulator security.basic.path= /** security.basic.authorize-mode=ROLE diff --git a/examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml b/examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml index 355284d39..9403ee454 100644 --- a/examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml +++ b/examples/hawkbit-device-simulator/src/main/resources/logback-spring.xml @@ -12,16 +12,7 @@ - - - - - - - - - - + diff --git a/examples/hawkbit-example-app/README.md b/examples/hawkbit-example-app/README.md index 068acdd15..a495f2d2b 100644 --- a/examples/hawkbit-example-app/README.md +++ b/examples/hawkbit-example-app/README.md @@ -33,3 +33,45 @@ The Management API can be accessed via http://localhost:8080/rest/v1 - **manifest-simple.yml** for a standalone hawkBit installation with embedded H2. - **manifest.yml** for a standalone hawkBit installation with embedded H2 and RabbitMQ service binding for DMF integration (note: this manifest is used for the sandbox above). - Run ```cf push``` against you cloud foundry environment. + +# Enable Clustering (experimental) + +Clustering in hawkBit is based on _Spring Cloud Bus_. It is not enabled in the example app by default. + +Add to your `application.properties` : + +``` +spring.cloud.bus.enabled=true +``` + +Add to your `pom.xml` : + +``` + + org.springframework.cloud + spring-cloud-stream-binder-rabbit + +``` + +Optional as well is the addition of [Protostuff](https://github.com/protostuff/protostuff) based message payload serialization for improved performance. + + +Add to your `application.properties` : + +``` +spring.cloud.stream.bindings.springCloudBusInput.content-type=application/binary+protostuff +spring.cloud.stream.bindings.springCloudBusOutput.content-type=application/binary+protostuff +``` + +Add to your `pom.xml` : + +``` + + io.protostuff + protostuff-core + + + io.protostuff + protostuff-runtime + +``` diff --git a/examples/hawkbit-example-app/pom.xml b/examples/hawkbit-example-app/pom.xml index 15d802792..f0bae1729 100644 --- a/examples/hawkbit-example-app/pom.xml +++ b/examples/hawkbit-example-app/pom.xml @@ -97,7 +97,6 @@ hawkbit-repository-jpa ${project.version} - org.springframework.boot diff --git a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/MyUI.java b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/MyUI.java index 53cdf1382..f731f5660 100644 --- a/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/MyUI.java +++ b/examples/hawkbit-example-app/src/main/java/org/eclipse/hawkbit/app/MyUI.java @@ -8,14 +8,10 @@ */ package org.eclipse.hawkbit.app; -import java.util.concurrent.ScheduledExecutorService; - import org.eclipse.hawkbit.ui.HawkbitUI; -import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy; -import org.eclipse.hawkbit.ui.push.UIEventProvider; -import org.springframework.beans.factory.annotation.Autowired; +import org.eclipse.hawkbit.ui.push.EventPushStrategy; +import org.vaadin.spring.events.EventBus.SessionEventBus; -import com.google.common.eventbus.EventBus; import com.vaadin.annotations.Push; import com.vaadin.shared.communication.PushMode; import com.vaadin.shared.ui.ui.Transport; @@ -35,12 +31,18 @@ import com.vaadin.spring.annotation.SpringUI; // Vaadin. @SuppressWarnings({ "squid:MaximumInheritanceDepth" }) public class MyUI extends HawkbitUI { - private static final long serialVersionUID = 1L; - @Autowired - public MyUI(final ScheduledExecutorService scheduledExecutorService, final EventBus systemEventBus, - final org.vaadin.spring.events.EventBus.SessionEventBus eventBus, final UIEventProvider provider) { - super(new DelayedEventBusPushStrategy(scheduledExecutorService, eventBus, systemEventBus, provider)); + /** + * Constructor + * + * @param pushStrategy + * the push strategy + * @param eventBus + * the event bus + */ + public MyUI(final EventPushStrategy pushStrategy, final SessionEventBus eventBus) { + super(pushStrategy, eventBus); } + } diff --git a/examples/hawkbit-example-core-feign-client/pom.xml b/examples/hawkbit-example-core-feign-client/pom.xml index c41f7953d..4121cd095 100644 --- a/examples/hawkbit-example-core-feign-client/pom.xml +++ b/examples/hawkbit-example-core-feign-client/pom.xml @@ -22,7 +22,7 @@ - com.netflix.feign + io.github.openfeign feign-core @@ -46,7 +46,7 @@ slf4j-api - com.netflix.feign + io.github.openfeign feign-slf4j diff --git a/examples/hawkbit-example-ddi-feign-client/pom.xml b/examples/hawkbit-example-ddi-feign-client/pom.xml index 3797d609b..d1ab01df6 100644 --- a/examples/hawkbit-example-ddi-feign-client/pom.xml +++ b/examples/hawkbit-example-ddi-feign-client/pom.xml @@ -41,11 +41,11 @@ guava - com.netflix.feign + io.github.openfeign feign-core - com.netflix.feign + io.github.openfeign feign-jackson diff --git a/examples/hawkbit-example-mgmt-feign-client/pom.xml b/examples/hawkbit-example-mgmt-feign-client/pom.xml index 7e96e3b00..3d0a69bc7 100644 --- a/examples/hawkbit-example-mgmt-feign-client/pom.xml +++ b/examples/hawkbit-example-mgmt-feign-client/pom.xml @@ -36,12 +36,11 @@ guava - com.netflix.feign + io.github.openfeign feign-core - - com.netflix.feign + io.github.openfeign feign-jackson diff --git a/examples/pom.xml b/examples/pom.xml index aca34785c..60c82cdd4 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -20,7 +20,7 @@ hawkbit-examples-parent hawkBit-example :: Parent pom - + repo.eclipse.org @@ -42,22 +42,4 @@ hawkbit-example-mgmt-feign-client hawkbit-example-mgmt-simulator - - - - - org.springframework.cloud - spring-cloud-dependencies - Brixton.SR5 - pom - import - - - com.netflix.feign - feign-jackson - 8.16.2 - - - - \ No newline at end of file diff --git a/hawkbit-autoconfigure/pom.xml b/hawkbit-autoconfigure/pom.xml index 044e6aece..7eb1b6d3a 100644 --- a/hawkbit-autoconfigure/pom.xml +++ b/hawkbit-autoconfigure/pom.xml @@ -26,13 +26,7 @@ ${project.version} true - - org.eclipse.hawkbit - hawkbit-cache-redis - ${project.version} - true - - + org.eclipse.hawkbit hawkbit-dmf-amqp ${project.version} @@ -83,5 +77,15 @@ spring-boot-configuration-processor true + + io.protostuff + protostuff-core + true + + + io.protostuff + protostuff-runtime + true + diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java index 2d61624cf..4090b44de 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java @@ -8,17 +8,21 @@ */ package org.eclipse.hawkbit.autoconfigure.cache; +import static com.google.common.cache.CacheBuilder.newBuilder; + import java.util.Collection; +import java.util.concurrent.Callable; import java.util.stream.Collectors; import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; -import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.guava.GuavaCacheManager; import org.springframework.cache.interceptor.CacheOperationInvocationContext; @@ -27,6 +31,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; +import com.google.common.cache.CacheBuilder; + /** * A configuration for configuring the spring {@link CacheManager} for specific * multi-tenancy caching. The caches between tenants must not interfere each @@ -37,33 +43,58 @@ import org.springframework.context.annotation.Primary; */ @Configuration @EnableCaching -public class CacheAutoConfiguration extends CachingConfigurerSupport { +public class CacheAutoConfiguration { @Autowired private TenantAware tenantAware; + @Autowired + @Qualifier("directCacheManager") + private CacheManager directCacheManager; + /** * @return the default cache manager bean if none other cache manager is * existing. */ - @Override @Bean @ConditionalOnMissingBean @Primary public TenancyCacheManager cacheManager() { - return new TenantAwareCacheManager(directCacheManager(), tenantAware); + return new TenantAwareCacheManager(directCacheManager, tenantAware); } /** - * @return the direct cache manager to access without tenant aware check, - * cause in sometimes it's necessary to access the cache directly - * without having the current tenant, e.g. initial creation of - * tenant + * A separate configuration of the direct cache manager for the + * {@link TenantAwareCacheManager} that it can get overridden by another + * configuration. */ - @Bean(name = "directCacheManager") - @ConditionalOnMissingBean(name = "directCacheManager") - public CacheManager directCacheManager() { - return new GuavaCacheManager(); + @Configuration + @EnableConfigurationProperties(CacheProperties.class) + static class DirectCacheManagerConfiguration { + + @Autowired + private CacheProperties cacheProperties; + + /** + * @return the direct cache manager to access without tenant aware + * check, cause in sometimes it's necessary to access the cache + * directly without having the current tenant, e.g. initial + * creation of tenant + */ + @Bean(name = "directCacheManager") + @ConditionalOnMissingBean(name = "directCacheManager") + public CacheManager directCacheManager() { + final GuavaCacheManager cacheManager = new GuavaCacheManager(); + + if (cacheProperties.getTtl() > 0) { + final CacheBuilder cacheBuilder = newBuilder() + .expireAfterWrite(cacheProperties.getTtl(), cacheProperties.getTtlUnit()); + cacheManager.setCacheBuilder(cacheBuilder); + } + + return cacheManager; + } + } /** @@ -198,6 +229,11 @@ public class CacheAutoConfiguration extends CachingConfigurerSupport { delegate.clear(); } + @Override + public T get(final Object key, final Callable valueLoader) { + return delegate.get(key, valueLoader); + } + } } diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheProperties.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheProperties.java new file mode 100644 index 000000000..22087b8c0 --- /dev/null +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheProperties.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.autoconfigure.cache; + +import static java.util.concurrent.TimeUnit.MILLISECONDS; + +import java.util.concurrent.TimeUnit; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Properties for configuring the cache within a cluster. The TTL (time to live) + * is used for the lifetime limit of data in caches. After lifetime the data + * gets reloaded out of the database. + */ +@ConfigurationProperties("hawkbit.cache.global") +public class CacheProperties { + + /** + * TTL for cached entries in millis. + */ + private int ttl; + + /** + * Initial delay in millis + */ + private int initialDelay; + + public long getInitialDelay() { + return initialDelay; + } + + public void setInitialDelay(final int initialDelay) { + this.initialDelay = initialDelay; + } + + public int getTtl() { + return ttl; + } + + public void setTtl(final int ttl) { + this.ttl = ttl; + } + + public final TimeUnit getTtlUnit() { + return MILLISECONDS; + } +} diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/DownloadIdCacheAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/DownloadIdCacheAutoConfiguration.java index 134b50d90..144135b94 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/DownloadIdCacheAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/DownloadIdCacheAutoConfiguration.java @@ -8,10 +8,10 @@ */ package org.eclipse.hawkbit.autoconfigure.cache; -import org.eclipse.hawkbit.cache.CacheConstants; -import org.eclipse.hawkbit.cache.TenancyCacheManager; +import org.eclipse.hawkbit.cache.DefaultDownloadIdCache; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.Cache; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.cache.CacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -20,9 +20,6 @@ import org.springframework.context.annotation.Configuration; * A configuration for configuring a cache for the download id's. * * This is done by providing a named cache. - * - * - * */ @Configuration public class DownloadIdCacheAutoConfiguration { @@ -31,16 +28,18 @@ public class DownloadIdCacheAutoConfiguration { private CacheManager cacheManager; /** - * Bean for the download id cache. + * Bean for the downloadId cache that returns the DefaultDownloadIdCache. + * The DefaultDownloadIdCache cannot be used within a cluster because the + * downloadId cache is not shared among notes. This means, a downloadId + * which is stored on note A for downloading an artifact can only be used + * for downloading the artifact form node A. * - * @return the cache + * @return the DefaultDownloadIdCache */ - @Bean(name = CacheConstants.DOWNLOAD_ID_CACHE) - public Cache downloadIdCache() { - if (cacheManager instanceof TenancyCacheManager) { - return ((TenancyCacheManager) cacheManager).getDirectCache(CacheConstants.DOWNLOAD_ID_CACHE); - } - return cacheManager.getCache(CacheConstants.DOWNLOAD_ID_CACHE); + @Bean + @ConditionalOnMissingBean + public DownloadIdCache downloadIdCache() { + return new DefaultDownloadIdCache(cacheManager); } } diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/RedisAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/RedisAutoConfiguration.java deleted file mode 100644 index a6c1062e3..000000000 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/RedisAutoConfiguration.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.autoconfigure.cache; - -import org.eclipse.hawkbit.cache.RedisConfiguration; -import org.eclipse.hawkbit.cache.annotation.EnableRedis; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.context.annotation.Configuration; - -/** - * A configuration for configuring the redis configuration. - * - * - * - */ -@Configuration -@ConditionalOnClass(value = RedisConfiguration.class) -@EnableRedis -public class RedisAutoConfiguration { - -} diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/event/EventPublisherAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/event/EventPublisherAutoConfiguration.java new file mode 100644 index 000000000..ebca0308d --- /dev/null +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/event/EventPublisherAutoConfiguration.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.autoconfigure.event; + +import java.util.concurrent.Executor; + +import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter; +import org.eclipse.hawkbit.repository.event.remote.RemoteTenantAwareEvent; +import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; +import org.eclipse.hawkbit.tenancy.TenantAware; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.cloud.bus.ConditionalOnBusEnabled; +import org.springframework.cloud.bus.ServiceMatcher; +import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.event.ApplicationEventMulticaster; +import org.springframework.context.event.SimpleApplicationEventMulticaster; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.core.ResolvableType; +import org.springframework.messaging.converter.MessageConverter; + +import io.protostuff.ProtostuffIOUtil; +import io.protostuff.Schema; + +/** + * Auto configuration for the event bus. + * + */ +@Configuration +@RemoteApplicationEventScan(basePackages = "org.eclipse.hawkbit.repository.event.remote") +public class EventPublisherAutoConfiguration { + + @Autowired + @Qualifier("asyncExecutor") + private Executor executor; + + @Autowired + private TenantAware tenantAware; + + /** + * Server internal event publisher that allows parallel event processing if + * the event listener is marked as so. + * + * @return publisher bean + */ + @Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME) + public ApplicationEventMulticaster applicationEventMulticaster() { + final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new TenantAwareApplicationEventPublisher( + tenantAware); + simpleApplicationEventMulticaster.setTaskExecutor(executor); + return simpleApplicationEventMulticaster; + } + + /** + * Bean for creating a singleton instance of the + * {@link EventPublisherHolder} + * + * @return the singleton instance of the {@link EventPublisherHolder} + */ + @Bean + public EventPublisherHolder eventBusHolder() { + return EventPublisherHolder.getInstance(); + } + + private static class TenantAwareApplicationEventPublisher extends SimpleApplicationEventMulticaster { + + private final TenantAware tenantAware; + + @Autowired(required = false) + private ServiceMatcher serviceMatcher; + + /** + * Constructor. + * + * @param tenantAware + * the tenant ware + */ + protected TenantAwareApplicationEventPublisher(final TenantAware tenantAware) { + this.tenantAware = tenantAware; + } + + /** + * Was overridden that not every event has to run within a own + * tenantAware. + */ + @Override + public void multicastEvent(final ApplicationEvent event, final ResolvableType eventType) { + if (serviceMatcher == null || !(event instanceof RemoteTenantAwareEvent)) { + super.multicastEvent(event, eventType); + return; + } + final RemoteTenantAwareEvent remoteEvent = (RemoteTenantAwareEvent) event; + + if (serviceMatcher.isFromSelf(remoteEvent)) { + super.multicastEvent(event, eventType); + return; + } + + tenantAware.runAsTenant(remoteEvent.getTenant(), () -> { + super.multicastEvent(event, eventType); + return null; + }); + } + + } + + @ConditionalOnBusEnabled + @ConditionalOnClass({ Schema.class, ProtostuffIOUtil.class }) + protected static class BusProtoStuffAutoConfiguration { + /** + * + * @return the protostuff io message converter + */ + @Bean + public MessageConverter busProtoBufConverter() { + return new BusProtoStuffMessageConverter(); + } + + } + +} diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/eventbus/EventBusAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/eventbus/EventBusAutoConfiguration.java deleted file mode 100644 index c0cbabb08..000000000 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/eventbus/EventBusAutoConfiguration.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.autoconfigure.eventbus; - -import java.util.concurrent.Executor; - -import org.eclipse.hawkbit.eventbus.EventBusSubscriberProcessor; -import org.eclipse.hawkbit.eventbus.EventSubscriber; -import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.google.common.eventbus.AsyncEventBus; -import com.google.common.eventbus.EventBus; - -/** - * Auto configuration for the event bus. - * - */ -@Configuration -public class EventBusAutoConfiguration { - - @Autowired - @Qualifier("asyncExecutor") - private Executor executor; - - /** - * Server internal eventBus that allows parallel event processing if the - * subscriber is marked as so. - * - * @return eventbus bean - */ - @Bean - @ConditionalOnMissingBean - public EventBus eventBus() { - return new AsyncEventBus(executor); - } - - /** - * @return the {@link EventBusSubscriberProcessor} to find classes annotated - * with {@link EventSubscriber}. - */ - @Bean - @ConditionalOnMissingBean - public EventBusSubscriberProcessor eventBusSubscriberProcessor() { - return new EventBusSubscriberProcessor(); - } - - /** - * @return the singleton instance of the {@link EventBusHolder} - */ - @Bean - public EventBusHolder eventBusHolder() { - return EventBusHolder.getInstance(); - } - -} diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java index 245e4d57a..c2a2e8759 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/repository/JpaRepositoryAutoConfiguration.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.autoconfigure.repository; import org.eclipse.hawkbit.EnableJpaRepository; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; -import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyResolver; +import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java index 565b1520a..0cb8f0027 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/security/SecurityManagedConfiguration.java @@ -23,7 +23,7 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import org.eclipse.hawkbit.ExcludePathAwareShallowETagFilter; -import org.eclipse.hawkbit.cache.CacheConstants; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.im.authentication.TenantUserPasswordAuthenticationToken; @@ -47,12 +47,10 @@ import org.eclipse.hawkbit.tenancy.TenantAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.security.SecurityProperties; import org.springframework.boot.context.embedded.FilterRegistrationBean; import org.springframework.boot.context.embedded.ServletListenerRegistrationBean; -import org.springframework.cache.Cache; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; @@ -436,8 +434,7 @@ public class SecurityManagedConfiguration { private DdiSecurityProperties ddiSecurityConfiguration; @Autowired - @Qualifier(CacheConstants.DOWNLOAD_ID_CACHE) - private Cache downloadIdCache; + private DownloadIdCache downloadIdCache; @Override protected void configure(final HttpSecurity http) throws Exception { diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java index 1dff4223f..ea98d52a3 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/ui/UIAutoConfiguration.java @@ -9,15 +9,20 @@ package org.eclipse.hawkbit.autoconfigure.ui; import org.eclipse.hawkbit.DistributedResourceBundleMessageSource; +import org.eclipse.hawkbit.ui.push.DelayedEventBusPushStrategy; +import org.eclipse.hawkbit.ui.push.EventPushStrategy; import org.eclipse.hawkbit.ui.push.HawkbitEventProvider; import org.eclipse.hawkbit.ui.push.UIEventProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.vaadin.spring.annotation.EnableVaadinExtensions; import org.vaadin.spring.events.annotation.EnableEventBus; import org.vaadin.spring.security.annotation.EnableVaadinSecurity; +import com.vaadin.spring.annotation.UIScope; + /** * The hawkbit-ui autoconfiguration. */ @@ -48,4 +53,22 @@ public class UIAutoConfiguration { return new HawkbitEventProvider(); } + /** + * The UI scoped event push strategy. Session scope is necessary, that every + * UI has an own strategy. + * + * @param applicationContext + * the context to add the listener + * + * @return the provider bean + */ + @Bean + @ConditionalOnMissingBean + @UIScope + public EventPushStrategy eventPushStrategy(final ConfigurableApplicationContext applicationContext) { + final DelayedEventBusPushStrategy delayedEventBusPushStrategy = new DelayedEventBusPushStrategy(); + applicationContext.addApplicationListener(delayedEventBusPushStrategy); + return delayedEventBusPushStrategy; + } + } diff --git a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/web/WebMvcAutoConfiguration.java b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/web/WebMvcAutoConfiguration.java index 03140f302..37431a554 100644 --- a/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/web/WebMvcAutoConfiguration.java @@ -24,28 +24,12 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @Configuration public class WebMvcAutoConfiguration extends WebMvcConfigurerAdapter { - /* - * (non-Javadoc) - * - * @see - * org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter - * #configurePathMatch - * (org.springframework.web.servlet.config.annotation.PathMatchConfigurer) - */ @Override public void configurePathMatch(final PathMatchConfigurer configurer) { configurer.setUseSuffixPatternMatch(false); configurer.setUseRegisteredSuffixPatternMatch(false); } - /* - * (non-Javadoc) - * - * @see org.springframework.web.servlet.config.annotation. - * WebMvcConfigurerAdapter# configureContentNegotiation - * (org.springframework.web.servlet.config.annotation. - * ContentNegotiationConfigurer) - */ @Override public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) { configurer.favorPathExtension(false); diff --git a/hawkbit-autoconfigure/src/main/resources/META-INF/spring.factories b/hawkbit-autoconfigure/src/main/resources/META-INF/spring.factories index 7df1f5ed2..176c84bb0 100644 --- a/hawkbit-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/hawkbit-autoconfigure/src/main/resources/META-INF/spring.factories @@ -7,9 +7,8 @@ org.eclipse.hawkbit.autoconfigure.url.PropertyHostnameResolverAutoConfiguration, org.eclipse.hawkbit.autoconfigure.web.WebMvcAutoConfiguration,\ org.eclipse.hawkbit.autoconfigure.cache.CacheAutoConfiguration,\ org.eclipse.hawkbit.autoconfigure.cache.DownloadIdCacheAutoConfiguration,\ -org.eclipse.hawkbit.autoconfigure.eventbus.EventBusAutoConfiguration,\ +org.eclipse.hawkbit.autoconfigure.event.EventPublisherAutoConfiguration,\ org.eclipse.hawkbit.autoconfigure.scheduling.AsyncConfigurerAutoConfiguration,\ -org.eclipse.hawkbit.autoconfigure.cache.RedisAutoConfiguration,\ org.eclipse.hawkbit.autoconfigure.scheduling.ExecutorAutoConfiguration,\ org.eclipse.hawkbit.autoconfigure.amqp.AmqpAutoConfiguration,\ org.eclipse.hawkbit.autoconfigure.security.InMemoryUserManagementConfiguration diff --git a/hawkbit-autoconfigure/src/main/resources/hawkbitdefaults.properties b/hawkbit-autoconfigure/src/main/resources/hawkbitdefaults.properties index c57380e7c..935618296 100644 --- a/hawkbit-autoconfigure/src/main/resources/hawkbitdefaults.properties +++ b/hawkbit-autoconfigure/src/main/resources/hawkbitdefaults.properties @@ -14,6 +14,19 @@ security.basic.realm=HawkBit security.user.name=admin security.user.password=admin +# Spring cloud bus and stream +spring.cloud.bus.enabled=false +# Disable Cloud Bus default events +spring.cloud.bus.env.enabled=false +spring.cloud.bus.ack.enabled=false +spring.cloud.bus.trace.enabled=false +spring.cloud.bus.refresh.enabled=false +# Disable Cloud Bus endpoints +endpoints.spring.cloud.bus.refresh.enabled=false +endpoints.spring.cloud.bus.env.enabled=false +# Spring cloud bus and stream END + + ### JPA / Datasource - START spring.jpa.database=H2 spring.jpa.show-sql=false diff --git a/hawkbit-cache-redis/pom.xml b/hawkbit-cache-redis/pom.xml deleted file mode 100644 index 637a6b49f..000000000 --- a/hawkbit-cache-redis/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - 4.0.0 - - org.eclipse.hawkbit - hawkbit-parent - 0.2.0-SNAPSHOT - - hawkbit-cache-redis - hawkBit :: Redis Cache Manager - - - - org.eclipse.hawkbit - hawkbit-core - ${project.version} - - - org.springframework.data - spring-data-redis - - - org.springframework.boot - spring-boot - - - redis.clients - jedis - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - - - org.eclipse.hawkbit - hawkbit-repository-api - ${project.version} - test - - - org.springframework.boot - spring-boot-starter-test - test - - - org.easytesting - fest-assert-core - test - - - org.easytesting - fest-assert - test - - - org.springframework.hateoas - spring-hateoas - test - - - ru.yandex.qatools.allure - allure-junit-adaptor - test - - - - \ No newline at end of file diff --git a/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/RedisConfiguration.java b/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/RedisConfiguration.java deleted file mode 100644 index d9f759da3..000000000 --- a/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/RedisConfiguration.java +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.cache; - -import org.eclipse.hawkbit.cache.eventbus.EventDistributor; -import org.eclipse.hawkbit.tenancy.TenantAware; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cache.CacheManager; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Primary; -import org.springframework.data.redis.cache.RedisCacheManager; -import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.listener.RedisMessageListenerContainer; -import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; -import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; - -/** - * The spring Redis configuration which is enabled by using the profile - * {@code redis} to use a Redis server as cache. - * - */ -@Configuration -@EnableConfigurationProperties(RedisProperties.class) -public class RedisConfiguration { - - @Autowired - private RedisProperties redisProperties; - - @Autowired - private TenantAware tenantAware; - - /** - * @return the {@link EventDistributor} to distribute and consume the events - * from Redis - */ - @Bean - public EventDistributor eventDistributor() { - return new EventDistributor(); - } - - /** - * @return the spring redis cache manager. - */ - @Bean - @Primary - public CacheManager cacheManager() { - return new TenantAwareCacheManager(directCacheManager(), tenantAware); - } - - /** - * - * @return bean for the direct cache manager. - */ - @Bean(name = "directCacheManager") - public CacheManager directCacheManager() { - return new RedisCacheManager(redisTemplate()); - } - - /** - * @return the redis connection factory to create a redis connection based - * on the {@link RedisProperties} - */ - @Bean - public JedisConnectionFactory jedisConnectionFactory() { - final JedisConnectionFactory factory = new JedisConnectionFactory(); - factory.setHostName(redisProperties.getHost()); - factory.setPort(redisProperties.getPort()); - factory.setUsePool(true); - return factory; - } - - /** - * @return the spring {@link RedisTemplate} configured with the necessary - * object serializers - */ - @Bean - public RedisTemplate redisTemplate() { - final RedisTemplate redisTemplate = new RedisTemplate<>(); - redisTemplate.setConnectionFactory(jedisConnectionFactory()); - redisTemplate.setKeySerializer(new JdkSerializationRedisSerializer()); - redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer()); - redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); - return redisTemplate; - } - - /** - * @return the spring-redis message listener adapter to consume messages - * from the Redis server - */ - @Bean - public MessageListenerAdapter messageListenerAdapter() { - final MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(eventDistributor()); - messageListenerAdapter.setSerializer(new JdkSerializationRedisSerializer()); - return messageListenerAdapter; - } - - /** - * @return the spring-redis message listener container to register the - * message listener adapter - */ - @Bean - public RedisMessageListenerContainer redisContainer() { - final RedisMessageListenerContainer container = new RedisMessageListenerContainer(); - container.setConnectionFactory(jedisConnectionFactory()); - container.addMessageListener(messageListenerAdapter(), eventDistributor().getTopics()); - return container; - } - -} diff --git a/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/RedisProperties.java b/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/RedisProperties.java deleted file mode 100644 index ab409bbf5..000000000 --- a/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/RedisProperties.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.cache; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * Bean which holds the necessary properties for configuring the Redis - * connection. - * - */ -@ConfigurationProperties("hawkbit.server.redis") -public class RedisProperties { - - /** - * Redis server hostname. - */ - private String host; - - /** - * Redis server port. - */ - private int port; - - /** - * @return the host - */ - public String getHost() { - return host; - } - - /** - * @param host - * the host to set - */ - public void setHost(final String host) { - this.host = host; - } - - /** - * @return the port - */ - public int getPort() { - return port; - } - - /** - * @param port - * the port to set - */ - public void setPort(final int port) { - this.port = port; - } -} diff --git a/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/annotation/EnableRedis.java b/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/annotation/EnableRedis.java deleted file mode 100644 index eb88a6d9d..000000000 --- a/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/annotation/EnableRedis.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.cache.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.eclipse.hawkbit.cache.RedisConfiguration; -import org.springframework.context.annotation.Import; - -/** - * Annotation to enable redis caching. - * - * - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Import(RedisConfiguration.class) -public @interface EnableRedis { - -} diff --git a/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/eventbus/EventDistributor.java b/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/eventbus/EventDistributor.java deleted file mode 100644 index 4640de88d..000000000 --- a/hawkbit-cache-redis/src/main/java/org/eclipse/hawkbit/cache/eventbus/EventDistributor.java +++ /dev/null @@ -1,140 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.cache.eventbus; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; - -import org.eclipse.hawkbit.eventbus.EventSubscriber; -import org.eclipse.hawkbit.eventbus.event.DistributedEvent; -import org.eclipse.hawkbit.eventbus.event.Event; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.listener.PatternTopic; -import org.springframework.data.redis.listener.Topic; -import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; -import org.springframework.stereotype.Service; - -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -/** - * The distributor for events. - * - */ -@EventSubscriber -@Service -public class EventDistributor { - - private static final Logger LOGGER = LoggerFactory.getLogger(EventDistributor.class); - /** - * the node id to filter self published events in the redis message - * subscriber. - */ - private static final String NODE_ID = UUID.randomUUID().toString(); - - private static final String DISTRIBUTION_CHANNEL_TOPIC = "com/bosch/sp/distEvent"; - private static final String SEND_DISTRIBUTION_CHANNEL = DISTRIBUTION_CHANNEL_TOPIC + "/" + NODE_ID; - private static final String SUB_DISTRIBUTION_CHANNEL = DISTRIBUTION_CHANNEL_TOPIC + "*"; - - @Autowired(required = false) - private RedisTemplate redisTemplate; - - @Autowired - private EventBus eventBus; - - /** - * consumes all {@link DistributedEvent}s posted on the {@link EventBus} and - * distribute them to the Redis server. - * - * @param event - * the distributed event posted on the {@link EventBus} - */ - @Subscribe - public void distribute(final DistributedEvent event) { - if (redisTemplate != null) { - if (!NODE_ID.equals(event.getNodeId())) { - logDistributingEvent(event, SEND_DISTRIBUTION_CHANNEL); - event.setOriginNodeId(NODE_ID); - redisTemplate.convertAndSend(SEND_DISTRIBUTION_CHANNEL, event); - } - } else { - logNotDistributingEvent(event, SEND_DISTRIBUTION_CHANNEL); - } - } - - /** - * message listener callback method for the {@link MessageListenerAdapter} - * which calls the method in case a message is received from the Redis - * server of the type {@link DistributedEventWrapper}. - * - * @param event - * the {@link DistributedEventWrapper} event which was received - * by the Redis client - * @param channel - * the on which the event was received - */ - public void handleMessage(final DistributedEvent event, final String channel) { - LOGGER.trace("retrieving event from redis {} on channel {}, posting to the local event bus", event, channel); - if (!NODE_ID.equals(event.getOriginNodeId())) { - event.setNodeId(NODE_ID); - eventBus.post(event); - } - } - - /** - * @return a collection of all topics which this Redis message listener - * wants to subscribe - */ - public Collection getTopics() { - final List topics = new ArrayList<>(); - topics.add(new PatternTopic(SUB_DISTRIBUTION_CHANNEL)); - return topics; - } - - private static void logDistributingEvent(final Event event, final String channel) { - LOGGER.trace("distributing event {} from node {} to topic {}", event, NODE_ID, channel); - } - - private static void logNotDistributingEvent(final Event event, final String channel) { - LOGGER.debug("no redis template configured, event {} will not be distributed to channel {} from node {}", event, - channel, NODE_ID); - } - - /** - * testing purposes. - * - * @param redisTemplate - * the redisTemplate to set - */ - void setRedisTemplate(final RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } - - /** - * testing purposes. - * - * @param eventBus - * the eventBus to set - */ - void setEventBus(final EventBus eventBus) { - this.eventBus = eventBus; - } - - /** - * @return the nodeId - */ - static String getNodeId() { - return NODE_ID; - } -} diff --git a/hawkbit-cache-redis/src/test/java/org/eclipse/hawkbit/cache/eventbus/EventDistributorTest.java b/hawkbit-cache-redis/src/test/java/org/eclipse/hawkbit/cache/eventbus/EventDistributorTest.java deleted file mode 100644 index bebd82484..000000000 --- a/hawkbit-cache-redis/src/test/java/org/eclipse/hawkbit/cache/eventbus/EventDistributorTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.cache.eventbus; - -import static org.fest.assertions.api.Assertions.assertThat; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import java.util.Collection; - -import org.eclipse.hawkbit.eventbus.event.EntityEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.listener.Topic; -import org.springframework.hateoas.Identifiable; - -import com.google.common.eventbus.EventBus; - -import ru.yandex.qatools.allure.annotations.Features; -import ru.yandex.qatools.allure.annotations.Stories; - -@Features("Unit Tests - Cluster Cache") -@Stories("EventDistributor Test") -@RunWith(MockitoJUnitRunner.class) -// TODO: create description annotations -public class EventDistributorTest { - - @Mock - private RedisTemplate redisTemplateMock; - - @Mock - private EventBus eventBusMock; - - private EventDistributor underTest; - - @Before - public void before() { - underTest = new EventDistributor(); - underTest.setEventBus(eventBusMock); - underTest.setRedisTemplate(redisTemplateMock); - } - - @Test - public void distributeDistributedEventSendsToRedis() { - - final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 500L, 100L, 200L); - underTest.distribute(event); - - // origin node ID should be set by distributing the event - assertThat(event.getOriginNodeId()).isNotNull(); - verify(redisTemplateMock).convertAndSend(anyString(), eq(event)); - } - - @Test - public void dontDistributeDistributedEventIfSameNode() { - final String knownNodeId = EventDistributor.getNodeId(); - final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 500L, 100L, 200L); - event.setNodeId(knownNodeId); - - // test - underTest.distribute(event); - - assertThat(event.getOriginNodeId()).isNull(); - verify(redisTemplateMock, times(0)).convertAndSend(anyString(), eq(event)); - } - - @Test - public void handleDistributedMessageFromRedis() { - final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 500L, 100L, 200L); - final String knownChannel = "someChannel"; - - underTest.handleMessage(event, knownChannel); - - assertThat(event.getNodeId()).isEqualTo(EventDistributor.getNodeId()); - verify(eventBusMock).post(eq(event)); - } - - @Test - public void handleDistributedMessageFilteredIfSameNodeId() { - final DownloadProgressEvent event = new DownloadProgressEvent("tenant", 123L, 500L, 100L, 200L); - final String knownChannel = "someChannel"; - event.setOriginNodeId(EventDistributor.getNodeId()); - - underTest.handleMessage(event, knownChannel); - - assertThat(event.getNodeId()).isNull(); - verify(eventBusMock, times(0)).post(eq(event)); - } - - @Test - public void subscribedTopicsContains2PatternTopics() { - final Collection topics = underTest.getTopics(); - assertThat(topics).hasSize(1); - } - - private class TestEntityEvent implements EntityEvent { - - private String originNodeId; - private String nodeId; - private final String tenant; - private final MyEntity entity; - - /** - * @param myEntity - */ - public TestEntityEvent(final MyEntity myEntity, final String tenant) { - this.entity = myEntity; - this.tenant = tenant; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.eventbus.event.Event#getRevision() - */ - @Override - public long getRevision() { - return 0; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.NodeAware#getOriginNodeId() - */ - @Override - public String getOriginNodeId() { - return originNodeId; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.NodeAware#setOriginNodeId( - * java. lang.String) - */ - @Override - public void setOriginNodeId(final String originNodeId) { - this.originNodeId = originNodeId; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.eventbus.event.NodeAware#getNodeId() - */ - @Override - public String getNodeId() { - return nodeId; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.NodeAware#setNodeId(java. - * lang. String) - */ - @Override - public void setNodeId(final String nodeId) { - this.nodeId = nodeId; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.EntityEvent#getEntity(java. - * lang. Class) - */ - @Override - public E getEntity(final Class entityClass) { - return entityClass.cast(entity); - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.EntityEvent#getEntity() - */ - @Override - public Object getEntity() { - return entity; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.EntityEvent#getTenant() - */ - @Override - public String getTenant() { - return tenant; - } - } - - private class MyEntity implements Identifiable { - private final String id = "123"; - - /* - * (non-Javadoc) - * - * @see org.springframework.hateoas.Identifiable#getId() - */ - @Override - public String getId() { - return id; - } - } - -} diff --git a/hawkbit-cache-redis/src/test/java/org/eclipse/hawkbit/cache/redis/RedisPropertiesTest.java b/hawkbit-cache-redis/src/test/java/org/eclipse/hawkbit/cache/redis/RedisPropertiesTest.java deleted file mode 100644 index ab57dd541..000000000 --- a/hawkbit-cache-redis/src/test/java/org/eclipse/hawkbit/cache/redis/RedisPropertiesTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.cache.redis; - -import static org.fest.assertions.api.Assertions.assertThat; - -import org.eclipse.hawkbit.cache.RedisProperties; -import org.junit.Test; - -import ru.yandex.qatools.allure.annotations.Features; -import ru.yandex.qatools.allure.annotations.Stories; - -@Features("Unit Tests - Cluster Cache") -@Stories("Redis Properties Test") -public class RedisPropertiesTest { - - @Test - public void setAndGetProps() { - final String knownHost = "bumlux"; - final int knownPort = 1234; - - final RedisProperties underTest = new RedisProperties(); - underTest.setHost(knownHost); - underTest.setPort(knownPort); - - assertThat(underTest.getHost()).isEqualTo(knownHost); - assertThat(underTest.getPort()).isEqualTo(knownPort); - } - -} diff --git a/hawkbit-core/pom.xml b/hawkbit-core/pom.xml index b8f339a01..d962aa096 100644 --- a/hawkbit-core/pom.xml +++ b/hawkbit-core/pom.xml @@ -53,6 +53,16 @@ allure-junit-adaptor test + + org.easytesting + fest-assert-core + test + + + org.easytesting + fest-assert + test + org.springframework.boot spring-boot-configuration-processor diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCache.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCache.java new file mode 100644 index 000000000..5750f609d --- /dev/null +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCache.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.cache; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.Cache; +import org.springframework.cache.Cache.ValueWrapper; +import org.springframework.cache.CacheManager; + +/** + * A default implementation of the {@link DownloadIdCache} which uses the + * {@link CacheManager} implementation to store the download-ids. + */ +public class DefaultDownloadIdCache implements DownloadIdCache { + + static final String DOWNLOAD_ID_CACHE = "DowonloadIdCache"; + + private final CacheManager cacheManager; + + /** + * @param cacheManager + * the underlying cache-manager to store the download-ids + */ + @Autowired + public DefaultDownloadIdCache(final CacheManager cacheManager) { + this.cacheManager = cacheManager; + } + + @Override + public void put(final String downloadId, final DownloadArtifactCache object) { + getCache().put(downloadId, object); + } + + @Override + public DownloadArtifactCache get(final String downloadId) { + final ValueWrapper valueWrapper = getCache().get(downloadId); + return (valueWrapper == null) ? null : (DownloadArtifactCache) valueWrapper.get(); + } + + @Override + public void evict(final String downloadId) { + getCache().evict(downloadId); + } + + private Cache getCache() { + if (cacheManager instanceof TenancyCacheManager) { + return ((TenancyCacheManager) cacheManager).getDirectCache(DOWNLOAD_ID_CACHE); + } + return cacheManager.getCache(DOWNLOAD_ID_CACHE); + } +} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadArtifactCache.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadArtifactCache.java index b533b0058..9dbc50b26 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadArtifactCache.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadArtifactCache.java @@ -9,10 +9,7 @@ package org.eclipse.hawkbit.cache; /** - * Cache Object for download a Artifact. - * - * - * + * Cache Object for downloading an artifact. */ public class DownloadArtifactCache { @@ -21,7 +18,7 @@ public class DownloadArtifactCache { /** * Constructor. - * + * * @param downloadType * the type for searching the artifact. * @param id diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadIdCache.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadIdCache.java new file mode 100644 index 000000000..77dcb714d --- /dev/null +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadIdCache.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.cache; + +/** + * A interface declaration of the download-id-cache which allows to store + * volatile generated download-IDs used to have a single unique download-request + * e.g. for distributed download-server. + * + * A valid download-id is created during a successful download-authorization + * request e.g. from a download-server. In the DMF response a unique + * download-URL containing a generated download-id which can be used to download + * the artifact using this single download-url. + * + * The {@link DownloadIdCache} handles storing this unique download-id from the + * DMF authorization request until the actual artifact download-request via HTTP + * with the unique ID is performed. + * + */ +public interface DownloadIdCache { + + /** + * Puts a given artifact cache object with the given downloadId key into the + * cache. + * + * @param downloadId + * the ID to store the cache object to look it up later on + * @param downloadArtifactCacheObject + * the object to store into the cache + */ + void put(final String downloadId, final DownloadArtifactCache downloadArtifactCacheObject); + + /** + * Retrieves a {@link DownloadArtifactCache} by a given downloadId. + * + * @param downloadId + * the ID to retrieve the artifact cache object + * @return the found {@link DownloadArtifactCache} or {@code null} if none + * exists for the given ID + */ + DownloadArtifactCache get(final String downloadId); + + /** + * Evicts a {@link DownloadArtifactCache} for the given downloadId + * + * @param downloadId + * the ID to be evicted + */ + void evict(String downloadId); + +} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadType.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadType.java index 4a78f3e4c..b903fbd1c 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadType.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/DownloadType.java @@ -10,9 +10,6 @@ package org.eclipse.hawkbit.cache; /** * The type of the id which is saved. - * - * - * */ public enum DownloadType { BY_SHA1 diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java index 9338bcbe7..26e744367 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenancyCacheManager.java @@ -12,7 +12,6 @@ import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; /** - * * A cache interface which handles multi tenancy. */ public interface TenancyCacheManager extends CacheManager { @@ -21,7 +20,7 @@ public interface TenancyCacheManager extends CacheManager { * A direct access for retrieving the cache without including the current * tenant key. This is necessary e.g. for retrieving caches not for the * current tenant. - * + * * @param name * the name of the cache to retrieve directly * @return the cache associated with the name without tenancy separation @@ -31,10 +30,9 @@ public interface TenancyCacheManager extends CacheManager { /** * Evicts all caches for a given tenant. All caches under a certain tenant * gets evicted. - * + * * @param tenant * the tenant to evict caches */ void evictCaches(final String tenant); - } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java index 055d9bf6c..142af6778 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/TenantAwareCacheManager.java @@ -8,8 +8,9 @@ */ package org.eclipse.hawkbit.cache; +import static java.util.Collections.emptyList; + import java.util.Collection; -import java.util.Collections; import java.util.stream.Collectors; import org.eclipse.hawkbit.tenancy.TenantAware; @@ -25,10 +26,6 @@ import org.springframework.cache.CacheManager; * * Additionally it also provide functionality to retrieve all caches overall * tenants at once, for monitoring and system access. - * - * - * - * */ public class TenantAwareCacheManager implements TenancyCacheManager { @@ -39,47 +36,45 @@ public class TenantAwareCacheManager implements TenancyCacheManager { private final TenantAware tenantAware; /** + * Constructor. + * * @param delegate * the {@link CacheManager} to delegate to. * @param tenantAware * the tenant aware to retrieve the current tenant */ public TenantAwareCacheManager(final CacheManager delegate, final TenantAware tenantAware) { - this.delegate = delegate; this.tenantAware = tenantAware; + this.delegate = delegate; } @Override public Cache getCache(final String name) { String currentTenant = tenantAware.getCurrentTenant(); - if (currentTenant == null) { + if (isTenantInvalid(currentTenant)) { return null; } currentTenant = currentTenant.toUpperCase(); - if (currentTenant.contains(TENANT_CACHE_DELIMITER)) { - return null; - } - return delegate.getCache(currentTenant + TENANT_CACHE_DELIMITER + name); + + return delegate.getCache(buildKey(currentTenant, name)); } @Override public Collection getCacheNames() { String currentTenant = tenantAware.getCurrentTenant(); - if (currentTenant == null) { - return Collections.emptyList(); + if (isTenantInvalid(currentTenant)) { + return emptyList(); } currentTenant = currentTenant.toUpperCase(); - if (currentTenant.contains(TENANT_CACHE_DELIMITER)) { - return Collections.emptyList(); - } + return getCacheNames(currentTenant); } /** * A direct access for retrieving all cache names overall tenants. - * + * * @return all cache names without tenant check */ public Collection getDirectCacheNames() { @@ -91,17 +86,17 @@ public class TenantAwareCacheManager implements TenancyCacheManager { return delegate.getCache(name); } - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.cache.TenancyCacheManager#evictCaches(java. - * lang. String) - */ @Override public void evictCaches(final String tenant) { - getCacheNames(tenant) - .forEach(cachename -> delegate.getCache(tenant + TENANT_CACHE_DELIMITER + cachename).clear()); + getCacheNames(tenant).forEach(cachename -> delegate.getCache(buildKey(tenant, cachename)).clear()); + } + + private boolean isTenantInvalid(final String tenant) { + return tenant == null || tenant.contains(TENANT_CACHE_DELIMITER); + } + + private String buildKey(final String tenant, final String cacheName) { + return tenant + TENANT_CACHE_DELIMITER + cacheName; } private Collection getCacheNames(final String tenant) { diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/DeadEventListener.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/DeadEventListener.java deleted file mode 100644 index 27e397706..000000000 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/DeadEventListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import com.google.common.eventbus.DeadEvent; -import com.google.common.eventbus.Subscribe; - -/** - * Catches all dead events by means of events with no fitting subscriber on the - * bus. - * - * - * - */ -@EventSubscriber -@Service -public class DeadEventListener { - private static final Logger LOG = LoggerFactory.getLogger(DeadEventListener.class); - - /** - * Listens for dead vents and prints them into LOG. - * - * @param event - * to print - */ - @Subscribe - public void listen(final DeadEvent event) { - LOG.info("DeadEvent on bus! {}", event.getEvent()); - } -} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/EventBusSubscriberProcessor.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/EventBusSubscriberProcessor.java deleted file mode 100644 index f7ce86ef6..000000000 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/EventBusSubscriberProcessor.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus; - -import java.lang.reflect.Method; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.config.BeanPostProcessor; - -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -/** - * An {@link BeanPostProcessor} implementation which registers all beans as a - * event bus subscriber if the classes are annotated with - * {@link EventSubscriber} and have at least one method annotated with the - * guava's {@link Subscribe} annoation. - * - * - */ - -public class EventBusSubscriberProcessor implements BeanPostProcessor { - - private static final Logger LOGGER = LoggerFactory.getLogger(EventBusSubscriberProcessor.class); - - @Autowired - private EventBus eventBus; - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.config.BeanPostProcessor# - * postProcessBeforeInitialization (java.lang.Object, java.lang.String) - */ - @Override - public Object postProcessBeforeInitialization(final Object bean, final String beanName) { - return bean; - } - - /* - * (non-Javadoc) - * - * @see org.springframework.beans.factory.config.BeanPostProcessor# - * postProcessAfterInitialization( java.lang.Object, java.lang.String) - */ - @Override - public Object postProcessAfterInitialization(final Object bean, final String beanName) { - final Class beanClass = bean.getClass(); - final EventSubscriber eventSubscriber = beanClass.getAnnotation(EventSubscriber.class); - if (eventSubscriber != null) { - LOGGER.trace("Found bean {} with {} annotation ", bean.getClass().getName(), - EventSubscriber.class.getSimpleName()); - final Method[] declaredMethods = beanClass.getDeclaredMethods(); - for (final Method method : declaredMethods) { - final Subscribe subscriber = method.getAnnotation(Subscribe.class); - if (subscriber != null) { - LOGGER.trace("Found method {} for bean {} with {} annotation", method.getName(), - bean.getClass().getName(), Subscribe.class.getSimpleName()); - eventBus.register(bean); - return bean; - } - } - } - if (eventSubscriber != null) { - LOGGER.debug("Found bean {} with {} annotation but without any method with necessary {} annotation", - bean.getClass().getName(), EventSubscriber.class.getSimpleName(), Subscribe.class.getSimpleName()); - } - return bean; - } - - /** - * package private setter for testing purposes. - * - * @param eventBus - * the event bus - */ - void setEventBus(final EventBus eventBus) { - this.eventBus = eventBus; - } -} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/EventSubscriber.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/EventSubscriber.java deleted file mode 100644 index dd2f84074..000000000 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/EventSubscriber.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** - * Marks an class as an event subscriber to listen on event on the event bus - * without explicit register this class to the event bus. - * - *
- * @EventSubscriber
- * public class MySubscriber {
- *     @Subscribe
- *     public void listen(MyEvent event) {
- *         System.out.println("event received: " + event);
- *     }
- * }
- * 
- * - * - * - * - */ -@Target({ TYPE }) -@Retention(RUNTIME) -public @interface EventSubscriber { - -} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractDistributedEvent.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractDistributedEvent.java deleted file mode 100644 index c467a746c..000000000 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractDistributedEvent.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus.event; - -/** - * An abstract class of the {@link DistributedEvent} implementation which holds - * all the necessary information of distributing events to other nodes. - * - * - * - * - */ -public abstract class AbstractDistributedEvent implements DistributedEvent { - - private static final long serialVersionUID = 1L; - private final long revision; - private String originNodeId; - private String nodeId; - private final String tenant; - - /** - * - * @param revision - * the revision of this event - * @param tenant - * the tenant for this event - */ - protected AbstractDistributedEvent(final long revision, final String tenant) { - this.revision = revision; - this.tenant = tenant; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.NodeAware#setOriginNodeId(java. - * lang. String) - */ - @Override - public void setOriginNodeId(final String originNodeId) { - this.originNodeId = originNodeId; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.NodeAware#setNodeId(java.lang. - * String) - */ - @Override - public void setNodeId(final String nodeId) { - this.nodeId = nodeId; - - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.hawkbit.server.eventbus.event.NodeAware#getOriginNodeId() - */ - @Override - public String getOriginNodeId() { - return this.originNodeId; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.eventbus.event.NodeAware#getNodeId() - */ - @Override - public String getNodeId() { - return this.nodeId; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.eventbus.event.Event#getRevision() - */ - @Override - public long getRevision() { - return revision; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.hawkbit.server.eventbus.event.EntityEvent#getTenant() - */ - @Override - public String getTenant() { - return tenant; - } - -} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/DefaultEvent.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/DefaultEvent.java deleted file mode 100644 index 1874fc01f..000000000 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/DefaultEvent.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus.event; - -/** - * Abstract event definition class which holds the necessary revsion and tenant - * information which every event needs. - * - * @see AbstractDistributedEvent for events which should be distributed to other - * cluster nodes - */ -public class DefaultEvent implements Event { - - private final long revision; - private final String tenant; - - /** - * @param revision - * the revision number of the event - * @param tenant - * the tenant of the event - */ - protected DefaultEvent(final long revision, final String tenant) { - this.revision = revision; - this.tenant = tenant; - } - - @Override - public long getRevision() { - return revision; - } - - @Override - public String getTenant() { - return tenant; - } - -} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributedEvent.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributedEvent.java deleted file mode 100644 index b529afa91..000000000 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/DistributedEvent.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus.event; - -import java.io.Serializable; - -/** - * Marks an event to as an distributed event which will be distributed to other - * nodes. - * - * - * - * - */ -public interface DistributedEvent extends Event, NodeAware, Serializable { - -} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityEvent.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityEvent.java deleted file mode 100644 index 688b261e1..000000000 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/EntityEvent.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus.event; - -/** - * An event interface which declares event types that an entity has been - * changed. {@link EntityEvent}s should not implement {@link DistributedEvent} - * due all {@link EntityEvent}s will be distributed to other nodes. - * - * Retrieving an {@link EntityEvent} on a different node the entity will be load - * lazy. - * - * - * - * - */ -public interface EntityEvent extends Event, NodeAware { - - /** - * A typesafe way to retrieve the entity from the event, which might be - * loaded lazy in case the event has been distributed from another node. - * - * @param entityClass - * the class of the entity to retrieve - * @return the entity might be lazy loaded. Might be {@code null} in case - * the entity e.g. is queried lazy on a different node and has been - * already deleted from the database - * @throws ClassCastException - * in case a wrong entity class is given for this event - */ - E getEntity(Class entityClass); - - /** - * An unsafe way to retrieve the entity from this event which might be - * loaded lazy in case the event has been distributed from another node. - * - * @return the entity might be lazy loaded. Might be {@code null} in case - * the entity e.g. is queried lazy on a different node and has been - * already deleted from the database - */ - Object getEntity(); -} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/Event.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/Event.java deleted file mode 100644 index 9cbf6ef12..000000000 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/Event.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus.event; - -/** - * An event declaration which holds an revision for each event so consumers have - * the chance to know if they might already retrieved an newer event. - * - * - * - * - */ -public interface Event { - - /** - * @return the revision of this event which should be increment or each new - * event in case the event have a causalität. Might be {@code -1} in - * case the events does not provide any revision. - */ - long getRevision(); - - /** - * @return the tenant of the entity. - */ - String getTenant(); -} diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/NodeAware.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/NodeAware.java deleted file mode 100644 index 2d7532d07..000000000 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/NodeAware.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus.event; - -/** - * Interface to be implemented by events which are distributed to other nodes - * where it's necessary to know which node sent an event and which nodes - * retrieved the event from which node. Using the EventDistributor the - * implementation only needs to contain the necessary node IDs, setting and - * retrieving the node IDs is transparent by the EventDistributor so the event - * distributor does not hang in an endless loop of distributing the events which - * self posted. - * - * - * - * - */ -public interface NodeAware { - - /** - * @return the origin node ID in case the event has been forwarded to other - * nodes or {@code null} if the event has not been forwarded to - * other nodes - */ - String getOriginNodeId(); - - /** - * @param originNodeId - * the origin node ID where this event has been sent originally - */ - void setOriginNodeId(String originNodeId); - - /** - * @return the node ID which is processing this event locally, set by the - * EventDistributor so he can determine if this event has been - * received by another node and is processing on the current node. - */ - String getNodeId(); - - /** - * @param nodeId - * the ID of the node this event is processing. - */ - void setNodeId(String nodeId); - -} diff --git a/hawkbit-core/src/test/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCacheTest.java b/hawkbit-core/src/test/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCacheTest.java new file mode 100644 index 000000000..fb1b6caa8 --- /dev/null +++ b/hawkbit-core/src/test/java/org/eclipse/hawkbit/cache/DefaultDownloadIdCacheTest.java @@ -0,0 +1,124 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.cache; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.support.SimpleValueWrapper; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +@Features("Unit Tests - Cache") +@Stories("Download ID Cache") +@RunWith(MockitoJUnitRunner.class) +public class DefaultDownloadIdCacheTest { + + @Mock + private CacheManager cacheManagerMock; + + @Mock + private TenancyCacheManager tenancyCacheManagerMock; + + @Mock + private Cache cacheMock; + + @Captor + private ArgumentCaptor cacheManagerKeyCaptor; + + @Captor + private ArgumentCaptor cacheManagerValueCaptor; + + private DefaultDownloadIdCache underTest; + + private final String knownKey = "12345"; + + @Before + public void before() { + underTest = new DefaultDownloadIdCache(cacheManagerMock); + when(cacheManagerMock.getCache(DefaultDownloadIdCache.DOWNLOAD_ID_CACHE)).thenReturn(cacheMock); + when(tenancyCacheManagerMock.getDirectCache(DefaultDownloadIdCache.DOWNLOAD_ID_CACHE)).thenReturn(cacheMock); + } + + @Test + @Description("Verifies that putting key and value is delegated to the CacheManager implementation") + public void putKeyAndValueIsDelegatedToCacheManager() { + final DownloadArtifactCache value = new DownloadArtifactCache(DownloadType.BY_SHA1, knownKey); + + underTest.put(knownKey, value); + + verify(cacheMock).put(cacheManagerKeyCaptor.capture(), cacheManagerValueCaptor.capture()); + + assertThat(cacheManagerKeyCaptor.getValue()).isEqualTo(knownKey); + assertThat(cacheManagerValueCaptor.getValue()).isEqualTo(value); + } + + @Test + @Description("Verifies that evicting a key is delegated to the CacheManager implementation") + public void evictKeyIsDelegatedToCacheManager() { + + underTest.evict(knownKey); + + verify(cacheMock).evict(cacheManagerKeyCaptor.capture()); + + assertThat(cacheManagerKeyCaptor.getValue()).isEqualTo(knownKey); + } + + @Test + @Description("Verifies that retrieving a value for a specific key is delegated to the CacheManager implementation") + public void getValueReturnsTheAssociatedValueForKey() { + final String knownKey = "12345"; + final DownloadArtifactCache knownValue = new DownloadArtifactCache(DownloadType.BY_SHA1, knownKey); + + when(cacheMock.get(knownKey)).thenReturn(new SimpleValueWrapper(knownValue)); + + final DownloadArtifactCache downloadArtifactCache = underTest.get(knownKey); + + assertThat(downloadArtifactCache).isEqualTo(knownValue); + } + + @Test + @Description("Verifies that retrieving a null value for a specific key is delegated to the CacheManager implementation") + public void getValueReturnsNullIfNoKeyIsAssociated() { + + when(cacheMock.get(knownKey)).thenReturn(new SimpleValueWrapper(null)); + + final DownloadArtifactCache downloadArtifactCache = underTest.get(knownKey); + + assertThat(downloadArtifactCache).isNull(); + } + + @Test + @Description("Verifies that TenancyCacheManager is using direct cache because download-ids are global unique and don't need to run as tenant aware") + public void tenancyCacheManagerIsUsingDirectCache() { + + underTest = new DefaultDownloadIdCache(tenancyCacheManagerMock); + final DownloadArtifactCache value = new DownloadArtifactCache(DownloadType.BY_SHA1, knownKey); + + underTest.put(knownKey, value); + + verify(cacheMock).put(cacheManagerKeyCaptor.capture(), cacheManagerValueCaptor.capture()); + + verify(tenancyCacheManagerMock).getDirectCache(DefaultDownloadIdCache.DOWNLOAD_ID_CACHE); + assertThat(cacheManagerKeyCaptor.getValue()).isEqualTo(knownKey); + assertThat(cacheManagerValueCaptor.getValue()).isEqualTo(value); + } +} diff --git a/hawkbit-core/src/test/java/org/eclipse/hawkbit/eventbus/EventBusSubscriberProcessorTest.java b/hawkbit-core/src/test/java/org/eclipse/hawkbit/eventbus/EventBusSubscriberProcessorTest.java deleted file mode 100644 index de85af07b..000000000 --- a/hawkbit-core/src/test/java/org/eclipse/hawkbit/eventbus/EventBusSubscriberProcessorTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.eventbus; - -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.stereotype.Service; - -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -import ru.yandex.qatools.allure.annotations.Features; -import ru.yandex.qatools.allure.annotations.Stories; - -@Features("Unit Tests - Cluster Event Bus") -@Stories("EventBus Subscriber Processor Test") -@RunWith(MockitoJUnitRunner.class) -// TODO: create description annotations -public class EventBusSubscriberProcessorTest { - - @Mock - private EventBus eventBusMock; - - private final EventBusSubscriberProcessor postProcessorUnderTest = new EventBusSubscriberProcessor(); - - @Before - public void before() { - reset(eventBusMock); - postProcessorUnderTest.setEventBus(eventBusMock); - } - - @Test - public void correctAnnotatedClassAndMethodIsRegistered() { - final TestEventSubscriberClass testEventSubscriberClass = new TestEventSubscriberClass(); - postProcessorUnderTest.postProcessAfterInitialization(testEventSubscriberClass, "correctEventSubscriber"); - verify(eventBusMock, times(1)).register(testEventSubscriberClass); - } - - @Test - public void eventSubscriberWithoutMethodAnnotationIsNotRegistered() { - final TestWrongEventSubscriberClass testEventSubscriberClass = new TestWrongEventSubscriberClass(); - postProcessorUnderTest.postProcessAfterInitialization(testEventSubscriberClass, "correctEventSubscriber"); - verify(eventBusMock, times(0)).register(testEventSubscriberClass); - } - - @EventSubscriber - @Service - private class TestEventSubscriberClass { - @Subscribe - public void subscribe(final String s) { - - } - } - - @EventSubscriber - @Service - private class TestWrongEventSubscriberClass { - public void methodWithoutAnnotation(final String s) { - - } - } -} diff --git a/hawkbit-ddi-api/pom.xml b/hawkbit-ddi-api/pom.xml index 969f0d930..9dc4adf74 100644 --- a/hawkbit-ddi-api/pom.xml +++ b/hawkbit-ddi-api/pom.xml @@ -37,9 +37,5 @@ org.hibernate hibernate-validator
- - org.springframework.security - spring-security-web - diff --git a/hawkbit-ddi-resource/pom.xml b/hawkbit-ddi-resource/pom.xml index cb85f8c8c..9664789eb 100644 --- a/hawkbit-ddi-resource/pom.xml +++ b/hawkbit-ddi-resource/pom.xml @@ -67,22 +67,6 @@ tests test - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-logging - - - test - - - org.springframework.boot - spring-boot-starter-log4j2 - test - com.h2database h2 @@ -103,13 +87,6 @@ spring-security-config test - - org.eclipse.hawkbit - hawkbit-repository-jpa - ${project.version} - tests - test - org.eclipse.hawkbit hawkbit-http-security diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java index a1b7e6de4..20ffacc90 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiArtifactDownloadTest.java @@ -30,7 +30,8 @@ import java.util.Locale; import java.util.TimeZone; import org.apache.commons.lang3.RandomUtils; -import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent; +import org.eclipse.hawkbit.ddi.rest.resource.DdiArtifactDownloadTest.DownloadTestConfiguration; +import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Artifact; @@ -41,15 +42,15 @@ import org.eclipse.hawkbit.rest.AbstractRestIntegrationTestWithMongoDB; import org.junit.Before; import org.junit.Test; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.event.EventListener; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort.Direction; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; import com.google.common.base.Charsets; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; import com.google.common.net.HttpHeaders; import ru.yandex.qatools.allure.annotations.Description; @@ -61,6 +62,7 @@ import ru.yandex.qatools.allure.annotations.Stories; */ @Features("Component Tests - Direct Device Integration API") @Stories("Artifact Download Resource") +@SpringApplicationConfiguration(classes = DownloadTestConfiguration.class) public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMongoDB { private static final int ARTIFACT_SIZE = 5 * 1024 * 1024; @@ -69,9 +71,8 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong LOG = LoggerFactory.getLogger(DdiArtifactDownloadTest.class); } - private volatile int downLoadProgress = 0; - private volatile long shippedBytes = 0; - private volatile long shippedBytesTotal = 0; + private volatile static int downLoadProgress = 0; + private volatile static long shippedBytes = 0; private final SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); @@ -80,9 +81,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); } - @Autowired - private EventBus eventBus; - @Test @Description("Tests non allowed requests on the artifact ressource, e.g. invalid URI, wrong if-match, wrong command.") public void invalidRequestsOnArtifactResource() throws Exception { @@ -252,8 +250,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong public void downloadArtifactThroughFileName() throws Exception { downLoadProgress = 1; shippedBytes = 0; - shippedBytesTotal = 0; - eventBus.register(this); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); // create target @@ -293,7 +289,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong // download complete assertThat(downLoadProgress).isEqualTo(10); - assertThat(shippedBytes).isEqualTo(shippedBytesTotal).isEqualTo(ARTIFACT_SIZE); + assertThat(shippedBytes).isEqualTo(ARTIFACT_SIZE); } @Test @@ -332,8 +328,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong public void downloadArtifactByNameFailsIfNotAuthenticated() throws Exception { downLoadProgress = 1; shippedBytes = 0; - shippedBytesTotal = 0; - eventBus.register(this); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); @@ -357,7 +351,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .andExpect(status().isNotFound()); assertThat(downLoadProgress).isEqualTo(1); - assertThat(shippedBytes).isEqualTo(shippedBytesTotal).isEqualTo(0L); + assertThat(shippedBytes).isEqualTo(0L); } @Test @@ -366,8 +360,6 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong public void downloadArtifactByNameByNamedController() throws Exception { downLoadProgress = 1; shippedBytes = 0; - shippedBytesTotal = 0; - eventBus.register(this); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); @@ -414,7 +406,7 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong // download complete assertThat(downLoadProgress).isEqualTo(10); - assertThat(shippedBytes).isEqualTo(shippedBytesTotal).isEqualTo(ARTIFACT_SIZE); + assertThat(shippedBytes).isEqualTo(ARTIFACT_SIZE); } @Test @@ -573,11 +565,23 @@ public class DdiArtifactDownloadTest extends AbstractRestIntegrationTestWithMong .isEqualTo(new String(artifact.getMd5Hash() + " file1.tar.bz2").getBytes(Charsets.US_ASCII)); } - @Subscribe - public void listen(final DownloadProgressEvent event) { - downLoadProgress++; - shippedBytes += event.getShippedBytesSinceLast(); - shippedBytesTotal = event.getShippedBytesOverall(); + public static class DownloadTestConfiguration { + + @Bean + public Listener cancelEventHandlerStubBean() { + return new Listener(); + } } + + private static class Listener { + + @EventListener(classes = DownloadProgressEvent.class) + public void listen(final DownloadProgressEvent event) { + downLoadProgress++; + shippedBytes += event.getShippedBytesSinceLast(); + + } + } + } diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java index b476f5c8f..ce977b016 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiCancelActionTest.java @@ -31,7 +31,6 @@ import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; import org.junit.Test; -import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import ru.yandex.qatools.allure.annotations.Description; @@ -74,7 +73,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { // get update action anyway mvc.perform(get("/{tenant}/controller/v1/4712/deploymentBase/" + updateAction.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id", equalTo(String.valueOf(updateAction.getId())))) .andExpect(jsonPath("$.deployment.download", equalTo("forced"))) .andExpect(jsonPath("$.deployment.update", equalTo("forced"))) @@ -118,7 +117,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { long current = System.currentTimeMillis(); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() @@ -150,7 +149,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { current = System.currentTimeMillis(); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.cancelAction.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() @@ -170,7 +169,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { get("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction.getId(), tenantAware.getCurrentTenant()) .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction.getId())))) .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction.getId())))); assertThat(targetManagement.findTargetByControllerID("4712").getTargetInfo().getLastTargetQuery()) @@ -360,14 +359,14 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { get("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction.getId(), tenantAware.getCurrentTenant()) .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction.getId())))) .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction.getId())))); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(6); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.cancelAction.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() @@ -386,14 +385,14 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { assertThat(deploymentManagement.findActionsByTarget(savedTarget)).hasSize(3); mvc.perform(get("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction2.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction2.getId())))) .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction2.getId())))); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(8); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.cancelAction.href", equalTo("http://localhost/" + tenantAware.getCurrentTenant() @@ -426,7 +425,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction3.getId(), tenantAware.getCurrentTenant()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction3.getId())))) .andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(updateAction3.getId())))); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(12); @@ -435,7 +434,7 @@ public class DdiCancelActionTest extends AbstractRestIntegrationTest { mvc.perform(post("/{tenant}/controller/v1/4712/cancelAction/" + cancelAction3.getId() + "/feedback", tenantAware.getCurrentTenant()) .content(JsonBuilder.cancelActionFeedback(cancelAction3.getId().toString(), "closed")) - .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON_UTF8)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); assertThat(deploymentManagement.countActionStatusAll()).isEqualTo(13); diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java index aa26c3931..e828e5049 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiConfigDataTest.java @@ -52,7 +52,7 @@ public class DdiConfigDataTest extends AbstractRestIntegrationTest { final long current = System.currentTimeMillis(); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.configData.href", equalTo( "http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/configData"))); @@ -75,7 +75,7 @@ public class DdiConfigDataTest extends AbstractRestIntegrationTest { mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.configData.href").doesNotExist()); } diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java index 8b0248a39..7e13b8755 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiDeploymentBaseTest.java @@ -27,13 +27,13 @@ import java.util.List; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.RandomUtils; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.RepositoryModelConstants; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; @@ -44,7 +44,6 @@ import org.fest.assertions.core.Condition; import org.junit.Test; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort.Direction; -import org.springframework.hateoas.MediaTypes; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; @@ -136,7 +135,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD long current = System.currentTimeMillis(); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId()))); @@ -155,7 +154,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD get("/{tenant}/controller/v1/4712/deploymentBase/" + uaction.getId(), tenantAware.getCurrentTenant()) .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", equalTo(String.valueOf(action.getId())))) .andExpect(jsonPath("$.deployment.download", equalTo("forced"))) .andExpect(jsonPath("$.deployment.update", equalTo("forced"))) @@ -236,7 +235,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD MvcResult mvcResult = mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)).andReturn(); + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)).andReturn(); final String urlBeforeSwitch = JsonPath.compile("_links.deploymentBase.href") .read(mvcResult.getResponse().getContentAsString()).toString(); @@ -244,7 +243,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD // Time is not yet over, so we should see the same URL mvcResult = mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)).andReturn(); + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)).andReturn(); assertThat(JsonPath.compile("_links.deploymentBase.href").read(mvcResult.getResponse().getContentAsString()) .toString()).isEqualTo(urlBeforeSwitch) .startsWith("http://localhost/" + tenantAware.getCurrentTenant() @@ -255,7 +254,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD mvcResult = mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)).andReturn(); + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)).andReturn(); assertThat(JsonPath.compile("_links.deploymentBase.href").read(mvcResult.getResponse().getContentAsString()) .toString()).isNotEqualTo(urlBeforeSwitch); @@ -300,7 +299,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD long current = System.currentTimeMillis(); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId()))); @@ -319,7 +318,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD get("/{tenant}/controller/v1/4712/deploymentBase/" + uaction.getId(), tenantAware.getCurrentTenant()) .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", equalTo(String.valueOf(action.getId())))) .andExpect(jsonPath("$.deployment.download", equalTo("attempt"))) .andExpect(jsonPath("$.deployment.update", equalTo("attempt"))) @@ -424,7 +423,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD long current = System.currentTimeMillis(); mvc.perform(get("/{tenant}/controller/v1/4712", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/deploymentBase/" + uaction.getId()))); @@ -441,7 +440,7 @@ public class DdiDeploymentBaseTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/4712/deploymentBase/{actionId}", tenantAware.getCurrentTenant(), uaction.getId()).accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.id", equalTo(String.valueOf(action.getId())))) .andExpect(jsonPath("$.deployment.download", equalTo("forced"))) .andExpect(jsonPath("$.deployment.update", equalTo("forced"))) diff --git a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java index 7aad25600..dbb84b87a 100644 --- a/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java +++ b/hawkbit-ddi-resource/src/test/java/org/eclipse/hawkbit/ddi/rest/resource/DdiRootControllerTest.java @@ -122,7 +122,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD final long current = System.currentTimeMillis(); mvc.perform(get("/default-tenant/controller/v1/4711")).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))); assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery()) .isGreaterThanOrEqualTo(current); @@ -154,7 +154,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD securityRule.runAs(WithSpringAuthorityRule.withUser("controller", CONTROLLER_ROLE_ANONYMOUS), () -> { mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:02:00"))); return null; }); @@ -165,7 +165,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD public void rootRsNotModified() throws Exception { final String etag = mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))).andReturn().getResponse() .getHeader("ETag"); @@ -182,7 +182,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD .perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()) .header("If-None-Match", etag).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() @@ -215,7 +215,7 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant()) .header("If-None-Match", etagWithFirstUpdate).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))) .andExpect(jsonPath("$._links.deploymentBase.href", startsWith("http://localhost/" + tenantAware.getCurrentTenant() @@ -236,8 +236,9 @@ public class DdiRootControllerTest extends AbstractRestIntegrationTestWithMongoD final long current = System.currentTimeMillis(); mvc.perform(get("/{tenant}/controller/v1/4711", tenantAware.getCurrentTenant())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andExpect(content().contentType(APPLICATION_JSON_HAL_UTF)) .andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00"))); + assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery()) .isLessThanOrEqualTo(System.currentTimeMillis()); assertThat(targetManagement.findTargetByControllerID("4711").getTargetInfo().getLastTargetQuery()) diff --git a/hawkbit-ddi-resource/src/test/resources/application-test.properties b/hawkbit-ddi-resource/src/test/resources/application-test.properties index 599441734..762218d22 100644 --- a/hawkbit-ddi-resource/src/test/resources/application-test.properties +++ b/hawkbit-ddi-resource/src/test/resources/application-test.properties @@ -7,6 +7,9 @@ # http://www.eclipse.org/legal/epl-v10.html # +logging.level.=INFO +logging.level.org.eclipse.persistence=ERROR + spring.data.mongodb.uri=mongodb://localhost/spArtifactRepository${random.value} spring.data.mongodb.port=28017 diff --git a/hawkbit-ddi-resource/src/test/resources/logback-spring.xml b/hawkbit-ddi-resource/src/test/resources/logback-spring.xml deleted file mode 100644 index 6a53b21ac..000000000 --- a/hawkbit-ddi-resource/src/test/resources/logback-spring.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/hawkbit-dmf-amqp/pom.xml b/hawkbit-dmf-amqp/pom.xml index c2ed7c213..b9541f85e 100644 --- a/hawkbit-dmf-amqp/pom.xml +++ b/hawkbit-dmf-amqp/pom.xml @@ -57,10 +57,6 @@ org.springframework.boot spring-boot - - com.fasterxml.jackson.core - jackson-annotations - com.fasterxml.jackson.core jackson-databind @@ -69,6 +65,8 @@ org.slf4j slf4j-api + + org.springframework.boot spring-boot-configuration-processor diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java index d60f4e233..d123bdbc7 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpAuthenticationMessageHandler.java @@ -15,6 +15,7 @@ import org.eclipse.hawkbit.api.HostnameResolver; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; import org.eclipse.hawkbit.cache.DownloadArtifactCache; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.cache.DownloadType; import org.eclipse.hawkbit.dmf.json.model.Artifact; import org.eclipse.hawkbit.dmf.json.model.ArtifactHash; @@ -31,7 +32,6 @@ import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.core.RabbitTemplate; -import org.springframework.cache.Cache; import org.springframework.http.HttpStatus; import org.springframework.security.authentication.AuthenticationServiceException; import org.springframework.security.authentication.BadCredentialsException; @@ -56,7 +56,7 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService { private final ArtifactManagement artifactManagement; - private final Cache cache; + private final DownloadIdCache cache; private final HostnameResolver hostnameResolver; @@ -78,7 +78,7 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService { */ public AmqpAuthenticationMessageHandler(final RabbitTemplate rabbitTemplate, final AmqpControllerAuthentication authenticationManager, final ArtifactManagement artifactManagement, - final Cache cache, final HostnameResolver hostnameResolver, + final DownloadIdCache cache, final HostnameResolver hostnameResolver, final ControllerManagement controllerManagement) { super(rabbitTemplate); this.authenticationManager = authenticationManager; @@ -89,7 +89,7 @@ public class AmqpAuthenticationMessageHandler extends BaseAmqpService { } /** - * Executed on a authentication request. + * Executed on an authentication request. * * @param message * the amqp message diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java index 24a5025a2..0630375c9 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpConfiguration.java @@ -15,12 +15,13 @@ import java.util.concurrent.ScheduledExecutorService; import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.api.HostnameResolver; -import org.eclipse.hawkbit.cache.CacheConstants; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.dmf.amqp.api.AmqpSettings; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.SystemSecurityContext; @@ -45,7 +46,7 @@ import org.springframework.boot.autoconfigure.amqp.RabbitProperties; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cache.Cache; +import org.springframework.cloud.bus.ServiceMatcher; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.retry.backoff.ExponentialBackOffPolicy; @@ -74,6 +75,9 @@ public class AmqpConfiguration { @Autowired private ConnectionFactory rabbitConnectionFactory; + @Autowired(required = false) + private ServiceMatcher serviceMatcher; + @Configuration @ConditionalOnMissingBean(ConnectionFactory.class) @ConditionalOnProperty(prefix = "hawkbit.dmf.rabbitmq", name = "enabled", matchIfMissing = true) @@ -288,7 +292,7 @@ public class AmqpConfiguration { * for target authentication * @param artifactManagement * for artifact URI generation - * @param cache + * @param downloadIdCache * for download IDs * @param hostnameResolver * for resolving the host for downloads @@ -299,10 +303,10 @@ public class AmqpConfiguration { @Bean public AmqpAuthenticationMessageHandler amqpAuthenticationMessageHandler(final RabbitTemplate rabbitTemplate, final AmqpControllerAuthentication authenticationManager, final ArtifactManagement artifactManagement, - @Qualifier(CacheConstants.DOWNLOAD_ID_CACHE) final Cache cache, final HostnameResolver hostnameResolver, + final DownloadIdCache downloadIdCache, final HostnameResolver hostnameResolver, final ControllerManagement controllerManagement) { - return new AmqpAuthenticationMessageHandler(rabbitTemplate, authenticationManager, artifactManagement, cache, - hostnameResolver, controllerManagement); + return new AmqpAuthenticationMessageHandler(rabbitTemplate, authenticationManager, artifactManagement, + downloadIdCache, hostnameResolver, controllerManagement); } /** @@ -330,6 +334,23 @@ public class AmqpConfiguration { return new ConfigurableRabbitListenerContainerFactory(amqpProperties, rabbitConnectionFactory, errorHandler); } + /** + * create the authentication bean for controller over amqp. + * + * @param systemManagement + * the systemManagement + * @param controllerManagement + * the controllerManagement + * @param tenantConfigurationManagement + * the tenantConfigurationManagement + * @param tenantAware + * the tenantAware + * @param ddiSecruityProperties + * the ddiSecruityProperties + * @param systemSecurityContext + * the systemSecurityContext + * @return the bean + */ @Bean @ConditionalOnMissingBean(AmqpControllerAuthentication.class) public AmqpControllerAuthentication amqpControllerAuthentication(final SystemManagement systemManagement, @@ -340,13 +361,31 @@ public class AmqpConfiguration { tenantAware, ddiSecruityProperties, systemSecurityContext); } + /** + * Create the dispatcher bean. + * + * @param rabbitTemplate + * the rabbitTemplate + * @param amqpSenderService + * to send AMQP message + * @param artifactUrlHandler + * for generating download URLs + * @param systemSecurityContext + * for execution with system permissions + * @param systemManagement + * the systemManagement + * @param targetManagement + * to access target information + * @return the bean + */ @Bean @ConditionalOnMissingBean(AmqpMessageDispatcherService.class) public AmqpMessageDispatcherService amqpMessageDispatcherService(final RabbitTemplate rabbitTemplate, final AmqpSenderService amqpSenderService, final ArtifactUrlHandler artifactUrlHandler, - final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement) { + final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement, + final TargetManagement targetManagement) { return new AmqpMessageDispatcherService(rabbitTemplate, amqpSenderService, artifactUrlHandler, - systemSecurityContext, systemManagement); + systemSecurityContext, systemManagement, targetManagement, serviceMatcher); } private static Map getTTLMaxArgsAuthenticationQueue() { diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java index 835654843..33fe03419 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherService.java @@ -25,38 +25,40 @@ import org.eclipse.hawkbit.dmf.json.model.Artifact; import org.eclipse.hawkbit.dmf.json.model.ArtifactHash; import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.dmf.json.model.SoftwareModule; -import org.eclipse.hawkbit.eventbus.EventSubscriber; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.util.IpUtil; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.RabbitTemplate; - -import com.google.common.eventbus.Subscribe; +import org.springframework.cloud.bus.ServiceMatcher; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.context.event.EventListener; /** * {@link AmqpMessageDispatcherService} create all outgoing AMQP messages and * delegate the messages to a {@link AmqpSenderService}. - * + * * Additionally the dispatcher listener/subscribe for some target events e.g. * assignment. * */ -@EventSubscriber public class AmqpMessageDispatcherService extends BaseAmqpService { private final ArtifactUrlHandler artifactUrlHandler; private final AmqpSenderService amqpSenderService; private final SystemSecurityContext systemSecurityContext; private final SystemManagement systemManagement; + private final TargetManagement targetManagement; + private final ServiceMatcher serviceMatcher; /** * Constructor. - * + * * @param rabbitTemplate * the rabbitTemplate * @param amqpSenderService @@ -66,51 +68,68 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { * @param systemSecurityContext * for execution with system permissions * @param systemManagement - * to access to tenant metadata + * the systemManagement + * @param targetManagement + * to access target information + * @param serviceMatcher + * to check in cluster case if the message is from the same + * cluster node */ public AmqpMessageDispatcherService(final RabbitTemplate rabbitTemplate, final AmqpSenderService amqpSenderService, final ArtifactUrlHandler artifactUrlHandler, final SystemSecurityContext systemSecurityContext, - final SystemManagement systemManagement) { + final SystemManagement systemManagement, final TargetManagement targetManagement, + final ServiceMatcher serviceMatcher) { super(rabbitTemplate); this.artifactUrlHandler = artifactUrlHandler; this.amqpSenderService = amqpSenderService; this.systemSecurityContext = systemSecurityContext; this.systemManagement = systemManagement; + this.targetManagement = targetManagement; + this.serviceMatcher = serviceMatcher; } /** * Method to send a message to a RabbitMQ Exchange after the Distribution * set has been assign to a Target. * - * @param targetAssignDistributionSetEvent + * @param assignedEvent * the object to be send. */ - @Subscribe - public void targetAssignDistributionSet(final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent) { - final URI targetAdress = targetAssignDistributionSetEvent.getTarget().getTargetInfo().getAddress(); + @EventListener(classes = TargetAssignDistributionSetEvent.class) + public void targetAssignDistributionSet(final TargetAssignDistributionSetEvent assignedEvent) { + if (isFromSelf(assignedEvent)) { + return; + } + + sendUpdateMessageToTarget(assignedEvent.getTenant(), + targetManagement.findTargetByControllerID(assignedEvent.getControllerId()), assignedEvent.getActionId(), + assignedEvent.getModules()); + } + + void sendUpdateMessageToTarget(final String tenant, final Target target, final Long actionId, + final Collection modules) { + if (target == null) { + return; + } + + final URI targetAdress = target.getTargetInfo().getAddress(); if (!IpUtil.isAmqpUri(targetAdress)) { return; } - final String controllerId = targetAssignDistributionSetEvent.getTarget().getControllerId(); - final Collection modules = targetAssignDistributionSetEvent - .getSoftwareModules(); final DownloadAndUpdateRequest downloadAndUpdateRequest = new DownloadAndUpdateRequest(); - downloadAndUpdateRequest.setActionId(targetAssignDistributionSetEvent.getActionId()); + downloadAndUpdateRequest.setActionId(actionId); - final String targetSecurityToken = systemSecurityContext - .runAsSystem(targetAssignDistributionSetEvent.getTarget()::getSecurityToken); + final String targetSecurityToken = systemSecurityContext.runAsSystem(target::getSecurityToken); downloadAndUpdateRequest.setTargetSecurityToken(targetSecurityToken); for (final org.eclipse.hawkbit.repository.model.SoftwareModule softwareModule : modules) { - final SoftwareModule amqpSoftwareModule = convertToAmqpSoftwareModule( - targetAssignDistributionSetEvent.getTarget(), softwareModule); + final SoftwareModule amqpSoftwareModule = convertToAmqpSoftwareModule(target, softwareModule); downloadAndUpdateRequest.addSoftwareModule(amqpSoftwareModule); } final Message message = getMessageConverter().toMessage(downloadAndUpdateRequest, - createConnectorMessageProperties(targetAssignDistributionSetEvent.getTenant(), controllerId, - EventTopic.DOWNLOAD_AND_INSTALL)); + createConnectorMessageProperties(tenant, target.getControllerId(), EventTopic.DOWNLOAD_AND_INSTALL)); amqpSenderService.sendMessage(message, targetAdress); } @@ -118,19 +137,29 @@ public class AmqpMessageDispatcherService extends BaseAmqpService { * Method to send a message to a RabbitMQ Exchange after the assignment of * the Distribution set to a Target has been canceled. * - * @param cancelTargetAssignmentDistributionSetEvent + * @param cancelEvent * the object to be send. */ - @Subscribe - public void targetCancelAssignmentToDistributionSet( - final CancelTargetAssignmentEvent cancelTargetAssignmentDistributionSetEvent) { - final String controllerId = cancelTargetAssignmentDistributionSetEvent.getTarget().getControllerId(); - final Long actionId = cancelTargetAssignmentDistributionSetEvent.getActionId(); - final Message message = getMessageConverter().toMessage(actionId, createConnectorMessageProperties( - cancelTargetAssignmentDistributionSetEvent.getTenant(), controllerId, EventTopic.CANCEL_DOWNLOAD)); + @EventListener(classes = CancelTargetAssignmentEvent.class) + public void targetCancelAssignmentToDistributionSet(final CancelTargetAssignmentEvent cancelEvent) { + if (isFromSelf(cancelEvent)) { + return; + } - amqpSenderService.sendMessage(message, - cancelTargetAssignmentDistributionSetEvent.getTarget().getTargetInfo().getAddress()); + sendCancelMessageToTarget(cancelEvent.getTenant(), cancelEvent.getEntity().getControllerId(), + cancelEvent.getActionId(), cancelEvent.getEntity().getTargetInfo().getAddress()); + } + + private boolean isFromSelf(final RemoteApplicationEvent event) { + return serviceMatcher != null && !serviceMatcher.isFromSelf(event); + } + + void sendCancelMessageToTarget(final String tenant, final String controllerId, final Long actionId, + final URI address) { + final Message message = getMessageConverter().toMessage(actionId, + createConnectorMessageProperties(tenant, controllerId, EventTopic.CANCEL_DOWNLOAD)); + + amqpSenderService.sendMessage(message, address); } diff --git a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java index d91ab6a14..14698c9f4 100644 --- a/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java +++ b/hawkbit-dmf-amqp/src/main/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerService.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.amqp; import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.Collections; -import java.util.List; import java.util.Optional; import java.util.UUID; @@ -26,15 +25,11 @@ import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.RepositoryConstants; -import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; import org.eclipse.hawkbit.repository.exception.TooManyStatusEntriesException; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.util.IpUtil; import org.slf4j.Logger; @@ -176,7 +171,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService { final String replyTo = message.getMessageProperties().getReplyTo(); if (StringUtils.isEmpty(replyTo)) { - logAndThrowMessageError(message, "No ReplyTo was set for the createThing Event."); + logAndThrowMessageError(message, "No ReplyTo was set for the createThing TenantAwareEvent."); } final URI amqpUri = IpUtil.createAmqpUri(virtualHost, replyTo); @@ -187,23 +182,20 @@ public class AmqpMessageHandlerService extends BaseAmqpService { } private void lookIfUpdateAvailable(final Target target) { - final Optional action = controllerManagement.findOldestActiveActionByTarget(target); - if (!action.isPresent()) { + final Optional actionOptional = controllerManagement.findOldestActiveActionByTarget(target); + if (!actionOptional.isPresent()) { return; } - if (action.get().isCancelingOrCanceled()) { - amqpMessageDispatcherService.targetCancelAssignmentToDistributionSet( - new CancelTargetAssignmentEvent(target, action.get().getId())); + final Action action = actionOptional.get(); + if (action.isCancelingOrCanceled()) { + amqpMessageDispatcherService.sendCancelMessageToTarget(target.getTenant(), target.getControllerId(), + action.getId(), target.getTargetInfo().getAddress()); return; } - final DistributionSet distributionSet = action.get().getDistributionSet(); - final List softwareModuleList = controllerManagement - .findSoftwareModulesByDistributionSet(distributionSet); - amqpMessageDispatcherService.targetAssignDistributionSet(new TargetAssignDistributionSetEvent( - target.getOptLockRevision(), target.getTenant(), target, action.get().getId(), softwareModuleList)); - + amqpMessageDispatcherService.sendUpdateMessageToTarget(action.getTenant(), action.getTarget(), action.getId(), + action.getDistributionSet().getModules()); } /** @@ -332,5 +324,4 @@ public class AmqpMessageHandlerService extends BaseAmqpService { "Cancel recjected message is not allowed, if action is on state: " + action.getStatus()); } } - } diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java index 555db1c25..07e5b245e 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthenticationTest.java @@ -21,6 +21,7 @@ import java.net.URL; import org.eclipse.hawkbit.api.HostnameResolver; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.DownloadResponse; @@ -54,7 +55,6 @@ import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.MessageConverter; -import org.springframework.cache.Cache; import org.springframework.http.HttpStatus; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.core.Authentication; @@ -95,7 +95,7 @@ public class AmqpControllerAuthenticationTest { private SystemManagement systemManagement; @Mock - private Cache cacheMock; + private DownloadIdCache cacheMock; @Mock private HostnameResolver hostnameResolverMock; diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index c001e4fe3..448c3c7ce 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -19,9 +19,9 @@ import static org.mockito.Mockito.when; import java.net.URI; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.UUID; import org.eclipse.hawkbit.api.ArtifactUrl; import org.eclipse.hawkbit.api.ArtifactUrlHandler; @@ -31,8 +31,12 @@ import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageType; import org.eclipse.hawkbit.dmf.json.model.DownloadAndUpdateRequest; import org.eclipse.hawkbit.repository.SystemManagement; -import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; +import org.eclipse.hawkbit.repository.jpa.ActionRepository; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.ActionType; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -48,6 +52,7 @@ import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.AbstractJavaTypeMapper; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.ActiveProfiles; @@ -82,11 +87,15 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { private Target testTarget; + @Autowired + protected ActionRepository actionRepository; + @Override public void before() throws Exception { super.before(); - testTarget = entityFactory.generateTarget(CONTROLLER_ID, TEST_TOKEN); - testTarget.getTargetInfo().setAddress(AMQP_URI.toString()); + final Target generateTarget = entityFactory.generateTarget(CONTROLLER_ID, TEST_TOKEN); + generateTarget.getTargetInfo().setAddress(AMQP_URI.toString()); + testTarget = targetManagement.createTarget(generateTarget); this.rabbitTemplate = Mockito.mock(RabbitTemplate.class); when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter()); @@ -105,41 +114,62 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { when(systemManagement.getTenantMetadata()).thenReturn(tenantMetaData); amqpMessageDispatcherService = new AmqpMessageDispatcherService(rabbitTemplate, senderService, - artifactUrlHandlerMock, systemSecurityContext, systemManagement); + artifactUrlHandlerMock, systemSecurityContext, systemManagement, targetManagement, serviceMatcher); } @Test @Description("Verfies that download and install event with no software modul works") public void testSendDownloadRequesWithEmptySoftwareModules() { + final Action action = createAction( + testdataFactory.createDistributionSetWithNoSoftwareModules(UUID.randomUUID().toString(), "1.0")); + final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent( - 1L, TENANT, testTarget, 1L, Collections.emptyList()); + action, serviceMatcher.getServiceId()); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); - final Message sendMessage = createArgumentCapture( - targetAssignDistributionSetEvent.getTarget().getTargetInfo().getAddress()); - final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage); + + final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent); + final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage, action); assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN); assertTrue("No softwaremmodule should be contained in the request", downloadAndUpdateRequest.getSoftwareModules().isEmpty()); } + private Message getCaptureAdressEvent(final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent) { + final Target target = targetManagement + .findTargetByControllerID(targetAssignDistributionSetEvent.getControllerId()); + final Message sendMessage = createArgumentCapture(target.getTargetInfo().getAddress()); + return sendMessage; + } + + private JpaAction createAction(final DistributionSet testDs) { + final Action action = entityFactory.generateAction(); + final JpaAction jpaAction = (JpaAction) action; + action.setDistributionSet(testDs); + action.setTarget(testTarget); + jpaAction.setActionType(ActionType.FORCED); + + return actionRepository.save(jpaAction); + } + @Test @Description("Verfies that download and install event with 3 software moduls and no artifacts works") public void testSendDownloadRequesWithSoftwareModulesAndNoArtifacts() { - final DistributionSet dsA = testdataFactory.createDistributionSet(""); + final DistributionSet createDistributionSet = testdataFactory + .createDistributionSet(UUID.randomUUID().toString()); + final Action action = createAction(createDistributionSet); + final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent( - 1L, TENANT, testTarget, 1L, dsA.getModules()); + action, serviceMatcher.getServiceId()); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); - final Message sendMessage = createArgumentCapture( - targetAssignDistributionSetEvent.getTarget().getTargetInfo().getAddress()); - final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage); - assertEquals("Expecting a size of 3 software modules in the reuqest", 3, - downloadAndUpdateRequest.getSoftwareModules().size()); + final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent); + final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage, action); + assertThat(createDistributionSet.getModules()).hasSameSizeAs(downloadAndUpdateRequest.getSoftwareModules()); assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN); for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest .getSoftwareModules()) { assertTrue("Artifact list for softwaremodule should be empty", softwareModule.getArtifacts().isEmpty()); - for (final SoftwareModule softwareModule2 : dsA.getModules()) { + for (final SoftwareModule softwareModule2 : action.getDistributionSet().getModules()) { assertNotNull("Sofware module ID should be set", softwareModule.getModuleId()); if (!softwareModule.getModuleId().equals(softwareModule2.getId())) { continue; @@ -157,7 +187,7 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { @Test @Description("Verfies that download and install event with software moduls and artifacts works") public void testSendDownloadRequest() { - final DistributionSet dsA = testdataFactory.createDistributionSet(""); + final DistributionSet dsA = testdataFactory.createDistributionSet(UUID.randomUUID().toString()); final SoftwareModule module = dsA.getModules().iterator().next(); final List receivedList = new ArrayList<>(); for (final Artifact artifact : testdataFactory.createArtifacts(module.getId())) { @@ -165,14 +195,16 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { receivedList.add(new DbArtifact()); } + final Action action = createAction(dsA); + Mockito.when(rabbitTemplate.convertSendAndReceive(any())).thenReturn(receivedList); final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = new TargetAssignDistributionSetEvent( - 1L, TENANT, testTarget, 1L, dsA.getModules()); + action, serviceMatcher.getServiceId()); amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); - final Message sendMessage = createArgumentCapture( - targetAssignDistributionSetEvent.getTarget().getTargetInfo().getAddress()); - final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage); + final Message sendMessage = getCaptureAdressEvent(targetAssignDistributionSetEvent); + final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage, action); + assertEquals("DownloadAndUpdateRequest event should contains 3 software modules", 3, downloadAndUpdateRequest.getSoftwareModules().size()); assertThat(downloadAndUpdateRequest.getTargetSecurityToken()).isEqualTo(TEST_TOKEN); @@ -201,11 +233,11 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { @Description("Verfies that send cancel event works") public void testSendCancelRequest() { final CancelTargetAssignmentEvent cancelTargetAssignmentDistributionSetEvent = new CancelTargetAssignmentEvent( - testTarget, 1L); + testTarget, 1L, serviceMatcher.getServiceId()); amqpMessageDispatcherService .targetCancelAssignmentToDistributionSet(cancelTargetAssignmentDistributionSetEvent); final Message sendMessage = createArgumentCapture( - cancelTargetAssignmentDistributionSetEvent.getTarget().getTargetInfo().getAddress()); + cancelTargetAssignmentDistributionSetEvent.getEntity().getTargetInfo().getAddress()); assertCancelMessage(sendMessage); } @@ -219,12 +251,11 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest { } - private DownloadAndUpdateRequest assertDownloadAndInstallMessage(final Message sendMessage) { + private DownloadAndUpdateRequest assertDownloadAndInstallMessage(final Message sendMessage, final Action action) { assertEventMessage(sendMessage); final DownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(sendMessage, DownloadAndUpdateRequest.class); - assertEquals("The action ID of the downloadAndUpdateRequest event shuold be 1", - downloadAndUpdateRequest.getActionId(), Long.valueOf(1)); + assertEquals(downloadAndUpdateRequest.getActionId(), action.getId()); assertEquals("The topic of the event shuold contain DOWNLOAD_AND_INSTALL", EventTopic.DOWNLOAD_AND_INSTALL, sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC)); assertEquals("Security token of target", downloadAndUpdateRequest.getTargetSecurityToken(), TEST_TOKEN); diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java index 991b19fc7..ff4c5a82b 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageHandlerServiceTest.java @@ -21,14 +21,14 @@ import java.lang.reflect.Field; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; -import java.util.ArrayList; -import java.util.List; +import java.util.Collection; import java.util.Optional; import org.eclipse.hawkbit.api.HostnameResolver; import org.eclipse.hawkbit.artifact.repository.ArtifactRepository; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.dmf.amqp.api.EventTopic; import org.eclipse.hawkbit.dmf.amqp.api.MessageHeaderKey; import org.eclipse.hawkbit.dmf.amqp.api.MessageType; @@ -40,17 +40,16 @@ import org.eclipse.hawkbit.dmf.json.model.TenantSecurityToken.FileResource; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.EntityFactory; -import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.Artifact; -import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.security.SecurityTokenGenerator; @@ -67,7 +66,6 @@ import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; import org.springframework.amqp.support.converter.MessageConverter; -import org.springframework.cache.Cache; import org.springframework.http.HttpStatus; import ru.yandex.qatools.allure.annotations.Description; @@ -108,7 +106,7 @@ public class AmqpMessageHandlerServiceTest { private ArtifactRepository artifactRepositoryMock; @Mock - private Cache cacheMock; + private DownloadIdCache downloadIdCache; @Mock private HostnameResolver hostnameResolverMock; @@ -120,11 +118,13 @@ public class AmqpMessageHandlerServiceTest { public void before() throws Exception { messageConverter = new Jackson2JsonMessageConverter(); when(rabbitTemplate.getMessageConverter()).thenReturn(messageConverter); + amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate, amqpMessageDispatcherServiceMock, + controllerManagementMock, entityFactoryMock); amqpMessageHandlerService = new AmqpMessageHandlerService(rabbitTemplate, amqpMessageDispatcherServiceMock, controllerManagementMock, entityFactoryMock); amqpAuthenticationMessageHandlerService = new AmqpAuthenticationMessageHandler(rabbitTemplate, - authenticationManagerMock, artifactManagementMock, cacheMock, hostnameResolverMock, + authenticationManagerMock, artifactManagementMock, downloadIdCache, hostnameResolverMock, controllerManagementMock); } @@ -363,10 +363,6 @@ public class AmqpMessageHandlerServiceTest { // for the test the same action can be used when(controllerManagementMock.findOldestActiveActionByTarget(Matchers.any())).thenReturn(Optional.of(action)); - final List softwareModuleList = createSoftwareModuleList(); - when(controllerManagementMock.findSoftwareModulesByDistributionSet(Matchers.any())) - .thenReturn(softwareModuleList); - final MessageProperties messageProperties = createMessageProperties(MessageType.EVENT); messageProperties.setHeader(MessageHeaderKey.TOPIC, EventTopic.UPDATE_ACTION_STATUS.name()); final ActionUpdateStatus actionUpdateStatus = createActionUpdateStatus(ActionStatus.FINISHED, 23L); @@ -380,20 +376,19 @@ public class AmqpMessageHandlerServiceTest { verify(controllerManagementMock).updateTargetStatus(Matchers.any(TargetInfo.class), Matchers.isNull(TargetUpdateStatus.class), Matchers.isNotNull(Long.class), Matchers.isNull(URI.class)); - final ArgumentCaptor captorTargetAssignDistributionSetEvent = ArgumentCaptor - .forClass(TargetAssignDistributionSetEvent.class); - verify(amqpMessageDispatcherServiceMock, times(1)) - .targetAssignDistributionSet(captorTargetAssignDistributionSetEvent.capture()); - final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent = captorTargetAssignDistributionSetEvent - .getValue(); + final ArgumentCaptor tenantCaptor = ArgumentCaptor.forClass(String.class); + final ArgumentCaptor targetCaptor = ArgumentCaptor.forClass(Target.class); + final ArgumentCaptor actionIdCaptor = ArgumentCaptor.forClass(Long.class); - assertThat(targetAssignDistributionSetEvent.getTarget().getControllerId()).as("event has wrong controller id") - .isEqualTo("target1"); - assertThat(targetAssignDistributionSetEvent.getTarget().getSecurityToken()) - .as("targetoken not filled correctly").isEqualTo(action.getTarget().getSecurityToken()); - assertThat(targetAssignDistributionSetEvent.getActionId()).as("event has wrong action id").isEqualTo(22L); - assertThat(targetAssignDistributionSetEvent.getSoftwareModules()).as("event has wrong sofware modules") - .isEqualTo(softwareModuleList); + verify(amqpMessageDispatcherServiceMock, times(1)).sendUpdateMessageToTarget(tenantCaptor.capture(), + targetCaptor.capture(), actionIdCaptor.capture(), Matchers.any(Collection.class)); + final String tenant = tenantCaptor.getValue(); + final String controllerId = targetCaptor.getValue().getControllerId(); + final Long actionId = actionIdCaptor.getValue(); + + assertThat(tenant).as("event has tenant").isEqualTo("DEFAULT"); + assertThat(controllerId).as("event has wrong controller id").isEqualTo("target1"); + assertThat(actionId).as("event has wrong action id").isEqualTo(22L); } @@ -424,14 +419,6 @@ public class AmqpMessageHandlerServiceTest { return messageProperties; } - private List createSoftwareModuleList() { - final List softwareModuleList = new ArrayList<>(); - final JpaSoftwareModule softwareModule = new JpaSoftwareModule(); - softwareModule.setId(777L); - softwareModuleList.add(softwareModule); - return softwareModuleList; - } - private Action createActionWithTarget(final Long targetId, final Status status) throws IllegalAccessException { // is needed for the creation of targets initalizeSecurityTokenGenerator(); @@ -440,6 +427,10 @@ public class AmqpMessageHandlerServiceTest { final JpaAction actionMock = mock(JpaAction.class); final JpaTarget targetMock = mock(JpaTarget.class); final TargetInfo targetInfoMock = mock(TargetInfo.class); + final DistributionSet distributionSetMock = mock(DistributionSet.class); + + when(distributionSetMock.getId()).thenReturn(1L); + when(actionMock.getDistributionSet()).thenReturn(distributionSetMock); when(actionMock.getId()).thenReturn(targetId); when(actionMock.getStatus()).thenReturn(status); when(actionMock.getTenant()).thenReturn("DEFAULT"); diff --git a/hawkbit-dmf-amqp/src/test/resources/application-test.properties b/hawkbit-dmf-amqp/src/test/resources/application-test.properties index 79b1fe78f..93a0c0990 100644 --- a/hawkbit-dmf-amqp/src/test/resources/application-test.properties +++ b/hawkbit-dmf-amqp/src/test/resources/application-test.properties @@ -7,8 +7,6 @@ # http://www.eclipse.org/legal/epl-v10.html # - - # supported: H2, MYSQL hawkbit.server.database=H2 @@ -35,4 +33,4 @@ H2.spring.datasource.password=sa MYSQL.spring.datasource.url=jdbc:mysql://localhost:3306/sp_test MYSQL.spring.datasource.driverClassName=org.mariadb.jdbc.Driver MYSQL.spring.datasource.username=root -MYSQL.spring.datasource.password= +MYSQL.spring.datasource.password= \ No newline at end of file diff --git a/hawkbit-dmf-api/pom.xml b/hawkbit-dmf-api/pom.xml index 2ade4a6c7..89eca9426 100644 --- a/hawkbit-dmf-api/pom.xml +++ b/hawkbit-dmf-api/pom.xml @@ -25,9 +25,5 @@ com.fasterxml.jackson.core jackson-annotations - - com.fasterxml.jackson.core - jackson-databind - diff --git a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpDownloadAuthenticationFilter.java b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpDownloadAuthenticationFilter.java index 4185c9b83..56755bddd 100644 --- a/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpDownloadAuthenticationFilter.java +++ b/hawkbit-http-security/src/main/java/org/eclipse/hawkbit/security/HttpDownloadAuthenticationFilter.java @@ -13,9 +13,9 @@ import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.cache.Cache; import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter; /** @@ -31,16 +31,16 @@ public class HttpDownloadAuthenticationFilter extends AbstractPreAuthenticatedPr private static final Logger LOG = LoggerFactory.getLogger(HttpDownloadAuthenticationFilter.class); private final Pattern pattern; - private final Cache cache; + private final DownloadIdCache downloadIdCache; /** * Constructor. * - * @param cache + * @param downloadIdCache * the cache */ - public HttpDownloadAuthenticationFilter(final Cache cache) { - this.cache = cache; + public HttpDownloadAuthenticationFilter(final DownloadIdCache downloadIdCache) { + this.downloadIdCache = downloadIdCache; this.pattern = Pattern.compile(REQUEST_ID_REGEX_PATTERN); } @@ -56,7 +56,7 @@ public class HttpDownloadAuthenticationFilter extends AbstractPreAuthenticatedPr if (id == null) { return null; } - return cache.get(id).get(); + return downloadIdCache.get(id); } @Override diff --git a/hawkbit-mgmt-api/pom.xml b/hawkbit-mgmt-api/pom.xml index 4c99cd7bc..b6b316f6e 100644 --- a/hawkbit-mgmt-api/pom.xml +++ b/hawkbit-mgmt-api/pom.xml @@ -32,11 +32,6 @@ javax.validation validation-api - - javax.servlet - javax.servlet-api - provided - diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/system/MgmtSystemTenantConfigurationValueRequest.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/system/MgmtSystemTenantConfigurationValueRequest.java index 9a9aed209..45e39cd70 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/system/MgmtSystemTenantConfigurationValueRequest.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/system/MgmtSystemTenantConfigurationValueRequest.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.mgmt.json.model.system; +import java.io.Serializable; + import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -21,13 +23,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class MgmtSystemTenantConfigurationValueRequest { @JsonProperty(required = true) - private Object value; + private Serializable value; /** * * @return the value of the MgmtSystemTenantConfigurationValueRequest */ - public Object getValue() { + public Serializable getValue() { return value; } @@ -37,7 +39,10 @@ public class MgmtSystemTenantConfigurationValueRequest { * @param value */ public void setValue(final Object value) { - this.value = value; + if (!(value instanceof Serializable)) { + throw new IllegalArgumentException("The value muste be a instance of " + Serializable.class.getName()); + } + this.value = (Serializable) value; } } diff --git a/hawkbit-mgmt-resource/pom.xml b/hawkbit-mgmt-resource/pom.xml index 007c6789b..a425a4db7 100644 --- a/hawkbit-mgmt-resource/pom.xml +++ b/hawkbit-mgmt-resource/pom.xml @@ -25,7 +25,7 @@ org.eclipse.hawkbit hawkbit-repository-api ${project.version} - + org.eclipse.hawkbit hawkbit-mgmt-api @@ -36,15 +36,14 @@ hawkbit-rest-core ${project.version} - - commons-io - commons-io - 2.4 - org.springframework.plugin spring-plugin-core + + org.springframework + spring-context + @@ -66,22 +65,6 @@ tests test - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-logging - - - test - - - org.springframework.boot - spring-boot-starter-log4j2 - test - com.h2database h2 @@ -158,10 +141,10 @@ allure-junit-adaptor test - + org.springframework spring-context-support test - + \ No newline at end of file diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java index acd088c85..bca7a8c78 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetMapper.java @@ -24,12 +24,12 @@ import org.eclipse.hawkbit.mgmt.json.model.distributionset.MgmtTargetAssignmentR import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index 7fd534320..f8588a3c3 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -28,7 +28,6 @@ import org.eclipse.hawkbit.mgmt.json.model.targetfilter.MgmtTargetFilterQuery; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.DeploymentManagement; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; @@ -38,6 +37,7 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResource.java index b6f9f27c8..14b09cbb0 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResource.java @@ -10,20 +10,16 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import java.io.IOException; -import org.apache.commons.io.IOUtils; import org.eclipse.hawkbit.artifact.repository.ArtifactRepository; import org.eclipse.hawkbit.artifact.repository.model.DbArtifact; -import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.DownloadArtifactCache; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.cache.DownloadType; import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadRestApi; import org.eclipse.hawkbit.rest.util.RequestResponseContextHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.cache.Cache; -import org.springframework.cache.Cache.ValueWrapper; import org.springframework.context.annotation.Scope; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -32,6 +28,8 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.WebApplicationContext; +import com.google.common.io.ByteStreams; + /** * A resource for download artifacts. * @@ -48,8 +46,7 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi { private ArtifactRepository artifactRepository; @Autowired - @Qualifier(CacheConstants.DOWNLOAD_ID_CACHE) - private Cache cache; + private DownloadIdCache downloadIdCache; @Autowired private RequestResponseContextHolder requestResponseContextHolder; @@ -66,13 +63,12 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi { @ResponseBody public ResponseEntity downloadArtifactByDownloadId(@PathVariable("downloadId") final String downloadId) { try { - final ValueWrapper cacheWrapper = cache.get(downloadId); - if (cacheWrapper == null) { + final DownloadArtifactCache artifactCache = downloadIdCache.get(downloadId); + if (artifactCache == null) { LOGGER.warn("Download Id {} could not be found", downloadId); return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - final DownloadArtifactCache artifactCache = (DownloadArtifactCache) cacheWrapper.get(); DbArtifact artifact = null; if (DownloadType.BY_SHA1.equals(artifactCache.getDownloadType())) { @@ -87,14 +83,14 @@ public class MgmtDownloadResource implements MgmtDownloadRestApi { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } try { - IOUtils.copy(artifact.getFileInputStream(), + ByteStreams.copy(artifact.getFileInputStream(), requestResponseContextHolder.getHttpServletResponse().getOutputStream()); } catch (final IOException e) { LOGGER.error("Cannot copy streams", e); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); } } finally { - cache.evict(downloadId); + downloadIdCache.evict(downloadId); } return ResponseEntity.ok().build(); diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSystemResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSystemResource.java index fb9218d31..8678edd2a 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSystemResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSystemResource.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; +import java.io.Serializable; import java.util.Map; import org.eclipse.hawkbit.mgmt.json.model.system.MgmtSystemTenantConfigurationValue; @@ -116,11 +117,9 @@ public class MgmtSystemResource implements MgmtSystemRestApi { final TenantConfigurationKey configKey = TenantConfigurationKey.fromKeyName(keyName); - final TenantConfigurationValue updatedValue = tenantConfigurationManagement - + final TenantConfigurationValue updatedValue = tenantConfigurationManagement .addOrUpdateConfiguration(configKey, configurationValueRest.getValue()); return new ResponseEntity<>(MgmtSystemMapper.toResponse(keyName, updatedValue), HttpStatus.OK); } } - diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index 62b8548f1..240fdd153 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -438,7 +438,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest // perform request mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[0]._links.self.href", equalTo("http://localhost/rest/v1/distributionsets/" + set.getId()))) .andExpect(jsonPath("$.content.[0].id", equalTo(set.getId().intValue()))) @@ -469,7 +469,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest // perform request mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$._links.self.href", equalTo("http://localhost/rest/v1/distributionsets/" + set.getId()))) .andExpect(jsonPath("$.id", equalTo(set.getId().intValue()))) @@ -522,7 +522,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest .perform(post("/rest/v1/distributionsets/").content(JsonBuilder.distributionSets(sets)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0]name", equalTo(one.getName()))) .andExpect(jsonPath("[0]description", equalTo(one.getDescription()))) .andExpect(jsonPath("[0]type", equalTo(standardDsType.getKey()))) @@ -757,7 +757,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()) .contentType(MediaType.APPLICATION_JSON).content(jsonArray.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0]key", equalTo(knownKey1))).andExpect(jsonPath("[0]value", equalTo(knownValue1))) .andExpect(jsonPath("[1]key", equalTo(knownKey2))) .andExpect(jsonPath("[1]value", equalTo(knownValue2))); @@ -786,7 +786,7 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest mvc.perform(put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey) .contentType(MediaType.APPLICATION_JSON).content(jsonObject.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); final DistributionSetMetadata assertDS = distributionSetManagement.findOne(testDS, knownKey); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java index 0dd90b35f..9a47d8483 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetTypeResourceTest.java @@ -68,7 +68,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration // generated in this test) mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[?(@.key==" + standardDsType.getKey() + ")]$..name", contains(standardDsType.getName()))) .andExpect(jsonPath("$.content.[?(@.key==" + standardDsType.getKey() + ")]$..description", @@ -107,7 +107,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration // descending mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:DESC")).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[0].id", equalTo(testType.getId().intValue()))) .andExpect(jsonPath("$.content.[0].name", equalTo("TestName123"))) .andExpect(jsonPath("$.content.[0].description", equalTo("Desc1234"))) @@ -121,7 +121,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration // ascending mvc.perform(get("/rest/v1/distributionsettypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "KEY:ASC")).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[3].id", equalTo(testType.getId().intValue()))) .andExpect(jsonPath("$.content.[3].name", equalTo("TestName123"))) .andExpect(jsonPath("$.content.[3].description", equalTo("Desc1234"))) @@ -152,7 +152,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration .perform(post("/rest/v1/distributionsettypes/").content(JsonBuilder.distributionSetTypes(types)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo("TestName1"))).andExpect(jsonPath("[0].key", equalTo("test1"))) .andExpect(jsonPath("[0].description", equalTo("Desc1"))) .andExpect(jsonPath("[0].createdBy", equalTo("uploadTester"))) @@ -258,7 +258,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/mandatorymoduletypes", testType.getId()) .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo(osType.getName()))) .andExpect(jsonPath("[0].description", equalTo(osType.getDescription()))) .andExpect(jsonPath("[0].maxAssignments", equalTo(1))).andExpect(jsonPath("[0].key", equalTo("os"))); @@ -277,7 +277,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration mvc.perform(get("/rest/v1/distributionsettypes/{dstID}/optionalmoduletypes", testType.getId()) .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo(appType.getName()))) .andExpect(jsonPath("[0].description", equalTo(appType.getDescription()))) .andExpect(jsonPath("[0].maxAssignments", equalTo(Integer.MAX_VALUE))) @@ -384,7 +384,7 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractRestIntegration mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.name", equalTo("TestName123"))) .andExpect(jsonPath("$.description", equalTo("Desc1234"))) .andExpect(jsonPath("$.createdBy", equalTo("uploadTester"))) diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java index b15ff7983..92552954c 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDownloadResourceTest.java @@ -11,8 +11,8 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.eclipse.hawkbit.cache.CacheConstants; import org.eclipse.hawkbit.cache.DownloadArtifactCache; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.cache.DownloadType; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.repository.model.Artifact; @@ -23,8 +23,6 @@ import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.cache.Cache; import org.springframework.context.annotation.Description; import ru.yandex.qatools.allure.annotations.Features; @@ -35,8 +33,7 @@ import ru.yandex.qatools.allure.annotations.Stories; public class MgmtDownloadResourceTest extends AbstractRestIntegrationTestWithMongoDB { @Autowired - @Qualifier(CacheConstants.DOWNLOAD_ID_CACHE) - private Cache downloadIdCache; + private DownloadIdCache downloadIdCache; private final String downloadIdSha1 = "downloadIdSha1"; @@ -47,7 +44,7 @@ public class MgmtDownloadResourceTest extends AbstractRestIntegrationTestWithMon final DistributionSet distributionSet = testdataFactory.createDistributionSet("Test"); final SoftwareModule softwareModule = distributionSet.getModules().stream().findFirst().get(); - final Artifact artifact = testdataFactory.createArtifacts(softwareModule.getId()).stream().findFirst().get(); + final Artifact artifact = testdataFactory.createArtifacts(softwareModule.getId()).stream().findFirst().get(); downloadIdCache.put(downloadIdSha1, new DownloadArtifactCache(DownloadType.BY_SHA1, artifact.getSha1Hash())); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java index e495c0d9d..0d64803cf 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtRolloutResourceTest.java @@ -125,7 +125,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { @Description("Testing the empty list is returned if no rollout exists") public void noRolloutReturnsEmptyList() throws Exception { mvc.perform(get("/rest/v1/rollouts")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(0))).andExpect(jsonPath("$.total", equalTo(0))); } @@ -138,7 +138,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { postRollout("rollout2", 5, dsA.getId(), "name==target2"); mvc.perform(get("/rest/v1/rollouts")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))) .andExpect(jsonPath("content[0].name", equalTo("rollout1"))) .andExpect(jsonPath("content[0].status", equalTo("ready"))) @@ -159,7 +159,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { postRollout("rollout2", 5, dsA.getId(), "name==target2"); mvc.perform(get("/rest/v1/rollouts?limit=1")).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(2))); } @@ -177,7 +177,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // retrieve rollout groups from created rollout mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(4))).andExpect(jsonPath("$.total", equalTo(4))) .andExpect(jsonPath("$.content[0].status", equalTo("ready"))) .andExpect(jsonPath("$.content[1].status", equalTo("ready"))) @@ -202,7 +202,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // check rollout is in running state mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("status", equalTo("running"))); } @@ -228,7 +228,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // check rollout is in running state mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("status", equalTo("paused"))); } @@ -258,7 +258,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // check rollout is in running state mvc.perform(get("/rest/v1/rollouts/{rolloutId}", rollout.getId())).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("id", equalTo(rollout.getId().intValue()))) .andExpect(jsonPath("status", equalTo("running"))); } @@ -320,7 +320,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // (amountTargets / groupSize = 2) mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups?sort=ID:ASC", rollout.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))) .andExpect(jsonPath("$.content[0].status", equalTo("running"))) .andExpect(jsonPath("$.content[1].status", equalTo("scheduled"))); @@ -344,7 +344,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // retrieve single rollout group with known ID mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}", rollout.getId(), firstGroup.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("id", equalTo(firstGroup.getId().intValue()))) .andExpect(jsonPath("status", equalTo("ready"))).andExpect(jsonPath("name", notNullValue())); } @@ -367,7 +367,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // retrieve targets from the first rollout group with known ID mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(5))).andExpect(jsonPath("$.total", equalTo(5))); } @@ -392,7 +392,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId()) .param("q", "controllerId==" + targets.get(0).getControllerId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))); } @@ -416,7 +416,7 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // retrieve targets from the first rollout group with known ID mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups/{groupId}/targets", rollout.getId(), firstGroup.getId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(5))).andExpect(jsonPath("$.total", equalTo(5))); } @@ -462,18 +462,18 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*2")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))) .andExpect(jsonPath("$.content[0].name", equalTo(rollout2.getName()))); mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==rollout*")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(3))).andExpect(jsonPath("$.total", equalTo(3))); mvc.perform(get("/rest/v1/rollouts").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==*1")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))); } @@ -492,19 +492,19 @@ public class MgmtRolloutResourceTest extends AbstractRestIntegrationTest { // retrieve rollout groups from created rollout mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()) .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1")).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(1))).andExpect(jsonPath("$.total", equalTo(1))) .andExpect(jsonPath("$.content[0].name", equalTo("group-1"))); mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()) .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group*")).andDo(MockMvcResultPrinter.print()) - .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(4))).andExpect(jsonPath("$.total", equalTo(4))); mvc.perform(get("/rest/v1/rollouts/{rolloutId}/deploygroups", rollout.getId()) .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, "name==group-1,name==group-2")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content", hasSize(2))).andExpect(jsonPath("$.total", equalTo(2))); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index a87580796..2bda57ddf 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -138,7 +138,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file) .accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.hashes.md5", equalTo(md5sum))) .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum))) .andExpect(jsonPath("$.size", equalTo(random.length))) @@ -213,7 +213,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file) .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.hashes.md5", equalTo(md5sum))) .andExpect(jsonPath("$.hashes.sha1", equalTo(sha1sum))) .andExpect(jsonPath("$.providedFilename", equalTo("orig"))).andExpect(status().isCreated()); @@ -237,7 +237,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(fileUpload("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).file(file) .param("filename", "customFilename").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.providedFilename", equalTo("customFilename"))).andExpect(status().isCreated()); // check result in db... @@ -341,7 +341,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // perform test mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}", sm.getId(), artifact.getId()) .accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.id", equalTo(artifact.getId().intValue()))) .andExpect(jsonPath("$.size", equalTo(random.length))) .andExpect(jsonPath("$.hashes.md5", equalTo(artifact.getMd5Hash()))) @@ -369,7 +369,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts", sm.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.[0].id", equalTo(artifact.getId().intValue()))) .andExpect(jsonPath("$.[0].size", equalTo(random.length))) .andExpect(jsonPath("$.[0].hashes.md5", equalTo(artifact.getMd5Hash()))) @@ -538,7 +538,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].name", contains("name1"))) .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].version", contains("version1"))) .andExpect(jsonPath("$.content.[?(@.id==" + os.getId() + ")].description", contains("description1"))) @@ -623,7 +623,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // only by name, only one exists per name mvc.perform(get("/rest/v1/softwaremodules?q=name==osName1").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].name", contains("osName1"))) .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].version", contains("1.0.0"))) .andExpect(jsonPath("$.content.[?(@.id==" + os1.getId() + ")].description", contains("description1"))) @@ -634,7 +634,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // by type, 2 software modules per type exists mvc.perform(get("/rest/v1/softwaremodules?q=type==application").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].name", contains("appName1"))) .andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].version", contains("3.0.0"))) .andExpect(jsonPath("$.content.[?(@.id==" + ah1.getId() + ")].description", contains("description1"))) @@ -650,7 +650,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // by type and version=2.0.0 -> only one result mvc.perform(get("/rest/v1/softwaremodules?q=type==runtime;version==2.0.0").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].name", contains("runtimeName1"))) .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].version", contains("2.0.0"))) .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].description", contains("description1"))) @@ -660,7 +660,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW // by type and version range >=2.0.0 -> 2 result mvc.perform(get("/rest/v1/softwaremodules?q=type==runtime;version=ge=2.0.0").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].name", contains("runtimeName1"))) .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].version", contains("2.0.0"))) .andExpect(jsonPath("$.content.[?(@.id==" + jvm1.getId() + ")].description", contains("description1"))) @@ -691,14 +691,14 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW @Test @WithUser(principal = "uploadTester", allSpPermissions = true) @Description("Tests GET request on /rest/v1/softwaremodules/{smId}.") - public void getSoftareModule() throws Exception { + public void getSoftwareModule() throws Exception { SoftwareModule os = entityFactory.generateSoftwareModule(osType, "name1", "version1", "description1", "vendor1"); os = softwareManagement.createSoftwareModule(os); mvc.perform(get("/rest/v1/softwaremodules/{smId}", os.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.name", equalTo("name1"))).andExpect(jsonPath("$.version", equalTo("version1"))) .andExpect(jsonPath("$.description", equalTo("description1"))) .andExpect(jsonPath("$.vendor", equalTo("vendor1"))).andExpect(jsonPath("$.type", equalTo("os"))) @@ -718,7 +718,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules/{smId}", jvm.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.name", equalTo("name1"))).andExpect(jsonPath("$.version", equalTo("version1"))) .andExpect(jsonPath("$.description", equalTo("description1"))) .andExpect(jsonPath("$.vendor", equalTo("vendor1"))).andExpect(jsonPath("$.type", equalTo("runtime"))) @@ -738,7 +738,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(get("/rest/v1/softwaremodules/{smId}", ah.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.name", equalTo("name1"))).andExpect(jsonPath("$.version", equalTo("version1"))) .andExpect(jsonPath("$.description", equalTo("description1"))) .andExpect(jsonPath("$.vendor", equalTo("vendor1"))) @@ -778,7 +778,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW .perform(post("/rest/v1/softwaremodules/").content(JsonBuilder.softwareModules(modules)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo("name1"))) .andExpect(jsonPath("[0].version", equalTo("version1"))) .andExpect(jsonPath("[0].description", equalTo("description1"))) @@ -941,7 +941,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(post("/rest/v1/softwaremodules/{swId}/metadata", sm.getId()).contentType(MediaType.APPLICATION_JSON) .content(jsonArray.toString())).andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0]key", equalTo(knownKey1))).andExpect(jsonPath("[0]value", equalTo(knownValue1))) .andExpect(jsonPath("[1]key", equalTo(knownKey2))) .andExpect(jsonPath("[1]value", equalTo(knownValue2))); @@ -971,7 +971,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractRestIntegrationTestW mvc.perform(put("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey) .contentType(MediaType.APPLICATION_JSON).content(jsonObject.toString())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("key", equalTo(knownKey))).andExpect(jsonPath("value", equalTo(updateValue))); final SoftwareModuleMetadata assertDS = softwareManagement.findSoftwareModuleMetadata(sm.getId(), knownKey); diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java index 8150eba54..893164a53 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleTypeResourceTest.java @@ -64,7 +64,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[?(@.key==" + osType.getKey() + ")].name", contains(osType.getName()))) .andExpect(jsonPath("$.content.[?(@.key==" + osType.getKey() + ")].description", contains(osType.getDescription()))) @@ -108,7 +108,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:DESC")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[1].id", equalTo(testType.getId().intValue()))) .andExpect(jsonPath("$.content.[1].name", equalTo("TestName123"))) .andExpect(jsonPath("$.content.[1].description", equalTo("Desc1234"))) @@ -124,7 +124,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT mvc.perform(get("/rest/v1/softwaremoduletypes").accept(MediaType.APPLICATION_JSON) .param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "MAXASSIGNMENTS:ASC")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.content.[2].id", equalTo(testType.getId().intValue()))) .andExpect(jsonPath("$.content.[2].name", equalTo("TestName123"))) .andExpect(jsonPath("$.content.[2].description", equalTo("Desc1234"))) @@ -171,7 +171,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT .perform(post("/rest/v1/softwaremoduletypes/").content(JsonBuilder.softwareModuleTypes(types)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo("TestName1"))).andExpect(jsonPath("[0].key", equalTo("test1"))) .andExpect(jsonPath("[0].description", equalTo("Desc1"))) .andExpect(jsonPath("[0].createdBy", equalTo("uploadTester"))) @@ -214,7 +214,7 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractRestIntegrationT mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("$.name", equalTo("TestName123"))) .andExpect(jsonPath("$.description", equalTo("Desc1234"))) .andExpect(jsonPath("$.maxAssignments", equalTo(5))) diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java index 5694c9bfb..c020f087c 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetFilterQueryResourceTest.java @@ -8,37 +8,30 @@ */ package org.eclipse.hawkbit.mgmt.rest.resource; -import static com.google.common.collect.Lists.newArrayList; import static org.fest.assertions.api.Assertions.assertThat; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.Matchers.*; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -import java.util.*; -import java.util.stream.Collectors; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.eclipse.hawkbit.exception.SpServerError; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; -import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; -import org.eclipse.hawkbit.repository.model.*; -import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.exception.MessageNotReadableException; import org.eclipse.hawkbit.rest.json.model.ExceptionInfo; -import org.eclipse.hawkbit.rest.util.JsonBuilder; import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter; import org.json.JSONObject; import org.junit.Test; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Slice; -import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MvcResult; -import com.jayway.jsonpath.JsonPath; - import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; import ru.yandex.qatools.allure.annotations.Stories; @@ -51,8 +44,6 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Target Filter Query Resource") public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTest { - private static final String TARGET_DESCRIPTION_TEST = "created in test"; - private static final String JSON_PATH_ROOT = "$"; // fields, attributes @@ -75,17 +66,16 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe private static final String JSON_PATH_QUERY = JSON_PATH_ROOT + JSON_PATH_FIELD_QUERY; private static final String JSON_PATH_AUTO_ASSIGN_DS = JSON_PATH_ROOT + JSON_PATH_FIELD_AUTO_ASSIGN_DS; - @Test @Description("Ensures that deletion is executed if permitted.") public void deleteTargetFilterQueryReturnsOK() throws Exception { final String filterName = "filter_01"; - TargetFilterQuery filterQuery = createSingleTargetFilterQuery(filterName, "name=test_01"); + final TargetFilterQuery filterQuery = createSingleTargetFilterQuery(filterName, "name=test_01"); mvc.perform(delete(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId())) .andExpect(status().isOk()); - TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryById(filterQuery.getId()); + final TargetFilterQuery tfq = targetFilterQueryManagement.findTargetFilterQueryById(filterQuery.getId()); assertThat(tfq).isNull(); } @@ -116,7 +106,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe final String body = new JSONObject().put("query", filterQuery2).toString(); // prepare - TargetFilterQuery tfq = createSingleTargetFilterQuery(filterName, filterQuery); + final TargetFilterQuery tfq = createSingleTargetFilterQuery(filterName, filterQuery); mvc.perform(put(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId()).content(body) .contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -124,7 +114,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe .andExpect(jsonPath("$.query", equalTo(filterQuery2))) .andExpect(jsonPath("$.name", equalTo(filterName))); - TargetFilterQuery tfqCheck = targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()); + final TargetFilterQuery tfqCheck = targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()); assertThat(tfqCheck.getQuery()).isEqualTo(filterQuery2); assertThat(tfqCheck.getName()).isEqualTo(filterName); } @@ -149,12 +139,11 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe .andExpect(jsonPath("$.query", equalTo(filterQuery))) .andExpect(jsonPath("$.name", equalTo(filterName2))); - TargetFilterQuery tfqCheck = targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()); + final TargetFilterQuery tfqCheck = targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()); assertThat(tfqCheck.getQuery()).isEqualTo(filterQuery); assertThat(tfqCheck.getName()).isEqualTo(filterName2); } - @Test @Description("Ensures that request returns list of filters in defined format.") public void getTargetFilterQueryWithoutAdditionalRequestParameters() throws Exception { @@ -250,7 +239,8 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe final String knownQuery = "name=test01"; final String knownName = "someName"; final TargetFilterQuery tfq = createSingleTargetFilterQuery(knownName, knownQuery); - final String hrefPrefix = "http://localhost"+MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING+"/" + tfq.getId(); + final String hrefPrefix = "http://localhost" + MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + + tfq.getId(); // test mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -302,13 +292,15 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe final DistributionSet set = testdataFactory.createDistributionSet("one"); final TargetFilterQuery tfq = createSingleTargetFilterQuery(knownName, knownQuery); - mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/"+tfq.getId()+"/autoAssignDS") + mvc.perform(post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS") .content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).getAutoAssignDistributionSet()).isEqualTo(set); + assertThat(targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).getAutoAssignDistributionSet()) + .isEqualTo(set); - final String hrefPrefix = "http://localhost"+MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING+"/" + tfq.getId(); + final String hrefPrefix = "http://localhost" + MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + + tfq.getId(); mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) @@ -336,20 +328,18 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractRestIntegrationTe assertThat(targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).getAutoAssignDistributionSet()) .isEqualTo(set); - mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/"+tfq.getId()+"/autoAssignDS")) - .andExpect(status().isOk()) - .andExpect(jsonPath(JSON_PATH_NAME, equalTo(dsName))); + mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")) + .andExpect(status().isOk()).andExpect(jsonPath(JSON_PATH_NAME, equalTo(dsName))); - mvc.perform(delete(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/"+tfq.getId()+"/autoAssignDS")) + mvc.perform(delete(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")) .andExpect(status().isNoContent()); assertThat(targetFilterQueryManagement.findTargetFilterQueryById(tfq.getId()).getAutoAssignDistributionSet()) .isNull(); - mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/"+tfq.getId()+"/autoAssignDS")) + mvc.perform(get(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + tfq.getId() + "/autoAssignDS")) .andExpect(status().isNoContent()); - } private TargetFilterQuery createSingleTargetFilterQuery(final String name, final String query) { diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index 0f8d1366b..b35a21175 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -735,7 +735,7 @@ public class MgmtTargetResourceTest extends AbstractRestIntegrationTest { .perform(post("/rest/v1/targets/").content(JsonBuilder.targets(targets, true)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(jsonPath("[0].name", equalTo("testname1"))) .andExpect(jsonPath("[0].controllerId", equalTo("id1"))) .andExpect(jsonPath("[0].description", equalTo("testid1"))) diff --git a/hawkbit-mgmt-resource/src/test/resources/application-test.properties b/hawkbit-mgmt-resource/src/test/resources/application-test.properties index cd98bb23f..3b4a31adf 100644 --- a/hawkbit-mgmt-resource/src/test/resources/application-test.properties +++ b/hawkbit-mgmt-resource/src/test/resources/application-test.properties @@ -7,6 +7,9 @@ # http://www.eclipse.org/legal/epl-v10.html # +logging.level.=INFO +logging.level.org.eclipse.persistence=ERROR + # supported: H2, MYSQL hawkbit.server.database=H2 @@ -46,4 +49,4 @@ MYSQL.spring.datasource.password= # SP Controller configuration hawkbit.controller.pollingTime=00:01:00 -hawkbit.controller.pollingOverdueTime=00:01:00 +hawkbit.controller.pollingOverdueTime=00:01:00 \ No newline at end of file diff --git a/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml b/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml deleted file mode 100644 index 6dd6c94e0..000000000 --- a/hawkbit-mgmt-resource/src/test/resources/logback-spring.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-api/pom.xml b/hawkbit-repository/hawkbit-repository-api/pom.xml index 431148592..079c038ab 100644 --- a/hawkbit-repository/hawkbit-repository-api/pom.xml +++ b/hawkbit-repository/hawkbit-repository-api/pom.xml @@ -8,7 +8,8 @@ http://www.eclipse.org/legal/epl-v10.html --> - + 4.0.0 org.eclipse.hawkbit @@ -36,6 +37,10 @@ org.springframework.hateoas spring-hateoas + + org.springframework.cloud + spring-cloud-bus + diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index ac1d7e201..b5b39ff59 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -16,7 +16,7 @@ import java.util.Optional; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent; +import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException; @@ -25,7 +25,6 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.Artifact; -import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; @@ -34,8 +33,6 @@ import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.security.access.prepost.PreAuthorize; -import com.google.common.eventbus.EventBus; - /** * Service layer for all operations of the DDI API (with access permissions only * for the controller). @@ -59,7 +56,7 @@ public interface ControllerManagement { Action addCancelActionStatus(@NotNull ActionStatus actionStatus); /** - * Sends the download progress and notifies the {@link EventBus} with a + * Sends the download progress and notifies the event publisher with a * {@link DownloadProgressEvent}. * * @param statusId @@ -148,19 +145,6 @@ public interface ControllerManagement { @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) Target findOrRegisterTargetIfItDoesNotexist(@NotEmpty String controllerId, URI address); - /** - * Retrieves all {@link SoftwareModule}s which are assigned to the given - * {@link DistributionSet}. - * - * @param distributionSet - * the distribution set which should be assigned to the returned - * {@link SoftwareModule}s - * @return a list of {@link SoftwareModule}s assigned to given - * {@code distributionSet} - */ - @PreAuthorize(SpringEvalExpressions.IS_CONTROLLER) - List findSoftwareModulesByDistributionSet(@NotNull DistributionSet distributionSet); - /** * Retrieves last {@link Action} for a download of an artifact of given * module and target. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 6b100e30b..b14cc9131 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -24,6 +24,7 @@ import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java index 337475318..88cc36330 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/RolloutManagement.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.repository; import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java index 9c467f9dd..6b57d277b 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.repository; +import java.io.Serializable; + import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; @@ -40,7 +42,8 @@ public interface TenantConfigurationManagement { * if the property cannot be converted to the given */ @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) - TenantConfigurationValue addOrUpdateConfiguration(TenantConfigurationKey configurationKey, T value); + TenantConfigurationValue addOrUpdateConfiguration( + TenantConfigurationKey configurationKey, T value); /** * Build the tenant configuration by the given key @@ -55,8 +58,8 @@ public interface TenantConfigurationManagement { * or returns the tenant configuration value */ @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) - TenantConfigurationValue buildTenantConfigurationValueByKey(TenantConfigurationKey configurationKey, - Class propertyType, TenantConfiguration tenantConfiguration); + TenantConfigurationValue buildTenantConfigurationValueByKey( + TenantConfigurationKey configurationKey, Class propertyType, TenantConfiguration tenantConfiguration); /** * Deletes a specific configuration for the current tenant. Does nothing in @@ -87,7 +90,7 @@ public interface TenantConfigurationManagement { * {@code propertyType} */ @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) - TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey); + TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey); /** * Retrieves a configuration value from the e.g. tenant overwritten @@ -113,7 +116,7 @@ public interface TenantConfigurationManagement { * {@code propertyType} */ @PreAuthorize(value = SpringEvalExpressions.HAS_AUTH_TENANT_CONFIGURATION) - TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey, + TenantConfigurationValue getConfigurationValue(TenantConfigurationKey configurationKey, Class propertyType); /** diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/CustomEvents.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/CustomEvents.java similarity index 91% rename from hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/CustomEvents.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/CustomEvents.java index 4416e1a63..c723dd684 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/eventbus/event/CustomEvents.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/CustomEvents.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.eventbus.event; +package org.eclipse.hawkbit.repository.event; /** * Events to be published to refresh data on UI. diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/CacheConstants.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/TenantAwareEvent.java similarity index 52% rename from hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/CacheConstants.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/TenantAwareEvent.java index 6bc28d7f3..90c228b4f 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/cache/CacheConstants.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/TenantAwareEvent.java @@ -6,22 +6,18 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.cache; +package org.eclipse.hawkbit.repository.event; /** - * Cache Constants. - * - * + * An event declaration which holds an revision for each event so consumers have + * the chance to know if they might already retrieved a newer event. * */ -public final class CacheConstants { +@FunctionalInterface +public interface TenantAwareEvent { /** - * Constant for download cache id. + * @return the tenant of the event. */ - public static final String DOWNLOAD_ID_CACHE = "DowonloadIdCache"; - - private CacheConstants() { - } - + String getTenant(); } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DistributionSetDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DistributionSetDeletedEvent.java new file mode 100644 index 000000000..96bf12752 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DistributionSetDeletedEvent.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import org.eclipse.hawkbit.repository.model.DistributionSet; + +/** + * Defines the remote event for deletion of {@link DistributionSet}. + */ +public class DistributionSetDeletedEvent extends RemoteIdEvent { + + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public DistributionSetDeletedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param tenant + * the tenant + * @param entityId + * the entity id + * @param applicationId + * the origin application id + */ + public DistributionSetDeletedEvent(final String tenant, final Long entityId, final String applicationId) { + super(entityId, tenant, applicationId); + } +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DistributionSetTagDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DistributionSetTagDeletedEvent.java new file mode 100644 index 000000000..77dfc59cc --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DistributionSetTagDeletedEvent.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import org.eclipse.hawkbit.repository.model.DistributionSetTag; + +/** + * Defines the the remote event of delete a {@link DistributionSetTag}. + */ +public class DistributionSetTagDeletedEvent extends RemoteIdEvent { + + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public DistributionSetTagDeletedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor for json serialization. + * + * @param tenant + * the tenant + * @param entityId + * the entity id + * @param applicationId + * the origin application id + */ + + public DistributionSetTagDeletedEvent(final String tenant, final Long entityId, final String applicationId) { + super(entityId, tenant, applicationId); + } +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DownloadProgressEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DownloadProgressEvent.java new file mode 100644 index 000000000..568bc5a28 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/DownloadProgressEvent.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +/** + * TenantAwareEvent that contains an updated download progress for a given + * ActionStatus that was written for a download request. + * + */ +public class DownloadProgressEvent extends RemoteTenantAwareEvent { + + private static final long serialVersionUID = 1L; + + private Long shippedBytesSinceLast; + + /** + * Default constructor. + */ + public DownloadProgressEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param tenant + * the tenant + * @param shippedBytesSinceLast + * the shippedBytesSinceLast + * @param applicationId + * the application id. + */ + public DownloadProgressEvent(final String tenant, final Long shippedBytesSinceLast, final String applicationId) { + super(shippedBytesSinceLast, tenant, applicationId); + this.shippedBytesSinceLast = shippedBytesSinceLast; + } + + public long getShippedBytesSinceLast() { + return shippedBytesSinceLast; + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManager.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManager.java new file mode 100644 index 000000000..d6cd7d2e1 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManager.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; + +/** + * Loads an entity e.g. if a remote event is received. + */ +@FunctionalInterface +public interface EventEntityManager { + + /** + * Find an entity by given id and return it. + * + * @param tenant + * the tenant + * @param id + * the id + * @param entityType + * the entity type + * @return the entity + */ + E findEntity(String tenant, Long id, Class entityType); + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManagerHolder.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManagerHolder.java new file mode 100644 index 000000000..9c02b48eb --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/EventEntityManagerHolder.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import org.springframework.beans.factory.annotation.Autowired; + +/** + * A singleton bean which holds the event entity manager to have autowiring in + * the events. + * + */ +public final class EventEntityManagerHolder { + + private static final EventEntityManagerHolder SINGLETON = new EventEntityManagerHolder(); + + @Autowired + private EventEntityManager eventEntityManager; + + private EventEntityManagerHolder() { + + } + + /** + * @return the cache manager holder singleton instance + */ + public static EventEntityManagerHolder getInstance() { + return SINGLETON; + } + + /** + * @return the eventEntityManager + */ + public EventEntityManager getEventEntityManager() { + return eventEntityManager; + } +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/RemoteIdEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/RemoteIdEvent.java new file mode 100644 index 000000000..5fb7cca27 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/RemoteIdEvent.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +/** + * An base definition class for an event which contains an id. + * + */ +public class RemoteIdEvent extends RemoteTenantAwareEvent { + + private static final long serialVersionUID = 1L; + + private Long entityId; + + /** + * Default constructor. + */ + protected RemoteIdEvent() { + // for serialization libs like jackson + } + + /** + * Constructor for json serialization. + * + * @param entityId + * the entity Id + * @param tenant + * the tenant + * @param applicationId + * the origin application id + */ + protected RemoteIdEvent(final Long entityId, final String tenant, final String applicationId) { + super(entityId, tenant, applicationId); + this.entityId = entityId; + } + + public Long getEntityId() { + return entityId; + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEvent.java new file mode 100644 index 000000000..0539f05b0 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEvent.java @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import org.eclipse.hawkbit.repository.event.TenantAwareEvent; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; + +/** + * A distributed tenant aware event. It's the base class of the other + * distributed events. All the necessary information of distributing events to + * other nodes. + * + */ +public class RemoteTenantAwareEvent extends RemoteApplicationEvent implements TenantAwareEvent { + private static final long serialVersionUID = 1L; + + private String tenant; + + /** + * Default constructor. + */ + protected RemoteTenantAwareEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param source + * the for the remote event. + * @param tenant + * the tenant + * @param applicationId + * the applicationId + */ + public RemoteTenantAwareEvent(final Object source, final String tenant, final String applicationId) { + super(source, applicationId, "**"); + this.tenant = tenant; + } + + @Override + public String getTenant() { + return tenant; + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetAssignDistributionSetEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetAssignDistributionSetEvent.java new file mode 100644 index 000000000..db88c280e --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetAssignDistributionSetEvent.java @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import java.util.Collection; +import java.util.Collections; + +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.SoftwareModule; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * TenantAwareEvent that gets sent when a distribution set gets assigned to a + * target. + */ +public class TargetAssignDistributionSetEvent extends RemoteTenantAwareEvent { + + private static final long serialVersionUID = 1L; + + private Long actionId; + + private Long distributionSetId; + + private String controllerId; + + private transient Collection modules; + + /** + * Default constructor. + */ + public TargetAssignDistributionSetEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param action + * the action + * @param applicationId + * the application id. + */ + public TargetAssignDistributionSetEvent(final Action action, final String applicationId) { + this(action.getTenant(), action.getId(), action.getDistributionSet().getId(), + action.getTarget().getControllerId(), applicationId); + this.modules = action.getDistributionSet().getModules(); + + } + + private TargetAssignDistributionSetEvent(final String tenant, final Long actionId, final Long distributionSetId, + final String controllerId, final String applicationId) { + super(actionId, tenant, applicationId); + this.actionId = actionId; + this.distributionSetId = distributionSetId; + this.controllerId = controllerId; + } + + public Long getActionId() { + return actionId; + } + + public String getControllerId() { + return controllerId; + } + + public Long getDistributionSetId() { + return distributionSetId; + } + + /** + * @return modules if Event has been published by same node otherwise empty. + */ + @JsonIgnore + public Collection getModules() { + if (modules == null) { + return Collections.emptyList(); + } + + return modules; + } +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetDeletedEvent.java new file mode 100644 index 000000000..3ae9556f3 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetDeletedEvent.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import org.eclipse.hawkbit.repository.model.Target; + +/** + * + * Defines the remote event of deleting a {@link Target}. + */ +public class TargetDeletedEvent extends RemoteIdEvent { + + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public TargetDeletedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor for json serialization. + * + * @param tenant + * the tenant + * @param entityId + * the entity id + * @param applicationId + * the origin application id + */ + public TargetDeletedEvent(final String tenant, final Long entityId, final String applicationId) { + super(entityId, tenant, applicationId); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetTagDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetTagDeletedEvent.java new file mode 100644 index 000000000..846ad39cf --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/TargetTagDeletedEvent.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import org.eclipse.hawkbit.repository.model.TargetTag; + +/** + * Defines the remote event of delete a {@link TargetTag}. + * + */ +public class TargetTagDeletedEvent extends RemoteIdEvent { + + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public TargetTagDeletedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor for json serialization. + * + * @param tenant + * the tenant + * @param entityId + * the entity id + * @param applicationId + * the origin application id + */ + public TargetTagDeletedEvent(final String tenant, final Long entityId, final String applicationId) { + super(entityId, tenant, applicationId); + } +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionCreatedEvent.java new file mode 100644 index 000000000..aa62485e7 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionCreatedEvent.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.Action; + +/** + * Defines the remote event of creating a new {@link Action}. + */ +public class ActionCreatedEvent extends RemoteEntityEvent { + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public ActionCreatedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor + * + * @param action + * the created action + * @param applicationId + * the origin application id + */ + public ActionCreatedEvent(final Action action, final String applicationId) { + super(action, applicationId); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionUpdatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionUpdatedEvent.java new file mode 100644 index 000000000..ff9783fe1 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionUpdatedEvent.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.Action; + +/** + * Defines the remote event of updated a {@link Action}. + */ +public class ActionUpdatedEvent extends RemoteEntityEvent { + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public ActionUpdatedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor + * + * @param action + * the updated action + * @param applicationId + * the origin application id + */ + public ActionUpdatedEvent(final Action action, final String applicationId) { + super(action, applicationId); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/CancelTargetAssignmentEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/CancelTargetAssignmentEvent.java new file mode 100644 index 000000000..ea105ac9c --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/CancelTargetAssignmentEvent.java @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.Target; + +/** + * Event that gets sent when the assignment of a distribution set to a target + * gets canceled. + */ +public class CancelTargetAssignmentEvent extends RemoteEntityEvent { + + private static final long serialVersionUID = 1L; + + private Long actionId; + + /** + * Default constructor. + */ + public CancelTargetAssignmentEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param baseEntity + * the target + * @param actionId + * the actionId + * @param applicationId + * the origin application id + */ + public CancelTargetAssignmentEvent(final Target baseEntity, final Long actionId, final String applicationId) { + super(baseEntity, applicationId); + this.actionId = actionId; + } + + /** + * @return the action id of the assignment + */ + public Long getActionId() { + return actionId; + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetCreatedEvent.java new file mode 100644 index 000000000..27d36f2de --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetCreatedEvent.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.DistributionSet; + +/** + * Defines the the remote of creating a new {@link DistributionSet}. + * + */ +public class DistributionSetCreatedEvent extends RemoteEntityEvent { + + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public DistributionSetCreatedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param distributionSet + * the created distributionSet + * @param applicationId + * the origin application id + */ + public DistributionSetCreatedEvent(final DistributionSet distributionSet, final String applicationId) { + super(distributionSet, applicationId); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagCreatedEvent.java similarity index 53% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagCreatedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagCreatedEvent.java index d7226275b..82e4b62fb 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagCreatedEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagCreatedEvent.java @@ -6,26 +6,35 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.eventbus.event; +package org.eclipse.hawkbit.repository.event.remote.entity; import org.eclipse.hawkbit.repository.model.DistributionSetTag; /** - * Defines the {@link AbstractBaseEntityEvent} for creation of a new + * Defines the {@link RemoteEntityEvent} for creation of a new * {@link DistributionSetTag}. * */ -public class DistributionSetTagCreatedEvent extends AbstractBaseEntityEvent { +public class DistributionSetTagCreatedEvent extends RemoteEntityEvent { private static final long serialVersionUID = 1L; + /** + * Default constructor. + */ + public DistributionSetTagCreatedEvent() { + // for serialization libs like jackson + } + /** * Constructor. * * @param tag - * the tag which is updated + * the tag which is deleted + * @param applicationId + * the origin application id */ - public DistributionSetTagCreatedEvent(final DistributionSetTag tag) { - super(tag); + public DistributionSetTagCreatedEvent(final DistributionSetTag tag, final String applicationId) { + super(tag, applicationId); } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagUpdateEvent.java similarity index 51% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagUpdateEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagUpdateEvent.java index d74872b01..c55114ddb 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagUpdateEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagUpdateEvent.java @@ -6,26 +6,34 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.eventbus.event; +package org.eclipse.hawkbit.repository.event.remote.entity; import org.eclipse.hawkbit.repository.model.DistributionSetTag; /** - * Defines the {@link AbstractBaseEntityEvent} for update a - * {@link DistributionSetTag}. + * Defines the remote event for update a {@link DistributionSetTag}. * */ -public class DistributionSetTagUpdateEvent extends AbstractBaseEntityEvent { +public class DistributionSetTagUpdateEvent extends RemoteEntityEvent { private static final long serialVersionUID = 1L; + /** + * Default constructor. + */ + public DistributionSetTagUpdateEvent() { + // for serialization libs like jackson + } + /** * Constructor. * * @param tag - * the tag which is updated + * tag the tag which is updated + * @param applicationId + * the applicationID */ - public DistributionSetTagUpdateEvent(final DistributionSetTag tag) { - super(tag); + public DistributionSetTagUpdateEvent(final DistributionSetTag tag, final String applicationId) { + super(tag, applicationId); } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetUpdateEvent.java new file mode 100644 index 000000000..a6a3bf8d4 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetUpdateEvent.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.DistributionSet; + +/** + * Defines the remote event for updating a {@link DistributionSet}. + * + */ +public class DistributionSetUpdateEvent extends RemoteEntityEvent { + + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public DistributionSetUpdateEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param ds + * Distribution Set + * @param applicationId + * the origin application id + */ + public DistributionSetUpdateEvent(final DistributionSet ds, final String applicationId) { + super(ds, applicationId); + } +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RemoteEntityEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RemoteEntityEvent.java new file mode 100644 index 000000000..c01e04858 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RemoteEntityEvent.java @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.apache.commons.lang3.ClassUtils; +import org.eclipse.hawkbit.repository.event.remote.EventEntityManagerHolder; +import org.eclipse.hawkbit.repository.event.remote.RemoteIdEvent; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * A base definition class for remote events which contain a tenant aware base + * entity. + * + * @param + * the type of the entity + */ +public class RemoteEntityEvent extends RemoteIdEvent { + + private static final Logger LOG = LoggerFactory.getLogger(RemoteEntityEvent.class); + + private static final long serialVersionUID = 1L; + + private String entityClass; + + private transient E entity; + + /** + * Default constructor. + */ + protected RemoteEntityEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param baseEntity + * the base entity + * @param applicationId + * the origin application id + */ + protected RemoteEntityEvent(final E baseEntity, final String applicationId) { + super(baseEntity.getId(), baseEntity.getTenant(), applicationId); + this.entityClass = baseEntity.getClass().getName(); + this.entity = baseEntity; + } + + /** + * @return the entityClass + */ + public String getEntityClass() { + return entityClass; + } + + @JsonIgnore + public E getEntity() { + if (entity == null) { + entity = reloadEntityFromRepository(); + } + return entity; + } + + @SuppressWarnings("unchecked") + private E reloadEntityFromRepository() { + try { + final Class clazz = (Class) ClassUtils.getClass(entityClass); + return EventEntityManagerHolder.getInstance().getEventEntityManager().findEntity(getTenant(), getEntityId(), + clazz); + } catch (final ClassNotFoundException e) { + LOG.error("Cannot reload entity because class is not found", e); + } + return null; + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupCreatedEvent.java new file mode 100644 index 000000000..65519ea84 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupCreatedEvent.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.RolloutGroup; + +/** + * TenantAwareEvent definition which is been published in case a rollout group + * has been created for a specific rollout. + * + */ +public class RolloutGroupCreatedEvent extends RemoteEntityEvent { + + private static final long serialVersionUID = 1L; + + private Long rolloutId; + + /** + * Default constructor. + */ + public RolloutGroupCreatedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor + * + * @param rolloutGroup + * the updated rolloutGroup + * @param applicationId + * the origin application id + */ + public RolloutGroupCreatedEvent(final RolloutGroup rolloutGroup, final String applicationId) { + super(rolloutGroup, applicationId); + this.rolloutId = rolloutGroup.getRollout().getId(); + } + + public Long getRolloutId() { + return rolloutId; + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupUpdatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupUpdatedEvent.java new file mode 100644 index 000000000..35089dd53 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupUpdatedEvent.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.RolloutGroup; + +/** + * Defines the remote event of updated a {@link RolloutGroup}. + */ +public class RolloutGroupUpdatedEvent extends RemoteEntityEvent { + + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public RolloutGroupUpdatedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor + * + * @param rolloutGroup + * the updated rolloutGroup + * @param applicationId + * the origin application id + */ + public RolloutGroupUpdatedEvent(final RolloutGroup rolloutGroup, final String applicationId) { + super(rolloutGroup, applicationId); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutUpdatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutUpdatedEvent.java new file mode 100644 index 000000000..fb0b85125 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutUpdatedEvent.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.Rollout; + +/** + * Defines the remote event of updated a {@link Rollout}. + */ +public class RolloutUpdatedEvent extends RemoteEntityEvent { + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public RolloutUpdatedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor + * + * @param rollout + * the updated rollout + * @param applicationId + * the origin application id + */ + public RolloutUpdatedEvent(final Rollout rollout, final String applicationId) { + super(rollout, applicationId); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetCreatedEvent.java new file mode 100644 index 000000000..04fe01827 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetCreatedEvent.java @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.Target; + +/** + * Defines the remote event of creating a new {@link Target}. + * + */ +public class TargetCreatedEvent extends RemoteEntityEvent { + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public TargetCreatedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param baseEntity + * the target + * @param applicationId + * the origin application id + */ + public TargetCreatedEvent(final Target baseEntity, final String applicationId) { + super(baseEntity, applicationId); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagCreatedEvent.java similarity index 51% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagDeletedEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagCreatedEvent.java index ebf6c73c9..f2d6ac7f9 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagDeletedEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagCreatedEvent.java @@ -6,25 +6,34 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.eventbus.event; +package org.eclipse.hawkbit.repository.event.remote.entity; import org.eclipse.hawkbit.repository.model.TargetTag; /** - * Defines the {@link AbstractBaseEntityEvent} of update a {@link TargetTag}. + * Defines the remote event for the creation of a new {@link TargetTag}. * */ -public class TargetTagDeletedEvent extends AbstractBaseEntityEvent { +public class TargetTagCreatedEvent extends RemoteEntityEvent { private static final long serialVersionUID = 1L; + /** + * Default constructor. + */ + public TargetTagCreatedEvent() { + // for serialization libs like jackson + } + /** * Constructor. * * @param tag * the tag which is deleted + * @param applicationId + * the origin application id */ - public TargetTagDeletedEvent(final TargetTag tag) { - super(tag); + public TargetTagCreatedEvent(final TargetTag tag, final String applicationId) { + super(tag, applicationId); } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagUpdateEvent.java similarity index 51% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagUpdateEvent.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagUpdateEvent.java index f87443235..8fadb5c89 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagUpdateEvent.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagUpdateEvent.java @@ -6,25 +6,34 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.eventbus.event; +package org.eclipse.hawkbit.repository.event.remote.entity; import org.eclipse.hawkbit.repository.model.TargetTag; /** - * Defines the {@link AbstractBaseEntityEvent} for update a {@link TargetTag}. + * Defines the remote event for updating a {@link TargetTag}. * */ -public class TargetTagUpdateEvent extends AbstractBaseEntityEvent { +public class TargetTagUpdateEvent extends RemoteEntityEvent { private static final long serialVersionUID = 1L; + /** + * Default constructor. + */ + public TargetTagUpdateEvent() { + // for serialization libs like jackson + } + /** * Constructor. * * @param tag * the tag which is updated + * @param applicationId + * the origin application id */ - public TargetTagUpdateEvent(final TargetTag tag) { - super(tag); + public TargetTagUpdateEvent(final TargetTag tag, final String applicationId) { + super(tag, applicationId); } } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetUpdatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetUpdatedEvent.java new file mode 100644 index 000000000..f8e89a674 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetUpdatedEvent.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.model.Target; + +/** + * Defines the remote event for updating a {@link Target}. + * + */ +public class TargetUpdatedEvent extends RemoteEntityEvent { + + private static final long serialVersionUID = 1L; + + /** + * Default constructor. + */ + public TargetUpdatedEvent() { + // for serialization libs like jackson + } + + /** + * Constructor. + * + * @param baseEntity + * Target entity + * @param applicationId + * the origin application id + */ + public TargetUpdatedEvent(final Target baseEntity, final String applicationId) { + super(baseEntity, applicationId); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractBaseEntityEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractBaseEntityEvent.java deleted file mode 100644 index d13e89ee7..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractBaseEntityEvent.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent; -import org.eclipse.hawkbit.eventbus.event.EntityEvent; -import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; - -/** - * An abstract definition class for {@link EntityEvent} for - * {@link TenantAwareBaseEntity}s, which holds the {@link TenantAwareBaseEntity} - * . - * - * - * - * @param - * the type of the {@link TenantAwareBaseEntity} - */ -public abstract class AbstractBaseEntityEvent extends AbstractDistributedEvent - implements EntityEvent { - - /** - * - */ - private static final long serialVersionUID = 1L; - private final E entity; - - /** - * @param baseEntity - * the entity which has been created or modified - */ - public AbstractBaseEntityEvent(final E baseEntity) { - super(baseEntity.getOptLockRevision(), baseEntity.getTenant()); - this.entity = baseEntity; - } - - @Override - public E getEntity() { - return entity; - } - - @Override - public T getEntity(final Class entityClass) { - return entityClass.cast(entity); - } - - @Override - public String getTenant() { - return entity.getTenant(); - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java deleted file mode 100644 index 2520ebc9c..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/AbstractPropertyChangeEvent.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import java.util.Map; - -import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; - -/** - * Property change event. - * - * @param - */ -public class AbstractPropertyChangeEvent extends AbstractBaseEntityEvent { - - private static final long serialVersionUID = -3671601415138242311L; - private final transient Map changeSet; - - /** - * Initialize base entity and property changed with old and new value. - * - * @param baseEntity - * entity changed - * @param changeSetValues - * details of properties changed and old value and new value of - * the changed properties - */ - public AbstractPropertyChangeEvent(final E baseEntity, final Map changeSetValues) { - super(baseEntity); - this.changeSet = changeSetValues; - } - - /** - * @return the changeSet - */ - public Map getChangeSet() { - return changeSet; - } - - /** - * Carries old value and new value of a property . - */ - public static class PropertyChange { - - private final Object oldValue; - private final Object newValue; - - /** - * Initialize old value and new changes value of property. - * - * @param oldValue - * old value before change - * @param newValue - * new value after change - */ - public PropertyChange(final Object oldValue, final Object newValue) { - super(); - this.oldValue = oldValue; - this.newValue = newValue; - } - - /** - * @return the oldValue - */ - public Object getOldValue() { - return oldValue; - } - - /** - * @return the newValue - */ - public Object getNewValue() { - return newValue; - } - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionCreatedEvent.java deleted file mode 100644 index 73188b85e..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionCreatedEvent.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.repository.model.Action; - -/** - * Defines the {@link AbstractBaseEntityEvent} of creating a new {@link Action}. - */ -public class ActionCreatedEvent extends AbstractBaseEntityEvent { - private static final long serialVersionUID = 181780358321768629L; - - /** - * @param action - */ - public ActionCreatedEvent(final Action action) { - super(action); - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java deleted file mode 100644 index 5197bd9a0..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/ActionPropertyChangeEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import java.util.Map; - -import org.eclipse.hawkbit.repository.model.Action; - -/** - * Defines the {@link AbstractPropertyChangeEvent} of {@link Action}. - */ -public class ActionPropertyChangeEvent extends AbstractPropertyChangeEvent { - private static final long serialVersionUID = 181780358321768629L; - - /** - * @param action - * @param changeSetValues - */ - public ActionPropertyChangeEvent(final Action action, final Map changeSetValues) { - super(action, changeSetValues); - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/CancelTargetAssignmentEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/CancelTargetAssignmentEvent.java deleted file mode 100644 index 66a953f56..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/CancelTargetAssignmentEvent.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.Event; -import org.eclipse.hawkbit.repository.model.Target; - -/** - * Event that gets sent when the assignment of a distribution set to a target - * gets canceled. - * - * - * - */ -public class CancelTargetAssignmentEvent implements Event { - - private final Target target; - private final Long actionId; - - /** - * Creates a new {@link CancelTargetAssignmentEvent}. - * - * @param target - * entity - * @param actionId - * the action id of the assignment - */ - public CancelTargetAssignmentEvent(final Target target, final Long actionId) { - this.target = target; - this.actionId = actionId; - } - - /** - * @return the action id of the assignment - */ - public Long getActionId() { - return actionId; - } - - /** - * @return target where the action got canceled - */ - public Target getTarget() { - return target; - } - - @Override - public long getRevision() { - return -1; - } - - @Override - public String getTenant() { - return target.getTenant(); - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionCreatedEvent.java deleted file mode 100644 index 20515521d..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionCreatedEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.repository.model.DistributionSet; - -/** - * Defines the {@link AbstractBaseEntityEvent} of creating a new {@link DistributionSet}. - * - */ -public class DistributionCreatedEvent extends AbstractBaseEntityEvent { - - private static final long serialVersionUID = 1L; - - /** - * @param distributionSet - * the distributionSet which has been created - */ - public DistributionCreatedEvent(final DistributionSet distributionSet) { - super(distributionSet); - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionDeletedEvent.java deleted file mode 100644 index 47c8c8435..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionDeletedEvent.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent; -import org.eclipse.hawkbit.repository.model.DistributionSet; - -/** - * Defines the {@link AbstractDistributedEvent} for deletion of - * {@link DistributionSet}. - */ -public class DistributionDeletedEvent extends AbstractDistributedEvent { - private static final long serialVersionUID = -3308850381757843098L; - private final Long distributionId; - - /** - * @param tenant - * the tenant for this event - * @param distributionId - * the ID of the distribution set which has been deleted - */ - public DistributionDeletedEvent(final String tenant, final Long distributionId) { - super(-1, tenant); - this.distributionId = distributionId; - } - - public Long getDistributionSetId() { - return distributionId; - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagAssigmentResultEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagAssigmentResultEvent.java deleted file mode 100644 index e0844a167..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagAssigmentResultEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.Event; -import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; - -/** - * A event for assignment target tag. - */ -public class DistributionSetTagAssigmentResultEvent implements Event { - - private final DistributionSetTagAssignmentResult assigmentResult; - private final String tenant; - - /** - * Constructor. - * - * @param assigmentResult - * the assignment result - * @param tenant - * current - */ - public DistributionSetTagAssigmentResultEvent(final DistributionSetTagAssignmentResult assigmentResult, - final String tenant) { - this.assigmentResult = assigmentResult; - this.tenant = tenant; - } - - public DistributionSetTagAssignmentResult getAssigmentResult() { - return assigmentResult; - } - - @Override - public long getRevision() { - return -1; - } - - @Override - public String getTenant() { - return tenant; - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagDeletedEvent.java deleted file mode 100644 index f2f134a3a..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetTagDeletedEvent.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.repository.model.DistributionSetTag; - -/** - * Defines the {@link AbstractBaseEntityEvent} of update a - * {@link DistributionSetTag}. - * - */ -public class DistributionSetTagDeletedEvent extends AbstractBaseEntityEvent { - - private static final long serialVersionUID = 1L; - - /** - * Constructor. - * - * @param tag - * the tag which is deleted - */ - public DistributionSetTagDeletedEvent(final DistributionSetTag tag) { - super(tag); - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetUpdateEvent.java deleted file mode 100644 index d060e2ee5..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DistributionSetUpdateEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.repository.model.DistributionSet; - -/** - * Defines the {@link AbstractBaseEntityEvent} for update a {@link DistributionSet}. - * - */ -public class DistributionSetUpdateEvent extends AbstractBaseEntityEvent { - - private static final long serialVersionUID = 1L; - - - /** - * Constructor - * @param ds Distribution Set - */ - public DistributionSetUpdateEvent(final DistributionSet ds) { - super(ds); - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DownloadProgressEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DownloadProgressEvent.java deleted file mode 100644 index 6d145e0ae..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/DownloadProgressEvent.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent; - -/** - * Event that contains an updated download progress for a given ActionStatus - * that was written for a download request. - * - */ -public class DownloadProgressEvent extends AbstractDistributedEvent { - - private static final long serialVersionUID = 1L; - - private final Long statusId; - private final long requestedBytes; - private final long shippedBytesSinceLast; - private final long shippedBytesOverall; - - /** - * Constructor. - * - * @param tenant - * the tenant for this event - * @param statusId - * of ActionStatus that was written for the download request - * @param requestedBytes - * bytes requested - * @param shippedBytesSinceLast - * bytes since last event - * @param shippedBytesOverall - * on the download request - */ - public DownloadProgressEvent(final String tenant, final Long statusId, final Long requestedBytes, - final Long shippedBytesSinceLast, final Long shippedBytesOverall) { - // the revision of the DownloadProgressEvent is just equal the - // shippedBytesOverall as this is a growing number. - super(shippedBytesOverall, tenant); - this.statusId = statusId; - this.requestedBytes = requestedBytes; - this.shippedBytesSinceLast = shippedBytesSinceLast; - this.shippedBytesOverall = shippedBytesOverall; - } - - public Long getStatusId() { - return statusId; - } - - public long getRequestedBytes() { - return requestedBytes; - } - - public long getShippedBytesSinceLast() { - return shippedBytesSinceLast; - } - - public long getShippedBytesOverall() { - return shippedBytesOverall; - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutChangeEvent.java deleted file mode 100644 index 05960938f..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutChangeEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.DefaultEvent; - -/** - * Event declaration for the UI to notify the UI that a rollout has been - * changed. - * - * @author Michael Hirsch - * - */ -public class RolloutChangeEvent extends DefaultEvent { - - private final Long rolloutId; - - /** - * @param revision - * the revision of the event - * @param tenant - * the tenant of the event - * @param rolloutId - * the ID of the rollout which has been changed - */ - public RolloutChangeEvent(final long revision, final String tenant, final Long rolloutId) { - super(revision, tenant); - this.rolloutId = rolloutId; - } - - public Long getRolloutId() { - return rolloutId; - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupChangeEvent.java deleted file mode 100644 index 686625d03..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupChangeEvent.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.DefaultEvent; - -/** - * Event declaration for the UI to notify the UI that a rollout has been - * changed. - * - * @author Michael Hirsch - * - */ -public class RolloutGroupChangeEvent extends DefaultEvent { - - private final Long rolloutId; - private final Long rolloutGroupId; - - /** - * @param revision - * the revision of the event - * @param tenant - * the tenant of the event - * @param rolloutId - * the ID of the rollout which has been changed - * @param rolloutGroupId - * the ID of the rollout group which has been changed - */ - public RolloutGroupChangeEvent(final long revision, final String tenant, final Long rolloutId, - final Long rolloutGroupId) { - super(revision, tenant); - this.rolloutId = rolloutId; - this.rolloutGroupId = rolloutGroupId; - } - - public Long getRolloutId() { - return rolloutId; - } - - public Long getRolloutGroupId() { - return rolloutGroupId; - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupCreatedEvent.java deleted file mode 100644 index 47fb6b39e..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupCreatedEvent.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent; - -/** - * Event definition which is been published in case a rollout group has been - * created for a specific rollout. - * - * @author Michael Hirsch - * - */ -public class RolloutGroupCreatedEvent extends AbstractDistributedEvent { - - private static final long serialVersionUID = 1L; - private final Long rolloutId; - private final Long rolloutGroupId; - private final int totalRolloutGroup; - private final int createdRolloutGroup; - - /** - * Creating a new rollout group created event for a specific rollout. - * - * @param tenant - * the tenant of this event - * @param revision - * the revision of the event - * @param rolloutId - * the ID of the rollout the group has been created - * @param rolloutGroupId - * identifier of this group - * @param totalRolloutGroup - * the total number of rollout groups for this rollout - * @param createdRolloutGroup - * the number of already created groups of the rollout - */ - public RolloutGroupCreatedEvent(final String tenant, final long revision, final Long rolloutId, - final Long rolloutGroupId, final int totalRolloutGroup, final int createdRolloutGroup) { - super(revision, tenant); - this.rolloutId = rolloutId; - this.rolloutGroupId = rolloutGroupId; - this.totalRolloutGroup = totalRolloutGroup; - this.createdRolloutGroup = createdRolloutGroup; - - } - - public Long getRolloutId() { - return rolloutId; - } - - public int getTotalRolloutGroup() { - return totalRolloutGroup; - } - - public int getCreatedRolloutGroup() { - return createdRolloutGroup; - } - - public Long getRolloutGroupId() { - return rolloutGroupId; - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java deleted file mode 100644 index b0b31b79a..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutGroupPropertyChangeEvent.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import java.util.Map; - -import org.eclipse.hawkbit.repository.model.RolloutGroup; - -/** - * Defines the {@link AbstractPropertyChangeEvent} of {@link RolloutGroup}. - */ -public class RolloutGroupPropertyChangeEvent extends AbstractPropertyChangeEvent { - - private static final long serialVersionUID = 4026477044419472686L; - - /** - * - * @param rolloutGroup - * @param changeSetValues - */ - public RolloutGroupPropertyChangeEvent(final RolloutGroup rolloutGroup, - final Map changeSetValues) { - super(rolloutGroup, changeSetValues); - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java deleted file mode 100644 index 9bb975c3a..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/RolloutPropertyChangeEvent.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import java.util.Map; - -import org.eclipse.hawkbit.repository.model.Rollout; - -/** - * Defines the {@link AbstractPropertyChangeEvent} of {@link Rollout}. - */ -public class RolloutPropertyChangeEvent extends AbstractPropertyChangeEvent { - private static final long serialVersionUID = 1056221355466373514L; - - /** - * - * @param rollout - * @param changeSetValues - */ - public RolloutPropertyChangeEvent(final Rollout rollout, final Map changeSetValues) { - super(rollout, changeSetValues); - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetAssignDistributionSetEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetAssignDistributionSetEvent.java deleted file mode 100644 index e87d49b57..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetAssignDistributionSetEvent.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import java.util.Collection; - -import org.eclipse.hawkbit.eventbus.event.DefaultEvent; -import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.repository.model.Target; - -/** - * Event that gets sent when a distribution set gets assigned to a target. - * - */ -public class TargetAssignDistributionSetEvent extends DefaultEvent { - - private final Collection softwareModules; - private final Target target; - private final Long actionId; - - /** - * Creates a new {@link TargetAssignDistributionSetEvent}. - * - * @param revision - * the revision of the event - * @param tenant - * the tenant of the event - * @param target - * the assigned {@link Target} - * @param actionId - * the action id of the assignment - * @param softwareModules - * the software modules which have been assigned to the target - */ - public TargetAssignDistributionSetEvent(final long revision, final String tenant, final Target target, - final Long actionId, final Collection softwareModules) { - super(revision, tenant); - this.target = target; - this.actionId = actionId; - this.softwareModules = softwareModules; - } - - /** - * @return the action id of the assignment - */ - public Long getActionId() { - return actionId; - } - - /** - * @return the {@link Target} which has been assigned to the distribution - * set - */ - public Target getTarget() { - return target; - } - - /** - * @return the software modules which have been assigned to the target - */ - public Collection getSoftwareModules() { - return softwareModules; - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetCreatedEvent.java deleted file mode 100644 index 446f21856..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetCreatedEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.repository.model.Target; - -/** - * Defines the {@link AbstractBaseEntityEvent} of creating a new {@link Target}. - * - * - */ -public class TargetCreatedEvent extends AbstractBaseEntityEvent { - - private static final long serialVersionUID = 1L; - - /** - * @param target - * the target which has been created - */ - public TargetCreatedEvent(final Target target) { - super(target); - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetDeletedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetDeletedEvent.java deleted file mode 100644 index 637a0dcc5..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetDeletedEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.AbstractDistributedEvent; -import org.eclipse.hawkbit.repository.model.Target; - -/** - * - * Defines the {@link AbstractBaseEntityEvent} of deleting a {@link Target}. - */ -public class TargetDeletedEvent extends AbstractDistributedEvent { - - private static final long serialVersionUID = 1L; - private final long targetId; - - /** - * @param tenant - * the tenant for this event - * @param targetId - * the ID of the target which has been deleted - */ - public TargetDeletedEvent(final String tenant, final long targetId) { - super(-1, tenant); - this.targetId = targetId; - } - - /** - * @return the targetId - */ - public long getTargetId() { - return targetId; - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetInfoUpdateEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetInfoUpdateEvent.java deleted file mode 100644 index 1e7e29719..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetInfoUpdateEvent.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.EntityEvent; -import org.eclipse.hawkbit.repository.model.TargetInfo; - -/** - * Event for update the targets info. - */ -public class TargetInfoUpdateEvent implements EntityEvent { - - private final long revision; - private final TargetInfo targetInfo; - private final String tenant; - private String originNodeId; - private String nodeId; - - /** - * Constructor. - * - * @param targetInfo - * the target info entity - */ - public TargetInfoUpdateEvent(final TargetInfo targetInfo) { - this.targetInfo = targetInfo; - this.tenant = targetInfo.getTarget().getTenant(); - this.revision = -1; - } - - @Override - public void setOriginNodeId(final String originNodeId) { - this.originNodeId = originNodeId; - } - - @Override - public void setNodeId(final String nodeId) { - this.nodeId = nodeId; - - } - - @Override - public String getOriginNodeId() { - return this.originNodeId; - } - - @Override - public String getNodeId() { - return this.nodeId; - } - - @Override - public long getRevision() { - return revision; - } - - @Override - public E getEntity(final Class entityClass) { - return entityClass.cast(targetInfo); - } - - @Override - public TargetInfo getEntity() { - return targetInfo; - } - - @Override - public String getTenant() { - return tenant; - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagAssigmentResultEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagAssigmentResultEvent.java deleted file mode 100644 index 4fe99266e..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagAssigmentResultEvent.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.eventbus.event.Event; -import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; - -/** - * A event for assignment target tag. - */ -public class TargetTagAssigmentResultEvent implements Event { - - private final TargetTagAssignmentResult assigmentResult; - private final String tenant; - - /** - * Constructor. - * - * @param assigmentResult - * the assignment result- - * @param tenant - * current - */ - public TargetTagAssigmentResultEvent(final TargetTagAssignmentResult assigmentResult, final String tenant) { - this.tenant = tenant; - this.assigmentResult = assigmentResult; - } - - public TargetTagAssignmentResult getAssigmentResult() { - return assigmentResult; - } - - @Override - public long getRevision() { - return -1; - } - - @Override - public String getTenant() { - return tenant; - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagCreatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagCreatedEvent.java deleted file mode 100644 index 9b5b67f47..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetTagCreatedEvent.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.repository.model.TargetTag; - -/** - * Defines the {@link AbstractBaseEntityEvent} for creation of a new - * {@link TargetTag}. - * - */ -public class TargetTagCreatedEvent extends AbstractBaseEntityEvent { - - private static final long serialVersionUID = 1L; - - /** - * Constructor. - * - * @param tag - * the tag which has been created - */ - public TargetTagCreatedEvent(final TargetTag tag) { - super(tag); - } -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetUpdatedEvent.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetUpdatedEvent.java deleted file mode 100644 index 8ae5718e9..000000000 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/eventbus/event/TargetUpdatedEvent.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.eventbus.event; - -import org.eclipse.hawkbit.repository.model.Target; - -/** - * Defines the {@link AbstractBaseEntityEvent} of updating a {@link Target}. - * - */ -public class TargetUpdatedEvent extends AbstractBaseEntityEvent { - - private static final long serialVersionUID = 5665118668865832477L; - - /** - * Constructor - * - * @param baseEntity - * Target entity - */ - public TargetUpdatedEvent(final Target baseEntity) { - super(baseEntity); - } - -} diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java index 2b5daed2e..10550e37d 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java @@ -43,12 +43,6 @@ public interface ActionStatus extends TenantAwareBaseEntity { */ void addMessage(String message); - /** - * @return current {@link Status#DOWNLOAD} progress if known by the update - * server. - */ - short getDownloadProgressPercent(); - /** * @return immutable list of message entries that in the * {@link ActionStatus}. diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java similarity index 93% rename from hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java rename to hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java index 171808cb0..c7bff07a3 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/DistributionSetAssignmentResult.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetAssignmentResult.java @@ -6,13 +6,12 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository; +package org.eclipse.hawkbit.repository.model; import java.util.Collections; import java.util.List; -import org.eclipse.hawkbit.repository.model.AssignmentResult; -import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.TargetManagement; import org.springframework.util.CollectionUtils; /** diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java index 5b6bd5bfa..e26843ac1 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetTagAssignmentResult.java @@ -10,16 +10,13 @@ package org.eclipse.hawkbit.repository.model; import java.util.List; -import org.eclipse.hawkbit.eventbus.event.Event; - /** * Result object for {@link DistributionSetTag} assignments. * */ -public class DistributionSetTagAssignmentResult extends AssignmentResult implements Event { +public class DistributionSetTagAssignmentResult extends AssignmentResult { private final DistributionSetTag distributionSetTag; - private final String tenant; /** * Constructor. @@ -39,24 +36,13 @@ public class DistributionSetTagAssignmentResult extends AssignmentResult assignedDs, final List unassignedDs, - final DistributionSetTag distributionSetTag, final String tenant) { + final DistributionSetTag distributionSetTag) { super(assigned, alreadyAssigned, unassigned, assignedDs, unassignedDs); this.distributionSetTag = distributionSetTag; - this.tenant = tenant; } public DistributionSetTag getDistributionSetTag() { return distributionSetTag; } - @Override - public long getRevision() { - return 0; - } - - @Override - public String getTenant() { - return tenant; - } - } diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java index a204ef506..5f27357ce 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java @@ -8,14 +8,17 @@ */ package org.eclipse.hawkbit.repository.model; +import java.io.Serializable; + /** * represents a tenant configuration value including some meta data * * @param * type of the configuration value */ -public final class TenantConfigurationValue { +public final class TenantConfigurationValue implements Serializable { + private static final long serialVersionUID = 1L; private T value; private Long lastModifiedAt; private String lastModifiedBy; @@ -87,7 +90,7 @@ public final class TenantConfigurationValue { * the key type * @return the tenant configuration value builder */ - public static TenantConfigurationValueBuilder builder() { + public static TenantConfigurationValueBuilder builder() { return new TenantConfigurationValueBuilder<>(); } @@ -98,7 +101,7 @@ public final class TenantConfigurationValue { * @param * type of the configuration value */ - public static class TenantConfigurationValueBuilder { + public static class TenantConfigurationValueBuilder { private final TenantConfigurationValue configuration = new TenantConfigurationValue<>(); diff --git a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/InnerOuterDataReportSeries.java b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/InnerOuterDataReportSeries.java index 357f9a554..e8b2fb50a 100644 --- a/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/InnerOuterDataReportSeries.java +++ b/hawkbit-repository/hawkbit-repository-api/src/main/java/org/eclipse/hawkbit/repository/report/model/InnerOuterDataReportSeries.java @@ -19,8 +19,9 @@ import java.io.Serializable; * @param * The type parameter for the report series data */ -public class InnerOuterDataReportSeries { +public class InnerOuterDataReportSeries implements Serializable { + private static final long serialVersionUID = 1L; private final DataReportSeries innerSeries; private final DataReportSeries outerSeries; diff --git a/hawkbit-repository/hawkbit-repository-core/pom.xml b/hawkbit-repository/hawkbit-repository-core/pom.xml index 77e20cf3c..3710c8861 100644 --- a/hawkbit-repository/hawkbit-repository-core/pom.xml +++ b/hawkbit-repository/hawkbit-repository-core/pom.xml @@ -24,6 +24,16 @@ hawkbit-repository-api ${project.version} + + io.protostuff + protostuff-core + true + + + io.protostuff + protostuff-runtime + true + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/event/BusProtoStuffMessageConverter.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/event/BusProtoStuffMessageConverter.java new file mode 100644 index 000000000..a72b73f75 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/event/BusProtoStuffMessageConverter.java @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.event; + +import org.apache.commons.lang3.ClassUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.integration.support.MutableMessageHeaders; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHeaders; +import org.springframework.messaging.converter.AbstractMessageConverter; +import org.springframework.messaging.converter.MessageConversionException; +import org.springframework.messaging.support.MessageHeaderAccessor; +import org.springframework.util.MimeType; + +import io.protostuff.LinkedBuffer; +import io.protostuff.ProtobufIOUtil; +import io.protostuff.ProtostuffIOUtil; +import io.protostuff.Schema; +import io.protostuff.runtime.RuntimeSchema; + +/** + * A customize message converter for the spring cloud events. The converter is + * registered for the application/binary+protostuff type. + * + */ +public class BusProtoStuffMessageConverter extends AbstractMessageConverter { + + public static final MimeType APPLICATION_BINARY_PROTOSTUFF = new MimeType("application", "binary+protostuff"); + private static final Logger LOG = LoggerFactory.getLogger(BusProtoStuffMessageConverter.class); + private static final String DEFAULT_CLASS_FIELD_NAME = "__Class__"; + + /** + * Constructor. + */ + public BusProtoStuffMessageConverter() { + super(APPLICATION_BINARY_PROTOSTUFF); + } + + @Override + protected boolean supports(final Class aClass) { + return RemoteApplicationEvent.class.isAssignableFrom(aClass); + } + + @Override + public Object convertFromInternal(final Message message, final Class targetClass, + final Object conversionHint) { + final Object payload = message.getPayload(); + + try { + final Class deserializeClass = ClassUtils + .getClass(message.getHeaders().get(DEFAULT_CLASS_FIELD_NAME).toString()); + if (payload instanceof byte[]) { + @SuppressWarnings("unchecked") + final Schema schema = (Schema) RuntimeSchema.getSchema(deserializeClass); + final Object deserializeEvent = schema.newMessage(); + ProtobufIOUtil.mergeFrom((byte[]) message.getPayload(), deserializeEvent, schema); + return deserializeEvent; + } + } catch (final ClassNotFoundException e) { + LOG.error("Protostuff cannot find derserialize class", e); + throw new MessageConversionException(message, "Failed to read payload", e); + } + + return null; + } + + @Override + protected Object convertToInternal(final Object payload, final MessageHeaders headers, + final Object conversionHint) { + checkIfHeaderMutable(headers); + final Class serializeClass = payload.getClass(); + @SuppressWarnings("unchecked") + final Schema schema = (Schema) RuntimeSchema.getSchema(serializeClass); + final LinkedBuffer buffer = LinkedBuffer.allocate(); + final byte[] serializeByte; + try { + serializeByte = ProtostuffIOUtil.toByteArray(payload, schema, buffer); + } finally { + buffer.clear(); + } + + headers.put(DEFAULT_CLASS_FIELD_NAME, serializeClass.getName()); + return serializeByte; + } + + private static void checkIfHeaderMutable(final MessageHeaders headers) { + if (isAccessorMutable(headers) || headers instanceof MutableMessageHeaders) { + return; + } + LOG.error("Protostuff cannot set serializae class because message header is not mutable"); + throw new MessageConversionException( + "Cannot set the serialize class to message header. Need Mutable message header"); + } + + private static boolean isAccessorMutable(final MessageHeaders headers) { + final MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(headers, MessageHeaderAccessor.class); + return accessor != null && accessor.isMutable(); + } + +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/TimestampCalculator.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/TimestampCalculator.java similarity index 94% rename from hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/TimestampCalculator.java rename to hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/TimestampCalculator.java index 63813cf41..e6676ef87 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/TimestampCalculator.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/TimestampCalculator.java @@ -6,13 +6,13 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa; +package org.eclipse.hawkbit.repository; import java.time.Duration; import java.time.Instant; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder; +import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java deleted file mode 100644 index 3829d639b..000000000 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EventBusHolder.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.model.helper; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.google.common.eventbus.EventBus; - -/** - * A singleton bean which holds the {@link EventBus} to have to the cache - * manager in beans not instantiated by spring e.g. JPA entities or - * CacheFieldEntityListener which cannot be autowired. - * - */ -public final class EventBusHolder { - - private static final EventBusHolder SINGLETON = new EventBusHolder(); - - @Autowired - private EventBus eventBus; - - private EventBusHolder() { - - } - - /** - * @return the cache manager holder singleton instance - */ - public static EventBusHolder getInstance() { - return SINGLETON; - } - - /** - * @return the eventBus - */ - public EventBus getEventBus() { - return eventBus; - } - - /** - * @param eventBus - * the eventBus to set - */ - public void setEventBus(final EventBus eventBus) { - this.eventBus = eventBus; - } - -} diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventPublisherHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventPublisherHolder.java new file mode 100644 index 000000000..5a5037ac6 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/EventPublisherHolder.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.model.helper; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEventPublisher; + +/** + * A singleton bean which holds the event publisher to have to the cache manager + * in beans not instantiated by spring e.g. JPA entities or + * CacheFieldEntityListener which cannot be autowired. + * + */ +public final class EventPublisherHolder { + + private static final EventPublisherHolder SINGLETON = new EventPublisherHolder(); + + @Autowired + private ApplicationEventPublisher eventPublisher; + + @Autowired + private ApplicationContext applicationContext; + + private EventPublisherHolder() { + + } + + /** + * @return the cache manager holder singleton instance + */ + public static EventPublisherHolder getInstance() { + return SINGLETON; + } + + /** + * @return the eventPublisher + */ + public ApplicationEventPublisher getEventPublisher() { + return eventPublisher; + } + + public String getApplicationId() { + return applicationContext.getId(); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java similarity index 96% rename from hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java rename to hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java index 1b1fbb091..d1327c690 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/SystemManagementHolder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/SystemManagementHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.model.helper; +package org.eclipse.hawkbit.repository.model.helper; import org.eclipse.hawkbit.repository.SystemManagement; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantConfigurationManagementHolder.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java similarity index 95% rename from hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantConfigurationManagementHolder.java rename to hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java index 239274c45..700511db6 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/TenantConfigurationManagementHolder.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/model/helper/TenantConfigurationManagementHolder.java @@ -6,7 +6,7 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.model.helper; +package org.eclipse.hawkbit.repository.model.helper; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.springframework.beans.factory.annotation.Autowired; diff --git a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolver.java b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/rsql/VirtualPropertyResolver.java similarity index 85% rename from hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolver.java rename to hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/rsql/VirtualPropertyResolver.java index 14f23b5be..764db5937 100644 --- a/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolver.java +++ b/hawkbit-repository/hawkbit-repository-core/src/main/java/org/eclipse/hawkbit/repository/rsql/VirtualPropertyResolver.java @@ -6,19 +6,14 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.rsql; +package org.eclipse.hawkbit.repository.rsql; -import java.time.Duration; import java.time.Instant; import org.apache.commons.lang3.text.StrLookup; import org.apache.commons.lang3.text.StrSubstitutor; -import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.jpa.TimestampCalculator; -import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder; +import org.eclipse.hawkbit.repository.TimestampCalculator; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; -import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; -import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; /** * Adds macro capabilities to RSQL expressions that are used to filter for diff --git a/hawkbit-repository/hawkbit-repository-jpa/pom.xml b/hawkbit-repository/hawkbit-repository-jpa/pom.xml index 44f74e97c..42fc9a62f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/pom.xml +++ b/hawkbit-repository/hawkbit-repository-jpa/pom.xml @@ -56,14 +56,6 @@ com.google.guava guava - - org.springframework.boot - spring-boot - - - org.springframework.boot - spring-boot-starter-logging - org.springframework.boot spring-boot-starter-data-jpa @@ -101,16 +93,6 @@ ${project.version} test - - com.fasterxml.jackson.core - jackson-core - test - - - com.fasterxml.jackson.core - jackson-databind - test - com.h2database h2 @@ -188,17 +170,7 @@ - - org.apache.maven.plugins - maven-jar-plugin - - - - test-jar - - - - + diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java index 5a7f98298..2212fabfa 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/RepositoryApplicationConfiguration.java @@ -10,6 +10,8 @@ package org.eclipse.hawkbit; import java.util.Map; +import javax.persistence.EntityManager; + import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.DeploymentManagement; @@ -26,6 +28,8 @@ import org.eclipse.hawkbit.repository.TargetFilterQueryManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantStatsManagement; +import org.eclipse.hawkbit.repository.event.remote.EventEntityManager; +import org.eclipse.hawkbit.repository.event.remote.EventEntityManagerHolder; import org.eclipse.hawkbit.repository.jpa.JpaArtifactManagement; import org.eclipse.hawkbit.repository.jpa.JpaControllerManagement; import org.eclipse.hawkbit.repository.jpa.JpaDeploymentManagement; @@ -45,20 +49,19 @@ import org.eclipse.hawkbit.repository.jpa.aspects.ExceptionMappingAspectHandler; import org.eclipse.hawkbit.repository.jpa.autoassign.AutoAssignChecker; import org.eclipse.hawkbit.repository.jpa.autoassign.AutoAssignScheduler; import org.eclipse.hawkbit.repository.jpa.configuration.MultiTenantJpaTransactionManager; +import org.eclipse.hawkbit.repository.jpa.event.JpaEventEntityManager; import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder; -import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; -import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder; -import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.repository.jpa.rsql.RsqlParserValidationOracle; +import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder; import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -77,7 +80,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.validation.beanvalidation.MethodValidationPostProcessor; import com.google.common.collect.Maps; -import com.google.common.eventbus.EventBus; /** * General configuration for hawkBit's Repository. @@ -93,8 +95,6 @@ import com.google.common.eventbus.EventBus; @EnableScheduling @EntityScan("org.eclipse.hawkbit.repository.jpa.model") public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { - @Autowired - private EventBus eventBus; @Bean @ConditionalOnMissingBean @@ -163,14 +163,6 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { return EntityInterceptorHolder.getInstance(); } - /** - * @return the singleton instance of the {@link CacheManagerHolder} - */ - @Bean - public CacheManagerHolder cacheManagerHolder() { - return CacheManagerHolder.getInstance(); - } - /** * * @return the singleton instance of the @@ -273,9 +265,7 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { @Bean @ConditionalOnMissingBean public TenantStatsManagement tenantStatsManagement() { - final TenantStatsManagement mgmt = new JpaTenantStatsManagement(); - eventBus.register(mgmt); - return mgmt; + return new JpaTenantStatsManagement(); } /** @@ -400,6 +390,32 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { return new JpaEntityFactory(); } + /** + * {@link EventEntityManagerHolder} bean. + * + * @return a new {@link EventEntityManagerHolder} + */ + @Bean + @ConditionalOnMissingBean + public EventEntityManagerHolder eventEntityManagerHolder() { + return EventEntityManagerHolder.getInstance(); + } + + /** + * {@link EventEntityManager} bean. + * + * @param aware + * the tenant aware + * @param entityManager + * the entitymanager + * @return a new {@link EventEntityManager} + */ + @Bean + @ConditionalOnMissingBean + public EventEntityManager eventEntityManager(final TenantAware aware, final EntityManager entityManager) { + return new JpaEventEntityManager(aware, entityManager); + } + /** * {@link AutoAssignChecker} bean. * @@ -415,9 +431,9 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { */ @Bean @ConditionalOnMissingBean - public AutoAssignChecker autoAssignChecker(TargetFilterQueryManagement targetFilterQueryManagement, - TargetManagement targetManagement, DeploymentManagement deploymentManagement, - PlatformTransactionManager transactionManager) { + public AutoAssignChecker autoAssignChecker(final TargetFilterQueryManagement targetFilterQueryManagement, + final TargetManagement targetManagement, final DeploymentManagement deploymentManagement, + final PlatformTransactionManager transactionManager) { return new AutoAssignChecker(targetFilterQueryManagement, targetManagement, deploymentManagement, transactionManager); } @@ -437,8 +453,10 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration { */ @Bean @ConditionalOnMissingBean - public AutoAssignScheduler autoAssignScheduler(TenantAware tenantAware, SystemManagement systemManagement, - SystemSecurityContext systemSecurityContext, AutoAssignChecker autoAssignChecker) { + public AutoAssignScheduler autoAssignScheduler(final TenantAware tenantAware, + final SystemManagement systemManagement, final SystemSecurityContext systemSecurityContext, + final AutoAssignChecker autoAssignChecker) { return new AutoAssignScheduler(tenantAware, systemManagement, systemSecurityContext, autoAssignChecker); } + } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java index 05424467c..fa9e44931 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaControllerManagement.java @@ -9,7 +9,6 @@ package org.eclipse.hawkbit.repository.jpa; import java.net.URI; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -24,10 +23,10 @@ import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.RepositoryProperties; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.event.remote.DownloadProgressEvent; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ToManyAttributeEntriesException; import org.eclipse.hawkbit.repository.exception.TooManyStatusEntriesException; -import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus_; @@ -41,7 +40,6 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.Artifact; -import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; @@ -49,10 +47,13 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.security.HawkbitSecurityProperties; import org.eclipse.hawkbit.security.SystemSecurityContext; +import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.jpa.domain.Specification; @@ -86,9 +87,6 @@ public class JpaControllerManagement implements ControllerManagement { @Autowired private TargetInfoRepository targetInfoRepository; - @Autowired - private SoftwareModuleRepository softwareModuleRepository; - @Autowired private ActionStatusRepository actionStatusRepository; @@ -105,11 +103,17 @@ public class JpaControllerManagement implements ControllerManagement { private TenantConfigurationManagement tenantConfigurationManagement; @Autowired - private CacheWriteNotify cacheWriteNotify; + private TenantAware tenantAware; @Autowired private SystemSecurityContext systemSecurityContext; + @Autowired + private ApplicationEventPublisher eventPublisher; + + @Autowired + private ApplicationContext applicationContext; + @Override public String getPollingTime() { final TenantConfigurationKey configurationKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; @@ -178,12 +182,6 @@ public class JpaControllerManagement implements ControllerManagement { return actionRepository.findFirstByTargetAndActive(new Sort(Direction.ASC, "id"), (JpaTarget) target, true); } - @Override - public List findSoftwareModulesByDistributionSet(final DistributionSet distributionSet) { - return Collections - .unmodifiableList(softwareModuleRepository.findByAssignedTo((JpaDistributionSet) distributionSet)); - } - @Override public Action findActionWithDetails(final Long actionId) { return actionRepository.findById(actionId); @@ -480,7 +478,8 @@ public class JpaControllerManagement implements ControllerManagement { @Override public void downloadProgress(final Long statusId, final Long requestedBytes, final Long shippedBytesSinceLast, final Long shippedBytesOverall) { - cacheWriteNotify.downloadProgress(statusId, requestedBytes, shippedBytesSinceLast, shippedBytesOverall); + eventPublisher.publishEvent(new DownloadProgressEvent(tenantAware.getCurrentTenant(), shippedBytesSinceLast, + applicationContext.getId())); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java index 8c68347c0..5c45a2af3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDeploymentManagement.java @@ -30,12 +30,10 @@ import javax.validation.constraints.NotNull; import org.eclipse.hawkbit.repository.ActionFields; import org.eclipse.hawkbit.repository.DeploymentManagement; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.RepositoryConstants; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; @@ -51,11 +49,9 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; -import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaTarget; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; -import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.eclipse.hawkbit.repository.jpa.specifications.TargetSpecifications; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.ActionType; @@ -63,20 +59,22 @@ import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetWithActionType; -import org.eclipse.hawkbit.security.SystemSecurityContext; +import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.hibernate.validator.constraints.NotEmpty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.AuditorAware; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -90,7 +88,6 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import com.google.common.collect.Lists; -import com.google.common.eventbus.EventBus; /** * JPA implementation for {@link DeploymentManagement}. @@ -110,9 +107,6 @@ public class JpaDeploymentManagement implements DeploymentManagement { @Autowired private DistributionSetRepository distributoinSetRepository; - @Autowired - private SoftwareModuleRepository softwareModuleRepository; - @Autowired private TargetRepository targetRepository; @@ -129,14 +123,14 @@ public class JpaDeploymentManagement implements DeploymentManagement { private AuditorAware auditorProvider; @Autowired - private EventBus eventBus; + private ApplicationEventPublisher eventPublisher; + + @Autowired + private ApplicationContext applicationContext; @Autowired private AfterTransactionCommitExecutor afterCommit; - @Autowired - private SystemSecurityContext systemSecurityContext; - @Autowired private VirtualPropertyReplacer virtualPropertyReplacer; @@ -316,21 +310,18 @@ public class JpaDeploymentManagement implements DeploymentManagement { LOG.debug("assignDistribution({}) finished {}", set, result); - final List softwareModules = softwareModuleRepository.findByAssignedTo(set); - // detaching as it is not necessary to persist the set itself entityManager.detach(set); - sendDistributionSetAssignmentEvent(targets, targetIdsCancellList, targetIdsToActions, softwareModules); + sendDistributionSetAssignmentEvent(targets, targetIdsCancellList, targetIdsToActions); return result; } private void sendDistributionSetAssignmentEvent(final List targets, final Set targetIdsCancellList, - final Map targetIdsToActions, final List softwareModules) { + final Map targetIdsToActions) { targets.stream().filter(t -> !!!targetIdsCancellList.contains(t.getId())) - .forEach(t -> assignDistributionSetEvent(t, targetIdsToActions.get(t.getControllerId()).getId(), - softwareModules)); + .forEach(t -> assignDistributionSetEvent(targetIdsToActions.get(t.getControllerId()))); } private static JpaAction createTargetAction(final Map targetsWithActionMap, @@ -349,17 +340,11 @@ public class JpaDeploymentManagement implements DeploymentManagement { return actionForTarget; } - private void assignDistributionSetEvent(final JpaTarget target, final Long actionId, - final List modules) { - ((JpaTargetInfo) target.getTargetInfo()).setUpdateStatus(TargetUpdateStatus.PENDING); + private void assignDistributionSetEvent(final Action action) { + ((JpaTargetInfo) action.getTarget().getTargetInfo()).setUpdateStatus(TargetUpdateStatus.PENDING); - @SuppressWarnings({ "unchecked", "rawtypes" }) - final Collection softwareModules = (Collection) modules; - afterCommit.afterCommit(() -> { - eventBus.post(new TargetInfoUpdateEvent(target.getTargetInfo())); - eventBus.post(new TargetAssignDistributionSetEvent(target.getOptLockRevision(), target.getTenant(), target, - actionId, softwareModules)); - }); + afterCommit.afterCommit(() -> eventPublisher + .publishEvent(new TargetAssignDistributionSetEvent(action, applicationContext.getId()))); } /** @@ -431,7 +416,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { /** * Sends the {@link CancelTargetAssignmentEvent} for a specific target to - * the {@link EventBus}. + * the eventPublisher. * * @param target * the Target which has been assigned to a distribution set @@ -439,7 +424,8 @@ public class JpaDeploymentManagement implements DeploymentManagement { * the action id of the assignment */ private void cancelAssignDistributionSetEvent(final Target target, final Long actionId) { - afterCommit.afterCommit(() -> eventBus.post(new CancelTargetAssignmentEvent(target, actionId))); + afterCommit.afterCommit(() -> eventPublisher + .publishEvent(new CancelTargetAssignmentEvent(target, actionId, applicationContext.getId()))); } @Override @@ -534,11 +520,7 @@ public class JpaDeploymentManagement implements DeploymentManagement { // in case we canceled an action before for this target, then don't fire // assignment event if (!overrideObsoleteUpdateActions.contains(savedAction.getId())) { - final List softwareModules = softwareModuleRepository - .findByAssignedTo((JpaDistributionSet) savedAction.getDistributionSet()); - // send distribution set assignment event - - assignDistributionSetEvent((JpaTarget) savedAction.getTarget(), savedAction.getId(), softwareModules); + assignDistributionSetEvent(savedAction); } return savedAction; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java index 17f26b801..1cefd8f35 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaDistributionSetManagement.java @@ -27,8 +27,7 @@ import org.eclipse.hawkbit.repository.DistributionSetMetadataFields; import org.eclipse.hawkbit.repository.DistributionSetTypeFields; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagAssigmentResultEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityLockedException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; @@ -57,6 +56,8 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -68,7 +69,6 @@ import org.springframework.validation.annotation.Validated; import com.google.common.base.Strings; import com.google.common.collect.Lists; -import com.google.common.eventbus.EventBus; /** * JPA implementation of {@link DistributionSetManagement}. @@ -103,7 +103,10 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { private ActionRepository actionRepository; @Autowired - private EventBus eventBus; + private ApplicationEventPublisher eventPublisher; + + @Autowired + private ApplicationContext applicationContext; @Autowired private AfterTransactionCommitExecutor afterCommit; @@ -146,18 +149,13 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { } result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), 0, toBeChangedDSs.size(), Collections.emptyList(), - Collections.unmodifiableList(distributionSetRepository.save(toBeChangedDSs)), myTag, - tenantAware.getCurrentTenant()); + Collections.unmodifiableList(distributionSetRepository.save(toBeChangedDSs)), myTag); } else { result = new DistributionSetTagAssignmentResult(dsIds.size() - toBeChangedDSs.size(), toBeChangedDSs.size(), 0, Collections.unmodifiableList(distributionSetRepository.save(toBeChangedDSs)), - Collections.emptyList(), myTag, tenantAware.getCurrentTenant()); + Collections.emptyList(), myTag); } - final DistributionSetTagAssignmentResult resultAssignment = result; - afterCommit.afterCommit(() -> eventBus - .post(new DistributionSetTagAssigmentResultEvent(resultAssignment, tenantAware.getCurrentTenant()))); - // no reason to persist the tag entityManager.detach(myTag); return result; @@ -187,7 +185,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { // soft delete assigned if (!assigned.isEmpty()) { - Long[] dsIds = assigned.toArray(new Long[assigned.size()]); + final Long[] dsIds = assigned.toArray(new Long[assigned.size()]); distributionSetRepository.deleteDistributionSet(dsIds); targetFilterQueryRepository.unsetAutoAssignDistributionSet(dsIds); } @@ -203,8 +201,8 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { distributionSetRepository.deleteByIdIn(toHardDelete); } - Arrays.stream(distributionSetIDs) - .forEach(dsId -> eventBus.post(new DistributionDeletedEvent(tenantAware.getCurrentTenant(), dsId))); + Arrays.stream(distributionSetIDs).forEach(dsId -> eventPublisher.publishEvent( + new DistributionSetDeletedEvent(tenantAware.getCurrentTenant(), dsId, applicationContext.getId()))); } @Override @@ -710,16 +708,7 @@ public class JpaDistributionSetManagement implements DistributionSetManagement { allDs.forEach(ds -> ds.addTag(tag)); - final List save = Collections.unmodifiableList(distributionSetRepository.save(allDs)); - - afterCommit.afterCommit(() -> { - - final DistributionSetTagAssignmentResult result = new DistributionSetTagAssignmentResult(0, save.size(), 0, - save, Collections.emptyList(), tag, tenantAware.getCurrentTenant()); - eventBus.post(new DistributionSetTagAssigmentResultEvent(result, tenantAware.getCurrentTenant())); - }); - - return save; + return Collections.unmodifiableList(distributionSetRepository.save(allDs)); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java index c6795f600..303e9f718 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaReportManagement.java @@ -44,7 +44,6 @@ import org.eclipse.hawkbit.repository.report.model.SeriesTime; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.cache.annotation.Cacheable; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -81,7 +80,6 @@ public class JpaReportManagement implements ReportManagement { private TenantAware tenantAware; @Override - @Cacheable("targetStatus") public DataReportSeries targetStatus() { final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); @@ -106,7 +104,44 @@ public class JpaReportManagement implements ReportManagement { } @Override - @Cacheable("distributionUsageAssigned") + public DataReportSeries targetsLastPoll() { + + final LocalDateTime now = LocalDateTime.now(); + final LocalDateTime beforeHour = now.minusHours(1); + final LocalDateTime beforeDay = now.minusDays(1); + final LocalDateTime beforeWeek = now.minusWeeks(1); + final LocalDateTime beforeMonth = now.minusMonths(1); + final LocalDateTime beforeYear = now.minusYears(1); + + final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + final List> resultList = new ArrayList<>(); + + // hours + resultList.add(new DataReportSeriesItem(SeriesTime.HOUR, + entityManager.createQuery(createCountSelectTargetsLastPoll(cb, beforeHour, now)).getSingleResult())); + // days + resultList.add(new DataReportSeriesItem(SeriesTime.DAY, entityManager + .createQuery(createCountSelectTargetsLastPoll(cb, beforeDay, beforeHour)).getSingleResult())); + // weeks + resultList.add(new DataReportSeriesItem(SeriesTime.WEEK, entityManager + .createQuery(createCountSelectTargetsLastPoll(cb, beforeWeek, beforeDay)).getSingleResult())); + // months + resultList.add(new DataReportSeriesItem(SeriesTime.MONTH, entityManager + .createQuery(createCountSelectTargetsLastPoll(cb, beforeMonth, beforeWeek)).getSingleResult())); + // years + resultList.add(new DataReportSeriesItem(SeriesTime.YEAR, entityManager + .createQuery(createCountSelectTargetsLastPoll(cb, beforeYear, beforeMonth)).getSingleResult())); + // years + resultList.add(new DataReportSeriesItem(SeriesTime.MORE_THAN_YEAR, + entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, beforeYear)).getSingleResult())); + // never + resultList.add(new DataReportSeriesItem(SeriesTime.NEVER, + entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, null)).getSingleResult())); + + return new DataReportSeries<>("TargetLastPoll", resultList); + } + + @Override public List> distributionUsageAssigned(final int topXEntries) { // top X entries distribution usage @@ -132,7 +167,6 @@ public class JpaReportManagement implements ReportManagement { } @Override - @Cacheable("distributionUsageInstalled") public List> distributionUsageInstalled(final int topXEntries) { // top X entries distribution usage final CriteriaBuilder cbTopX = entityManager.getCriteriaBuilder(); @@ -157,7 +191,6 @@ public class JpaReportManagement implements ReportManagement { } @Override - @Cacheable("targetsCreatedOverPeriod") public DataReportSeries targetsCreatedOverPeriod(final DateType dateType, final LocalDateTime from, final LocalDateTime to) { final Query createNativeQuery = entityManager @@ -208,7 +241,6 @@ public class JpaReportManagement implements ReportManagement { } @Override - @Cacheable("feedbackReceivedOverTime") public DataReportSeries feedbackReceivedOverTime(final DateType dateType, final LocalDateTime from, final LocalDateTime to) { final Query createNativeQuery = entityManager @@ -223,47 +255,8 @@ public class JpaReportManagement implements ReportManagement { return new DataReportSeries<>("FeedbackRecieved", reportItems); } - @Override - @Cacheable("targetsLastPoll") - public DataReportSeries targetsLastPoll() { - - final LocalDateTime now = LocalDateTime.now(); - final LocalDateTime beforeHour = now.minusHours(1); - final LocalDateTime beforeDay = now.minusDays(1); - final LocalDateTime beforeWeek = now.minusWeeks(1); - final LocalDateTime beforeMonth = now.minusMonths(1); - final LocalDateTime beforeYear = now.minusYears(1); - - final CriteriaBuilder cb = entityManager.getCriteriaBuilder(); - final List> resultList = new ArrayList<>(); - - // hours - resultList.add(new DataReportSeriesItem(SeriesTime.HOUR, - entityManager.createQuery(createCountSelectTargetsLastPoll(cb, beforeHour, now)).getSingleResult())); - // days - resultList.add(new DataReportSeriesItem(SeriesTime.DAY, entityManager - .createQuery(createCountSelectTargetsLastPoll(cb, beforeDay, beforeHour)).getSingleResult())); - // weeks - resultList.add(new DataReportSeriesItem(SeriesTime.WEEK, entityManager - .createQuery(createCountSelectTargetsLastPoll(cb, beforeWeek, beforeDay)).getSingleResult())); - // months - resultList.add(new DataReportSeriesItem(SeriesTime.MONTH, entityManager - .createQuery(createCountSelectTargetsLastPoll(cb, beforeMonth, beforeWeek)).getSingleResult())); - // years - resultList.add(new DataReportSeriesItem(SeriesTime.YEAR, entityManager - .createQuery(createCountSelectTargetsLastPoll(cb, beforeYear, beforeMonth)).getSingleResult())); - // years - resultList.add(new DataReportSeriesItem(SeriesTime.MORE_THAN_YEAR, - entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, beforeYear)).getSingleResult())); - // never - resultList.add(new DataReportSeriesItem(SeriesTime.NEVER, - entityManager.createQuery(createCountSelectTargetsLastPoll(cb, null, null)).getSingleResult())); - - return new DataReportSeries<>("TargetLastPoll", resultList); - } - - private CriteriaQuery createCountSelectTargetsLastPoll(final CriteriaBuilder cb, final LocalDateTime from, - final LocalDateTime to) { + private static CriteriaQuery createCountSelectTargetsLastPoll(final CriteriaBuilder cb, + final LocalDateTime from, final LocalDateTime to) { Long start = null; Long end = null; @@ -289,8 +282,8 @@ public class JpaReportManagement implements ReportManagement { return countSelect; } - private List> mapDistirbutionUsageResultToDataReport(final int topXEntries, - final List resultListTop) { + private static List> mapDistirbutionUsageResultToDataReport( + final int topXEntries, final List resultListTop) { final List> innerOuterReport = new ArrayList<>(); final Map map = new LinkedHashMap<>(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java index 24617a49f..eda694aab 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaRolloutManagement.java @@ -24,8 +24,8 @@ import org.eclipse.hawkbit.repository.RolloutFields; import org.eclipse.hawkbit.repository.RolloutGroupManagement; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.TargetManagement; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent; import org.eclipse.hawkbit.repository.exception.RolloutIllegalStateException; -import org.eclipse.hawkbit.repository.jpa.cache.CacheWriteNotify; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; import org.eclipse.hawkbit.repository.jpa.model.JpaRolloutGroup; import org.eclipse.hawkbit.repository.jpa.model.JpaRollout_; @@ -54,6 +54,7 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -110,15 +111,15 @@ public class JpaRolloutManagement implements RolloutManagement { @Autowired private ApplicationContext context; + @Autowired + private ApplicationEventPublisher eventPublisher; + @Autowired private NoCountPagingRepository criteriaNoCountDao; @Autowired private PlatformTransactionManager txManager; - @Autowired - private CacheWriteNotify cacheWriteNotify; - @Autowired private VirtualPropertyReplacer virtualPropertyReplacer; @@ -249,13 +250,6 @@ public class JpaRolloutManagement implements RolloutManagement { int groupIndex = 0; final Long totalCount = savedRollout.getTotalTargets(); final int groupSize = (int) Math.ceil((double) totalCount / (double) amountOfGroups); - // validate if the amount of groups that will be created are the amount - // of groups that the client what's to have created. - int amountGroupValidated = amountOfGroups; - final int amountGroupCreation = (int) (Math.ceil((double) totalCount / (double) groupSize)); - if (amountGroupCreation == (amountOfGroups - 1)) { - amountGroupValidated--; - } RolloutGroup lastSavedGroup = null; while (pageIndex < totalCount) { groupIndex++; @@ -282,11 +276,11 @@ public class JpaRolloutManagement implements RolloutManagement { targetGroup .forEach(target -> rolloutTargetGroupRepository.save(new RolloutTargetGroup(savedGroup, target))); - cacheWriteNotify.rolloutGroupCreated(groupIndex, savedRollout.getId(), savedGroup.getId(), - amountGroupValidated, groupIndex); + eventPublisher.publishEvent(new RolloutGroupCreatedEvent(group, context.getId())); pageIndex += groupSize; } + savedRollout.setRolloutGroupsCreated(groupIndex); savedRollout.setStatus(RolloutStatus.READY); return rolloutRepository.save(savedRollout); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java index 7308fb1d0..cc41c8ce3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaSoftwareManagement.java @@ -598,12 +598,10 @@ public class JpaSoftwareManagement implements SoftwareManagement { @Override public List findSoftwareModuleMetadataBySoftwareModuleId(final Long softwareModuleId) { - return Collections - .unmodifiableList(softwareModuleMetadataRepository - .findAll((Specification) (root, query, - cb) -> cb.and(cb.equal( - root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), - softwareModuleId)))); + return Collections.unmodifiableList(softwareModuleMetadataRepository + .findAll((Specification) (root, query, cb) -> cb + .and(cb.equal(root.get(JpaSoftwareModuleMetadata_.softwareModule).get(JpaSoftwareModule_.id), + softwareModuleId)))); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java index 7dd292645..4ef8ed14a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTagManagement.java @@ -17,12 +17,12 @@ import java.util.List; import org.eclipse.hawkbit.repository.TagFields; import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet; @@ -33,8 +33,11 @@ import org.eclipse.hawkbit.repository.jpa.rsql.RSQLUtility; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -44,8 +47,6 @@ import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; -import com.google.common.eventbus.EventBus; - /** * JP>A implementation of {@link TagManagement}. * @@ -67,14 +68,17 @@ public class JpaTagManagement implements TagManagement { private DistributionSetRepository distributionSetRepository; @Autowired - private EventBus eventBus; + private ApplicationEventPublisher eventPublisher; @Autowired - private TenantAware tenantAware; + private ApplicationContext applicationContext; @Autowired private AfterTransactionCommitExecutor afterCommit; + @Autowired + private TenantAware tenantAware; + @Autowired private VirtualPropertyReplacer virtualPropertyReplacer; @@ -96,7 +100,8 @@ public class JpaTagManagement implements TagManagement { final TargetTag save = targetTagRepository.save((JpaTargetTag) targetTag); - afterCommit.afterCommit(() -> eventBus.post(new TargetTagCreatedEvent(save))); + afterCommit.afterCommit( + () -> eventPublisher.publishEvent(new TargetTagCreatedEvent(save, applicationContext.getId()))); return save; } @@ -115,7 +120,8 @@ public class JpaTagManagement implements TagManagement { }); final List save = Collections.unmodifiableList(targetTagRepository.save(targetTags)); - afterCommit.afterCommit(() -> save.forEach(tag -> eventBus.post(new TargetTagCreatedEvent(tag)))); + afterCommit.afterCommit(() -> save.forEach( + tag -> eventPublisher.publishEvent(new TargetTagCreatedEvent(tag, applicationContext.getId())))); return save; } @@ -137,7 +143,8 @@ public class JpaTagManagement implements TagManagement { // finally delete the tag itself targetTagRepository.deleteByName(targetTagName); - afterCommit.afterCommit(() -> eventBus.post(new TargetTagDeletedEvent(tag))); + afterCommit.afterCommit(() -> eventPublisher.publishEvent( + new TargetTagDeletedEvent(tenantAware.getCurrentTenant(), tag.getId(), applicationContext.getId()))); } @@ -174,7 +181,8 @@ public class JpaTagManagement implements TagManagement { checkNotNull(targetTag.getName()); checkNotNull(targetTag.getId()); final TargetTag save = targetTagRepository.save((JpaTargetTag) targetTag); - afterCommit.afterCommit(() -> eventBus.post(new TargetTagUpdateEvent(save))); + afterCommit.afterCommit(() -> eventPublisher + .publishEvent(new TargetTagUpdateEvent(save, EventPublisherHolder.getInstance().getApplicationId()))); return save; } @@ -197,7 +205,8 @@ public class JpaTagManagement implements TagManagement { final DistributionSetTag save = distributionSetTagRepository.save((JpaDistributionSetTag) distributionSetTag); - afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagCreatedEvent(save))); + afterCommit.afterCommit(() -> eventPublisher + .publishEvent(new DistributionSetTagCreatedEvent(save, applicationContext.getId()))); return save; } @@ -216,8 +225,8 @@ public class JpaTagManagement implements TagManagement { } final List save = Collections .unmodifiableList(distributionSetTagRepository.save(distributionSetTags)); - afterCommit.afterCommit(() -> save.forEach(tag -> eventBus.post(new DistributionSetTagCreatedEvent(tag)))); - + afterCommit.afterCommit(() -> save.forEach(tag -> eventPublisher + .publishEvent(new DistributionSetTagCreatedEvent(tag, applicationContext.getId())))); return save; } @@ -238,7 +247,9 @@ public class JpaTagManagement implements TagManagement { distributionSetTagRepository.deleteByName(tagName); - afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagDeletedEvent(tag))); + afterCommit.afterCommit( + () -> eventPublisher.publishEvent(new DistributionSetTagDeletedEvent(tenantAware.getCurrentTenant(), + tag.getId(), applicationContext.getId()))); } @Override @@ -248,7 +259,8 @@ public class JpaTagManagement implements TagManagement { checkNotNull(distributionSetTag.getName()); checkNotNull(distributionSetTag.getId()); final DistributionSetTag save = distributionSetTagRepository.save((JpaDistributionSetTag) distributionSetTag); - afterCommit.afterCommit(() -> eventBus.post(new DistributionSetTagUpdateEvent(save))); + afterCommit.afterCommit(() -> eventPublisher.publishEvent( + new DistributionSetTagUpdateEvent(save, EventPublisherHolder.getInstance().getApplicationId()))); return save; } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java index f2eac4051..b42e33b3c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTargetManagement.java @@ -16,7 +16,6 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import javax.annotation.PreDestroy; import javax.persistence.EntityManager; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; @@ -32,8 +31,8 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.FilterParams; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagAssigmentResultEvent; +import org.eclipse.hawkbit.repository.TimestampCalculator; +import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.executor.AfterTransactionCommitExecutor; @@ -56,6 +55,8 @@ import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -71,7 +72,6 @@ import org.springframework.util.Assert; import org.springframework.validation.annotation.Validated; import com.google.common.collect.Lists; -import com.google.common.eventbus.EventBus; /** * JPA implementation of {@link TargetManagement}. @@ -97,7 +97,10 @@ public class JpaTargetManagement implements TargetManagement { private NoCountPagingRepository criteriaNoCountDao; @Autowired - private EventBus eventBus; + private ApplicationEventPublisher eventPublisher; + + @Autowired + private ApplicationContext applicationContext; @Autowired private TenantAware tenantAware; @@ -218,7 +221,8 @@ public class JpaTargetManagement implements TargetManagement { public void deleteTargets(final Collection targetIDs) { targetRepository.deleteByIdIn(targetIDs); - targetIDs.forEach(targetId -> eventBus.post(new TargetDeletedEvent(tenantAware.getCurrentTenant(), targetId))); + targetIDs.forEach(targetId -> eventPublisher.publishEvent( + new TargetDeletedEvent(tenantAware.getCurrentTenant(), targetId, applicationContext.getId()))); } @Override @@ -368,8 +372,6 @@ public class JpaTargetManagement implements TargetManagement { final TargetTagAssignmentResult result = new TargetTagAssignmentResult(0, 0, alreadyAssignedTargets.size(), Collections.emptyList(), alreadyAssignedTargets, tag); - afterCommit.afterCommit( - () -> eventBus.post(new TargetTagAssigmentResultEvent(result, tenantAware.getCurrentTenant()))); return result; } @@ -380,9 +382,6 @@ public class JpaTargetManagement implements TargetManagement { allTargets.size(), 0, Collections.unmodifiableList(targetRepository.save(allTargets)), Collections.emptyList(), tag); - afterCommit.afterCommit( - () -> eventBus.post(new TargetTagAssigmentResultEvent(result, tenantAware.getCurrentTenant()))); - // no reason to persist the tag entityManager.detach(tag); return result; @@ -396,15 +395,7 @@ public class JpaTargetManagement implements TargetManagement { .findAll(TargetSpecifications.byControllerIdWithStatusAndTagsInJoin(controllerIds)); allTargets.forEach(target -> target.addTag(tag)); - final List save = Collections.unmodifiableList(targetRepository.save(allTargets)); - - afterCommit.afterCommit(() -> { - final TargetTagAssignmentResult assigmentResult = new TargetTagAssignmentResult(0, save.size(), 0, save, - Collections.emptyList(), tag); - eventBus.post(new TargetTagAssigmentResultEvent(assigmentResult, tenantAware.getCurrentTenant())); - }); - - return save; + return Collections.unmodifiableList(targetRepository.save(allTargets)); } private List unAssignTag(final Collection targets, final TargetTag tag) { @@ -413,13 +404,7 @@ public class JpaTargetManagement implements TargetManagement { toUnassign.forEach(target -> target.removeTag(tag)); - final List save = Collections.unmodifiableList(targetRepository.save(toUnassign)); - afterCommit.afterCommit(() -> { - final TargetTagAssignmentResult assigmentResult = new TargetTagAssignmentResult(0, 0, save.size(), - Collections.emptyList(), save, tag); - eventBus.post(new TargetTagAssigmentResultEvent(assigmentResult, tenantAware.getCurrentTenant())); - }); - return save; + return Collections.unmodifiableList(targetRepository.save(toUnassign)); } @Override @@ -612,11 +597,6 @@ public class JpaTargetManagement implements TargetManagement { return countByCriteriaAPI(specList); } - @PreDestroy - void destroy() { - eventBus.unregister(this); - } - @Override @Modifying @Transactional(isolation = Isolation.READ_UNCOMMITTED) diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java index d5d6a5540..2b62e660c 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/JpaTenantConfigurationManagement.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.repository.jpa; +import java.io.Serializable; + import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.jpa.model.JpaTenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfiguration; @@ -46,8 +48,8 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan @Override @Cacheable(value = "tenantConfiguration", key = "#configurationKey.getKeyName()") - public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey, - final Class propertyType) { + public TenantConfigurationValue getConfigurationValue( + final TenantConfigurationKey configurationKey, final Class propertyType) { validateTenantConfigurationDataType(configurationKey, propertyType); final TenantConfiguration tenantConfiguration = tenantConfigurationRepository @@ -75,7 +77,7 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan } @Override - public TenantConfigurationValue buildTenantConfigurationValueByKey( + public TenantConfigurationValue buildTenantConfigurationValueByKey( final TenantConfigurationKey configurationKey, final Class propertyType, final TenantConfiguration tenantConfiguration) { if (tenantConfiguration != null) { @@ -95,7 +97,8 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan } @Override - public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey) { + public TenantConfigurationValue getConfigurationValue( + final TenantConfigurationKey configurationKey) { return getConfigurationValue(configurationKey, configurationKey.getDataType()); } @@ -122,8 +125,8 @@ public class JpaTenantConfigurationManagement implements EnvironmentAware, Tenan @CacheEvict(value = "tenantConfiguration", key = "#configurationKey.getKeyName()") @Transactional(isolation = Isolation.READ_UNCOMMITTED) @Modifying - public TenantConfigurationValue addOrUpdateConfiguration(final TenantConfigurationKey configurationKey, - final T value) { + public TenantConfigurationValue addOrUpdateConfiguration( + final TenantConfigurationKey configurationKey, final T value) { if (!configurationKey.getDataType().isAssignableFrom(value.getClass())) { throw new TenantConfigurationValidatorException(String.format( diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java index 817bd076e..305179681 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/RolloutRepository.java @@ -20,6 +20,7 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; /** @@ -43,7 +44,7 @@ public interface RolloutRepository * @return the count of the updated rows. Zero if no row has been updated */ @Modifying - @Transactional(isolation = Isolation.READ_UNCOMMITTED) + @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_COMMITTED) @Query("UPDATE JpaRollout r SET r.lastCheck = :lastCheck WHERE r.lastCheck < (:lastCheck - :delay) AND r.status=:status") int updateLastCheck(@Param("lastCheck") final long lastCheck, @Param("delay") final long delay, @Param("status") final RolloutStatus status); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java index de6e437a3..94d23f11e 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/SoftwareModuleRepository.java @@ -89,13 +89,13 @@ public interface SoftwareModuleRepository /** * * - * @param set + * @param setId * to search for * @return all {@link SoftwareModule}s that are assigned to given * {@link DistributionSet} */ @EntityGraph(value = "SoftwareModule.artifacts", type = EntityGraphType.LOAD) - List findByAssignedTo(JpaDistributionSet set); + List findByAssignedToId(Long setId); /** * @param pageable diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java index 6dda89ad7..0f6f40768 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/TargetInfoRepository.java @@ -15,7 +15,6 @@ import javax.persistence.Entity; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; -import org.springframework.cache.annotation.CacheEvict; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -53,6 +52,5 @@ public interface TargetInfoRepository { * * @return persisted or updated {@link Entity} */ - @CacheEvict(value = { "targetStatus", "distributionUsageInstalled", "targetsLastPoll" }, allEntries = true) S save(S entity); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java index 5dfb70633..b46f45739 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/aspects/ExceptionMappingAspectHandler.java @@ -41,9 +41,6 @@ import com.google.common.collect.Maps; * {@link Aspect} catches persistence exceptions and wraps them to custom * specific exceptions Additionally it checks and prevents access to certain * packages. Logging aspect which logs the call stack - * - * - * */ @Aspect public class ExceptionMappingAspectHandler implements Ordered { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java deleted file mode 100644 index b4e322c77..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheField.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.cache; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; -import org.springframework.cache.CacheManager; -import org.springframework.data.annotation.Transient; - -/** - * Marks an field within a JPA entity as transient and this field should be - * loaded from a configured {@link CacheManager} by using the JPA entity - * listeners. - * - * - * - * @see CacheFieldEntityListener - */ -@Target({ FIELD }) -@Retention(RUNTIME) -@Transient -public @interface CacheField { - - /** - * @return the cache key name for this cacheable field which is used to - * store the value. - */ - String key(); - -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java deleted file mode 100644 index 021a17a9d..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeys.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.cache; - -import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; - -/** - * RepositoryConstants for cache keys used in multiple classes. - * - * - * - * - * @see CacheFieldEntityListener - * @see CacheWriteNotify - * @see CacheField - * - */ -public final class CacheKeys { - - /** - * The cache key name for the {@link UpdateActionStatus} download progress - * event. - */ - public static final String DOWNLOAD_PROGRESS_PERCENT = "download.progress.percent"; - public static final String ROLLOUT_GROUP_CREATED = "rollout.group.created"; - public static final String ROLLOUT_GROUP_TOTAL = "rollout.group.total"; - - /** - * utility class only private constructor. - */ - private CacheKeys() { - - } - - /** - * calculates the cache key for a specific entity. The cache key must be - * different for each different identifiable entity by its ID. - * - * @param entityId - * the ID of the entity to build the specific cache key for this - * entity - * @param cacheKey - * the cache key for the field to be cached - * @return the combined cache key based on the given {@code entityId} and - * {@code cacheKey} - */ - public static String entitySpecificCacheKey(final String entityId, final String cacheKey) { - return entityId + "." + cacheKey; - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotify.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotify.java deleted file mode 100644 index 6dfdf157f..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotify.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.cache; - -import java.math.RoundingMode; - -import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent; -import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.tenancy.TenantAware; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.stereotype.Service; - -import com.google.common.eventbus.EventBus; -import com.google.common.math.DoubleMath; - -/** - * An service which combines the functionality for functional use cases to write - * into the cache an notify the writing to the cache to the {@link EventBus}. - * - * - * - */ -@Service -public class CacheWriteNotify { - private static final int DOWNLOAD_PROGRESS_MAX = 100; - - @Autowired - private CacheManager cacheManager; - - @Autowired - private EventBus eventBus; - - @Autowired - private TenantAware tenantAware; - - /** - * writes the download progress into the cache - * {@link CacheKeys#DOWNLOAD_PROGRESS_PERCENT} and notifies the - * {@link EventBus} with a {@link DownloadProgressEvent}. - * - * @param statusId - * the ID of the {@link ActionStatus} - * @param requestedBytes - * requested bytes of the request - * @param shippedBytesSinceLast - * since last event - * @param shippedBytesOverall - * for the download request - */ - public void downloadProgress(final Long statusId, final Long requestedBytes, final Long shippedBytesSinceLast, - final Long shippedBytesOverall) { - - final Cache cache = cacheManager.getCache(ActionStatus.class.getName()); - final String cacheKey = CacheKeys.entitySpecificCacheKey(String.valueOf(statusId), - CacheKeys.DOWNLOAD_PROGRESS_PERCENT); - - final int progressPercent = DoubleMath.roundToInt(shippedBytesOverall * 100.0 / requestedBytes, - RoundingMode.DOWN); - - if (progressPercent < DOWNLOAD_PROGRESS_MAX) { - cache.put(cacheKey, progressPercent); - } else { - // in case we reached progress 100 delete the cache value again - // because otherwise he will - // keep there forever - cache.evict(cacheKey); - } - - eventBus.post(new DownloadProgressEvent(tenantAware.getCurrentTenant(), statusId, requestedBytes, - shippedBytesSinceLast, shippedBytesOverall)); - } - - /** - * Writes the {@link CacheKeys#ROLLOUT_GROUP_CREATED} and - * {@link CacheKeys#ROLLOUT_GROUP_TOTAL} into the cache and notfies the - * {@link EventBus} with a {@link RolloutGroupCreatedEvent}. - * - * @param revision - * the revision of the event - * @param rolloutId - * the ID of the rollout the group has been created - * @param rolloutGroupId - * the ID of the rollout group which has been created - * @param totalRolloutGroup - * the total number of rollout groups for this rollout - * @param createdRolloutGroup - * the number of already created groups of the rollout - */ - public void rolloutGroupCreated(final long revision, final Long rolloutId, final Long rolloutGroupId, - final int totalRolloutGroup, final int createdRolloutGroup) { - - final Cache cache = cacheManager.getCache(Rollout.class.getName()); - final String cacheKeyGroupTotal = CacheKeys.entitySpecificCacheKey(String.valueOf(rolloutId), - CacheKeys.ROLLOUT_GROUP_TOTAL); - final String cacheKeyGroupCreated = CacheKeys.entitySpecificCacheKey(String.valueOf(rolloutId), - CacheKeys.ROLLOUT_GROUP_CREATED); - if (createdRolloutGroup < totalRolloutGroup) { - cache.put(cacheKeyGroupTotal, totalRolloutGroup); - cache.put(cacheKeyGroupCreated, createdRolloutGroup); - } else { - // in case we reached progress 100 delete the cache value again - // because otherwise he will keep there forever - cache.evict(cacheKeyGroupTotal); - cache.evict(cacheKeyGroupCreated); - } - eventBus.post(new RolloutGroupCreatedEvent(tenantAware.getCurrentTenant(), revision, rolloutId, rolloutGroupId, - totalRolloutGroup, createdRolloutGroup)); - } - - /** - * @param cacheManager - * the cacheManager to set - */ - void setCacheManager(final CacheManager cacheManager) { - this.cacheManager = cacheManager; - } - - /** - * @param eventBus - * the eventBus to set - */ - void setEventBus(final EventBus eventBus) { - this.eventBus = eventBus; - } - - /** - * @param tenantAware - * the tenantAware to set - */ - void setTenantAware(final TenantAware tenantAware) { - this.tenantAware = tenantAware; - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/event/JpaEventEntityManager.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/event/JpaEventEntityManager.java new file mode 100644 index 000000000..08127fd89 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/event/JpaEventEntityManager.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.jpa.event; + +import javax.persistence.EntityManager; + +import org.eclipse.hawkbit.repository.event.remote.EventEntityManager; +import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; +import org.eclipse.hawkbit.tenancy.TenantAware; +import org.springframework.transaction.annotation.Isolation; +import org.springframework.transaction.annotation.Transactional; + +/** + * A TenantAwareEvent entity manager, which loads an entity by id and type for + * remote events. + */ +@Transactional(readOnly = true, isolation = Isolation.READ_UNCOMMITTED) +public class JpaEventEntityManager implements EventEntityManager { + + private final TenantAware tenantAware; + + private final EntityManager entityManager; + + /** + * Constructor. + * + * @param tenantAware + * the tenant aware + * @param entityManager + * the entity manager + */ + public JpaEventEntityManager(final TenantAware tenantAware, final EntityManager entityManager) { + this.tenantAware = tenantAware; + this.entityManager = entityManager; + } + + @Override + public E findEntity(final String tenant, final Long id, + final Class entityType) { + return tenantAware.runAsTenant(tenant, () -> entityManager.find(entityType, id)); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java deleted file mode 100644 index 572f64369..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/eventbus/EventMerger.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.eventbus; - -import java.util.Iterator; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import org.eclipse.hawkbit.eventbus.EventSubscriber; -import org.eclipse.hawkbit.eventbus.event.Event; -import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutChangeEvent; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupChangeEvent; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent; -import org.eclipse.hawkbit.repository.model.Rollout; -import org.eclipse.hawkbit.repository.model.RolloutGroup; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; - -import com.google.common.eventbus.AllowConcurrentEvents; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; - -/** - * Collects and merges fine grained events to more generic events and push them - * in a fixed delay on the events bus. This helps for code which are not - * interested in all fine grained events, e.g. UI code. The UI code is not - * interested in handling the flood of events, so collecting the events and - * merge them to one event together and post them in a fixed interval is easier - * to consume e.g. for push notifications on UI. - * - */ -@EventSubscriber -@Service -public class EventMerger { - - private static final Set rolloutEvents = ConcurrentHashMap.newKeySet(); - private static final Set rolloutGroupEvents = ConcurrentHashMap.newKeySet(); - - @Autowired - private EventBus eventBus; - - /** - * Checks if there are events to publish in the fixed interval. - */ - @Scheduled(initialDelay = 10000, fixedDelay = 2000) - public void rolloutEventScheduler() { - final Iterator rolloutIterator = rolloutEvents.iterator(); - while (rolloutIterator.hasNext()) { - final RolloutEventKey eventKey = rolloutIterator.next(); - eventBus.post(new RolloutChangeEvent(1, eventKey.tenant, eventKey.rolloutId)); - rolloutIterator.remove(); - } - - final Iterator rolloutGroupIterator = rolloutGroupEvents.iterator(); - while (rolloutGroupIterator.hasNext()) { - final RolloutEventKey eventKey = rolloutGroupIterator.next(); - eventBus.post(new RolloutGroupChangeEvent(1, eventKey.tenant, eventKey.rolloutId, eventKey.rolloutGroupId)); - rolloutGroupIterator.remove(); - } - } - - /** - * Called by the event bus to retrieve all necessary events to collect and - * merge. - * - * @param event - * the event on the event bus - */ - @Subscribe - @AllowConcurrentEvents - public void onEvent(final Event event) { - Long rolloutId = null; - Long rolloutGroupId = null; - if (event instanceof ActionCreatedEvent) { - rolloutId = getRolloutId(((ActionCreatedEvent) event).getEntity().getRollout()); - rolloutGroupId = getRolloutGroupId(((ActionCreatedEvent) event).getEntity().getRolloutGroup()); - } else if (event instanceof ActionPropertyChangeEvent) { - rolloutId = getRolloutId(((ActionPropertyChangeEvent) event).getEntity().getRollout()); - rolloutGroupId = getRolloutGroupId(((ActionPropertyChangeEvent) event).getEntity().getRolloutGroup()); - } else if (event instanceof RolloutPropertyChangeEvent) { - rolloutId = ((RolloutPropertyChangeEvent) event).getEntity().getId(); - } else if (event instanceof RolloutGroupCreatedEvent) { - rolloutId = ((RolloutGroupCreatedEvent) event).getRolloutId(); - rolloutGroupId = ((RolloutGroupCreatedEvent) event).getRolloutGroupId(); - } else if (event instanceof RolloutGroupPropertyChangeEvent) { - final RolloutGroup rolloutGroup = ((RolloutGroupPropertyChangeEvent) event).getEntity(); - rolloutId = rolloutGroup.getRollout().getId(); - rolloutGroupId = rolloutGroup.getId(); - } - - if (rolloutId != null) { - rolloutEvents.add(new RolloutEventKey(rolloutId, event.getTenant())); - if (rolloutGroupId != null) { - rolloutGroupEvents.add(new RolloutEventKey(rolloutId, rolloutGroupId, event.getTenant())); - } - } - } - - private Long getRolloutGroupId(final RolloutGroup rolloutGroup) { - if (rolloutGroup != null) { - return rolloutGroup.getId(); - } - return null; - } - - private Long getRolloutId(final Rollout rollout) { - if (rollout != null) { - return rollout.getId(); - } - return null; - } - - /** - * The rollout key in the concurrent set to be hold. - * - * @author Michael Hirsch - * - */ - private static final class RolloutEventKey { - private final Long rolloutId; - private final String tenant; - private final Long rolloutGroupId; - - private RolloutEventKey(final Long rolloutId, final Long rolloutGroupId, final String tenant) { - this.rolloutGroupId = rolloutGroupId; - this.rolloutId = rolloutId; - this.tenant = tenant; - } - - private RolloutEventKey(final Long rolloutId, final String tenant) { - this(rolloutId, null, tenant); - } - - @Override - public int hashCode() {// NOSONAR - as this is generated - final int prime = 31; - int result = 1; - result = prime * result + ((rolloutGroupId == null) ? 0 : rolloutGroupId.hashCode()); - result = prime * result + ((rolloutId == null) ? 0 : rolloutId.hashCode()); - result = prime * result + ((tenant == null) ? 0 : tenant.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) {// NOSONAR - as this is - // generated - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final RolloutEventKey other = (RolloutEventKey) obj; - if (rolloutGroupId == null) { - if (other.rolloutGroupId != null) { - return false; - } - } else if (!rolloutGroupId.equals(other.rolloutGroupId)) { - return false; - } - if (rolloutId == null) { - if (other.rolloutId != null) { - return false; - } - } else if (!rolloutId.equals(other.rolloutId)) { - return false; - } - if (tenant == null) { - if (other.tenant != null) { - return false; - } - } else if (!tenant.equals(other.tenant)) { - return false; - } - return true; - } - - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java index 983cb2763..319f9123a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaBaseEntity.java @@ -31,8 +31,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener; */ @MappedSuperclass @Access(AccessType.FIELD) -@EntityListeners({ AuditingEntityListener.class, CacheFieldEntityListener.class, EntityPropertyChangeListener.class, - EntityInterceptorListener.class }) +@EntityListeners({ AuditingEntityListener.class, EntityPropertyChangeListener.class, EntityInterceptorListener.class }) public abstract class AbstractJpaBaseEntity implements BaseEntity { private static final long serialVersionUID = 1L; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java index 09c261b60..cfd48afb2 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/AbstractJpaTenantAwareBaseEntity.java @@ -14,9 +14,9 @@ import javax.persistence.PrePersist; import javax.validation.constraints.Size; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; -import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder; import org.eclipse.hawkbit.repository.model.TenantAwareBaseEntity; +import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; import org.eclipse.persistence.annotations.Multitenant; import org.eclipse.persistence.annotations.MultitenantType; import org.eclipse.persistence.annotations.TenantDiscriminatorColumn; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java deleted file mode 100644 index b303f33a4..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/CacheFieldEntityListener.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.model; - -import java.io.Serializable; -import java.lang.reflect.Field; - -import javax.persistence.PostLoad; -import javax.persistence.PostRemove; - -import org.apache.commons.lang3.reflect.FieldUtils; -import org.eclipse.hawkbit.repository.jpa.cache.CacheField; -import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; -import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cache.Cache; -import org.springframework.cache.Cache.ValueWrapper; -import org.springframework.cache.CacheManager; -import org.springframework.hateoas.Identifiable; - -/** - * An JPA entity listener which enriches the JPA entity fields which are - * annotated with {@link CacheField} with values from the {@link CacheManager}. - * Only JPA entities which are implementing {@link Identifiable} can be handled - * by this entity listener cause the cache keys are calculated with the ID of - * the entity. - * - * - * - * - */ -public class CacheFieldEntityListener { - - private static final Logger LOGGER = LoggerFactory.getLogger(CacheFieldEntityListener.class); - - /** - * enriches the JPA entities after loading the entity from the SQL database. - * - * @param target - * the target which has been loaded from the database - */ - @PostLoad - public void postLoad(final Object target) { - if (target instanceof Identifiable) { - final CacheManager cacheManager = CacheManagerHolder.getInstance().getCacheManager(); - @SuppressWarnings("rawtypes") - final String id = ((Identifiable) target).getId().toString(); - final Class type = target.getClass(); - findCacheFields(type, id, (field, cacheKey, id1) -> { - final Cache cache = cacheManager.getCache(type.getName()); - final ValueWrapper valueWrapper = cache.get(CacheKeys.entitySpecificCacheKey(id1.toString(), cacheKey)); - if (valueWrapper != null && valueWrapper.get() != null) { - FieldUtils.writeField(field, target, valueWrapper.get(), true); - } - }); - } - } - - /** - * deletes the associated cache fields from the cache when deleted the - * entity from the database. - * - * @param target - * the entity which has been deleted - */ - @PostRemove - public void postDelete(final Object target) { - if (target instanceof Identifiable) { - final CacheManager cacheManager = CacheManagerHolder.getInstance().getCacheManager(); - @SuppressWarnings("rawtypes") - final String id = ((Identifiable) target).getId().toString(); - final Class type = target.getClass(); - findCacheFields(type, id, (field, cacheKey, id1) -> { - final Cache cache = cacheManager.getCache(type.getName()); - cache.evict(CacheKeys.entitySpecificCacheKey(id1.toString(), cacheKey)); - }); - } - } - - private void findCacheFields(final Class type, final Serializable id, - final CacheFieldCallback callback) { - final Field[] declaredFields = type.getDeclaredFields(); - for (final Field field : declaredFields) { - if (field.getAnnotation(CacheField.class) != null) { - try { - final CacheField annotation = field.getAnnotation(CacheField.class); - callback.fromCache(field, annotation.key(), id); - } catch (final IllegalAccessException e) { - LOGGER.error("cannot access the field {} for the entity {}, ignoring the cacheable field", field, - type, e); - } - } - } - } - - @FunctionalInterface - private interface CacheFieldCallback { - /** - * callback methods which is called by the - * {@link CacheFieldEntityListener#findCacheFields(Class, Serializable, CacheFieldCallback)} - * in case a field is annotated with {@link CacheField}. - * - * @param field - * the field which is annotaed with {@link CacheField} - * @param cacheKey - * the configured cache key in the annotation - * {@link CacheField#key()} - * @param id - * the ID of the entity - * @throws IllegalAccessException - * in case the field cannot be accessed - */ - void fromCache(final Field field, final String cacheKey, Serializable id) throws IllegalAccessException; - } - -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java index 6aec1e131..01e4e5676 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaAction.java @@ -30,16 +30,15 @@ import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.repository.eventbus.event.ActionCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.ActionPropertyChangeEvent; -import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper; -import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; import org.eclipse.persistence.annotations.CascadeOnDelete; import org.eclipse.persistence.descriptors.DescriptorEvent; @@ -187,13 +186,14 @@ public class JpaAction extends AbstractJpaTenantAwareBaseEntity implements Actio @Override public void fireCreateEvent(final DescriptorEvent descriptorEvent) { - EventBusHolder.getInstance().getEventBus().post(new ActionCreatedEvent(this)); + EventPublisherHolder.getInstance().getEventPublisher() + .publishEvent(new ActionCreatedEvent(this, EventPublisherHolder.getInstance().getApplicationId())); } @Override public void fireUpdateEvent(final DescriptorEvent descriptorEvent) { - EventBusHolder.getInstance().getEventBus() - .post(new ActionPropertyChangeEvent(this, EntityPropertyChangeHelper.getChangeSet(descriptorEvent))); + EventPublisherHolder.getInstance().getEventPublisher() + .publishEvent(new ActionUpdatedEvent(this, EventPublisherHolder.getInstance().getApplicationId())); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java index 8fa774c00..131ed8113 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaActionStatus.java @@ -25,11 +25,8 @@ import javax.persistence.ManyToOne; import javax.persistence.NamedAttributeNode; import javax.persistence.NamedEntityGraph; import javax.persistence.Table; -import javax.persistence.Transient; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.repository.jpa.cache.CacheField; -import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; @@ -72,13 +69,6 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements @Column(name = "detail_message", length = 512) private List messages; - /** - * Note: filled only in {@link Status#DOWNLOAD}. - */ - @Transient - @CacheField(key = CacheKeys.DOWNLOAD_PROGRESS_PERCENT) - private short downloadProgressPercent; - /** * Creates a new {@link ActionStatus} object. * @@ -121,11 +111,6 @@ public class JpaActionStatus extends AbstractJpaTenantAwareBaseEntity implements // JPA default constructor. } - @Override - public short getDownloadProgressPercent() { - return downloadProgressPercent; - } - @Override public Long getOccurredAt() { return occurredAt; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java index 372109ac1..fe2fc53f3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaDistributionSet.java @@ -12,9 +12,9 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -34,14 +34,11 @@ import javax.persistence.Table; import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; -import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent.PropertyChange; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException; import org.eclipse.hawkbit.repository.exception.UnsupportedSoftwareModuleForThisDistributionSetException; -import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper; -import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; @@ -52,8 +49,13 @@ import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetFilterQuery; import org.eclipse.hawkbit.repository.model.TargetInfo; +import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; import org.eclipse.persistence.annotations.CascadeOnDelete; import org.eclipse.persistence.descriptors.DescriptorEvent; +import org.eclipse.persistence.queries.UpdateObjectQuery; +import org.eclipse.persistence.sessions.changesets.DirectToFieldChangeRecord; +import org.eclipse.persistence.sessions.changesets.ObjectChangeSet; +import org.springframework.context.ApplicationEvent; /** * Jpa implementation of {@link DistributionSet}. @@ -347,27 +349,40 @@ public class JpaDistributionSet extends AbstractJpaNamedVersionedEntity implemen @Override public void fireCreateEvent(final DescriptorEvent descriptorEvent) { - EventBusHolder.getInstance().getEventBus().post(new DistributionCreatedEvent(this)); + publishEventWithEventPublisher( + new DistributionSetCreatedEvent(this, EventPublisherHolder.getInstance().getApplicationId())); } @Override public void fireUpdateEvent(final DescriptorEvent descriptorEvent) { - final Map changeSet = EntityPropertyChangeHelper.getChangeSet(descriptorEvent); - EventBusHolder.getInstance().getEventBus().post(new DistributionSetUpdateEvent(this)); + publishEventWithEventPublisher( + new DistributionSetUpdateEvent(this, EventPublisherHolder.getInstance().getApplicationId())); - if (changeSet.containsKey(DELETED_PROPERTY)) { - final Boolean newDeleted = (Boolean) changeSet.get(DELETED_PROPERTY).getNewValue(); - if (newDeleted) { - EventBusHolder.getInstance().getEventBus().post(new DistributionDeletedEvent(getTenant(), getId())); - } + if (isSoftDeleted(descriptorEvent)) { + publishEventWithEventPublisher(new DistributionSetDeletedEvent(getTenant(), getId(), + EventPublisherHolder.getInstance().getApplicationId())); } - } @Override public void fireDeleteEvent(final DescriptorEvent descriptorEvent) { - EventBusHolder.getInstance().getEventBus().post(new DistributionDeletedEvent(getTenant(), getId())); + publishEventWithEventPublisher(new DistributionSetDeletedEvent(getTenant(), getId(), + EventPublisherHolder.getInstance().getApplicationId())); + } + + private static void publishEventWithEventPublisher(final ApplicationEvent event) { + EventPublisherHolder.getInstance().getEventPublisher().publishEvent(event); + } + + private static boolean isSoftDeleted(final DescriptorEvent event) { + final ObjectChangeSet changeSet = ((UpdateObjectQuery) event.getQuery()).getObjectChangeSet(); + final List changes = changeSet.getChanges().stream() + .filter(record -> record instanceof DirectToFieldChangeRecord) + .map(record -> (DirectToFieldChangeRecord) record).collect(Collectors.toList()); + + return changes.stream().filter(record -> DELETED_PROPERTY.equals(record.getAttribute()) + && Boolean.parseBoolean(record.getNewValue().toString())).count() > 0; } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java index dc1b82ac2..ef9fd9cf6 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRollout.java @@ -28,12 +28,9 @@ import javax.persistence.UniqueConstraint; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutPropertyChangeEvent; -import org.eclipse.hawkbit.repository.jpa.cache.CacheField; -import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; -import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper; -import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent; import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; @@ -86,12 +83,7 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event @Column(name = "total_targets") private long totalTargets; - @Transient - @CacheField(key = CacheKeys.ROLLOUT_GROUP_TOTAL) - private int rolloutGroupsTotal; - - @Transient - @CacheField(key = CacheKeys.ROLLOUT_GROUP_CREATED) + @Column(name = "rollout_groups_created") private int rolloutGroupsCreated; @Transient @@ -172,14 +164,6 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event this.totalTargets = totalTargets; } - public int getRolloutGroupsTotal() { - return rolloutGroupsTotal; - } - - public void setRolloutGroupsTotal(final int rolloutGroupsTotal) { - this.rolloutGroupsTotal = rolloutGroupsTotal; - } - @Override public int getRolloutGroupsCreated() { return rolloutGroupsCreated; @@ -215,8 +199,8 @@ public class JpaRollout extends AbstractJpaNamedEntity implements Rollout, Event @Override public void fireUpdateEvent(final DescriptorEvent descriptorEvent) { - EventBusHolder.getInstance().getEventBus() - .post(new RolloutPropertyChangeEvent(this, EntityPropertyChangeHelper.getChangeSet(descriptorEvent))); + EventPublisherHolder.getInstance().getEventPublisher() + .publishEvent(new RolloutUpdatedEvent(this, EventPublisherHolder.getInstance().getApplicationId())); } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java index 2c17a41c7..31f282a64 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaRolloutGroup.java @@ -26,12 +26,11 @@ import javax.persistence.Transient; import javax.persistence.UniqueConstraint; import javax.validation.constraints.Size; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupPropertyChangeEvent; -import org.eclipse.hawkbit.repository.jpa.model.helper.EntityPropertyChangeHelper; -import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; +import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; import org.eclipse.persistence.descriptors.DescriptorEvent; /** @@ -256,8 +255,9 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr @Override public void fireUpdateEvent(final DescriptorEvent descriptorEvent) { - EventBusHolder.getInstance().getEventBus().post( - new RolloutGroupPropertyChangeEvent(this, EntityPropertyChangeHelper.getChangeSet(descriptorEvent))); + EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new RolloutGroupUpdatedEvent(this, + + EventPublisherHolder.getInstance().getApplicationId())); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java index 371f992fc..90747b493 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/JpaTarget.java @@ -37,10 +37,9 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.eclipse.hawkbit.im.authentication.SpPermission; -import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent; -import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; +import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityChecker; import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder; import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder; @@ -49,6 +48,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetInfo; import org.eclipse.hawkbit.repository.model.TargetTag; +import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; import org.eclipse.persistence.annotations.CascadeOnDelete; import org.eclipse.persistence.descriptors.DescriptorEvent; import org.springframework.data.domain.Persistable; @@ -278,16 +278,19 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Persistable, TargetInfo, EventAwareE @Override public void fireUpdateEvent(final DescriptorEvent descriptorEvent) { - EventBusHolder.getInstance().getEventBus().post(new TargetInfoUpdateEvent(this)); + EventPublisherHolder.getInstance().getEventPublisher().publishEvent( + new TargetUpdatedEvent(this.getTarget(), EventPublisherHolder.getInstance().getApplicationId())); } @Override diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java deleted file mode 100644 index 64417c7d6..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/CacheManagerHolder.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.model.helper; - -import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.CacheManager; - -/** - * A singleton bean which holds the {@link CacheManager} to have to the cache - * manager in beans not instantiated by spring e.g. JPA entities or - * {@link CacheFieldEntityListener} which cannot be autowired. - * - * - * - */ -public final class CacheManagerHolder { - - private static final CacheManagerHolder SINGLETON = new CacheManagerHolder(); - - @Autowired - private CacheManager cacheManager; - - private CacheManagerHolder() { - - } - - /** - * @return the cache manager holder singleton instance - */ - public static CacheManagerHolder getInstance() { - return SINGLETON; - } - - /** - * @return the cacheManager - */ - public CacheManager getCacheManager() { - return cacheManager; - } - - /** - * Normally not used when using spring-boot then the cachemanager is - * autowired to the CacheManagerHolder, but for testing purposes. - * - * @param cacheManager - * the cache manager to set for the cache manager holder. - */ - public void setCacheManager(final CacheManager cacheManager) { - this.cacheManager = cacheManager; - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EntityPropertyChangeHelper.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EntityPropertyChangeHelper.java deleted file mode 100644 index 3d296c513..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/model/helper/EntityPropertyChangeHelper.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.model.helper; - -import java.util.Map; -import java.util.stream.Collectors; - -import org.eclipse.hawkbit.repository.eventbus.event.AbstractPropertyChangeEvent.PropertyChange; -import org.eclipse.persistence.descriptors.DescriptorEvent; -import org.eclipse.persistence.internal.sessions.ObjectChangeSet; -import org.eclipse.persistence.queries.UpdateObjectQuery; -import org.eclipse.persistence.sessions.changesets.DirectToFieldChangeRecord; - -/** - * Helper class to get the change set for the property changes in the Entity. - * - */ -public final class EntityPropertyChangeHelper { - - private EntityPropertyChangeHelper() { - // noop - } - - /** - * To get the map of entity property change set - * - * @param clazz - * @param event - * @return the map of the changeSet - */ - public static Map getChangeSet(final DescriptorEvent event) { - final ObjectChangeSet changeSet = ((UpdateObjectQuery) event.getQuery()).getObjectChangeSet(); - return changeSet.getChanges().stream().filter(record -> record instanceof DirectToFieldChangeRecord) - .map(record -> (DirectToFieldChangeRecord) record) - .collect(Collectors.toMap(record -> record.getAttribute(), - record -> new PropertyChange(record.getOldValue(), record.getNewValue()))); - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java index 38665db38..9c7ab5e0a 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtility.java @@ -31,6 +31,7 @@ import org.eclipse.hawkbit.repository.FieldValueConverter; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; +import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.SimpleTypeConverter; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_7_2__cascade_delete___H2.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_7_2__cascade_delete___H2.sql new file mode 100644 index 000000000..0c6225fae --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_7_2__cascade_delete___H2.sql @@ -0,0 +1,27 @@ +alter table sp_ds_module drop constraint fk_ds_module_ds; +alter table sp_ds_module + add constraint fk_ds_module_ds + foreign key (ds_id) + references sp_distribution_set (id) + on delete cascade; + +alter table sp_ds_module drop constraint fk_ds_module_module; +alter table sp_ds_module + add constraint fk_ds_module_module + foreign key (module_id) + references sp_base_software_module (id) + on delete cascade; + +alter table sp_external_artifact drop constraint fk_external_assigned_sm; +alter table sp_external_artifact + add constraint fk_external_assigned_sm + foreign key (software_module) + references sp_base_software_module (id) + on delete cascade; + +alter table sp_artifact drop constraint fk_assigned_sm; +alter table sp_artifact + add constraint fk_assigned_sm + foreign key (software_module) + references sp_base_software_module (id) + on delete cascade; \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_9_0__add_rollout_groups_created___H2.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_9_0__add_rollout_groups_created___H2.sql new file mode 100644 index 000000000..64518f762 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/H2/V1_9_0__add_rollout_groups_created___H2.sql @@ -0,0 +1,2 @@ + ALTER TABLE sp_rollout ADD column rollout_groups_created BIGINT; + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_7_2__cascade_delete___MYSQL.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_7_2__cascade_delete___MYSQL.sql new file mode 100644 index 000000000..9cc12b375 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_7_2__cascade_delete___MYSQL.sql @@ -0,0 +1,27 @@ +alter table sp_ds_module drop FOREIGN KEY fk_ds_module_ds; +alter table sp_ds_module + add constraint fk_ds_module_ds + foreign key (ds_id) + references sp_distribution_set (id) + on delete cascade; + +alter table sp_ds_module drop FOREIGN KEY fk_ds_module_module; +alter table sp_ds_module + add constraint fk_ds_module_module + foreign key (module_id) + references sp_base_software_module (id) + on delete cascade; + +alter table sp_external_artifact drop FOREIGN KEY fk_external_assigned_sm; +alter table sp_external_artifact + add constraint fk_external_assigned_sm + foreign key (software_module) + references sp_base_software_module (id) + on delete cascade; + +alter table sp_artifact drop FOREIGN KEY fk_assigned_sm; +alter table sp_artifact + add constraint fk_assigned_sm + foreign key (software_module) + references sp_base_software_module (id) + on delete cascade; \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_9_0__add_rollout_groups_created___MYSQL.sql b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_9_0__add_rollout_groups_created___MYSQL.sql new file mode 100644 index 000000000..64518f762 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/main/resources/db/migration/MYSQL/V1_9_0__add_rollout_groups_created___MYSQL.sql @@ -0,0 +1,2 @@ + ALTER TABLE sp_rollout ADD column rollout_groups_created BIGINT; + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/AbstractRemoteEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/AbstractRemoteEventTest.java new file mode 100644 index 000000000..84841b4ea --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/AbstractRemoteEventTest.java @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import static org.junit.Assert.fail; + +import java.util.Map; + +import org.apache.commons.lang3.ClassUtils; +import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter; +import org.eclipse.hawkbit.repository.event.TenantAwareEvent; +import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; +import org.junit.Before; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.cloud.bus.jackson.BusJacksonAutoConfiguration; +import org.springframework.integration.support.MessageBuilder; +import org.springframework.integration.support.MutableMessageHeaders; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHeaders; +import org.springframework.messaging.converter.AbstractMessageConverter; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.util.MimeType; +import org.springframework.util.MimeTypeUtils; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Maps; + +/** + * Test the remote entity events. + */ +public abstract class AbstractRemoteEventTest extends AbstractJpaIntegrationTest { + + @Autowired + private BusProtoStuffMessageConverter busProtoStuffMessageConverter; + + private AbstractMessageConverter jacksonMessageConverter; + + @Before + public void setup() throws Exception { + final BusJacksonAutoConfiguration autoConfiguration = new BusJacksonAutoConfiguration(); + this.jacksonMessageConverter = autoConfiguration.busJsonConverter(); + ReflectionTestUtils.setField(jacksonMessageConverter, "packagesToScan", + new String[] { "org.eclipse.hawkbit.repository.event.remote", + ClassUtils.getPackageName(RemoteApplicationEvent.class) }); + ((InitializingBean) jacksonMessageConverter).afterPropertiesSet(); + + } + + private Message createProtoStuffMessage(final TenantAwareEvent event) { + final Map headers = Maps.newLinkedHashMap(); + headers.put(MessageHeaders.CONTENT_TYPE, BusProtoStuffMessageConverter.APPLICATION_BINARY_PROTOSTUFF); + return busProtoStuffMessageConverter.toMessage(event, new MutableMessageHeaders(headers)); + } + + private Message createJsonMessage(final Object event) { + final Map headers = Maps.newLinkedHashMap(); + headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON); + try { + final String json = new ObjectMapper().writeValueAsString(event); + final Message message = MessageBuilder.withPayload(json).copyHeaders(headers).build(); + return message; + } catch (final JsonProcessingException e) { + fail(e.getMessage()); + } + return null; + } + + protected Message createMessageWithImmutableHeader(final TenantAwareEvent event) { + final Map headers = Maps.newLinkedHashMap(); + return busProtoStuffMessageConverter.toMessage(event, new MessageHeaders(headers)); + } + + protected TenantAwareEvent createJacksonEvent(final TenantAwareEvent event) { + final Message message = createJsonMessage(event); + return (TenantAwareEvent) jacksonMessageConverter.fromMessage(message, event.getClass()); + } + + protected TenantAwareEvent createProtoStuffEvent(final TenantAwareEvent event) { + final Message message = createProtoStuffMessage(event); + return (TenantAwareEvent) busProtoStuffMessageConverter.fromMessage(message, event.getClass()); + } +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteIdEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteIdEventTest.java new file mode 100644 index 000000000..341cbd863 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteIdEventTest.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assert.fail; + +import java.lang.reflect.Constructor; +import java.util.Arrays; + +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test the remote entity events. + */ +@Features("Component Tests - Repository") +@Stories("Entity Id Events") +public class RemoteIdEventTest extends AbstractRemoteEventTest { + + private static final long ENTITY_ID = 1L; + + @Test + @Description("Verifies that the is ds id correct reloaded") + public void testDistributionSetDeletedEvent() { + assertAndCreateRemoteEvent(DistributionSetDeletedEvent.class); + } + + @Test + @Description("Verifies that the ds tag id is correct reloaded") + public void testDistributionSetTagDeletedEvent() { + assertAndCreateRemoteEvent(DistributionSetTagDeletedEvent.class); + } + + @Test + @Description("Verifies that the target id is correct reloaded") + public void testTargetDeletedEvent() { + assertAndCreateRemoteEvent(TargetDeletedEvent.class); + } + + @Test + @Description("Verifies that the target tag id is correct reloaded") + public void testTargetTagDeletedEvent() { + assertAndCreateRemoteEvent(TargetTagDeletedEvent.class); + } + + protected void assertAndCreateRemoteEvent(final Class eventType) { + + final Constructor constructor = Arrays.stream(eventType.getDeclaredConstructors()) + .filter(con -> con.getParameterCount() == 3).findAny() + .orElseThrow(() -> new IllegalArgumentException("Given event is not RemoteIdEvent compatible")); + + try { + final RemoteIdEvent event = (RemoteIdEvent) constructor.newInstance("tenant", ENTITY_ID, "Node"); + assertEntity(ENTITY_ID, event); + } catch (final ReflectiveOperationException e) { + fail("Exception should not happen " + e.getMessage()); + } + } + + protected RemoteIdEvent assertEntity(final long id, final RemoteIdEvent event) { + assertThat(event.getEntityId()).isSameAs(id); + + RemoteIdEvent underTestCreatedEvent = (RemoteIdEvent) createProtoStuffEvent(event); + assertThat(underTestCreatedEvent.getEntityId()).isEqualTo(id); + + underTestCreatedEvent = (RemoteIdEvent) createJacksonEvent(event); + assertThat(underTestCreatedEvent.getEntityId()).isEqualTo(id); + + return underTestCreatedEvent; + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEventTest.java new file mode 100644 index 000000000..ed1a5223b --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/RemoteTenantAwareEventTest.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote; + +import static org.fest.assertions.api.Assertions.assertThat; +import static org.junit.Assert.fail; + +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Target; +import org.junit.Test; +import org.springframework.messaging.converter.MessageConversionException; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +@Features("Component Tests - Repository") +@Stories("RemoteTenantAwareEvent Tests") +public class RemoteTenantAwareEventTest extends AbstractRemoteEventTest { + + @Test + @Description("Verifies that a immutable header is not work") + public void testMessageWithImmutableHeader() { + final DownloadProgressEvent downloadProgressEvent = new DownloadProgressEvent("DEFAULT", 3L, "Node"); + + try { + createMessageWithImmutableHeader(downloadProgressEvent); + fail("MessageConversionException should happen"); + } catch (final MessageConversionException e) { + // ok + } + } + + @Test + @Description("Verifies that the download progress reloading by remote events works") + public void reloadDownloadProgessByRemoteEvent() { + final DownloadProgressEvent downloadProgressEvent = new DownloadProgressEvent("DEFAULT", 3L, "Node"); + + DownloadProgressEvent remoteEvent = (DownloadProgressEvent) createProtoStuffEvent(downloadProgressEvent); + assertThat(downloadProgressEvent).isEqualTo(remoteEvent); + + remoteEvent = (DownloadProgressEvent) createJacksonEvent(downloadProgressEvent); + assertThat(downloadProgressEvent).isEqualTo(remoteEvent); + } + + @Test + @Description("Verifies that target assignment event works") + public void testTargetAssignDistributionSetEvent() { + final DistributionSet dsA = testdataFactory.createDistributionSet(""); + final JpaAction generateAction = (JpaAction) entityFactory.generateAction(); + generateAction.setActionType(ActionType.FORCED); + final Target generateTarget = entityFactory.generateTarget("Test"); + final Target target = targetManagement.createTarget(generateTarget); + generateAction.setTarget(target); + generateAction.setDistributionSet(dsA); + final Action action = actionRepository.save(generateAction); + + final TargetAssignDistributionSetEvent assignmentEvent = new TargetAssignDistributionSetEvent(action, + serviceMatcher.getServiceId()); + + TargetAssignDistributionSetEvent underTest = (TargetAssignDistributionSetEvent) createProtoStuffEvent( + assignmentEvent); + assertTargetAssignDistributionSetEvent(action, underTest); + + underTest = (TargetAssignDistributionSetEvent) createJacksonEvent(assignmentEvent); + assertTargetAssignDistributionSetEvent(action, underTest); + } + + private void assertTargetAssignDistributionSetEvent(final Action action, + final TargetAssignDistributionSetEvent underTest) { + assertThat(underTest.getActionId()).isNotNull(); + assertThat(underTest.getControllerId()).isNotNull(); + assertThat(underTest.getDistributionSetId()).isNotNull(); + + assertThat(underTest.getActionId()).isEqualTo(action.getId()); + assertThat(underTest.getControllerId()).isEqualTo(action.getTarget().getControllerId()); + assertThat(underTest.getDistributionSetId()).isEqualTo(action.getDistributionSet().getId()); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/AbstractRemoteEntityEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/AbstractRemoteEntityEventTest.java new file mode 100644 index 000000000..9c7c4ecb9 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/AbstractRemoteEntityEventTest.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import static org.fest.assertions.Assertions.assertThat; +import static org.junit.Assert.fail; + +import java.lang.reflect.Constructor; + +import org.eclipse.hawkbit.repository.event.remote.AbstractRemoteEventTest; + +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test the remote entity events. + */ +@Features("Component Tests - Repository") +@Stories("Entity Events") +public abstract class AbstractRemoteEntityEventTest extends AbstractRemoteEventTest { + + protected RemoteEntityEvent assertAndCreateRemoteEvent(final Class> eventType) { + final E baseEntity = createEntity(); + final RemoteEntityEvent event = createRemoteEvent(baseEntity, eventType); + assertEntity(baseEntity, event); + return event; + } + + protected RemoteEntityEvent createRemoteEvent(final E baseEntity, + final Class> eventType) { + + Constructor constructor = null; + for (final Constructor constructors : eventType.getDeclaredConstructors()) { + if (constructors.getParameterCount() == 2) { + constructor = constructors; + } + } + + if (constructor == null) { + throw new IllegalArgumentException("No suitable constructor foundes"); + } + + try { + return (RemoteEntityEvent) constructor.newInstance(baseEntity, "Node"); + } catch (final ReflectiveOperationException e) { + fail("Exception should not happen " + e.getMessage()); + } + return null; + } + + protected RemoteEntityEvent assertEntity(final E baseEntity, final RemoteEntityEvent event) { + assertThat(event.getEntity()).isSameAs(baseEntity); + + RemoteEntityEvent underTestCreatedEvent = (RemoteEntityEvent) createProtoStuffEvent(event); + assertThat(underTestCreatedEvent.getEntity()).isEqualTo(baseEntity); + + underTestCreatedEvent = (RemoteEntityEvent) createJacksonEvent(event); + assertThat(underTestCreatedEvent.getEntity()).isEqualTo(baseEntity); + return underTestCreatedEvent; + } + + protected abstract E createEntity(); +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionEventTest.java new file mode 100644 index 000000000..a831b36df --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/ActionEventTest.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent; +import org.eclipse.hawkbit.repository.jpa.model.JpaAction; +import org.eclipse.hawkbit.repository.model.Action; +import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.Target; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test the remote entity events. + */ +@Features("Component Tests - Repository") +@Stories("Test ActionCreatedEvent and ActionUpdatedEvent") +public class ActionEventTest extends AbstractRemoteEntityEventTest { + + @Test + @Description("Verifies that the action entity reloading by remote created works") + public void testActionCreatedEvent() { + assertAndCreateRemoteEvent(ActionCreatedEvent.class); + } + + @Test + @Description("Verifies that the action entity reloading by remote updated works") + public void testActionUpdatedEvent() { + assertAndCreateRemoteEvent(ActionUpdatedEvent.class); + + } + + @Override + protected Action createEntity() { + final JpaAction generateAction = (JpaAction) entityFactory.generateAction(); + generateAction.setActionType(ActionType.FORCED); + final Target generateTarget = entityFactory.generateTarget("Test"); + final Target target = targetManagement.createTarget(generateTarget); + generateAction.setTarget(target); + return actionRepository.save(generateAction); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetEventTest.java new file mode 100644 index 000000000..d7a5015d4 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetEventTest.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test the remote entity events. + */ +@Features("Component Tests - Repository") +@Stories("Test DistributionSetCreatedEvent and DistributionSetUpdateEvent") +public class DistributionSetEventTest extends AbstractRemoteEntityEventTest { + + @Test + @Description("Verifies that the distribution set entity reloading by remote created event works") + public void testDistributionSetCreatedEvent() { + assertAndCreateRemoteEvent(DistributionSetCreatedEvent.class); + } + + @Test + @Description("Verifies that the distribution set entity reloading by remote updated event works") + public void testDistributionSetUpdateEvent() { + assertAndCreateRemoteEvent(DistributionSetUpdateEvent.class); + } + + @Override + protected DistributionSet createEntity() { + return distributionSetManagement.createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2", + "incomplete", distributionSetManagement.findDistributionSetTypeByKey("os"), null)); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagEventTest.java new file mode 100644 index 000000000..42e3c5aba --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/DistributionSetTagEventTest.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.model.DistributionSetTag; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test the remote entity events. + */ +@Features("Component Tests - Repository") +@Stories("Test DistributionSetTagCreatedEvent and DistributionSetTagUpdateEvent") +public class DistributionSetTagEventTest extends AbstractRemoteEntityEventTest { + + @Test + @Description("Verifies that the distribution set tag entity reloading by remote created event works") + public void testDistributionSetTagCreatedEvent() { + assertAndCreateRemoteEvent(DistributionSetTagCreatedEvent.class); + } + + @Test + @Description("Verifies that the distribution set tag entity reloading by remote updated event works") + public void testDistributionSetTagUpdateEvent() { + assertAndCreateRemoteEvent(DistributionSetTagUpdateEvent.class); + } + + @Override + protected DistributionSetTag createEntity() { + return tagManagement.createDistributionSetTag(entityFactory.generateDistributionSetTag("tag1")); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutEventTest.java new file mode 100644 index 000000000..77d689cc1 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutEventTest.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test the remote entity events. + */ +@Features("Component Tests - Repository") +@Stories("Test RolloutUpdatedEvent") +public class RolloutEventTest extends AbstractRemoteEntityEventTest { + + @Test + @Description("Verifies that the rollout entity reloading by remote updated event works") + public void testRolloutUpdatedEvent() { + assertAndCreateRemoteEvent(RolloutUpdatedEvent.class); + } + + @Override + protected Rollout createEntity() { + targetManagement.createTarget(entityFactory.generateTarget("12345")); + final DistributionSet ds = distributionSetManagement + .createDistributionSet(entityFactory.generateDistributionSet("incomplete", "2", "incomplete", + distributionSetManagement.findDistributionSetTypeByKey("os"), null)); + + final Rollout rollout = entityFactory.generateRollout(); + rollout.setName("exampleRollout"); + rollout.setTargetFilterQuery("controllerId==*"); + rollout.setDistributionSet(ds); + + final JpaRollout entity = (JpaRollout) rolloutManagement.createRollout(rollout, 10, + new RolloutGroupConditionBuilder().successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10") + .build()); + + return entity; + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupEventTest.java new file mode 100644 index 000000000..72f36b043 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/RolloutGroupEventTest.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import static org.fest.assertions.api.Assertions.assertThat; + +import java.util.UUID; + +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent; +import org.eclipse.hawkbit.repository.jpa.model.JpaRollout; +import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupSuccessCondition; +import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test the remote entity events. + */ +@Features("Component Tests - Repository") +@Stories("Test RolloutGroupCreatedEvent and RolloutGroupUpdatedEvent") +public class RolloutGroupEventTest extends AbstractRemoteEntityEventTest { + + @Test + @Description("Verifies that the rollout group entity reloading by remote created event works") + public void testRolloutGroupCreatedEvent() { + final RolloutGroupCreatedEvent createdEvent = (RolloutGroupCreatedEvent) assertAndCreateRemoteEvent( + RolloutGroupCreatedEvent.class); + assertThat(createdEvent.getRolloutId()).isNotNull(); + } + + @Test + @Description("Verifies that the rollout group entity reloading by remote updated event works") + public void testRolloutGroupUpdatedEvent() { + assertAndCreateRemoteEvent(RolloutGroupUpdatedEvent.class); + } + + @Override + protected RolloutGroup createEntity() { + targetManagement.createTarget(entityFactory.generateTarget(UUID.randomUUID().toString())); + final DistributionSet ds = distributionSetManagement + .createDistributionSet(entityFactory.generateDistributionSet(UUID.randomUUID().toString(), "2", + "incomplete", distributionSetManagement.findDistributionSetTypeByKey("os"), null)); + + final Rollout rollout = entityFactory.generateRollout(); + rollout.setName(UUID.randomUUID().toString()); + rollout.setTargetFilterQuery("controllerId==*"); + rollout.setDistributionSet(ds); + + final JpaRollout entity = (JpaRollout) rolloutManagement.createRollout(rollout, 10, + new RolloutGroupConditionBuilder().successCondition(RolloutGroupSuccessCondition.THRESHOLD, "10") + .build()); + + return rolloutManagement.findRolloutById(entity.getId()).getRolloutGroups().get(0); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetEventTest.java new file mode 100644 index 000000000..98e4e1150 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetEventTest.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import static org.fest.assertions.api.Assertions.assertThat; + +import org.eclipse.hawkbit.repository.model.Target; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test the remote entity events. + */ +@Features("Component Tests - Repository") +@Stories("Test TargetCreatedEvent, TargetUpdatedEvent and CancelTargetAssignmentEvent") +public class TargetEventTest extends AbstractRemoteEntityEventTest { + + @Test + @Description("Verifies that the target entity reloading by remote created event works") + public void testTargetCreatedEvent() { + assertAndCreateRemoteEvent(TargetCreatedEvent.class); + } + + @Test + @Description("Verifies that the target entity reloading by remote updated event works") + public void testTargetUpdatedEvent() { + assertAndCreateRemoteEvent(TargetUpdatedEvent.class); + } + + @Test + @Description("Verifies that cancel target assignment event works") + public void testCancelTargetAssignmentEvent() { + final Target target = createEntity(); + final CancelTargetAssignmentEvent assignmentEvent = new CancelTargetAssignmentEvent(target, 1L, "node"); + final CancelTargetAssignmentEvent underTest = (CancelTargetAssignmentEvent) assertEntity(target, + assignmentEvent); + + assertThat(underTest.getActionId()).isNotNull(); + } + + @Override + protected Target createEntity() { + return targetManagement.createTarget(entityFactory.generateTarget("12345")); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagEventTest.java new file mode 100644 index 000000000..c7bfce600 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/event/remote/entity/TargetTagEventTest.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.event.remote.entity; + +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.model.TargetTag; +import org.junit.Test; + +import ru.yandex.qatools.allure.annotations.Description; +import ru.yandex.qatools.allure.annotations.Features; +import ru.yandex.qatools.allure.annotations.Stories; + +/** + * Test the remote entity events. + */ +@Features("Component Tests - Repository") +@Stories("Test TargetTagCreatedEvent and TargetTagUpdateEvent") +public class TargetTagEventTest extends AbstractRemoteEntityEventTest { + + @Test + @Description("Verifies that the target tag entity reloading by remote created event works") + public void testTargetTagCreatedEvent() { + assertAndCreateRemoteEvent(TargetTagCreatedEvent.class); + } + + @Test + @Description("Verifies that the target tag entity reloading by remote updated event works") + public void testTargetTagUpdateEventt() { + assertAndCreateRemoteEvent(TargetTagUpdateEvent.class); + } + + @Override + protected TargetTag createEntity() { + return tagManagement.createTargetTag(entityFactory.generateTargetTag("tag1")); + } + +} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java index ae414ef19..bd91c8272 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DeploymentManagementTest.java @@ -22,9 +22,8 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.ActionStatusFields; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; -import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; import org.eclipse.hawkbit.repository.exception.ForceQuitActionNotAllowedException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; import org.eclipse.hawkbit.repository.jpa.configuration.Constants; @@ -41,20 +40,22 @@ import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.ActionWithStatusCount; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; +import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationListener; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort.Direction; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; @@ -69,8 +70,21 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Deployment Management") public class DeploymentManagementTest extends AbstractJpaIntegrationTest { + private EventHandlerStub eventHandlerStub; + + private CancelEventHandlerStub cancelEventHandlerStub; + @Autowired - private EventBus eventBus; + private ConfigurableApplicationContext applicationContext; + + @Before + public void addHandler() { + eventHandlerStub = new EventHandlerStub(); + applicationContext.addApplicationListener(eventHandlerStub); + + cancelEventHandlerStub = new CancelEventHandlerStub(); + applicationContext.addApplicationListener(cancelEventHandlerStub); + } @Test @Description("Test verifies that the repistory retrieves the action including all defined (lazy) details.") @@ -86,6 +100,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertThat(action.getTarget()).as("Target in action").isNotNull(); assertThat(action.getTarget().getAssignedDistributionSet()).as("AssignedDistributionSet of target in action") .isNotNull(); + } @Test @@ -377,9 +392,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Simple deployment or distribution set to target assignment test.") public void assignDistributionSet2Targets() throws InterruptedException { - - final EventHandlerMock eventHandlerMock = new EventHandlerMock(20); - eventBus.register(eventHandlerMock); + eventHandlerStub.setExpectedNumberOfEvents(20); final String myCtrlIDPref = "myCtrlID"; final Iterable savedNakedTargets = targetManagement @@ -425,7 +438,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { } } - final List events = eventHandlerMock.getEvents(10, TimeUnit.SECONDS); + final List events = eventHandlerStub.getEvents(10, TimeUnit.SECONDS); assertTargetAssignDistributionSetEvents(savedDeployedTargets, ds, events); } @@ -433,8 +446,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Test that it is not possible to assign a distribution set that is not complete.") public void failDistributionSetAssigmentThatIsNotComplete() throws InterruptedException { - final EventHandlerMock eventHandlerMock = new EventHandlerMock(0); - eventBus.register(eventHandlerMock); + eventHandlerStub.setExpectedNumberOfEvents(0); final List targets = testdataFactory.createTargets(10); @@ -454,21 +466,20 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { } catch (final IncompleteDistributionSetException ex) { } + // give some chance to receive events asynchronously + Thread.sleep(1L); + final List events = eventHandlerStub.getEvents(5, TimeUnit.SECONDS); + assertThat(events).as("events should be empty").isEmpty(); + incomplete.addModule(os); final DistributionSet nowComplete = distributionSetManagement.updateDistributionSet(incomplete); - // give some chance to receive events asynchronously - Thread.sleep(300); - final List events = eventHandlerMock.getEvents(1, TimeUnit.MILLISECONDS); - assertThat(events).as("events should be empty").isEmpty(); - - final EventHandlerMock eventHandlerMockAfterCompletionOfDs = new EventHandlerMock(10); - eventBus.register(eventHandlerMockAfterCompletionOfDs); + eventHandlerStub.setExpectedNumberOfEvents(10); assertThat(deploymentManagement.assignDistributionSet(nowComplete, targets).getAssigned()) .as("assign ds doesn't work").isEqualTo(10); - assertTargetAssignDistributionSetEvents(targets, nowComplete, - eventHandlerMockAfterCompletionOfDs.getEvents(10, TimeUnit.SECONDS)); + + assertTargetAssignDistributionSetEvents(targets, nowComplete, eventHandlerStub.getEvents(15, TimeUnit.SECONDS)); } @Test @@ -485,15 +496,12 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { // Each of the four targets get one assignment (4 * 1 = 4) final int expectedNumberOfEventsForAssignment = 4; - final EventHandlerMock eventHandlerMock = new EventHandlerMock(expectedNumberOfEventsForAssignment); - eventBus.register(eventHandlerMock); + eventHandlerStub.setExpectedNumberOfEvents(expectedNumberOfEventsForAssignment); // Each of the four targets get two more assignment the which are // cancelled (4 * 2 = 8) final int expectedNumberOfEventsForCancel = 8; - final CancelEventHandlerMock cancelEventHandlerMock = new CancelEventHandlerMock( - expectedNumberOfEventsForCancel); - eventBus.register(cancelEventHandlerMock); + cancelEventHandlerStub.setExpectedNumberOfEvents(expectedNumberOfEventsForCancel); final DeploymentResult deploymentResult = prepareComplexRepo(undeployedTargetPrefix, noOfUndeployedTargets, deployedTargetPrefix, noOfDeployedTargets, noOfDistributionSets, "myTestDS"); @@ -535,10 +543,10 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { .doesNotContain(Iterables.toArray(deployedTargetsFromDB, JpaTarget.class)); // For each of the 4 targets 1 distribution sets gets assigned - eventHandlerMock.getEvents(10, TimeUnit.SECONDS); + eventHandlerStub.getEvents(10, TimeUnit.SECONDS); // For each of the 4 targets 2 distribution sets gets cancelled - cancelEventHandlerMock.getEvents(10, TimeUnit.SECONDS); + cancelEventHandlerStub.getEvents(10, TimeUnit.SECONDS); } @@ -825,7 +833,7 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { assertThat(dsA.getOptLockRevision()).as("lock revision is wrong").isEqualTo( distributionSetManagement.findDistributionSetByIdWithDetails(dsA.getId()).getOptLockRevision()); - final List targs = new ArrayList(); + final List targs = new ArrayList<>(); targs.add(targ); final Iterable savedTargs = deploymentManagement.assignDistributionSet(dsA, targs).getAssignedEntity(); targ = savedTargs.iterator().next(); @@ -934,17 +942,20 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { private void assertTargetAssignDistributionSetEvents(final List targets, final DistributionSet ds, final List events) { + assertThat(events).isNotEmpty(); for (final Target myt : targets) { boolean found = false; for (final TargetAssignDistributionSetEvent event : events) { - if (event.getTarget().getControllerId().equals(myt.getControllerId())) { + if (event.getControllerId().equals(myt.getControllerId())) { found = true; final List activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(myt); assertThat(activeActionsByTarget).as("size of active actions for target is wrong").isNotEmpty(); assertThat(event.getActionId()).as("Action id in database and event do not match") .isEqualTo(activeActionsByTarget.get(0).getId()); - assertThat(event.getSoftwareModules()).as("softwaremodule size is not correct") - .containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()])); + + assertThat(distributionSetManagement.findDistributionSetById(event.getDistributionSetId()) + .getModules()).as("softwaremodule size is not correct") + .containsOnly(ds.getModules().toArray(new SoftwareModule[ds.getModules().size()])); } } assertThat(found).as("No event found for controller " + myt.getControllerId()).isTrue(); @@ -952,19 +963,17 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { } /** - * + * * */ - private class DeploymentResult + private class DeploymentResult { + final List deployedTargetIDs = new ArrayList<>(); + final List undeployedTargetIDs = new ArrayList<>(); + final List distributionSetIDs = new ArrayList<>(); - { - final List deployedTargetIDs = new ArrayList(); - final List undeployedTargetIDs = new ArrayList(); - final List distributionSetIDs = new ArrayList(); - - private final List undeployedTargets = new ArrayList(); - private final List deployedTargets = new ArrayList(); - private final List distributionSets = new ArrayList(); + private final List undeployedTargets = new ArrayList<>(); + private final List deployedTargets = new ArrayList<>(); + private final List distributionSets = new ArrayList<>(); public DeploymentResult(final Iterable deployedTs, final Iterable undeployedTs, final Iterable dss, final String deployedTargetPrefix, @@ -982,101 +991,97 @@ public class DeploymentManagementTest extends AbstractJpaIntegrationTest { } - /** - * @return the distributionSetIDs - */ public List getDistributionSetIDs() { return distributionSetIDs; } - /** - * @return - */ public List getDeployedTargetIDs() { return deployedTargetIDs; } - /** - * @return - */ public List getUndeployedTargets() { return undeployedTargets; } - /** - * @return - */ public List getDistributionSets() { return distributionSets; } - /** - * @return - */ public List getDeployedTargets() { return deployedTargets; } - /** - * @return the undeployedTargetIDs - */ public List getUndeployedTargetIDs() { return undeployedTargetIDs; } } - private static class EventHandlerMock { + protected static class EventHandlerStub implements ApplicationListener { private final List events = Collections.synchronizedList(new LinkedList<>()); - private final CountDownLatch latch; - private final int expectedNumberOfEvents; + private CountDownLatch latch; + private int expectedNumberOfEvents; - private EventHandlerMock(final int expectedNumberOfEvents) { + /** + * @param expectedNumberOfEvents + * the expectedNumberOfEvents to set + */ + public void setExpectedNumberOfEvents(final int expectedNumberOfEvents) { + events.clear(); this.expectedNumberOfEvents = expectedNumberOfEvents; this.latch = new CountDownLatch(expectedNumberOfEvents); } - @Subscribe - public void handleEvent(final TargetAssignDistributionSetEvent event) { - events.add(event); - latch.countDown(); - } - public List getEvents(final long timeout, final TimeUnit unit) throws InterruptedException { latch.await(timeout, unit); - final List handledEvents = new LinkedList<>(events); + final List handledEvents = Collections + .unmodifiableList(new LinkedList<>(events)); assertThat(handledEvents).as("Did not receive the expected amount of events (" + expectedNumberOfEvents + ") within timeout. Received events are " + handledEvents).hasSize(expectedNumberOfEvents); - return handledEvents; + + } + + @Override + public void onApplicationEvent(final TargetAssignDistributionSetEvent event) { + if (latch == null) { + return; + } + events.add(event); + latch.countDown(); + } } - private static class CancelEventHandlerMock { + private static class CancelEventHandlerStub implements ApplicationListener { private final List events = Collections.synchronizedList(new LinkedList<>()); - private final CountDownLatch latch; - private final int expectedNumberOfEvents; + private CountDownLatch latch; + private int expectedNumberOfEvents; - private CancelEventHandlerMock(final int expectedNumberOfEvents) { + public void setExpectedNumberOfEvents(final int expectedNumberOfEvents) { + events.clear(); this.expectedNumberOfEvents = expectedNumberOfEvents; this.latch = new CountDownLatch(expectedNumberOfEvents); } - @Subscribe - public void handleEvent(final CancelTargetAssignmentEvent event) { - events.add(event); - latch.countDown(); - } - public List getEvents(final long timeout, final TimeUnit unit) throws InterruptedException { latch.await(timeout, unit); - final List handledEvents = new LinkedList(events); + final List handledEvents = new LinkedList<>(events); assertThat(handledEvents).as("Did not receive the expected amount of events (" + expectedNumberOfEvents + ") within timeout. Received events are " + handledEvents).hasSize(expectedNumberOfEvents); return handledEvents; } + + @Override + public void onApplicationEvent(final CancelTargetAssignmentEvent event) { + if (latch == null) { + return; + } + events.add(event); + latch.countDown(); + } } } diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java index bcb6a1f32..c5b730bee 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/DistributionSetManagementTest.java @@ -16,7 +16,6 @@ import java.util.Collection; import java.util.Iterator; import java.util.List; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.exception.DistributionSetTypeUndefinedException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; @@ -35,6 +34,7 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.DistributionSetFilter.DistributionSetFilterBuilder; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetTag; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java index ca82924a8..0d9338304 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/ReportManagementTest.java @@ -20,7 +20,6 @@ import java.util.Calendar; import java.util.List; import java.util.stream.Collectors; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.ReportManagement; import org.eclipse.hawkbit.repository.ReportManagement.DateTypes; import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus; @@ -30,6 +29,7 @@ import org.eclipse.hawkbit.repository.model.Action; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.ActionStatus; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java index 5f2fe3fbd..53720d378 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TagManagementTest.java @@ -269,7 +269,7 @@ public class TagManagementTest extends AbstractJpaIntegrationTest { @Test @Description("Ensures that a deleted tag is removed from the repository as defined.") - public void deleteTargetTas() { + public void deleteTargetTags() { // create test data final Iterable tags = createTargetsWithTags(); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java index 6689f0c25..b509ab51f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TargetManagementTest.java @@ -29,7 +29,6 @@ import javax.persistence.Query; import javax.validation.ConstraintViolationException; import org.eclipse.hawkbit.im.authentication.SpPermission; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.TenantNotExistException; import org.eclipse.hawkbit.repository.jpa.model.JpaAction; @@ -39,6 +38,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTargetInfo; import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag; import org.eclipse.hawkbit.repository.model.Action.Status; import org.eclipse.hawkbit.repository.model.DistributionSet; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.Tag; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java index 73feda1c2..2065e9026 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/TenantConfigurationManagementTest.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.repository.jpa; import static org.fest.assertions.api.Assertions.assertThat; import static org.junit.Assert.fail; +import java.io.Serializable; import java.time.Duration; import java.util.Arrays; import java.util.HashMap; @@ -222,7 +223,7 @@ public class TenantConfigurationManagementTest extends AbstractJpaIntegrationTes public void requestConfigValueWithWrongType() { try { tenantConfigurationManagement.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, - Object.class); + Serializable.class); Assert.fail(""); } catch (final TenantConfigurationValidatorException e) { diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeysTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeysTest.java deleted file mode 100644 index 921d1953a..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheKeysTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.cache; - -import static org.fest.assertions.api.Assertions.assertThat; - -import org.junit.Test; - -import ru.yandex.qatools.allure.annotations.Features; -import ru.yandex.qatools.allure.annotations.Stories; - -@Features("Unit Tests - Repository") -@Stories("CacheKeys") -public class CacheKeysTest { - - @Test - public void entitySpecificCacheKeyPattern() { - final String knownEntityId = "123"; - final String knownCacheKey = "someField"; - final String entitySpecificCacheKey = CacheKeys.entitySpecificCacheKey(knownEntityId, knownCacheKey); - assertThat(entitySpecificCacheKey).isEqualTo(knownEntityId + "." + knownCacheKey); - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotifyTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotifyTest.java deleted file mode 100644 index 1f6fbca6f..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/cache/CacheWriteNotifyTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.cache; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.eclipse.hawkbit.repository.eventbus.event.DownloadProgressEvent; -import org.eclipse.hawkbit.repository.model.ActionStatus; -import org.eclipse.hawkbit.tenancy.TenantAware; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; - -import com.google.common.eventbus.EventBus; - -import ru.yandex.qatools.allure.annotations.Features; -import ru.yandex.qatools.allure.annotations.Stories; - -@Features("Unit Tests - Repository") -@Stories("CacheWriteNotify") -@RunWith(MockitoJUnitRunner.class) -public class CacheWriteNotifyTest { - - @Mock - private EventBus eventBusMock; - - @Mock - private CacheManager cacheManagerMock; - - @Mock - private Cache cacheMock; - - @Mock - private TenantAware tenantAwareMock; - - private CacheWriteNotify underTest; - - @Before - public void before() { - underTest = new CacheWriteNotify(); - underTest.setEventBus(eventBusMock); - underTest.setCacheManager(cacheManagerMock); - underTest.setTenantAware(tenantAwareMock); - } - - @Test - public void downloadgProgressIsCachedAndEventSent() { - final long knownStatusId = 1; - - when(cacheManagerMock.getCache(ActionStatus.class.getName())).thenReturn(cacheMock); - when(tenantAwareMock.getCurrentTenant()).thenReturn("default"); - - underTest.downloadProgress(knownStatusId, 500L, 100L, 100L); - - verify(cacheManagerMock).getCache(eq(ActionStatus.class.getName())); - verify(cacheMock).put(knownStatusId + "." + CacheKeys.DOWNLOAD_PROGRESS_PERCENT, 20); - verify(eventBusMock).post(any(DownloadProgressEvent.class)); - } - -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/RepositoryEntityEventTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/event/RepositoryEntityEventTest.java similarity index 68% rename from hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/RepositoryEntityEventTest.java rename to hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/event/RepositoryEntityEventTest.java index 0aa305d52..507347e63 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/RepositoryEntityEventTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/event/RepositoryEntityEventTest.java @@ -6,33 +6,31 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ -package org.eclipse.hawkbit.repository.jpa.eventbus; +package org.eclipse.hawkbit.repository.jpa.event; import static org.fest.assertions.Assertions.assertThat; -import java.net.URI; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import org.eclipse.hawkbit.eventbus.event.Event; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent; +import org.eclipse.hawkbit.repository.event.TenantAwareEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest; +import org.eclipse.hawkbit.repository.jpa.event.RepositoryEntityEventTest.RepositoryTestConfiguration; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.fest.assertions.api.Assertions; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; - -import com.google.common.eventbus.EventBus; -import com.google.common.eventbus.Subscribe; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.event.EventListener; import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; @@ -40,17 +38,15 @@ import ru.yandex.qatools.allure.annotations.Stories; @Features("Component Tests - Repository") @Stories("Entity Events") +@SpringApplicationConfiguration(classes = RepositoryTestConfiguration.class) public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { @Autowired - private EventBus eventBus; - - private final MyEventListener eventListener = new MyEventListener(); + private MyEventListener eventListener; @Before public void beforeTest() { eventListener.queue.clear(); - eventBus.register(eventListener); } @Test @@ -77,19 +73,6 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { assertThat(targetUpdatedEvent.getEntity().getId()).isEqualTo(createdTarget.getId()); } - @Test - @Description("Verifies that the target info update event is published when a target info has been updated") - public void targetInfoUpdateEventIsPublished() throws InterruptedException { - final Target createdTarget = targetManagement.createTarget(entityFactory.generateTarget("12345")); - controllerManagament.updateTargetStatus(createdTarget.getTargetInfo(), TargetUpdateStatus.PENDING, - System.currentTimeMillis(), URI.create("http://127.0.0.1")); - - final TargetInfoUpdateEvent targetInfoUpdatedEvent = eventListener.waitForEvent(TargetInfoUpdateEvent.class, 1, - TimeUnit.SECONDS); - assertThat(targetInfoUpdatedEvent).isNotNull(); - assertThat(targetInfoUpdatedEvent.getEntity().getTarget().getId()).isEqualTo(createdTarget.getId()); - } - @Test @Description("Verifies that the target deleted event is published when a target has been deleted") public void targetDeletedEventIsPublished() throws InterruptedException { @@ -100,7 +83,7 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { final TargetDeletedEvent targetDeletedEvent = eventListener.waitForEvent(TargetDeletedEvent.class, 1, TimeUnit.SECONDS); assertThat(targetDeletedEvent).isNotNull(); - assertThat(targetDeletedEvent.getTargetId()).isEqualTo(createdTarget.getId()); + assertThat(targetDeletedEvent.getEntityId()).isEqualTo(createdTarget.getId()); } @Test @@ -112,8 +95,8 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { final DistributionSet createDistributionSet = distributionSetManagement .createDistributionSet(generateDistributionSet); - final DistributionCreatedEvent dsCreatedEvent = eventListener.waitForEvent(DistributionCreatedEvent.class, 1, - TimeUnit.SECONDS); + final DistributionSetCreatedEvent dsCreatedEvent = eventListener.waitForEvent(DistributionSetCreatedEvent.class, + 1, TimeUnit.SECONDS); assertThat(dsCreatedEvent).isNotNull(); assertThat(dsCreatedEvent.getEntity().getId()).isEqualTo(createDistributionSet.getId()); } @@ -130,24 +113,33 @@ public class RepositoryEntityEventTest extends AbstractJpaIntegrationTest { distributionSetManagement.deleteDistributionSet(createDistributionSet); - final DistributionDeletedEvent dsDeletedEvent = eventListener.waitForEvent(DistributionDeletedEvent.class, 1, - TimeUnit.SECONDS); + final DistributionSetDeletedEvent dsDeletedEvent = eventListener.waitForEvent(DistributionSetDeletedEvent.class, + 1, TimeUnit.SECONDS); assertThat(dsDeletedEvent).isNotNull(); - assertThat(dsDeletedEvent.getDistributionSetId()).isEqualTo(createDistributionSet.getId()); + assertThat(dsDeletedEvent.getEntityId()).isEqualTo(createDistributionSet.getId()); } - private class MyEventListener { + public static class RepositoryTestConfiguration { - private final BlockingQueue queue = new LinkedBlockingQueue<>(); + @Bean + public MyEventListener myEventListenerBean() { + return new MyEventListener(); + } - @Subscribe - public void onEvent(final Event event) { + } + + private static class MyEventListener { + + private final BlockingQueue queue = new LinkedBlockingQueue<>(); + + @EventListener(classes = TenantAwareEvent.class) + public void onEvent(final TenantAwareEvent event) { queue.offer(event); } public T waitForEvent(final Class eventType, final long timeout, final TimeUnit timeUnit) throws InterruptedException { - Event event = null; + TenantAwareEvent event = null; while ((event = queue.poll(timeout, timeUnit)) != null) { if (event.getClass().isAssignableFrom(eventType)) { return (T) event; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java deleted file mode 100644 index 3479ed232..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/eventbus/CacheFieldEntityListenerTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.repository.jpa.eventbus; - -import static org.fest.assertions.api.Assertions.assertThat; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.eclipse.hawkbit.repository.jpa.cache.CacheField; -import org.eclipse.hawkbit.repository.jpa.cache.CacheKeys; -import org.eclipse.hawkbit.repository.jpa.model.CacheFieldEntityListener; -import org.eclipse.hawkbit.repository.jpa.model.helper.CacheManagerHolder; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.cache.support.SimpleValueWrapper; -import org.springframework.hateoas.Identifiable; - -import ru.yandex.qatools.allure.annotations.Features; -import ru.yandex.qatools.allure.annotations.Stories; - -@Features("Unit Tests - Repository") -@Stories("EventBus") -@RunWith(MockitoJUnitRunner.class) -public class CacheFieldEntityListenerTest { - - private static final String TEST_CACHE_FIELD = "testCacheField"; - - @Mock - private CacheManager cacheManagerMock; - - @Mock - private Cache cacheMock; - - private CacheFieldEntityListener underTest; - - @Before - public void before() { - // mock - when(cacheManagerMock.getCache(anyString())).thenReturn(cacheMock); - - underTest = new CacheFieldEntityListener(); - CacheManagerHolder.getInstance().setCacheManager(cacheManagerMock); - } - - @Test - public void postLoadSetsCacheFields() { - final String entityId = "123"; - final String normalFieldValue = "bumlux"; - final TestEntity testObject = new TestEntity(entityId, normalFieldValue); - final int expectedTestValue = -1; - - when(cacheMock.get(CacheKeys.entitySpecificCacheKey(entityId, TEST_CACHE_FIELD))) - .thenReturn(new SimpleValueWrapper(expectedTestValue)); - - // pre verify everything is ok - assertThat(testObject.getCacheField()).isNotEqualTo(expectedTestValue); - assertThat(testObject.getNormalField()).isEqualTo(normalFieldValue); - - // test - underTest.postLoad(testObject); - - assertThat(testObject.getNormalField()).isEqualTo(normalFieldValue); - // now cache value should be like the value in the mock of the cache - assertThat(testObject.getCacheField()).isEqualTo(expectedTestValue); - } - - @Test - public void postRemoveEvictsCacheField() { - final String entityId = "123"; - final String normalFieldValue = "bumlux"; - final TestEntity testObject = new TestEntity(entityId, normalFieldValue); - // test - underTest.postDelete(testObject); - - verify(cacheMock).evict(eq(CacheKeys.entitySpecificCacheKey(entityId, TEST_CACHE_FIELD))); - } - - private final class TestEntity implements Identifiable { - - private final String id; - - private final String normalField; - - @CacheField(key = TEST_CACHE_FIELD) - private int cacheField; - - private TestEntity(final String id, final String normalFieldValue) { - this.id = id; - this.normalField = normalFieldValue; - } - - /* - * (non-Javadoc) - * - * @see org.springframework.hateoas.Identifiable#getId() - */ - @Override - public String getId() { - return id; - } - - /** - * @return the normalField - */ - String getNormalField() { - return normalField; - } - - /** - * @return the cacheField - */ - int getCacheField() { - return cacheField; - } - } -} diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java index db5f04c8a..691a659c5 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLUtilityTest.java @@ -26,12 +26,13 @@ import org.eclipse.hawkbit.repository.FieldNameProvider; import org.eclipse.hawkbit.repository.SoftwareModuleFields; import org.eclipse.hawkbit.repository.TargetFields; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; +import org.eclipse.hawkbit.repository.TimestampCalculator; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException; -import org.eclipse.hawkbit.repository.jpa.TimestampCalculator; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; +import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolverTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolverTest.java index 473b2dc3a..87b2c9018 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolverTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/VirtualPropertyResolverTest.java @@ -18,8 +18,9 @@ import java.time.Instant; import org.apache.commons.lang3.text.StrSubstitutor; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.jpa.TimestampCalculator; +import org.eclipse.hawkbit.repository.TimestampCalculator; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; +import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.junit.Before; diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/application-test.properties b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/application-test.properties index ed93684d2..3a2f0baff 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/application-test.properties +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/application-test.properties @@ -7,6 +7,9 @@ # http://www.eclipse.org/legal/epl-v10.html # +logging.level.=INFO +logging.level.org.eclipse.persistence=ERROR + spring.data.mongodb.uri=mongodb://localhost/spArtifactRepository${random.value} spring.data.mongodb.port=28017 diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml b/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml deleted file mode 100644 index 2079a6964..000000000 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/resources/logback-spring.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-test/pom.xml b/hawkbit-repository/hawkbit-repository-test/pom.xml index 4a05735ac..09e86dff8 100644 --- a/hawkbit-repository/hawkbit-repository-test/pom.xml +++ b/hawkbit-repository/hawkbit-repository-test/pom.xml @@ -34,6 +34,10 @@ hawkbit-artifact-repository-mongo ${project.version} + + org.springframework.boot + spring-boot-starter-logging + org.springframework spring-context-support @@ -49,7 +53,6 @@ commons-io commons-io - 2.5 org.springframework.boot @@ -71,5 +74,21 @@ org.springframework.security spring-security-web + + org.springframework.cloud + spring-cloud-stream-binder-test + + + org.springframework.cloud + spring-cloud-stream-test-support + + + io.protostuff + protostuff-core + + + io.protostuff + protostuff-runtime + \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java index ac3ed6085..73f425971 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/TestConfiguration.java @@ -13,36 +13,44 @@ import java.util.concurrent.Executors; import org.eclipse.hawkbit.api.ArtifactUrlHandlerProperties; import org.eclipse.hawkbit.api.PropertyBasedArtifactUrlHandler; -import org.eclipse.hawkbit.cache.CacheConstants; -import org.eclipse.hawkbit.cache.TenancyCacheManager; +import org.eclipse.hawkbit.cache.DefaultDownloadIdCache; +import org.eclipse.hawkbit.cache.DownloadIdCache; import org.eclipse.hawkbit.cache.TenantAwareCacheManager; -import org.eclipse.hawkbit.repository.jpa.model.helper.EventBusHolder; -import org.eclipse.hawkbit.repository.jpa.rsql.VirtualPropertyResolver; +import org.eclipse.hawkbit.event.BusProtoStuffMessageConverter; +import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.model.helper.EventPublisherHolder; import org.eclipse.hawkbit.repository.rsql.VirtualPropertyReplacer; +import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver; import org.eclipse.hawkbit.repository.test.util.JpaTestRepositoryManagement; import org.eclipse.hawkbit.repository.test.util.TestRepositoryManagement; import org.eclipse.hawkbit.repository.test.util.TestdataFactory; import org.eclipse.hawkbit.security.DdiSecurityProperties; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SpringSecurityAuditorAware; +import org.eclipse.hawkbit.security.SystemSecurityContext; import org.eclipse.hawkbit.tenancy.TenantAware; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.aop.interceptor.SimpleAsyncUncaughtExceptionHandler; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cache.Cache; import org.springframework.cache.guava.GuavaCacheManager; +import org.springframework.cloud.bus.ConditionalOnBusEnabled; +import org.springframework.cloud.bus.ServiceMatcher; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AdviceMode; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; +import org.springframework.context.event.SimpleApplicationEventMulticaster; +import org.springframework.context.support.AbstractApplicationContext; import org.springframework.data.domain.AuditorAware; +import org.springframework.messaging.converter.MessageConverter; import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.util.AntPathMatcher; -import com.google.common.eventbus.AsyncEventBus; -import com.google.common.eventbus.EventBus; import com.mongodb.MongoClientOptions; /** @@ -59,8 +67,9 @@ import com.mongodb.MongoClientOptions; @EnableAutoConfiguration public class TestConfiguration implements AsyncConfigurer { @Bean - public TestRepositoryManagement testRepositoryManagement() { - return new JpaTestRepositoryManagement(); + public TestRepositoryManagement testRepositoryManagement(final SystemSecurityContext systemSecurityContext, + final SystemManagement systemManagement) { + return new JpaTestRepositoryManagement(cacheManager(), systemSecurityContext, systemManagement); } @Bean @@ -87,7 +96,7 @@ public class TestConfiguration implements AsyncConfigurer { } @Bean - public TenancyCacheManager cacheManager() { + public TenantAwareCacheManager cacheManager() { return new TenantAwareCacheManager(new GuavaCacheManager(), tenantAware()); } @@ -96,19 +105,21 @@ public class TestConfiguration implements AsyncConfigurer { * * @return the cache */ - @Bean(name = CacheConstants.DOWNLOAD_ID_CACHE) - public Cache downloadIdCache() { - return cacheManager().getDirectCache(CacheConstants.DOWNLOAD_ID_CACHE); + @Bean + public DownloadIdCache downloadIdCache() { + return new DefaultDownloadIdCache(cacheManager()); + } + + @Bean(name = AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME) + public SimpleApplicationEventMulticaster applicationEventMulticaster() { + final SimpleApplicationEventMulticaster simpleApplicationEventMulticaster = new SimpleApplicationEventMulticaster(); + simpleApplicationEventMulticaster.setTaskExecutor(asyncExecutor()); + return simpleApplicationEventMulticaster; } @Bean - public EventBus eventBus() { - return new AsyncEventBus(asyncExecutor()); - } - - @Bean - public EventBusHolder eventBusHolder() { - return EventBusHolder.getInstance(); + public EventPublisherHolder eventBusHolder() { + return EventPublisherHolder.getInstance(); } @Bean @@ -140,4 +151,23 @@ public class TestConfiguration implements AsyncConfigurer { return new VirtualPropertyResolver(); } + @Bean + @ConditionalOnMissingBean + public ServiceMatcher serviceMatcher(final ApplicationContext applicationContext) { + final ServiceMatcher serviceMatcher = new ServiceMatcher(); + serviceMatcher.setMatcher(new AntPathMatcher(":")); + serviceMatcher.setApplicationContext(applicationContext); + return serviceMatcher; + } + + /** + * + * @return the protostuff io message converter + */ + @Bean + @ConditionalOnBusEnabled + public MessageConverter busProtoBufConverter() { + return new BusProtoStuffMessageConverter(); + } + } diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java index 8f3becc4c..d945e779f 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/AbstractIntegrationTest.java @@ -44,6 +44,8 @@ import org.junit.runners.model.FrameworkMethod; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.cloud.bus.ServiceMatcher; +import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.Environment; import org.springframework.data.auditing.AuditingHandler; @@ -51,6 +53,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.gridfs.GridFsOperations; +import org.springframework.hateoas.MediaTypes; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ActiveProfiles; @@ -68,7 +71,7 @@ import de.flapdoodle.embed.mongo.MongodExecutable; @WebAppConfiguration @ActiveProfiles({ "test" }) @WithUser(principal = "bumlux", allSpPermissions = true, authorities = { CONTROLLER_ROLE, SYSTEM_ROLE }) -@SpringApplicationConfiguration(classes = { TestConfiguration.class }) +@SpringApplicationConfiguration(classes = { TestConfiguration.class, TestSupportBinderAutoConfiguration.class }) // destroy the context after each test class because otherwise we get problem // when context is // refreshed we e.g. get two instances of CacheManager which leads to very @@ -80,6 +83,12 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { protected static final Pageable pageReq = new PageRequest(0, 400); + /** + * Constant for MediaType HAL with encoding UTF-8. Necessary since Spring + * version 4.3.2 @see https://jira.spring.io/browse/SPR-14577 + */ + protected static final String APPLICATION_JSON_HAL_UTF = MediaTypes.HAL_JSON + ";charset=UTF-8"; + /** * Number of {@link DistributionSetType}s that exist in every test case. One * generated by using @@ -162,6 +171,9 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware { @Autowired protected MongodExecutable mongodExecutable; + @Autowired + protected ServiceMatcher serviceMatcher; + @Rule public final WithSpringAuthorityRule securityRule = new WithSpringAuthorityRule(); diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/JpaTestRepositoryManagement.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/JpaTestRepositoryManagement.java index 7d7908d6e..b4e3b49dd 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/JpaTestRepositoryManagement.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/JpaTestRepositoryManagement.java @@ -15,20 +15,34 @@ import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.security.SystemSecurityContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; public class JpaTestRepositoryManagement implements TestRepositoryManagement { private static final Logger LOGGER = LoggerFactory.getLogger(JpaTestRepositoryManagement.class); - @Autowired - private TenantAwareCacheManager cacheManager; - @Autowired - private SystemSecurityContext systemSecurityContext; + private final TenantAwareCacheManager cacheManager; - @Autowired - private SystemManagement systemManagement; + private final SystemSecurityContext systemSecurityContext; + + private final SystemManagement systemManagement; + + /** + * Constructor. + * + * @param cacheManager + * the cachemanager + * @param systemSecurityContext + * the systemSecurityContext + * @param systemManagement + * the systemManagement + */ + public JpaTestRepositoryManagement(final TenantAwareCacheManager cacheManager, + final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement) { + this.cacheManager = cacheManager; + this.systemSecurityContext = systemSecurityContext; + this.systemManagement = systemManagement; + } @Override @Transactional diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/WithSpringAuthorityRule.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/WithSpringAuthorityRule.java index 8324d1d56..909012d25 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/WithSpringAuthorityRule.java +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/util/WithSpringAuthorityRule.java @@ -18,7 +18,7 @@ import java.util.concurrent.Callable; import org.eclipse.hawkbit.im.authentication.SpPermission; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; import org.eclipse.hawkbit.im.authentication.UserPrincipal; -import org.eclipse.hawkbit.repository.jpa.model.helper.SystemManagementHolder; +import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; diff --git a/hawkbit-security-core/pom.xml b/hawkbit-security-core/pom.xml index a9b2347b6..8a3107971 100644 --- a/hawkbit-security-core/pom.xml +++ b/hawkbit-security-core/pom.xml @@ -37,7 +37,6 @@ org.apache.commons commons-lang3 - ${commons-lang3.version} com.google.guava diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/DispatcherRunnable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/DispatcherRunnable.java index 69620347a..c15350bed 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/DispatcherRunnable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/DispatcherRunnable.java @@ -8,7 +8,7 @@ */ package org.eclipse.hawkbit.ui; -import org.eclipse.hawkbit.eventbus.event.Event; +import org.eclipse.hawkbit.repository.event.TenantAwareEvent; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.vaadin.spring.events.EventBus; @@ -28,7 +28,7 @@ import com.vaadin.util.CurrentInstance; public class DispatcherRunnable implements Runnable { private final SecurityContext userContext; - private final Event event; + private final TenantAwareEvent event; private final VaadinSession session; private final EventBus eventBus; @@ -44,7 +44,7 @@ public class DispatcherRunnable implements Runnable { * the event which is distributed to the UI. */ public DispatcherRunnable(final EventBus eventBus, final VaadinSession session, final SecurityContext userContext, - final Event event) { + final TenantAwareEvent event) { this.eventBus = eventBus; this.session = session; this.userContext = userContext; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java index 9768c2390..d0f7d4538 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/HawkbitUI.java @@ -61,6 +61,8 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { private transient EventPushStrategy pushStrategy; + protected transient EventBus.SessionEventBus eventBus; + @Autowired private SpringViewProvider viewProvider; @@ -78,23 +80,23 @@ public class HawkbitUI extends DefaultHawkbitUI implements DetachListener { @Autowired private ErrorView errorview; - @Autowired - protected transient EventBus.SessionEventBus eventBus; - /** * Default constructor. */ - public HawkbitUI() { - // is empty, is ok. + @Autowired + public HawkbitUI(final EventBus.SessionEventBus eventBus) { + this.eventBus = eventBus; } /** * Constructor taking the push strategy. - * + * * @param pushStrategy * the strategy to push events from the backend to the UI */ - public HawkbitUI(final EventPushStrategy pushStrategy) { + @Autowired + public HawkbitUI(final EventPushStrategy pushStrategy, final EventBus.SessionEventBus eventBus) { + this(eventBus); this.pushStrategy = pushStrategy; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java index 95770cb8f..08f1f8aec 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleEvent.java @@ -9,14 +9,14 @@ package org.eclipse.hawkbit.ui.artifacts.event; import org.eclipse.hawkbit.repository.model.SoftwareModule; -import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; +import org.eclipse.hawkbit.ui.common.table.BaseUIEntityEvent; /** - * Event to represent software add, update or delete. + * TenantAwareEvent to represent software add, update or delete. * */ -public class SoftwareModuleEvent extends BaseEntityEvent { +public class SoftwareModuleEvent extends BaseUIEntityEvent { /** * Software module events in the Upload UI. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleTypeEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleTypeEvent.java index 7262aee72..aedb8830b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleTypeEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/SoftwareModuleTypeEvent.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.artifacts.event; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; /** - * Event to represent software module type add, update or delete. + * TenantAwareEvent to represent software module type add, update or delete. */ public class SoftwareModuleTypeEvent { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java index e1fe4e07f..f96db0082 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadArtifactUIEvent.java @@ -9,7 +9,7 @@ package org.eclipse.hawkbit.ui.artifacts.event; /** - * Event generated in Upload artifact UI. + * TenantAwareEvent generated in Upload artifact UI. * * * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java index 90ad5c0f0..5d432ff04 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java @@ -21,7 +21,7 @@ public class UploadFileStatus implements Serializable { private static final long serialVersionUID = -3599629192216760811L; - private String fileName; + private final String fileName; private long contentLength; @@ -30,19 +30,48 @@ public class UploadFileStatus implements Serializable { private String failureReason; private SoftwareModule softwareModule; - - public UploadFileStatus(String fileName) { + + /** + * constructor for UploadFileStatus + * + * @param fileName + * name of the file to be uploaded + */ + public UploadFileStatus(final String fileName) { this.fileName = fileName; } - public UploadFileStatus(String fileName, long bytesRead, long contentLength,SoftwareModule softwareModule) { + /** + * constructor for UploadFileStatus + * + * @param fileName + * name of the file to be uploaded + * @param bytesRead + * number of bytes + * @param contentLength + * length of the content (stream) + * @param softwareModule + * softwareModule + */ + public UploadFileStatus(final String fileName, final long bytesRead, final long contentLength, + final SoftwareModule softwareModule) { this.fileName = fileName; this.contentLength = contentLength; this.bytesRead = bytesRead; this.softwareModule = softwareModule; } - public UploadFileStatus(String fileName, String failureReason,SoftwareModule selectedSw) { + /** + * constructor for UploadFileStatus + * + * @param fileName + * name of the file to be uploaded + * @param failureReason + * reason of failure + * @param selectedSw + * the selected softwareModule + */ + public UploadFileStatus(final String fileName, final String failureReason, final SoftwareModule selectedSw) { this.failureReason = failureReason; this.fileName = fileName; this.softwareModule = selectedSw; @@ -63,7 +92,7 @@ public class UploadFileStatus implements Serializable { public String getFailureReason() { return failureReason; } - + public SoftwareModule getSoftwareModule() { return softwareModule; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java index 4a8d0a747..2eaa5fd6b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadStatusEvent.java @@ -16,7 +16,7 @@ package org.eclipse.hawkbit.ui.artifacts.event; public class UploadStatusEvent { /** - * Event type definition of events during the artifact upload life-cycle + * TenantAwareEvent type definition of events during the artifact upload life-cycle * from receiving the upload until the process end. */ public enum UploadStatusEventType { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java index 6f5735b0a..83674c4ef 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadConfirmationWindow.java @@ -94,7 +94,7 @@ public class UploadConfirmationWindow implements Button.ClickListener { private final I18N i18n; - private Window uploadConfrimationWindow; + private Window window; private Button uploadBtn; @@ -133,7 +133,7 @@ public class UploadConfirmationWindow implements Button.ClickListener { buildLayout(); } - private Boolean checkIfArtifactDetailsDispalyed(final Long bSoftwareModuleId) { + private Boolean checkIfArtifactDetailsDisplayed(final Long bSoftwareModuleId) { if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent() && artifactUploadState.getSelectedBaseSoftwareModule().get().getId().equals(bSoftwareModuleId)) { return true; @@ -503,15 +503,15 @@ public class UploadConfirmationWindow implements Button.ClickListener { uploadArtifactDetails.addComponent(footer); uploadArtifactDetails.setComponentAlignment(footer, Alignment.MIDDLE_CENTER); - uploadConfrimationWindow = new Window(); - uploadConfrimationWindow.setContent(uploadArtifactDetails); - uploadConfrimationWindow.setResizable(Boolean.FALSE); - uploadConfrimationWindow.setClosable(Boolean.TRUE); - uploadConfrimationWindow.setDraggable(Boolean.TRUE); - uploadConfrimationWindow.setModal(true); - uploadConfrimationWindow.addCloseListener(event -> onPopupClose()); - uploadConfrimationWindow.setCaption(i18n.get("header.caption.upload.details")); - uploadConfrimationWindow.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION); + window = new Window(); + window.setContent(uploadArtifactDetails); + window.setResizable(Boolean.FALSE); + window.setClosable(Boolean.TRUE); + window.setDraggable(Boolean.TRUE); + window.setModal(true); + window.addCloseListener(event -> onPopupClose()); + window.setCaption(i18n.get("header.caption.upload.details")); + window.addStyleName(SPUIStyleDefinitions.CONFIRMATION_WINDOW_CAPTION); } private void onPopupClose() { @@ -531,16 +531,16 @@ public class UploadConfirmationWindow implements Button.ClickListener { } public Window getUploadConfrimationWindow() { - return uploadConfrimationWindow; + return window; } @Override public void buttonClick(final ClickEvent event) { if (event.getComponent().getId().equals(UIComponentIdProvider.UPLOAD_ARTIFACT_DETAILS_CLOSE)) { - uploadConfrimationWindow.close(); + window.close(); } else if (event.getComponent().getId().equals(UIComponentIdProvider.UPLOAD_DISCARD_DETAILS_BUTTON)) { uploadLayout.clearUploadedFileDetails(); - uploadConfrimationWindow.close(); + window.close(); } else if (event.getComponent().getId().equals(UIComponentIdProvider.UPLOAD_BUTTON)) { processArtifactUpload(); } else if (event.getComponent().getId().startsWith(UIComponentIdProvider.UPLOAD_DELETE_ICON)) { @@ -563,7 +563,7 @@ public class UploadConfirmationWindow implements Button.ClickListener { uploadLayout.getFileSelected().remove(customFile); uploadLayout.updateUploadCounts(); if (uploadDetailsTable.getItemIds().isEmpty()) { - uploadConfrimationWindow.close(); + window.close(); uploadLayout.clearUploadedFileDetails(); } @@ -593,14 +593,14 @@ public class UploadConfirmationWindow implements Button.ClickListener { createArtifact(itemId, customFile.getFilePath(), artifactManagement, bSoftwareModule); } } - refreshArtifactDetailsLayout = checkIfArtifactDetailsDispalyed(bSoftwareModule.getId()); + refreshArtifactDetailsLayout = checkIfArtifactDetailsDisplayed(bSoftwareModule.getId()); } if (refreshArtifactDetailsLayout) { uploadLayout.refreshArtifactDetailsLayout(artifactUploadState.getSelectedBaseSoftwareModule().get()); } uploadLayout.clearFileList(); - uploadConfrimationWindow.close(); + window.close(); // call upload result window currentUploadResultWindow = new UploadResultWindow(uploadResultList, i18n); UI.getCurrent().addWindow(currentUploadResultWindow.getUploadResultsWindow()); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractAcceptCriteria.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractAcceptCriteria.java index 2fa2900d5..a5f2e195a 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractAcceptCriteria.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/AbstractAcceptCriteria.java @@ -56,7 +56,7 @@ public abstract class AbstractAcceptCriteria extends ServerSideCriterion { return true; } else { // Display action not allowed notification for invalid drop - /* mouse event will be Event.ONMOUSEUP on drop */ + /* mouse event will be TenantAwareEvent.ONMOUSEUP on drop */ // From com.google.gwt.user.client.Event if (typeVal == 8) { invalidDrop(); @@ -82,7 +82,7 @@ public abstract class AbstractAcceptCriteria extends ServerSideCriterion { private void showHideDropAreaHighlights(final int typeVal, final Component compsource, final DragAndDropEvent dragEvent) { - /* mouse event will be Event.ONMOUSEUP on drop */ + /* mouse event will be TenantAwareEvent.ONMOUSEUP on drop */ // From com.google.gwt.user.client.Event if (typeVal == 8) { hideDropHints(); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ConfirmationDialog.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ConfirmationDialog.java index 7de439722..652a1e526 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ConfirmationDialog.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/ConfirmationDialog.java @@ -120,7 +120,7 @@ public class ConfirmationDialog implements Button.ClickListener { } /** - * Event handler for button clicks. + * TenantAwareEvent handler for button clicks. * * @param event * the click event. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java index 2b1aad837..7884a9ad6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/detailslayout/AbstractTableDetailsLayout.java @@ -18,8 +18,8 @@ import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.ui.common.builder.LabelBuilder; -import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; +import org.eclipse.hawkbit.ui.common.table.BaseUIEntityEvent; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -117,7 +117,7 @@ public abstract class AbstractTableDetailsLayout extends * @param baseEntityEvent * the event */ - protected void onBaseEntityEvent(final BaseEntityEvent baseEntityEvent) { + protected void onBaseEntityEvent(final BaseUIEntityEvent baseEntityEvent) { final BaseEntityEventType eventType = baseEntityEvent.getEventType(); if (BaseEntityEventType.SELECTED_ENTITY == eventType || BaseEntityEventType.UPDATED_ENTITY == eventType) { UI.getCurrent().access(() -> populateData(baseEntityEvent.getEntity())); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index 257832a8f..90e9c3027 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -247,7 +247,7 @@ public abstract class AbstractTable extends Table { } - protected void onBaseEntityEvent(final BaseEntityEvent event) { + protected void onBaseEntityEvent(final BaseUIEntityEvent event) { if (BaseEntityEventType.MINIMIZED == event.getEventType()) { UI.getCurrent().access(() -> applyMinTableSettings()); } else if (BaseEntityEventType.MAXIMIZED == event.getEventType()) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseUIEntityEvent.java similarity index 82% rename from hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java rename to hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseUIEntityEvent.java index b0b7551ac..e090d23d2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseEntityEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/BaseUIEntityEvent.java @@ -11,10 +11,10 @@ package org.eclipse.hawkbit.ui.common.table; import org.eclipse.hawkbit.repository.model.BaseEntity; /** - * Event to represent add, update or delete. + * TenantAwareEvent to represent add, update or delete. * */ -public class BaseEntityEvent { +public class BaseUIEntityEvent { private final BaseEntityEventType eventType; @@ -28,7 +28,7 @@ public class BaseEntityEvent { * @param entity * the entity reference */ - public BaseEntityEvent(final BaseEntityEventType eventType, final T entity) { + public BaseUIEntityEvent(final BaseEntityEventType eventType, final T entity) { this.eventType = eventType; this.entity = entity; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java index 8a9260ee1..8dea84450 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTagToken.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.common.tagdetails; import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import javax.annotation.PostConstruct; @@ -19,8 +18,8 @@ import javax.annotation.PreDestroy; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.model.BaseEntity; -import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; +import org.eclipse.hawkbit.ui.common.table.BaseUIEntityEvent; import org.eclipse.hawkbit.ui.management.state.ManagementUIState; import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.SPUIDefinitions; @@ -98,7 +97,7 @@ public abstract class AbstractTagToken implements Serializ eventBus.unsubscribe(this); } - protected void onBaseEntityEvent(final BaseEntityEvent baseEntityEvent) { + protected void onBaseEntityEvent(final BaseUIEntityEvent baseEntityEvent) { if (BaseEntityEventType.SELECTED_ENTITY != baseEntityEvent.getEventType()) { return; } @@ -260,13 +259,10 @@ public abstract class AbstractTagToken implements Serializ tokensAdded.keySet().forEach(previouslyAddedToken -> tokenField.removeToken(previouslyAddedToken)); } - protected Long getTagIdByTagName(final String tagName) { - final Optional> mapEntry = tagDetails.entrySet().stream() - .filter(entry -> entry.getValue().getName().equals(tagName)).findFirst(); - if (mapEntry.isPresent()) { - return mapEntry.get().getKey(); - } - return null; + protected Long getTagIdByTagName(final Long tagId) { + return tagDetails.entrySet().stream().filter(entry -> entry.getValue().getId().equals(tagId)).findFirst() + .map(entry -> entry.getKey()).orElse(null); + } protected void removeTokenItem(final Long tokenId, final String name) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java index e72d066e4..d645bb000 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/AbstractTargetTagToken.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.common.tagdetails; import java.util.List; import org.eclipse.hawkbit.repository.TagManagement; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; import org.eclipse.hawkbit.repository.model.BaseEntity; import org.eclipse.hawkbit.ui.push.TargetTagCreatedEventContainer; import org.eclipse.hawkbit.ui.push.TargetTagDeletedEventContainer; @@ -42,7 +42,7 @@ public abstract class AbstractTargetTagToken extends Abstr @EventBusListenerMethod(scope = EventScope.SESSION) void onTargetTagDeletedEvent(final TargetTagDeletedEventContainer container) { - container.getEvents().stream().map(event -> getTagIdByTagName(event.getEntity().getName())) + container.getEvents().stream().map(event -> getTagIdByTagName(event.getEntityId())) .forEach(this::removeTagFromCombo); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java index 8a27eed03..50153a27d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/DistributionTagToken.java @@ -18,7 +18,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSetTag; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; -import org.eclipse.hawkbit.ui.push.DistributionSetTagAssignmentResultEventContainer; import org.eclipse.hawkbit.ui.push.DistributionSetTagCreatedEventContainer; import org.eclipse.hawkbit.ui.push.DistributionSetTagDeletedEventContainer; import org.eclipse.hawkbit.ui.push.DistributionSetTagUpdatedEventContainer; @@ -75,6 +74,7 @@ public class DistributionTagToken extends AbstractTagToken { private DistributionSetTagAssignmentResult toggleAssignment(final String tagNameSelected) { final DistributionSetTagAssignmentResult result = distributionSetManagement .toggleTagAssignment(Sets.newHashSet(selectedEntity.getId()), tagNameSelected); + processTargetTagAssigmentResult(result); uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; } @@ -125,7 +125,7 @@ public class DistributionTagToken extends AbstractTagToken { @EventBusListenerMethod(scope = EventScope.SESSION) void onDistributionSetTagDeletedEvent(final DistributionSetTagDeletedEventContainer eventContainer) { - eventContainer.getEvents().stream().map(event -> getTagIdByTagName(event.getEntity().getName())) + eventContainer.getEvents().stream().map(event -> getTagIdByTagName(event.getEntityId())) .forEach(this::removeTagFromCombo); } @@ -139,16 +139,13 @@ public class DistributionTagToken extends AbstractTagToken { }); } - @EventBusListenerMethod(scope = EventScope.SESSION) - void onTargetTagAssigmentResultEvent(final DistributionSetTagAssignmentResultEventContainer eventContainer) { - eventContainer.getEvents().stream().map(event -> event.getAssigmentResult()).forEach(assignmentResult -> { - final DistributionSetTag tag = assignmentResult.getDistributionSetTag(); - if (isAssign(assignmentResult)) { - addNewToken(tag.getId()); - } else if (isUnassign(assignmentResult)) { - removeTokenItem(tag.getId(), tag.getName()); - } - }); + private void processTargetTagAssigmentResult(final DistributionSetTagAssignmentResult assignmentResult) { + final DistributionSetTag tag = assignmentResult.getDistributionSetTag(); + if (isAssign(assignmentResult)) { + addNewToken(tag.getId()); + } else if (isUnassign(assignmentResult)) { + removeTokenItem(tag.getId(), tag.getName()); + } } protected boolean isAssign(final DistributionSetTagAssignmentResult assignmentResult) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java index 6df99e348..c72c3ff1b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/tagdetails/TargetTagToken.java @@ -17,7 +17,6 @@ import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTagAssignmentResult; import org.eclipse.hawkbit.ui.management.event.ManagementUIEvent; import org.eclipse.hawkbit.ui.management.event.TargetTableEvent; -import org.eclipse.hawkbit.ui.push.TargetTagAssigmentResultEventContainer; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; import org.springframework.beans.factory.annotation.Autowired; import org.vaadin.spring.events.EventScope; @@ -69,6 +68,7 @@ public class TargetTagToken extends AbstractTargetTagToken { final Set targetList = new HashSet<>(); targetList.add(selectedEntity.getControllerId()); final TargetTagAssignmentResult result = targetManagement.toggleTagAssignment(targetList, tagNameSelected); + processTargetTagAssigmentResult(result); uinotification.displaySuccess(HawkbitCommonUtil.createAssignmentMessage(tagNameSelected, result, i18n)); return result; } @@ -105,17 +105,17 @@ public class TargetTagToken extends AbstractTargetTagToken { } } - @EventBusListenerMethod(scope = EventScope.SESSION) - void onTargetTagAssigmentResultEvent(final TargetTagAssigmentResultEventContainer holder) { - holder.getEvents().stream().map(event -> event.getAssigmentResult()).forEach(assignmentResult -> { - final TargetTag targetTag = assignmentResult.getTargetTag(); - if (isAssign(assignmentResult)) { - addNewToken(targetTag.getId()); - } else if (isUnassign(assignmentResult)) { - removeTokenItem(targetTag.getId(), targetTag.getName()); - } - }); - + /** + * + * @param assignmentResult + */ + public void processTargetTagAssigmentResult(final TargetTagAssignmentResult assignmentResult) { + final TargetTag targetTag = assignmentResult.getTargetTag(); + if (isAssign(assignmentResult)) { + addNewToken(targetTag.getId()); + } else if (isUnassign(assignmentResult)) { + removeTokenItem(targetTag.getId(), targetTag.getName()); + } } protected boolean isAssign(final TargetTagAssignmentResult assignmentResult) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java index d9026d64b..1bd7c1368 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetDetails.java @@ -30,7 +30,6 @@ import org.eclipse.hawkbit.ui.common.tagdetails.DistributionTagToken; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.decorators.SPUIButtonStyleSmallNoBorder; import org.eclipse.hawkbit.ui.distributions.event.SaveActionWindowEvent; -import org.eclipse.hawkbit.ui.distributions.event.SoftwareModuleAssignmentDiscardEvent; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.management.dstable.DistributionAddUpdateWindowLayout; import org.eclipse.hawkbit.ui.management.event.DistributionTableEvent; @@ -365,22 +364,6 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet onBaseEntityEvent(distributionTableEvent); } - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final SoftwareModuleAssignmentDiscardEvent softwareModuleAssignmentDiscardEvent) { - if (softwareModuleAssignmentDiscardEvent.getDistributionSetIdName() != null) { - UI.getCurrent().access(() -> { - final DistributionSetIdName distIdName = softwareModuleAssignmentDiscardEvent - .getDistributionSetIdName(); - if (distIdName.getId().equals(getSelectedBaseEntityId()) - && distIdName.getName().equals(getSelectedBaseEntity().getName())) { - setSelectedBaseEntity( - distributionSetManagement.findDistributionSetByIdWithDetails(getSelectedBaseEntityId())); - populateModule(); - } - }); - } - } - @EventBusListenerMethod(scope = EventScope.SESSION) void onEvent(final SaveActionWindowEvent saveActionWindowEvent) { if ((saveActionWindowEvent == SaveActionWindowEvent.SAVED_ASSIGNMENTS @@ -422,13 +405,6 @@ public class DistributionSetDetails extends AbstractNamedVersionedEntityTableDet return true; } - private boolean isDistributionSetSelected(final DistributionSet ds) { - final DistributionSetIdName lastselectedDistDS = manageDistUIState.getLastSelectedDistribution().isPresent() - ? manageDistUIState.getLastSelectedDistribution().get() : null; - return ds != null && lastselectedDistDS != null && lastselectedDistDS.getName().equals(ds.getName()) - && lastselectedDistDS.getVersion().endsWith(ds.getVersion()); - } - @Override protected void showMetadata(final ClickEvent event) { final DistributionSet ds = distributionSetManagement diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java index 3b9f6cfcb..51bc1caf4 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/dstable/DistributionSetTable.java @@ -21,8 +21,8 @@ import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SoftwareManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleIdName; @@ -160,8 +160,8 @@ public class DistributionSetTable extends AbstractNamedVersionTable visibleItemIds = (List) getVisibleItemIds(); boolean shouldRefreshDs = false; - for (final DistributionDeletedEvent deletedEvent : eventContainer.getEvents()) { - final Long distributionSetId = deletedEvent.getDistributionSetId(); + for (final DistributionSetDeletedEvent deletedEvent : eventContainer.getEvents()) { + final Long distributionSetId = deletedEvent.getEntityId(); final DistributionSetIdName targetIdName = new DistributionSetIdName(distributionSetId, null, null); if (visibleItemIds.contains(targetIdName)) { dsContainer.removeItem(targetIdName); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/event/SoftwareModuleAssignmentDiscardEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/event/SoftwareModuleAssignmentDiscardEvent.java deleted file mode 100644 index c2365fa07..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/distributions/event/SoftwareModuleAssignmentDiscardEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.distributions.event; - -import org.eclipse.hawkbit.ui.common.DistributionSetIdName; - -/** - * Event fired on discard of software module assignment. - * - * - * - * - */ -public class SoftwareModuleAssignmentDiscardEvent { - - private DistributionSetIdName distributionSetIdName; - - /** - * - * @param distributionSetIdName. - */ - public SoftwareModuleAssignmentDiscardEvent(final DistributionSetIdName distributionSetIdName) { - this.distributionSetIdName = distributionSetIdName; - } - - public DistributionSetIdName getDistributionSetIdName() { - return distributionSetIdName; - } - - public void setDistributionSetIdName(final DistributionSetIdName distributionSetIdName) { - this.distributionSetIdName = distributionSetIdName; - } - -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectTable.java index 82d41a616..efa591579 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/DistributionSetSelectTable.java @@ -16,8 +16,8 @@ import java.util.Map; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; import org.eclipse.hawkbit.ui.distributions.dstable.ManageDistBeanQuery; import org.eclipse.hawkbit.ui.distributions.state.ManageDistUIState; import org.eclipse.hawkbit.ui.utils.I18N; @@ -86,8 +86,8 @@ public class DistributionSetSelectTable extends Table { @EventBusListenerMethod(scope = EventScope.SESSION) void onEvents(final List events) { final Object firstEvent = events.get(0); - if (DistributionCreatedEvent.class.isInstance(firstEvent) - || DistributionDeletedEvent.class.isInstance(firstEvent)) { + if (DistributionSetCreatedEvent.class.isInstance(firstEvent) + || DistributionSetDeletedEvent.class.isInstance(firstEvent)) { refreshDistributions(); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java index 40130492f..8dc037449 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/filtermanagement/TargetFilterTable.java @@ -77,9 +77,6 @@ public class TargetFilterTable extends Table { @Autowired private transient TargetFilterQueryManagement targetFilterQueryManagement; - @Autowired - private transient DistributionSetManagement distributionSetManagement; - @Autowired private DistributionSetSelectWindow dsSelectWindow; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java index bdb92bfc7..fe57dc415 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/dstable/DistributionTable.java @@ -20,8 +20,8 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetTagAssignmentResult; import org.eclipse.hawkbit.repository.model.Target; @@ -127,8 +127,8 @@ public class DistributionTable extends AbstractNamedVersionTable visibleItemIds = (List) getVisibleItemIds(); boolean shouldRefreshDs = false; - for (final DistributionDeletedEvent deletedEvent : eventContainer.getEvents()) { - final Long distributionSetId = deletedEvent.getDistributionSetId(); + for (final DistributionSetDeletedEvent deletedEvent : eventContainer.getEvents()) { + final Long distributionSetId = deletedEvent.getEntityId(); final DistributionSetIdName targetIdName = new DistributionSetIdName(distributionSetId, null, null); if (visibleItemIds.contains(targetIdName)) { dsContainer.removeItem(targetIdName); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java index c35942682..e94c0a585 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/DistributionTableEvent.java @@ -9,14 +9,14 @@ package org.eclipse.hawkbit.ui.management.event; import org.eclipse.hawkbit.repository.model.DistributionSet; -import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; +import org.eclipse.hawkbit.ui.common.table.BaseUIEntityEvent; /** - * Class which contains the Event when selecting all entries of the + * Class which contains the TenantAwareEvent when selecting all entries of the * distributions table */ -public class DistributionTableEvent extends BaseEntityEvent { +public class DistributionTableEvent extends BaseUIEntityEvent { /** * Constructor. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java index cf2661c60..50e870bd2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetAddUpdateWindowEvent.java @@ -9,8 +9,8 @@ package org.eclipse.hawkbit.ui.management.event; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; +import org.eclipse.hawkbit.ui.common.table.BaseUIEntityEvent; /** * @@ -18,7 +18,7 @@ import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; * * */ -public class TargetAddUpdateWindowEvent extends BaseEntityEvent { +public class TargetAddUpdateWindowEvent extends BaseUIEntityEvent { /** * Constructor. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java index 214d12106..33de6e8ea 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/event/TargetTableEvent.java @@ -9,13 +9,13 @@ package org.eclipse.hawkbit.ui.management.event; import org.eclipse.hawkbit.repository.model.Target; -import org.eclipse.hawkbit.ui.common.table.BaseEntityEvent; import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType; +import org.eclipse.hawkbit.ui.common.table.BaseUIEntityEvent; /** - * Class which contains the Event when selecting all entries of the target table + * Class which contains the TenantAwareEvent when selecting all entries of the target table */ -public class TargetTableEvent extends BaseEntityEvent { +public class TargetTableEvent extends BaseUIEntityEvent { /** * Target table components events. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java index 15bdbb030..6d5cb8d13 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/CountMessageLabel.java @@ -80,7 +80,7 @@ public class CountMessageLabel extends Label { } /** - * Event Listener to show the message count. + * TenantAwareEvent Listener to show the message count. * * @param event */ @@ -102,7 +102,7 @@ public class CountMessageLabel extends Label { } /** - * Event Listener for Pinning Distribution. + * TenantAwareEvent Listener for Pinning Distribution. * * @param event */ diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java index c50e0d254..11a786c72 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/footer/ManangementConfirmationWindowLayout.java @@ -19,10 +19,10 @@ import java.util.Set; import java.util.stream.Collectors; import org.eclipse.hawkbit.repository.DeploymentManagement; -import org.eclipse.hawkbit.repository.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.model.Action.ActionType; +import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult; import org.eclipse.hawkbit.repository.model.RepositoryModelConstants; import org.eclipse.hawkbit.repository.model.TargetIdName; import org.eclipse.hawkbit.ui.common.DistributionSetIdName; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java index 9daef0cd9..238a9e709 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/management/targettable/TargetTable.java @@ -30,8 +30,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.eclipse.hawkbit.repository.FilterParams; import org.eclipse.hawkbit.repository.SpPermissionChecker; import org.eclipse.hawkbit.repository.TargetManagement; -import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent; import org.eclipse.hawkbit.repository.model.NamedEntity; import org.eclipse.hawkbit.repository.model.Target; import org.eclipse.hawkbit.repository.model.TargetIdName; @@ -57,7 +56,6 @@ import org.eclipse.hawkbit.ui.management.state.TargetTableFilters; import org.eclipse.hawkbit.ui.push.CancelTargetAssignmentEventContainer; import org.eclipse.hawkbit.ui.push.TargetCreatedEventContainer; import org.eclipse.hawkbit.ui.push.TargetDeletedEventContainer; -import org.eclipse.hawkbit.ui.push.TargetInfoUpdateEventContainer; import org.eclipse.hawkbit.ui.push.TargetUpdatedEventContainer; import org.eclipse.hawkbit.ui.utils.AssignInstalledDSTooltipGenerator; import org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil; @@ -134,7 +132,7 @@ public class TargetTable extends AbstractTable { final List visibleItemIds = (List) getVisibleItemIds(); boolean shouldRefreshTargets = false; for (final TargetDeletedEvent deletedEvent : eventContainer.getEvents()) { - final TargetIdName targetIdName = new TargetIdName(deletedEvent.getTargetId(), null, null); + final TargetIdName targetIdName = new TargetIdName(deletedEvent.getEntityId(), null, null); if (visibleItemIds.contains(targetIdName)) { targetContainer.removeItem(targetIdName); } else { @@ -157,30 +155,11 @@ public class TargetTable extends AbstractTable { // history, re-select // the updated target so the action history gets // refreshed. - reselectTargetIfSelectedInStream(eventContainer.getEvents().stream().map(event -> event.getTarget())); + reselectTargetIfSelectedInStream(eventContainer.getEvents().stream().map(event -> event.getEntity())); } @EventBusListenerMethod(scope = EventScope.SESSION) void onTargetUpdatedEvents(final TargetUpdatedEventContainer eventContainer) { - onTargetUpdateEvents(eventContainer.getEvents().stream() - .map(targetInfoUpdateEvent -> targetInfoUpdateEvent.getEntity()).collect(Collectors.toList())); - } - - @EventBusListenerMethod(scope = EventScope.SESSION) - void onTargetInfoUpdateEvents(final TargetInfoUpdateEventContainer eventContainer) { - onTargetUpdateEvents(eventContainer.getEvents().stream() - .map(targetInfoUpdateEvent -> targetInfoUpdateEvent.getEntity().getTarget()) - .collect(Collectors.toList())); - } - - /** - * EventListener method which is called by the event bus to notify about a - * list of {@link TargetInfoUpdateEvent}. - * - * @param updatedTargets - * list of updated targets - */ - private void onTargetUpdateEvents(final List updatedTargets) { final LazyQueryContainer targetContainer = (LazyQueryContainer) getContainerDataSource(); @SuppressWarnings("unchecked") final List visibleItemIds = (List) getVisibleItemIds(); @@ -188,7 +167,8 @@ public class TargetTable extends AbstractTable { if (isFilterEnabled()) { refreshTargets(); } else { - updatedTargets.stream().filter(target -> visibleItemIds.contains(target.getTargetIdName())) + eventContainer.getEvents().stream().map(event -> event.getEntity()) + .filter(target -> visibleItemIds.contains(target.getTargetIdName())) .forEach(target -> updateVisibleItemOnEvent(target.getTargetInfo())); targetContainer.commit(); } @@ -197,7 +177,7 @@ public class TargetTable extends AbstractTable { // history, re-select // the updated target so the action history gets // refreshed. - reselectTargetIfSelectedInStream(updatedTargets.stream()); + reselectTargetIfSelectedInStream(eventContainer.getEvents().stream().map(event -> event.getEntity())); } private void reselectTargetIfSelectedInStream(final Stream targets) { @@ -881,8 +861,8 @@ public class TargetTable extends AbstractTable { } } - private long getTargetsCountWithFilter(final long totalTargetsCount, - final Long pinnedDistId, final FilterParams filterParams) { + private long getTargetsCountWithFilter(final long totalTargetsCount, final Long pinnedDistId, + final FilterParams filterParams) { final long size; if (managementUIState.getTargetTableFilters().getTargetFilterQuery().isPresent()) { size = targetManagement.countTargetByTargetFilterQuery( diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardEvent.java index b9d3d2eea..885098a6b 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardEvent.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/menu/DashboardEvent.java @@ -14,7 +14,7 @@ package org.eclipse.hawkbit.ui.menu; /* - * Event bus events used in Dashboard are listed here as inner classes. + * TenantAwareEvent bus events used in Dashboard are listed here as inner classes. */ /** * Containing all dashboard events. @@ -48,7 +48,7 @@ public final class DashboardEvent { } /** - * Event to indicate that the current shown view has been changed. + * TenantAwareEvent to indicate that the current shown view has been changed. * * * diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/CancelTargetAssignmentEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/CancelTargetAssignmentEventContainer.java index e7172d3d9..5109310ad 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/CancelTargetAssignmentEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/CancelTargetAssignmentEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; /** * EventHolder for {@link CancelTargetAssignmentEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java index 8bb875a3f..b87d18d67 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DelayedEventBusPushStrategy.java @@ -19,27 +19,37 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import org.eclipse.hawkbit.eventbus.event.EntityEvent; -import org.eclipse.hawkbit.eventbus.event.Event; import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails; +import org.eclipse.hawkbit.repository.event.TenantAwareEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.ActionCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.ActionUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.RolloutUpdatedEvent; +import org.eclipse.hawkbit.repository.model.Rollout; +import org.eclipse.hawkbit.repository.model.RolloutGroup; +import org.eclipse.hawkbit.ui.push.event.RolloutChangeEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangeEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.scheduling.annotation.Async; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.context.HttpSessionSecurityContextRepository; import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventBus.SessionEventBus; -import com.google.common.eventbus.AllowConcurrentEvents; -import com.google.common.eventbus.Subscribe; import com.vaadin.server.VaadinSession; import com.vaadin.server.VaadinSession.State; import com.vaadin.server.WrappedSession; import com.vaadin.ui.UI; /** - * A {@link EventPushStrategy} implementation which retrieves events from - * {@link com.google.common.eventbus.EventBus} and store them first in an queue + * An {@link EventPushStrategy} implementation which retrieves events from + * {@link com.google.common.eventbus.EventBus} and store them first in a queue * where they will dispatched every 2 seconds to the {@link EventBus} in a * Vaadin access thread {@link UI#access(Runnable)}. * @@ -52,66 +62,26 @@ import com.vaadin.ui.UI; * in the event and only forwards event from the right tenant to the UI. * */ -public class DelayedEventBusPushStrategy implements EventPushStrategy { +public class DelayedEventBusPushStrategy implements EventPushStrategy, ApplicationListener { private static final Logger LOG = LoggerFactory.getLogger(DelayedEventBusPushStrategy.class); private static final int BLOCK_SIZE = 10_000; - private final ScheduledExecutorService executorService; - private final BlockingDeque queue = new LinkedBlockingDeque<>(BLOCK_SIZE); - private final EventBus.SessionEventBus eventBus; - private final com.google.common.eventbus.EventBus systemEventBus; + private final BlockingDeque queue = new LinkedBlockingDeque<>( + BLOCK_SIZE); private int uiid = -1; + @Autowired + private ScheduledExecutorService executorService; + + @Autowired + private EventBus.SessionEventBus eventBus; + + @Autowired + private UIEventProvider eventProvider; private ScheduledFuture jobHandle; - private final UIEventProvider eventProvider; - - /** - * Constructor. - * - * @param executorService - * for scheduled execution of event forwarding to the UI - * @param eventBus - * the session event bus to where the events should be dispatched - * @param systemEventBus - * the system event bus where to retrieve the events from the - * back-end - * @param eventProvider - * for event delegation to UI - */ - public DelayedEventBusPushStrategy(final ScheduledExecutorService executorService, final SessionEventBus eventBus, - final com.google.common.eventbus.EventBus systemEventBus, final UIEventProvider eventProvider) { - this.executorService = executorService; - this.eventBus = eventBus; - this.systemEventBus = systemEventBus; - this.eventProvider = eventProvider; - } - - /** - * An {@link com.google.common.eventbus.EventBus} subscriber which - * subscribes {@link EntityEvent} from the repository to dispatch these - * events to the UI {@link SessionEventBus}. - * - * @param event - * the entity event which has been published from the repository - */ - @Subscribe - @AllowConcurrentEvents - public void dispatch(final Event event) { - // to dispatch too many events which are not interested on the UI - if (!isEventProvided(event)) { - LOG.trace("Event is not supported in the UI!!! Dropped event is {}", event); - return; - } - - if (!queue.offer(event)) { - LOG.trace("Deque limit is reached, cannot add more events for UI {}! Dropped event is {}", uiid, event); - return; - } - } - - private boolean isEventProvided(final Event event) { + private boolean isEventProvided(final org.eclipse.hawkbit.repository.event.TenantAwareEvent event) { return eventProvider.getEvents().containsKey(event.getClass()); } @@ -125,40 +95,15 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { jobHandle = executorService.scheduleWithFixedDelay(new DispatchRunnable(vaadinUI, vaadinUI.getSession()), 10_000, 1_000, TimeUnit.MILLISECONDS); - systemEventBus.register(this); } @Override public void clean() { LOG.info("Cleanup delayed event push strategy for UI", uiid); - systemEventBus.unregister(this); jobHandle.cancel(true); queue.clear(); } - /** - * Checks if the tenant within the event is equal with the current tenant in - * the context. - * - * @param userContext - * the security context of the current session - * @param event - * the event to dispatch to the UI - * @return {@code true} if the event can be dispatched to the UI otherwise - * {@code false} - */ - protected static boolean eventSecurityCheck(final SecurityContext userContext, final Event event) { - if (userContext == null || userContext.getAuthentication() == null) { - return false; - } - final Object tenantAuthenticationDetails = userContext.getAuthentication().getDetails(); - if (tenantAuthenticationDetails instanceof TenantAwareAuthenticationDetails) { - return ((TenantAwareAuthenticationDetails) tenantAuthenticationDetails).getTenant() - .equalsIgnoreCase(event.getTenant()); - } - return false; - } - private final class DispatchRunnable implements Runnable { private final UI vaadinUI; @@ -180,7 +125,12 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { return; } - final List events = new ArrayList<>(size); + final WrappedSession wrappedSession = vaadinSession.getSession(); + if (wrappedSession == null) { + return; + } + + final List events = new ArrayList<>(size); final int eventsSize = queue.drainTo(events); if (events.isEmpty()) { @@ -188,11 +138,6 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { return; } - final WrappedSession wrappedSession = vaadinSession.getSession(); - if (wrappedSession == null) { - return; - } - LOG.debug("UI EventBus aggregator dispatches {} events for session {} for UI {}", eventsSize, vaadinSession, vaadinUI.getUIId()); @@ -203,14 +148,41 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { } - private void doDispatch(final List events, final WrappedSession wrappedSession) { + /** + * Checks if the tenant within the event is equal with the current + * tenant in the context. + * + * @param userContext + * the security context of the current session + * @param event + * the event to dispatch to the UI + * @return {@code true} if the event can be dispatched to the UI + * otherwise {@code false} + */ + private boolean eventSecurityCheck(final SecurityContext userContext, + final org.eclipse.hawkbit.repository.event.TenantAwareEvent event) { + if (userContext == null || userContext.getAuthentication() == null) { + return false; + } + final Object tenantAuthenticationDetails = userContext.getAuthentication().getDetails(); + if (tenantAuthenticationDetails instanceof TenantAwareAuthenticationDetails) { + return ((TenantAwareAuthenticationDetails) tenantAuthenticationDetails).getTenant() + .equalsIgnoreCase(event.getTenant()); + } + return false; + } + + private void doDispatch(final List events, + final WrappedSession wrappedSession) { final SecurityContext userContext = (SecurityContext) wrappedSession .getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY); final SecurityContext oldContext = SecurityContextHolder.getContext(); try { SecurityContextHolder.setContext(userContext); - final List> groupedEvents = groupEvents(events, userContext, eventProvider); + final List> groupedEvents = groupEvents(events, userContext, + eventProvider); + vaadinUI.access(() -> { if (vaadinSession.getState() != State.OPEN) { return; @@ -227,18 +199,19 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { } @SuppressWarnings("unchecked") - private List> groupEvents(final List events, final SecurityContext userContext, - final UIEventProvider eventProvider) { + private List> groupEvents(final List events, + final SecurityContext userContext, final UIEventProvider eventProvider) { return events.stream().filter(event -> eventSecurityCheck(userContext, event)) - .collect(Collectors.groupingBy(Event::getClass)).entrySet().stream().map(entry -> { - EventContainer holder = null; + .collect(Collectors.groupingBy(TenantAwareEvent::getClass)).entrySet().stream().map(entry -> { + EventContainer holder = null; try { - final Constructor declaredConstructor = (Constructor) eventProvider + final Constructor declaredConstructor = (Constructor) eventProvider .getEvents().get(entry.getKey()).getDeclaredConstructor(List.class); declaredConstructor.setAccessible(true); - holder = (EventContainer) declaredConstructor.newInstance(entry.getValue()); + holder = (EventContainer) declaredConstructor + .newInstance(entry.getValue()); } catch (final ReflectiveOperationException e) { LOG.error("Failed to create EventHolder!", e); } @@ -248,4 +221,87 @@ public class DelayedEventBusPushStrategy implements EventPushStrategy { } } + /** + * An application event publisher subscriber which subscribes + * {@link TenantAwareEvent} from the repository to dispatch these events to + * the UI {@link SessionEventBus} . + * + * @param applicationEvent + * the entity event which has been published from the repository + */ + @Override + @Async + public void onApplicationEvent(final ApplicationEvent applicationEvent) { + if (!(applicationEvent instanceof org.eclipse.hawkbit.repository.event.TenantAwareEvent)) { + return; + } + + final org.eclipse.hawkbit.repository.event.TenantAwareEvent event = (TenantAwareEvent) applicationEvent; + + collectRolloutEvent(event); + // to dispatch too many events which are not interested on the UI + if (!isEventProvided(event)) { + LOG.trace("Event is not supported in the UI!!! Dropped event is {}", event); + return; + } + offerEvent(event); + } + + private void offerEventIfNotContains(final org.eclipse.hawkbit.repository.event.TenantAwareEvent event) { + if (queue.contains(event)) { + return; + } + offerEvent(event); + } + + private void offerEvent(final org.eclipse.hawkbit.repository.event.TenantAwareEvent event) { + if (!queue.offer(event)) { + LOG.warn("Deque limit is reached, cannot add more events!!! Dropped event is {}", event); + } + } + + private void collectRolloutEvent(final TenantAwareEvent event) { + Long rolloutId = null; + Long rolloutGroupId = null; + if (event instanceof ActionCreatedEvent) { + rolloutId = getRolloutId(((ActionCreatedEvent) event).getEntity().getRollout()); + rolloutGroupId = getRolloutGroupId(((ActionCreatedEvent) event).getEntity().getRolloutGroup()); + } else if (event instanceof ActionUpdatedEvent) { + rolloutId = getRolloutId(((ActionUpdatedEvent) event).getEntity().getRollout()); + rolloutGroupId = getRolloutGroupId(((ActionUpdatedEvent) event).getEntity().getRolloutGroup()); + } else if (event instanceof RolloutUpdatedEvent) { + rolloutId = ((RolloutUpdatedEvent) event).getEntityId(); + } else if (event instanceof RolloutGroupCreatedEvent) { + rolloutId = ((RolloutGroupCreatedEvent) event).getRolloutId(); + rolloutGroupId = ((RolloutGroupCreatedEvent) event).getEntityId(); + } else if (event instanceof RolloutGroupUpdatedEvent) { + final RolloutGroup rolloutGroup = ((RolloutGroupUpdatedEvent) event).getEntity(); + rolloutId = rolloutGroup.getRollout().getId(); + rolloutGroupId = rolloutGroup.getId(); + } + + if (rolloutId == null) { + return; + } + offerEventIfNotContains(new RolloutChangeEvent(event.getTenant(), rolloutId)); + + if (rolloutGroupId != null) { + offerEventIfNotContains(new RolloutGroupChangeEvent(event.getTenant(), rolloutId, rolloutGroupId)); + } + } + + private static Long getRolloutGroupId(final RolloutGroup rolloutGroup) { + if (rolloutGroup != null) { + return rolloutGroup.getId(); + } + return null; + } + + private static Long getRolloutId(final Rollout rollout) { + if (rollout != null) { + return rollout.getId(); + } + return null; + } + } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionCreatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionCreatedEventContainer.java index 7f1dbe75d..31d4b5630 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionCreatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionCreatedEventContainer.java @@ -10,21 +10,21 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; /** - * EventHolder for {@link DistributionCreatedEvent}s. + * EventHolder for {@link DistributionSetCreatedEvent}s. * */ -public class DistributionCreatedEventContainer implements EventContainer { - private final List events; +public class DistributionCreatedEventContainer implements EventContainer { + private final List events; - DistributionCreatedEventContainer(final List events) { + DistributionCreatedEventContainer(final List events) { this.events = events; } @Override - public List getEvents() { + public List getEvents() { return events; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionDeletedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionDeletedEventContainer.java index 50343d10f..9005d28fc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionDeletedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionDeletedEventContainer.java @@ -10,21 +10,21 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; /** - * EventHolder for {@link DistributionDeletedEvent}s. + * EventHolder for {@link DistributionSetDeletedEvent}s. * */ -public class DistributionDeletedEventContainer implements EventContainer { - private final List events; +public class DistributionDeletedEventContainer implements EventContainer { + private final List events; - DistributionDeletedEventContainer(final List events) { + DistributionDeletedEventContainer(final List events) { this.events = events; } @Override - public List getEvents() { + public List getEvents() { return events; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagAssignmentResultEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagAssignmentResultEventContainer.java deleted file mode 100644 index 80b306982..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagAssignmentResultEventContainer.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.push; - -import java.util.List; - -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagAssigmentResultEvent; - -/** - * EventHolder for {@link DistributionSetTagAssigmentResultEvent}s. - * - */ -public class DistributionSetTagAssignmentResultEventContainer - implements EventContainer { - private final List events; - - DistributionSetTagAssignmentResultEventContainer(final List events) { - this.events = events; - } - - @Override - public List getEvents() { - return events; - } - -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagCreatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagCreatedEventContainer.java index e1ec74525..0c32085fe 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagCreatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagCreatedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; /** * EventHolder for {@link DistributionSetTagCreatedEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagDeletedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagDeletedEventContainer.java index 8c66e746d..ed155c047 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagDeletedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagDeletedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetTagDeletedEvent; /** * EventHolder for {@link DistributionSetTagDeletedEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagUpdatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagUpdatedEventContainer.java index 283d6d6c5..0fa68b534 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagUpdatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetTagUpdatedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent; /** * EventHolder for {@link DistributionSetTagUpdateEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetUpdatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetUpdatedEventContainer.java index b8be78a21..0482bdcaf 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetUpdatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/DistributionSetUpdatedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; /** * EventHolder for {@link DistributionSetUpdateEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/EventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/EventContainer.java index bbb4a4947..0ee74e9fc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/EventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/EventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.eventbus.event.Event; +import org.eclipse.hawkbit.repository.event.TenantAwareEvent; /** * EventHolder beans contains a list of events that can be process by the UI in @@ -21,7 +21,7 @@ import org.eclipse.hawkbit.eventbus.event.Event; * */ @FunctionalInterface -public interface EventContainer { +public interface EventContainer { /** * @return list of contained events diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/HawkbitEventProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/HawkbitEventProvider.java index 782a4b99e..5c60dafa0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/HawkbitEventProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/HawkbitEventProvider.java @@ -10,25 +10,22 @@ package org.eclipse.hawkbit.ui.push; import java.util.Map; -import org.eclipse.hawkbit.eventbus.event.Event; -import org.eclipse.hawkbit.repository.eventbus.event.CancelTargetAssignmentEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagAssigmentResultEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetTagUpdateEvent; -import org.eclipse.hawkbit.repository.eventbus.event.DistributionSetUpdateEvent; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutChangeEvent; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupChangeEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagAssigmentResultEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; -import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent; +import org.eclipse.hawkbit.repository.event.TenantAwareEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.DistributionSetTagDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.CancelTargetAssignmentEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.DistributionSetUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutChangeEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangeEvent; import com.google.common.collect.Maps; @@ -37,30 +34,26 @@ import com.google.common.collect.Maps; */ public class HawkbitEventProvider implements UIEventProvider { - private static final Map, Class> EVENTS = Maps.newHashMapWithExpectedSize(18); + private static final Map, Class> EVENTS = Maps.newHashMapWithExpectedSize(15); static { EVENTS.put(TargetTagDeletedEvent.class, TargetTagDeletedEventContainer.class); EVENTS.put(TargetTagCreatedEvent.class, TargetTagCreatedEventContainer.class); EVENTS.put(TargetTagUpdateEvent.class, TargetTagUpdatedEventContainer.class); - EVENTS.put(TargetTagAssigmentResultEvent.class, TargetTagAssigmentResultEventContainer.class); EVENTS.put(DistributionSetTagCreatedEvent.class, DistributionSetTagCreatedEventContainer.class); EVENTS.put(DistributionSetTagDeletedEvent.class, DistributionSetTagDeletedEventContainer.class); EVENTS.put(DistributionSetTagUpdateEvent.class, DistributionSetTagUpdatedEventContainer.class); - EVENTS.put(DistributionSetTagAssigmentResultEvent.class, - DistributionSetTagAssignmentResultEventContainer.class); EVENTS.put(TargetCreatedEvent.class, TargetCreatedEventContainer.class); - EVENTS.put(TargetInfoUpdateEvent.class, TargetInfoUpdateEventContainer.class); EVENTS.put(TargetDeletedEvent.class, TargetDeletedEventContainer.class); EVENTS.put(TargetUpdatedEvent.class, TargetUpdatedEventContainer.class); EVENTS.put(CancelTargetAssignmentEvent.class, CancelTargetAssignmentEventContainer.class); EVENTS.put(DistributionSetUpdateEvent.class, DistributionSetUpdatedEventContainer.class); - EVENTS.put(DistributionDeletedEvent.class, DistributionDeletedEventContainer.class); - EVENTS.put(DistributionCreatedEvent.class, DistributionCreatedEventContainer.class); + EVENTS.put(DistributionSetDeletedEvent.class, DistributionDeletedEventContainer.class); + EVENTS.put(DistributionSetCreatedEvent.class, DistributionCreatedEventContainer.class); EVENTS.put(RolloutGroupChangeEvent.class, RolloutGroupChangeEventContainer.class); EVENTS.put(RolloutChangeEvent.class, RolloutChangeEventContainer.class); @@ -68,7 +61,7 @@ public class HawkbitEventProvider implements UIEventProvider { } @Override - public Map, Class> getEvents() { + public Map, Class> getEvents() { return EVENTS; } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutChangeEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutChangeEventContainer.java index dd9189874..6dea3fa15 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutChangeEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutChangeEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutChangeEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutChangeEvent; /** * EventHolder for {@link RolloutChangeEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangeEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangeEventContainer.java index 5fbc992b8..c3d9688e1 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangeEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/RolloutGroupChangeEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutGroupChangeEvent; +import org.eclipse.hawkbit.ui.push.event.RolloutGroupChangeEvent; /** * EventHolder for {@link RolloutGroupChangeEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetCreatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetCreatedEventContainer.java index 5cfa091de..6fbdeae10 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetCreatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetCreatedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.TargetCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetCreatedEvent; /** * EventHolder for {@link TargetCreatedEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetDeletedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetDeletedEventContainer.java index 47bd594ff..cf59c514d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetDeletedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetDeletedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.TargetDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent; /** * EventHolder for {@link TargetDeletedEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetInfoUpdateEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetInfoUpdateEventContainer.java deleted file mode 100644 index 76035d510..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetInfoUpdateEventContainer.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.push; - -import java.util.List; - -import org.eclipse.hawkbit.repository.eventbus.event.TargetInfoUpdateEvent; - -/** - * EventHolder for {@link TargetInfoUpdateEvent}s. - * - */ -public class TargetInfoUpdateEventContainer implements EventContainer { - private final List events; - - TargetInfoUpdateEventContainer(final List events) { - this.events = events; - } - - @Override - public List getEvents() { - return events; - } - -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagAssigmentResultEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagAssigmentResultEventContainer.java deleted file mode 100644 index ef81e4389..000000000 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagAssigmentResultEventContainer.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2015 Bosch Software Innovations GmbH and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.eclipse.hawkbit.ui.push; - -import java.util.List; - -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagAssigmentResultEvent; - -/** - * EventHolder for {@link TargetTagAssigmentResultEvent}s. - * - */ -public class TargetTagAssigmentResultEventContainer implements EventContainer { - private final List events; - - TargetTagAssigmentResultEventContainer(final List events) { - this.events = events; - } - - @Override - public List getEvents() { - return events; - } - -} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagCreatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagCreatedEventContainer.java index 5b6698a06..87d549121 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagCreatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagCreatedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagCreatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagCreatedEvent; /** * EventHolder for {@link TargetTagCreatedEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagDeletedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagDeletedEventContainer.java index 502327e27..d64c496e3 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagDeletedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagDeletedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagDeletedEvent; +import org.eclipse.hawkbit.repository.event.remote.TargetTagDeletedEvent; /** * EventHolder for {@link TargetTagDeletedEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagUpdatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagUpdatedEventContainer.java index 19dd53f2a..69d096f5f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagUpdatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetTagUpdatedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.TargetTagUpdateEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdateEvent; /** * EventHolder for {@link TargetTagUpdateEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetUpdatedEventContainer.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetUpdatedEventContainer.java index f44106fe8..44e48dc23 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetUpdatedEventContainer.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/TargetUpdatedEventContainer.java @@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.List; -import org.eclipse.hawkbit.repository.eventbus.event.TargetUpdatedEvent; +import org.eclipse.hawkbit.repository.event.remote.entity.TargetUpdatedEvent; /** * EventHolder for {@link TargetUpdatedEvent}s. diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/UIEventProvider.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/UIEventProvider.java index c32f4192f..4003fd43c 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/UIEventProvider.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/UIEventProvider.java @@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.push; import java.util.Collections; import java.util.Map; -import org.eclipse.hawkbit.eventbus.event.Event; +import org.eclipse.hawkbit.repository.event.TenantAwareEvent; /** * The UI event provider hold all supported repository events which will @@ -25,7 +25,7 @@ public interface UIEventProvider { * * @return list of provided event types. Should not be null */ - default Map, Class> getEvents() { + default Map, Class> getEvents() { return Collections.emptyMap(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangeEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangeEvent.java new file mode 100644 index 000000000..c97747dcc --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutChangeEvent.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.push.event; + +/** + * TenantAwareEvent declaration for the UI to notify the UI that a rollout has + * been changed. + * + */ +public class RolloutChangeEvent extends TenantAwareUiEvent { + + private final Long rolloutId; + + /** + * Constructor. + * + * @param tenant + * the tenant of the event + * @param rolloutId + * the ID of the rollout which has been changed + */ + public RolloutChangeEvent(final String tenant, final Long rolloutId) { + super(tenant); + this.rolloutId = rolloutId; + } + + public Long getRolloutId() { + return rolloutId; + } + + @Override + public String toString() { + return "RolloutChangeEvent [rolloutId=" + rolloutId + ", getTenant()=" + getTenant() + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((rolloutId == null) ? 0 : rolloutId.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final RolloutChangeEvent other = (RolloutChangeEvent) obj; + if (rolloutId == null) { + if (other.rolloutId != null) { + return false; + } + } else if (!rolloutId.equals(other.rolloutId)) { + return false; + } + return true; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangeEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangeEvent.java new file mode 100644 index 000000000..27748481b --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/RolloutGroupChangeEvent.java @@ -0,0 +1,90 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.push.event; + +/** + * TenantAwareEvent declaration for the UI to notify the UI that a rollout has + * been changed. + * + * + */ +public class RolloutGroupChangeEvent extends TenantAwareUiEvent { + + private final Long rolloutId; + private final Long rolloutGroupId; + + /** + * Constructor. + * + * @param tenant + * the tenant of the event + * @param rolloutId + * the ID of the rollout which has been changed + * @param rolloutGroupId + * the ID of the rollout group which has been changed + */ + public RolloutGroupChangeEvent(final String tenant, final Long rolloutId, final Long rolloutGroupId) { + super(tenant); + this.rolloutId = rolloutId; + this.rolloutGroupId = rolloutGroupId; + } + + public Long getRolloutId() { + return rolloutId; + } + + public Long getRolloutGroupId() { + return rolloutGroupId; + } + + @Override + public String toString() { + return "RolloutGroupChangeEvent [rolloutId=" + rolloutId + ", rolloutGroupId=" + rolloutGroupId + + ", getTenant()=" + getTenant() + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((rolloutGroupId == null) ? 0 : rolloutGroupId.hashCode()); + result = prime * result + ((rolloutId == null) ? 0 : rolloutId.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final RolloutGroupChangeEvent other = (RolloutGroupChangeEvent) obj; + if (rolloutGroupId == null) { + if (other.rolloutGroupId != null) { + return false; + } + } else if (!rolloutGroupId.equals(other.rolloutGroupId)) { + return false; + } + if (rolloutId == null) { + if (other.rolloutId != null) { + return false; + } + } else if (!rolloutId.equals(other.rolloutId)) { + return false; + } + return true; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/TenantAwareUiEvent.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/TenantAwareUiEvent.java new file mode 100644 index 000000000..8d0e952e5 --- /dev/null +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/push/event/TenantAwareUiEvent.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.ui.push.event; + +import org.eclipse.hawkbit.repository.event.TenantAwareEvent; + +/** + * UI event definition class which holds the necessary tenant information which + * every UI event needs. + * + */ +public class TenantAwareUiEvent implements TenantAwareEvent { + + private final String tenant; + + /** + * Constructor. + * + * @param tenant + * the tenant of the event + */ + protected TenantAwareUiEvent(final String tenant) { + this.tenant = tenant; + } + + @Override + public String getTenant() { + return tenant; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((tenant == null) ? 0 : tenant.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final TenantAwareUiEvent other = (TenantAwareUiEvent) obj; + if (tenant == null) { + if (other.tenant != null) { + return false; + } + } else if (!tenant.equals(other.tenant)) { + return false; + } + return true; + } + +} diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java index 6fa6c2660..c4db28f6f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rollout/RolloutListGrid.java @@ -28,7 +28,6 @@ import java.util.Set; import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.eventbus.event.RolloutChangeEvent; import org.eclipse.hawkbit.repository.model.Rollout; import org.eclipse.hawkbit.repository.model.Rollout.RolloutStatus; import org.eclipse.hawkbit.repository.model.SoftwareModule; @@ -40,6 +39,7 @@ import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlButtonRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.HtmlLabelRenderer; import org.eclipse.hawkbit.ui.customrenderers.renderers.RolloutRenderer; import org.eclipse.hawkbit.ui.push.RolloutChangeEventContainer; +import org.eclipse.hawkbit.ui.push.event.RolloutChangeEvent; import org.eclipse.hawkbit.ui.rollout.DistributionBarHelper; import org.eclipse.hawkbit.ui.rollout.StatusFontIcon; import org.eclipse.hawkbit.ui.rollout.event.RolloutEvent; diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java index ddede7320..a253f25a5 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgroup/RolloutGroupListGrid.java @@ -16,9 +16,7 @@ import java.util.Locale; import java.util.Map; import org.eclipse.hawkbit.repository.RolloutGroupManagement; -import org.eclipse.hawkbit.repository.RolloutManagement; import org.eclipse.hawkbit.repository.SpPermissionChecker; -import org.eclipse.hawkbit.repository.model.RolloutGroup; import org.eclipse.hawkbit.repository.model.RolloutGroup.RolloutGroupStatus; import org.eclipse.hawkbit.repository.model.TotalTargetCountStatus; import org.eclipse.hawkbit.ui.common.grid.AbstractGrid; @@ -66,9 +64,6 @@ public class RolloutGroupListGrid extends AbstractGrid { @Autowired private transient RolloutGroupManagement rolloutGroupManagement; - @Autowired - private transient RolloutManagement rolloutManagement; - @Autowired private transient RolloutUIState rolloutUIState; @@ -90,11 +85,10 @@ public class RolloutGroupListGrid extends AbstractGrid { * Handles the RolloutGroupChangeEvent to refresh the item in the grid. * * - * @param rolloutGroupChangeEvent + * @param eventContainer * the event which contains the rollout group which has been * change */ - @SuppressWarnings("unchecked") @EventBusListenerMethod(scope = EventScope.SESSION) public void onRolloutGroupChangeEvent(final RolloutGroupChangeEventContainer eventContainer) { if (!rolloutUIState.isShowRolloutGroups()) { @@ -104,11 +98,6 @@ public class RolloutGroupListGrid extends AbstractGrid { ((LazyQueryContainer) getContainerDataSource()).refresh(); } - private String calculateFinishedPercentage(final RolloutGroup rolloutGroup) { - return HawkbitCommonUtil.formattingFinishedPercentage(rolloutGroup, - rolloutManagement.getFinishedPercentForRunningGroup(rolloutGroup.getRollout().getId(), rolloutGroup)); - } - @Override protected Container createContainer() { final BeanQueryFactory rolloutQf = new BeanQueryFactory<>(RolloutGroupBeanQuery.class); diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java index a558616ca..7f09d8633 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/rollout/rolloutgrouptargets/RolloutGroupTargetsCountLabelMessage.java @@ -66,7 +66,7 @@ public class RolloutGroupTargetsCountLabelMessage extends Label { } /** - * Event Listener to show the message count. + * TenantAwareEvent Listener to show the message count. * * @param event */ diff --git a/pom.xml b/pom.xml index f86c58177..d30ad8fa8 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,6 @@ hawkbit-ui hawkbit-artifact-repository-mongo hawkbit-autoconfigure - hawkbit-cache-redis hawkbit-test-report examples extensions @@ -106,8 +105,10 @@ - 1.6.2.RELEASE + 1.6.3.RELEASE 4.1.2.RELEASE + 4.3.3.RELEASE + 4.3.2.RELEASE Hopper-SR4 3.2.2 @@ -148,6 +149,11 @@ 4.1 20141113 2.1.0 + Camden.SR1 + 9.3.1 + 1.7.0 + 1.3.5 + @@ -459,13 +465,14 @@ - - - org.slf4j - slf4j-api - ${slf4j.version} - + + com.vaadin + vaadin-bom + ${vaadin.version} + pom + import + com.vaadin vaadin-spring-boot @@ -481,26 +488,6 @@ vaadin-spring-ext-security ${vaadin.spring.addon.version} - - com.vaadin - vaadin-server - ${vaadin.version} - - - com.vaadin - vaadin-push - ${vaadin.version} - - - com.vaadin - vaadin-client - ${vaadin.version} - - - com.vaadin - vaadin-themes - ${vaadin.version} - org.vaadin.addons.lazyquerycontainer vaadin-lazyquerycontainer @@ -549,6 +536,13 @@ ${jlorem.version} + + org.springframework.cloud + spring-cloud-dependencies + ${spring.cloud.version} + pom + import + org.springframework.boot spring-boot-starter-actuator @@ -605,6 +599,34 @@ org.eclipse.persistence.jpa ${eclipselink.version} + + io.github.openfeign + feign-jackson + ${feign.extension.version} + + + io.github.openfeign + feign-gson + ${feign.extension.version} + + + io.github.openfeign + feign-jaxrs + ${feign.extension.version} + + + + + io.protostuff + protostuff-core + ${io-protostuff.version} + + + io.protostuff + protostuff-runtime + ${io-protostuff.version} + + cz.jirutka.rsql @@ -700,6 +722,11 @@ guava ${guava.version} + + com.jayway.awaitility + awaitility + ${jayway.awaitility.version} + \ No newline at end of file