-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4186 from Agnul97/feature-job_step_inventory_cont…
…ainers ✨ [Job] Added new job-step to start/stop inventory-v1 containers on Kura side
- Loading branch information
Showing
13 changed files
with
445 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...ation/src/test/resources/features/jobEngine/JobEngineServiceProcessorInventoryI9n.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
37 changes: 37 additions & 0 deletions
37
...a/org/eclipse/kapua/service/device/management/inventory/job/DeviceContainerJobModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
...se/kapua/service/device/management/inventory/job/DeviceContainerStartTargetProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
|
64 changes: 64 additions & 0 deletions
64
...pse/kapua/service/device/management/inventory/job/DeviceContainerStopTargetProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
|
||
|
25 changes: 25 additions & 0 deletions
25
...kapua/service/device/management/inventory/job/definition/DeviceContainerPropertyKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
Oops, something went wrong.