Skip to content

Commit

Permalink
Merge branch 'backport-4187' into release-2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Coduz committed Feb 11, 2025
2 parents aaea7b7 + d05c3f5 commit bac2ae6
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Feature: Job Execution service CRUD tests
| integer | maxNumberChildEntities | 5 |
Given I create a job with the name "TestJob"
And A regular job execution item
When I update the end time of the execution item
When I update the end time of the execution item as if the job finished now
Then No exception was thrown
When I search for the last job execution in the database
Then The job execution items match
Expand Down Expand Up @@ -156,6 +156,24 @@ Feature: Job Execution service CRUD tests

And I test the sanity of the job execution factory

Scenario: Update the end time of an existing execution item and see if status is computed correctly

Given I login as user with name "kapua-sys" and password "kapua-password"
And I configure the job service
| type | name | value |
| boolean | infiniteChildEntities | true |
| integer | maxNumberChildEntities | 5 |
Given I create a job with the name "TestJob"
And A regular job execution item
When I update the end time of the execution item as if the job finished now
Then No exception was thrown
When I search for the last job execution in the database
Then The job execution status is "TERMINATED"
When I update the end time of the execution item as if the job never finished
Then No exception was thrown
When I search for the last job execution in the database
Then The job execution status is "RUNNING"

@teardown
Scenario: Tear down test resources
Given Stop Docker environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.kapua.service.job.execution.JobExecutionListResult;
import org.eclipse.kapua.service.job.execution.JobExecutionQuery;
import org.eclipse.kapua.service.job.execution.JobExecutionService;
import org.eclipse.kapua.service.job.execution.JobExecutionStatus;
import org.eclipse.kapua.service.job.targets.JobTargetFactory;
import org.eclipse.kapua.service.job.targets.JobTargetListResult;
import org.eclipse.kapua.service.job.targets.JobTargetQuery;
Expand Down Expand Up @@ -84,7 +85,8 @@ public JobExecutionListResult simpleQuery(
@QueryParam("sortParam") String sortParam,
@QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir,
@QueryParam("offset") @DefaultValue("0") int offset,
@QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException {
@QueryParam("limit") @DefaultValue("50") int limit,
@QueryParam("status") JobExecutionStatus statusParam) throws KapuaException {
JobExecutionQuery query = jobExecutionFactory.newQuery(scopeId);

AndPredicate andPredicate = query.andPredicate(query.attributePredicate(JobExecutionAttributes.JOB_ID, jobId));
Expand All @@ -95,6 +97,11 @@ public JobExecutionListResult simpleQuery(
if (endDateParam != null) {
andPredicate.and(query.attributePredicate(JobExecutionAttributes.ENDED_ON, endDateParam.getDate(), AttributePredicate.Operator.LESS_THAN_OR_EQUAL));
}
if (statusParam != null && statusParam.equals(JobExecutionStatus.RUNNING)) {
andPredicate.and(query.attributePredicate(JobExecutionAttributes.ENDED_ON, null, AttributePredicate.Operator.IS_NULL));
} else if (statusParam != null && statusParam.equals(JobExecutionStatus.TERMINATED)) {
andPredicate.and(query.attributePredicate(JobExecutionAttributes.ENDED_ON, null, AttributePredicate.Operator.NOT_NULL));
}

query.setPredicate(andPredicate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ paths:
format: 'date-time'
- $ref: '../openapi.yaml#/components/parameters/sortParam'
- $ref: '../openapi.yaml#/components/parameters/sortDir'
- name: status
in: query
description: status of job execution
schema:
type: string
enum:
- RUNNING
- TERMINATED
- $ref: '../openapi.yaml#/components/parameters/limit'
- $ref: '../openapi.yaml#/components/parameters/offset'
- $ref: '../openapi.yaml#/components/parameters/askTotalCount'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ components:
items:
allOf:
- $ref: '../openapi.yaml#/components/schemas/kapuaId'
status:
description: status of job execution
type: string
enum:
- RUNNING
- TERMINATED
example:
type: jobExecution
id: GTh9xBWezHY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,16 @@ default String getType() {
* @since 1.1.0
*/
void setLog(String log);

/**
* @return
* @since 2.1.0
*/
JobExecutionStatus getStatus();

/**
* @param status
* @since 2.1.0
*/
void setStatus(JobExecutionStatus status);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2017, 2024 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.execution;

/**
* @since 2.1.0
*/
public enum JobExecutionStatus {

/**
* @since 2.1.0
*/
RUNNING,

/**
* @since 2.1.0
*/
TERMINATED
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.kapua.commons.model.id.KapuaEid;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.job.execution.JobExecution;
import org.eclipse.kapua.service.job.execution.JobExecutionStatus;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
Expand All @@ -29,6 +30,7 @@
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -69,6 +71,10 @@ public class JobExecutionImpl extends AbstractKapuaUpdatableEntity implements Jo
@Column(name = "log", nullable = true, updatable = true)
private String log;

@Transient
private JobExecutionStatus status;


/**
* Constructor.
*
Expand Down Expand Up @@ -167,4 +173,18 @@ public String getLog() {
public void setLog(String log) {
this.log = log;
}

@Override
public JobExecutionStatus getStatus() {
if (this.getEndedOn() != null) {
return JobExecutionStatus.TERMINATED;
} else {
return JobExecutionStatus.RUNNING;
}
}

@Override
public void setStatus(JobExecutionStatus status) {
this.status = status;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.kapua.service.job.execution.JobExecutionListResult;
import org.eclipse.kapua.service.job.execution.JobExecutionQuery;
import org.eclipse.kapua.service.job.execution.JobExecutionService;
import org.eclipse.kapua.service.job.execution.JobExecutionStatus;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.slf4j.Logger;
Expand Down Expand Up @@ -107,7 +108,7 @@ public void updateJobIdForExecution() throws Exception {
}
}

@When("I update the end time of the execution item")
@When("I update the end time of the execution item as if the job finished now")
public void updateJobExecutionEndTime() throws Exception {
JobExecution execution = (JobExecution) stepData.get(JOB_EXECUTION);
primeException();
Expand All @@ -120,6 +121,19 @@ public void updateJobExecutionEndTime() throws Exception {
}
}

@When("I update the end time of the execution item as if the job never finished")
public void updateJobExecutionEndTimeWithNull() throws Exception {
JobExecution execution = (JobExecution) stepData.get(JOB_EXECUTION);
primeException();
try {
execution.setEndedOn(null);
execution = jobExecutionService.update(execution);
stepData.put(JOB_EXECUTION, execution);
} catch (KapuaException ex) {
verifyException(ex);
}
}

@When("I search for the last job execution in the database")
public void findLastJobExecution() throws Exception {
JobExecution execution = (JobExecution) stepData.get(JOB_EXECUTION);
Expand Down Expand Up @@ -419,7 +433,6 @@ private void logJobInfo(JobExecutionListResult jobExecutionList, Job job, int ex
}
}


@Then("The job execution matches the creator")
public void checkJobExecutionItemAgainstCreator() {
JobExecutionCreator executionCreator = (JobExecutionCreator) stepData.get("JobExecutionCreator");
Expand All @@ -430,7 +443,7 @@ public void checkJobExecutionItemAgainstCreator() {
}

@Then("The job execution items match")
public void checkJobExecutionItems() {
public void checkJobExecutionItemsRunning() {
JobExecution execution = (JobExecution) stepData.get(JOB_EXECUTION);
JobExecution foundExecution = (JobExecution) stepData.get("JobExecutionFound");
Assert.assertEquals(execution.getScopeId(), foundExecution.getScopeId());
Expand All @@ -439,6 +452,12 @@ public void checkJobExecutionItems() {
Assert.assertEquals(execution.getEndedOn(), foundExecution.getEndedOn());
}

@Then("The job execution status is {string}")
public void checkJobExecutionItems(String status) {
JobExecution foundExecution = (JobExecution) stepData.get("JobExecutionFound");
Assert.assertEquals(foundExecution.getStatus(), JobExecutionStatus.valueOf(status));
}

@Then("There is no such job execution item in the database")
public void checkThatNoExecutionWasFound() {
Assert.assertNull("Unexpected job execution item found!", stepData.get("JobExecutionFound"));
Expand Down

0 comments on commit bac2ae6

Please sign in to comment.