Skip to content

Commit

Permalink
feat(job): Added JobServiceSetting 'job.step.property.value.length.ma…
Browse files Browse the repository at this point in the history
…x' as soft limit for JobStepProperty.propertyValue

Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Jul 24, 2023
1 parent 4fa39ca commit ce8c8d3
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 2 deletions.
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 @@ -38,6 +38,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 @@ -75,6 +77,10 @@ public class JobStepServiceImpl extends AbstractKapuaService implements JobStepS
private static final JobStepDefinitionService JOB_STEP_DEFINITION_SERVICE = LOCATOR.getService(JobStepDefinitionService.class);


private final JobServiceSettings jobServiceSettings = JobServiceSettings.getInstance();

private final int jobStepPropertyValueLengthMax = jobServiceSettings.getInt(JobServiceSettingKeys.JOB_STEP_PROPERTY_VALUE_LENGTH_MAX);

public JobStepServiceImpl() {
super(JobEntityManagerFactory.getInstance(), null);
}
Expand All @@ -90,8 +96,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 @@ -175,6 +181,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

0 comments on commit ce8c8d3

Please sign in to comment.