Skip to content

Commit

Permalink
Added check on JobExecutions when modifying JobSteps
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Feb 17, 2021
1 parent 90544a0 commit 8ccc3f1
Show file tree
Hide file tree
Showing 10 changed files with 221 additions and 37 deletions.
5 changes: 3 additions & 2 deletions assembly/broker/configurations/locator.xml
Expand Up @@ -86,11 +86,12 @@
<api>org.eclipse.kapua.service.device.registry.event.DeviceEventService</api>
<api>org.eclipse.kapua.service.device.registry.lifecycle.DeviceLifeCycleService</api>

<api>org.eclipse.kapua.service.job.execution.JobExecutionService</api>
<api>org.eclipse.kapua.service.job.execution.JobExecutionFactory</api>
<api>org.eclipse.kapua.service.job.step.JobStepService</api>
<api>org.eclipse.kapua.service.job.step.JobStepFactory</api>

<api>org.eclipse.kapua.service.job.step.definition.JobStepDefinitionService</api>

<api>org.eclipse.kapua.service.job.step.definition.JobStepDefinitionFactory</api>
<api>org.eclipse.kapua.service.job.targets.JobTargetService</api>
<api>org.eclipse.kapua.service.job.targets.JobTargetFactory</api>

Expand Down
Expand Up @@ -64,10 +64,10 @@ public ListLoadResult<GwtJobStepDefinition> findAll() throws GwtKapuaException {
gwtJobStepDefinitionList.add(gwtJobStepDefinition);
}

} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
return new BaseListLoadResult<GwtJobStepDefinition>(gwtJobStepDefinitionList);
} catch (Exception e) {
throw KapuaExceptionHandler.buildExceptionFromError(e);
}
return new BaseListLoadResult<GwtJobStepDefinition>(gwtJobStepDefinitionList);
}

@Override
Expand All @@ -82,11 +82,10 @@ public GwtJobStepDefinition find(String gwtJobStepDefinitionId) throws GwtKapuaE

setEnumOnJobStepProperty(gwtJobStepDefinition.getStepProperties());
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
return gwtJobStepDefinition;
} catch (Exception e) {
throw KapuaExceptionHandler.buildExceptionFromError(e);
}

return gwtJobStepDefinition;
}

@Override
Expand Down
Expand Up @@ -75,11 +75,10 @@ public PagingLoadResult<GwtJobStep> query(PagingLoadConfig loadConfig, GwtJobSte
gwtJobStepList.add(gwtJobStep);
}

} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
return new BasePagingLoadResult<GwtJobStep>(gwtJobStepList, loadConfig.getOffset(), totalLength);
} catch (Exception e) {
throw KapuaExceptionHandler.buildExceptionFromError(e);
}

return new BasePagingLoadResult<GwtJobStep>(gwtJobStepList, loadConfig.getOffset(), totalLength);
}

@Override
Expand Down Expand Up @@ -115,13 +114,13 @@ public GwtJobStep create(GwtXSRFToken xsrfToken, GwtJobStepCreator gwtJobStepCre
gwtJobStep = KapuaGwtJobModelConverter.convertJobStep(jobStep);

setEnumOnJobStepProperty(gwtJobStep.getStepProperties());
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
}

//
// Return result
return gwtJobStep;
//
// Return result
return gwtJobStep;
} catch (Exception e) {
throw KapuaExceptionHandler.buildExceptionFromError(e);
}
}

@Override
Expand All @@ -133,8 +132,8 @@ public void delete(GwtXSRFToken xsrfToken, String gwtScopeId, String gwtJobStepI

try {
JOB_STEP_SERVICE.delete(scopeId, jobTargetId);
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
} catch (Exception e) {
throw KapuaExceptionHandler.buildExceptionFromError(e);
}
}

Expand All @@ -153,8 +152,8 @@ public GwtJobStep find(String gwtScopeId, String gwtJobStepId) throws GwtKapuaEx

setEnumOnJobStepProperty(gwtJobStep.getStepProperties());
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);
} catch (Exception e) {
throw KapuaExceptionHandler.buildExceptionFromError(e);
}

return gwtJobStep;
Expand Down Expand Up @@ -193,10 +192,11 @@ public GwtJobStep update(GwtXSRFToken xsrfToken, GwtJobStep gwtJobStep) throws G

setEnumOnJobStepProperty(gwtJobStep.getStepProperties());
}
} catch (Throwable t) {
KapuaExceptionHandler.handle(t);

return gwtJobStepUpdated;
} catch (Exception e) {
throw KapuaExceptionHandler.buildExceptionFromError(e);
}
return gwtJobStepUpdated;
}

