Fix sonar findings: JpaRolloutGroup (#1988)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -232,7 +232,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
if (readyGroups == rolloutGroups.size()) {
|
if (readyGroups == rolloutGroups.size()) {
|
||||||
if (rollout.isDynamic() && !rolloutGroups.get(rolloutGroups.size() - 1).isDynamic()) {
|
if (rollout.isDynamic() && !rolloutGroups.get(rolloutGroups.size() - 1).isDynamic()) {
|
||||||
// add first dynamic group one by using the last as a parent and as a pattern
|
// add first dynamic group one by using the last as a parent and as a pattern
|
||||||
createDynamicGroup(rollout, rolloutGroups.get(rolloutGroups.size() - 1), rolloutGroups.size(), RolloutGroupStatus.READY);
|
createDynamicGroup(rollout, (JpaRolloutGroup) rolloutGroups.get(rolloutGroups.size() - 1), rolloutGroups.size(), RolloutGroupStatus.READY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rolloutApprovalStrategy.isApprovalNeeded(rollout)) {
|
if (!rolloutApprovalStrategy.isApprovalNeeded(rollout)) {
|
||||||
@@ -583,7 +583,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
return scheduledGroups == groupsToBeScheduled.size();
|
return scheduledGroups == groupsToBeScheduled.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RolloutGroup fillRolloutGroupWithTargets(final JpaRollout rollout, final JpaRolloutGroup group,
|
private JpaRolloutGroup fillRolloutGroupWithTargets(final JpaRollout rollout, final JpaRolloutGroup group,
|
||||||
final List<RolloutGroup> rolloutGroups) {
|
final List<RolloutGroup> rolloutGroups) {
|
||||||
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.CREATING);
|
RolloutHelper.verifyRolloutInStatus(rollout, RolloutStatus.CREATING);
|
||||||
|
|
||||||
@@ -735,7 +735,7 @@ public class JpaRolloutExecutor implements RolloutExecutor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDynamicGroup(final JpaRollout rollout, final RolloutGroup lastGroup, final int groupCount,
|
private void createDynamicGroup(final JpaRollout rollout, final JpaRolloutGroup lastGroup, final int groupCount,
|
||||||
final RolloutGroupStatus status) {
|
final RolloutGroupStatus status) {
|
||||||
try {
|
try {
|
||||||
RolloutHelper.verifyRolloutGroupAmount(groupCount + 1, quotaManagement);
|
RolloutHelper.verifyRolloutGroupAmount(groupCount + 1, quotaManagement);
|
||||||
|
|||||||
@@ -664,7 +664,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create and persist the groups (w/o filling them with targets)
|
// create and persist the groups (w/o filling them with targets)
|
||||||
RolloutGroup lastSavedGroup = null;
|
JpaRolloutGroup lastSavedGroup = null;
|
||||||
for (final RolloutGroup srcGroup : groups) {
|
for (final RolloutGroup srcGroup : groups) {
|
||||||
final JpaRolloutGroup group = new JpaRolloutGroup();
|
final JpaRolloutGroup group = new JpaRolloutGroup();
|
||||||
group.setName(srcGroup.getName());
|
group.setName(srcGroup.getName());
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository.jpa.model;
|
package org.eclipse.hawkbit.repository.jpa.model;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -27,6 +28,8 @@ import jakarta.persistence.UniqueConstraint;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import jakarta.validation.constraints.Size;
|
import jakarta.validation.constraints.Size;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.RolloutGroupDeletedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.RolloutGroupDeletedEvent;
|
||||||
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent;
|
import org.eclipse.hawkbit.repository.event.remote.entity.RolloutGroupUpdatedEvent;
|
||||||
import org.eclipse.hawkbit.repository.model.Rollout;
|
import org.eclipse.hawkbit.repository.model.Rollout;
|
||||||
@@ -43,19 +46,21 @@ import org.eclipse.persistence.descriptors.DescriptorEvent;
|
|||||||
* JPA entity definition of persisting a group of an rollout.
|
* JPA entity definition of persisting a group of an rollout.
|
||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "sp_rolloutgroup", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "rollout",
|
@Table(name = "sp_rolloutgroup", uniqueConstraints = @UniqueConstraint(columnNames = { "name", "rollout", "tenant" }, name = "uk_rolloutgroup"))
|
||||||
"tenant" }, name = "uk_rolloutgroup"))
|
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for sub entities
|
||||||
// exception squid:S2160 - BaseEntity equals/hashcode is handling correctly for
|
|
||||||
// sub entities
|
|
||||||
@SuppressWarnings("squid:S2160")
|
@SuppressWarnings("squid:S2160")
|
||||||
public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGroup, EventAwareEntity {
|
public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGroup, EventAwareEntity {
|
||||||
|
|
||||||
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Getter
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "rollout", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolloutgroup_rollout"))
|
@JoinColumn(name = "rollout", nullable = false, updatable = false, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_rolloutgroup_rollout"))
|
||||||
private JpaRollout rollout;
|
private JpaRollout rollout;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "status", nullable = false)
|
@Column(name = "status", nullable = false)
|
||||||
@ObjectTypeConverter(name = "rolloutgroupstatus", objectType = RolloutGroup.RolloutGroupStatus.class, dataType = Integer.class, conversionValues = {
|
@ObjectTypeConverter(name = "rolloutgroupstatus", objectType = RolloutGroup.RolloutGroupStatus.class, dataType = Integer.class, conversionValues = {
|
||||||
@ConversionValue(objectValue = "READY", dataValue = "0"),
|
@ConversionValue(objectValue = "READY", dataValue = "0"),
|
||||||
@@ -68,227 +73,107 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr
|
|||||||
private RolloutGroupStatus status = RolloutGroupStatus.CREATING;
|
private RolloutGroupStatus status = RolloutGroupStatus.CREATING;
|
||||||
|
|
||||||
@CascadeOnDelete
|
@CascadeOnDelete
|
||||||
@OneToMany(mappedBy = "rolloutGroup", fetch = FetchType.LAZY, cascade = {
|
@OneToMany(mappedBy = "rolloutGroup", fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST }, targetEntity = RolloutTargetGroup.class)
|
||||||
CascadeType.PERSIST }, targetEntity = RolloutTargetGroup.class)
|
|
||||||
private List<RolloutTargetGroup> rolloutTargetGroup;
|
private List<RolloutTargetGroup> rolloutTargetGroup;
|
||||||
|
|
||||||
// No foreign key to avoid to many nested cascades on delete which some DBs cannot handle
|
// No foreign key to avoid to many nested cascades on delete which some DBs cannot handle
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST })
|
@ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST })
|
||||||
@JoinColumn(name = "parent_id")
|
@JoinColumn(name = "parent_id")
|
||||||
private JpaRolloutGroup parent;
|
private JpaRolloutGroup parent;
|
||||||
|
|
||||||
|
@Setter @Getter
|
||||||
@Column(name = "is_dynamic") // dynamic is reserved keyword in some databases
|
@Column(name = "is_dynamic") // dynamic is reserved keyword in some databases
|
||||||
private boolean dynamic;
|
private boolean dynamic;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "success_condition", nullable = false)
|
@Column(name = "success_condition", nullable = false)
|
||||||
@NotNull
|
@NotNull
|
||||||
private RolloutGroupSuccessCondition successCondition = RolloutGroupSuccessCondition.THRESHOLD;
|
private RolloutGroupSuccessCondition successCondition = RolloutGroupSuccessCondition.THRESHOLD;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "success_condition_exp", length = 512, nullable = false)
|
@Column(name = "success_condition_exp", length = 512, nullable = false)
|
||||||
@Size(max = 512)
|
@Size(max = 512)
|
||||||
@NotNull
|
@NotNull
|
||||||
private String successConditionExp;
|
private String successConditionExp;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "success_action", nullable = false)
|
@Column(name = "success_action", nullable = false)
|
||||||
@NotNull
|
@NotNull
|
||||||
private RolloutGroupSuccessAction successAction = RolloutGroupSuccessAction.NEXTGROUP;
|
private RolloutGroupSuccessAction successAction = RolloutGroupSuccessAction.NEXTGROUP;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "success_action_exp", length = 512)
|
@Column(name = "success_action_exp", length = 512)
|
||||||
@Size(max = 512)
|
@Size(max = 512)
|
||||||
private String successActionExp;
|
private String successActionExp;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "error_condition")
|
@Column(name = "error_condition")
|
||||||
private RolloutGroupErrorCondition errorCondition;
|
private RolloutGroupErrorCondition errorCondition;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "error_condition_exp", length = 512)
|
@Column(name = "error_condition_exp", length = 512)
|
||||||
@Size(max = 512)
|
@Size(max = 512)
|
||||||
private String errorConditionExp;
|
private String errorConditionExp;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "error_action")
|
@Column(name = "error_action")
|
||||||
private RolloutGroupErrorAction errorAction;
|
private RolloutGroupErrorAction errorAction;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "error_action_exp", length = 512)
|
@Column(name = "error_action_exp", length = 512)
|
||||||
@Size(max = 512)
|
@Size(max = 512)
|
||||||
private String errorActionExp;
|
private String errorActionExp;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "total_targets")
|
@Column(name = "total_targets")
|
||||||
private int totalTargets;
|
private int totalTargets;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "target_filter", length = 1024)
|
@Column(name = "target_filter", length = 1024)
|
||||||
@Size(max = 1024)
|
@Size(max = 1024)
|
||||||
private String targetFilterQuery = "";
|
private String targetFilterQuery = "";
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "target_percentage")
|
@Column(name = "target_percentage")
|
||||||
private float targetPercentage = 100;
|
private float targetPercentage = 100;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
@Column(name = "confirmation_required")
|
@Column(name = "confirmation_required")
|
||||||
private boolean confirmationRequired;
|
private boolean confirmationRequired;
|
||||||
|
|
||||||
|
@Setter
|
||||||
@Transient
|
@Transient
|
||||||
private transient TotalTargetCountStatus totalTargetCountStatus;
|
private transient TotalTargetCountStatus totalTargetCountStatus;
|
||||||
|
|
||||||
@Override
|
|
||||||
public Rollout getRollout() {
|
|
||||||
return rollout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRollout(final Rollout rollout) {
|
public void setRollout(final Rollout rollout) {
|
||||||
this.rollout = (JpaRollout) rollout;
|
this.rollout = (JpaRollout) rollout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public RolloutGroupStatus getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(final RolloutGroupStatus status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RolloutGroup getParent() {
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDynamic() {
|
|
||||||
return dynamic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDynamic(final boolean dynamic) {
|
|
||||||
this.dynamic = dynamic;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RolloutGroupSuccessCondition getSuccessCondition() {
|
|
||||||
return successCondition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSuccessCondition(final RolloutGroupSuccessCondition finishCondition) {
|
|
||||||
successCondition = finishCondition;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSuccessConditionExp() {
|
|
||||||
return successConditionExp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSuccessConditionExp(final String finishExp) {
|
|
||||||
successConditionExp = finishExp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RolloutGroupErrorCondition getErrorCondition() {
|
|
||||||
return errorCondition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorCondition(final RolloutGroupErrorCondition errorCondition) {
|
|
||||||
this.errorCondition = errorCondition;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getErrorConditionExp() {
|
|
||||||
return errorConditionExp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorConditionExp(final String errorExp) {
|
|
||||||
errorConditionExp = errorExp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RolloutGroupErrorAction getErrorAction() {
|
|
||||||
return errorAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorAction(final RolloutGroupErrorAction errorAction) {
|
|
||||||
this.errorAction = errorAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getErrorActionExp() {
|
|
||||||
return errorActionExp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorActionExp(final String errorActionExp) {
|
|
||||||
this.errorActionExp = errorActionExp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RolloutGroupSuccessAction getSuccessAction() {
|
|
||||||
return successAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSuccessActionExp() {
|
|
||||||
return successActionExp;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTotalTargets() {
|
|
||||||
return totalTargets;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalTargets(final int totalTargets) {
|
|
||||||
this.totalTargets = totalTargets;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the totalTargetCountStatus
|
* @return the totalTargetCountStatus
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TotalTargetCountStatus getTotalTargetCountStatus() {
|
public TotalTargetCountStatus getTotalTargetCountStatus() {
|
||||||
if (totalTargetCountStatus == null) {
|
if (totalTargetCountStatus == null) {
|
||||||
totalTargetCountStatus = new TotalTargetCountStatus(Long.valueOf(totalTargets), rollout.getActionType());
|
totalTargetCountStatus = new TotalTargetCountStatus((long) totalTargets, rollout.getActionType());
|
||||||
}
|
}
|
||||||
return totalTargetCountStatus;
|
return totalTargetCountStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTargetFilterQuery() {
|
|
||||||
return targetFilterQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTargetFilterQuery(final String targetFilterQuery) {
|
|
||||||
this.targetFilterQuery = targetFilterQuery;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float getTargetPercentage() {
|
|
||||||
return targetPercentage;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isConfirmationRequired() {
|
|
||||||
return confirmationRequired;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setConfirmationRequired(final boolean confirmationRequired) {
|
|
||||||
this.confirmationRequired = confirmationRequired;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTargetPercentage(final float targetPercentage) {
|
|
||||||
this.targetPercentage = targetPercentage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param totalTargetCountStatus the totalTargetCountStatus to set
|
|
||||||
*/
|
|
||||||
public void setTotalTargetCountStatus(final TotalTargetCountStatus totalTargetCountStatus) {
|
|
||||||
this.totalTargetCountStatus = totalTargetCountStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSuccessActionExp(final String successActionExp) {
|
|
||||||
this.successActionExp = successActionExp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSuccessAction(final RolloutGroupSuccessAction successAction) {
|
|
||||||
this.successAction = successAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setParent(final RolloutGroup parent) {
|
|
||||||
this.parent = (JpaRolloutGroup) parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<RolloutTargetGroup> getRolloutTargetGroup() {
|
public List<RolloutTargetGroup> getRolloutTargetGroup() {
|
||||||
if (rolloutTargetGroup == null) {
|
if (rolloutTargetGroup == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@@ -299,11 +184,17 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "RolloutGroup [rollout=" + (rollout != null ? rollout.getId() : "") + ", status=" + status
|
return "RolloutGroup [" +
|
||||||
+ ", rolloutTargetGroup=" + rolloutTargetGroup + ", parent=" + parent + ", finishCondition="
|
"rollout=" + (rollout != null ? rollout.getId() : "") +
|
||||||
+ successCondition + ", finishExp=" + successConditionExp + ", errorCondition=" + errorCondition
|
", name=" + getName() +
|
||||||
+ ", errorExp=" + errorConditionExp + ", getName()=" + getName() + ", getId()=" + getId()
|
", status=" + status +
|
||||||
+ ", isConfirmationRequired()=" + isConfirmationRequired() + "]";
|
", parent=" + parent +
|
||||||
|
", finishCondition=" + successCondition + ", finishExp=" + successConditionExp +
|
||||||
|
", errorCondition=" + errorCondition + ", errorExp=" + errorConditionExp +
|
||||||
|
", isConfirmationRequired()=" + isConfirmationRequired() +
|
||||||
|
", rolloutTargetGroup=" + rolloutTargetGroup +
|
||||||
|
", id()=" + getId() +
|
||||||
|
"]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -313,13 +204,13 @@ public class JpaRolloutGroup extends AbstractJpaNamedEntity implements RolloutGr
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
|
public void fireUpdateEvent(final DescriptorEvent descriptorEvent) {
|
||||||
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new RolloutGroupUpdatedEvent(this,
|
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(
|
||||||
this.getRollout().getId(), EventPublisherHolder.getInstance().getApplicationId()));
|
new RolloutGroupUpdatedEvent(this, getRollout().getId(), EventPublisherHolder.getInstance().getApplicationId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
|
public void fireDeleteEvent(final DescriptorEvent descriptorEvent) {
|
||||||
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(new RolloutGroupDeletedEvent(getTenant(),
|
EventPublisherHolder.getInstance().getEventPublisher().publishEvent(
|
||||||
getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
|
new RolloutGroupDeletedEvent(getTenant(), getId(), getClass(), EventPublisherHolder.getInstance().getApplicationId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user