Skip to content

Commit

Permalink
Merge pull request #4186 from Agnul97/feature-job_step_inventory_cont…
Browse files Browse the repository at this point in the history
…ainers

✨ [Job] Added new job-step to start/stop inventory-v1 containers on Kura side
  • Loading branch information
Coduz authored Feb 26, 2025
2 parents 9e83a3d + 9502b40 commit dfbe735
Show file tree
Hide file tree
Showing 13 changed files with 445 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,11 @@
<artifactId>kapua-device-management-command-job</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-device-management-inventory-job</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-device-management-configuration-api</artifactId>
Expand Down
6 changes: 1 addition & 5 deletions qa/common/src/main/resources/sql/all_delete.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ FROM job_job_step;

DELETE
FROM job_job_step_definition
WHERE id NOT IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

DELETE
FROM job_job_step_definition_properties
WHERE step_definition_id NOT IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
WHERE name NOT IN ('Asset Write','Bundle Start','Bundle Stop','Command Execution','Configuration Put','Keystore Certificate Create','Keystore Keypair Create','Keystore Item Delete','Package Download / Install','Package Uninstall','Container Start','Container Stop');

DELETE
FROM job_job_step_properties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"classpath:features/jobEngine/JobEngineServiceProcessorConfigurationI9n.feature",
"classpath:features/jobEngine/JobEngineServiceProcessorKeystoreI9n.feature",
"classpath:features/jobEngine/JobEngineServiceProcessorPackagesI9n.feature",
"classpath:features/jobEngine/JobEngineServiceProcessorInventoryI9n.feature"
},
glue = {
"org.eclipse.kapua.service.job.steps",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
###############################################################################
# Copyright (c) 2024, 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
###############################################################################
@env_docker
@it
@jobEngine
@jobEngineTargetProcessors

Feature: Job Engine Service - Inventory Step Processors
Tests for Device Management Inventory Processor

@setup
Scenario: Setup test resources
Given Init Security Context
And Start Docker environment with resources
| db |
| events-broker |
| job-engine |
| message-broker |
| broker-auth-service |
| consumer-lifecycle |

Scenario: Container Start

Given I login as user with name "kapua-sys" and password "kapua-password"
And I start the Kura Mock
And Device birth message is sent
And Device "rpione3" is connected within 10s
And I create a job with the name "TestJob"
And I add device targets to job
| rpione3 |
And I search for step definition with the name
| Container Start |
And I add job step to job with name "Test Step - Container Start" and with selected job step definition and properties
| name | type | value |
| containerName | java.lang.String | db |
| containerVersion | java.lang.String | kapua/kapua-sql:latest |
| timeout | java.lang.Long | 5000 |
When I start a job
And I wait job to finish its execution up to 10s
Then I confirm that job has 1 job execution
And I confirm that job target in job has step index 0 and status "PROCESS_OK"

Scenario: Container Stop

Given I login as user with name "kapua-sys" and password "kapua-password"
And I start the Kura Mock
And Device birth message is sent
And Device "rpione3" is connected within 10s
And I create a job with the name "TestJob"
And I add device targets to job
| rpione3 |
And I search for step definition with the name
| Container Stop |
And I add job step to job with name "Test Step - Container Stop" and with selected job step definition and properties
| name | type | value |
| containerName | java.lang.String | db |
| containerVersion | java.lang.String | kapua/kapua-sql:latest |
| timeout | java.lang.Long | 5000 |
When I start a job
And I wait job to finish its execution up to 10s
Then I confirm that job has 1 job execution
And I confirm that job target in job has step index 0 and status "PROCESS_OK"

@teardown
Scenario: Tear down test resources
Given I logout
And KuraMock is disconnected
And Stop Docker environment
And Clean Locator Instance
4 changes: 4 additions & 0 deletions service/device/management/all/job/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-device-management-packages-job</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-device-management-inventory-job</artifactId>
</dependency>
</dependencies>

</project>
40 changes: 40 additions & 0 deletions service/device/management/inventory/job/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, 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
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-device-management-inventory</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>

<artifactId>kapua-device-management-inventory-job</artifactId>
<dependencies>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-job-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-device-management-inventory-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.kapua</groupId>
<artifactId>kapua-job-engine-commons</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2024, 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.service.device.management.inventory.job;

import com.google.inject.multibindings.ProvidesIntoSet;
import org.eclipse.kapua.commons.core.AbstractKapuaModule;
import org.eclipse.kapua.service.device.management.inventory.job.definition.DeviceContainerStartJobStepDefinition;
import org.eclipse.kapua.service.device.management.inventory.job.definition.DeviceContainerStopJobStepDefinition;
import org.eclipse.kapua.service.job.step.definition.JobStepDefinition;

public class DeviceContainerJobModule extends AbstractKapuaModule {

@Override
protected void configureModule() {
}

@ProvidesIntoSet
public JobStepDefinition deviceContainerStartJobStepDefinition() {
return new DeviceContainerStartJobStepDefinition();
}

@ProvidesIntoSet
public JobStepDefinition deviceContainerStopJobStepDefinition() {
return new DeviceContainerStopJobStepDefinition();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2017, 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.service.device.management.inventory.job;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.operation.AbstractDeviceTargetProcessor;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.service.device.management.inventory.DeviceInventoryManagementFactory;
import org.eclipse.kapua.service.device.management.inventory.DeviceInventoryManagementService;
import org.eclipse.kapua.service.device.management.inventory.job.definition.DeviceContainerPropertyKeys;
import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainer;
import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainerAction;
import org.eclipse.kapua.service.job.operation.TargetProcessor;
import org.eclipse.kapua.service.job.targets.JobTarget;

import javax.batch.runtime.context.JobContext;
import javax.batch.runtime.context.StepContext;
import javax.inject.Inject;

public class DeviceContainerStartTargetProcessor extends AbstractDeviceTargetProcessor implements TargetProcessor {

@Inject
DeviceInventoryManagementService deviceInventoryManagementService;

@Inject
DeviceInventoryManagementFactory deviceInventoryManagementFactory;
@Inject
JobContext jobContext;
@Inject
StepContext stepContext;

@Override
protected void initProcessing(JobTargetWrapper wrappedJobTarget) {
setContext(jobContext, stepContext);
}

@Override
public void processTarget(JobTarget jobTarget) throws KapuaException {

String containerName = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.CONTAINER_NAME, String.class);
String containerVersion = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.CONTAINER_VERSION, String.class);
Long timeout = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.TIMEOUT, Long.class);

DeviceInventoryContainer containerInput = deviceInventoryManagementFactory.newDeviceInventoryContainer();
containerInput.setName(containerName);
containerInput.setVersion(containerVersion);

KapuaSecurityUtils.doPrivileged(() -> deviceInventoryManagementService.execContainer(jobTarget.getScopeId(), jobTarget.getJobTargetId(), containerInput, DeviceInventoryContainerAction.START, timeout));
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2017, 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.service.device.management.inventory.job;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.job.engine.commons.operation.AbstractDeviceTargetProcessor;
import org.eclipse.kapua.job.engine.commons.wrappers.JobTargetWrapper;
import org.eclipse.kapua.service.device.management.inventory.DeviceInventoryManagementFactory;
import org.eclipse.kapua.service.device.management.inventory.DeviceInventoryManagementService;
import org.eclipse.kapua.service.device.management.inventory.job.definition.DeviceContainerPropertyKeys;
import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainer;
import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainerAction;
import org.eclipse.kapua.service.job.operation.TargetProcessor;
import org.eclipse.kapua.service.job.targets.JobTarget;

import javax.batch.runtime.context.JobContext;
import javax.batch.runtime.context.StepContext;
import javax.inject.Inject;

public class DeviceContainerStopTargetProcessor extends AbstractDeviceTargetProcessor implements TargetProcessor {

@Inject
DeviceInventoryManagementService deviceInventoryManagementService;

@Inject
DeviceInventoryManagementFactory deviceInventoryManagementFactory;

@Inject
JobContext jobContext;
@Inject
StepContext stepContext;

@Override
protected void initProcessing(JobTargetWrapper wrappedJobTarget) {
setContext(jobContext, stepContext);
}

@Override
public void processTarget(JobTarget jobTarget) throws KapuaException {

String containerName = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.CONTAINER_NAME, String.class);
String containerVersion = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.CONTAINER_VERSION, String.class);
Long timeout = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.TIMEOUT, Long.class);

DeviceInventoryContainer containerInput = deviceInventoryManagementFactory.newDeviceInventoryContainer();
containerInput.setName(containerName);
containerInput.setVersion(containerVersion);

KapuaSecurityUtils.doPrivileged(() -> deviceInventoryManagementService.execContainer(jobTarget.getScopeId(), jobTarget.getJobTargetId(), containerInput, DeviceInventoryContainerAction.STOP, timeout));
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2017, 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.service.device.management.inventory.job.definition;

import org.eclipse.kapua.service.job.step.definition.JobPropertyKey;

public class DeviceContainerPropertyKeys implements JobPropertyKey {

public static final String CONTAINER_NAME = "containerName";
public static final String CONTAINER_VERSION = "containerVersion";
public static final String TIMEOUT = "timeout";

private DeviceContainerPropertyKeys() {
}
}
Loading

0 comments on commit dfbe735

Please sign in to comment.