Skip to content

Commit

Permalink
Merge pull request #3699 from MDeLuise/fix/better-job-log
Browse files Browse the repository at this point in the history
Job execution log reports `target name` and `target short uuid`
  • Loading branch information
Coduz authored Jan 30, 2023
2 parents ce885d9 + 7b97865 commit 1e7fd4c
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ INTERNAL_ERROR=An internal error occurred: {0}.
JOB_STEP_MISSING=The Job {0} in scope {1} does not have steps configured.
JOB_TARGET_MISSING=The Job {0} in scope {1} does not have targets configured.
JOB_TARGET_INVALID=The Job {0} in scope {1} cannot be started because at least one of the {2} Job Target is not a current Job Target.
JOB_ALREADY_RUNNING=The Job {0} in scope {1} cannot be started because it is already is already running.
JOB_ALREADY_RUNNING=The Job {0} in scope {1} cannot be started because it is already running.
JOB_STARTING=The Job {0} in scope {1} cannot be started.
JOB_RESUMING=The Job Execution {2} of Job {0} in scope {1} cannot be resumed.
JOB_RUNNING=The Job {0} in scope {1} is running and the operation cannot be performed.
Expand Down
4 changes: 4 additions & 0 deletions job-engine/commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-job-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-device-registry-api</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* 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.job.engine.commons.operation;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.service.device.registry.Device;
import org.eclipse.kapua.service.device.registry.DeviceRegistryService;
import org.eclipse.kapua.service.job.targets.JobTarget;

