Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase target name to 128 and target controller id to 256 #849

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface NamedEntity extends TenantAwareBaseEntity {
/**
* Maximum length of name.
*/
int NAME_MAX_SIZE = 64;
int NAME_MAX_SIZE = 128;

/**
* Maximum length of description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface Target extends NamedEntity {
/**
* Maximum length of controllerId.
*/
int CONTROLLER_ID_MAX_SIZE = 64;
int CONTROLLER_ID_MAX_SIZE = 256;

/**
* Maximum length of securityToken.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ALTER TABLE sp_distribution_set ALTER COLUMN name SET DATA TYPE VARCHAR(128);
ALTER TABLE sp_distribution_set_type ALTER COLUMN name SET DATA TYPE VARCHAR(128);
ALTER TABLE sp_distributionset_tag ALTER COLUMN name SET DATA TYPE VARCHAR(128);
ALTER TABLE sp_base_software_module ALTER COLUMN name SET DATA TYPE VARCHAR(128);
ALTER TABLE sp_rollout ALTER COLUMN name SET DATA TYPE VARCHAR(128);
ALTER TABLE sp_rolloutgroup ALTER COLUMN name SET DATA TYPE VARCHAR(128);
ALTER TABLE sp_software_module_type ALTER COLUMN name SET DATA TYPE VARCHAR(128);
ALTER TABLE sp_target ALTER COLUMN name SET DATA TYPE VARCHAR(128);
ALTER TABLE sp_target_filter_query ALTER COLUMN name SET DATA TYPE VARCHAR(128);
ALTER TABLE sp_target_tag ALTER COLUMN name SET DATA TYPE VARCHAR(128);


ALTER TABLE sp_target ALTER COLUMN controller_id SET DATA TYPE VARCHAR(256);
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ CREATE TABLE sp_action
maintenance_duration VARCHAR(40),
maintenance_time_zone VARCHAR(40),
PRIMARY KEY (id)
);

ALTER TABLE sp_action ADD column maintenance_cron_schedule VARCHAR(40);
ALTER TABLE sp_action ADD column maintenance_duration VARCHAR(40);
ALTER TABLE sp_action ADD column maintenance_time_zone VARCHAR(40);
);

CREATE INDEX sp_idx_action_01
ON sp_action (tenant, distribution_set);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ALTER TABLE sp_distribution_set ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_distribution_set_type ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_distributionset_tag ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_base_software_module ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_rollout ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_rolloutgroup ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_software_module_type ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_target ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_target_filter_query ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_target_tag ALTER COLUMN name VARCHAR(128);


ALTER TABLE sp_target ALTER COLUMN controller_id VARCHAR(256);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ALTER TABLE sp_distribution_set MODIFY name VARCHAR(128);
ALTER TABLE sp_distribution_set_type MODIFY name VARCHAR(128);
ALTER TABLE sp_distributionset_tag MODIFY name VARCHAR(128);
ALTER TABLE sp_base_software_module MODIFY name VARCHAR(128);
ALTER TABLE sp_rollout MODIFY name VARCHAR(128);
ALTER TABLE sp_rolloutgroup MODIFY name VARCHAR(128);
ALTER TABLE sp_software_module_type MODIFY name VARCHAR(128);
ALTER TABLE sp_target MODIFY name VARCHAR(128);
ALTER TABLE sp_target_filter_query MODIFY name VARCHAR(128);
ALTER TABLE sp_target_tag MODIFY name VARCHAR(128);


ALTER TABLE sp_target MODIFY controller_id VARCHAR(256);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ALTER TABLE sp_distribution_set ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_distribution_set_type ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_distributionset_tag ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_base_software_module ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_rollout ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_rolloutgroup ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_software_module_type ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_target ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_target_filter_query ALTER COLUMN name VARCHAR(128);
ALTER TABLE sp_target_tag ALTER COLUMN name VARCHAR(128);


ALTER TABLE sp_target ALTER COLUMN controller_id VARCHAR(256);
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import org.eclipse.hawkbit.repository.model.DistributionSetTag;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.NamedVersionedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
Expand Down Expand Up @@ -218,7 +220,7 @@ private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().version("a")
.name(RandomStringUtils.randomAlphanumeric(65))))
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))))
.as("entity with too long name should not be created");

assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(
Expand All @@ -232,7 +234,7 @@ private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.name(RandomStringUtils.randomAlphanumeric(65))))
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))))
.as("entity with too long name should not be updated");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand All @@ -251,7 +253,7 @@ private void createAndUpdateDistributionSetWithInvalidVersion(final Distribution

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
.version(RandomStringUtils.randomAlphanumeric(65))))
.version(RandomStringUtils.randomAlphanumeric(NamedVersionedEntity.VERSION_MAX_SIZE + 1))))
.as("entity with too long name should not be created");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please fix the assertion error message, entity with too long version should not be created instead of entity with too long name should not be created. It's in multiple places in this file


assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(
Expand All @@ -260,7 +262,7 @@ private void createAndUpdateDistributionSetWithInvalidVersion(final Distribution

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.version(RandomStringUtils.randomAlphanumeric(65))))
.version(RandomStringUtils.randomAlphanumeric(NamedVersionedEntity.VERSION_MAX_SIZE + 1))))
.as("entity with too long name should not be updated");

assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSetType;
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.NamedVersionedEntity;
import org.eclipse.hawkbit.repository.test.matcher.Expect;
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.junit.Test;
Expand Down Expand Up @@ -128,7 +130,7 @@ private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().version("a")
.name(RandomStringUtils.randomAlphanumeric(65))))
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))))
.as("set with too long name should not be created");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand All @@ -147,7 +149,7 @@ private void createAndUpdateDistributionSetWithInvalidName(final DistributionSet

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.name(RandomStringUtils.randomAlphanumeric(65))))
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))))
.as("set with too long name should not be updated");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand All @@ -165,7 +167,7 @@ private void createAndUpdateDistributionSetWithInvalidVersion(final Distribution

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> distributionSetManagement.create(entityFactory.distributionSet().create().name("a")
.version(RandomStringUtils.randomAlphanumeric(65))))
.version(RandomStringUtils.randomAlphanumeric(NamedVersionedEntity.VERSION_MAX_SIZE + 1))))
.as("set with too long version should not be created");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand All @@ -184,7 +186,7 @@ private void createAndUpdateDistributionSetWithInvalidVersion(final Distribution

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
.version(RandomStringUtils.randomAlphanumeric(65))))
.version(RandomStringUtils.randomAlphanumeric(NamedVersionedEntity.VERSION_MAX_SIZE + 1))))
.as("set with too long version should not be updated");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetMetadata;
Expand Down Expand Up @@ -251,7 +252,7 @@ private void createAndUpdateTargetWithInvalidName(final Target target) {

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a")
.name(RandomStringUtils.randomAlphanumeric(65))))
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))))
.as("target with too long name should not be created");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand All @@ -261,7 +262,7 @@ private void createAndUpdateTargetWithInvalidName(final Target target) {

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId())
.name(RandomStringUtils.randomAlphanumeric(65))))
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1))))
.as("target with too long name should not be updated");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand All @@ -281,7 +282,7 @@ private void createAndUpdateTargetWithInvalidSecurityToken(final Target target)

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> targetManagement.create(entityFactory.target().create().controllerId("a")
.securityToken(RandomStringUtils.randomAlphanumeric(129))))
.securityToken(RandomStringUtils.randomAlphanumeric(Target.SECURITY_TOKEN_MAX_SIZE + 1))))
.as("target with too long token should not be created");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand All @@ -291,7 +292,7 @@ private void createAndUpdateTargetWithInvalidSecurityToken(final Target target)

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> targetManagement.update(entityFactory.target().update(target.getControllerId())
.securityToken(RandomStringUtils.randomAlphanumeric(129))))
.securityToken(RandomStringUtils.randomAlphanumeric(Target.SECURITY_TOKEN_MAX_SIZE + 1))))
.as("target with too long token should not be updated");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand Down Expand Up @@ -340,8 +341,8 @@ private void createTargetWithInvalidControllerId() {
.as("target with null controller id should not be created");

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> targetManagement
.create(entityFactory.target().create().controllerId(RandomStringUtils.randomAlphanumeric(65))))
.isThrownBy(() -> targetManagement.create(entityFactory.target().create()
.controllerId(RandomStringUtils.randomAlphanumeric(Target.CONTROLLER_ID_MAX_SIZE + 1))))
.as("target with too long controller id should not be created");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.hawkbit.repository.event.remote.entity.TargetTagUpdatedEvent;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.jpa.model.JpaTargetTag;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.Tag;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetTag;
Expand Down Expand Up @@ -132,7 +133,8 @@ private void createAndUpdateTagWithInvalidName(final Tag tag) {

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> targetTagManagement
.create(entityFactory.tag().create().name(RandomStringUtils.randomAlphanumeric(65))))
.create(entityFactory.tag().create().name(RandomStringUtils.randomAlphanumeric(
NamedEntity.NAME_MAX_SIZE + 1))))
.as("tag with too long name should not be created");

assertThatExceptionOfType(ConstraintViolationException.class)
Expand All @@ -141,7 +143,8 @@ private void createAndUpdateTagWithInvalidName(final Tag tag) {

assertThatExceptionOfType(ConstraintViolationException.class)
.isThrownBy(() -> targetTagManagement
.update(entityFactory.tag().update(tag.getId()).name(RandomStringUtils.randomAlphanumeric(65))))
.update(entityFactory.tag().update(tag.getId()).name(RandomStringUtils.randomAlphanumeric(
NamedEntity.NAME_MAX_SIZE + 1))))
.as("tag with too long name should not be updated");

assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.eclipse.hawkbit.repository.model.Action.Status;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetWithActionType;
Expand Down Expand Up @@ -989,7 +990,7 @@ public void invalidRequestsOnDistributionSetsResource() throws Exception {
.andExpect(status().isBadRequest());

final DistributionSet toLongName = testdataFactory
.generateDistributionSet(RandomStringUtils.randomAlphanumeric(80));
.generateDistributionSet(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1));
mvc.perform(post("/rest/v1/distributionsets").content(JsonBuilder.distributionSets(Arrays.asList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.hawkbit.repository.builder.SoftwareModuleTypeCreate;
import org.eclipse.hawkbit.repository.exception.QuotaExceededException;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.test.util.WithUser;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
Expand Down Expand Up @@ -618,7 +619,7 @@ public void invalidRequestsOnDistributionSetTypesResource() throws Exception {
.andExpect(status().isBadRequest());

final DistributionSetType toLongName = entityFactory.distributionSetType().create().key("test123")
.name(RandomStringUtils.randomAlphanumeric(80)).build();
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
mvc.perform(post("/rest/v1/distributionsettypes")
.content(JsonBuilder.distributionSetTypes(Arrays.asList(toLongName)))
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import org.apache.commons.lang3.RandomStringUtils;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
import org.eclipse.hawkbit.repository.test.util.WithUser;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
Expand Down Expand Up @@ -371,7 +372,7 @@ public void invalidRequestsOnSoftwaremoduleTypesResource() throws Exception {
.andExpect(status().isBadRequest());

final SoftwareModuleType toLongName = entityFactory.softwareModuleType().create().key("test123")
.name(RandomStringUtils.randomAlphanumeric(80)).build();
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
mvc.perform(
post("/rest/v1/softwaremoduletypes").content(JsonBuilder.softwareModuleTypes(Arrays.asList(toLongName)))
.contentType(MediaType.APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.eclipse.hawkbit.repository.model.ActionStatus;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.MetaData;
import org.eclipse.hawkbit.repository.model.NamedEntity;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TargetMetadata;
Expand Down Expand Up @@ -722,7 +723,7 @@ public void createTargetWithMissingMandatoryPropertyBadRequest() throws Exceptio
@Description("Verfies that a properties of new targets are validated as in allowed size range.")
public void createTargetWithInvalidPropertyBadRequest() throws Exception {
final Target test1 = entityFactory.target().create().controllerId("id1")
.name(RandomStringUtils.randomAlphanumeric(80)).build();
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();

final MvcResult mvcResult = mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
.content(JsonBuilder.targets(Arrays.asList(test1), true)).contentType(MediaType.APPLICATION_JSON))
Expand Down