diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java index 7131bbe0a..271221e4a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/ControllerManagement.java @@ -376,16 +376,10 @@ public class ControllerManagement { switch (actionStatus.getStatus()) { case ERROR: mergedTarget = deploymentManagement.updateTargetInfo(mergedTarget, TargetUpdateStatus.ERROR, false); - // set action inactive - mergedAction.setActive(false); - mergedAction.setStatus(Status.ERROR); - mergedTarget.setAssignedDistributionSet(null); - targetManagement.updateTarget(mergedTarget); + handleErrorOnAction(mergedAction, mergedTarget); break; case FINISHED: - // set action inactive - mergedAction.setActive(false); - mergedAction.setStatus(Status.FINISHED); + handleFinishedAndStoreInTargetStatus(mergedTarget, mergedAction); break; case CANCELED: @@ -404,6 +398,14 @@ public class ControllerManagement { return actionRepository.save(mergedAction); } + private void handleErrorOnAction(final Action mergedAction, final Target mergedTarget) { + // set action inactive + mergedAction.setActive(false); + mergedAction.setStatus(Status.ERROR); + mergedTarget.setAssignedDistributionSet(null); + targetManagement.updateTarget(mergedTarget); + } + private void checkForToManyStatusEntries(final Action action) { if (securityProperties.getDos().getMaxStatusEntriesPerAction() > 0) { @@ -420,6 +422,8 @@ public class ControllerManagement { } private void handleFinishedAndStoreInTargetStatus(final Target target, final Action action) { + action.setActive(false); + action.setStatus(Status.FINISHED); final TargetInfo targetInfo = target.getTargetInfo(); final DistributionSet ds = entityManager.merge(action.getDistributionSet()); targetInfo.setInstalledDistributionSet(ds); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java index 77f71bebf..bdeba4d0a 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DeploymentManagement.java @@ -534,7 +534,6 @@ public class DeploymentManagement { return saveAction; } else { throw new CancelActionNotAllowedException( - "Action [id: " + action.getId() + "] is not active and cannot be canceled"); } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java index 8df29956b..88e222e64 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/DistributionSetManagement.java @@ -915,7 +915,7 @@ public class DistributionSetManagement { @Transactional @PreAuthorize(SpringEvalExpressions.HAS_AUTH_CREATE_REPOSITORY) public List createDistributionSetTypes(@NotNull final Collection types) { - return types.stream().map(type -> createDistributionSetType(type)).collect(Collectors.toList()); + return types.stream().map(this::createDistributionSetType).collect(Collectors.toList()); } /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java index e790d0a5e..9cf487641 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TargetManagement.java @@ -74,8 +74,6 @@ import com.google.common.eventbus.EventBus; /** * Business service facade for managing {@link Target}s. * - * - * */ @Transactional(readOnly = true) @Validated diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java index 17a7965dd..bca57efa5 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Action.java @@ -50,7 +50,7 @@ import org.eclipse.persistence.annotations.CascadeOnDelete; @Index(name = "sp_idx_action_prim", columnList = "tenant,id") }) @NamedEntityGraphs({ @NamedEntityGraph(name = "Action.ds", attributeNodes = { @NamedAttributeNode("distributionSet") }), @NamedEntityGraph(name = "Action.all", attributeNodes = { @NamedAttributeNode("distributionSet"), - @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet") ) ) }) + @NamedAttributeNode(value = "target", subgraph = "target.ds") }, subgraphs = @NamedSubgraph(name = "target.ds", attributeNodes = @NamedAttributeNode("assignedDistributionSet"))) }) @Entity public class Action extends TenantAwareBaseEntity implements Comparable { private static final long serialVersionUID = 1L; @@ -64,11 +64,11 @@ public class Action extends TenantAwareBaseEntity implements Comparable * the {@link DistributionSet} which should be installed by this action. */ @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_ds") ) + @JoinColumn(name = "distribution_set", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_ds")) private DistributionSet distributionSet; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_target") ) + @JoinColumn(name = "target", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_target")) private Target target; @Column(name = "active") @@ -90,11 +90,11 @@ public class Action extends TenantAwareBaseEntity implements Comparable private List actionStatus; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "rolloutgroup", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rolloutgroup") ) + @JoinColumn(name = "rolloutgroup", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rolloutgroup")) private RolloutGroup rolloutGroup; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rollout") ) + @JoinColumn(name = "rollout", foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_action_rollout")) private Rollout rollout; /** @@ -305,21 +305,11 @@ public class Action extends TenantAwareBaseEntity implements Comparable return actionType == ActionType.FORCED; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "Action [distributionSet=" + distributionSet + ", getId()=" + getId() + "]"; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { // NOSONAR - as this is generated final int prime = 31; @@ -332,11 +322,6 @@ public class Action extends TenantAwareBaseEntity implements Comparable return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { // NOSONAR - as this is generated diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java index 0fdec839b..6409dc209 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/ActionStatus.java @@ -32,9 +32,6 @@ import com.google.common.base.Splitter; /** * Entity to store the status for a specific action. - * - * - * */ @Table(name = "sp_action_status", indexes = { @Index(name = "sp_idx_action_status_01", columnList = "tenant,action"), @Index(name = "sp_idx_action_status_02", columnList = "tenant,action,status"), @@ -42,10 +39,6 @@ import com.google.common.base.Splitter; @NamedEntityGraph(name = "ActionStatus.withMessages", attributeNodes = { @NamedAttributeNode("messages") }) @Entity public class ActionStatus extends TenantAwareBaseEntity { - - /** - * - */ private static final long serialVersionUID = 1L; @Column(name = "target_occurred_at") @@ -146,4 +139,55 @@ public class ActionStatus extends TenantAwareBaseEntity { public void setStatus(final Status status) { this.status = status; } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((action == null) ? 0 : action.hashCode()); + result = prime * result + ((messages == null) ? 0 : messages.hashCode()); + result = prime * result + ((occurredAt == null) ? 0 : occurredAt.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ActionStatus other = (ActionStatus) obj; + if (action == null) { + if (other.action != null) { + return false; + } + } else if (!action.equals(other.action)) { + return false; + } + if (messages == null) { + if (other.messages != null) { + return false; + } + } else if (!messages.equals(other.messages)) { + return false; + } + if (occurredAt == null) { + if (other.occurredAt != null) { + return false; + } + } else if (!occurredAt.equals(other.occurredAt)) { + return false; + } + if (status != other.status) { + return false; + } + return true; + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java index 5d829e4d6..23c5de34f 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/Artifact.java @@ -13,11 +13,7 @@ import javax.persistence.MappedSuperclass; /** * Tenant specific locally stored artifact representation that is used by - * {@link SoftwareModule} . - * - * - * - * + * {@link SoftwareModule}. */ @MappedSuperclass public abstract class Artifact extends TenantAwareBaseEntity { @@ -34,49 +30,73 @@ public abstract class Artifact extends TenantAwareBaseEntity { public abstract SoftwareModule getSoftwareModule(); - /** - * @return the md5Hash - */ public String getMd5Hash() { return md5Hash; } - /** - * @return the sha1Hash - */ public String getSha1Hash() { return sha1Hash; } - /** - * @param md5Hash - * the md5Hash to set - */ public void setMd5Hash(final String md5Hash) { this.md5Hash = md5Hash; } - /** - * @param sha1Hash - * the sha1Hash to set - */ public void setSha1Hash(final String sha1Hash) { this.sha1Hash = sha1Hash; } - /** - * @return the size - */ public Long getSize() { return size; } - /** - * @param size - * the size to set - */ public void setSize(final Long size) { this.size = size; } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((md5Hash == null) ? 0 : md5Hash.hashCode()); + result = prime * result + ((sha1Hash == null) ? 0 : sha1Hash.hashCode()); + result = prime * result + ((size == null) ? 0 : size.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Artifact other = (Artifact) obj; + if (md5Hash == null) { + if (other.md5Hash != null) { + return false; + } + } else if (!md5Hash.equals(other.md5Hash)) { + return false; + } + if (sha1Hash == null) { + if (other.sha1Hash != null) { + return false; + } + } else if (!sha1Hash.equals(other.sha1Hash)) { + return false; + } + if (size == null) { + if (other.size != null) { + return false; + } + } else if (!size.equals(other.size)) { + return false; + } + return true; + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java index e1c7e61ea..30fb73365 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/DistributionSetType.java @@ -38,10 +38,6 @@ import javax.persistence.UniqueConstraint; @UniqueConstraint(columnNames = { "name", "tenant" }, name = "uk_dst_name"), @UniqueConstraint(columnNames = { "type_key", "tenant" }, name = "uk_dst_key") }) public class DistributionSetType extends NamedEntity { - - /** - * - */ private static final long serialVersionUID = 1L; @OneToMany(targetEntity = DistributionSetTypeElement.class, cascade = { @@ -256,17 +252,10 @@ public class DistributionSetType extends NamedEntity { return this; } - /** - * @return the key - */ public String getKey() { return key; } - /** - * @param key - * the key to set - */ public void setKey(final String key) { this.key = key; } @@ -282,19 +271,10 @@ public class DistributionSetType extends NamedEntity { .containsAll(getMandatoryModuleTypes()); } - /** - * - * @return the DistributionSet type color - */ public String getColour() { return colour; } - /** - * - * @param colour - * the col - */ public void setColour(final String colour) { this.colour = colour; } @@ -303,14 +283,58 @@ public class DistributionSetType extends NamedEntity { return elements; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ @Override public String toString() { return "DistributionSetType [key=" + key + ", isDeleted()=" + isDeleted() + ", getId()=" + getId() + "]"; } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((colour == null) ? 0 : colour.hashCode()); + result = prime * result + (deleted ? 1231 : 1237); + result = prime * result + ((elements == null) ? 0 : elements.hashCode()); + result = prime * result + ((key == null) ? 0 : key.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final DistributionSetType other = (DistributionSetType) obj; + if (colour == null) { + if (other.colour != null) { + return false; + } + } else if (!colour.equals(other.colour)) { + return false; + } + if (deleted != other.deleted) { + return false; + } + if (elements == null) { + if (other.elements != null) { + return false; + } + } else if (!elements.equals(other.elements)) { + return false; + } + if (key == null) { + if (other.key != null) { + return false; + } + } else if (!key.equals(other.key)) { + return false; + } + return true; + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java index 30446a0bf..3ee2387ed 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/NamedEntity.java @@ -12,14 +12,8 @@ import javax.persistence.Column; import javax.persistence.MappedSuperclass; /** - * {@link TenantAwareBaseEntity} extension for all entities that are named in addition to - * their technical ID. - * - * - * - * - * - * + * {@link TenantAwareBaseEntity} extension for all entities that are named in + * addition to their technical ID. */ @MappedSuperclass public abstract class NamedEntity extends TenantAwareBaseEntity { @@ -67,4 +61,42 @@ public abstract class NamedEntity extends TenantAwareBaseEntity { this.name = name; } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final NamedEntity other = (NamedEntity) obj; + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + return true; + } + } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java index 2518e4b1b..f76cac155 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/SwMetadataCompositeKey.java @@ -11,16 +11,10 @@ package org.eclipse.hawkbit.repository.model; import java.io.Serializable; /** - * The Software Module Metadata composite key which contains the meta data key + * The Software Module meta data composite key which contains the meta data key * and the ID of the software module itself. - * - * - * */ public final class SwMetadataCompositeKey implements Serializable { - /** - * - */ private static final long serialVersionUID = 1L; private String key; @@ -28,9 +22,10 @@ public final class SwMetadataCompositeKey implements Serializable { private Long softwareModule; /** - * - */ + * Default constructor for JPA. + */ public SwMetadataCompositeKey() { + // Default constructor for JPA. } /** diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java index 5b75bd0bd..35c7466be 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantMetaData.java @@ -78,4 +78,41 @@ public class TenantMetaData extends BaseEntity { this.tenant = tenant; } + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((defaultDsType == null) ? 0 : defaultDsType.hashCode()); + result = prime * result + ((tenant == null) ? 0 : tenant.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final TenantMetaData other = (TenantMetaData) obj; + if (defaultDsType == null) { + if (other.defaultDsType != null) { + return false; + } + } else if (!defaultDsType.equals(other.defaultDsType)) { + return false; + } + if (tenant == null) { + if (other.tenant != null) { + return false; + } + } else if (!tenant.equals(other.tenant)) { + return false; + } + return true; + } } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java index 20dffde29..c7a4cb136 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TargetManagementTest.java @@ -54,15 +54,11 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Target Management") public class TargetManagementTest extends AbstractIntegrationTest { - @Test + @Test(expected = TenantNotExistException.class) @Description("Ensures that targets cannot be created e.g. in plug'n play scenarios when tenant does not exists.") @WithUser(tenantId = "tenantWhichDoesNotExists", allSpPermissions = true, autoCreateTenant = false) public void createTargetForTenantWhichDoesNotExistThrowsTenantNotExistException() { - try { - targetManagement.createTarget(new Target("targetId123")); - fail("tenant not exist"); - } catch (final TenantNotExistException e) { - } + targetManagement.createTarget(new Target("targetId123")); } @Test