Skip to content

Commit

Permalink
Merge pull request #3983 from MDeLuise/fix-jobExecRest
Browse files Browse the repository at this point in the history
Fix issue with job execution filtering in REST API for start date
  • Loading branch information
Coduz authored Mar 7, 2024
2 parents bf1684c + 0465086 commit ddd356d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,26 @@ Scenario: Query for executions of a specific job
When I query for the execution items for the current job
Then I count 3


Scenario: Query for executions of a specific job using start date

Given I login as user with name "kapua-sys" and password "kapua-password"
* I configure the job service
| type | name | value |
| boolean | infiniteChildEntities | true |
| integer | maxNumberChildEntities | 5 |
* I create a job with the name "TestJob"
* A regular job execution item
* A regular job execution item
* A regular job execution item
* A regular job execution item

When I query for the execution items for the current job starting from date in the future
Then I count 0

When I query for the execution items for the current job starting from date in the past
Then I count 4

Scenario: Job execution factory sanity checks

And I test the sanity of the job execution factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
*******************************************************************************/
package org.eclipse.kapua.app.api.resources.v1.resources;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import com.google.common.base.Strings;
import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
Expand All @@ -37,17 +48,6 @@
import org.eclipse.kapua.service.job.targets.JobTargetQuery;
import org.eclipse.kapua.service.job.targets.JobTargetService;

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

@Path("{scopeId}/jobs/{jobId}/executions")
public class JobExecutions extends AbstractKapuaResource {

Expand Down Expand Up @@ -128,7 +128,11 @@ public JobExecutionListResult query(
@PathParam("jobId") EntityId jobId,
JobExecutionQuery query) throws KapuaException {
query.setScopeId(scopeId);
query.setPredicate(query.attributePredicate(JobExecutionAttributes.JOB_ID, jobId));
final AndPredicate andPredicate = query.andPredicate(
query.attributePredicate(JobExecutionAttributes.JOB_ID, jobId),
query.getPredicate()
);
query.setPredicate(andPredicate);
return jobExecutionService.query(query);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*******************************************************************************/
package org.eclipse.kapua.service.job.steps;

import java.util.Calendar;
import java.util.Date;
import javax.inject.Inject;

import com.google.inject.Singleton;
import io.cucumber.java.After;
import io.cucumber.java.Before;
Expand All @@ -23,6 +27,7 @@
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.model.query.predicate.AndPredicate;
import org.eclipse.kapua.model.query.predicate.AttributePredicate;
import org.eclipse.kapua.qa.common.StepData;
import org.eclipse.kapua.service.job.Job;
Expand All @@ -42,8 +47,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;

@Singleton
public class JobExecutionServiceSteps extends JobServiceTestBase {

Expand Down Expand Up @@ -165,22 +168,51 @@ public void queryExecutionsForJobWithPackages() throws Exception {
}
}

// @And("I query for the execution items for the current job and I count {int} or more")
// public void iQueryForTheExecutionItemsForTheCurrentJobAndICountOrMore(int numberOfExecutions) throws Exception {
// Job job = (Job) stepData.get("Job");
// JobExecutionQuery tmpQuery = jobExecutionFactory.newQuery(getCurrentScopeId());
// tmpQuery.setPredicate(tmpQuery.attributePredicate(JobExecutionAttributes.JOB_ID, job.getId(), AttributePredicate.Operator.EQUAL));
// primeException();
// try {
// stepData.remove(JOB_EXECUTION_LIST);
// JobExecutionListResult resultList = jobExecutionService.query(tmpQuery);
// stepData.put(JOB_EXECUTION_LIST, resultList);
// stepData.updateCount(resultList.getSize());
// Assert.assertTrue(resultList.getSize() >= numberOfExecutions);
// } catch (KapuaException ex) {
// verifyException(ex);
// }
// }

@Then("I query for the execution items for the current job starting from date in the future")
public void queryExecutionsForJobWithStartDateInFuture() throws Exception {
final Date startDate = createDateInFuture();
queryExecutionsForJobWithStartDate(startDate);
}


@Then("I query for the execution items for the current job starting from date in the past")
public void queryExecutionsForJobWithStartDateInPast() throws Exception {
final Date startDate = createDateInPast();
queryExecutionsForJobWithStartDate(startDate);
}


private void queryExecutionsForJobWithStartDate(Date startDate) throws Exception {
final Job job = (Job) stepData.get("Job");
final JobExecutionQuery tmpQuery = jobExecutionFactory.newQuery(getCurrentScopeId());
final AndPredicate andPredicate = tmpQuery.andPredicate(tmpQuery.attributePredicate(JobExecutionAttributes.JOB_ID, job.getId()));
andPredicate.and(tmpQuery.attributePredicate(JobExecutionAttributes.STARTED_ON, startDate, AttributePredicate.Operator.GREATER_THAN_OR_EQUAL));
tmpQuery.setPredicate(andPredicate);
primeException();
try {
stepData.remove(JOB_EXECUTION_LIST);
JobExecutionListResult resultList = jobExecutionService.query(tmpQuery);
stepData.put(JOB_EXECUTION_LIST, resultList);
stepData.updateCount(resultList.getSize());
} catch (KapuaException ex) {
verifyException(ex);
}
}


private Date createDateInFuture() {
final Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, 7);
return calendar.getTime();
}


private Date createDateInPast() {
final Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -7);
return calendar.getTime();
}

@Then("I query for the execution items for the current job and I count {int} finished within {int} second(s)")
public void queryExecutionsForJob(int numberOfExecutions, int timeout) throws Exception {
Expand Down

0 comments on commit ddd356d

Please sign in to comment.