-
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.
feature: added required classes for job step on inventory-containers …
…start and stop
- Loading branch information
angelo.andreussi
committed
Feb 3, 2025
1 parent
171c17d
commit 4a22159
Showing
10 changed files
with
330 additions
and
0 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
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(); | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
...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,53 @@ | ||
/******************************************************************************* | ||
* 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.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 | ||
JobContext jobContext; | ||
@Inject | ||
StepContext stepContext; | ||
|
||
@Override | ||
protected void initProcessing(JobTargetWrapper wrappedJobTarget) { | ||
setContext(jobContext, stepContext); | ||
} | ||
|
||
@Override | ||
public void processTarget(JobTarget jobTarget) throws KapuaException { | ||
|
||
DeviceInventoryContainer containerInput = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.CONTAINER_INPUT, DeviceInventoryContainer.class); | ||
Long timeout = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.TIMEOUT, Long.class); | ||
|
||
KapuaSecurityUtils.doPrivileged(() -> deviceInventoryManagementService.execContainer(jobTarget.getScopeId(), jobTarget.getJobTargetId(), containerInput, DeviceInventoryContainerAction.START, timeout)); | ||
} | ||
} | ||
|
54 changes: 54 additions & 0 deletions
54
...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,54 @@ | ||
/******************************************************************************* | ||
* 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.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 | ||
JobContext jobContext; | ||
@Inject | ||
StepContext stepContext; | ||
|
||
@Override | ||
protected void initProcessing(JobTargetWrapper wrappedJobTarget) { | ||
setContext(jobContext, stepContext); | ||
} | ||
|
||
@Override | ||
public void processTarget(JobTarget jobTarget) throws KapuaException { | ||
|
||
DeviceInventoryContainer containerInput = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.CONTAINER_INPUT, DeviceInventoryContainer.class); | ||
Long timeout = stepContextWrapper.getStepProperty(DeviceContainerPropertyKeys.TIMEOUT, Long.class); | ||
|
||
KapuaSecurityUtils.doPrivileged(() -> deviceInventoryManagementService.execContainer(jobTarget.getScopeId(), jobTarget.getJobTargetId(), containerInput, DeviceInventoryContainerAction.STOP, timeout)); | ||
} | ||
} | ||
|
||
|
24 changes: 24 additions & 0 deletions
24
...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,24 @@ | ||
/******************************************************************************* | ||
* 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_INPUT = "containerInput"; | ||
public static final String TIMEOUT = "timeout"; | ||
|
||
private DeviceContainerPropertyKeys() { | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...ice/device/management/inventory/job/definition/DeviceContainerStartJobStepDefinition.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,56 @@ | ||
/******************************************************************************* | ||
* 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 com.beust.jcommander.internal.Lists; | ||
import org.eclipse.kapua.service.device.management.inventory.job.DeviceContainerStartTargetProcessor; | ||
import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainer; | ||
import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionRecord; | ||
import org.eclipse.kapua.service.job.step.definition.JobStepPropertyRecord; | ||
import org.eclipse.kapua.service.job.step.definition.JobStepType; | ||
import org.eclipse.kapua.service.job.step.definition.device.management.TimeoutJobStepPropertyRecord; | ||
|
||
public class DeviceContainerStartJobStepDefinition extends JobStepDefinitionRecord { | ||
|
||
public DeviceContainerStartJobStepDefinition() { | ||
super(null, | ||
"Container Start", | ||
"Execute request to start a container to the target devices of the Job", | ||
JobStepType.TARGET, | ||
null, | ||
DeviceContainerStartTargetProcessor.class.getName(), | ||
null, | ||
Lists.newArrayList( | ||
new JobStepPropertyRecord( | ||
DeviceContainerPropertyKeys.CONTAINER_INPUT, | ||
"XML/JSON that defines the container to be executed", | ||
DeviceInventoryContainer.class.getName(), | ||
null, | ||
"{\n" + | ||
" \"name\": \"docker_container_1\",\n" + | ||
" \"version\": \"nginx:latest\",\n" + | ||
" \"containerType\": \"DOCKER\",\n" + | ||
" \"state\": \"ACTIVE\"\n" + | ||
"}", | ||
Boolean.TRUE, | ||
Boolean.FALSE, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null), | ||
new TimeoutJobStepPropertyRecord() | ||
) | ||
); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...vice/device/management/inventory/job/definition/DeviceContainerStopJobStepDefinition.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,56 @@ | ||
/******************************************************************************* | ||
* 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.definition; | ||
|
||
import com.beust.jcommander.internal.Lists; | ||
import org.eclipse.kapua.service.device.management.inventory.job.DeviceContainerStopTargetProcessor; | ||
import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainer; | ||
import org.eclipse.kapua.service.job.step.definition.JobStepDefinitionRecord; | ||
import org.eclipse.kapua.service.job.step.definition.JobStepPropertyRecord; | ||
import org.eclipse.kapua.service.job.step.definition.JobStepType; | ||
import org.eclipse.kapua.service.job.step.definition.device.management.TimeoutJobStepPropertyRecord; | ||
|
||
public class DeviceContainerStopJobStepDefinition extends JobStepDefinitionRecord { | ||
|
||
public DeviceContainerStopJobStepDefinition() { | ||
super(null, | ||
"Container Stop", | ||
"Execute request to stop a container to the target devices of the Job", | ||
JobStepType.TARGET, | ||
null, | ||
DeviceContainerStopTargetProcessor.class.getName(), | ||
null, | ||
Lists.newArrayList( | ||
new JobStepPropertyRecord( | ||
DeviceContainerPropertyKeys.CONTAINER_INPUT, | ||
"XML/JSON that defines the container to be stopped", | ||
DeviceInventoryContainer.class.getName(), | ||
null, | ||
"{\n" + | ||
" \"name\": \"docker_container_1\",\n" + | ||
" \"version\": \"nginx:latest\",\n" + | ||
" \"containerType\": \"DOCKER\",\n" + | ||
" \"state\": \"ACTIVE\"\n" + | ||
"}", | ||
Boolean.TRUE, | ||
Boolean.FALSE, | ||
null, | ||
null, | ||
null, | ||
null, | ||
null), | ||
new TimeoutJobStepPropertyRecord() | ||
) | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
<modules> | ||
<module>api</module> | ||
<module>internal</module> | ||
<module>job</module> | ||
</modules> | ||
|
||
</project> |