Skip to content

Commit

Permalink
feature: added required classes for job step on inventory-containers …
Browse files Browse the repository at this point in the history
…start and stop
  • Loading branch information
angelo.andreussi committed Feb 3, 2025
1 parent 171c17d commit 4a22159
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,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
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,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));
}
}

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));
}
}


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() {
}
}
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()
)
);
}
}
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()
)
);
}
}
1 change: 1 addition & 0 deletions service/device/management/inventory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<modules>
<module>api</module>
<module>internal</module>
<module>job</module>
</modules>

</project>

0 comments on commit 4a22159

Please sign in to comment.