/**
Expand Down
5 changes: 0 additions & 5 deletions console/web/src/main/resources/locator.xml
Expand Up @@ -103,22 +103,17 @@

<api>org.eclipse.kapua.service.job.JobService</api>
<api>org.eclipse.kapua.service.job.JobFactory</api>

<api>org.eclipse.kapua.service.job.execution.JobExecutionService</api>
<api>org.eclipse.kapua.service.job.execution.JobExecutionFactory</api>

<api>org.eclipse.kapua.service.job.step.JobStepService</api>
<api>org.eclipse.kapua.service.job.step.JobStepFactory</api>

<api>org.eclipse.kapua.service.job.step.definition.JobStepDefinitionService</api>
<api>org.eclipse.kapua.service.job.step.definition.JobStepDefinitionFactory</api>

<api>org.eclipse.kapua.service.job.targets.JobTargetService</api>
<api>org.eclipse.kapua.service.job.targets.JobTargetFactory</api>

<api>org.eclipse.kapua.service.scheduler.trigger.TriggerService</api>
<api>org.eclipse.kapua.service.scheduler.trigger.TriggerFactory</api>

<api>org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionService</api>
<api>org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionFactory</api>

Expand Down
5 changes: 0 additions & 5 deletions rest-api/web/src/main/resources/locator.xml
Expand Up @@ -107,16 +107,12 @@

<api>org.eclipse.kapua.service.job.JobService</api>
<api>org.eclipse.kapua.service.job.JobFactory</api>

<api>org.eclipse.kapua.service.job.execution.JobExecutionService</api>
<api>org.eclipse.kapua.service.job.execution.JobExecutionFactory</api>

<api>org.eclipse.kapua.service.job.step.JobStepService</api>
<api>org.eclipse.kapua.service.job.step.JobStepFactory</api>

<api>org.eclipse.kapua.service.job.step.definition.JobStepDefinitionService</api>
<api>org.eclipse.kapua.service.job.step.definition.JobStepDefinitionFactory</api>

<api>org.eclipse.kapua.service.job.targets.JobTargetService</api>
<api>org.eclipse.kapua.service.job.targets.JobTargetFactory</api>

Expand All @@ -125,7 +121,6 @@

<api>org.eclipse.kapua.service.scheduler.trigger.TriggerService</api>
<api>org.eclipse.kapua.service.scheduler.trigger.TriggerFactory</api>

<api>org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionService</api>
<api>org.eclipse.kapua.service.scheduler.trigger.definition.TriggerDefinitionFactory</api>

Expand Down
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2021 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.exception;

import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.job.Job;
import org.eclipse.kapua.service.job.step.JobStep;

/**
* {@link JobServiceException} to throw when trying to modify {@link JobStep}s of a {@link Job} that already started once.
*
* @since 1.5.0
*/
public class CannotModifyJobStepsException extends JobServiceException {

private final KapuaId jobId;

/**
* Constructor.
*
* @param jobId The {@link Job#getId()}.
* @since 1.5.0
*/
public CannotModifyJobStepsException(KapuaId jobId) {
super(JobServiceErrorCodes.CANNOT_MODIFY_JOB_STEPS, jobId);

this.jobId = jobId;
}

/**
* Gets the {@link Job#getId()}.
*
* @return The {@link Job#getId()}.
* @since 1.5.0
*/
public KapuaId getJobId() {
return jobId;
}
}
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2021 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.exception;

import org.eclipse.kapua.KapuaErrorCode;

/**
* {@link KapuaErrorCode}s for {@link JobServiceException}
*
* @since 1.5.0
*/
public enum JobServiceErrorCodes implements KapuaErrorCode {

/**
* See {@link CannotModifyJobStepsException}.
*
* @since 1.5.0
*/
CANNOT_MODIFY_JOB_STEPS,
}
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2021 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.exception;

import org.eclipse.kapua.KapuaException;

/**
* {@link KapuaException} base for Scheduler Service {@link Exception}s
*
* @since 1.5.0
*/
public abstract class JobServiceException extends KapuaException {

private static final String KAPUA_ERROR_MESSAGES = "job-service-error-messages";

/**
* Constructor.
*
* @param code The {@link JobServiceErrorCodes}.
* @since 1.5.0
*/
public JobServiceException(JobServiceErrorCodes code) {
super(code);
}

/**
* Constructor.
*
* @param code The {@link JobServiceErrorCodes}.
* @param arguments Additional argument associated with the {@link JobServiceException}.
* @since 1.5.0
*/
public JobServiceException(JobServiceErrorCodes code, Object... arguments) {
super(code, arguments);
}

/**
* Constructor.
*
* @param code The {@link JobServiceErrorCodes}.
* @param cause The root {@link Throwable} of this {@link JobServiceException}.
* @param arguments Additional argument associated with the {@link JobServiceException}.
* @since 1.5.0
*/
public JobServiceException(JobServiceErrorCodes code, Throwable cause, Object... arguments) {
super(code, cause, arguments);
}

@Override
protected String getKapuaErrorMessagesBundle() {
return KAPUA_ERROR_MESSAGES;
}
}
@@ -0,0 +1,14 @@
###############################################################################
# Copyright (c) 2021 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
#
###############################################################################
CANNOT_MODIFY_JOB_STEPS=Cannot modify JobSteps of Job {0} because it has already started once.

0 comments on commit 8ccc3f1

Please sign in to comment.