Skip to content

Commit

Permalink
Merge pull request eclipse#3828 from Coduz/feat-longerJobStepProperty…
Browse files Browse the repository at this point in the history
…Value

feat(job): Increased length of `JobStepProperty.propertyValue` field to allow up to 4GB
  • Loading branch information
Coduz authored Jul 27, 2023
2 parents 736dc6d + 4523a52 commit a5a199b
Show file tree
Hide file tree
Showing 12 changed files with 252 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,22 @@ protected void refreshJobStepDefinition(GwtJobStepDefinition gwtJobStepDefinitio

textArea.setData(PROPERTY_TYPE, property.getPropertyType());
textArea.setData(PROPERTY_NAME, property.getPropertyName());
textArea.setMaxLength(65535);
jobStepPropertiesPanel.add(textArea);

JOB_STEP_SERVICE.getJobStepPropertyLengthMax(new AsyncCallback<Integer>() {
@Override
public void onFailure(Throwable caught) {
textArea.setMaxLength(104857600); // 100MB

FailureHandler.handle(caught);
}

@Override
public void onSuccess(Integer jobStepPropertyMaxLength) {
textArea.setMaxLength(jobStepPropertyMaxLength);
}
});

if (property.getExampleValue() != null) {
final String exampleValue = KapuaSafeHtmlUtils.htmlUnescape(property.getExampleValue());
exampleButton = new KapuaButton(getExampleButtonText(), new KapuaIcon(IconSet.EDIT), new SelectionListener<ButtonEvent>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ public GwtJobStep update(GwtXSRFToken xsrfToken, GwtJobStep gwtJobStep) throws G
}
}

@Override
public int getJobStepPropertyLengthMax() throws GwtKapuaException {
try {
return JOB_STEP_SERVICE.getJobStepPropertyMaxLength();
} catch (Exception e) {
throw KapuaExceptionHandler.buildExceptionFromError(e);
}
}

/**
* Set the {@link GwtJobStepProperty#isEnum()} property.
* This cannot be performed in *.shared.* packages (entity converters are in that package), since `Class.forName` is not present in the JRE Emulation library.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ void delete(GwtXSRFToken xsrfToken, String gwtScopeId, String gwtJobStepId)
GwtJobStep update(GwtXSRFToken xsrfToken, GwtJobStep gwtJobStep)
throws GwtKapuaException;

int getJobStepPropertyLengthMax()
throws GwtKapuaException;

/**
* Just to make Gwt serialize {@link GwtJobStepProperty}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ public JobStep find(KapuaId scopeId, KapuaId jobStepId) {
public void delete(KapuaId scopeId, KapuaId jobStepId) {
throw new UnsupportedOperationException();
}

@Override
public int getJobStepPropertyMaxLength() throws KapuaException {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.kapua.model.query.KapuaQuery;
import org.eclipse.kapua.service.KapuaEntityService;
import org.eclipse.kapua.service.KapuaUpdatableEntityService;
import org.eclipse.kapua.service.job.step.definition.JobStepProperty;

/**
* {@link JobStepService} exposes APIs to manage JobStep objects.<br>
Expand All @@ -38,4 +39,12 @@ public interface JobStepService extends KapuaEntityService<JobStep, JobStepCreat
@Override
JobStepListResult query(KapuaQuery query)
throws KapuaException;

/**
* Gets the maximum length that a {@link JobStepProperty#getPropertyValue()} is allowed to have.
*
* @since 2.0.0
*/
int getJobStepPropertyMaxLength()
throws KapuaException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*******************************************************************************
* Copyright (c) 2023, 2022 Eurotech and/or its affiliates 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
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.job.internal.settings;

import org.eclipse.kapua.commons.setting.SettingKey;
import org.eclipse.kapua.service.job.step.definition.JobStepProperty;

/**
* {@link SettingKey}s for {@link JobServiceSettings}.
*
* @since 2.0.0
*/
public enum JobServiceSettingKeys implements SettingKey {

/**
* Max length of {@link JobStepProperty#getPropertyValue()}.
*
* @since 2.0.0
*/
JOB_STEP_PROPERTY_VALUE_LENGTH_MAX("job.step.property.value.length.max");

/**
* The key value of the {@link SettingKey}.
*
* @since 120.0
*/
private final String key;

/**
* Constructor.
*
* @param key The key value of the {@link SettingKey}.
* @since 2.0.0
*/
private JobServiceSettingKeys(String key) {
this.key = key;
}

@Override
public String key() {
return key;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2016, 2022 Eurotech and/or its affiliates 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
*
* Contributors:
* Eurotech - initial API and implementation
*******************************************************************************/
package org.eclipse.kapua.service.job.internal.settings;

import org.eclipse.kapua.commons.setting.AbstractKapuaSetting;

/**
* {@link AbstractKapuaSetting} for {@code kapua-job-internal} module.
*
* @see AbstractKapuaSetting
* @since 2.0.0
*/
public class JobServiceSettings extends AbstractKapuaSetting<JobServiceSettingKeys> {

/**
* Setting filename.
*
* @since 2.0.0
*/
private static final String JOB_SERVICE_SETTING_RESOURCE = "job-service-settings.properties";

/**
* Singleton instance.
*
* @since 2.0.0
*/
private static final JobServiceSettings INSTANCE = new JobServiceSettings();

/**
* Constructor.
*
* @since 2.0.0
*/
private JobServiceSettings() {
super(JOB_SERVICE_SETTING_RESOURCE);
}

/**
* Gets a singleton instance of {@link JobServiceSettings}.
*
* @return A singleton instance of {@link JobServiceSettings}.
* @since 2.0.0
*/
public static JobServiceSettings getInstance() {
return INSTANCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.eclipse.kapua.service.job.execution.JobExecutionQuery;
import org.eclipse.kapua.service.job.execution.JobExecutionService;
import org.eclipse.kapua.service.job.internal.JobEntityManagerFactory;
import org.eclipse.kapua.service.job.internal.settings.JobServiceSettingKeys;
import org.eclipse.kapua.service.job.internal.settings.JobServiceSettings;
import org.eclipse.kapua.service.job.step.JobStep;
import org.eclipse.kapua.service.job.step.JobStepAttributes;
import org.eclipse.kapua.service.job.step.JobStepCreator;
Expand Down Expand Up @@ -80,6 +82,15 @@ public class JobStepServiceImpl extends AbstractKapuaService implements JobStepS
@Inject
QueryFactory queryFactory;

private final JobServiceSettings jobServiceSettings = JobServiceSettings.getInstance();

/**
* The maximum length that a {@link JobStepProperty#getPropertyValue()} is allowed to have
*
* @since 2.0.0
*/
private final int jobStepPropertyValueLengthMax = jobServiceSettings.getInt(JobServiceSettingKeys.JOB_STEP_PROPERTY_VALUE_LENGTH_MAX);

public JobStepServiceImpl() {
super(JobEntityManagerFactory.getInstance(), null);
}
Expand All @@ -95,8 +106,8 @@ public JobStep create(JobStepCreator jobStepCreator) throws KapuaException {

for (JobStepProperty jobStepProperty : jobStepCreator.getStepProperties()) {
if (jobStepProperty.getPropertyValue() != null) {
Integer stepPropertyMaxLength = jobStepProperty.getMaxLength() != null ? jobStepProperty.getMaxLength() : 65535;
ArgumentValidator.lengthRange(jobStepProperty.getPropertyValue(), jobStepProperty.getMinLength(), stepPropertyMaxLength, "stepProperties[]." + jobStepProperty.getName());
Integer stepPropertyMaxLength = jobStepProperty.getMaxLength() != null ? jobStepProperty.getMaxLength() : jobStepPropertyValueLengthMax;
ArgumentValidator.lengthRange(jobStepProperty.getPropertyValue(), jobStepProperty.getMinLength(), stepPropertyMaxLength, "jobStepCreator.stepProperties[]." + jobStepProperty.getName());
}
}

Expand Down Expand Up @@ -186,6 +197,14 @@ public JobStep update(JobStep jobStep) throws KapuaException {
ArgumentValidator.notNull(jobStep.getScopeId(), "jobStep.scopeId");
ArgumentValidator.validateEntityName(jobStep.getName(), "jobStep.name");
ArgumentValidator.notNull(jobStep.getJobStepDefinitionId(), "jobStep.stepDefinitionId");

for (JobStepProperty jobStepProperty : jobStep.getStepProperties()) {
if (jobStepProperty.getPropertyValue() != null) {
Integer stepPropertyMaxLength = jobStepProperty.getMaxLength() != null ? jobStepProperty.getMaxLength() : jobStepPropertyValueLengthMax;
ArgumentValidator.lengthRange(jobStepProperty.getPropertyValue(), jobStepProperty.getMinLength(), stepPropertyMaxLength, "jobStep.stepProperties[]." + jobStepProperty.getName());
}
}

if (jobStep.getDescription() != null) {
ArgumentValidator.numRange(jobStep.getDescription().length(), 0, 8192, "jobStep.description");
}
Expand Down Expand Up @@ -368,6 +387,17 @@ public void delete(KapuaId scopeId, KapuaId jobStepId) throws KapuaException {
});
}

@Override
public int getJobStepPropertyMaxLength() throws KapuaException {
//
// Check access
authorizationService.checkPermission(permissionFactory.newPermission(JobDomains.JOB_DOMAIN, Actions.read, KapuaId.ANY));

//
// Return the value
return jobStepPropertyValueLengthMax;
}

//
// Private methods
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
###############################################################################
# Copyright (c) 2023, 2022 Eurotech and/or its affiliates 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
#
# Contributors:
# Eurotech - initial API and implementation
#
###############################################################################
# 100 MB
job.step.property.value.length.max=104857600
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023, 2022 Eurotech and/or its affiliates 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
Contributors:
Eurotech - initial API and implementation
-->
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd"
logicalFilePath="KapuaDB/changelog-job-2.0.0.xml">

<include relativeToChangelogFile="true" file="job_job_step_properties-value_length.xml"/>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023, 2022 Eurotech and/or its affiliates 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
Contributors:
Eurotech - initial API and implementation
-->
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd"

logicalFilePath="KapuaDB/changelog-job-2.0.0.xml">

<include relativeToChangelogFile="true" file="../common-properties.xml"/>

<changeSet id="changelog-job_step_properties-2.0.0_valueLength" author="eurotech">
<modifyDataType
tableName="job_job_step_properties"
columnName="property_value"
newDataType="longtext"/>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<include relativeToChangelogFile="true" file="./1.2.0/changelog-job-1.2.0.xml"/>
<include relativeToChangelogFile="true" file="./1.5.0/changelog-job-1.5.0.xml"/>
<include relativeToChangelogFile="true" file="./1.6.0/changelog-job-1.6.0.xml"/>
<include relativeToChangelogFile="true" file="./2.0.0/changelog-job-2.0.0.xml"/>

</databaseChangeLog>

0 comments on commit a5a199b

Please sign in to comment.