Skip to content

Package: DevicePackageUninstallTargetProcessor

DevicePackageUninstallTargetProcessor

nameinstructionbranchcomplexitylinemethod
DevicePackageUninstallTargetProcessor()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getCompletedStatus(JobTarget)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
initProcessing(JobTargetWrapper)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
lambda$processTarget$0(KapuaId, JobTarget, DevicePackageUninstallRequest, DevicePackageUninstallOptions)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
processTarget(JobTarget)
M: 41 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2020 Eurotech and/or its affiliates and others
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Eurotech - initial API and implementation
11: *******************************************************************************/
12: package org.eclipse.kapua.service.device.management.packages.job;
13:
14: import org.eclipse.kapua.KapuaException;
15: import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
16: import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
17: import org.eclipse.kapua.locator.KapuaLocator;
18: import org.eclipse.kapua.model.id.KapuaId;
19: import org.eclipse.kapua.service.device.management.packages.DevicePackageFactory;
20: import org.eclipse.kapua.service.device.management.packages.DevicePackageManagementService;
21: import org.eclipse.kapua.service.device.management.packages.job.definition.DevicePackageUninstallPropertyKeys;
22: import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallOptions;
23: import org.eclipse.kapua.service.device.management.packages.model.uninstall.DevicePackageUninstallRequest;
24: import org.eclipse.kapua.service.job.operation.TargetProcessor;
25: import org.eclipse.kapua.service.job.targets.JobTarget;
26: import org.eclipse.kapua.service.job.targets.JobTargetStatus;
27:
28: import javax.batch.runtime.context.JobContext;
29: import javax.batch.runtime.context.StepContext;
30: import javax.inject.Inject;
31:
32: /**
33: * {@link TargetProcessor} for {@link DevicePackageManagementService#uninstallExec(KapuaId, KapuaId, DevicePackageUninstallRequest, Long)}.
34: *
35: * @since 1.0.0
36: */
37: public class DevicePackageUninstallTargetProcessor extends AbstractDevicePackageTargetProcessor implements TargetProcessor {
38:
39: private static final KapuaLocator LOCATOR = KapuaLocator.getInstance();
40:
41: private static final DevicePackageManagementService PACKAGES_MANAGEMENT_SERVICE = LOCATOR.getService(DevicePackageManagementService.class);
42: private static final DevicePackageFactory DEVICE_PACKAGE_FACTORY = LOCATOR.getFactory(DevicePackageFactory.class);
43:
44: @Inject
45: JobContext jobContext;
46:
47: @Inject
48: StepContext stepContext;
49:
50: @Override
51: protected void initProcessing(JobTargetWrapper wrappedJobTarget) {
52: setContext(jobContext, stepContext);
53: }
54:
55: @Override
56: public void processTarget(JobTarget jobTarget) throws KapuaException {
57:
58: KapuaId scopeId = jobTarget.getScopeId();
59: KapuaId jobId = jobTarget.getJobId();
60:
61: //
62: // Extract parameters from context
63: DevicePackageUninstallRequest packageUninstallRequest = stepContextWrapper.getStepProperty(DevicePackageUninstallPropertyKeys.PACKAGE_UNINSTALL_REQUEST, DevicePackageUninstallRequest.class);
64: Long timeout = stepContextWrapper.getStepProperty(DevicePackageUninstallPropertyKeys.TIMEOUT, Long.class);
65:
66: //
67: // Send the request
68: DevicePackageUninstallOptions packageUninstallOptions = DEVICE_PACKAGE_FACTORY.newDevicePackageUninstallOptions();
69: packageUninstallOptions.setTimeout(timeout);
70:
71: KapuaId operationId = KapuaSecurityUtils.doPrivileged(() -> PACKAGES_MANAGEMENT_SERVICE.uninstallExec(scopeId, jobTarget.getJobTargetId(), packageUninstallRequest, packageUninstallOptions));
72:
73: //
74: // Save the jobId-deviceManagementOperationId pair to track resuming
75: createJobDeviceManagementOperation(scopeId, jobId, jobTarget, operationId);
76: }
77:
78: @Override
79: protected JobTargetStatus getCompletedStatus(JobTarget jobTarget) {
80:
81:• if (JobTargetStatus.PROCESS_AWAITING.equals(jobTarget.getStatus())) {
82: return JobTargetStatus.AWAITING_COMPLETION;
83: }
84:
85: return super.getCompletedStatus(jobTarget);
86: }
87: }