public abstract class AbstractDeviceTargetProcessor extends AbstractTargetProcessor {
protected static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
protected static final DeviceRegistryService DEVICE_REGISTRY_SERVICE = LOCATOR.getService(DeviceRegistryService.class);
@Override
protected String getTargetDisplayName(JobTarget jobTarget) throws KapuaException {
Device device = KapuaSecurityUtils.doPrivileged(() -> DEVICE_REGISTRY_SERVICE.find(jobTarget.getScopeId(), jobTarget.getJobTargetId()));;
if (device == null) {
return "N/A";
}
return device.getClientId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public final Object processItem(Object item) throws Exception {
jobLogger.setClassLog(LOG);

JobTarget jobTarget = wrappedJobTarget.getJobTarget();
jobLogger.info("Processing item: {}", wrappedJobTarget.getJobTarget().getId());
jobLogger.info("Processing target:{} (id:{})", getTargetDisplayName(jobTarget), jobTarget.getId().toCompactId());
try {
processTarget(jobTarget);

jobTarget.setStatus(getCompletedStatus(jobTarget));

jobLogger.info("Processing item: {} - DONE!", jobTarget.getId());
jobLogger.info("Processing target:{} (id:{}) - DONE!", getTargetDisplayName(jobTarget), jobTarget.getId().toCompactId());
} catch (Exception e) {
jobLogger.error(e, "Processing item: {} - Error!", jobTarget.getId());
jobLogger.error(e, "Processing target:{} (id:{}) - Error!", getTargetDisplayName(jobTarget), jobTarget.getId().toCompactId());

jobTarget.setStatus(getFailedStatus(jobTarget));
wrappedJobTarget.setProcessingException(e);
Expand All @@ -68,8 +68,10 @@ public final Object processItem(Object item) throws Exception {
return wrappedJobTarget;
}

protected abstract String getTargetDisplayName(JobTarget jobTarget) throws KapuaException;

/**
* Actions before {@link #processTarget(JobTarget)} invokation.
* Actions before {@link #processTarget(JobTarget)} invocation.
*
* @param wrappedJobTarget The current {@link JobTargetWrapper}
* @since 1.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.kapua.job.engine.commons.operation;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.logger.JobLogger;
import org.eclipse.kapua.job.engine.commons.wrappers.JobContextWrapper;
Expand All @@ -21,6 +22,8 @@
import org.eclipse.kapua.model.query.KapuaQuery;
import org.eclipse.kapua.model.query.predicate.AndPredicate;
import org.eclipse.kapua.model.query.predicate.AttributePredicate;
import org.eclipse.kapua.service.device.registry.Device;
import org.eclipse.kapua.service.device.registry.DeviceRegistryService;
import org.eclipse.kapua.service.job.operation.TargetReader;
import org.eclipse.kapua.service.job.step.JobStepIndex;
import org.eclipse.kapua.service.job.targets.JobTarget;
Expand Down Expand Up @@ -54,6 +57,8 @@ public class DefaultTargetReader extends AbstractItemReader implements TargetRea

private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();

private static final DeviceRegistryService DEVICE_REGISTRY_SERVICE = LOCATOR.getService(DeviceRegistryService.class);

private final JobTargetFactory jobTargetFactory = LOCATOR.getFactory(JobTargetFactory.class);
private final JobTargetService jobTargetService = LOCATOR.getService(JobTargetService.class);

Expand Down Expand Up @@ -112,15 +117,15 @@ public Object readItem() throws Exception {
JobLogger jobLogger = jobContextWrapper.getJobLogger();
jobLogger.setClassLog(LOG);

jobLogger.info("Reading item...");

JobTargetWrapper currentWrappedJobTarget = null;
if (jobTargetIndex < wrappedJobTargets.size()) {
currentWrappedJobTarget = wrappedJobTargets.get(jobTargetIndex++);
}

jobLogger.info("Reading item... DONE!");
return currentWrappedJobTarget;
return KapuaSecurityUtils.doPrivileged(() -> {
JobTargetWrapper currentWrappedJobTarget = null;
if (jobTargetIndex < wrappedJobTargets.size()) {
currentWrappedJobTarget = wrappedJobTargets.get(jobTargetIndex++);
JobTarget jobTarget = jobTargetService.find(jobContextWrapper.getScopeId(), currentWrappedJobTarget.getJobTarget().getId());
jobLogger.info("Read target: {} (id: {})", getTargetDisplayName(jobTarget), jobTarget.getId().toCompactId());
}
return currentWrappedJobTarget;
});
}

/**
Expand Down Expand Up @@ -169,4 +174,12 @@ protected void targetSublistFiltering(JobContextWrapper jobContextWrapper, Kapua
}
}

protected String getTargetDisplayName(JobTarget jobTarget) throws KapuaException {
Device device = KapuaSecurityUtils.doPrivileged(() -> DEVICE_REGISTRY_SERVICE.find(jobTarget.getScopeId(), jobTarget.getJobTargetId()));
if (device == null) {
return "N/A";
}
return device.getClientId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ components:
optlock: 2
endedOn: '2019-12-06T12:01:00+01:00'
jobId: {}
log: "[INFO] 12/6/19 11:00 AM - Running before job...\n[INFO] 12/6/19 11:00 AM - Run configuration:\n[INFO] 12/6/19 11:00 AM - \tTarget count: all\n[INFO] 12/6/19 11:00 AM - \tReset step index: false\n[INFO] 12/6/19 11:00 AM - \tFrom step index: 0\n[INFO] 12/6/19 11:00 AM - \tResuming job execution: none\n[INFO] 12/6/19 11:00 AM - \tEnqueue: false\n[INFO] 12/6/19 11:00 AM - Creating job execution...\n[INFO] 12/6/19 11:00 AM - Creating job execution... DONE!\n[INFO] 12/6/19 11:00 AM - Running before job... DONE!\n[INFO] 12/6/19 11:00 AM - Opening cursor...\n[INFO] 12/6/19 11:00 AM - Opening cursor... DONE!\n[INFO] 12/6/19 11:00 AM - Reading item...\n[INFO] 12/6/19 11:00 AM - Reading item... DONE!\n[INFO] 12/6/19 11:00 AM - Processing item: 7200086575903566335\n[INFO] 12/6/19 11:01 AM - Processing item: 7200086575903566335 - DONE!\n[INFO] 12/6/19 11:01 AM - Reading item...\n[INFO] 12/6/19 11:01 AM - Reading item... DONE!\n[INFO] 12/6/19 11:01 AM - Writing items...\n[INFO] 12/6/19 11:01 AM - Writing items... DONE!\n[INFO] 12/6/19 11:01 AM - Running after job...\n"
log: "[INFO] 12/6/19 11:00 AM - Running before job...\n[INFO] 12/6/19 11:00 AM - Run configuration:\n[INFO] 12/6/19 11:00 AM - \tTarget count: all\n[INFO] 12/6/19 11:00 AM - \tReset step index: false\n[INFO] 12/6/19 11:00 AM - \tFrom step index: 0\n[INFO] 12/6/19 11:00 AM - \tResuming job execution: none\n[INFO] 12/6/19 11:00 AM - \tEnqueue: false\n[INFO] 12/6/19 11:00 AM - Creating job execution...\n[INFO] 12/6/19 11:00 AM - Creating job execution... DONE!\n[INFO] 12/6/19 11:00 AM - Running before job... DONE!\n[INFO] 12/6/19 11:00 AM - Reading step: download package (index: 0)...\n[INFO] 12/6/19 11:00 AM - Reading step: download package (index: 0)... DONE!\n[INFO] 12/6/19 11:00 AM - RReading target: pahoClient (id: SbQbzB6oOOo)...\n[INFO] 12/6/19 11:00 AM - Reading target:pahoClient (id:SbQbzB6oOOo)... DONE!\n[INFO] 12/6/19 11:00 AM - Processing target: pahoClient (id: SbQbzB6oOOo)\n[INFO] 12/6/19 11:01 AM - Processing target: pahoClient (id: SbQbzB6oOOo) - DONE!\n[INFO] 12/6/19 11:01 AM - Reading target: client2 (id: A4QbzB6oZZo)...\n[INFO] 12/6/19 11:01 AM - Reading target: client2 (id: A4QbzB6oZZo)... DONE!\n[INFO] 12/6/19 11:01 AM - Writing target processing results...\n[INFO] 12/6/19 11:01 AM - Writing target processing results... DONE!\n[INFO] 12/6/19 11:01 AM - Running after job...\n"
startedOn: '2019-12-06T12:00:58+01:00'
targetIds:
- Y-vYl9TKaf8
Expand Down Expand Up @@ -66,7 +66,7 @@ components:
optlock: 2
endedOn: '2019-12-06T12:01:00+01:00'
jobId: {}
log: "[INFO] 12/6/19 11:00 AM - Running before job...\n[INFO] 12/6/19 11:00 AM - Run configuration:\n[INFO] 12/6/19 11:00 AM - \tTarget count: all\n[INFO] 12/6/19 11:00 AM - \tReset step index: false\n[INFO] 12/6/19 11:00 AM - \tFrom step index: 0\n[INFO] 12/6/19 11:00 AM - \tResuming job execution: none\n[INFO] 12/6/19 11:00 AM - \tEnqueue: false\n[INFO] 12/6/19 11:00 AM - Creating job execution...\n[INFO] 12/6/19 11:00 AM - Creating job execution... DONE!\n[INFO] 12/6/19 11:00 AM - Running before job... DONE!\n[INFO] 12/6/19 11:00 AM - Opening cursor...\n[INFO] 12/6/19 11:00 AM - Opening cursor... DONE!\n[INFO] 12/6/19 11:00 AM - Reading item...\n[INFO] 12/6/19 11:00 AM - Reading item... DONE!\n[INFO] 12/6/19 11:00 AM - Processing item: 7200086575903566335\n[INFO] 12/6/19 11:01 AM - Processing item: 7200086575903566335 - DONE!\n[INFO] 12/6/19 11:01 AM - Reading item...\n[INFO] 12/6/19 11:01 AM - Reading item... DONE!\n[INFO] 12/6/19 11:01 AM - Writing items...\n[INFO] 12/6/19 11:01 AM - Writing items... DONE!\n[INFO] 12/6/19 11:01 AM - Running after job...\n"
log: "[INFO] 12/6/19 11:00 AM - Running before job...\n[INFO] 12/6/19 11:00 AM - Run configuration:\n[INFO] 12/6/19 11:00 AM - \tTarget count: all\n[INFO] 12/6/19 11:00 AM - \tReset step index: false\n[INFO] 12/6/19 11:00 AM - \tFrom step index: 0\n[INFO] 12/6/19 11:00 AM - \tResuming job execution: none\n[INFO] 12/6/19 11:00 AM - \tEnqueue: false\n[INFO] 12/6/19 11:00 AM - Creating job execution...\n[INFO] 12/6/19 11:00 AM - Creating job execution... DONE!\n[INFO] 12/6/19 11:00 AM - Running before job... DONE!\n[INFO] 12/6/19 11:00 AM - Reading step: download package (index: 0)...\n[INFO] 12/6/19 11:00 AM - Reading step: download package (index: 0)... DONE!\n[INFO] 12/6/19 11:00 AM - RReading target: pahoClient (id: SbQbzB6oOOo)...\n[INFO] 12/6/19 11:00 AM - Reading target:pahoClient (id:SbQbzB6oOOo)... DONE!\n[INFO] 12/6/19 11:00 AM - Processing target: pahoClient (id: SbQbzB6oOOo)\n[INFO] 12/6/19 11:01 AM - Processing target: pahoClient (id: SbQbzB6oOOo) - DONE!\n[INFO] 12/6/19 11:01 AM - Reading target: client2 (id: A4QbzB6oZZo)...\n[INFO] 12/6/19 11:01 AM - Reading target: client2 (id: A4QbzB6oZZo)... DONE!\n[INFO] 12/6/19 11:01 AM - Writing target processing results...\n[INFO] 12/6/19 11:01 AM - Writing target processing results... DONE!\n[INFO] 12/6/19 11:01 AM - Running after job...\n"
startedOn: '2019-12-06T12:00:58+01:00'
targetIds:
- Y-vYl9TKaf8
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.operation.AbstractTargetProcessor;
import org.eclipse.kapua.job.engine.commons.operation.AbstractDeviceTargetProcessor;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.device.management.asset.DeviceAssetManagementService;
import org.eclipse.kapua.service.device.management.asset.DeviceAssets;
Expand All @@ -33,9 +32,7 @@
*
* @since 1.0.0
*/
public class DeviceAssetWriteTargetProcessor extends AbstractTargetProcessor implements TargetProcessor {

private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
public class DeviceAssetWriteTargetProcessor extends AbstractDeviceTargetProcessor implements TargetProcessor {
private static final DeviceAssetManagementService ASSET_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceAssetManagementService.class);

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.operation.AbstractTargetProcessor;
import org.eclipse.kapua.job.engine.commons.operation.AbstractDeviceTargetProcessor;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.id.KapuaId;
Expand All @@ -32,8 +32,7 @@
*
* @since 1.0.0
*/
public class DeviceBundleStartTargetProcessor extends AbstractTargetProcessor implements TargetProcessor {

public class DeviceBundleStartTargetProcessor extends AbstractDeviceTargetProcessor implements TargetProcessor {
private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
private static final DeviceBundleManagementService BUNDLE_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceBundleManagementService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.operation.AbstractTargetProcessor;
import org.eclipse.kapua.job.engine.commons.operation.AbstractDeviceTargetProcessor;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.device.management.bundle.DeviceBundleManagementService;
import org.eclipse.kapua.service.device.management.bundle.job.definition.DeviceBundlePropertyKeys;
Expand All @@ -32,9 +31,7 @@
*
* @since 1.0.0
*/
public class DeviceBundleStopTargetProcessor extends AbstractTargetProcessor implements TargetProcessor {

private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
public class DeviceBundleStopTargetProcessor extends AbstractDeviceTargetProcessor implements TargetProcessor {
private static final DeviceBundleManagementService BUNDLE_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceBundleManagementService.class);

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.operation.AbstractTargetProcessor;
import org.eclipse.kapua.job.engine.commons.operation.AbstractDeviceTargetProcessor;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.device.management.command.DeviceCommandInput;
import org.eclipse.kapua.service.device.management.command.DeviceCommandManagementService;
Expand All @@ -33,9 +32,7 @@
*
* @since 1.0.0
*/
public class DeviceCommandExecTargetProcessor extends AbstractTargetProcessor implements TargetProcessor {

private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
public class DeviceCommandExecTargetProcessor extends AbstractDeviceTargetProcessor implements TargetProcessor {
private static final DeviceCommandManagementService COMMAND_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceCommandManagementService.class);

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.operation.AbstractTargetProcessor;
import org.eclipse.kapua.job.engine.commons.operation.AbstractDeviceTargetProcessor;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration;
import org.eclipse.kapua.service.device.management.configuration.DeviceConfigurationManagementService;
Expand All @@ -33,9 +32,7 @@
*
* @since 1.0.0
*/
public class DeviceConfigurationPutTargetProcessor extends AbstractTargetProcessor implements TargetProcessor {

private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
public class DeviceConfigurationPutTargetProcessor extends AbstractDeviceTargetProcessor implements TargetProcessor {
private static final DeviceConfigurationManagementService CONFIGURATION_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceConfigurationManagementService.class);

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.operation.AbstractTargetProcessor;
import org.eclipse.kapua.job.engine.commons.operation.AbstractDeviceTargetProcessor;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.id.KapuaId;
import org.eclipse.kapua.service.device.management.keystore.DeviceKeystoreManagementFactory;
import org.eclipse.kapua.service.device.management.keystore.DeviceKeystoreManagementService;
Expand All @@ -34,9 +33,7 @@
*
* @since 1.0.0
*/
public class DeviceKeystoreCertificateCreateTargetProcessor extends AbstractTargetProcessor implements TargetProcessor {

private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
public class DeviceKeystoreCertificateCreateTargetProcessor extends AbstractDeviceTargetProcessor implements TargetProcessor {
private static final DeviceKeystoreManagementService KEYSTORE_MANAGEMENT_SERVICE = LOCATOR.getService(DeviceKeystoreManagementService.class);
private static final DeviceKeystoreManagementFactory KEYSTORE_MANAGEMENT_FACTORY = LOCATOR.getFactory(DeviceKeystoreManagementFactory.class);

Expand Down
Loading

0 comments on commit 1e7fd4c

Please sign in to comment.