Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [Job] Added new job-step to start/stop inventory-v1 containers on Kura side #4186

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* 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.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_NAME,
"Name of the container to be executed",
String.class.getName(),
null,
null,
Boolean.TRUE,
Boolean.FALSE,
null,
null,
null,
null,
null),
new JobStepPropertyRecord(
DeviceContainerPropertyKeys.CONTAINER_VERSION,
"Version of the container to be executed",
String.class.getName(),
null,
null,
Boolean.TRUE,
Boolean.FALSE,
null,
null,
null,
null,
null),
new TimeoutJobStepPropertyRecord()
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* 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.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_NAME,
"Name of the container to be executed",
String.class.getName(),
null,
null,
Boolean.TRUE,
Boolean.FALSE,
null,
null,
null,
null,
null),
new JobStepPropertyRecord(
DeviceContainerPropertyKeys.CONTAINER_VERSION,
"Version of the container to be executed",
String.class.getName(),
null,
null,
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>
Loading