Skip to content
Permalink
Browse files

Merge pull request #2342 from eclipse/feature-jobTargetErrorMessage

Job target error message
  • Loading branch information
Coduz committed Mar 26, 2019
2 parents 5a50793 + c041650 commit 2362a6f4d26fcf5830e34d4ef69df56bb76e977e
Showing with 327 additions and 58 deletions.
  1. +6 −3 .../job/src/main/java/org/eclipse/kapua/app/console/module/job/client/targets/JobTabTargetsGrid.java
  2. +8 −6 .../module/job/src/main/java/org/eclipse/kapua/app/console/module/job/shared/model/GwtJobTarget.java
  3. +1 −2 ...src/main/java/org/eclipse/kapua/app/console/module/job/shared/util/GwtKapuaJobModelConverter.java
  4. +22 −2 ...src/main/java/org/eclipse/kapua/app/console/module/job/shared/util/KapuaGwtJobModelConverter.java
  5. +1 −1 .../resources/org/eclipse/kapua/app/console/module/job/client/messages/ConsoleJobMessages.properties
  6. +16 −6 ...commons/src/main/java/org/eclipse/kapua/job/engine/commons/operation/AbstractTargetProcessor.java
  7. +22 −8 ...ine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/operation/DefaultTargetReader.java
  8. +14 −6 ...ine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/operation/DefaultTargetWriter.java
  9. +19 −2 .../main/java/org/eclipse/kapua/job/engine/commons/{context → wrappers}/JobContextPropertyNames.java
  10. +7 −2 ...ns/src/main/java/org/eclipse/kapua/job/engine/commons/{context → wrappers}/JobContextWrapper.java
  11. +46 −0 job-engine/commons/src/main/java/org/eclipse/kapua/job/engine/commons/wrappers/JobTargetWrapper.java
  12. +13 −3 ...main/java/org/eclipse/kapua/job/engine/commons/{context → wrappers}/StepContextPropertyNames.java
  13. +7 −2 ...s/src/main/java/org/eclipse/kapua/job/engine/commons/{context → wrappers}/StepContextWrapper.java
  14. +10 −3 ...batch/src/main/java/org/eclipse/kapua/job/engine/jbatch/driver/utils/JobDefinitionBuildUtils.java
  15. +1 −3 job-engine/jbatch/src/main/java/org/eclipse/kapua/job/engine/jbatch/listener/KapuaJobListener.java
  16. +1 −1 service/api/src/main/java/org/eclipse/kapua/KapuaRuntimeErrorCodes.java
  17. +86 −3 service/job/api/src/main/java/org/eclipse/kapua/service/job/targets/JobTarget.java
  18. +17 −4 service/job/internal/src/main/java/org/eclipse/kapua/service/job/targets/internal/JobTargetImpl.java
  19. +2 −1 service/job/internal/src/main/resources/liquibase/1.1.0/changelog-job-1.1.0.xml
  20. +28 −0 service/job/internal/src/main/resources/liquibase/1.1.0/job_target-status_message.xml
@@ -117,14 +117,17 @@ protected void load(Object loadConfig, AsyncCallback<PagingLoadResult<GwtJobTarg
columnConfig.setSortable(false);
columnConfigs.add(columnConfig);

columnConfig = new ColumnConfig("displayName", MSGS.gridJobTargetColumnHeaderDisplayName(), 300);
columnConfig = new ColumnConfig("displayName", MSGS.gridJobTargetColumnHeaderDisplayName(), 250);
columnConfig.setSortable(false);
columnConfigs.add(columnConfig);

columnConfig = new ColumnConfig("stepIndex", MSGS.gridJobTargetColumnHeaderJobStepIndex(), 300);
columnConfig = new ColumnConfig("stepIndex", MSGS.gridJobTargetColumnHeaderJobStepIndex(), 100);
columnConfigs.add(columnConfig);

columnConfig = new ColumnConfig("status", MSGS.gridJobTargetColumnHeaderStatus(), 200);
columnConfig = new ColumnConfig("status", MSGS.gridJobTargetColumnHeaderStatus(), 150);
columnConfigs.add(columnConfig);

columnConfig = new ColumnConfig("statusMessage", MSGS.gridJobTargetColumnHeaderStatusMessage(), 400);
columnConfigs.add(columnConfig);

return columnConfigs;
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -20,7 +20,6 @@
}

