Unify target attributes and metadata (#2408)

* Unify target attributes and metadata

Currently, the target attributes are Map while the metadata,
which has the same concept is List.
This PR unifies them making the metadata also a Map

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-05-21 11:26:02 +03:00
committed by GitHub
parent 424520bb72
commit ceba4f5cfb
29 changed files with 490 additions and 1107 deletions

View File

@@ -54,16 +54,6 @@ public interface EntityFactory {
MetaData generateDsMetadata(@Size(min = 1, max = MetaData.KEY_MAX_SIZE) @NotNull String key,
@Size(max = MetaData.VALUE_MAX_SIZE) String value);
/**
* Generates an {@link MetaData} element for target without persisting it.
*
* @param key {@link MetaData#getKey()}
* @param value {@link MetaData#getValue()}
* @return {@link MetaData} object
*/
MetaData generateTargetMetadata(@Size(min = 1, max = MetaData.KEY_MAX_SIZE) @NotNull String key,
@Size(max = MetaData.VALUE_MAX_SIZE) String value);
/**
* @return {@link SoftwareModuleMetadataBuilder} object
*/

View File

@@ -35,7 +35,6 @@ import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.RolloutGroup;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.model.TargetMetadata;
import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.repository.model.TargetTypeAssignmentResult;
@@ -434,8 +433,7 @@ public interface TargetManagement {
* @throws EntityNotFoundException if distribution set with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
Page<Target> findByInstalledDistributionSetAndRsql(@NotNull Pageable pageReq, long distributionSetId,
@NotNull String rsqlParam);
Page<Target> findByInstalledDistributionSetAndRsql(@NotNull Pageable pageReq, long distributionSetId, @NotNull String rsqlParam);
/**
* Retrieves the {@link Target} which have a certain {@link TargetUpdateStatus}.
@@ -509,6 +507,19 @@ public interface TargetManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Page<Target> findByRsqlAndTag(@NotNull Pageable pageable, @NotNull String rsqlParam, long tagId);
/**
* Verify if a target matches a specific target filter query, does not have a
* specific DS already assigned and is compatible with it.
*
* @param controllerId of the {@link org.eclipse.hawkbit.repository.model.Target} to check
* @param distributionSetId of the {@link org.eclipse.hawkbit.repository.model.DistributionSet} to consider
* @param targetFilterQuery to execute
* @return true if it matches
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
boolean isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable(
@NotNull String controllerId, long distributionSetId, @NotNull String targetFilterQuery);
/**
* Initiates {@link TargetType} assignment to given {@link Target}s. If some
* targets in the list have the {@link TargetType} not yet assigned, they will
@@ -525,12 +536,10 @@ public interface TargetManagement {
TargetTypeAssignmentResult assignType(@NotEmpty Collection<String> controllerIds, @NotNull Long typeId);
/**
* Initiates {@link TargetType} un-assignment to given {@link Target}s. The type
* of the targets will be set to {@code null}
* Initiates {@link TargetType} un-assignment to given {@link Target}s. The type of the targets will be set to {@code null}
*
* @param controllerIds to remove the type from
* @return {@link TargetTypeAssignmentResult} with all metadata of the
* assignment outcome.
* @return {@link TargetTypeAssignmentResult} with all metadata of the assignment outcome.
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_TARGET)
TargetTypeAssignmentResult unassignType(@NotEmpty Collection<String> controllerIds);
@@ -631,6 +640,25 @@ public interface TargetManagement {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
List<Target> get(@NotNull Collection<Long> ids);
/**
* Verifies that {@link Target} with given controller ID exists in the repository.
*
* @param controllerId of target
* @return {@code true} if target with given ID exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
boolean existsByControllerId(@NotEmpty String controllerId);
/**
* Finds a single target tags its id.
*
* @param controllerId of the {@link Target}
* @return the found Tag set
* @throws EntityNotFoundException if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Set<TargetTag> getTags(@NotEmpty String controllerId);
/**
* Get controller attributes of given {@link Target}.
*
@@ -671,55 +699,37 @@ public interface TargetManagement {
Page<Target> findByControllerAttributesRequested(@NotNull Pageable pageReq);
/**
* Verifies that {@link Target} with given controller ID exists in the
* repository.
*
* @param controllerId of target
* @return {@code true} if target with given ID exists
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
boolean existsByControllerId(@NotEmpty String controllerId);
/**
* Verify if a target matches a specific target filter query, does not have a
* specific DS already assigned and is compatible with it.
*
* @param controllerId of the {@link org.eclipse.hawkbit.repository.model.Target} to
* check
* @param distributionSetId of the
* {@link org.eclipse.hawkbit.repository.model.DistributionSet} to
* consider
* @param targetFilterQuery to execute
* @return true if it matches
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY_AND_READ_TARGET)
boolean isTargetMatchingQueryAndDSNotAssignedAndCompatibleAndUpdatable(@NotNull String controllerId,
long distributionSetId, @NotNull String targetFilterQuery);
/**
* Finds a single target tags its id.
*
* @param controllerId of the {@link Target}
* @return the found Tag set
* @throws EntityNotFoundException if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_TARGET)
Set<TargetTag> getTagsByControllerId(@NotEmpty String controllerId);
/**
* Creates a list of target meta data entries.
* Creates a list of target meta-data entries.
*
* @param controllerId {@link Target} controller id the metadata has to be created for
* @param metadata the meta data entries to create or update
* @return the updated or created target metadata entries
* @param metadata the meta-data entries to create or update
* @throws EntityNotFoundException if given target does not exist
* @throws EntityAlreadyExistsException in case one of the metadata entry already exists for the specific
* key
* @throws AssignmentQuotaExceededException if the maximum number of {@link MetaData} entries is exceeded for
* the addressed {@link Target}
* @throws EntityAlreadyExistsException in case one of the metadata entry already exists for the specific key
* @throws AssignmentQuotaExceededException if the maximum number of {@link MetaData} entries is exceeded for the addressed {@link Target}
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
List<TargetMetadata> createMetaData(@NotEmpty String controllerId, @NotEmpty Collection<MetaData> metadata);
void createMetadata(@NotEmpty String controllerId, @NotEmpty Map<String, String> metadata);
/**
* Finds a single target meta-data by its id.
*
* @param controllerId of the {@link Target}
* @return the found target metadata
* @throws EntityNotFoundException if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Map<String, String> getMetadata(@NotEmpty String controllerId);
/**
* Updates a target meta-data value if corresponding entry exists.
*
* @param controllerId {@link Target} controller id of the metadata entry to be updated
* @param key meta data-entry key to be updated
* @param value meta data-entry to be new value
* @throws EntityNotFoundException in case the metadata entry does not exist and cannot be updated
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void updateMetadata(@NotEmpty String controllerId, @NotNull String key, @NotNull String value);
/**
* Deletes a target meta data entry.
@@ -729,64 +739,5 @@ public interface TargetManagement {
* @throws EntityNotFoundException if given target does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
void deleteMetaData(@NotEmpty String controllerId, @NotEmpty String key);
/**
* Finds all meta data by the given target id.
*
* @param pageable the page request to page the result
* @param controllerId the controller id to retrieve the metadata from
* @return a paged result of all meta data entries for a given target id
* @throws EntityNotFoundException if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<TargetMetadata> findMetaDataByControllerId(@NotNull Pageable pageable, @NotEmpty String controllerId);
/**
* Counts all meta data by the given target id.
*
* @param controllerId the controller id to retrieve the meta data from
* @return count of all meta data entries for a given target id
* @throws EntityNotFoundException if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
long countMetaDataByControllerId(@NotEmpty String controllerId);
/**
* Finds all metadata by the given target id and query.
*
* @param pageable the page request to page the result
* @param controllerId the controller id to retrieve the metadata from
* @param rsqlParam rsql query string
* @return a paged result of all meta data entries for a given target id
* @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
* @throws EntityNotFoundException if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Page<TargetMetadata> findMetaDataByControllerIdAndRsql(@NotNull Pageable pageable, @NotEmpty String controllerId,
@NotNull String rsqlParam);
/**
* Finds a single target meta data by its id.
*
* @param controllerId of the {@link Target}
* @param key of the meta data element
* @return the found TargetMetadata
* @throws EntityNotFoundException if target with given ID does not exist
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_READ_REPOSITORY)
Optional<TargetMetadata> getMetaDataByControllerId(@NotEmpty String controllerId, @NotEmpty String key);
/**
* Updates a target meta data value if corresponding entry exists.
*
* @param controllerId {@link Target} controller id of the metadata entry to be updated
* @param metadata meta data entry to be updated
* @return the updated meta data entry
* @throws EntityNotFoundException in case the metadata entry does not exist and cannot be updated
*/
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_UPDATE_REPOSITORY)
TargetMetadata updateMetadata(@NotEmpty String controllerId, @NotNull MetaData metadata);
void deleteMetadata(@NotEmpty String controllerId, @NotEmpty String key);
}

View File

@@ -75,10 +75,20 @@ public class EntityNotFoundException extends AbstractServerRtException {
* @param type of the entity that was not found
* @param entityId of the {@link BaseEntity}
*/
public EntityNotFoundException(final Class<? extends BaseEntity> type, final Object entityId) {
super(type.getSimpleName() + " with given identifier {" + entityId + "} does not exist.",
public EntityNotFoundException(final String type, final Object entityId) {
super(type + " with given identifier {" + entityId + "} does not exist.",
THIS_ERROR,
Map.of(TYPE, type.getSimpleName(), ENTITY_ID, entityId));
Map.of(TYPE, type, ENTITY_ID, entityId));
}
/**
* Parameterized constructor for {@link BaseEntity} not found.
*
* @param type of the entity that was not found
* @param entityId of the {@link BaseEntity}
*/
public EntityNotFoundException(final Class<? extends BaseEntity> type, final Object entityId) {
this(type.getSimpleName(), entityId);
}
/**

View File

@@ -47,6 +47,16 @@ public interface Target extends NamedEntity {
*/
int CONTROLLER_ATTRIBUTE_VALUE_SIZE = 128;
/**
* Maximum length of metadata key.
*/
int CONTROLLER_METADATA_KEY_SIZE = 128;
/**
* Maximum length of metadata value.
*/
int CONTROLLER_METADATA_VALUE_SIZE = 4000;
/**
* @return business identifier of the {@link Target}
*/

View File

@@ -1,26 +0,0 @@
/**
* Copyright (c) 2018 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.model;
/**
* {@link MetaData} of a {@link Target}.
*/
public interface TargetMetadata extends MetaData {
/**
* @return {@link Target} of this {@link MetaData} entry.
*/
Target getTarget();
@Override
default Long getEntityId() {
return getTarget().getId();
}
}