TargetManagement over RepositoryManagement (#2599)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -144,7 +144,7 @@ class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(TestdataFactory.DEFAULT_CONTROLLER_ID).get())
|
||||
.isEqualTo(ds);
|
||||
assertThat(
|
||||
targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getInstallationDate())
|
||||
targetManagement.getByControllerId(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getInstallationDate())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
|
||||
}
|
||||
@@ -171,7 +171,7 @@ class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
startsWith("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/"
|
||||
+ TestdataFactory.DEFAULT_CONTROLLER_ID + "/deploymentBase/" + actionId)));
|
||||
final long timeAfterFirstPoll = System.currentTimeMillis() + 1;
|
||||
assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isBetween(timeBeforeFirstPoll, timeAfterFirstPoll);
|
||||
|
||||
// Retrieved is reported
|
||||
@@ -202,7 +202,7 @@ class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
equalTo("http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/"
|
||||
+ TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/" + cancelAction.getId())));
|
||||
final long timeAfter2ndPoll = System.currentTimeMillis() + 1;
|
||||
assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isBetween(timeBefore2ndPoll, timeAfter2ndPoll);
|
||||
|
||||
mvc.perform(get("/{tenant}/controller/v1/" + TestdataFactory.DEFAULT_CONTROLLER_ID + "/cancelAction/"
|
||||
@@ -212,7 +212,7 @@ class DdiCancelActionTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(jsonPath("$.id", equalTo(String.valueOf(cancelAction.getId()))))
|
||||
.andExpect(jsonPath("$.cancelAction.stopId", equalTo(String.valueOf(actionId))));
|
||||
assertThat(targetManagement.getByControllerID(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(TestdataFactory.DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
|
||||
// controller confirmed cancelled action, should not be active anymore
|
||||
|
||||
@@ -90,10 +90,10 @@ class DdiConfigDataTest extends AbstractDDiApiIntegrationTest {
|
||||
"http://localhost/" + tenantAware.getCurrentTenant() + "/controller/v1/4712/configData")));
|
||||
Thread.sleep(1); // is required: otherwise processing the next line is
|
||||
// often too fast and // the following assert will fail
|
||||
assertThat(targetManagement.getByControllerID("4712").orElseThrow(NoSuchElementException::new)
|
||||
assertThat(targetManagement.getByControllerId("4712").orElseThrow(NoSuchElementException::new)
|
||||
.getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.getByControllerID("4712").orElseThrow(NoSuchElementException::new)
|
||||
assertThat(targetManagement.getByControllerId("4712").orElseThrow(NoSuchElementException::new)
|
||||
.getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
|
||||
|
||||
@@ -113,9 +113,9 @@ class DdiConfirmationBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(jsonPath("$._links.confirmationBase.href", containsString(expectedConfirmationBaseLink)))
|
||||
.andExpect(jsonPath("$._links.deploymentBase.href").doesNotExist());
|
||||
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(actionStatusRepository.count()).isEqualTo(2);
|
||||
|
||||
|
||||
@@ -181,9 +181,9 @@ class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(jsonPath(
|
||||
"$._links.deploymentBase.href",
|
||||
startsWith(deploymentBaseLink(DEFAULT_CONTROLLER_ID, uaction.getId().toString()))));
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(countActionStatusAll()).isEqualTo(2);
|
||||
|
||||
@@ -281,9 +281,9 @@ class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")))
|
||||
.andExpect(jsonPath("$._links.deploymentBase.href",
|
||||
startsWith(deploymentBaseLink(DEFAULT_CONTROLLER_ID, uaction.getId().toString()))));
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(countActionStatusAll()).isEqualTo(2);
|
||||
|
||||
@@ -338,9 +338,9 @@ class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")))
|
||||
.andExpect(jsonPath("$._links.deploymentBase.href",
|
||||
startsWith(deploymentBaseLink(DEFAULT_CONTROLLER_ID, uaction.getId().toString()))));
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(countActionStatusAll()).isEqualTo(2);
|
||||
|
||||
@@ -403,9 +403,9 @@ class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")))
|
||||
.andExpect(jsonPath("$._links.deploymentBase.href",
|
||||
startsWith(deploymentBaseLink(DEFAULT_CONTROLLER_ID, uaction.getId().toString()))));
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(countActionStatusAll()).isEqualTo(2);
|
||||
|
||||
@@ -560,7 +560,7 @@ class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
final Target savedTarget = testdataFactory.createTarget(DEFAULT_CONTROLLER_ID);
|
||||
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
assignDistributionSet(ds, Collections.singletonList(savedTarget));
|
||||
final Action action = actionRepository
|
||||
.findAll(ActionSpecifications.byDistributionSetId(ds.getId()), PAGE)
|
||||
@@ -577,7 +577,7 @@ class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
|
||||
// redo
|
||||
ds = distributionSetManagement.getWithDetails(ds.getId()).get();
|
||||
assignDistributionSet(ds, Collections.singletonList(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get()));
|
||||
assignDistributionSet(ds, Collections.singletonList(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get()));
|
||||
final Action action2 = deploymentManagement.findActiveActionsByTarget(DEFAULT_CONTROLLER_ID, PAGE).getContent().get(0);
|
||||
postDeploymentFeedback(DEFAULT_CONTROLLER_ID, action2.getId(), getJsonClosedCancelActionFeedback(), status().isOk());
|
||||
findTargetAndAssertUpdateStatus(Optional.of(ds), TargetUpdateStatus.IN_SYNC, 0, Optional.of(ds));
|
||||
@@ -766,7 +766,7 @@ class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertActionStatusCount(final int actionStatusCount, final int minActionStatusCountInPage) {
|
||||
final Target target = targetManagement.getByControllerID(DdiDeploymentBaseTest.DEFAULT_CONTROLLER_ID).get();
|
||||
final Target target = targetManagement.getByControllerId(DdiDeploymentBaseTest.DEFAULT_CONTROLLER_ID).get();
|
||||
assertThat(target.getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
assertTargetCountByStatus(1, 0, 0);
|
||||
@@ -796,7 +796,7 @@ class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
final Optional<DistributionSet> ds,
|
||||
final TargetUpdateStatus updateStatus, final int activeActions,
|
||||
final Optional<DistributionSet> installedDs) {
|
||||
final Target myT = targetManagement.getByControllerID(DdiDeploymentBaseTest.DEFAULT_CONTROLLER_ID).get();
|
||||
final Target myT = targetManagement.getByControllerId(DdiDeploymentBaseTest.DEFAULT_CONTROLLER_ID).get();
|
||||
assertThat(myT.getUpdateStatus()).isEqualTo(updateStatus);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(myT.getControllerId(), PAGE)).hasSize(activeActions);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(myT.getControllerId())).isEqualTo(ds);
|
||||
@@ -818,7 +818,7 @@ class DdiDeploymentBaseTest extends AbstractDDiApiIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertStatusAndActiveActionsCount(final TargetUpdateStatus status, final int activeActions) {
|
||||
final Target target = targetManagement.getByControllerID(DdiDeploymentBaseTest.DEFAULT_CONTROLLER_ID).get();
|
||||
final Target target = targetManagement.getByControllerId(DdiDeploymentBaseTest.DEFAULT_CONTROLLER_ID).get();
|
||||
assertThat(target.getUpdateStatus()).isEqualTo(status);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(target.getControllerId(), PAGE)).hasSize(activeActions);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
final String knownTargetControllerId = "target1";
|
||||
final String knownCreatedBy = "knownPrincipal";
|
||||
testdataFactory.createTarget(knownTargetControllerId);
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerID(knownTargetControllerId).get();
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerId(knownTargetControllerId).get();
|
||||
assertThat(findTargetByControllerID.getCreatedBy()).isEqualTo(knownCreatedBy);
|
||||
// make a poll, audit information should not be changed, run as controller principal!
|
||||
callAs(withController("controller", CONTROLLER_ROLE_ANONYMOUS),
|
||||
@@ -136,7 +136,7 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
return null;
|
||||
});
|
||||
// verify that audit information has not changed
|
||||
final Target targetVerify = targetManagement.getByControllerID(knownTargetControllerId).get();
|
||||
final Target targetVerify = targetManagement.getByControllerId(knownTargetControllerId).get();
|
||||
assertThat(targetVerify.getCreatedBy()).isEqualTo(findTargetByControllerID.getCreatedBy());
|
||||
assertThat(targetVerify.getCreatedAt()).isEqualTo(findTargetByControllerID.getCreatedAt());
|
||||
assertThat(targetVerify.getLastModifiedBy()).isEqualTo(findTargetByControllerID.getLastModifiedBy());
|
||||
@@ -170,9 +170,9 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaTypes.HAL_JSON))
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")));
|
||||
assertThat(targetManagement.getByControllerID(controllerId).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(controllerId).get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.getByControllerID(controllerId).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(controllerId).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.REGISTERED);
|
||||
|
||||
// not allowed methods
|
||||
@@ -265,7 +265,7 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotModified());
|
||||
|
||||
final Target target = targetManagement.getByControllerID(controllerId).get();
|
||||
final Target target = targetManagement.getByControllerId(controllerId).get();
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("");
|
||||
assignDistributionSet(ds.getId(), controllerId);
|
||||
|
||||
@@ -338,18 +338,18 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
void rootRsPreCommissioned() throws Exception {
|
||||
final String controllerId = "4711";
|
||||
testdataFactory.createTarget(controllerId);
|
||||
assertThat(targetManagement.getByControllerID(controllerId).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
assertThat(targetManagement.getByControllerId(controllerId).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
final long current = System.currentTimeMillis();
|
||||
mvc.perform(get(CONTROLLER_BASE, tenantAware.getCurrentTenant(), controllerId))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaTypes.HAL_JSON))
|
||||
.andExpect(jsonPath("$.config.polling.sleep", equalTo("00:01:00")));
|
||||
assertThat(targetManagement.getByControllerID(controllerId).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(controllerId).get().getLastTargetQuery())
|
||||
.isLessThanOrEqualTo(System.currentTimeMillis());
|
||||
assertThat(targetManagement.getByControllerID(controllerId).get().getLastTargetQuery())
|
||||
assertThat(targetManagement.getByControllerId(controllerId).get().getLastTargetQuery())
|
||||
.isGreaterThanOrEqualTo(current);
|
||||
assertThat(targetManagement.getByControllerID(controllerId).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(controllerId).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.REGISTERED);
|
||||
}
|
||||
|
||||
@@ -361,6 +361,7 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
@Expect(type = TargetCreatedEvent.class, count = 1),
|
||||
@Expect(type = TargetPollEvent.class, count = 1) })
|
||||
void rootRsPlugAndPlayIpAddress() throws Exception {
|
||||
securityProperties.getClients().setTrackRemoteIp(true);
|
||||
// test
|
||||
final String knownControllerId1 = "0815";
|
||||
final long create = System.currentTimeMillis();
|
||||
@@ -373,8 +374,8 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
return null;
|
||||
});
|
||||
// verify
|
||||
final Target target = targetManagement.getByControllerID(knownControllerId1).get();
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createHttpUri("127.0.0.1"));
|
||||
final Target target = targetManagement.getByControllerId(knownControllerId1).get();
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createHttpUri("127.0.0.1").toString());
|
||||
assertThat(target.getCreatedBy()).isEqualTo("CONTROLLER_PLUG_AND_PLAY");
|
||||
assertThat(target.getCreatedAt()).isGreaterThanOrEqualTo(create);
|
||||
assertThat(target.getLastModifiedBy()).isEqualTo("CONTROLLER_PLUG_AND_PLAY");
|
||||
@@ -396,8 +397,8 @@ class DdiRootControllerTest extends AbstractDDiApiIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
// verify
|
||||
final Target target = targetManagement.getByControllerID(knownControllerId1).get();
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createHttpUri("***"));
|
||||
final Target target = targetManagement.getByControllerId(knownControllerId1).get();
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createHttpUri("***").toString());
|
||||
securityProperties.getClients().setTrackRemoteIp(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -97,30 +97,18 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
private final AmqpMessageSenderService amqpSenderService;
|
||||
private final SystemSecurityContext systemSecurityContext;
|
||||
private final SystemManagement systemManagement;
|
||||
private final TargetManagement targetManagement;
|
||||
private final TargetManagement<? extends Target> targetManagement;
|
||||
private final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement;
|
||||
private final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
||||
private final DeploymentManagement deploymentManagement;
|
||||
private final TenantConfigurationManagement tenantConfigurationManagement;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @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
|
||||
* @param distributionSetManagement to retrieve modules
|
||||
* @param tenantConfigurationManagement to access tenant configuration
|
||||
*/
|
||||
@SuppressWarnings("java:S107")
|
||||
protected AmqpMessageDispatcherService(
|
||||
final RabbitTemplate rabbitTemplate,
|
||||
final AmqpMessageSenderService amqpSenderService, final ArtifactUrlHandler artifactUrlHandler,
|
||||
final SystemSecurityContext systemSecurityContext, final SystemManagement systemManagement,
|
||||
final TargetManagement targetManagement,
|
||||
final TargetManagement<? extends Target> targetManagement,
|
||||
final SoftwareModuleManagement<? extends SoftwareModule> softwareModuleManagement,
|
||||
final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
||||
final DeploymentManagement deploymentManagement,
|
||||
@@ -209,15 +197,13 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
protected void targetCancelAssignmentToDistributionSet(final CancelTargetAssignmentServiceEvent cancelTargetAssignmentServiceEvent) {
|
||||
final CancelTargetAssignmentEvent cancelEvent = cancelTargetAssignmentServiceEvent.getRemoteEvent();
|
||||
final List<Target> eventTargets = partitionedParallelExecution(
|
||||
cancelEvent.getActions().keySet(), targetManagement::getByControllerID);
|
||||
cancelEvent.getActions().keySet(), targetManagement::getByControllerId);
|
||||
|
||||
eventTargets.forEach(target ->
|
||||
cancelEvent.getActionPropertiesForController(target.getControllerId())
|
||||
.map(ActionProperties::getId)
|
||||
.ifPresent(actionId ->
|
||||
sendCancelMessageToTarget(cancelEvent.getTenant(), target.getControllerId(), actionId, target.getAddress())
|
||||
)
|
||||
);
|
||||
.ifPresent(actionId -> sendCancelMessageToTarget
|
||||
(cancelEvent.getTenant(), target.getControllerId(), actionId, IpUtil.addressToUri(target.getAddress()))));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,7 +266,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
void sendMultiActionRequestToTarget(
|
||||
final Target target, final List<Action> actions,
|
||||
final Function<SoftwareModule, Map<String, String>> getSoftwareModuleMetaData) {
|
||||
final URI targetAddress = target.getAddress();
|
||||
final URI targetAddress = IpUtil.addressToUri(target.getAddress());
|
||||
if (!IpUtil.isAmqpUri(targetAddress) || CollectionUtils.isEmpty(actions)) {
|
||||
return;
|
||||
}
|
||||
@@ -406,7 +392,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
|
||||
private List<Target> getTargetsWithoutPendingCancellations(final Set<String> controllerIds) {
|
||||
return partitionedParallelExecution(controllerIds, partition ->
|
||||
targetManagement.getByControllerID(partition).stream()
|
||||
targetManagement.getByControllerId(partition).stream()
|
||||
.filter(target -> {
|
||||
if (hasPendingCancellations(target.getId())) {
|
||||
log.debug("Target {} has pending cancellations. Will not send update message to it.",
|
||||
@@ -456,7 +442,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
? Collections.emptyMap()
|
||||
: softwareModuleManagement.findMetaDataBySoftwareModuleIdsAndTargetVisible(allSmIds);
|
||||
|
||||
targetManagement.getByControllerID(controllerIds).forEach(target ->
|
||||
targetManagement.getByControllerId(controllerIds).forEach(target ->
|
||||
sendMultiActionRequestToTarget(
|
||||
target, controllerIdToActions.get(target.getControllerId()), module -> getSoftwareModuleMetadata.get(module.getId())));
|
||||
}
|
||||
@@ -476,7 +462,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
final ActionProperties action, final Target target, final Map<SoftwareModule, Map<String, String>> modules) {
|
||||
final String tenant = action.getTenant();
|
||||
|
||||
final URI targetAddress = target.getAddress();
|
||||
final URI targetAddress = IpUtil.addressToUri(target.getAddress());
|
||||
if (!IpUtil.isAmqpUri(targetAddress)) {
|
||||
return;
|
||||
}
|
||||
@@ -575,7 +561,6 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<SoftwareModule, Map<String, String>> getSoftwareModulesWithMetadata(final DistributionSet distributionSet) {
|
||||
final Map<Long, Map<String, String>> softwareModuleMetadata =
|
||||
softwareModuleManagement.findMetaDataBySoftwareModuleIdsAndTargetVisible(
|
||||
@@ -592,7 +577,7 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
final Map<String, ActionProperties> actions, final List<Target> targets,
|
||||
final Map<SoftwareModule, Map<String, String>> modules) {
|
||||
final List<DmfTarget> dmfTargets = targets.stream()
|
||||
.filter(target -> IpUtil.isAmqpUri(target.getAddress()))
|
||||
.filter(target -> IpUtil.isAmqpUri(IpUtil.addressToUri(target.getAddress())))
|
||||
.map(t -> convertToDmfTarget(t, actions.get(t.getControllerId()).getId()))
|
||||
.toList();
|
||||
|
||||
@@ -613,6 +598,6 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
||||
final Message message = getMessageConverter().toMessage(
|
||||
batchRequest,
|
||||
createMessagePropertiesBatch(firstAction.getTenant(), getBatchEventTopicForAction(firstAction)));
|
||||
amqpSenderService.sendMessage(message, firstTarget.getAddress());
|
||||
amqpSenderService.sendMessage(message, IpUtil.addressToUri(firstTarget.getAddress()));
|
||||
}
|
||||
}
|
||||
@@ -365,7 +365,7 @@ public class AmqpMessageHandlerService extends BaseAmqpService {
|
||||
final Action action = actionOptional.get();
|
||||
if (action.isCancelingOrCanceled()) {
|
||||
amqpMessageDispatcherService.sendCancelMessageToTarget(
|
||||
target.getTenant(), target.getControllerId(), action.getId(), target.getAddress());
|
||||
target.getTenant(), target.getControllerId(), action.getId(), IpUtil.addressToUri(target.getAddress()));
|
||||
} else {
|
||||
amqpMessageDispatcherService.sendUpdateMessageToTarget(
|
||||
new ActionProperties(action), action.getTarget(), getSoftwareModulesWithMetadata(action.getDistributionSet()));
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.artifact.ArtifactFilesystem;
|
||||
import org.eclipse.hawkbit.repository.artifact.model.AbstractDbArtifact;
|
||||
import org.eclipse.hawkbit.repository.artifact.model.DbArtifactHash;
|
||||
@@ -91,8 +93,8 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
testTarget = targetManagement.create(entityFactory.target().create().controllerId(CONTROLLER_ID)
|
||||
.securityToken(TEST_TOKEN).address(AMQP_URI.toString()));
|
||||
testTarget = targetManagement.create(
|
||||
Create.builder().controllerId(CONTROLLER_ID).securityToken(TEST_TOKEN).address(AMQP_URI.toString()).build());
|
||||
|
||||
this.rabbitTemplate = Mockito.mock(RabbitTemplate.class);
|
||||
when(rabbitTemplate.getMessageConverter()).thenReturn(new Jackson2JsonMessageConverter());
|
||||
@@ -308,9 +310,8 @@ class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTest {
|
||||
}
|
||||
|
||||
private Message getCaptureAddressEvent(final TargetAssignDistributionSetEvent targetAssignDistributionSetEvent) {
|
||||
final Target target = targetManagement
|
||||
.getByControllerID(targetAssignDistributionSetEvent.getActions().keySet().iterator().next()).get();
|
||||
return createArgumentCapture(target.getAddress());
|
||||
final Target target = targetManagement.getByControllerId(targetAssignDistributionSetEvent.getActions().keySet().iterator().next()).get();
|
||||
return createArgumentCapture(IpUtil.addressToUri(target.getAddress()));
|
||||
}
|
||||
|
||||
private Action createAction(final DistributionSet testDs) {
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaActionStatus;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.ActionProperties;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
|
||||
@@ -188,7 +188,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
protected void assertDmfDownloadAndUpdateRequest(
|
||||
final DmfDownloadAndUpdateRequest request, final Set<SoftwareModule> softwareModules, final String controllerId) {
|
||||
assertSoftwareModules(softwareModules, request.getSoftwareModules());
|
||||
final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.getByControllerID(controllerId));
|
||||
final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.getByControllerId(controllerId));
|
||||
assertThat(updatedTarget).isNotNull();
|
||||
assertThat(updatedTarget.getSecurityToken()).isEqualTo(request.getTargetSecurityToken());
|
||||
}
|
||||
@@ -267,7 +267,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
final int existingTargetsAfterCreation, final TargetUpdateStatus expectedTargetStatus,
|
||||
final String createdBy, final Map<String, String> attributes) {
|
||||
registerAndAssertTargetWithExistingTenant(controllerId, name, existingTargetsAfterCreation,
|
||||
expectedTargetStatus, createdBy, attributes, () -> targetManagement.getByControllerID(controllerId));
|
||||
expectedTargetStatus, createdBy, attributes, () -> targetManagement.getByControllerId(controllerId));
|
||||
}
|
||||
|
||||
protected void registerSameTargetAndAssertBasedOnVersion(final String controllerId,
|
||||
@@ -413,7 +413,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
|
||||
protected void assertConfirmRequest(final DmfConfirmRequest request, final Set<SoftwareModule> softwareModules, final String controllerId) {
|
||||
assertSoftwareModules(softwareModules, request.getSoftwareModules());
|
||||
final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.getByControllerID(controllerId));
|
||||
final Target updatedTarget = waitUntilIsPresent(() -> targetManagement.getByControllerId(controllerId));
|
||||
assertThat(updatedTarget).isNotNull();
|
||||
assertThat(updatedTarget.getSecurityToken()).isEqualTo(request.getTargetSecurityToken());
|
||||
}
|
||||
@@ -459,7 +459,7 @@ abstract class AbstractAmqpServiceIntegrationTest extends AbstractAmqpIntegratio
|
||||
assertThat(target.getDescription()).contains(target.getControllerId());
|
||||
assertThat(target.getCreatedBy()).isEqualTo(createdBy);
|
||||
assertThat(target.getUpdateStatus()).isEqualTo(updateStatus);
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createAmqpUri(getVirtualHost(), DmfTestConfiguration.REPLY_TO_EXCHANGE));
|
||||
assertThat(target.getAddress()).isEqualTo(IpUtil.createAmqpUri(getVirtualHost(), DmfTestConfiguration.REPLY_TO_EXCHANGE).toString());
|
||||
assertThat(targetManagement.getControllerAttributes(target.getControllerId())).isEqualTo(attributes);
|
||||
}
|
||||
}
|
||||
@@ -787,7 +787,7 @@ class AmqpMessageDispatcherServiceIntegrationTest extends AbstractAmqpServiceInt
|
||||
|
||||
private void waitUntilTargetHasStatus(final String controllerId, final TargetUpdateStatus status) {
|
||||
waitUntil(() -> {
|
||||
final Optional<Target> findTargetByControllerID = targetManagement.getByControllerID(controllerId);
|
||||
final Optional<Target> findTargetByControllerID = targetManagement.getByControllerId(controllerId);
|
||||
return findTargetByControllerID.isPresent()
|
||||
&& status.equals(findTargetByControllerID.get().getUpdateStatus());
|
||||
});
|
||||
|
||||
@@ -950,7 +950,7 @@ class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServiceIntegr
|
||||
amqpMessageHandlerService.setControllerManagement(mockedControllerManagement);
|
||||
createAndSendThingCreated(controllerId);
|
||||
verifyOneDeadLetterMessage();
|
||||
assertThat(targetManagement.getByControllerID(controllerId)).isEmpty();
|
||||
assertThat(targetManagement.getByControllerId(controllerId)).isEmpty();
|
||||
}
|
||||
} finally {
|
||||
amqpMessageHandlerService.setControllerManagement(controllerManagement);
|
||||
|
||||
@@ -85,7 +85,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
private final DistributionSetManagement<? extends DistributionSet> distributionSetManagement;
|
||||
private final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement;
|
||||
private final DistributionSetInvalidationManagement distributionSetInvalidationManagement;
|
||||
private final TargetManagement targetManagement;
|
||||
private final TargetManagement<? extends Target> targetManagement;
|
||||
private final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement;
|
||||
private final DeploymentManagement deployManagement;
|
||||
private final SystemManagement systemManagement;
|
||||
@@ -99,7 +99,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
final DistributionSetManagement<? extends DistributionSet> distributionSetManagement,
|
||||
final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement,
|
||||
final DistributionSetInvalidationManagement distributionSetInvalidationManagement,
|
||||
final TargetManagement targetManagement, final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final TargetManagement<? extends Target> targetManagement,
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final DeploymentManagement deployManagement, final TenantConfigurationManagement tenantConfigurationManagement,
|
||||
final MgmtDistributionSetMapper mgmtDistributionSetMapper,
|
||||
final SystemManagement systemManagement, final SystemSecurityContext systemSecurityContext) {
|
||||
@@ -120,18 +121,15 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
public ResponseEntity<PagedList<MgmtDistributionSet>> getDistributionSets(
|
||||
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
|
||||
final Slice<? extends DistributionSet> findDsPage;
|
||||
final long countModulesAll;
|
||||
final Page<? extends DistributionSet> findDsPage;
|
||||
if (rsqlParam != null) {
|
||||
findDsPage = distributionSetManagement.findByRsql(rsqlParam, pageable);
|
||||
countModulesAll = ((Page<? extends DistributionSet>) findDsPage).getTotalElements();
|
||||
} else {
|
||||
findDsPage = distributionSetManagement.findAll(pageable);
|
||||
countModulesAll = distributionSetManagement.count();
|
||||
}
|
||||
|
||||
final List<MgmtDistributionSet> rest = MgmtDistributionSetMapper.toResponseFromDsList(findDsPage.getContent());
|
||||
return ResponseEntity.ok(new PagedList<>(rest, countModulesAll));
|
||||
return ResponseEntity.ok(new PagedList<>(rest, findDsPage.getTotalElements()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -201,9 +199,9 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetSortParam(sortParam));
|
||||
final Page<Target> targetsAssignedDS;
|
||||
if (rsqlParam != null) {
|
||||
targetsAssignedDS = this.targetManagement.findByAssignedDistributionSetAndRsql(distributionSetId, rsqlParam, pageable);
|
||||
targetsAssignedDS = targetManagement.findByAssignedDistributionSetAndRsql(distributionSetId, rsqlParam, pageable);
|
||||
} else {
|
||||
targetsAssignedDS = this.targetManagement.findByAssignedDistributionSet(distributionSetId, pageable);
|
||||
targetsAssignedDS = targetManagement.findByAssignedDistributionSet(distributionSetId, pageable);
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(new PagedList<>(
|
||||
|
||||
@@ -54,8 +54,8 @@ import org.eclipse.hawkbit.mgmt.rest.resource.mapper.MgmtTargetMapper;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.PagingUtility;
|
||||
import org.eclipse.hawkbit.repository.ConfirmationManagement;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidConfirmationFeedbackException;
|
||||
@@ -65,6 +65,7 @@ import org.eclipse.hawkbit.repository.model.DeploymentRequest;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||
import org.eclipse.hawkbit.utils.TenantConfigHelper;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -83,25 +84,25 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
|
||||
private static final String ACTION_TARGET_MISSING_ASSIGN_WARN = "given action ({}) is not assigned to given target ({}).";
|
||||
|
||||
private final TargetManagement targetManagement;
|
||||
private final TargetManagement<? extends Target> targetManagement;
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
private final ConfirmationManagement confirmationManagement;
|
||||
private final DeploymentManagement deploymentManagement;
|
||||
private final MgmtTargetMapper mgmtTargetMapper;
|
||||
private final MgmtDistributionSetMapper mgmtDistributionSetMapper;
|
||||
private final EntityFactory entityFactory;
|
||||
private final TenantConfigHelper tenantConfigHelper;
|
||||
|
||||
MgmtTargetResource(
|
||||
final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
||||
final ConfirmationManagement confirmationManagement,
|
||||
final MgmtDistributionSetMapper mgmtDistributionSetMapper,
|
||||
final EntityFactory entityFactory,
|
||||
final SystemSecurityContext systemSecurityContext,
|
||||
final TenantConfigurationManagement tenantConfigurationManagement) {
|
||||
final TargetManagement<? extends Target> targetManagement, final TargetTypeManagement<? extends TargetType> targetTypeManagement,
|
||||
final DeploymentManagement deploymentManagement, final ConfirmationManagement confirmationManagement,
|
||||
final MgmtTargetMapper mgmtTargetMapper, final MgmtDistributionSetMapper mgmtDistributionSetMapper,
|
||||
final SystemSecurityContext systemSecurityContext, final TenantConfigurationManagement tenantConfigurationManagement) {
|
||||
this.targetManagement = targetManagement;
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
this.confirmationManagement = confirmationManagement;
|
||||
this.mgmtTargetMapper = mgmtTargetMapper;
|
||||
this.mgmtDistributionSetMapper = mgmtDistributionSetMapper;
|
||||
this.entityFactory = entityFactory;
|
||||
this.tenantConfigHelper = TenantConfigHelper.usingContext(systemSecurityContext, tenantConfigurationManagement);
|
||||
}
|
||||
|
||||
@@ -119,24 +120,21 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
public ResponseEntity<PagedList<MgmtTarget>> getTargets(
|
||||
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
|
||||
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeTargetSortParam(sortParam));
|
||||
final Slice<Target> findTargetsAll;
|
||||
final long countTargetsAll;
|
||||
final Page<? extends Target> findTargetsAll;
|
||||
if (rsqlParam != null) {
|
||||
findTargetsAll = targetManagement.findByRsql(rsqlParam, pageable);
|
||||
countTargetsAll = targetManagement.countByRsql(rsqlParam);
|
||||
} else {
|
||||
findTargetsAll = targetManagement.findAll(pageable);
|
||||
countTargetsAll = targetManagement.count();
|
||||
}
|
||||
|
||||
final List<MgmtTarget> rest = MgmtTargetMapper.toResponse(findTargetsAll.getContent(), tenantConfigHelper);
|
||||
return ResponseEntity.ok(new PagedList<>(rest, countTargetsAll));
|
||||
return ResponseEntity.ok(new PagedList<>(rest, findTargetsAll.getTotalElements()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtTarget>> createTargets(final List<MgmtTargetRequestBody> targets) {
|
||||
log.debug("creating {} targets", targets.size());
|
||||
final Collection<Target> createdTargets = this.targetManagement.create(MgmtTargetMapper.fromRequest(entityFactory, targets));
|
||||
final Collection<? extends Target> createdTargets = this.targetManagement.create(mgmtTargetMapper.fromRequest(targets));
|
||||
log.debug("{} targets created, return status {}", targets.size(), HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(MgmtTargetMapper.toResponse(createdTargets, tenantConfigHelper), HttpStatus.CREATED);
|
||||
}
|
||||
@@ -152,22 +150,26 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
}
|
||||
}
|
||||
|
||||
final Target updateTarget;
|
||||
if (targetRest.getTargetType() != null && targetRest.getTargetType() == -1L) {
|
||||
// if targetType in request is -1 - unassign targetType from target
|
||||
this.targetManagement.unassignType(targetId);
|
||||
// update target without targetType here ...
|
||||
updateTarget = this.targetManagement.update(entityFactory.target().update(targetId)
|
||||
.name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress())
|
||||
.securityToken(targetRest.getSecurityToken()).requestAttributes(targetRest.getRequestAttributes()));
|
||||
} else {
|
||||
updateTarget = this.targetManagement.update(
|
||||
entityFactory.target().update(targetId).name(targetRest.getName()).description(targetRest.getDescription())
|
||||
.address(targetRest.getAddress()).targetType(targetRest.getTargetType())
|
||||
.securityToken(targetRest.getSecurityToken())
|
||||
.requestAttributes(targetRest.getRequestAttributes()));
|
||||
|
||||
}
|
||||
final Target targetToUpdate = targetManagement.getByControllerId(targetId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, targetId));
|
||||
final TargetType targetType = Optional.ofNullable(targetRest.getTargetType())
|
||||
.map(targetTypeId -> {
|
||||
if (targetTypeId == -1L) {
|
||||
// if targetType in request is -1 - unassign targetType from target
|
||||
targetManagement.unassignType(targetId);
|
||||
return null;
|
||||
} else {
|
||||
return targetTypeManagement.get(targetRest.getTargetType())
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetRest.getTargetType()));
|
||||
}
|
||||
})
|
||||
.orElse(null);
|
||||
final Target updateTarget = targetManagement.update(TargetManagement.Update.builder().id(targetToUpdate.getId())
|
||||
.targetType(targetType)
|
||||
.name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress())
|
||||
.securityToken(targetRest.getSecurityToken())
|
||||
.requestControllerAttributes(targetRest.getRequestAttributes())
|
||||
.build());
|
||||
|
||||
final MgmtTarget response = MgmtTargetMapper.toResponse(updateTarget, tenantConfigHelper, null);
|
||||
MgmtTargetMapper.addTargetLinks(response);
|
||||
@@ -294,7 +296,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
log.debug("updateActionConfirmation with data [targetId={}, actionId={}]: {}", targetId, actionId, actionConfirmation);
|
||||
|
||||
return getValidatedAction(targetId, actionId)
|
||||
.<ResponseEntity<Void>>map(action -> {
|
||||
.<ResponseEntity<Void>> map(action -> {
|
||||
try {
|
||||
switch (actionConfirmation.getConfirmation()) {
|
||||
case CONFIRMED:
|
||||
@@ -471,7 +473,7 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
}
|
||||
|
||||
private Target findTargetWithExceptionIfNotFound(final String targetId) {
|
||||
return targetManagement.getByControllerID(targetId)
|
||||
return targetManagement.getByControllerId(targetId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(Target.class, targetId));
|
||||
}
|
||||
|
||||
|
||||
@@ -51,11 +51,11 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
|
||||
|
||||
private final TargetTagManagement<? extends TargetTag> tagManagement;
|
||||
private final TargetManagement targetManagement;
|
||||
private final TargetManagement<? extends Target> targetManagement;
|
||||
private final TenantConfigHelper tenantConfigHelper;
|
||||
|
||||
MgmtTargetTagResource(
|
||||
final TargetTagManagement<? extends TargetTag> tagManagement, final TargetManagement targetManagement,
|
||||
final TargetTagManagement<? extends TargetTag> tagManagement, final TargetManagement<? extends Target> targetManagement,
|
||||
final SystemSecurityContext securityContext, final TenantConfigurationManagement configurationManagement) {
|
||||
this.tagManagement = tagManagement;
|
||||
this.targetManagement = targetManagement;
|
||||
@@ -172,7 +172,7 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
|
||||
@AuditLog(entity = "TargetTag", type = AuditLog.Type.UPDATE, description = "Unassign Target From Target Tag")
|
||||
public ResponseEntity<Void> unassignTarget(final Long targetTagId, final String controllerId) {
|
||||
log.debug("Unassign target {} for target tag {}", controllerId, targetTagId);
|
||||
this.targetManagement.unassignTag(List.of(controllerId), targetTagId);
|
||||
targetManagement.unassignTag(List.of(controllerId), targetTagId);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@@ -182,10 +182,10 @@ public class MgmtTargetTagResource implements MgmtTargetTagRestApi {
|
||||
final Long targetTagId, final OnNotFoundPolicy onNotFoundPolicy, final List<String> controllerIds) {
|
||||
log.debug("Unassign {} targets for target tag {}", controllerIds.size(), targetTagId);
|
||||
if (onNotFoundPolicy == OnNotFoundPolicy.FAIL) {
|
||||
this.targetManagement.unassignTag(controllerIds, targetTagId);
|
||||
targetManagement.unassignTag(controllerIds, targetTagId);
|
||||
} else {
|
||||
final AtomicReference<Collection<String>> notFound = new AtomicReference<>();
|
||||
this.targetManagement.unassignTag(controllerIds, targetTagId, notFound::set);
|
||||
targetManagement.unassignTag(controllerIds, targetTagId, notFound::set);
|
||||
if (notFound.get() != null && onNotFoundPolicy == OnNotFoundPolicy.ON_WHAT_FOUND_AND_FAIL) {
|
||||
// has not found and ON_WHAT_FOUND_AND_FAIL
|
||||
throw new EntityNotFoundException(Target.class, notFound.get());
|
||||
|
||||
@@ -13,17 +13,18 @@ import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMaintenanceWindow;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtPollStatus;
|
||||
@@ -41,8 +42,9 @@ import org.eclipse.hawkbit.mgmt.rest.api.SortDirection;
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.ActionStatusFields;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
@@ -51,18 +53,27 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.PollStatus;
|
||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.rest.json.model.ResponseList;
|
||||
import org.eclipse.hawkbit.util.IpUtil;
|
||||
import org.eclipse.hawkbit.utils.TenantConfigHelper;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and back.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@Slf4j
|
||||
@Service
|
||||
public final class MgmtTargetMapper {
|
||||
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
|
||||
MgmtTargetMapper(final TargetTypeManagement<? extends TargetType> targetTypeManagement) {
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add links to a target response.
|
||||
*
|
||||
@@ -114,7 +125,7 @@ public final class MgmtTargetMapper {
|
||||
* @param targets list of targets
|
||||
* @return the response
|
||||
*/
|
||||
public static List<MgmtTarget> toResponse(final Collection<Target> targets, final TenantConfigHelper configHelper) {
|
||||
public static List<MgmtTarget> toResponse(final Collection<? extends Target> targets, final TenantConfigHelper configHelper) {
|
||||
if (targets == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -142,12 +153,17 @@ public final class MgmtTargetMapper {
|
||||
targetRest.setUpdateStatus(target.getUpdateStatus().name().toLowerCase());
|
||||
targetRest.setGroup(target.getGroup());
|
||||
|
||||
final URI address = target.getAddress();
|
||||
final String address = target.getAddress();
|
||||
if (address != null) {
|
||||
if (IpUtil.isIpAddresKnown(address)) {
|
||||
targetRest.setIpAddress(address.getHost());
|
||||
try {
|
||||
final URI addressURI = new URI(address);
|
||||
if (IpUtil.isIpAddresKnown(addressURI)) {
|
||||
targetRest.setIpAddress(addressURI.getHost());
|
||||
}
|
||||
} catch (final URISyntaxException e) {
|
||||
log.warn("Fail to parse address to URI: {}", e.getMessage());
|
||||
}
|
||||
targetRest.setAddress(address.toString());
|
||||
targetRest.setAddress(address);
|
||||
}
|
||||
|
||||
targetRest.setCreatedBy(target.getCreatedBy());
|
||||
@@ -184,12 +200,12 @@ public final class MgmtTargetMapper {
|
||||
return targetRest;
|
||||
}
|
||||
|
||||
public static List<TargetCreate> fromRequest(final EntityFactory entityFactory, final Collection<MgmtTargetRequestBody> targetsRest) {
|
||||
public List<Create> fromRequest(final Collection<MgmtTargetRequestBody> targetsRest) {
|
||||
if (targetsRest == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return targetsRest.stream().map(targetRest -> fromRequest(entityFactory, targetRest)).toList();
|
||||
return targetsRest.stream().map(this::fromRequest).toList();
|
||||
}
|
||||
|
||||
public static Map<String, String> fromRequestMetadata(final List<MgmtMetadata> metadata) {
|
||||
@@ -207,7 +223,7 @@ public final class MgmtTargetMapper {
|
||||
return actionStatus.stream()
|
||||
.map(status -> toResponse(status,
|
||||
deploymentManagement.findMessagesByActionStatusId(
|
||||
status.getId(), PageRequest.of(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT))
|
||||
status.getId(), PageRequest.of(0, MgmtRestConstants.REQUEST_PARAMETER_PAGING_MAX_LIMIT))
|
||||
.getContent()))
|
||||
.toList();
|
||||
}
|
||||
@@ -323,10 +339,18 @@ public final class MgmtTargetMapper {
|
||||
}
|
||||
}
|
||||
|
||||
private static TargetCreate fromRequest(final EntityFactory entityFactory, final MgmtTargetRequestBody targetRest) {
|
||||
return entityFactory.target().create().controllerId(targetRest.getControllerId()).name(targetRest.getName())
|
||||
private Create fromRequest(final MgmtTargetRequestBody targetRest) {
|
||||
return Create.builder()
|
||||
.controllerId(targetRest.getControllerId()).name(targetRest.getName())
|
||||
.description(targetRest.getDescription()).securityToken(targetRest.getSecurityToken())
|
||||
.address(targetRest.getAddress()).targetType(targetRest.getTargetType()).group(targetRest.getGroup());
|
||||
.address(targetRest.getAddress())
|
||||
.targetType(Optional.ofNullable(targetRest.getTargetType())
|
||||
.map(targetTypeId -> targetTypeManagement.get(targetTypeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId)))
|
||||
.map(TargetType.class::cast)
|
||||
.orElse(null))
|
||||
.group(targetRest.getGroup())
|
||||
.build();
|
||||
}
|
||||
|
||||
private static String getType(final Action action) {
|
||||
|
||||
@@ -17,6 +17,8 @@ import java.util.Map;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditionBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroupConditions;
|
||||
@@ -33,22 +35,22 @@ import org.springframework.util.CollectionUtils;
|
||||
@Slf4j
|
||||
class JsonBuilder {
|
||||
|
||||
static String targets(final List<Target> targets, final boolean withToken) throws JSONException {
|
||||
static String targets(final List<Create> creates, final boolean withToken) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final Target target : targets) {
|
||||
final String address = target.getAddress() != null ? target.getAddress().toString() : null;
|
||||
final String targetType = target.getTargetType() != null ? target.getTargetType().getId().toString() : null;
|
||||
final String token = withToken ? target.getSecurityToken() : null;
|
||||
for (final Create create : creates) {
|
||||
final String address = create.getAddress() != null ? create.getAddress() : null;
|
||||
final String targetType = create.getTargetType() != null ? create.getTargetType().getId().toString() : null;
|
||||
final String token = withToken ? create.getSecurityToken() : null;
|
||||
|
||||
builder.append(new JSONObject().put("controllerId", target.getControllerId())
|
||||
.put("description", target.getDescription()).put("name", target.getName()).put("createdAt", "0")
|
||||
builder.append(new JSONObject().put("controllerId", create.getControllerId())
|
||||
.put("description", create.getDescription()).put("name", create.getName()).put("createdAt", "0")
|
||||
.put("updatedAt", "0").put("createdBy", "systemtest").put("updatedBy", "systemtest")
|
||||
.put("address", address).put("securityToken", token).put("targetType", targetType).toString());
|
||||
|
||||
if (++i < targets.size()) {
|
||||
if (++i < creates.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
@@ -58,21 +60,21 @@ class JsonBuilder {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
static String targets(final List<Target> targets, final boolean withToken, final long targetTypeId) throws JSONException {
|
||||
static String targets(final List<Create> creates, final boolean withToken, final long targetTypeId) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final Target target : targets) {
|
||||
final String address = target.getAddress() != null ? target.getAddress().toString() : null;
|
||||
final String token = withToken ? target.getSecurityToken() : null;
|
||||
for (final Create create : creates) {
|
||||
final String address = create.getAddress() != null ? create.getAddress() : null;
|
||||
final String token = withToken ? create.getSecurityToken() : null;
|
||||
|
||||
builder.append(new JSONObject().put("controllerId", target.getControllerId())
|
||||
.put("description", target.getDescription()).put("name", target.getName()).put("createdAt", "0")
|
||||
builder.append(new JSONObject().put("controllerId", create.getControllerId())
|
||||
.put("description", create.getDescription()).put("name", create.getName()).put("createdAt", "0")
|
||||
.put("updatedAt", "0").put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh")
|
||||
.put("address", address).put("securityToken", token).put("targetType", targetTypeId).toString());
|
||||
|
||||
if (++i < targets.size()) {
|
||||
if (++i < creates.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
|
||||
@@ -1374,8 +1375,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
|
||||
// prepare targets
|
||||
final Collection<String> knownTargetIds = Arrays.asList("1", "2", "3", "4", "5");
|
||||
|
||||
knownTargetIds.forEach(
|
||||
controllerId -> targetManagement.create(entityFactory.target().create().controllerId(controllerId)));
|
||||
knownTargetIds.forEach(controllerId -> targetManagement.create(TargetManagement.Create.builder().controllerId(controllerId).build()));
|
||||
|
||||
// assign already one target to DS
|
||||
assignDistributionSet(createdDs.getId(), knownTargetIds.iterator().next());
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.eclipse.hawkbit.repository.TargetManagement.Create.*;
|
||||
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.put;
|
||||
@@ -32,9 +33,9 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
|
||||
void shouldRetrieveDistinctTargetGroups() throws Exception {
|
||||
|
||||
final List<String> expectedGroups = List.of("Europe", "Asia");
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target1").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target2").group("Asia"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target3").group("Europe"));
|
||||
targetManagement.create(builder().controllerId("target1").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("target2").group("Asia").build());
|
||||
targetManagement.create(builder().controllerId("target3").group("Europe").build());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -45,9 +46,9 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
|
||||
|
||||
@Test
|
||||
void shouldRetrieveTargetsFilteredByGroupAndParentGroupCorrectly() throws Exception {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target1").group("Europe/West"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target2").group("Europe/East"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target3").group("Europe"));
|
||||
targetManagement.create(builder().controllerId("target1").group("Europe/West").build());
|
||||
targetManagement.create(builder().controllerId("target2").group("Europe/East").build());
|
||||
targetManagement.create(builder().controllerId("target3").group("Europe").build());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/assigned")
|
||||
.param("group", "Europe/East")
|
||||
@@ -69,9 +70,9 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
|
||||
|
||||
@Test
|
||||
void shouldGetAssignedTargetsToSpecificGroup() throws Exception {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target1").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target2").group("US"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target3").group("Europe"));
|
||||
targetManagement.create(builder().controllerId("target1").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("target2").group("US").build());
|
||||
targetManagement.create(builder().controllerId("target3").group("Europe").build());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/Europe/assigned")
|
||||
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC"))
|
||||
@@ -83,9 +84,9 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
|
||||
|
||||
@Test
|
||||
void shouldAssignListOfTargetsToASpecificGroup() throws Exception {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target1").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target2"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target3").group("Europe"));
|
||||
targetManagement.create(builder().controllerId("target1").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("target2").build());
|
||||
targetManagement.create(builder().controllerId("target3").group("Europe").build());
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/newGroup/assigned")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
@@ -113,9 +114,9 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
|
||||
|
||||
@Test
|
||||
void shouldAssignListOfTargetsToProvidedGroupWithSubgroup() throws Exception {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target1").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target2"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target3").group("US"));
|
||||
targetManagement.create(builder().controllerId("target1").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("target2").build());
|
||||
targetManagement.create(builder().controllerId("target3").group("US").build());
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/assigned")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
@@ -143,9 +144,9 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
|
||||
|
||||
@Test
|
||||
void shouldAssignTargetsToProvidedGroupByRsql() throws Exception {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target1").group("A"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target2"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("shouldNotAssign").group("B"));
|
||||
targetManagement.create(builder().controllerId("target1").group("A").build());
|
||||
targetManagement.create(builder().controllerId("target2").build());
|
||||
targetManagement.create(builder().controllerId("shouldNotAssign").group("B").build());
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/C")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
@@ -164,8 +165,8 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
|
||||
|
||||
@Test
|
||||
void shouldUnassignTargetsFromGroup() throws Exception {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target1").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target2").group("Europe"));
|
||||
targetManagement.create(builder().controllerId("target1").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("target2").group("Europe").build());
|
||||
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/assigned")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
@@ -188,9 +189,9 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
|
||||
|
||||
@Test
|
||||
void shouldUnassignTargetsFromGroupByRsqlFilter() throws Exception {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target1").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target2").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("nonMatchingTarget").group("Europe"));
|
||||
targetManagement.create(builder().controllerId("target1").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("target2").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("nonMatchingTarget").group("Europe").build());
|
||||
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
@@ -208,11 +209,11 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
|
||||
|
||||
@Test
|
||||
void shouldUpdateTargetGroupsOfTargetsMatchingTheRsqlFilter() throws Exception {
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target1").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target2").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target3").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("shouldNotBeUpdated1").group("Europe"));
|
||||
targetManagement.create(entityFactory.target().create().controllerId("shouldNotBeUpdated2").group("Europe"));
|
||||
targetManagement.create(builder().controllerId("target1").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("target2").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("target3").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("shouldNotBeUpdated1").group("Europe").build());
|
||||
targetManagement.create(builder().controllerId("shouldNotBeUpdated2").group("Europe").build());
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING)
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
|
||||
@@ -31,7 +31,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@@ -55,7 +54,8 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
@@ -89,6 +89,7 @@ import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
@@ -153,13 +154,14 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String knownNameNotModify = "controllerName";
|
||||
final Long unassignTargetTypeValue = -1L;
|
||||
|
||||
final TargetType targetType = targetTypeManagement.create(Create.builder().name("targettype1").description("targettypedes1").build());
|
||||
final TargetType targetType = targetTypeManagement.create(
|
||||
TargetTypeManagement.Create.builder().name("targettype1").description("targettypedes1").build());
|
||||
|
||||
final String body = new JSONObject().put("targetType", unassignTargetTypeValue).toString();
|
||||
|
||||
// create a target with the created TargetType
|
||||
targetManagement.create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModify)
|
||||
.address(knownNewAddress).targetType(targetType.getId()));
|
||||
targetManagement.create(Create.builder().controllerId(knownControllerId).name(knownNameNotModify)
|
||||
.address(knownNewAddress).targetType(targetType).build());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -192,15 +194,16 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final Long unassignTargetTypeValue = -1L;
|
||||
final String controllerNewName = "controllerNewName";
|
||||
|
||||
final TargetType targetType = targetTypeManagement.create(Create.builder().name("targettype1").description("targettypedes1").build());
|
||||
final TargetType targetType = targetTypeManagement.create(
|
||||
TargetTypeManagement.Create.builder().name("targettype1").description("targettypedes1").build());
|
||||
|
||||
final String body = new JSONObject()
|
||||
.put("targetType", unassignTargetTypeValue).put("name", "controllerNewName")
|
||||
.toString();
|
||||
|
||||
// create a target with the created TargetType
|
||||
targetManagement.create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModify)
|
||||
.address(knownNewAddress).targetType(targetType.getId()));
|
||||
targetManagement.create(Create.builder().controllerId(knownControllerId).name(knownNameNotModify)
|
||||
.address(knownNewAddress).targetType(targetType).build());
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -616,7 +619,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
assertThat(targetManagement.getByControllerID(knownControllerId)).isNotPresent();
|
||||
assertThat(targetManagement.getByControllerId(knownControllerId)).isNotPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -653,8 +656,8 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String body = new JSONObject().put("description", knownNewDescription).toString();
|
||||
|
||||
// prepare
|
||||
targetManagement.create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModify)
|
||||
.description("old description"));
|
||||
targetManagement.create(
|
||||
Create.builder().controllerId(knownControllerId).name(knownNameNotModify).description("old description").build());
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -664,7 +667,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.description", equalTo(knownNewDescription)))
|
||||
.andExpect(jsonPath("$.name", equalTo(knownNameNotModify)));
|
||||
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerID(knownControllerId).get();
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerId(knownControllerId).get();
|
||||
assertThat(findTargetByControllerID.getDescription()).isEqualTo(knownNewDescription);
|
||||
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModify);
|
||||
}
|
||||
@@ -680,15 +683,15 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String body = new JSONObject().put("description", knownNewDescription).toString();
|
||||
|
||||
// prepare
|
||||
targetManagement.create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModify)
|
||||
.description("old description"));
|
||||
targetManagement.create(
|
||||
Create.builder().controllerId(knownControllerId).name(knownNameNotModify).description("old description").build());
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerID(knownControllerId).get();
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerId(knownControllerId).get();
|
||||
assertThat(findTargetByControllerID.getDescription()).isEqualTo("old description");
|
||||
}
|
||||
|
||||
@@ -703,8 +706,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String body = new JSONObject().put("securityToken", knownNewToken).toString();
|
||||
|
||||
// prepare
|
||||
targetManagement
|
||||
.create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModify));
|
||||
targetManagement.create(Create.builder().controllerId(knownControllerId).name(knownNameNotModify).build());
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -714,7 +716,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.securityToken", equalTo(knownNewToken)))
|
||||
.andExpect(jsonPath("$.name", equalTo(knownNameNotModify)));
|
||||
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerID(knownControllerId).get();
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerId(knownControllerId).get();
|
||||
assertThat(findTargetByControllerID.getSecurityToken()).isEqualTo(knownNewToken);
|
||||
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModify);
|
||||
}
|
||||
@@ -730,8 +732,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final String body = new JSONObject().put("address", knownNewAddress).toString();
|
||||
|
||||
// prepare
|
||||
targetManagement.create(entityFactory.target().create().controllerId(knownControllerId).name(knownNameNotModify)
|
||||
.address(knownNewAddress));
|
||||
targetManagement.create(Create.builder().controllerId(knownControllerId).name(knownNameNotModify).address(knownNewAddress).build());
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownControllerId).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
@@ -741,7 +742,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("$.address", equalTo(knownNewAddress)))
|
||||
.andExpect(jsonPath("$.name", equalTo(knownNameNotModify)));
|
||||
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerID(knownControllerId).get();
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerId(knownControllerId).get();
|
||||
assertThat(findTargetByControllerID.getAddress()).hasToString(knownNewAddress);
|
||||
assertThat(findTargetByControllerID.getName()).isEqualTo(knownNameNotModify);
|
||||
}
|
||||
@@ -1014,7 +1015,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
void createTargetWithEmptyNameAndLongControllerId() throws Exception {
|
||||
final String randomString = randomString(JpaTarget.CONTROLLER_ID_MAX_SIZE);
|
||||
|
||||
final Target target = entityFactory.target().create().controllerId(randomString).build();
|
||||
final Create target = Create.builder().controllerId(randomString).build();
|
||||
|
||||
final String targetList = JsonBuilder.targets(List.of(target), false);
|
||||
|
||||
@@ -1026,7 +1027,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("[0].controllerId", equalTo(randomString)))
|
||||
.andExpect(jsonPath("[0].name", equalTo(expectedTargetName)));
|
||||
|
||||
assertThat(targetManagement.getByControllerID(randomString).get().getName()).isEqualTo(expectedTargetName);
|
||||
assertThat(targetManagement.getByControllerId(randomString).get().getName()).isEqualTo(expectedTargetName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1099,12 +1100,11 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void createTargetWithInvalidPropertyBadRequest() throws Exception {
|
||||
final Target test1 = entityFactory.target().create().controllerId("id1")
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
final Create test1 = Create.builder().controllerId("id1").name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
|
||||
.content(JsonBuilder.targets(Collections.singletonList(test1), true))
|
||||
.content(JsonBuilder.targets(List.of(test1), true))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest())
|
||||
@@ -1124,14 +1124,14 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void createTargetsListReturnsSuccessful() throws Exception {
|
||||
final Target test1 = entityFactory.target().create().controllerId("id1").name("testname1")
|
||||
final Create test1 = Create.builder().controllerId("id1").name("testname1")
|
||||
.securityToken("token").address("amqp://test123/foobar").description("testid1").build();
|
||||
final Target test2 = entityFactory.target().create().controllerId("id2").name("testname2")
|
||||
final Create test2 = Create.builder().controllerId("id2").name("testname2")
|
||||
.description("testid2").build();
|
||||
final Target test3 = entityFactory.target().create().controllerId("id3").name("testname3")
|
||||
final Create test3 = Create.builder().controllerId("id3").name("testname3")
|
||||
.description("testid3").build();
|
||||
|
||||
final List<Target> targets = Arrays.asList(test1, test2, test3);
|
||||
final List<Create> targets = List.of(test1, test2, test3);
|
||||
|
||||
final MvcResult mvcResult = mvc
|
||||
.perform(post("/rest/v1/targets").content(JsonBuilder.targets(targets, true))
|
||||
@@ -1189,7 +1189,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().is2xxSuccessful());
|
||||
|
||||
final Slice<Target> findTargetsAll = targetManagement.findAll(PageRequest.of(0, 100));
|
||||
final Page<? extends Target> findTargetsAll = targetManagement.findAll(PageRequest.of(0, 100));
|
||||
final Target target = findTargetsAll.getContent().get(0);
|
||||
assertThat(targetManagement.count()).isEqualTo(1);
|
||||
assertThat(target.getControllerId()).isEqualTo(knownControllerId);
|
||||
@@ -1639,7 +1639,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
implicitLock(set);
|
||||
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
|
||||
target = targetManagement.getByControllerID(target.getControllerId()).get();
|
||||
target = targetManagement.getByControllerId(target.getControllerId()).get();
|
||||
|
||||
// repeating DS assignment leads again to OK
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + target.getControllerId() + "/assignedDS")
|
||||
@@ -1651,7 +1651,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("total", equalTo(1)));
|
||||
|
||||
// ...but does not change the target
|
||||
assertThat(targetManagement.getByControllerID(target.getControllerId()).get()).isEqualTo(target);
|
||||
assertThat(targetManagement.getByControllerId(target.getControllerId()).get()).isEqualTo(target);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1743,7 +1743,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId()).get()).isEqualTo(set);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(target.getControllerId()).get()).isEqualTo(set);
|
||||
target = targetManagement.getByControllerID(target.getControllerId()).get();
|
||||
target = targetManagement.getByControllerId(target.getControllerId()).get();
|
||||
assertThat(target.getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
// repeating DS assignment leads again to OK
|
||||
@@ -1757,7 +1757,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("total", equalTo(1)));
|
||||
|
||||
// ...but does not change the target
|
||||
assertThat(targetManagement.getByControllerID(target.getControllerId()).get()).isEqualTo(target);
|
||||
assertThat(targetManagement.getByControllerId(target.getControllerId()).get()).isEqualTo(target);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2460,15 +2460,15 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final TargetType type1 = testdataFactory.createTargetType("typeWithDs", Set.of(standardDsType));
|
||||
final TargetType type2 = testdataFactory.createTargetType("typeWithOutDs", Set.of(standardDsType));
|
||||
|
||||
final Target test1 = entityFactory.target().create().controllerId("id1").name("targetWithoutType")
|
||||
final Create test1 = Create.builder().controllerId("id1").name("targetWithoutType")
|
||||
.securityToken("token").address("amqp://test123/foobar").description("testid1").build();
|
||||
final Target test2 = entityFactory.target().create().controllerId("id2").name("targetOfType1")
|
||||
.targetType(type1.getId()).description("testid2").build();
|
||||
final Target test3 = entityFactory.target().create().controllerId("id3").name("targetOfType2")
|
||||
.targetType(type2.getId()).description("testid3").build();
|
||||
final Create test2 = Create.builder().controllerId("id2").name("targetOfType1")
|
||||
.targetType(type1).description("testid2").build();
|
||||
final Create test3 = Create.builder().controllerId("id3").name("targetOfType2")
|
||||
.targetType(type2).description("testid3").build();
|
||||
final String hrefType1 = "http://localhost/rest/v1/targettypes/" + type1.getId();
|
||||
|
||||
final List<Target> targets = Arrays.asList(test1, test2, test3);
|
||||
final List<Create> targets = List.of(test1, test2, test3);
|
||||
|
||||
mvc
|
||||
.perform(post("/rest/v1/targets").content(JsonBuilder.targets(targets, true))
|
||||
@@ -2530,10 +2530,9 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
final List<? extends TargetType> targetTypes = testdataFactory.createTargetTypes("targettype", 1);
|
||||
assertThat(targetTypes).hasSize(1);
|
||||
|
||||
final Target target = entityFactory.target().create().controllerId("targetcontroller").name("testtarget")
|
||||
.targetType(targetTypes.get(0).getId()).build();
|
||||
final Create target = Create.builder().controllerId("targetcontroller").name("testtarget").targetType(targetTypes.get(0)).build();
|
||||
|
||||
final String targetList = JsonBuilder.targets(Collections.singletonList(target), false);
|
||||
final String targetList = JsonBuilder.targets(List.of(target), false);
|
||||
|
||||
// test query target over rest resource
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING).content(targetList)
|
||||
@@ -2542,7 +2541,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andExpect(jsonPath("[0].controllerId", equalTo("targetcontroller")))
|
||||
.andExpect(jsonPath("[0].targetType", equalTo(targetTypes.get(0).getId().intValue())));
|
||||
|
||||
assertThat(targetManagement.getByControllerID("targetcontroller").get().getTargetType().getId())
|
||||
assertThat(targetManagement.getByControllerId("targetcontroller").get().getTargetType().getId())
|
||||
.isEqualTo(targetTypes.get(0).getId());
|
||||
}
|
||||
|
||||
@@ -2556,7 +2555,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
assertThat(targetTypes).hasSize(2);
|
||||
|
||||
final String controllerId = "targetcontroller";
|
||||
final Target target = testdataFactory.createTarget(controllerId, "testtarget", targetTypes.get(0).getId());
|
||||
final Target target = testdataFactory.createTarget(controllerId, "testtarget", targetTypes.get(0));
|
||||
|
||||
assertThat(target).isNotNull();
|
||||
assertThat(target.getTargetType().getId()).isEqualTo(targetTypes.get(0).getId());
|
||||
@@ -2583,13 +2582,12 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
assertThat(targetType).isNotPresent();
|
||||
|
||||
final String controllerId = "targetcontroller";
|
||||
final Target target = entityFactory.target().create().controllerId(controllerId).name("testtarget").build();
|
||||
final Create target = Create.builder().controllerId(controllerId).name("testtarget").build();
|
||||
|
||||
final String targetList = JsonBuilder.targets(Collections.singletonList(target), false, unknownTargetTypeId);
|
||||
final String targetList = JsonBuilder.targets(List.of(target), false, unknownTargetTypeId);
|
||||
|
||||
// post target over rest resource
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING).content(targetList)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING).content(targetList).contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isNotFound())
|
||||
.andExpect(jsonPath("message", Matchers.containsString(errorMsg)));
|
||||
}
|
||||
@@ -2614,7 +2612,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
assertThat(targetManagement.getByControllerID(targetControllerId).get().getTargetType().getId())
|
||||
assertThat(targetManagement.getByControllerId(targetControllerId).get().getTargetType().getId())
|
||||
.isEqualTo(targetType.getId());
|
||||
}
|
||||
|
||||
@@ -2663,8 +2661,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
assertThat(targetTypes).hasSize(1);
|
||||
|
||||
final String targetControllerId = "targetcontroller";
|
||||
final Target target = testdataFactory.createTarget(targetControllerId, "testtarget",
|
||||
targetTypes.get(0).getId());
|
||||
final Target target = testdataFactory.createTarget(targetControllerId, "testtarget", targetTypes.get(0));
|
||||
|
||||
assertThat(target).isNotNull();
|
||||
assertThat(target.getTargetType().getId()).isEqualTo(targetTypes.get(0).getId());
|
||||
@@ -2674,7 +2671,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
|
||||
assertThat(targetManagement.getByControllerID(targetControllerId).get().getTargetType()).isNull();
|
||||
assertThat(targetManagement.getByControllerId(targetControllerId).get().getTargetType()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2874,12 +2871,11 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
}
|
||||
|
||||
private void createTarget(final String controllerId) {
|
||||
targetManagement.create(entityFactory.target().create().controllerId(controllerId)
|
||||
.address(IpUtil.createHttpUri("127.0.0.1").toString()));
|
||||
targetManagement.create(Create.builder().controllerId(controllerId).address(IpUtil.createHttpUri("127.0.0.1").toString()).build());
|
||||
}
|
||||
|
||||
private Target assertTarget(final String controllerId, final String name, final String description) {
|
||||
final Optional<Target> target1 = targetManagement.getByControllerID(controllerId);
|
||||
final Optional<Target> target1 = targetManagement.getByControllerId(controllerId);
|
||||
assertThat(target1).isPresent();
|
||||
final Target t = target1.get();
|
||||
assertThat(t.getName()).isEqualTo(name);
|
||||
@@ -3020,7 +3016,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
}
|
||||
|
||||
private Target createSingleTarget(final String controllerId, final String name) {
|
||||
targetManagement.create(entityFactory.target().create().controllerId(controllerId).name(name).description(TARGET_DESCRIPTION_TEST));
|
||||
targetManagement.create(Create.builder().controllerId(controllerId).name(name).description(TARGET_DESCRIPTION_TEST).build());
|
||||
return controllerManagement.findOrRegisterTargetIfItDoesNotExist(controllerId, LOCALHOST);
|
||||
}
|
||||
|
||||
@@ -3034,7 +3030,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
char character = 'a';
|
||||
for (int index = 0; index < amount; index++) {
|
||||
final String str = String.valueOf(character);
|
||||
targetManagement.create(entityFactory.target().create().controllerId(str).name(str).description(str));
|
||||
targetManagement.create(Create.builder().controllerId(str).name(str).description(str).build());
|
||||
controllerManagement.findOrRegisterTargetIfItDoesNotExist(str, LOCALHOST);
|
||||
character++;
|
||||
}
|
||||
@@ -3054,7 +3050,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
// verify active action
|
||||
final Slice<Action> actionsByTarget = deploymentManagement.findActionsByTarget(tA.getControllerId(), PAGE);
|
||||
assertThat(actionsByTarget.getContent()).hasSize(1);
|
||||
return targetManagement.getByControllerID(tA.getControllerId()).get();
|
||||
return targetManagement.getByControllerId(tA.getControllerId()).get();
|
||||
}
|
||||
|
||||
private void setupTargetWithMetadata(final String knownControllerId, final String knownKey, final String knownValue) {
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.eclipse.hawkbit.exception.SpServerError;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
@@ -458,8 +459,8 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
String typeName = "TestTypeUsedDelete";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target").name("TargetOfTestType")
|
||||
.description("target description").targetType(testType.getId()));
|
||||
targetManagement.create(TargetManagement.Create.builder()
|
||||
.controllerId("target").name("TargetOfTestType").description("target description").targetType(testType).build());
|
||||
|
||||
assertThat(targetTypeManagement.count()).isEqualTo(1);
|
||||
assertThat(targetManagement.count()).isEqualTo(1);
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
|
||||
/**
|
||||
@@ -20,11 +19,6 @@ import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
*/
|
||||
public interface EntityFactory {
|
||||
|
||||
/**
|
||||
* @return {@link TargetBuilder} object
|
||||
*/
|
||||
TargetBuilder target();
|
||||
|
||||
/**
|
||||
* @return {@link ActionStatusBuilder} object
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
* Copyright (c) 2025 Contributors to the Eclipse Foundation
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.model.helper;
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit.repository;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.BRACKET_CLOSE;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.BRACKET_OPEN;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_AND;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_CREATE_TARGET;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_DELETE_TARGET;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_PREFIX;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_UPDATE_TARGET;
|
||||
@@ -28,15 +27,17 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.im.authentication.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
@@ -44,6 +45,7 @@ import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.RolloutGroup;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
@@ -55,16 +57,17 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Management service for {@link Target}s.
|
||||
*/
|
||||
public interface TargetManagement extends PermissionSupport {
|
||||
public interface TargetManagement<T extends Target>
|
||||
extends RepositoryManagement<T, TargetManagement.Create, TargetManagement.Update> {
|
||||
|
||||
String DETAILS_BASE = "base";
|
||||
String DETAILS_AUTO_CONFIRMATION_STATUS = "autoConfirmationStatus";
|
||||
String DETAILS_TAGS = "tags";
|
||||
String DETAILS_ACTIONS = "actions";
|
||||
|
||||
String HAS_AUTH_READ_DISTRIBUTION_SET_AND_READ_TARGET = BRACKET_OPEN +
|
||||
HAS_AUTH_PREFIX + SpPermission.READ_DISTRIBUTION_SET + HAS_AUTH_SUFFIX +
|
||||
@@ -119,15 +122,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_READ_DISTRIBUTION_SET_AND_READ_TARGET)
|
||||
boolean existsByInstalledOrAssignedDistributionSet(long distributionSetId);
|
||||
|
||||
/**
|
||||
* Count {@link TargetFilterQuery}s for given target filter query.
|
||||
*
|
||||
* @param rsql filter definition in RSQL syntax
|
||||
* @return the found number of {@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long countByRsql(@NotEmpty String rsql);
|
||||
|
||||
/**
|
||||
* Count {@link TargetFilterQuery}s for given target filter query with UPDATE permission.
|
||||
*
|
||||
@@ -149,18 +143,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long countByRsqlAndCompatible(@NotEmpty String rsql, @NotNull Long distributionSetIdTypeId);
|
||||
|
||||
/**
|
||||
* Count all targets for given {@link TargetFilterQuery} and that are compatible
|
||||
* with the passed {@link DistributionSetType} and UPDATE permission.
|
||||
*
|
||||
* @param rsql filter definition in RSQL syntax
|
||||
* @param distributionSetIdTypeId ID of the {@link DistributionSetType} the targets need to be
|
||||
* compatible with
|
||||
* @return the found number of{@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long countByRsqlAndCompatibleAndUpdatable(@NotEmpty String rsql, @NotNull Long distributionSetIdTypeId);
|
||||
|
||||
/**
|
||||
* Count all targets with failed actions for specific Rollout and that are
|
||||
* compatible with the passed {@link DistributionSetType} and created after
|
||||
@@ -184,48 +166,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long countByTargetFilterQuery(long targetFilterQueryId);
|
||||
|
||||
/**
|
||||
* Counts all {@link Target}s in the repository.
|
||||
*
|
||||
* @return number of targets
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
long count();
|
||||
|
||||
/**
|
||||
* creating a new {@link Target}.
|
||||
*
|
||||
* @param create to be created
|
||||
* @return the created {@link Target}
|
||||
* @throws EntityAlreadyExistsException given target already exists.
|
||||
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link TargetCreate} for field constraints.
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_CREATE_TARGET)
|
||||
Target create(@NotNull @Valid TargetCreate create);
|
||||
|
||||
/**
|
||||
* creates multiple {@link Target}s. If the given {@link Target}s already exists
|
||||
* in the DB an {@link EntityAlreadyExistsException} is thrown. {@link Target}s
|
||||
* contain all objects of the parameter targets, including duplicates.
|
||||
*
|
||||
* @param creates to be created.
|
||||
* @return the created {@link Target}s
|
||||
* @throws EntityAlreadyExistsException of one of the given targets already exist.
|
||||
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link TargetCreate}
|
||||
* for field constraints.
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_CREATE_TARGET)
|
||||
List<Target> create(@NotNull @Valid Collection<TargetCreate> creates);
|
||||
|
||||
/**
|
||||
* Deletes all targets with the given IDs.
|
||||
*
|
||||
* @param ids the IDs of the targets to be deleted
|
||||
* @throws EntityNotFoundException if (at least one) of the given target IDs does not exist
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_DELETE_TARGET)
|
||||
void delete(@NotEmpty Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* Deletes target with the given controller ID.
|
||||
*
|
||||
@@ -372,7 +312,7 @@ public interface TargetManagement extends PermissionSupport {
|
||||
* @return List of found{@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
List<Target> getByControllerID(@NotEmpty Collection<String> controllerIDs);
|
||||
List<Target> getByControllerId(@NotEmpty Collection<String> controllerIDs);
|
||||
|
||||
/**
|
||||
* Find a {@link Target} based a given ID.
|
||||
@@ -381,7 +321,7 @@ public interface TargetManagement extends PermissionSupport {
|
||||
* @return {@link Target}
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Optional<Target> getByControllerID(@NotEmpty String controllerId);
|
||||
Optional<Target> getByControllerId(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* Gets a {@link Target} based a given controller id and includes the details specified by the details key.
|
||||
@@ -408,11 +348,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
return getWithDetails(controllerId, DETAILS_TAGS);
|
||||
}
|
||||
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
default Target getWithActions(@NotEmpty String controllerId) {
|
||||
return getWithDetails(controllerId, DETAILS_ACTIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter {@link Target}s for all the given parameters. If all parameters except
|
||||
* pageable are null, all available {@link Target}s are returned.
|
||||
@@ -463,28 +398,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Page<Target> findByUpdateStatus(@NotNull TargetUpdateStatus status, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all targets.
|
||||
*
|
||||
* @param pageable pagination parameter
|
||||
* @return the found {@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Slice<Target> findAll(@NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all targets.
|
||||
*
|
||||
* @param rsql in RSQL notation
|
||||
* @param pageable pagination parameter
|
||||
* @return the found {@link Target}s, never {@code null}
|
||||
* @throws RSQLParameterUnsupportedFieldException if a field in the RSQL string is used but not provided by the
|
||||
* given {@code fieldNameProvider}
|
||||
* @throws RSQLParameterSyntaxException if the RSQL syntax is wrong
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Slice<Target> findByRsql(@NotNull String rsql, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Retrieves all target based on {@link TargetFilterQuery}.
|
||||
*
|
||||
@@ -627,6 +540,7 @@ public interface TargetManagement extends PermissionSupport {
|
||||
|
||||
/**
|
||||
* Finds targets by group or subgroup.
|
||||
*
|
||||
* @param group - provided group/subgroup to filter for
|
||||
* @param withSubgroups - whether is a subgroup or not e.g. x/y/z
|
||||
* @param pageable - page parameter
|
||||
@@ -634,6 +548,7 @@ public interface TargetManagement extends PermissionSupport {
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Page<Target> findTargetsByGroup(@NotEmpty String group, boolean withSubgroups, @NotNull Pageable pageable);
|
||||
|
||||
/**
|
||||
* Finds all the distinct target groups in the scope of a tenant
|
||||
*
|
||||
@@ -660,36 +575,6 @@ public interface TargetManagement extends PermissionSupport {
|
||||
@PreAuthorize(HAS_AUTH_UPDATE_TARGET)
|
||||
void assignTargetsWithGroup(String group, @NotEmpty List<String> controllerIds);
|
||||
|
||||
/**
|
||||
* updates the {@link Target}.
|
||||
*
|
||||
* @param update to be updated
|
||||
* @return the updated {@link Target}
|
||||
* @throws EntityNotFoundException if given target does not exist
|
||||
* @throws ConstraintViolationException if fields are not filled as specified. Check {@link TargetUpdate}
|
||||
* for field constraints.
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_UPDATE_TARGET)
|
||||
Target update(@NotNull @Valid TargetUpdate update);
|
||||
|
||||
/**
|
||||
* Find a {@link Target} based a given ID.
|
||||
*
|
||||
* @param id to look for
|
||||
* @return {@link Target}
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
Optional<Target> get(long id);
|
||||
|
||||
/**
|
||||
* Retrieves all targets.
|
||||
*
|
||||
* @param ids the ids to for
|
||||
* @return the found {@link Target}s
|
||||
*/
|
||||
@PreAuthorize(HAS_AUTH_READ_TARGET)
|
||||
List<Target> get(@NotNull Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* Verifies that {@link Target} with given controller ID exists in the repository.
|
||||
*
|
||||
@@ -801,4 +686,85 @@ public interface TargetManagement extends PermissionSupport {
|
||||
*/
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_UPDATE_REPOSITORY)
|
||||
void deleteMetadata(@NotNull String controllerId, @NotEmpty String key);
|
||||
|
||||
@SuperBuilder
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
final class Create extends UpdateCreate {
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = Target.CONTROLLER_ID_MAX_SIZE)
|
||||
@NotNull
|
||||
private String controllerId;
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
|
||||
@NotNull(groups = Create.class)
|
||||
private String name;
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = Target.SECURITY_TOKEN_MAX_SIZE)
|
||||
@NotNull
|
||||
@ToString.Exclude
|
||||
private String securityToken;
|
||||
|
||||
// java:S1144 - constructor is actually used by SuperBuilder's build() method
|
||||
// java:S3358 - better readable that way
|
||||
@SuppressWarnings({ "java:S1144", "java:S3358" })
|
||||
private Create(final CreateBuilder<?, ?> builder) {
|
||||
super(builder);
|
||||
controllerId = builder.controllerId;
|
||||
// truncate controller ID to max name length (if too big)
|
||||
name = ObjectUtils.isEmpty(builder.name)
|
||||
? controllerId != null && controllerId.length() > NamedEntity.NAME_MAX_SIZE
|
||||
? controllerId.substring(0, NamedEntity.NAME_MAX_SIZE)
|
||||
: controllerId
|
||||
: builder.name;
|
||||
securityToken = ObjectUtils.isEmpty(builder.securityToken)
|
||||
? SecurityTokenGeneratorHolder.getInstance().generateToken()
|
||||
: builder.securityToken;
|
||||
}
|
||||
}
|
||||
|
||||
@SuperBuilder
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
final class Update extends UpdateCreate implements Identifiable<Long> {
|
||||
|
||||
@NotNull
|
||||
private Long id;
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
|
||||
private String name;
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = Target.SECURITY_TOKEN_MAX_SIZE)
|
||||
@ToString.Exclude
|
||||
private String securityToken;
|
||||
|
||||
private Boolean requestControllerAttributes;
|
||||
}
|
||||
|
||||
@SuperBuilder
|
||||
@Getter
|
||||
class UpdateCreate {
|
||||
|
||||
@ValidString
|
||||
@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE)
|
||||
private String description;
|
||||
|
||||
private TargetType targetType;
|
||||
|
||||
@Size(max = Target.ADDRESS_MAX_SIZE)
|
||||
private String address;
|
||||
|
||||
private Long lastTargetQuery;
|
||||
private TargetUpdateStatus updateStatus;
|
||||
|
||||
@ValidString
|
||||
private String group;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,6 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
@@ -19,11 +16,9 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.eclipse.hawkbit.im.authentication.SpringEvalExpressions;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.TargetTag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
/**
|
||||
* Management service for {@link TargetTag}s.
|
||||
@@ -58,7 +53,7 @@ public interface TargetTagManagement<T extends TargetTag>
|
||||
|
||||
@ValidString
|
||||
@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE)
|
||||
@NotNull(groups = DistributionSetTagManagement.Create.class)
|
||||
@NotNull(groups = Create.class)
|
||||
private String name;
|
||||
|
||||
@ValidString
|
||||
|
||||
@@ -35,8 +35,6 @@ import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.model.Type;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
/**
|
||||
@@ -112,7 +110,7 @@ public interface TargetTypeManagement<T extends TargetType>
|
||||
}
|
||||
key = builder.key == null ? builder.name : builder.key;
|
||||
name = builder.name == null ? builder.key : builder.name;
|
||||
this.distributionSetTypes = builder.distributionSetTypes == null ? Collections.emptySet() : builder.distributionSetTypes;
|
||||
distributionSetTypes = builder.distributionSetTypes == null ? Collections.emptySet() : builder.distributionSetTypes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
|
||||
/**
|
||||
* Builder for {@link Target}.
|
||||
*/
|
||||
public interface TargetBuilder {
|
||||
|
||||
/**
|
||||
* @param controllerId of the updatable entity
|
||||
* @return builder instance
|
||||
*/
|
||||
TargetUpdate update(@NotEmpty String controllerId);
|
||||
|
||||
/**
|
||||
* @return builder instance
|
||||
*/
|
||||
TargetCreate create();
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.BaseEntity;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
|
||||
/**
|
||||
* Builder to create a new {@link Target} entry. Defines all fields that can be
|
||||
* set at creation time. Other fields are set by the repository automatically,
|
||||
* e.g. {@link BaseEntity#getCreatedAt()}.
|
||||
*/
|
||||
public interface TargetCreate {
|
||||
|
||||
/**
|
||||
* @param controllerId for {@link Target#getControllerId()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate controllerId(@Size(min = 1, max = Target.CONTROLLER_ID_MAX_SIZE) @NotNull String controllerId);
|
||||
|
||||
/**
|
||||
* @param name for {@link Target#getName()} filled with {@link #controllerId(String)} as default if not set explicitly
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate name(@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE) @NotNull String name);
|
||||
|
||||
/**
|
||||
* @param description for {@link Target#getDescription()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
|
||||
|
||||
/**
|
||||
* @param targetTypeId for {@link Target#getTargetType()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate targetType(Long targetTypeId);
|
||||
|
||||
/**
|
||||
* @param securityToken for {@link Target#getSecurityToken()} is generated with a random sequence as default if not set explicitly
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate securityToken(@Size(min = 1, max = Target.SECURITY_TOKEN_MAX_SIZE) @NotNull String securityToken);
|
||||
|
||||
/**
|
||||
* @param address for {@link Target#getAddress()}
|
||||
* @return updated builder instance
|
||||
* @throws IllegalArgumentException If the given string violates RFC 2396
|
||||
*/
|
||||
TargetCreate address(@Size(max = Target.ADDRESS_MAX_SIZE) String address);
|
||||
|
||||
/**
|
||||
* @param lastTargetQuery for {@link Target#getLastTargetQuery()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate lastTargetQuery(Long lastTargetQuery);
|
||||
|
||||
/**
|
||||
* @param status for {@link Target#getUpdateStatus()} is {@link TargetUpdateStatus#UNKNOWN} as default if not set explicitly
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate status(@NotNull TargetUpdateStatus status);
|
||||
|
||||
/**
|
||||
* @param group for setting the group of the target
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetCreate group(String group);
|
||||
|
||||
/**
|
||||
* @return peek on current state of {@link Target} in the builder
|
||||
*/
|
||||
Target build();
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
|
||||
/**
|
||||
* Builder to update an existing {@link Target} entry. Defines all fields that
|
||||
* can be updated.
|
||||
*/
|
||||
public interface TargetUpdate {
|
||||
|
||||
/**
|
||||
* @param name for {@link Target#getName()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate name(@Size(min = 1, max = NamedEntity.NAME_MAX_SIZE) @NotNull String name);
|
||||
|
||||
/**
|
||||
* @param description for {@link Target#getDescription()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate description(@Size(max = NamedEntity.DESCRIPTION_MAX_SIZE) String description);
|
||||
|
||||
/**
|
||||
* @param securityToken for {@link Target#getSecurityToken()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate securityToken(@Size(min = 1, max = Target.SECURITY_TOKEN_MAX_SIZE) @NotNull String securityToken);
|
||||
|
||||
/**
|
||||
* @param targetTypeId for {@link Target#getTargetType()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate targetType(@NotNull Long targetTypeId);
|
||||
|
||||
/**
|
||||
* @param address for {@link Target#getAddress()}
|
||||
* @return updated builder instance
|
||||
* @throws IllegalArgumentException If the given string violates RFC 2396
|
||||
*/
|
||||
TargetUpdate address(@Size(max = Target.ADDRESS_MAX_SIZE) String address);
|
||||
|
||||
/**
|
||||
* @param lastTargetQuery for {@link Target#getLastTargetQuery()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate lastTargetQuery(Long lastTargetQuery);
|
||||
|
||||
/**
|
||||
* @param status for {@link Target#getUpdateStatus()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate status(@NotNull TargetUpdateStatus status);
|
||||
|
||||
/**
|
||||
* @param requestAttributes for {@link Target#isRequestControllerAttributes()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate requestAttributes(Boolean requestAttributes);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param group for {@link Target#getGroup()}
|
||||
* @return updated builder instance
|
||||
*/
|
||||
TargetUpdate group(String group);
|
||||
}
|
||||
@@ -9,18 +9,15 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.model;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* The {@link Target} is the target of all provisioning operations. It contains
|
||||
* the currently installed {@link DistributionSet} (i.e. current state). In
|
||||
* addition it holds the target {@link DistributionSet} that has to be
|
||||
* provisioned next (i.e. target state).
|
||||
* </p>
|
||||
* The {@link Target} is the target of all provisioning operations. It contains the currently installed {@link DistributionSet}
|
||||
* (i.e. current state). In addition, it holds the target {@link DistributionSet} that has to be provisioned next (i.e. target state).
|
||||
*/
|
||||
public interface Target extends NamedEntity {
|
||||
public interface Target extends NamedEntity, Identifiable<Long> {
|
||||
|
||||
/**
|
||||
* Maximum length of controllerId.
|
||||
@@ -79,7 +76,7 @@ public interface Target extends NamedEntity {
|
||||
/**
|
||||
* @return the address under which the target can be reached
|
||||
*/
|
||||
URI getAddress();
|
||||
String getAddress();
|
||||
|
||||
/**
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when the {@link Target} polled the server the last time or <code>null</code> if target
|
||||
@@ -88,8 +85,7 @@ public interface Target extends NamedEntity {
|
||||
Long getLastTargetQuery();
|
||||
|
||||
/**
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when
|
||||
* {@link #getInstalledDistributionSet()} was applied.
|
||||
* @return time in {@link TimeUnit#MILLISECONDS} GMT when {@link #getInstalledDistributionSet()} was applied.
|
||||
*/
|
||||
Long getInstallationDate();
|
||||
|
||||
@@ -104,10 +100,8 @@ public interface Target extends NamedEntity {
|
||||
TargetType getTargetType();
|
||||
|
||||
/**
|
||||
* @return the poll time which holds the last poll time of the target, the
|
||||
* next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled
|
||||
* before this method returns {@code null}
|
||||
* @return the poll time which holds the last poll time of the target, the next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled before this method returns {@code null}
|
||||
*/
|
||||
PollStatus getPollStatus();
|
||||
|
||||
@@ -120,8 +114,7 @@ public interface Target extends NamedEntity {
|
||||
AutoConfirmationStatus getAutoConfirmationStatus();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if the {@link Target} has not jet provided
|
||||
* {@link #getControllerAttributes()}.
|
||||
* @return <code>true</code> if the {@link Target} has not yet provided {@link #getControllerAttributes()}.
|
||||
*/
|
||||
boolean isRequestControllerAttributes();
|
||||
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
*
|
||||
* @param <T> update or create builder interface
|
||||
*/
|
||||
public abstract class AbstractMetadataUpdateCreate<T> {
|
||||
|
||||
@ValidString
|
||||
@Getter
|
||||
protected String key;
|
||||
@ValidString
|
||||
protected String value;
|
||||
|
||||
public T key(final String key) {
|
||||
this.key = AbstractBaseEntityBuilder.strip(key);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T value(final String value) {
|
||||
this.value = AbstractBaseEntityBuilder.strip(value);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getValue() {
|
||||
return Optional.ofNullable(value);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
*
|
||||
* @param <T> update or create builder interface
|
||||
*/
|
||||
public abstract class AbstractSoftwareModuleMetadataUpdateCreate<T> extends AbstractMetadataUpdateCreate<T> {
|
||||
|
||||
protected Boolean targetVisible;
|
||||
protected long softwareModuleId;
|
||||
|
||||
public T softwareModuleId(final long softwareModuleId) {
|
||||
this.softwareModuleId = softwareModuleId;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public long getSoftwareModuleId() {
|
||||
return softwareModuleId;
|
||||
}
|
||||
|
||||
public Optional<Boolean> isTargetVisible() {
|
||||
return Optional.ofNullable(targetVisible);
|
||||
}
|
||||
|
||||
public T targetVisible(final Boolean targetVisible) {
|
||||
this.targetVisible = targetVisible;
|
||||
return (T) this;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
*
|
||||
* @param <T> update or create builder interface
|
||||
*/
|
||||
public class AbstractTagUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
|
||||
|
||||
@ValidString
|
||||
protected String colour;
|
||||
|
||||
public T colour(final String colour) {
|
||||
this.colour = AbstractBaseEntityBuilder.strip(colour);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getColour() {
|
||||
return Optional.ofNullable(colour);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
*
|
||||
* @param <T> update or create builder interface
|
||||
*/
|
||||
public abstract class AbstractTargetTypeUpdateCreate<T> extends AbstractTypeUpdateCreate<T> {
|
||||
|
||||
protected Collection<Long> compatible;
|
||||
|
||||
/**
|
||||
* @param compatible list of ID
|
||||
* @return generic type
|
||||
*/
|
||||
public T compatible(final Collection<Long> compatible) {
|
||||
this.compatible = compatible;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return List of ID
|
||||
*/
|
||||
public Optional<Collection<Long>> getCompatible() {
|
||||
return Optional.ofNullable(compatible);
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.ToString;
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidTargetAddressException;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
*
|
||||
* @param <T> update or create builder interface
|
||||
*/
|
||||
public class AbstractTargetUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
|
||||
|
||||
@ValidString
|
||||
protected String controllerId;
|
||||
protected String address;
|
||||
@ToString.Exclude
|
||||
@ValidString
|
||||
protected String securityToken;
|
||||
protected Long lastTargetQuery;
|
||||
protected TargetUpdateStatus status;
|
||||
protected Boolean requestAttributes;
|
||||
protected Long targetTypeId;
|
||||
protected String group;
|
||||
|
||||
protected AbstractTargetUpdateCreate(final String controllerId) {
|
||||
this.controllerId = AbstractBaseEntityBuilder.strip(controllerId);
|
||||
}
|
||||
|
||||
public T status(final TargetUpdateStatus status) {
|
||||
this.status = status;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T address(final String address) {
|
||||
// check if this is a real URI
|
||||
if (address != null) {
|
||||
try {
|
||||
URI.create(AbstractBaseEntityBuilder.strip(address));
|
||||
} catch (final IllegalArgumentException e) {
|
||||
throw new InvalidTargetAddressException(
|
||||
"The given address " + address + " violates the RFC-2396 specification", e);
|
||||
}
|
||||
}
|
||||
this.address = address;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T securityToken(final String securityToken) {
|
||||
this.securityToken = AbstractBaseEntityBuilder.strip(securityToken);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T requestAttributes(final Boolean requestAttributes) {
|
||||
this.requestAttributes = requestAttributes;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T lastTargetQuery(final Long lastTargetQuery) {
|
||||
this.lastTargetQuery = lastTargetQuery;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public TargetCreate controllerId(final String controllerId) {
|
||||
this.controllerId = AbstractBaseEntityBuilder.strip(controllerId);
|
||||
return (TargetCreate) this;
|
||||
}
|
||||
|
||||
public T targetType(final Long targetTypeId) {
|
||||
this.targetTypeId = targetTypeId;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public T group(final String group) {
|
||||
this.group = group;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public String getControllerId() {
|
||||
return controllerId;
|
||||
}
|
||||
|
||||
public Optional<String> getAddress() {
|
||||
return Optional.ofNullable(address);
|
||||
}
|
||||
|
||||
public Optional<String> getSecurityToken() {
|
||||
return Optional.ofNullable(securityToken);
|
||||
}
|
||||
|
||||
public Optional<Long> getLastTargetQuery() {
|
||||
return Optional.ofNullable(lastTargetQuery);
|
||||
}
|
||||
|
||||
public Optional<TargetUpdateStatus> getStatus() {
|
||||
return Optional.ofNullable(status);
|
||||
}
|
||||
|
||||
public Long getTargetTypeId() {
|
||||
return targetTypeId;
|
||||
}
|
||||
|
||||
public Optional<String> getGroup() { return Optional.ofNullable(group); }
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2023 Bosch.IO GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.builder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ValidString;
|
||||
|
||||
/**
|
||||
* Create and update builder DTO.
|
||||
*
|
||||
* @param <T> update or create builder interface
|
||||
*/
|
||||
public abstract class AbstractTypeUpdateCreate<T> extends AbstractNamedEntityBuilder<T> {
|
||||
|
||||
@ValidString
|
||||
protected String colour;
|
||||
@ValidString
|
||||
protected String key;
|
||||
|
||||
public T colour(final String colour) {
|
||||
this.colour = AbstractBaseEntityBuilder.strip(colour);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getColour() {
|
||||
return Optional.ofNullable(colour);
|
||||
}
|
||||
|
||||
public T key(final String key) {
|
||||
this.key = AbstractBaseEntityBuilder.strip(key);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public Optional<String> getKey() {
|
||||
return Optional.ofNullable(key);
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.ActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutGroupBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaActionStatusBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutGroupBuilder;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -24,21 +23,13 @@ import org.springframework.validation.annotation.Validated;
|
||||
@Validated
|
||||
public class JpaEntityFactory implements EntityFactory {
|
||||
|
||||
private final TargetBuilder targetBuilder;
|
||||
private final RolloutBuilder rolloutBuilder;
|
||||
|
||||
@SuppressWarnings("java:S107")
|
||||
public JpaEntityFactory(
|
||||
final TargetBuilder targetBuilder, final RolloutBuilder rolloutBuilder) {
|
||||
this.targetBuilder = targetBuilder;
|
||||
public JpaEntityFactory(final RolloutBuilder rolloutBuilder) {
|
||||
this.rolloutBuilder = rolloutBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetBuilder target() {
|
||||
return targetBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionStatusBuilder actionStatus() {
|
||||
return new JpaActionStatusBuilder();
|
||||
|
||||
@@ -36,14 +36,12 @@ import org.eclipse.hawkbit.repository.RolloutStatusCache;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryption;
|
||||
import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryptionSecretsStore;
|
||||
import org.eclipse.hawkbit.repository.artifact.encryption.ArtifactEncryptionService;
|
||||
import org.eclipse.hawkbit.repository.autoassign.AutoAssignExecutor;
|
||||
import org.eclipse.hawkbit.repository.builder.RolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
|
||||
import org.eclipse.hawkbit.repository.event.remote.EventEntityManager;
|
||||
import org.eclipse.hawkbit.repository.event.remote.EventEntityManagerHolder;
|
||||
@@ -56,7 +54,6 @@ import org.eclipse.hawkbit.repository.jpa.autocleanup.AutoActionCleanup;
|
||||
import org.eclipse.hawkbit.repository.jpa.autocleanup.AutoCleanupScheduler;
|
||||
import org.eclipse.hawkbit.repository.jpa.autocleanup.CleanupTask;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaRolloutBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.jpa.cluster.DistributedLockRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.cluster.LockProperties;
|
||||
import org.eclipse.hawkbit.repository.jpa.event.JpaEventEntityManager;
|
||||
@@ -73,7 +70,7 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetType;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.AfterTransactionCommitExecutorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantAwareHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
|
||||
import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository;
|
||||
@@ -99,8 +96,8 @@ 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.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder;
|
||||
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
||||
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
||||
@@ -300,11 +297,6 @@ public class JpaRepositoryConfiguration {
|
||||
return e -> e instanceof TargetPollEvent && !repositoryProperties.isPublishTargetPollEvent();
|
||||
}
|
||||
|
||||
@Bean
|
||||
TargetBuilder targetBuilder(final TargetTypeManagement<? extends TargetType> targetTypeManagement) {
|
||||
return new JpaTargetBuilder(targetTypeManagement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param distributionSetManagement for loading {@link Rollout#getDistributionSet()}
|
||||
* @return RolloutBuilder bean
|
||||
@@ -391,7 +383,7 @@ public class JpaRepositoryConfiguration {
|
||||
RolloutExecutor rolloutExecutor(
|
||||
final ActionRepository actionRepository, final RolloutGroupRepository rolloutGroupRepository,
|
||||
final RolloutTargetGroupRepository rolloutTargetGroupRepository,
|
||||
final RolloutRepository rolloutRepository, final TargetManagement targetManagement,
|
||||
final RolloutRepository rolloutRepository, final TargetManagement<? extends Target> targetManagement,
|
||||
final DeploymentManagement deploymentManagement, final RolloutGroupManagement rolloutGroupManagement,
|
||||
final RolloutManagement rolloutManagement, final QuotaManagement quotaManagement,
|
||||
final RolloutGroupEvaluationManager evaluationManager, final RolloutApprovalStrategy rolloutApprovalStrategy,
|
||||
@@ -424,8 +416,8 @@ public class JpaRepositoryConfiguration {
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
EntityFactory entityFactory(final TargetBuilder targetBuilder, final RolloutBuilder rolloutBuilder) {
|
||||
return new JpaEntityFactory(targetBuilder, rolloutBuilder);
|
||||
EntityFactory entityFactory(final RolloutBuilder rolloutBuilder) {
|
||||
return new JpaEntityFactory(rolloutBuilder);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,7 +456,8 @@ public class JpaRepositoryConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
AutoAssignExecutor autoAssignExecutor(
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement, final TargetManagement targetManagement,
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final TargetManagement<? extends Target> targetManagement,
|
||||
final DeploymentManagement deploymentManagement,
|
||||
final PlatformTransactionManager transactionManager, final ContextAware contextAware) {
|
||||
return new AutoAssignChecker(targetFilterQueryManagement, targetManagement, deploymentManagement, transactionManager, contextAware);
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Slf4j
|
||||
public class AutoAssignChecker extends AbstractAutoAssignExecutor {
|
||||
|
||||
private final TargetManagement targetManagement;
|
||||
private final TargetManagement<? extends Target> targetManagement;
|
||||
|
||||
/**
|
||||
* Instantiates a new auto assign checker
|
||||
@@ -51,7 +51,7 @@ public class AutoAssignChecker extends AbstractAutoAssignExecutor {
|
||||
*/
|
||||
public AutoAssignChecker(
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final TargetManagement targetManagement, final DeploymentManagement deploymentManagement,
|
||||
final TargetManagement<? extends Target> targetManagement, final DeploymentManagement deploymentManagement,
|
||||
final PlatformTransactionManager transactionManager, final ContextAware contextAware) {
|
||||
super(targetFilterQueryManagement, deploymentManagement, transactionManager, contextAware);
|
||||
this.targetManagement = targetManagement;
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetBuilder;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
|
||||
/**
|
||||
* Builder implementation for {@link Target}.
|
||||
*/
|
||||
public class JpaTargetBuilder implements TargetBuilder {
|
||||
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
|
||||
public JpaTargetBuilder(final TargetTypeManagement<? extends TargetType> targetTypeManagement) {
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetUpdate update(final String controllerId) {
|
||||
return new JpaTargetUpdate(controllerId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetCreate create() {
|
||||
return new JpaTargetCreate(targetTypeManagement);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractTargetUpdateCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Create/build implementation.
|
||||
*/
|
||||
public class JpaTargetCreate extends AbstractTargetUpdateCreate<TargetCreate> implements TargetCreate {
|
||||
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
|
||||
JpaTargetCreate(final TargetTypeManagement<? extends TargetType> targetTypeManagement) {
|
||||
super(null);
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaTarget build() {
|
||||
final JpaTarget target = new JpaTarget(controllerId, securityToken);
|
||||
|
||||
if (!ObjectUtils.isEmpty(name)) {
|
||||
target.setName(name);
|
||||
}
|
||||
|
||||
if (targetTypeId != null) {
|
||||
final TargetType targetType = targetTypeManagement.get(targetTypeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId));
|
||||
target.setTargetType(targetType);
|
||||
}
|
||||
|
||||
target.setDescription(description);
|
||||
target.setAddress(address);
|
||||
target.setUpdateStatus(getStatus().orElse(TargetUpdateStatus.UNKNOWN));
|
||||
getLastTargetQuery().ifPresent(target::setLastTargetQuery);
|
||||
target.setGroup(getGroup().orElse(null));
|
||||
|
||||
return target;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others
|
||||
*
|
||||
* This program and the accompanying materials are made
|
||||
* available under the terms of the Eclipse Public License 2.0
|
||||
* which is available at https://www.eclipse.org/legal/epl-2.0/
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.jpa.builder;
|
||||
|
||||
import org.eclipse.hawkbit.repository.builder.AbstractTargetUpdateCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
|
||||
public class JpaTargetUpdate extends AbstractTargetUpdateCreate<TargetUpdate> implements TargetUpdate {
|
||||
|
||||
JpaTargetUpdate(final String controllerId) {
|
||||
super(controllerId);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ import org.eclipse.hawkbit.repository.MaintenanceScheduleHelper;
|
||||
import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.RepositoryConstants;
|
||||
import org.eclipse.hawkbit.repository.RepositoryProperties;
|
||||
import org.eclipse.hawkbit.repository.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
@@ -105,6 +106,7 @@ import org.eclipse.hawkbit.tenancy.configuration.ControllerPollProperties;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.PollingTime;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
import org.eclipse.hawkbit.util.IpUtil;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
|
||||
import org.springframework.dao.ConcurrencyFailureException;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -666,13 +668,15 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
}
|
||||
|
||||
private Target createTarget(final String controllerId, final URI address, final String name, final String type) {
|
||||
|
||||
log.debug("Creating target for thing ID \"{}\".", controllerId);
|
||||
JpaTarget jpaTarget = (JpaTarget) entityFactory.target().create()
|
||||
.controllerId(controllerId).description("Plug and Play target: " + controllerId)
|
||||
.name((StringUtils.hasText(name) ? name : controllerId)).status(TargetUpdateStatus.REGISTERED)
|
||||
.lastTargetQuery(System.currentTimeMillis())
|
||||
.address(Optional.ofNullable(address).map(URI::toString).orElse(null)).build();
|
||||
final JpaTarget jpaTarget = new JpaTarget();
|
||||
jpaTarget.setControllerId(controllerId);
|
||||
jpaTarget.setDescription("Plug and Play target: " + controllerId);
|
||||
jpaTarget.setName((StringUtils.hasText(name) ? name : controllerId));
|
||||
jpaTarget.setSecurityToken(SecurityTokenGeneratorHolder.getInstance().generateToken());
|
||||
jpaTarget.setUpdateStatus(TargetUpdateStatus.REGISTERED);
|
||||
jpaTarget.setLastTargetQuery(System.currentTimeMillis());
|
||||
jpaTarget.setAddress(Optional.ofNullable(address).map(URI::toString).orElse(null));
|
||||
|
||||
if (StringUtils.hasText(type)) {
|
||||
var targetTypeOptional = getTargetType(type);
|
||||
@@ -770,7 +774,7 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
@SuppressWarnings("java:S3776") // it's just complex
|
||||
private Target updateTarget(final JpaTarget toUpdate, final URI address, final String name, final String type) {
|
||||
if (isStoreEager(toUpdate, address, name, type) || !queue.offer(new TargetPoll(toUpdate))) {
|
||||
if (isAddressChanged(toUpdate.getAddress(), address)) {
|
||||
if (isAddressChanged(IpUtil.addressToUri(toUpdate.getAddress()), address)) {
|
||||
toUpdate.setAddress(address.toString());
|
||||
}
|
||||
if (isNameChanged(toUpdate.getName(), name)) {
|
||||
@@ -804,16 +808,14 @@ public class JpaControllerManagement extends JpaActionManagement implements Cont
|
||||
}
|
||||
|
||||
private boolean isStoreEager(final JpaTarget toUpdate, final URI address, final String name, final String type) {
|
||||
return repositoryProperties.isEagerPollPersistence() || isAddressChanged(toUpdate.getAddress(), address)
|
||||
return repositoryProperties.isEagerPollPersistence() || isAddressChanged(IpUtil.addressToUri(toUpdate.getAddress()), address)
|
||||
|| isNameChanged(toUpdate.getName(), name) || isTypeChanged(toUpdate.getTargetType(), type)
|
||||
|| isStatusUnknown(toUpdate.getUpdateStatus());
|
||||
}
|
||||
|
||||
private void handleFinishedCancelation(final JpaActionStatus actionStatus, final JpaAction action) {
|
||||
// in case of successful cancellation we also report the success at
|
||||
// the canceled action itself.
|
||||
actionStatus.addMessage(
|
||||
RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished sucessfully.");
|
||||
// in case of successful cancellation we also report the success at the canceled action itself.
|
||||
actionStatus.addMessage(RepositoryConstants.SERVER_MESSAGE_PREFIX + "Cancellation completion is finished successfully.");
|
||||
DeploymentHelper.successCancellation(action, actionRepository, targetRepository);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,16 +41,12 @@ import org.eclipse.hawkbit.repository.QuotaManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TimestampCalculator;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
|
||||
import org.eclipse.hawkbit.repository.jpa.acm.AccessController;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetCreate;
|
||||
import org.eclipse.hawkbit.repository.jpa.builder.JpaTargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTarget;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
|
||||
@@ -96,12 +92,12 @@ import org.springframework.validation.annotation.Validated;
|
||||
@Validated
|
||||
@Service
|
||||
@ConditionalOnBooleanProperty(prefix = "hawkbit.jpa", name = { "enabled", "target-management" }, matchIfMissing = true)
|
||||
public class JpaTargetManagement implements TargetManagement {
|
||||
public class JpaTargetManagement
|
||||
extends AbstractJpaRepositoryManagement<JpaTarget, TargetManagement.Create, TargetManagement.Update, TargetRepository, TargetFields>
|
||||
implements TargetManagement<JpaTarget> {
|
||||
|
||||
private final EntityManager entityManager;
|
||||
private final JpaDistributionSetManagement distributionSetManagement;
|
||||
private final QuotaManagement quotaManagement;
|
||||
private final TargetRepository targetRepository;
|
||||
private final TargetTypeRepository targetTypeRepository;
|
||||
private final RolloutGroupRepository rolloutGroupRepository;
|
||||
private final TargetFilterQueryRepository targetFilterQueryRepository;
|
||||
@@ -109,17 +105,17 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
private final TenantAware tenantAware;
|
||||
|
||||
@SuppressWarnings("java:S107")
|
||||
protected JpaTargetManagement(final EntityManager entityManager,
|
||||
protected JpaTargetManagement(
|
||||
final TargetRepository jpaRepository, final EntityManager entityManager,
|
||||
final JpaDistributionSetManagement distributionSetManagement, final QuotaManagement quotaManagement,
|
||||
final TargetRepository targetRepository, final TargetTypeRepository targetTypeRepository,
|
||||
final TargetTypeRepository targetTypeRepository,
|
||||
final RolloutGroupRepository rolloutGroupRepository,
|
||||
final TargetFilterQueryRepository targetFilterQueryRepository,
|
||||
final TargetTagRepository targetTagRepository,
|
||||
final TenantAware tenantAware) {
|
||||
this.entityManager = entityManager;
|
||||
super(jpaRepository, entityManager);
|
||||
this.distributionSetManagement = distributionSetManagement;
|
||||
this.quotaManagement = quotaManagement;
|
||||
this.targetRepository = targetRepository;
|
||||
this.targetTypeRepository = targetTypeRepository;
|
||||
this.rolloutGroupRepository = rolloutGroupRepository;
|
||||
this.targetFilterQueryRepository = targetFilterQueryRepository;
|
||||
@@ -130,39 +126,32 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public long countByAssignedDistributionSet(final long distributionSetId) {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException((distributionSetId));
|
||||
return targetRepository.count(TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId()));
|
||||
return jpaRepository.count(TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByFilters(final FilterParams filterParams) {
|
||||
final List<Specification<JpaTarget>> specList = buildSpecificationList(filterParams);
|
||||
return JpaManagementHelper.countBySpec(targetRepository, specList);
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByInstalledDistributionSet(final long distributionSetId) {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException((distributionSetId));
|
||||
return targetRepository.count(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId()));
|
||||
return jpaRepository.count(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByInstalledOrAssignedDistributionSet(final long distributionSetId) {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException((distributionSetId));
|
||||
return targetRepository.exists(TargetSpecifications.hasInstalledOrAssignedDistributionSet(validDistSet.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByRsql(final String rsql) {
|
||||
return JpaManagementHelper.countBySpec(
|
||||
targetRepository,
|
||||
List.of(RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class)));
|
||||
return jpaRepository.exists(TargetSpecifications.hasInstalledOrAssignedDistributionSet(validDistSet.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByRsqlAndUpdatable(String rsql) {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class));
|
||||
return targetRepository.count(AccessController.Operation.UPDATE, combineWithAnd(specList));
|
||||
return jpaRepository.count(AccessController.Operation.UPDATE, combineWithAnd(specList));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -170,21 +159,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.isCompatibleWithDistributionSetType(distributionSetIdTypeId));
|
||||
return JpaManagementHelper.countBySpec(targetRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByRsqlAndCompatibleAndUpdatable(String rsql, Long distributionSetIdTypeId) {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.isCompatibleWithDistributionSetType(distributionSetIdTypeId));
|
||||
return targetRepository.count(AccessController.Operation.UPDATE, combineWithAnd(specList));
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countByFailedInRollout(final String rolloutId, final Long dsTypeId) {
|
||||
final List<Specification<JpaTarget>> specList = List.of(TargetSpecifications.failedActionsForRollout(rolloutId));
|
||||
return JpaManagementHelper.countBySpec(targetRepository, specList);
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -195,48 +176,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return countByRsql(targetFilterQuery.getQuery());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
return targetRepository.count();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Target create(final TargetCreate c) {
|
||||
final JpaTargetCreate create = (JpaTargetCreate) c;
|
||||
return targetRepository.save(AccessController.Operation.CREATE, create.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public List<Target> create(final Collection<TargetCreate> targets) {
|
||||
final List<JpaTarget> targetList = targets.stream().map(JpaTargetCreate.class::cast).map(JpaTargetCreate::build).toList();
|
||||
return Collections.unmodifiableList(targetRepository.saveAll(AccessController.Operation.CREATE, targetList));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void delete(final Collection<Long> ids) {
|
||||
final List<JpaTarget> targets = targetRepository.findAllById(ids);
|
||||
if (targets.size() < ids.size()) {
|
||||
throw new EntityNotFoundException(Target.class, ids,
|
||||
targets.stream().map(Target::getId).filter(id -> !ids.contains(id)).toList());
|
||||
}
|
||||
targetRepository.deleteAll(targets);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void deleteByControllerID(final String controllerId) {
|
||||
targetRepository.delete(getByControllerIdAndThrowIfNotFound(controllerId));
|
||||
jpaRepository.delete(getByControllerIdAndThrowIfNotFound(controllerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -245,7 +190,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSet jpaDistributionSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
final Long distSetTypeId = jpaDistributionSet.getType().getId();
|
||||
|
||||
return targetRepository
|
||||
return jpaRepository
|
||||
.findAllWithoutCount(
|
||||
AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
@@ -261,7 +206,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSet jpaDistributionSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
final Long distSetTypeId = jpaDistributionSet.getType().getId();
|
||||
|
||||
return targetRepository.count(
|
||||
return jpaRepository.count(
|
||||
AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
@@ -272,7 +217,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public Slice<Target> findByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(
|
||||
final Collection<Long> groups, final String rsql, final DistributionSetType dsType, final Pageable pageable) {
|
||||
return targetRepository
|
||||
return jpaRepository
|
||||
.findAllWithoutCount(AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
@@ -285,7 +230,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public long countByRsqlAndNotInRolloutGroupsAndCompatibleAndUpdatable(
|
||||
final String rsql, final Collection<Long> groups, final DistributionSetType dsType) {
|
||||
return targetRepository.count(AccessController.Operation.UPDATE,
|
||||
return jpaRepository.count(AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.isNotInRolloutGroups(groups),
|
||||
@@ -297,7 +242,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
TargetSpecifications.failedActionsForRollout(rolloutId),
|
||||
TargetSpecifications.isNotInRolloutGroups(groups));
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -305,13 +250,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final List<Specification<JpaTarget>> specList = List.of(
|
||||
TargetSpecifications.failedActionsForRollout(rolloutId),
|
||||
TargetSpecifications.isNotInRolloutGroups(groups));
|
||||
return JpaManagementHelper.countBySpec(targetRepository, specList);
|
||||
return JpaManagementHelper.countBySpec(jpaRepository, specList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Target> findByRsqlAndNoOverridingActionsAndNotInRolloutAndCompatibleAndUpdatable(
|
||||
final long rolloutId, final String rsql, final DistributionSetType distributionSetType, final Pageable pageable) {
|
||||
return targetRepository
|
||||
return jpaRepository
|
||||
.findAllWithoutCount(AccessController.Operation.UPDATE,
|
||||
combineWithAnd(List.of(
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
@@ -323,7 +268,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
@Override
|
||||
public long countByActionsInRolloutGroup(final long rolloutGroupId) {
|
||||
return targetRepository.count(TargetSpecifications.isInActionRolloutGroup(rolloutGroupId));
|
||||
return jpaRepository.count(TargetSpecifications.isInActionRolloutGroup(rolloutGroupId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -333,7 +278,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(
|
||||
targetRepository, List.of(TargetSpecifications.hasNoActionInRolloutGroup(group)), pageable);
|
||||
jpaRepository, List.of(TargetSpecifications.hasNoActionInRolloutGroup(group)), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -341,7 +286,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(
|
||||
targetRepository,
|
||||
jpaRepository,
|
||||
List.of(TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId())), pageable);
|
||||
}
|
||||
|
||||
@@ -353,28 +298,28 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.hasAssignedDistributionSet(validDistSet.getId()));
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target> getByControllerID(final Collection<String> controllerIDs) {
|
||||
return Collections.unmodifiableList(targetRepository.findAll(TargetSpecifications.byControllerIdWithAssignedDsInJoin(controllerIDs)));
|
||||
public List<Target> getByControllerId(final Collection<String> controllerIDs) {
|
||||
return Collections.unmodifiableList(jpaRepository.findAll(TargetSpecifications.byControllerIdWithAssignedDsInJoin(controllerIDs)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Target> getByControllerID(final String controllerId) {
|
||||
return targetRepository.findByControllerId(controllerId).map(Target.class::cast);
|
||||
public Optional<Target> getByControllerId(final String controllerId) {
|
||||
return jpaRepository.findByControllerId(controllerId).map(Target.class::cast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Target getWithDetails(final String controllerId, final String detailsKey) {
|
||||
return targetRepository.getWithDetailsByControllerId(controllerId, "Target." + detailsKey);
|
||||
return jpaRepository.getWithDetailsByControllerId(controllerId, "Target." + detailsKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Target> findByFilters(final FilterParams filterParams, final Pageable pageable) {
|
||||
final List<Specification<JpaTarget>> specList = buildSpecificationList(filterParams);
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -382,7 +327,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final DistributionSet validDistSet = distributionSetManagement.getOrElseThrowException(distributionSetId);
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(
|
||||
targetRepository, List.of(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId())), pageReq);
|
||||
jpaRepository, List.of(TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId())), pageReq);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -393,26 +338,13 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.hasInstalledDistributionSet(validDistSet.getId()));
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Target> findByUpdateStatus(final TargetUpdateStatus status, final Pageable pageable) {
|
||||
return JpaManagementHelper.findAllWithCountBySpec(
|
||||
targetRepository, List.of(TargetSpecifications.hasTargetUpdateStatus(status)), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Target> findAll(final Pageable pageable) {
|
||||
return targetRepository.findAllWithoutCount(pageable).map(Target.class::cast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice<Target> findByRsql(final String rsql, final Pageable pageable) {
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(
|
||||
targetRepository,
|
||||
List.of(RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class)), pageable
|
||||
);
|
||||
jpaRepository, List.of(TargetSpecifications.hasTargetUpdateStatus(status)), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -421,7 +353,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetFilterQuery.class, targetFilterQueryId));
|
||||
|
||||
return JpaManagementHelper.findAllWithoutCountBySpec(
|
||||
targetRepository, List.of(RsqlUtility.getInstance().buildRsqlSpecification(
|
||||
jpaRepository, List.of(RsqlUtility.getInstance().buildRsqlSpecification(
|
||||
targetFilterQuery.getQuery(), TargetFields.class)), pageable
|
||||
);
|
||||
}
|
||||
@@ -429,7 +361,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public Page<Target> findByTag(final long tagId, final Pageable pageable) {
|
||||
throwEntityNotFoundExceptionIfTagDoesNotExist(tagId);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, List.of(TargetSpecifications.hasTag(tagId)), pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, List.of(TargetSpecifications.hasTag(tagId)), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -440,7 +372,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
RsqlUtility.getInstance().buildRsqlSpecification(rsql, TargetFields.class),
|
||||
TargetSpecifications.hasTag(tagId));
|
||||
|
||||
return JpaManagementHelper.findAllWithCountBySpec(targetRepository, specList, pageable);
|
||||
return JpaManagementHelper.findAllWithCountBySpec(jpaRepository, specList, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -460,7 +392,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
targetsWithoutSameType.forEach(target -> target.setTargetType(type));
|
||||
|
||||
final TargetTypeAssignmentResult result = new TargetTypeAssignmentResult(
|
||||
targetsWithSameType.size(), targetRepository.saveAll(targetsWithoutSameType), Collections.emptyList(), type);
|
||||
targetsWithSameType.size(), jpaRepository.saveAll(targetsWithoutSameType), Collections.emptyList(), type);
|
||||
|
||||
// no reason to persist the type
|
||||
entityManager.detach(type);
|
||||
@@ -481,7 +413,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
// set new target type to null for all targets
|
||||
allTargets.forEach(target -> target.setTargetType(null));
|
||||
|
||||
return new TargetTypeAssignmentResult(0, Collections.emptyList(), targetRepository.saveAll(allTargets), null);
|
||||
return new TargetTypeAssignmentResult(0, Collections.emptyList(), jpaRepository.saveAll(allTargets), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -508,7 +440,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return target;
|
||||
} else {
|
||||
target.addTag(tag);
|
||||
return targetRepository.save(target);
|
||||
return jpaRepository.save(target);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -535,7 +467,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
return updateTag(controllerIds, targetTagId, notFoundHandler, (tag, target) -> {
|
||||
if (target.getTags().contains(tag)) {
|
||||
target.removeTag(tag);
|
||||
return targetRepository.save(target);
|
||||
return jpaRepository.save(target);
|
||||
} else {
|
||||
return target;
|
||||
}
|
||||
@@ -549,7 +481,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public Target unassignType(final String controllerId) {
|
||||
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
|
||||
target.setTargetType(null);
|
||||
return targetRepository.save(target);
|
||||
return jpaRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -559,12 +491,12 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
public Target assignType(final String controllerId, final Long targetTypeId) {
|
||||
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
|
||||
|
||||
targetRepository.getAccessController().ifPresent(acm ->
|
||||
jpaRepository.getAccessController().ifPresent(acm ->
|
||||
acm.assertOperationAllowed(AccessController.Operation.UPDATE, target));
|
||||
|
||||
final JpaTargetType targetType = getTargetTypeByIdAndThrowIfNotFound(targetTypeId);
|
||||
target.setTargetType(targetType);
|
||||
return targetRepository.save(target);
|
||||
return jpaRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -572,16 +504,16 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
if (withSubgroups) {
|
||||
// search for eq(group) and like(group%)
|
||||
return JpaManagementHelper
|
||||
.findAllWithCountBySpec(targetRepository, List.of(TargetSpecifications.eqOrSubTargetGroup(group)), pageable);
|
||||
.findAllWithCountBySpec(jpaRepository, List.of(TargetSpecifications.eqOrSubTargetGroup(group)), pageable);
|
||||
} else {
|
||||
return JpaManagementHelper
|
||||
.findAllWithCountBySpec(targetRepository, List.of(TargetSpecifications.eqTargetGroup(group)), pageable);
|
||||
.findAllWithCountBySpec(jpaRepository, List.of(TargetSpecifications.eqTargetGroup(group)), pageable);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> findGroups() {
|
||||
return targetRepository.findDistinctGroups();
|
||||
return jpaRepository.findDistinctGroups();
|
||||
}
|
||||
|
||||
|
||||
@@ -618,40 +550,9 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX,
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public Target update(final TargetUpdate u) {
|
||||
final JpaTargetUpdate update = (JpaTargetUpdate) u;
|
||||
|
||||
final JpaTarget target = getByControllerIdAndThrowIfNotFound(update.getControllerId());
|
||||
|
||||
update.getName().ifPresent(target::setName);
|
||||
update.getDescription().ifPresent(target::setDescription);
|
||||
update.getAddress().ifPresent(target::setAddress);
|
||||
update.getSecurityToken().ifPresent(target::setSecurityToken);
|
||||
if (update.getTargetTypeId() != null) {
|
||||
final TargetType targetType = getTargetTypeByIdAndThrowIfNotFound(update.getTargetTypeId());
|
||||
target.setTargetType(targetType);
|
||||
}
|
||||
|
||||
return targetRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Target> get(final long id) {
|
||||
return targetRepository.findById(id).map(Target.class::cast);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target> get(final Collection<Long> ids) {
|
||||
return Collections.unmodifiableList(targetRepository.findAll(TargetSpecifications.hasIdIn(ids)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByControllerId(final String controllerId) {
|
||||
return targetRepository.exists(TargetSpecifications.hasControllerId(controllerId));
|
||||
return jpaRepository.exists(TargetSpecifications.hasControllerId(controllerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -669,7 +570,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
final Specification<JpaTarget> combinedSpecification = Objects
|
||||
.requireNonNull(SpecificationsBuilder.combineWithAnd(specList));
|
||||
return targetRepository.exists(AccessController.Operation.UPDATE, combinedSpecification);
|
||||
return jpaRepository.exists(AccessController.Operation.UPDATE, combinedSpecification);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -689,7 +590,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
backoff = @Backoff(delay = Constants.TX_RT_DELAY))
|
||||
public void requestControllerAttributes(final String controllerId) {
|
||||
final JpaTarget target = getByControllerIdAndThrowIfNotFound(controllerId);
|
||||
targetRepository.getAccessController()
|
||||
jpaRepository.getAccessController()
|
||||
.ifPresent(acm -> acm.assertOperationAllowed(AccessController.Operation.UPDATE, target));
|
||||
target.setRequestControllerAttributes(true);
|
||||
AfterTransactionCommitExecutorHolder.getInstance().getAfterCommit().afterCommit(() ->
|
||||
@@ -708,7 +609,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
@Override
|
||||
public Page<Target> findByControllerAttributesRequested(final Pageable pageable) {
|
||||
return JpaManagementHelper.findAllWithCountBySpec(
|
||||
targetRepository, List.of(TargetSpecifications.hasRequestControllerAttributesTrue()), pageable);
|
||||
jpaRepository, List.of(TargetSpecifications.hasRequestControllerAttributesTrue()), pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -725,7 +626,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
metadata.put(key, value);
|
||||
|
||||
targetRepository.save(target);
|
||||
jpaRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -745,7 +646,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
metadata.putAll(md);
|
||||
|
||||
assertMetadataQuota(target.getId(), metadata.size());
|
||||
targetRepository.save(target);
|
||||
jpaRepository.save(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -771,7 +672,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
throw new EntityNotFoundException("Target metadata", controllerId + ":" + key);
|
||||
}
|
||||
|
||||
targetRepository.save(target);
|
||||
jpaRepository.save(target);
|
||||
}
|
||||
|
||||
private Map<String, String> getMap(final String controllerId, final MapAttribute<JpaTarget, String, String> mapAttribute) {
|
||||
@@ -817,7 +718,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
|
||||
private JpaTarget getByControllerIdAndThrowIfNotFound(final String controllerId) {
|
||||
return targetRepository.getByControllerId(controllerId);
|
||||
return jpaRepository.getByControllerId(controllerId);
|
||||
}
|
||||
|
||||
private JpaTargetType getTargetTypeByIdAndThrowIfNotFound(final long id) {
|
||||
@@ -862,7 +763,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
|
||||
private List<JpaTarget> findTargetsByInSpecification(final Collection<String> controllerIds, final Specification<JpaTarget> specification) {
|
||||
return ListUtils.partition(new ArrayList<>(controllerIds), Constants.MAX_ENTRIES_IN_STATEMENT).stream()
|
||||
.map(ids -> targetRepository.findAll(TargetSpecifications.hasControllerIdIn(ids).and(specification)))
|
||||
.map(ids -> jpaRepository.findAll(TargetSpecifications.hasControllerIdIn(ids).and(specification)))
|
||||
.flatMap(List::stream).toList();
|
||||
}
|
||||
|
||||
@@ -872,10 +773,10 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
final JpaTargetTag tag = targetTagRepository.findById(targetTagId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetTag.class, targetTagId));
|
||||
final List<JpaTarget> targets = controllerIds.size() == 1 ?
|
||||
targetRepository.findByControllerId(controllerIds.iterator().next())
|
||||
jpaRepository.findByControllerId(controllerIds.iterator().next())
|
||||
.map(List::of)
|
||||
.orElseGet(Collections::emptyList) :
|
||||
targetRepository
|
||||
jpaRepository
|
||||
.findAll(TargetSpecifications.byControllerIdWithTagsInJoin(controllerIds));
|
||||
if (targets.size() < controllerIds.size()) {
|
||||
final Collection<String> notFound = notFound(controllerIds, targets);
|
||||
@@ -886,7 +787,7 @@ public class JpaTargetManagement implements TargetManagement {
|
||||
}
|
||||
}
|
||||
|
||||
targetRepository.getAccessController()
|
||||
jpaRepository.getAccessController()
|
||||
.ifPresent(acm -> acm.assertOperationAllowed(AccessController.Operation.UPDATE, targets));
|
||||
|
||||
try {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.model;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -54,7 +53,6 @@ import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
|
||||
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.SecurityTokenGeneratorHolder;
|
||||
import org.eclipse.hawkbit.repository.jpa.utils.MapAttributeConverter;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.PollStatus;
|
||||
@@ -101,6 +99,8 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Column(name = "controller_id", length = Target.CONTROLLER_ID_MAX_SIZE, updatable = false, nullable = false)
|
||||
@Size(min = 1, max = Target.CONTROLLER_ID_MAX_SIZE)
|
||||
@NotNull
|
||||
@@ -115,6 +115,7 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
private String securityToken;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Column(name = "address", length = Target.ADDRESS_MAX_SIZE)
|
||||
@Size(max = Target.ADDRESS_MAX_SIZE)
|
||||
private String address;
|
||||
@@ -212,18 +213,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
@OneToMany(mappedBy = "target", fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
|
||||
private List<RolloutTargetGroup> rolloutTargetGroup;
|
||||
|
||||
public JpaTarget(final String controllerId, final String securityToken) {
|
||||
this.controllerId = controllerId;
|
||||
// truncate controller ID to max name length (if too big)
|
||||
setName(controllerId != null && controllerId.length() > NAME_MAX_SIZE ? controllerId.substring(0, NAME_MAX_SIZE) : controllerId);
|
||||
this.securityToken = ObjectUtils.isEmpty(securityToken) ? SecurityTokenGeneratorHolder.getInstance().generateToken() : securityToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getControllerId() {
|
||||
return controllerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSecurityToken() {
|
||||
final SystemSecurityContext systemSecurityContext = SystemSecurityContextHolder.getInstance().getSystemSecurityContext();
|
||||
@@ -233,22 +222,6 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ipAddress
|
||||
*/
|
||||
@Override
|
||||
public URI getAddress() {
|
||||
if (address == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return URI.create(address);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
log.warn("Invalid address provided. Cloud not be configured to URI", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the poll time which holds the last poll time of the target, the next poll time and the overdue time. In case the
|
||||
* {@link #lastTargetQuery} is not set e.g. the target never polled before this method returns {@code null}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
package org.eclipse.hawkbit.repository.jpa.acm;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.CREATE_ROLLOUT;
|
||||
import static org.eclipse.hawkbit.im.authentication.SpPermission.READ_REPOSITORY;
|
||||
@@ -27,7 +28,9 @@ import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement.AutoAssignDistributionSetUpdate;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.autoassign.AutoAssignChecker;
|
||||
@@ -59,10 +62,10 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void verifyTargetReadOperations() {
|
||||
final Target permittedTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device01").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
final Target hiddenTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device02").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device02").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
runAs(withUser("user", READ_TARGET + "/controllerId==" + permittedTarget.getControllerId()), () -> {
|
||||
// verify targetManagement#findAll
|
||||
@@ -78,15 +81,15 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
.map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId());
|
||||
|
||||
// verify targetManagement#getByControllerID
|
||||
assertThat(targetManagement.getByControllerID(permittedTarget.getControllerId())).isPresent();
|
||||
assertThat(targetManagement.getByControllerId(permittedTarget.getControllerId())).isPresent();
|
||||
final String hiddenTargetControllerId = hiddenTarget.getControllerId();
|
||||
assertThatThrownBy(() -> targetManagement.getByControllerID(hiddenTargetControllerId))
|
||||
assertThatThrownBy(() -> targetManagement.getByControllerId(hiddenTargetControllerId))
|
||||
.as("Missing read permissions for hidden target.")
|
||||
.isInstanceOf(InsufficientPermissionException.class);
|
||||
|
||||
// verify targetManagement#getByControllerID
|
||||
// verify targetManagement#getByControllerId
|
||||
assertThat(targetManagement
|
||||
.getByControllerID(Arrays.asList(permittedTarget.getControllerId(), hiddenTargetControllerId))
|
||||
.getByControllerId(List.of(permittedTarget.getControllerId(), hiddenTargetControllerId))
|
||||
.stream().map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId());
|
||||
|
||||
// verify targetManagement#get
|
||||
@@ -94,8 +97,8 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetManagement.get(hiddenTarget.getId())).isEmpty();
|
||||
|
||||
// verify targetManagement#get
|
||||
assertThat(targetManagement.get(Arrays.asList(permittedTarget.getId(), hiddenTarget.getId())).stream()
|
||||
.map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId());
|
||||
final List<Long> withHidden = List.of(permittedTarget.getId(), hiddenTarget.getId());
|
||||
assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> targetManagement.get(withHidden));
|
||||
|
||||
// verify targetManagement#getControllerAttributes
|
||||
assertThat(targetManagement.getControllerAttributes(permittedTarget.getControllerId())).isEmpty();
|
||||
@@ -121,14 +124,14 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void verifyTagFilteringAndManagement() {
|
||||
final Target permittedTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device01").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
final Target readOnlyTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device02").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device02").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
final String readOnlyTargetControllerId = readOnlyTarget.getControllerId();
|
||||
|
||||
final Target hiddenTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device03").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device03").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
final Long myTagId = targetTagManagement.create(TargetTagManagement.Create.builder().name("myTag").build()).getId();
|
||||
|
||||
@@ -200,9 +203,9 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.lock(ds);
|
||||
|
||||
final Target permittedTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device01").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
final String hiddenTargetControllerId = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device02").status(TargetUpdateStatus.REGISTERED))
|
||||
.create(Create.builder().controllerId("device02").updateStatus(TargetUpdateStatus.REGISTERED).build())
|
||||
.getControllerId();
|
||||
|
||||
runAs(withUser("user", READ_TARGET + "/controllerId==" + permittedTarget.getControllerId()), () ->
|
||||
@@ -240,9 +243,9 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest {
|
||||
distributionSetManagement.lock(secondDs);
|
||||
|
||||
final Target manageableTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device01").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device01").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
final Target readOnlyTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("device02").status(TargetUpdateStatus.REGISTERED));
|
||||
.create(Create.builder().controllerId("device02").updateStatus(TargetUpdateStatus.REGISTERED).build());
|
||||
|
||||
runAs(withUser("user",
|
||||
READ_TARGET + "/controllerId==" + manageableTarget.getControllerId() + " or controllerId==" + readOnlyTarget.getControllerId(),
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
@@ -427,7 +428,7 @@ class AutoAssignCheckerIntTest extends AbstractJpaIntegrationTest {
|
||||
private void verifyThatTargetsHaveDistributionSetAssignment(final DistributionSet set, final List<Target> targets, final int count) {
|
||||
final List<Long> targetIds = targets.stream().map(Target::getId).toList();
|
||||
|
||||
final Slice<Target> targetsAll = targetManagement.findAll(PAGE);
|
||||
final Page<? extends Target> targetsAll = targetManagement.findAll(PAGE);
|
||||
assertThat(targetsAll).as("Count of targets").hasSize(count);
|
||||
|
||||
for (final Target target : targetsAll) {
|
||||
@@ -452,7 +453,7 @@ class AutoAssignCheckerIntTest extends AbstractJpaIntegrationTest {
|
||||
private void verifyThatTargetsNotHaveDistributionSetAssignment(final List<Target> targets) {
|
||||
final List<Long> targetIds = targets.stream().map(Target::getId).toList();
|
||||
|
||||
final Slice<Target> targetsAll = targetManagement.findAll(PAGE);
|
||||
final Page<? extends Target> targetsAll = targetManagement.findAll(PAGE);
|
||||
|
||||
for (final Target target : targetsAll) {
|
||||
if (targetIds.contains(target.getId())) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.event.TenantAwareEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.DistributionSetDeletedEvent;
|
||||
@@ -80,7 +81,7 @@ class RepositoryEntityEventTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void targetUpdateEventIsPublished() throws InterruptedException {
|
||||
final Target createdTarget = testdataFactory.createTarget("12345");
|
||||
targetManagement.update(entityFactory.target().update(createdTarget.getControllerId()).name("updateName"));
|
||||
targetManagement.update(TargetManagement.Update.builder().id(createdTarget.getId()).name("updateName").build());
|
||||
|
||||
final TargetUpdatedEvent targetUpdatedEvent = eventListener.waitForEvent(TargetUpdatedEvent.class);
|
||||
assertThat(targetUpdatedEvent).isNotNull();
|
||||
|
||||
@@ -749,13 +749,10 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetPollEvent.class, count = 2) })
|
||||
void findOrRegisterTargetIfItDoesNotExistWithExistingTypeAndUpdateToNonExistingType() {
|
||||
createTargetType("knownTargetTypeName");
|
||||
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST,
|
||||
null, "knownTargetTypeName");
|
||||
final Target sameTarget = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST,
|
||||
null, "unknownTargetTypeName");
|
||||
final Target target = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST, null, "knownTargetTypeName");
|
||||
final Target sameTarget = controllerManagement.findOrRegisterTargetIfItDoesNotExist("AA", LOCALHOST, null, "unknownTargetTypeName");
|
||||
assertThat(target.getId()).as("Target should be the same").isEqualTo(sameTarget.getId());
|
||||
assertThat(sameTarget.getTargetType().getName()).as("Target type should be unchanged")
|
||||
.isEqualTo("knownTargetTypeName");
|
||||
assertThat(sameTarget.getTargetType().getName()).as("Target type should be unchanged").isEqualTo("knownTargetTypeName");
|
||||
assertThat(targetRepository.count()).as("Only 1 target should be registred").isEqualTo(1L);
|
||||
}
|
||||
|
||||
@@ -1109,7 +1106,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING)));
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(actionRepository.findById(action.getId()))
|
||||
.hasValueSatisfying(a -> assertThat(a.getStatus()).isEqualTo(Status.FINISHED));
|
||||
@@ -1141,7 +1138,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(action.getId()).status(Action.Status.RUNNING)));
|
||||
|
||||
// nothing changed as "feedback after close" is disabled
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
// however, additional action status has been stored
|
||||
assertThat(actionStatusRepository.findAll(PAGE).getNumberOfElements()).isEqualTo(4);
|
||||
assertThat(controllerManagement.findActionStatusByAction(action.getId(), PAGE).getNumberOfElements()).isEqualTo(4);
|
||||
@@ -1168,7 +1165,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
});
|
||||
|
||||
// verify that audit information has not changed
|
||||
final Target targetVerify = targetManagement.getByControllerID(controllerId).get();
|
||||
final Target targetVerify = targetManagement.getByControllerId(controllerId).get();
|
||||
assertThat(targetVerify.getCreatedBy()).isEqualTo(target.getCreatedBy());
|
||||
assertThat(targetVerify.getCreatedAt()).isEqualTo(target.getCreatedAt());
|
||||
assertThat(targetVerify.getLastModifiedBy()).isEqualTo(target.getLastModifiedBy());
|
||||
@@ -1730,7 +1727,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Long dsId = testdataFactory.createDistributionSet().getId();
|
||||
testdataFactory.createTarget();
|
||||
assignDistributionSet(dsId, DEFAULT_CONTROLLER_ID);
|
||||
assertThat(targetManagement.getByControllerID(DEFAULT_CONTROLLER_ID).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(DEFAULT_CONTROLLER_ID).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
return deploymentManagement.findActiveActionsByTarget(DEFAULT_CONTROLLER_ID, PAGE).getContent().get(0).getId();
|
||||
@@ -1740,7 +1737,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet(dsName);
|
||||
final Long dsId = ds.getId();
|
||||
assignDistributionSet(dsId, defaultControllerId, DOWNLOAD_ONLY);
|
||||
assertThat(targetManagement.getByControllerID(defaultControllerId).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(targetManagement.getByControllerId(defaultControllerId).get().getUpdateStatus()).isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
final Long id = deploymentManagement.findActiveActionsByTarget(defaultControllerId, PAGE).getContent().get(0).getId();
|
||||
assertThat(id).isNotNull();
|
||||
@@ -1749,7 +1746,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private Long assignDs(final Long dsId, final String defaultControllerId, final Action.ActionType actionType) {
|
||||
assignDistributionSet(dsId, defaultControllerId, actionType);
|
||||
assertThat(targetManagement.getByControllerID(defaultControllerId).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(defaultControllerId).get().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
final Long id = deploymentManagement.findActiveActionsByTarget(defaultControllerId, PAGE).getContent().get(0)
|
||||
@@ -1817,7 +1814,7 @@ class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
final Long actionId, final String controllerId,
|
||||
final TargetUpdateStatus expectedTargetUpdateStatus, final Action.Status expectedActionActionStatus,
|
||||
final Action.Status expectedActionStatus, final boolean actionActive) {
|
||||
final TargetUpdateStatus targetStatus = targetManagement.getByControllerID(controllerId).get().getUpdateStatus();
|
||||
final TargetUpdateStatus targetStatus = targetManagement.getByControllerId(controllerId).get().getUpdateStatus();
|
||||
assertThat(targetStatus).isEqualTo(expectedTargetUpdateStatus);
|
||||
final Action action = deploymentManagement.findAction(actionId).get();
|
||||
assertThat(action.getStatus()).isEqualTo(expectedActionActionStatus);
|
||||
|
||||
@@ -350,7 +350,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("target has update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
@@ -368,7 +368,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.addCancelActionStatus(entityFactory.actionStatus().create(secondAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of actions status").hasSize(7);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712")).as("wrong ds").contains(dsFirst);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
@@ -381,7 +381,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(9);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712")).as("wrong assigned ds")
|
||||
.contains(dsInstalled);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet dsInstalled = action.getDistributionSet();
|
||||
|
||||
// check initial status
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
@@ -417,7 +417,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
entityFactory.actionStatus().create(firstAction.getId()).status(Status.CANCELED));
|
||||
assertThat(actionStatusRepository.findAll()).as("wrong size of action status").hasSize(7);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712")).as("wrong assigned ds").contains(dsSecond);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong target update status")
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus()).as("wrong target update status")
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
// we cancel second -> remain assigned until finished cancellation
|
||||
@@ -432,7 +432,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712"))
|
||||
.as("wrong installed ds")
|
||||
.contains(dsInstalled);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("wrong target info update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
@@ -449,7 +449,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("newDS", true);
|
||||
|
||||
// verify initial status
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
Action assigningAction = assignSet(target, ds);
|
||||
@@ -470,7 +470,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(assigningAction.getStatus()).as("wrong size of status").isEqualTo(Status.CANCELED);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet("4712")).as("wrong assigned ds")
|
||||
.contains(dsInstalled);
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong target update status")
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus()).as("wrong target update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
}
|
||||
|
||||
@@ -481,7 +481,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
void forceQuitNotAllowedThrowsException() {
|
||||
final Action action = prepareFinishedUpdate("4712", "installed", true);
|
||||
// verify initial status
|
||||
assertThat(targetManagement.getByControllerID("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
assertThat(targetManagement.getByControllerId("4712").get().getUpdateStatus()).as("wrong update status")
|
||||
.isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
|
||||
final Target target = action.getTarget();
|
||||
@@ -1098,23 +1098,24 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(actions).as("Actions should be initiated by current user")
|
||||
.allMatch(a -> a.getInitiatedBy().equals(tenantAware.getCurrentUsername()));
|
||||
|
||||
final Iterable<Target> allFoundTargets = targetManagement.findAll(PAGE).getContent();
|
||||
final Iterable<? extends Target> allFoundTargets = targetManagement.findAll(PAGE).getContent();
|
||||
|
||||
// get final updated version of targets
|
||||
savedDeployedTargets = targetManagement.getByControllerID(savedDeployedTargets.stream().map(Target::getControllerId).toList());
|
||||
savedDeployedTargets = targetManagement.getByControllerId(savedDeployedTargets.stream().map(Target::getControllerId).toList());
|
||||
|
||||
assertThat(allFoundTargets).as("founded targets are wrong").containsAll(savedDeployedTargets)
|
||||
Assertions.<Target>assertThat(allFoundTargets).as("founded targets are wrong")
|
||||
.containsAll(savedDeployedTargets)
|
||||
.containsAll(savedNakedTargets);
|
||||
assertThat(savedDeployedTargets).as("saved target are wrong").doesNotContain(toArray(savedNakedTargets, Target.class));
|
||||
assertThat(savedNakedTargets).as("saved target are wrong").doesNotContain(toArray(savedDeployedTargets, Target.class));
|
||||
|
||||
for (final Target myt : savedNakedTargets) {
|
||||
final Target t = targetManagement.getByControllerID(myt.getControllerId()).get();
|
||||
final Target t = targetManagement.getByControllerId(myt.getControllerId()).get();
|
||||
assertThat(deploymentManagement.countActionsByTarget(t.getControllerId())).as("action should be empty").isZero();
|
||||
}
|
||||
|
||||
for (final Target myt : savedDeployedTargets) {
|
||||
final Target t = targetManagement.getByControllerID(myt.getControllerId()).get();
|
||||
final Target t = targetManagement.getByControllerId(myt.getControllerId()).get();
|
||||
final List<Action> activeActionsByTarget = deploymentManagement.findActiveActionsByTarget(t.getControllerId(), PAGE).getContent();
|
||||
assertThat(activeActionsByTarget).as("action should not be empty").isNotEmpty();
|
||||
assertThat(t.getUpdateStatus()).as("wrong target update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
@@ -1267,7 +1268,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
.isEqualTo(dsC.getId());
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds should not be null").isNotPresent();
|
||||
assertThat(targetManagement.getByControllerID(t.getControllerId()).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(t.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
}
|
||||
|
||||
@@ -1278,12 +1279,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
// verify, that dsA is deployed correctly
|
||||
for (final Target t_ : updatedTsDsA) {
|
||||
final Target t = targetManagement.getByControllerID(t_.getControllerId()).get();
|
||||
final Target t = targetManagement.getByControllerId(t_.getControllerId()).get();
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId()))
|
||||
.as("assigned ds is wrong").contains(dsA);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds is wrong").contains(dsA);
|
||||
assertThat(targetManagement.getByControllerID(t.getControllerId()).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(t.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.IN_SYNC);
|
||||
assertThat(deploymentManagement.findActiveActionsByTarget(t.getControllerId(), PAGE))
|
||||
.as("no actions should be active").isEmpty();
|
||||
@@ -1298,7 +1299,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
findActionsByDistributionSet(pageRequest, dsA.getId()).getContent().get(1);
|
||||
|
||||
// get final updated version of targets
|
||||
final List<Target> deployResWithDsBTargets = targetManagement.getByControllerID(deployResWithDsB
|
||||
final List<Target> deployResWithDsBTargets = targetManagement.getByControllerId(deployResWithDsB
|
||||
.getDeployedTargets().stream().map(Target::getControllerId).toList());
|
||||
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").usingElementComparator(controllerIdComparator())
|
||||
@@ -1306,12 +1307,12 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(deployed2DS).as("deployed ds is wrong").hasSameSizeAs(deployResWithDsBTargets);
|
||||
|
||||
for (final Target t_ : deployed2DS) {
|
||||
final Target t = targetManagement.getByControllerID(t_.getControllerId()).get();
|
||||
final Target t = targetManagement.getByControllerId(t_.getControllerId()).get();
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(t.getControllerId())).as("assigned ds is wrong")
|
||||
.contains(dsA);
|
||||
assertThat(deploymentManagement.getInstalledDistributionSet(t.getControllerId()))
|
||||
.as("installed ds should be null").isNotPresent();
|
||||
assertThat(targetManagement.getByControllerID(t.getControllerId()).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(t.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong target info update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
|
||||
}
|
||||
@@ -1419,7 +1420,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
targs = assignDistributionSet(dsA, targs).getAssignedEntity().stream().map(Action::getTarget)
|
||||
.toList();
|
||||
implicitLock(dsA);
|
||||
Target targ = targetManagement.getByControllerID(targs.iterator().next().getControllerId()).get();
|
||||
Target targ = targetManagement.getByControllerId(targs.iterator().next().getControllerId()).get();
|
||||
|
||||
// checking the revisions of the created entities
|
||||
// verifying that the revision of the object and the revision within the
|
||||
@@ -1445,7 +1446,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.addUpdateActionStatus(
|
||||
entityFactory.actionStatus().create(updAct.getContent().get(0).getId()).status(Status.FINISHED));
|
||||
|
||||
targ = targetManagement.getByControllerID(targ.getControllerId()).get();
|
||||
targ = targetManagement.getByControllerId(targ.getControllerId()).get();
|
||||
|
||||
assertEquals(0, deploymentManagement.findActiveActionsByTarget(targ.getControllerId(), PAGE).getTotalElements(),
|
||||
"active target actions are wrong");
|
||||
@@ -1468,7 +1469,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertEquals(1, deploymentManagement.findActiveActionsByTarget(targ.getControllerId(), PAGE).getTotalElements(),
|
||||
"active actions are wrong");
|
||||
assertEquals(TargetUpdateStatus.PENDING,
|
||||
targetManagement.getByControllerID(targ.getControllerId()).get().getUpdateStatus(),
|
||||
targetManagement.getByControllerId(targ.getControllerId()).get().getUpdateStatus(),
|
||||
"target status is wrong");
|
||||
assertEquals(dsB, deploymentManagement.getAssignedDistributionSet(targ.getControllerId()).get(),
|
||||
"wrong assigned ds");
|
||||
@@ -1609,8 +1610,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<DeploymentRequest> deploymentRequests = new ArrayList<>();
|
||||
for (int i = 0; i < quotaManagement.getMaxTargetDistributionSetAssignmentsPerManualAssignment(); i++) {
|
||||
final Target target = testdataFactory.createTarget("test-target-" + i, "test-target-" + i,
|
||||
targetType.getId());
|
||||
final Target target = testdataFactory.createTarget("test-target-" + i, "test-target-" + i, targetType);
|
||||
final DeploymentRequest deployment = DeploymentManagement
|
||||
.deploymentRequest(target.getControllerId(), ds.getId()).build();
|
||||
deploymentRequests.add(deployment);
|
||||
@@ -1619,8 +1619,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
deploymentManagement.assignDistributionSets(deploymentRequests);
|
||||
implicitLock(ds);
|
||||
|
||||
final List<Target> content = targetManagement.findAll(Pageable.unpaged()).getContent();
|
||||
|
||||
final List<? extends Target> content = targetManagement.findAll(Pageable.unpaged()).getContent();
|
||||
content.stream().map(JpaTarget.class::cast)
|
||||
.forEach(jpaTarget -> assertThat(jpaTarget.getAssignedDistributionSet()).isEqualTo(ds));
|
||||
}
|
||||
@@ -1633,8 +1632,8 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("test-ds");
|
||||
final TargetType targetType1 = testdataFactory.createTargetType("test-type1", Set.of(ds.getType()));
|
||||
final TargetType targetType2 = testdataFactory.createTargetType("test-type2", Set.of(ds.getType()));
|
||||
final Target target1 = testdataFactory.createTarget("test-target1", "test-target1", targetType1.getId());
|
||||
final Target target2 = testdataFactory.createTarget("test-target2", "test-target2", targetType2.getId());
|
||||
final Target target1 = testdataFactory.createTarget("test-target1", "test-target1", targetType1);
|
||||
final Target target2 = testdataFactory.createTarget("test-target2", "test-target2", targetType2);
|
||||
|
||||
final DeploymentRequest deployment1 = DeploymentManagement.deploymentRequest(target1.getControllerId(), ds.getId()).build();
|
||||
final DeploymentRequest deployment2 = DeploymentManagement.deploymentRequest(target2.getControllerId(), ds.getId()).build();
|
||||
@@ -1660,7 +1659,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("test-ds");
|
||||
final DistributionSetType dsType = testdataFactory.findOrCreateDistributionSetType("test-ds-type", "dsType");
|
||||
final TargetType targetType = testdataFactory.createTargetType("target-type", Set.of(dsType));
|
||||
final Target target = testdataFactory.createTarget("test-target", "test-target", targetType.getId());
|
||||
final Target target = testdataFactory.createTarget("test-target", "test-target", targetType);
|
||||
|
||||
final DeploymentRequest deploymentRequest = DeploymentManagement.deploymentRequest(target.getControllerId(), ds.getId()).build();
|
||||
final List<DeploymentRequest> deploymentRequests = List.of(deploymentRequest);
|
||||
@@ -1676,7 +1675,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
void verifyDSAssignmentFailsForTargetsWithTargetTypesThatAreNotCompatibleWithAnyDs() {
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet("test-ds");
|
||||
final TargetType emptyTargetType = testdataFactory.createTargetType("target-type", Set.of());
|
||||
final Target targetWithEmptyType = testdataFactory.createTarget("test-target", "test-target", emptyTargetType.getId());
|
||||
final Target targetWithEmptyType = testdataFactory.createTarget("test-target", "test-target", emptyTargetType);
|
||||
|
||||
final DeploymentRequest deploymentRequestWithEmptyType = DeploymentManagement
|
||||
.deploymentRequest(targetWithEmptyType.getControllerId(), ds.getId()).build();
|
||||
@@ -1702,7 +1701,7 @@ class DeploymentManagementTest extends AbstractJpaIntegrationTest {
|
||||
private JpaAction assignSet(final Target target, final DistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
implicitLock(ds);
|
||||
assertThat(targetManagement.getByControllerID(target.getControllerId()).get().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(target.getControllerId()).get().getUpdateStatus())
|
||||
.as("wrong update status").isEqualTo(TargetUpdateStatus.PENDING);
|
||||
assertThat(deploymentManagement.getAssignedDistributionSet(target.getControllerId())).as("wrong assigned ds")
|
||||
.contains(ds);
|
||||
|
||||
@@ -717,7 +717,7 @@ class SoftwareModuleManagementTest extends AbstractJpaIntegrationTest {
|
||||
private Action assignSet(final JpaTarget target, final JpaDistributionSet ds) {
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
implicitLock(ds);
|
||||
assertThat(targetManagement.getByControllerID(target.getControllerId()).orElseThrow().getUpdateStatus())
|
||||
assertThat(targetManagement.getByControllerId(target.getControllerId()).orElseThrow().getUpdateStatus())
|
||||
.isEqualTo(TargetUpdateStatus.PENDING);
|
||||
final Optional<DistributionSet> assignedDistributionSet = deploymentManagement
|
||||
.getAssignedDistributionSet(target.getControllerId());
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Set;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -90,7 +91,7 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
targAs = assignTag(targAs, targTagX);
|
||||
|
||||
final Target targSpecialName = targetManagement
|
||||
.update(entityFactory.target().update(targAs.get(0).getControllerId()).name("targ-A-special"));
|
||||
.update(TargetManagement.Update.builder().id(targAs.get(0).getId()).name("targ-A-special").build());
|
||||
|
||||
final String targetDsBIdPref = "targ-B";
|
||||
List<Target> targBs = testdataFactory.createTargets(100, targetDsBIdPref,
|
||||
@@ -134,58 +135,58 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
final List<TargetUpdateStatus> both = List.of(TargetUpdateStatus.UNKNOWN, TargetUpdateStatus.PENDING);
|
||||
|
||||
// get final updated version of targets
|
||||
targAs = targetManagement.getByControllerID(targAs.stream().map(Target::getControllerId).toList());
|
||||
targBs = targetManagement.getByControllerID(targBs.stream().map(Target::getControllerId).toList());
|
||||
targCs = targetManagement.getByControllerID(targCs.stream().map(Target::getControllerId).toList());
|
||||
targAs = targetManagement.getByControllerId(targAs.stream().map(Target::getControllerId).toList());
|
||||
targBs = targetManagement.getByControllerId(targBs.stream().map(Target::getControllerId).toList());
|
||||
targCs = targetManagement.getByControllerId(targCs.stream().map(Target::getControllerId).toList());
|
||||
|
||||
// try to find several targets with different filter settings
|
||||
verifyThat1TargetHasNameAndId("targ-A-special", targSpecialName.getControllerId());
|
||||
verifyThatRepositoryContains500Targets();
|
||||
verifyThat200TargetsHaveTagD(targTagW, concat(targBs, targCs));
|
||||
verifyThat100TargetsContainsGivenTextAndHaveTagAssigned(targTagY, targTagW, targBs);
|
||||
verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, targetManagement.getByControllerID(assignedC).get());
|
||||
verifyThat1TargetHasTagHasDescOrNameAndDs(targTagW, setA, targetManagement.getByControllerId(assignedC).get());
|
||||
verifyThat0TargetsWithTagAndDescOrNameHasDS(targTagW, setA);
|
||||
verifyThat0TargetsWithNameOrdescAndDSHaveTag(targTagX, setA);
|
||||
verifyThat3TargetsHaveDSAssigned(setA, targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.getByControllerID(assignedA).get());
|
||||
verifyThat3TargetsHaveDSAssigned(setA, targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithDescOrNameHasDS(setA, targetManagement.getByControllerId(assignedA).get());
|
||||
List<Target> expected = concat(targAs, targBs, targCs, targDs);
|
||||
expected.removeAll(targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
expected.removeAll(targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThat496TargetsAreInStatusUnknown(unknown, expected);
|
||||
expected = concat(targBs, targCs);
|
||||
expected.removeAll(targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC)));
|
||||
expected.removeAll(targetManagement.getByControllerId(Arrays.asList(assignedB, assignedC)));
|
||||
verifyThat198TargetsAreInStatusUnknownAndHaveGivenTags(targTagY, targTagW, unknown, expected);
|
||||
verifyThat0TargetsAreInStatusUnknownAndHaveDSAssigned(setA, unknown);
|
||||
expected = concat(targAs);
|
||||
expected.remove(targetManagement.getByControllerID(assignedA).get());
|
||||
expected.remove(targetManagement.getByControllerId(assignedA).get());
|
||||
verifyThat99TargetsWithNameOrDescriptionAreInGivenStatus(unknown, expected);
|
||||
expected = concat(targBs);
|
||||
expected.remove(targetManagement.getByControllerID(assignedB).get());
|
||||
expected.remove(targetManagement.getByControllerId(assignedB).get());
|
||||
verifyThat99TargetsWithGivenNameOrDescAndTagAreInStatusUnknown(targTagW, unknown, expected);
|
||||
verifyThat4TargetsAreInStatusPending(pending,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC, assignedE)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC, assignedE)));
|
||||
verifyThat3TargetsWithGivenDSAreInPending(setA, pending,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThat1TargetWithGivenNameOrDescAndDSIsInPending(setA, pending,
|
||||
targetManagement.getByControllerID(assignedA).get());
|
||||
targetManagement.getByControllerId(assignedA).get());
|
||||
verifyThat1TargetWithGivenNameOrDescAndTagAndDSIsInPending(targTagW, setA, pending,
|
||||
targetManagement.getByControllerID(assignedB).get());
|
||||
targetManagement.getByControllerId(assignedB).get());
|
||||
verifyThat2TargetsWithGivenTagAndDSIsInPending(targTagW, setA, pending,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedB, assignedC)));
|
||||
verifyThat2TargetsWithGivenTagAreInPending(targTagW, pending,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedB, assignedC)));
|
||||
verifyThat200targetsWithGivenTagAreInStatusPendingOrUnknown(targTagW, both, concat(targBs, targCs));
|
||||
verifyThat1TargetAIsInStatusPendingAndHasDSInstalled(installedSet, pending,
|
||||
targetManagement.getByControllerID(installedC).get());
|
||||
verifyThat1TargetHasTypeAndDSAssigned(targetTypeX, setB, targetManagement.getByControllerID(assignedE).get());
|
||||
targetManagement.getByControllerId(installedC).get());
|
||||
verifyThat1TargetHasTypeAndDSAssigned(targetTypeX, setB, targetManagement.getByControllerId(assignedE).get());
|
||||
verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(setA,
|
||||
targetManagement.getByControllerID(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
targetManagement.getByControllerId(Arrays.asList(assignedA, assignedB, assignedC)));
|
||||
verifyThatTargetsHasNoTypeAndDSAssignedOrInstalled(installedSet,
|
||||
targetManagement.getByControllerID(Collections.singletonList(installedC)));
|
||||
targetManagement.getByControllerId(Collections.singletonList(installedC)));
|
||||
verifyThat100TargetsContainsGivenTextAndHaveTypeAssigned(targetTypeX, targEs);
|
||||
verifyThat400TargetsContainsGivenTextAndHaveNoTypeAssigned(concat(targAs, targBs, targCs, targDs));
|
||||
|
||||
expected = concat(targBs, targCs);
|
||||
expected.removeAll(targetManagement.getByControllerID(Arrays.asList(assignedB, assignedC)));
|
||||
expected.removeAll(targetManagement.getByControllerId(Arrays.asList(assignedB, assignedC)));
|
||||
verifyThat198TargetsAreInStatusUnknownAndOverdue(unknown, expected);
|
||||
}
|
||||
|
||||
@@ -201,7 +202,7 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(assignedSet, assignedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
assignedtargets = targetManagement.getByControllerID(assignedtargets.stream().map(Target::getControllerId).toList());
|
||||
assignedtargets = targetManagement.getByControllerId(assignedtargets.stream().map(Target::getControllerId).toList());
|
||||
|
||||
assertThat(targetManagement.findByAssignedDistributionSet(assignedSet.getId(), PAGE))
|
||||
.as("Contains the assigned targets").containsAll(assignedtargets)
|
||||
@@ -245,7 +246,7 @@ class TargetManagementSearchTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(assignedSet, installedtargets);
|
||||
|
||||
// get final updated version of targets
|
||||
installedtargets = targetManagement.getByControllerID(installedtargets.stream().map(Target::getControllerId).toList());
|
||||
installedtargets = targetManagement.getByControllerId(installedtargets.stream().map(Target::getControllerId).toList());
|
||||
|
||||
assertThat(targetManagement.findByInstalledDistributionSet(installedSet.getId(), PAGE))
|
||||
.as("Contains the assigned targets").containsAll(installedtargets)
|
||||
|
||||
@@ -15,6 +15,8 @@ import java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
@@ -87,15 +89,6 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
assertPermissions(() -> targetManagement.countByRsqlAndCompatible("controllerId==id", 1L), List.of(SpPermission.READ_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void countByRsqlAndCompatibleAndUpdatablePermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.countByRsqlAndCompatibleAndUpdatable("controllerId==id", 1L),
|
||||
List.of(SpPermission.READ_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@@ -117,7 +110,7 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void createPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.create(entityFactory.target().create().controllerId("controller").name("name")),
|
||||
assertPermissions(() -> targetManagement.create(Create.builder().controllerId("controller").name("name").build()),
|
||||
List.of(SpPermission.CREATE_TARGET));
|
||||
}
|
||||
|
||||
@@ -126,7 +119,7 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void createCollectionPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.create(List.of(entityFactory.target().create().controllerId("controller").name("name"))),
|
||||
assertPermissions(() -> targetManagement.create(List.of(Create.builder().controllerId("controller").name("name").build())),
|
||||
List.of(SpPermission.CREATE_TARGET));
|
||||
}
|
||||
|
||||
@@ -258,15 +251,15 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void getByControllerCollectionIDPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.getByControllerID(List.of("controllerId")), List.of(SpPermission.READ_TARGET));
|
||||
assertPermissions(() -> targetManagement.getByControllerId(List.of("controllerId")), List.of(SpPermission.READ_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.
|
||||
*/
|
||||
@Test
|
||||
void getByControllerIDPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.getByControllerID("controllerId"), List.of(SpPermission.READ_TARGET));
|
||||
void getByControllerIdPermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.getByControllerId("controllerId"), List.of(SpPermission.READ_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,7 +409,7 @@ class TargetManagementSecurityTest extends AbstractJpaIntegrationTest {
|
||||
*/
|
||||
@Test
|
||||
void updatePermissionsCheck() {
|
||||
assertPermissions(() -> targetManagement.update(entityFactory.target().update("controllerId")), List.of(SpPermission.UPDATE_TARGET));
|
||||
assertPermissions(() -> targetManagement.update(Update.builder().id(1L).build()), List.of(SpPermission.UPDATE_TARGET));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,14 +28,15 @@ import java.util.Set;
|
||||
|
||||
import jakarta.validation.ConstraintViolationException;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.im.authentication.SpRole;
|
||||
import org.eclipse.hawkbit.repository.FilterParams;
|
||||
import org.eclipse.hawkbit.repository.Identifiable;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetUpdate;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAssignDistributionSetEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetAttributesRequestedEvent;
|
||||
import org.eclipse.hawkbit.repository.event.remote.TargetDeletedEvent;
|
||||
@@ -77,6 +78,7 @@ import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||
import org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
@@ -96,7 +98,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void nonExistingEntityAccessReturnsNotPresent() {
|
||||
final Target target = testdataFactory.createTarget();
|
||||
assertThat(targetManagement.getByControllerID(NOT_EXIST_ID)).isNotPresent();
|
||||
assertThat(targetManagement.getByControllerId(NOT_EXIST_ID)).isNotPresent();
|
||||
assertThat(targetManagement.get(NOT_EXIST_IDL)).isNotPresent();
|
||||
assertThat(targetManagement.getMetadata(target.getControllerId()).get(NOT_EXIST_ID)).isNull();
|
||||
}
|
||||
@@ -150,7 +152,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
verifyThrownExceptionBy(() -> targetManagement.unassignTag(List.of(NOT_EXIST_ID), tag.getId()), "Target");
|
||||
verifyThrownExceptionBy(() -> targetManagement.unassignTag(List.of(target.getControllerId()), NOT_EXIST_IDL), "TargetTag");
|
||||
verifyThrownExceptionBy(() -> targetManagement.update(entityFactory.target().update(NOT_EXIST_ID)), "Target");
|
||||
verifyThrownExceptionBy(() -> targetManagement.update(Update.builder().id(NOT_EXIST_IDL).build()), "Target");
|
||||
|
||||
verifyThrownExceptionBy(() -> targetManagement.createMetadata(NOT_EXIST_ID, Map.of("123", "123")), "Target");
|
||||
verifyThrownExceptionBy(() -> targetManagement.deleteMetadata(NOT_EXIST_ID, "xxx"), "Target");
|
||||
@@ -166,7 +168,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void getTargetSecurityTokenOnlyWithCorrectPermission() throws Exception {
|
||||
final Target createdTarget = targetManagement
|
||||
.create(entityFactory.target().create().controllerId("targetWithSecurityToken").securityToken("token"));
|
||||
.create(Create.builder().controllerId("targetWithSecurityToken").securityToken("token").build());
|
||||
|
||||
// retrieve security token only with READ_TARGET_SEC_TOKEN permission
|
||||
final String securityTokenWithReadPermission = SecurityContextSwitch.getAs(
|
||||
@@ -203,11 +205,9 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void createTargetThatViolatesUniqueConstraintFails() {
|
||||
final TargetCreate targetCreate = entityFactory.target().create().controllerId("123");
|
||||
final Create targetCreate = Create.builder().controllerId("123").build();
|
||||
targetManagement.create(targetCreate);
|
||||
|
||||
assertThatExceptionOfType(EntityAlreadyExistsException.class)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreate));
|
||||
assertThatExceptionOfType(EntityAlreadyExistsException.class).isThrownBy(() -> targetManagement.create(targetCreate));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,10 +237,10 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 5) })
|
||||
void assignAndUnassignTargetsToTag() {
|
||||
final List<String> assignTarget = new ArrayList<>();
|
||||
assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId123")).getControllerId());
|
||||
assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId1234")).getControllerId());
|
||||
assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId1235")).getControllerId());
|
||||
assignTarget.add(targetManagement.create(entityFactory.target().create().controllerId("targetId1236")).getControllerId());
|
||||
assignTarget.add(targetManagement.create(Create.builder().controllerId("targetId123").build()).getControllerId());
|
||||
assignTarget.add(targetManagement.create(Create.builder().controllerId("targetId1234").build()).getControllerId());
|
||||
assignTarget.add(targetManagement.create(Create.builder().controllerId("targetId1235").build()).getControllerId());
|
||||
assignTarget.add(targetManagement.create(Create.builder().controllerId("targetId1236").build()).getControllerId());
|
||||
|
||||
final TargetTag targetTag = targetTagManagement.create(TargetTagManagement.Create.builder().name("Tag1").build());
|
||||
|
||||
@@ -273,7 +273,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetDeletedEvent.class, count = 12),
|
||||
@Expect(type = TargetUpdatedEvent.class, count = 6) })
|
||||
void deleteAndCreateTargets() {
|
||||
Target target = targetManagement.create(entityFactory.target().create().controllerId("targetId123"));
|
||||
Target target = targetManagement.create(Create.builder().controllerId("targetId123").build());
|
||||
assertThat(targetManagement.count()).as("target count is wrong").isEqualTo(1);
|
||||
targetManagement.delete(Collections.singletonList(target.getId()));
|
||||
assertThat(targetManagement.count()).as("target count is wrong").isZero();
|
||||
@@ -287,7 +287,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final List<Long> targets = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
target = targetManagement.create(entityFactory.target().create().controllerId("" + i));
|
||||
target = targetManagement.create(Create.builder().controllerId("" + i).build());
|
||||
targets.add(target.getId());
|
||||
targets.add(createTargetWithAttributes("" + (i * i + 1000)).getId());
|
||||
}
|
||||
@@ -312,7 +312,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetAssignDistributionSetEvent.class, count = 2),
|
||||
@Expect(type = TargetAttributesRequestedEvent.class, count = 1),
|
||||
@Expect(type = TargetPollEvent.class, count = 1) })
|
||||
void findTargetByControllerIDWithDetails() {
|
||||
void findTargetByControllerIdWithDetails() {
|
||||
final DistributionSet testDs1 = testdataFactory.createDistributionSet("test");
|
||||
final DistributionSet testDs2 = testdataFactory.createDistributionSet("test2");
|
||||
|
||||
@@ -342,7 +342,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assignDistributionSet(testDs2.getId(), "4711");
|
||||
implicitLock(testDs2);
|
||||
|
||||
Target target = targetManagement.getByControllerID("4711").orElseThrow(IllegalStateException::new);
|
||||
Target target = targetManagement.getByControllerId("4711").orElseThrow(IllegalStateException::new);
|
||||
// read data
|
||||
|
||||
assertThat(targetManagement.countByAssignedDistributionSet(testDs1.getId())).as("Target count is wrong")
|
||||
@@ -386,7 +386,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 1) })
|
||||
void createTargetDuplicate() {
|
||||
final TargetCreate targetCreate = entityFactory.target().create().controllerId("4711");
|
||||
final Create targetCreate = Create.builder().controllerId("4711").build();
|
||||
targetManagement.create(targetCreate);
|
||||
assertThatExceptionOfType(EntityAlreadyExistsException.class)
|
||||
.as("Target already exists")
|
||||
@@ -414,23 +414,18 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
Awaitility.await().until(() -> System.currentTimeMillis() > createdAt + 1);
|
||||
|
||||
savedTarget = targetManagement.update(
|
||||
entityFactory.target().update(savedTarget.getControllerId()).description("changed description"));
|
||||
assertThat(createdAt).as("CreatedAt compared with saved modifiedAt")
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
assertThat(modifiedAt).as("ModifiedAt compared with saved modifiedAt")
|
||||
.isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
savedTarget = targetManagement.update(Update.builder().id(savedTarget.getId()).description("changed description").build());
|
||||
assertThat(createdAt).as("CreatedAt compared with saved modifiedAt").isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
assertThat(modifiedAt).as("ModifiedAt compared with saved modifiedAt").isNotEqualTo(savedTarget.getLastModifiedAt());
|
||||
modifiedAt = savedTarget.getLastModifiedAt();
|
||||
|
||||
final Target foundTarget = targetManagement.getByControllerID(savedTarget.getControllerId())
|
||||
final Target foundTarget = targetManagement.getByControllerId(savedTarget.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(foundTarget).as("The target should not be null").isNotNull();
|
||||
assertThat(myCtrlID).as("ControllerId compared with saved controllerId")
|
||||
.isEqualTo(foundTarget.getControllerId());
|
||||
assertThat(myCtrlID).as("ControllerId compared with saved controllerId").isEqualTo(foundTarget.getControllerId());
|
||||
assertThat(savedTarget).as("Target compared with saved target").isEqualTo(foundTarget);
|
||||
assertThat(createdAt).as("CreatedAt compared with saved createdAt").isEqualTo(foundTarget.getCreatedAt());
|
||||
assertThat(modifiedAt).as("LastModifiedAt compared with saved lastModifiedAt")
|
||||
.isEqualTo(foundTarget.getLastModifiedAt());
|
||||
assertThat(modifiedAt).as("LastModifiedAt compared with saved lastModifiedAt").isEqualTo(foundTarget.getLastModifiedAt());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,7 +439,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Expect(type = TargetDeletedEvent.class, count = 51) })
|
||||
void bulkTargetCreationAndDelete() {
|
||||
final String myCtrlID = "myCtrlID";
|
||||
List<Target> firstList = testdataFactory.createTargets(100, myCtrlID, "first description");
|
||||
List<? extends Target> firstList = testdataFactory.createTargets(100, myCtrlID, "first description");
|
||||
|
||||
final Target extra = testdataFactory.createTarget("myCtrlID-00081XX");
|
||||
|
||||
@@ -459,7 +454,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
// lastModifiedAt
|
||||
firstList = firstList.stream()
|
||||
.map(t -> targetManagement.update(
|
||||
entityFactory.target().update(t.getControllerId()).name(t.getName().concat("\tchanged"))))
|
||||
Update.builder().id(t.getId()).name(t.getName().concat("\tchanged")).build()))
|
||||
.toList();
|
||||
|
||||
// verify that all entries are found
|
||||
@@ -490,17 +485,17 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
targetManagement.deleteByControllerID(extra.getControllerId());
|
||||
|
||||
final int numberToDelete = 50;
|
||||
final Collection<Target> targetsToDelete = firstList.subList(0, numberToDelete);
|
||||
final Collection<? extends Target> targetsToDelete = firstList.subList(0, numberToDelete);
|
||||
final Target[] deletedTargets = toArray(targetsToDelete, Target.class);
|
||||
final List<Long> targetsIdsToDelete = targetsToDelete.stream().map(Target::getId).toList();
|
||||
|
||||
targetManagement.delete(targetsIdsToDelete);
|
||||
|
||||
final List<Target> targetsLeft = targetManagement.findAll(PageRequest.of(0, 200)).getContent();
|
||||
final List<? extends Target> targetsLeft = targetManagement.findAll(PageRequest.of(0, 200)).getContent();
|
||||
assertThat(firstList.spliterator().getExactSizeIfKnown() - numberToDelete).as("Size of split list")
|
||||
.isEqualTo(targetsLeft.spliterator().getExactSizeIfKnown());
|
||||
|
||||
assertThat(targetsLeft).as("Not all undeleted found").doesNotContain(deletedTargets);
|
||||
Assertions.<Target>assertThat(targetsLeft).as("Not all undeleted found").doesNotContain(deletedTargets);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -523,14 +518,14 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<? extends TargetTag> t2Tags = testdataFactory.createTargetTags(noT2Tags, "tag2");
|
||||
t2Tags.forEach(tag -> targetManagement.assignTag(Collections.singletonList(t2.getControllerId()), tag.getId()));
|
||||
|
||||
final Target t11 = targetManagement.getByControllerID(t1.getControllerId())
|
||||
final Target t11 = targetManagement.getByControllerId(t1.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(getTargetTags(t11.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).containsAll(t1Tags);
|
||||
assertThat(getTargetTags(t11.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT1Tags).doesNotContain(toArray(t2Tags, TargetTag.class));
|
||||
|
||||
final Target t21 = targetManagement.getByControllerID(t2.getControllerId())
|
||||
final Target t21 = targetManagement.getByControllerId(t2.getControllerId())
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(getTargetTags(t21.getControllerId())).as("Tag size is wrong")
|
||||
.hasSize(noT2Tags).containsAll(t2Tags);
|
||||
@@ -707,7 +702,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
controllerManagement.findOrRegisterTargetIfItDoesNotExist(knownTargetControllerId, new URI("http://127.0.0.1"));
|
||||
|
||||
SecurityContextSwitch.getAs(SecurityContextSwitch.withUser("bumlux", "READ_TARGET"), () -> {
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerID(knownTargetControllerId)
|
||||
final Target findTargetByControllerID = targetManagement.getByControllerId(knownTargetControllerId)
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertThat(findTargetByControllerID).isNotNull();
|
||||
assertThat(findTargetByControllerID.getPollStatus()).isNotNull();
|
||||
@@ -729,7 +724,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
testdataFactory.createTargets(25, "target-id-B", "first description");
|
||||
|
||||
final Slice<Target> foundTargets = targetManagement.findByRsql(rsqlFilter, PAGE);
|
||||
final Page<? extends Target> foundTargets = targetManagement.findByRsql(rsqlFilter, PAGE);
|
||||
final long foundTargetsCount = targetManagement.countByRsql(rsqlFilter);
|
||||
|
||||
assertThat(targetManagement.count()).as("Total targets").isEqualTo(50L);
|
||||
@@ -749,8 +744,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
testdataFactory.createTarget("test" + i);
|
||||
}
|
||||
|
||||
final List<Target> foundDs = targetManagement.get(searchIds);
|
||||
|
||||
final List<? extends Target> foundDs = targetManagement.get(searchIds);
|
||||
assertThat(foundDs).hasSize(3);
|
||||
|
||||
final List<Long> collect = foundDs.stream().map(Target::getId).toList();
|
||||
@@ -769,7 +763,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetManagement.isControllerAttributesRequested(knownControllerId)).isFalse();
|
||||
|
||||
targetManagement.requestControllerAttributes(knownControllerId);
|
||||
final Target updated = targetManagement.getByControllerID(knownControllerId).get();
|
||||
final Target updated = targetManagement.getByControllerId(knownControllerId).get();
|
||||
|
||||
assertThat(target.isRequestControllerAttributes()).isFalse();
|
||||
assertThat(targetManagement.findByControllerAttributesRequested(PAGE).getContent()).contains(updated);
|
||||
@@ -892,7 +886,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final List<? extends TargetType> targetTypes = testdataFactory.createTargetTypes("targettype", 2);
|
||||
assertThat(targetTypes).hasSize(2);
|
||||
// create a target
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget", targetTypes.get(0).getId());
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget", targetTypes.get(0));
|
||||
// initial opt lock revision must be one
|
||||
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
|
||||
assertThat(targetFound).isPresent();
|
||||
@@ -900,8 +894,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
assertThat(targetFound.get().getTargetType().getId()).isEqualTo(targetTypes.get(0).getId());
|
||||
|
||||
// update the target type
|
||||
final TargetUpdate targetUpdate = entityFactory.target().update(target.getControllerId())
|
||||
.targetType(targetTypes.get(1).getId());
|
||||
final Update targetUpdate = Update.builder().id(target.getId()).targetType(targetTypes.get(1)).build();
|
||||
targetManagement.update(targetUpdate);
|
||||
|
||||
// opt lock revision must be changed
|
||||
@@ -1033,7 +1026,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final TargetType targetType = testdataFactory.findOrCreateTargetType("targettype");
|
||||
assertThat(targetType).isNotNull();
|
||||
// create a target
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget", targetType.getId());
|
||||
final Target target = testdataFactory.createTarget("target1", "testtarget", targetType);
|
||||
// initial opt lock revision must be one
|
||||
final Optional<JpaTarget> targetFound = targetRepository.findById(target.getId());
|
||||
assertThat(targetFound).isPresent();
|
||||
@@ -1089,7 +1082,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
final String controllerId2 = "target2";
|
||||
createTargetWithMetadata(controllerId1, 2);
|
||||
final TargetType type = testdataFactory.createTargetType("type1", Set.of());
|
||||
createTargetWithTargetTypeAndMetadata(controllerId2, type.getId(), 2);
|
||||
createTargetWithTargetTypeAndMetadata(controllerId2, type, 2);
|
||||
|
||||
assertThat(targetManagement.count()).as("Total targets").isEqualTo(2);
|
||||
|
||||
@@ -1148,7 +1141,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
void matchesFilterWrongType() {
|
||||
final TargetType type = testdataFactory.createTargetType("type", Set.of());
|
||||
final Target target = testdataFactory.createTarget("target", "target", type.getId());
|
||||
final Target target = testdataFactory.createTarget("target", "target", type);
|
||||
final DistributionSet ds = testdataFactory.createDistributionSet();
|
||||
|
||||
assertThat(targetManagement.isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable(target.getControllerId(),
|
||||
@@ -1263,155 +1256,138 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void createAndUpdateTargetWithInvalidDescription(final Target target) {
|
||||
final TargetCreate targetCreateTooLong = entityFactory.target().create().controllerId("a")
|
||||
.description(randomString(513));
|
||||
final Create targetCreateTooLong = Create.builder().controllerId("a").description(randomString(513)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long description should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateTooLong));
|
||||
|
||||
final TargetCreate targetCreateInvalidHtml = entityFactory.target().create().controllerId("a").description(INVALID_TEXT_HTML);
|
||||
final Create targetCreateInvalidHtml = Create.builder().controllerId("a").description(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid description should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateInvalidHtml));
|
||||
|
||||
final TargetUpdate targetUpdateTooLong = entityFactory.target().update(target.getControllerId())
|
||||
.description(randomString(513));
|
||||
final Update targetUpdateTooLong = Update.builder().id(target.getId()).description(randomString(513)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long description should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateTooLong));
|
||||
|
||||
final TargetUpdate targetUpdateInvalidHtml = entityFactory.target().update(target.getControllerId()).description(INVALID_TEXT_HTML);
|
||||
final Update targetUpdateInvalidHtml = Update.builder().id(target.getId()).description(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid description should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateInvalidHtml));
|
||||
}
|
||||
|
||||
private void createAndUpdateTargetWithInvalidName(final Target target) {
|
||||
final TargetCreate targetCreateTooLong = entityFactory.target().create().controllerId("a")
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1));
|
||||
final Create targetCreateTooLong = Create.builder().controllerId("a").name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long name should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateTooLong));
|
||||
|
||||
final TargetCreate targetCreateInvalidHtml = entityFactory.target().create().controllerId("a").name(INVALID_TEXT_HTML);
|
||||
final Create targetCreateInvalidHtml = Create.builder().controllerId("a").name(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid name should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateInvalidHtml));
|
||||
|
||||
final TargetUpdate targetUpdateTooLong = entityFactory.target().update(target.getControllerId())
|
||||
.name(randomString(NamedEntity.NAME_MAX_SIZE + 1));
|
||||
final Update targetUpdateTooLong = Update.builder().id(target.getId()).name(randomString(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long name should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateTooLong));
|
||||
|
||||
final TargetUpdate targetUpdateInvalidHtml = entityFactory.target().update(target.getControllerId()).name(INVALID_TEXT_HTML);
|
||||
final Update targetUpdateInvalidHtml = Update.builder().id(target.getId()).name(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid name should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateInvalidHtml));
|
||||
|
||||
final TargetUpdate targetUpdateEmpty = entityFactory.target().update(target.getControllerId()).name("");
|
||||
final Update targetUpdateEmpty = Update.builder().id(target.getId()).name("").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too short name should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateEmpty));
|
||||
|
||||
}
|
||||
|
||||
private void createAndUpdateTargetWithInvalidSecurityToken(final Target target) {
|
||||
final TargetCreate targetCreateTooLong = entityFactory.target().create().controllerId("a")
|
||||
.securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1));
|
||||
final Create targetCreateTooLong = Create.builder()
|
||||
.controllerId("a").securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long token should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateTooLong));
|
||||
|
||||
final TargetCreate targetCreateInvalidTextHtml = entityFactory.target().create().controllerId("a").securityToken(INVALID_TEXT_HTML);
|
||||
final Create targetCreateInvalidTextHtml = Create.builder().controllerId("a").securityToken(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid token should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateInvalidTextHtml));
|
||||
|
||||
final TargetUpdate targetUpdateTooLong = entityFactory.target().update(target.getControllerId())
|
||||
.securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1));
|
||||
final Update targetUpdateTooLong = Update.builder().id(target.getId())
|
||||
.securityToken(randomString(Target.SECURITY_TOKEN_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long token should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateTooLong));
|
||||
|
||||
final TargetUpdate targetUpdateInvalidHtml = entityFactory.target().update(target.getControllerId()).securityToken(INVALID_TEXT_HTML);
|
||||
final Update targetUpdateInvalidHtml = Update.builder().id(target.getId()).securityToken(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid token should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateInvalidHtml));
|
||||
|
||||
final TargetUpdate targetUpdateEmpty = entityFactory.target().update(target.getControllerId()).securityToken("");
|
||||
final Update targetUpdateEmpty = Update.builder().id(target.getId()).securityToken("").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too short token should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdateEmpty));
|
||||
}
|
||||
|
||||
private void createAndUpdateTargetWithInvalidAddress(final Target target) {
|
||||
final TargetCreate targetCreate = entityFactory.target().create().controllerId("a").address(randomString(513));
|
||||
final Create targetCreate = Create.builder().controllerId("a").address(randomString(513)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long address should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreate));
|
||||
|
||||
final TargetCreate targetCreate2 = entityFactory.target().create().controllerId("a");
|
||||
assertThatExceptionOfType(InvalidTargetAddressException.class)
|
||||
.as("target with invalid should not be created")
|
||||
.isThrownBy(() -> targetCreate2.address(INVALID_TEXT_HTML));
|
||||
|
||||
final TargetUpdate targetUpdate = entityFactory.target().update(target.getControllerId()).address(randomString(513));
|
||||
final Update targetUpdate = Update.builder().id(target.getId()).address(randomString(513)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long address should not be updated")
|
||||
.isThrownBy(() -> targetManagement.update(targetUpdate));
|
||||
|
||||
final TargetUpdate targetUpdate2 = entityFactory.target().update(target.getControllerId());
|
||||
assertThatExceptionOfType(InvalidTargetAddressException.class)
|
||||
.as("target with invalid address should not be updated")
|
||||
.isThrownBy(() -> targetUpdate2.address(INVALID_TEXT_HTML));
|
||||
}
|
||||
|
||||
private void createTargetWithInvalidControllerId() {
|
||||
final TargetCreate targetCreateEmpty = entityFactory.target().create().controllerId("");
|
||||
final Create targetCreateEmpty = Create.builder().controllerId("").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with empty controller id should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateEmpty));
|
||||
|
||||
final TargetCreate targetCreateNull = entityFactory.target().create().controllerId(null);
|
||||
final Create targetCreateNull = Create.builder().controllerId(null).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with null controller id should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateNull));
|
||||
|
||||
final TargetCreate targetCreateTooLongControllerId = entityFactory.target().create()
|
||||
.controllerId(randomString(Target.CONTROLLER_ID_MAX_SIZE + 1));
|
||||
final Create targetCreateTooLongControllerId = Create.builder()
|
||||
.controllerId(randomString(Target.CONTROLLER_ID_MAX_SIZE + 1)).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with too long controller id should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateTooLongControllerId));
|
||||
|
||||
final TargetCreate targetCreateInvaidTextHtml = entityFactory.target().create().controllerId(INVALID_TEXT_HTML);
|
||||
final Create targetCreateInvaidTextHtml = Create.builder().controllerId(INVALID_TEXT_HTML).build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class)
|
||||
.as("target with invalid controller id should not be created")
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateInvaidTextHtml));
|
||||
|
||||
final TargetCreate targetCreateEmptyTrim = entityFactory.target().create().controllerId(" ");
|
||||
final Create targetCreateEmptyTrim = Create.builder().controllerId(" ").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateEmptyTrim));
|
||||
|
||||
final TargetCreate targetCreateContainingSpace = entityFactory.target().create().controllerId("a b");
|
||||
final Create targetCreateContainingSpace = Create.builder().controllerId("a b").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateContainingSpace));
|
||||
|
||||
final TargetCreate targetCreateEmptyTrim2 = entityFactory.target().create().controllerId(" ");
|
||||
final Create targetCreateEmptyTrim2 = Create.builder().controllerId(" ").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateEmptyTrim2));
|
||||
|
||||
final TargetCreate targetCreateContainingSpaces = entityFactory.target().create().controllerId("aaa bbb");
|
||||
final Create targetCreateContainingSpaces = Create.builder().controllerId("aaa bbb").build();
|
||||
assertThatExceptionOfType(ConstraintViolationException.class).as(WHITESPACE_ERROR)
|
||||
.isThrownBy(() -> targetManagement.create(targetCreateContainingSpaces));
|
||||
|
||||
}
|
||||
|
||||
private Target createTargetWithAttributes(final String controllerId) {
|
||||
final Map<String, String> testData = new HashMap<>();
|
||||
testData.put("test1", "testdata1");
|
||||
|
||||
targetManagement.create(entityFactory.target().create().controllerId(controllerId));
|
||||
targetManagement.create(Create.builder().controllerId(controllerId).build());
|
||||
final Target target = controllerManagement.updateControllerAttributes(controllerId, testData, null);
|
||||
|
||||
assertThat(targetManagement.getControllerAttributes(controllerId)).as("Controller Attributes are wrong").isEqualTo(testData);
|
||||
@@ -1448,7 +1424,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void checkTargetHasNotTags(final Iterable<Target> targets, final TargetTag... tags) {
|
||||
for (final Target tl : targets) {
|
||||
targetManagement.getByControllerID(tl.getControllerId()).get();
|
||||
targetManagement.getByControllerId(tl.getControllerId()).get();
|
||||
|
||||
for (final Tag tag : tags) {
|
||||
for (final Tag tt : getTargetTags(tl.getControllerId())) {
|
||||
@@ -1485,8 +1461,8 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
return target;
|
||||
}
|
||||
|
||||
private Target createTargetWithTargetTypeAndMetadata(final String controllerId, final long targetTypeId, final int count) {
|
||||
final Target target = testdataFactory.createTarget(controllerId, controllerId, targetTypeId);
|
||||
private Target createTargetWithTargetTypeAndMetadata(final String controllerId, final TargetType targetType, final int count) {
|
||||
final Target target = testdataFactory.createTarget(controllerId, controllerId, targetType);
|
||||
|
||||
for (int index = 1; index <= count; index++) {
|
||||
insertMetadata("key" + index, controllerId + "-value" + index, target);
|
||||
@@ -1514,7 +1490,7 @@ class TargetManagementTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void validateFoundTargetsByRsql(final String rsqlFilter, final String... controllerIds) {
|
||||
final Slice<Target> foundTargetsByMetadataAndControllerId = targetManagement.findByRsql(rsqlFilter, PAGE);
|
||||
final Page<? extends Target> foundTargetsByMetadataAndControllerId = targetManagement.findByRsql(rsqlFilter, PAGE);
|
||||
final long foundTargetsByMetadataAndControllerIdCount = targetManagement.countByRsql(rsqlFilter);
|
||||
|
||||
assertThat(foundTargetsByMetadataAndControllerId.getNumberOfElements())
|
||||
|
||||
@@ -133,7 +133,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
List<Target> result = assignTag(groupA, tag);
|
||||
assertThat(result)
|
||||
.containsAll(
|
||||
targetManagement.getByControllerID(groupA.stream().map(Target::getControllerId).toList()))
|
||||
targetManagement.getByControllerId(groupA.stream().map(Target::getControllerId).toList()))
|
||||
.size().isEqualTo(20);
|
||||
assertThat(targetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent().stream().map(Target::getControllerId).sorted()
|
||||
.toList())
|
||||
@@ -144,7 +144,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
result = assignTag(groupAB, tag);
|
||||
assertThat(result)
|
||||
.containsAll(
|
||||
targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).toList()))
|
||||
targetManagement.getByControllerId(groupAB.stream().map(Target::getControllerId).toList()))
|
||||
.size().isEqualTo(40);
|
||||
assertThat(targetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent().stream().map(Target::getControllerId).sorted()
|
||||
.toList())
|
||||
@@ -153,7 +153,7 @@ class TargetTagManagementTest extends AbstractJpaIntegrationTest {
|
||||
// toggle A+B -> both unassigned
|
||||
result = unassignTag(groupAB, tag);
|
||||
assertThat(result)
|
||||
.containsAll(targetManagement.getByControllerID(groupAB.stream().map(Target::getControllerId).toList()))
|
||||
.containsAll(targetManagement.getByControllerId(groupAB.stream().map(Target::getControllerId).toList()))
|
||||
.size().isEqualTo(40);
|
||||
assertThat(targetManagement.findByTag(tag.getId(), Pageable.unpaged()).getContent()).isEmpty();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ package org.eclipse.hawkbit.repository.jpa.model;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Update;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.EntityInterceptor;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.helper.EntityInterceptorHolder;
|
||||
@@ -59,7 +60,7 @@ class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
final Target targetToBeCreated = testdataFactory.createTarget("targetToBeCreated");
|
||||
|
||||
final Target loadedTarget = targetManagement.getByControllerID(targetToBeCreated.getControllerId()).get();
|
||||
final Target loadedTarget = targetManagement.getByControllerId(targetToBeCreated.getControllerId()).get();
|
||||
assertThat(postLoadEntityListener.getEntity()).isNotNull();
|
||||
assertThat(postLoadEntityListener.getEntity()).isEqualTo(loadedTarget);
|
||||
}
|
||||
@@ -105,9 +106,8 @@ class EntityInterceptorListenerTest extends AbstractJpaIntegrationTest {
|
||||
|
||||
private void executeUpdateAndAssertCallbackResult(final AbstractEntityListener entityInterceptor) {
|
||||
final Target updateTarget = targetManagement.update(
|
||||
entityFactory.target()
|
||||
.update(addListenerAndCreateTarget(entityInterceptor, "targetToBeCreated").getControllerId())
|
||||
.name("New"));
|
||||
Update.builder().id(addListenerAndCreateTarget(entityInterceptor, "targetToBeCreated").getId())
|
||||
.name("New").build());
|
||||
|
||||
assertThat(entityInterceptor.getEntity()).isNotNull();
|
||||
assertThat(entityInterceptor.getEntity()).isEqualTo(updateTarget);
|
||||
|
||||
@@ -13,6 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.exception.RSQLParameterUnsupportedFieldException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
import org.eclipse.hawkbit.repository.jpa.model.JpaAction;
|
||||
@@ -39,8 +40,7 @@ class RsqlActionFieldsTest extends AbstractJpaIntegrationTest {
|
||||
@BeforeEach
|
||||
void setupBeforeTest() {
|
||||
final DistributionSet dsA = testdataFactory.createDistributionSet("daA");
|
||||
target = (JpaTarget) targetManagement
|
||||
.create(entityFactory.target().create().controllerId("targetId123").description("targetId123"));
|
||||
target = (JpaTarget) targetManagement.create(Create.builder().controllerId("targetId123").description("targetId123").build());
|
||||
|
||||
action = newJpaAction(dsA, false, null);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TargetManagement.Create;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeFields;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
@@ -31,7 +32,7 @@ import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.test.util.TestdataFactory;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Page;
|
||||
|
||||
/**
|
||||
* Feature: Component Tests - Repository<br/>
|
||||
@@ -67,20 +68,14 @@ class RsqlTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
targetTagManagement.create(TargetTagManagement.Create.builder().name("Tag4").build());
|
||||
|
||||
target = targetManagement.create(
|
||||
entityFactory.target().create()
|
||||
.controllerId("targetId123")
|
||||
.name("targetName123")
|
||||
.description("targetDesc123"));
|
||||
Create.builder().controllerId("targetId123").name("targetName123").description("targetDesc123").build());
|
||||
target = controllerManagement.updateControllerAttributes(target.getControllerId(), Map.of("revision", "1.1"), null);
|
||||
target = controllerManagement.findOrRegisterTargetIfItDoesNotExist(target.getControllerId(), LOCALHOST);
|
||||
targetManagement.createMetadata(target.getControllerId(), Map.of("metaKey", "metaValue"));
|
||||
assignDistributionSet(ds.getId(), target.getControllerId());
|
||||
targetManagement.assignType(target.getControllerId(), targetType1.getId());
|
||||
|
||||
target2 = targetManagement.create(
|
||||
entityFactory.target().create()
|
||||
.controllerId("targetId1234")
|
||||
.description("targetId1234"));
|
||||
target2 = targetManagement.create(Create.builder().controllerId("targetId1234").description("targetId1234").build());
|
||||
target2 = controllerManagement.updateControllerAttributes(target2.getControllerId(), Map.of("revision", "1.2"), null);
|
||||
targetManagement.assignType(target2.getControllerId(), targetType2.getId());
|
||||
targetManagement.createMetadata(target2.getControllerId(), Map.of("metaKey", "value"));
|
||||
@@ -435,7 +430,7 @@ class RsqlTargetFieldTest extends AbstractJpaIntegrationTest {
|
||||
}
|
||||
|
||||
private void assertRSQLQuery(final String rsql, final long expectedTargets) {
|
||||
final Slice<Target> findTargetPage = targetManagement.findByRsql(rsql, PAGE);
|
||||
final Page<? extends Target> findTargetPage = targetManagement.findByRsql(rsql, PAGE);
|
||||
assertThat(findTargetPage).isNotNull();
|
||||
assertThat(findTargetPage.getNumberOfElements()).isEqualTo(expectedTargets);
|
||||
assertThat(targetManagement.countByRsql(rsql)).isEqualTo(expectedTargets);
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Slice;
|
||||
|
||||
/**
|
||||
@@ -53,10 +54,10 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
createTargetForTenant(knownControllerId, anotherTenant);
|
||||
|
||||
// ensure both tenants see their target
|
||||
final Slice<Target> findTargetsForTenant = findTargetsForTenant(tenant);
|
||||
final Page<? extends Target> findTargetsForTenant = findTargetsForTenant(tenant);
|
||||
assertThat(findTargetsForTenant).hasSize(1);
|
||||
assertThat(findTargetsForTenant.getContent().get(0).getTenant().toUpperCase()).isEqualTo(tenant.toUpperCase());
|
||||
final Slice<Target> findTargetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
final Page<? extends Target> findTargetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
assertThat(findTargetsForAnotherTenant).hasSize(1);
|
||||
assertThat(findTargetsForAnotherTenant.getContent().get(0).getTenant().toUpperCase())
|
||||
.isEqualTo(anotherTenant.toUpperCase());
|
||||
@@ -74,12 +75,12 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
createTargetForTenant(controllerAnotherTenant, anotherTenant);
|
||||
|
||||
// find all targets for current tenant "mytenant"
|
||||
final Slice<Target> findTargetsAll = targetManagement.findAll(PAGE);
|
||||
final Page<? extends Target> findTargetsAll = targetManagement.findAll(PAGE);
|
||||
// no target has been created for "mytenant"
|
||||
assertThat(findTargetsAll).isEmpty();
|
||||
|
||||
// find all targets for anotherTenant
|
||||
final Slice<Target> findTargetsForTenant = findTargetsForTenant(anotherTenant);
|
||||
final Page<? extends Target> findTargetsForTenant = findTargetsForTenant(anotherTenant);
|
||||
// another tenant should have targets
|
||||
assertThat(findTargetsForTenant).hasSize(1);
|
||||
}
|
||||
@@ -143,7 +144,7 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
// ok
|
||||
}
|
||||
|
||||
Slice<Target> targetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
Page<? extends Target> targetsForAnotherTenant = findTargetsForTenant(anotherTenant);
|
||||
assertThat(targetsForAnotherTenant).hasSize(1);
|
||||
|
||||
// ensure another tenant can delete the target
|
||||
@@ -184,7 +185,7 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
return runAsTenant(tenant, () -> testdataFactory.createTarget(controllerId));
|
||||
}
|
||||
|
||||
private Slice<Target> findTargetsForTenant(final String tenant) throws Exception {
|
||||
private Page<? extends Target> findTargetsForTenant(final String tenant) throws Exception {
|
||||
return runAsTenant(tenant, () -> targetManagement.findAll(PAGE));
|
||||
}
|
||||
|
||||
@@ -195,8 +196,8 @@ class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
|
||||
});
|
||||
}
|
||||
|
||||
private DistributionSet createDistributionSetForTenant(final String tenant) throws Exception {
|
||||
return runAsTenant(tenant, () -> testdataFactory.createDistributionSet());
|
||||
private void createDistributionSetForTenant(final String tenant) throws Exception {
|
||||
runAsTenant(tenant, () -> testdataFactory.createDistributionSet());
|
||||
}
|
||||
|
||||
private Slice<? extends DistributionSet> findDistributionSetForTenant(final String tenant) throws Exception {
|
||||
|
||||
@@ -143,7 +143,7 @@ public abstract class AbstractIntegrationTest {
|
||||
@Autowired
|
||||
protected ControllerManagement controllerManagement;
|
||||
@Autowired
|
||||
protected TargetManagement targetManagement;
|
||||
protected TargetManagement<? extends Target> targetManagement;
|
||||
@Autowired
|
||||
protected TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
@Autowired
|
||||
|
||||
@@ -50,7 +50,6 @@ import org.eclipse.hawkbit.repository.TargetManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTagManagement;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.builder.DynamicRolloutGroupTemplate;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetCreate;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
@@ -154,7 +153,7 @@ public class TestdataFactory {
|
||||
private final DistributionSetTagManagement<?> distributionSetTagManagement;
|
||||
private final DistributionSetTypeManagement<?> distributionSetTypeManagement;
|
||||
private final DistributionSetInvalidationManagement distributionSetInvalidationManagement;
|
||||
private final TargetManagement targetManagement;
|
||||
private final TargetManagement<? extends Target> targetManagement;
|
||||
private final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement;
|
||||
private final TargetTypeManagement<? extends TargetType> targetTypeManagement;
|
||||
private final TargetTagManagement<? extends TargetTag> targetTagManagement;
|
||||
@@ -173,7 +172,8 @@ public class TestdataFactory {
|
||||
final DistributionSetTypeManagement<? extends DistributionSetType> distributionSetTypeManagement,
|
||||
final DistributionSetTagManagement<? extends DistributionSetTag> distributionSetTagManagement,
|
||||
final DistributionSetInvalidationManagement distributionSetInvalidationManagement,
|
||||
final TargetManagement targetManagement, final TargetFilterQueryManagement targetFilterQueryManagement,
|
||||
final TargetManagement<? extends Target> targetManagement,
|
||||
final TargetFilterQueryManagement<? extends TargetFilterQuery> targetFilterQueryManagement,
|
||||
final TargetTypeManagement<? extends TargetType> targetTypeManagement,
|
||||
final TargetTagManagement<? extends TargetTag> targetTagManagement,
|
||||
final DeploymentManagement deploymentManagement,
|
||||
@@ -594,27 +594,21 @@ public class TestdataFactory {
|
||||
* @return persisted {@link Target}
|
||||
*/
|
||||
public Target createTarget(final String controllerId, final String targetName) {
|
||||
final Target target = targetManagement.create(entityFactory.target().create().controllerId(controllerId).name(targetName));
|
||||
final Target target = targetManagement.create(TargetManagement.Create.builder().controllerId(controllerId).name(targetName).build());
|
||||
assertTargetProperlyCreated(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
public Target createTarget(final String controllerId, final String targetName, final String address) {
|
||||
final Target target = targetManagement.create(
|
||||
entityFactory.target().create().controllerId(controllerId).name(targetName).address(address));
|
||||
TargetManagement.Create.builder().controllerId(controllerId).name(targetName).address(address).build());
|
||||
assertTargetProperlyCreated(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param controllerId of the target
|
||||
* @param targetName name of the target
|
||||
* @param targetTypeId target type id
|
||||
* @return persisted {@link Target}
|
||||
*/
|
||||
public Target createTarget(final String controllerId, final String targetName, final Long targetTypeId) {
|
||||
public Target createTarget(final String controllerId, final String targetName, final TargetType targetType) {
|
||||
final Target target = targetManagement.create(
|
||||
entityFactory.target().create().controllerId(controllerId).name(targetName).targetType(targetTypeId));
|
||||
TargetManagement.Create.builder().controllerId(controllerId).name(targetName).targetType(targetType).build());
|
||||
assertTargetProperlyCreated(target);
|
||||
return target;
|
||||
}
|
||||
@@ -809,9 +803,9 @@ public class TestdataFactory {
|
||||
}
|
||||
|
||||
public List<Target> createTargets(final String prefix, final int offset, final int number) {
|
||||
final List<TargetCreate> targets = new ArrayList<>(number);
|
||||
final List<TargetManagement.Create> targets = new ArrayList<>(number);
|
||||
for (int i = 0; i < number; i++) {
|
||||
targets.add(entityFactory.target().create().controllerId(prefix + (offset + i)));
|
||||
targets.add(TargetManagement.Create.builder().controllerId(prefix + (offset + i)).build());
|
||||
}
|
||||
return createTargets(targets);
|
||||
}
|
||||
@@ -825,9 +819,9 @@ public class TestdataFactory {
|
||||
* @return {@link List} of {@link Target} entities
|
||||
*/
|
||||
public List<Target> createTargetsWithType(final int number, final String controllerIdPrefix, final TargetType targetType) {
|
||||
final List<TargetCreate> targets = new ArrayList<>(number);
|
||||
final List<TargetManagement.Create> targets = new ArrayList<>(number);
|
||||
for (int i = 0; i < number; i++) {
|
||||
targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i).targetType(targetType.getId()));
|
||||
targets.add(TargetManagement.Create.builder().controllerId(controllerIdPrefix + i).targetType(targetType).build());
|
||||
}
|
||||
return createTargets(targets);
|
||||
}
|
||||
@@ -839,25 +833,13 @@ public class TestdataFactory {
|
||||
* @return {@link List} of {@link Target} entities
|
||||
*/
|
||||
public List<Target> createTargets(final String... targetIds) {
|
||||
final List<TargetCreate> targets = new ArrayList<>();
|
||||
final List<TargetManagement.Create> targets = new ArrayList<>();
|
||||
for (final String targetId : targetIds) {
|
||||
targets.add(entityFactory.target().create().controllerId(targetId));
|
||||
targets.add(TargetManagement.Create.builder().controllerId(targetId).build());
|
||||
}
|
||||
return createTargets(targets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds {@link Target} objects with given prefix for
|
||||
* {@link Target#getControllerId()} followed by a number suffix starting with 0.
|
||||
*
|
||||
* @param numberOfTargets of {@link Target}s to generate
|
||||
* @param controllerIdPrefix for {@link Target#getControllerId()} generation.
|
||||
* @return list of {@link Target} objects
|
||||
*/
|
||||
public List<Target> generateTargets(final int numberOfTargets, final String controllerIdPrefix) {
|
||||
return generateTargets(0, numberOfTargets, controllerIdPrefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* builds a set of {@link Target} fixtures from the given parameters.
|
||||
*
|
||||
@@ -878,10 +860,12 @@ public class TestdataFactory {
|
||||
* @return list of {@link Target}
|
||||
*/
|
||||
public List<Target> createTargets(final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix) {
|
||||
final List<TargetCreate> targets = IntStream.range(0, numberOfTargets)
|
||||
.mapToObj(i -> entityFactory.target().create()
|
||||
final List<TargetManagement.Create> targets = IntStream.range(0, numberOfTargets)
|
||||
.mapToObj(i -> TargetManagement.Create.builder()
|
||||
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
|
||||
.description(descriptionPrefix + i))
|
||||
.description(descriptionPrefix + i)
|
||||
.build())
|
||||
.map(TargetManagement.Create.class::cast)
|
||||
.toList();
|
||||
return createTargets(targets);
|
||||
}
|
||||
@@ -897,10 +881,12 @@ public class TestdataFactory {
|
||||
*/
|
||||
public List<Target> createTargets(
|
||||
final int numberOfTargets, final String controllerIdPrefix, final String descriptionPrefix, final Long lastTargetQuery) {
|
||||
final List<TargetCreate> targets = IntStream.range(0, numberOfTargets)
|
||||
.mapToObj(i -> entityFactory.target().create()
|
||||
final List<TargetManagement.Create> targets = IntStream.range(0, numberOfTargets)
|
||||
.mapToObj(i -> TargetManagement.Create.builder()
|
||||
.controllerId(String.format("%s-%05d", controllerIdPrefix, i))
|
||||
.description(descriptionPrefix + i).lastTargetQuery(lastTargetQuery))
|
||||
.description(descriptionPrefix + i).lastTargetQuery(lastTargetQuery)
|
||||
.build())
|
||||
.map(TargetManagement.Create.class::cast)
|
||||
.toList();
|
||||
return createTargets(targets);
|
||||
}
|
||||
@@ -941,10 +927,9 @@ public class TestdataFactory {
|
||||
* @param targets to add {@link ActionStatus}
|
||||
* @param status to add
|
||||
* @param message to add
|
||||
* @return updated {@link Action}.
|
||||
*/
|
||||
public List<Action> sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status, final String message) {
|
||||
return sendUpdateActionStatusToTargets(targets, status, List.of(message));
|
||||
public void sendUpdateActionStatusToTargets(final Collection<Target> targets, final Status status, final String message) {
|
||||
sendUpdateActionStatusToTargets(targets, status, List.of(message));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1091,15 +1076,6 @@ public class TestdataFactory {
|
||||
createDistributionSet(prefix), "50", "5");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create {@link Rollout} with a new {@link DistributionSet} and {@link Target}s.
|
||||
*
|
||||
* @return created {@link Rollout}
|
||||
*/
|
||||
public Rollout createAndStartRollout() {
|
||||
return startAndReloadRollout(createRollout());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the data for a simple rollout scenario
|
||||
*
|
||||
@@ -1277,23 +1253,7 @@ public class TestdataFactory {
|
||||
assertThat(target.getUpdateStatus()).isEqualTo(TargetUpdateStatus.UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds {@link Target} objects with given prefix for {@link Target#getControllerId()} followed by a number suffix.
|
||||
*
|
||||
* @param start value for the controllerId suffix
|
||||
* @param numberOfTargets of {@link Target}s to generate
|
||||
* @param controllerIdPrefix for {@link Target#getControllerId()} generation.
|
||||
* @return list of {@link Target} objects
|
||||
*/
|
||||
private List<Target> generateTargets(final int start, final int numberOfTargets, final String controllerIdPrefix) {
|
||||
final List<Target> targets = new ArrayList<>(numberOfTargets);
|
||||
for (int i = start; i < start + numberOfTargets; i++) {
|
||||
targets.add(entityFactory.target().create().controllerId(controllerIdPrefix + i).build());
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
private List<Target> createTargets(final Collection<TargetCreate> targetCreates) {
|
||||
private List<Target> createTargets(final Collection<TargetManagement.Create> targetCreates) {
|
||||
// init new instance of array list since the TargetManagement#create will provide an unmodifiable list
|
||||
return new ArrayList<>(targetManagement.create(targetCreates));
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.hawkbit.security.HawkbitSecurityProperties;
|
||||
|
||||
/**
|
||||
* A utility which determines the correct IP of a connected {@link Target}. E.g
|
||||
* from a {@link HttpServletRequest}.
|
||||
* A utility which determines the correct IP of a connected {@link Target}. E.g from a {@link HttpServletRequest}.
|
||||
*/
|
||||
@Slf4j
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
// Exception squid:S2083 - false positive, file paths not handled here
|
||||
@SuppressWarnings("squid:S2083")
|
||||
@@ -42,16 +43,31 @@ public final class IpUtil {
|
||||
private static final Pattern IPV6_ADDRESS_WITH_PORT_PATTERN = Pattern.compile(
|
||||
"\\[(?<address>([0-9a-f]{1,4}:){7}([0-9a-f]){1,4})](:[0-9]{1,5})?");
|
||||
|
||||
/**
|
||||
* Converts address to URI. If the address is not parsable, it will log and return <code>null</code>.
|
||||
* @param address the address to convert
|
||||
* @return the {@link URI} or <code>null</code> if the address is not parsable
|
||||
*/
|
||||
public static URI addressToUri(final String address) {
|
||||
if (address == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return URI.create(address);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
log.debug("Failed to parse URI: {}", address, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the string based IP address from a given
|
||||
* {@link HttpServletRequest} by either the configured {@link HawkbitSecurityProperties.Clients#getRemoteIpHeader()}
|
||||
* (by default X-Forwarded-For) or by the {@link HttpServletRequest#getRemoteAddr()} method.
|
||||
*
|
||||
* @param request the {@link HttpServletRequest} to determine the IP address
|
||||
* where this request has been sent from
|
||||
* @param request the {@link HttpServletRequest} to determine the IP address where this request has been sent from
|
||||
* @param securityProperties hawkBit security properties.
|
||||
* @return the {@link URI} based IP address from the client which sent the
|
||||
* request
|
||||
* @return the {@link URI} based IP address from the client which sent the request
|
||||
*/
|
||||
public static URI getClientIpFromRequest(final HttpServletRequest request, final HawkbitSecurityProperties securityProperties) {
|
||||
return getClientIpFromRequest(
|
||||
|
||||
Reference in New Issue
Block a user