@Override
@SuppressWarnings({ "unchecked" })
public <X> X get(String property) {
if ("statusEnum".equals(property)) {
return (X) GwtJobTargetStatus.valueOf(getStatus());
@@ -65,14 +64,17 @@ public void setStepIndex(int stepIndex) {
set("stepIndex", stepIndex);
}

public String getErrorMessage() {
return get("errorMessage");
public String getStatusMessage() {
return get("statusMessage");
}

public void setErrorMessage(String errorMessage) {
set("errorMessage", errorMessage);
public void setStatusMessage(String statusMessage) {
set("statusMessage", statusMessage);
}

//
// Additional fields
//
public String getClientId() {
return get("clientId");
}
@@ -304,8 +304,7 @@ public static JobExecutionQuery convertJobExecutionQuery(PagingLoadConfig paging
sortField = JobAttributes.ENDED_ON;
}
SortOrder sortOrder = pagingLoadConfig.getSortDir().equals(SortDir.DESC) ? SortOrder.DESCENDING : SortOrder.ASCENDING;
FieldSortCriteria sortCriteria = new FieldSortCriteria(sortField, sortOrder);
query.setSortCriteria(sortCriteria);
query.setSortCriteria(new FieldSortCriteria(sortField, sortOrder));
query.setLimit(pagingLoadConfig.getLimit());
query.setOffset(pagingLoadConfig.getOffset());

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -39,91 +39,111 @@ private KapuaGwtJobModelConverter() {

public static GwtJob convertJob(Job job) {
GwtJob gwtJob = new GwtJob();

KapuaGwtCommonsModelConverter.convertUpdatableEntity(job, gwtJob);
gwtJob.setJobName(job.getName());
gwtJob.setDescription(job.getDescription());
gwtJob.setJobXmlDefinition(job.getJobXmlDefinition());
gwtJob.setJobSteps(convertJobSteps(job.getJobSteps()));

return gwtJob;
}

private static List<GwtJobStep> convertJobSteps(List<JobStep> jobStepList) {
List<GwtJobStep> gwtJobStepList = new ArrayList<GwtJobStep>();

for (JobStep jobStep : jobStepList) {
gwtJobStepList.add(convertJobStep(jobStep));
}

return gwtJobStepList;
}

public static GwtJobStep convertJobStep(JobStep jobStep) {
GwtJobStep gwtJobStep = new GwtJobStep();

KapuaGwtCommonsModelConverter.convertUpdatableEntity(jobStep, gwtJobStep);

gwtJobStep.setJobStepName(jobStep.getName());
gwtJobStep.setDescription(jobStep.getDescription());
gwtJobStep.setJobId(KapuaGwtCommonsModelConverter.convertKapuaId(jobStep.getJobId()));
gwtJobStep.setJobStepDefinitionId(KapuaGwtCommonsModelConverter.convertKapuaId(jobStep.getJobStepDefinitionId()));
gwtJobStep.setStepIndex(jobStep.getStepIndex());
gwtJobStep.setStepProperties(convertJobStepProperties(jobStep.getStepProperties()));

return gwtJobStep;
}

private static List<GwtJobStepProperty> convertJobStepProperties(List<JobStepProperty> jobStepPropertyList) {
List<GwtJobStepProperty> gwtJobStepPropertyList = new ArrayList<GwtJobStepProperty>();

for (JobStepProperty jobStepProperty : jobStepPropertyList) {
GwtJobStepProperty gwtJobStepProperty = new GwtJobStepProperty();
gwtJobStepProperty.setPropertyName(jobStepProperty.getName());
gwtJobStepProperty.setPropertyType(jobStepProperty.getPropertyType());
gwtJobStepProperty.setPropertyValue(jobStepProperty.getPropertyValue());
gwtJobStepPropertyList.add(gwtJobStepProperty);
}

return gwtJobStepPropertyList;
}

public static GwtJobTarget convertJobTarget(JobTarget jobTarget) {
GwtJobTarget gwtJobTarget = new GwtJobTarget();

KapuaGwtCommonsModelConverter.convertUpdatableEntity(jobTarget, gwtJobTarget);

gwtJobTarget.setJobTargetId(KapuaGwtCommonsModelConverter.convertKapuaId(jobTarget.getJobTargetId()));
gwtJobTarget.setClientId(KapuaGwtCommonsModelConverter.convertKapuaId(jobTarget.getJobTargetId()));
gwtJobTarget.setStatus(jobTarget.getStatus().toString());
gwtJobTarget.setStepIndex(jobTarget.getStepIndex());
gwtJobTarget.setErrorMessage(jobTarget.getException() != null ? jobTarget.getException().getMessage() : null);
gwtJobTarget.setStatusMessage(jobTarget.getStatusMessage());

return gwtJobTarget;
}

public static GwtJobStepDefinition convertJobStepDefinition(JobStepDefinition jobStepDefinition) {
GwtJobStepDefinition gwtJobStepDefinition = new GwtJobStepDefinition();

KapuaGwtCommonsModelConverter.convertEntity(jobStepDefinition, gwtJobStepDefinition);

gwtJobStepDefinition.setJobStepDefinitionName(jobStepDefinition.getName());
gwtJobStepDefinition.setDescription(jobStepDefinition.getDescription());
gwtJobStepDefinition.setProcessorName(jobStepDefinition.getProcessorName());
gwtJobStepDefinition.setReaderName(jobStepDefinition.getReaderName());
gwtJobStepDefinition.setWriterName(jobStepDefinition.getWriterName());
gwtJobStepDefinition.setStepProperties(convertJobStepProperties(jobStepDefinition.getStepProperties()));
gwtJobStepDefinition.setStepType(jobStepDefinition.getStepType().name());

return gwtJobStepDefinition;
}

public static GwtTrigger convertTrigger(Trigger trigger) {
GwtTrigger gwtTrigger = new GwtTrigger();

KapuaGwtCommonsModelConverter.convertUpdatableEntity(trigger, gwtTrigger);

gwtTrigger.setTriggerName(trigger.getName());
gwtTrigger.setCronScheduling(trigger.getCronScheduling());
gwtTrigger.setStartsOn(trigger.getStartsOn());
gwtTrigger.setEndsOn(trigger.getEndsOn());
gwtTrigger.setRetryInterval(trigger.getRetryInterval());
gwtTrigger.setTriggerProperties(convertTriggerProperties(trigger.getTriggerProperties()));

return gwtTrigger;
}

private static List<GwtTriggerProperty> convertTriggerProperties(List<TriggerProperty> triggerPropertyList) {
List<GwtTriggerProperty> gwtTriggerPropertyList = new ArrayList<GwtTriggerProperty>();

for (TriggerProperty triggerProperty : triggerPropertyList) {
GwtTriggerProperty gwtTriggerProperty = new GwtTriggerProperty();
gwtTriggerProperty.setPropertyName(triggerProperty.getName());
gwtTriggerProperty.setPropertyType(triggerProperty.getPropertyType());
gwtTriggerProperty.setPropertyValue(triggerProperty.getPropertyValue());
gwtTriggerPropertyList.add(gwtTriggerProperty);
}

return gwtTriggerPropertyList;
}

@@ -24,7 +24,7 @@ gridJobTabSchedulesLabel=Schedules
gridJobTargetColumnHeaderJobId=Job Id
gridJobTargetColumnHeaderJobClientId=Client ID
gridJobTargetColumnHeaderStatus=Status
gridJobTargetColumnHeaderErrorMessage=Error Message
gridJobTargetColumnHeaderStatusMessage=Status Message
gridJobTargetColumnHeaderJobStepIndex=Step Index
gridJobTargetColumnHeaderDisplayName=Display Name
gridJobStepColumnHeaderStepIndex=Step Index
@@ -12,8 +12,9 @@
package org.eclipse.kapua.job.engine.commons.operation;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.job.engine.commons.context.JobContextWrapper;
import org.eclipse.kapua.job.engine.commons.context.StepContextWrapper;
import org.eclipse.kapua.job.engine.commons.wrappers.JobContextWrapper;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.job.engine.commons.wrappers.StepContextWrapper;
import org.eclipse.kapua.service.job.operation.TargetOperation;
import org.eclipse.kapua.service.job.targets.JobTarget;
import org.eclipse.kapua.service.job.targets.JobTargetStatus;
@@ -23,6 +24,14 @@
import javax.batch.runtime.context.JobContext;
import javax.batch.runtime.context.StepContext;

/**
* {@link TargetOperation} {@code abstract} implementation.
* <p>
* All {@link org.eclipse.kapua.service.job.step.definition.JobStepDefinition} must provide their own implementation of the {@link TargetOperation}
* containing the actual processing logic of the {@link JobTarget}
*
* @since 1.0.0
*/
public abstract class AbstractTargetProcessor implements TargetOperation {

private static final Logger LOG = LoggerFactory.getLogger(AbstractTargetProcessor.class);
@@ -32,9 +41,10 @@

@Override
public final Object processItem(Object item) throws Exception {
JobTarget jobTarget = (JobTarget) item;
LOG.info("Processing item: {}", jobTarget.getId());
JobTargetWrapper wrappedJobTarget = (JobTargetWrapper) item;

JobTarget jobTarget = wrappedJobTarget.getJobTarget();
LOG.info("Processing item: {}", wrappedJobTarget.getJobTarget().getId());
try {
processTarget(jobTarget);

@@ -44,10 +54,10 @@ public final Object processItem(Object item) throws Exception {
} catch (Exception e) {
LOG.info("Processing item: {} - Error!", jobTarget.getId(), e);
jobTarget.setStatus(JobTargetStatus.PROCESS_FAILED);
jobTarget.setException(e);
wrappedJobTarget.setProcessingException(e);
}

return jobTarget;
return wrappedJobTarget;
}

public abstract void processTarget(JobTarget jobTarget) throws KapuaException;
@@ -12,8 +12,9 @@
package org.eclipse.kapua.job.engine.commons.operation;

import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.context.JobContextWrapper;
import org.eclipse.kapua.job.engine.commons.context.StepContextWrapper;
import org.eclipse.kapua.job.engine.commons.wrappers.JobContextWrapper;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.job.engine.commons.wrappers.StepContextWrapper;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.query.KapuaQuery;
import org.eclipse.kapua.model.query.predicate.AndPredicate;
@@ -35,7 +36,16 @@
import javax.batch.runtime.context.StepContext;
import javax.inject.Inject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
* Default {@link TargetReader} implementation.
* <p>
* All {@link org.eclipse.kapua.service.job.step.definition.JobStepDefinition} can use this {@link TargetReader} implementation or extend or provide one on their own.
*
* @since 1.0.0
*/
public class DefaultTargetReader extends AbstractItemReader implements TargetReader {

private static final Logger LOG = LoggerFactory.getLogger(DefaultTargetReader.class);
@@ -51,7 +61,7 @@
@Inject
private StepContext stepContext;

protected JobTargetListResult jobTargets;
protected List<JobTargetWrapper> wrappedJobTargets = new ArrayList<>();
protected int jobTargetIndex;

@Override
@@ -80,7 +90,11 @@ public void open(Serializable arg0) throws Exception {
// Query the targets
query.setPredicate(andPredicate);

jobTargets = KapuaSecurityUtils.doPrivileged(() -> jobTargetService.query(query));
JobTargetListResult jobTargets = KapuaSecurityUtils.doPrivileged(() -> jobTargetService.query(query));

//
// Wrap the JobTargets in a wrapper object to store additional informations
jobTargets.getItems().forEach(jt -> wrappedJobTargets.add(new JobTargetWrapper(jt)));

LOG.info("JOB {} - Opening cursor... Done!", jobContextWrapper.getJobId());
}
@@ -90,13 +104,13 @@ public Object readItem() throws Exception {
JobContextWrapper jobContextWrapper = new JobContextWrapper(jobContext);
LOG.info("JOB {} - Reading item...", jobContextWrapper.getJobId());

JobTarget currentJobTarget = null;
if (jobTargetIndex < jobTargets.getSize()) {
currentJobTarget = jobTargets.getItem(jobTargetIndex++);
JobTargetWrapper currentWrappedJobTarget = null;
if (jobTargetIndex < wrappedJobTargets.size()) {
currentWrappedJobTarget = wrappedJobTargets.get(jobTargetIndex++);
}

LOG.info("JOB {} - Reading item... Done!", jobContextWrapper.getJobId());
return currentJobTarget;
return currentWrappedJobTarget;
}

/**
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -12,8 +12,9 @@
package org.eclipse.kapua.job.engine.commons.operation;

import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.context.JobContextWrapper;
import org.eclipse.kapua.job.engine.commons.context.StepContextWrapper;
import org.eclipse.kapua.job.engine.commons.wrappers.JobContextWrapper;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.job.engine.commons.wrappers.StepContextWrapper;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.service.job.operation.TargetWriter;
import org.eclipse.kapua.service.job.targets.JobTarget;
@@ -28,6 +29,13 @@
import javax.inject.Inject;
import java.util.List;

/**
* Default {@link TargetWriter} implementation.
* <p>
* All {@link org.eclipse.kapua.service.job.step.definition.JobStepDefinition} can use this {@link TargetWriter} implementation or extend or provide one on their own.
*
* @since 1.0.0
*/
public class DefaultTargetWriter extends AbstractItemWriter implements TargetWriter {

private static final Logger LOG = LoggerFactory.getLogger(DefaultTargetWriter.class);
@@ -49,13 +57,14 @@ public void writeItems(List<Object> items) throws Exception {
LOG.info("JOB {} - Writing items...", jobContextWrapper.getJobId());

for (Object item : items) {
JobTarget processedJobTarget = (JobTarget) item;
JobTargetWrapper processedWrappedJobTarget = (JobTargetWrapper) item;
JobTarget processedJobTarget = processedWrappedJobTarget.getJobTarget();

JobTarget jobTarget = KapuaSecurityUtils.doPrivileged(() -> JOB_TARGET_SERVICE.find(processedJobTarget.getScopeId(), processedJobTarget.getId()));

jobTarget.setStepIndex(stepContextWrapper.getStepIndex());
jobTarget.setStatus(processedJobTarget.getStatus());
jobTarget.setException(processedJobTarget.getException());
jobTarget.setStatusMessage(processedWrappedJobTarget.getProcessingException() != null ? processedWrappedJobTarget.getProcessingException().getMessage() : null);

if (JobTargetStatus.PROCESS_OK.equals(jobTarget.getStatus())) {

@@ -72,5 +81,4 @@ public void writeItems(List<Object> items) throws Exception {

LOG.info("JOB {} - Writing items... Done!", jobContextWrapper.getJobId());
}

}

0 comments on commit 2362a6f

Please sign in to comment.
You can’t perform that action at this time.