Skip to content

Commit

Permalink
Merge pull request #3925 from Coduz/feat-deviceInventoryContainer
Browse files Browse the repository at this point in the history
feat(deviceManagement): mapped missing `DeviceInventoryContainer.state` property
  • Loading branch information
Coduz authored Dec 21, 2023
2 parents 09d0dd2 + 1fbb07b commit d1416e4
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ protected void onRender(Element parent, int index) {
column.setWidth(80);
configs.add(column);

column = new ColumnConfig();
column.setId("state");
column.setHeader("State");
column.setWidth(80);
configs.add(column);

ColumnModel columnModel = new ColumnModel(configs);

RpcProxy<ListLoadResult<GwtInventoryContainer>> proxy = new RpcProxy<ListLoadResult<GwtInventoryContainer>>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.kapua.service.device.management.inventory.model.bundle.DeviceInventoryBundles;
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.device.management.inventory.model.container.DeviceInventoryContainerState;
import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainers;
import org.eclipse.kapua.service.device.management.inventory.model.inventory.DeviceInventory;
import org.eclipse.kapua.service.device.management.inventory.model.inventory.DeviceInventoryItem;
Expand Down Expand Up @@ -154,6 +155,7 @@ public ListLoadResult<GwtInventoryContainer> findDeviceContainers(String scopeId
gwtInventoryContainer.setName(inventoryContainer.getName());
gwtInventoryContainer.setVersion(inventoryContainer.getVersion());
gwtInventoryContainer.setType(inventoryContainer.getContainerType());
gwtInventoryContainer.setState(inventoryContainer.getState().name());

gwtInventoryContainers.add(gwtInventoryContainer);
}
Expand All @@ -176,6 +178,7 @@ public void execDeviceContainer(GwtXSRFToken xsrfToken, String scopeIdString, St
deviceInventoryContainer.setName(gwtInventoryContainer.getName());
deviceInventoryContainer.setVersion(gwtInventoryContainer.getVersion());
deviceInventoryContainer.setContainerType(gwtInventoryContainer.getType());
deviceInventoryContainer.setState(DeviceInventoryContainerState.valueOf(gwtInventoryContainer.getState()));

DEVICE_INVENTORY_MANAGEMENT_SERVICE.execContainer(
scopeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@

public class GwtInventoryContainer extends KapuaBaseModel {

public enum GwtInventoryContainerState {
UNKNOWN,
INSTALLED,
UNINSTALLED,
ACTIVE
}

@Override
public <X> X get(String property) {
if ("stateEnum".equals(property)) {
return (X) (GwtInventoryContainer.GwtInventoryContainerState.valueOf(getState()));
} else {
return super.get(property);
}
}

private static final long serialVersionUID = -4434969168565872354L;

public void setName(String name) {
Expand All @@ -41,4 +57,17 @@ public void setType(String type) {
public String getType() {
return get("type");
}

public String getState() {
return get("state");
}

public GwtInventoryContainerState getStateEnum() {
return get("stateEnum");
}

public void setState(String state) {
set("state", state);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,62 @@
{
"name": "consumer-telemetry",
"version": "kapua/kapua-consumer-telemetry:latest",
"type": "DOCKER"
"type": "DOCKER",
"state": "ACTIVE"
},
{
"name": "job-engine",
"version": "kapua/kapua-job-engine:latest",
"type": "DOCKER"
"type": "DOCKER",
"state": "ACTIVE"
},
{
"name": "kapua-console",
"version": "kapua/kapua-console:latest",
"type": "DOCKER"
"type": "DOCKER",
"state": "ACTIVE"
},
{
"name": "kapua-api",
"version": "kapua/kapua-api:latest",
"type": "DOCKER"
"type": "DOCKER",
"state": "ACTIVE"
},
{
"name": "message-broker",
"version": "kapua/kapua-broker:latest",
"type": "DOCKER"
"type": "DOCKER",
"state": "ACTIVE"
},
{
"name": "es",
"version": "docker.elastic.co/elasticsearch/elasticsearch:7.8.1",
"type": "DOCKER"
"type": "DOCKER",
"state": "ACTIVE"
},
{
"name": "db",
"version": "kapua/kapua-sql:latest",
"type": "DOCKER"
"type": "DOCKER",
"state": "ACTIVE"
},
{
"name": "events-broker",
"version": "kapua/kapua-events-broker:latest",
"type": "DOCKER"
"type": "DOCKER",
"state": "UNKNOWN"
},
{
"name": "clever_heisenberg",
"version": "kura_alpine:",
"type": "DOCKER"
"type": "DOCKER",
"state": "UNINSTALLED"
},
{
"name": "kura",
"version": "eclipse/kura:latest",
"type": "DOCKER"
"type": "DOCKER",
"state": "INSTALLED"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ info:
name: Eclipse Public License 2.0
url: https://www.eclipse.org/legal/epl-2.0

paths: { }
paths: {}

components:
schemas:
Expand Down Expand Up @@ -81,6 +81,13 @@ components:
name: org.eclipse.equinox.cm
version: 1.4.400.v20200422-1833
status: RESOLVED
deviceInventoryContainerState:
type: string
enum:
- ACTIVE
- INSTALLED
- UNINSTALLED
- UNKNOWN
deviceInventoryContainer:
type: object
properties:
Expand All @@ -90,10 +97,13 @@ components:
type: string
containerType:
type: string
state:
$ref: '#/components/schemas/deviceInventoryContainerState'
example:
name: docker_container_1
version: nginx:latest
containerType: DOCKER
state: ACTIVE
deviceInventoryContainers:
type: object
properties:
Expand All @@ -107,9 +117,11 @@ components:
- name: docker_container_1
version: nginx:latest
containerType: DOCKER
state: ACTIVE
- name: docker_container_2
version: haproxy:latest
containerType: DOCKER
state: INSTALLED
deviceInventorySystemPackage:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class KuraInventoryContainer {
@JsonProperty("type")
public String type;

@JsonProperty("state")
public String state;

/**
* Gets the name.
*
Expand Down Expand Up @@ -73,23 +76,42 @@ public void setVersion(String version) {
}

/**
* Gets the state.
* Gets the type.
*
* @return The state.
* @return The type.
* @since 2.0.0
*/
public String getType() {
return type;
}

/**
* Sets the state.
* Sets the type.
*
* @param type The state.
* @param type The type.
* @since 2.0.0
*/
public void setType(String type) {
this.type = type;
}

/**
* Gets the state
*
* @return The state
* @since 2.0.0
*/
public String getState() {
return state;
}

/**
* Sets the state
*
* @param state The state
* @since 2.0.0
*/
public void setState(String state) {
this.state = state;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,21 @@ public interface DeviceInventoryContainer {
* @since 2.0.0
*/
void setContainerType(String containerType);

/**
* Gets the {@link DeviceInventoryContainerState}.
*
* @return The {@link DeviceInventoryContainerState}.
* @since 2.0.0
*/
DeviceInventoryContainerState getState();

/**
* Sets the {@link DeviceInventoryContainerState}.
*
* @param state The {@link DeviceInventoryContainerState}.
* @since 2.0.0
*/
void setState(DeviceInventoryContainerState state);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2023, 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.model.container;

/**
* The {@link DeviceInventoryContainer} states.
*
* @since 2.0.0
*/
public enum DeviceInventoryContainerState {

/**
* The container is running.
*
* @since 2.0.0
*/
ACTIVE,

/**
* The container is starting
*
* @since 2.0.0
*/
INSTALLED,

/**
* Tontainer has failed, or is stopped
*
* @since 2.0.0
*/
UNINSTALLED,

/**
* The container state can not be determined
*
* @since 2.0.0
*/
UNKNOWN,
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ public void execContainer(KapuaId scopeId, KapuaId deviceId, DeviceInventoryCont
ArgumentValidator.notNull(deviceInventoryContainer, "deviceInventoryContainer");
ArgumentValidator.notNull(deviceInventoryContainer.getName(), "deviceInventoryContainer.name");
ArgumentValidator.notNull(deviceInventoryContainer.getVersion(), "deviceInventoryContainer.version");
ArgumentValidator.notNull(deviceInventoryContainer.getContainerType(), "deviceInventoryContainer.type");
ArgumentValidator.notNull(deviceInventoryContainerAction, "deviceInventoryContainerAction");
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(DeviceManagementDomains.DEVICE_MANAGEMENT_DOMAIN, Actions.write, scopeId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.kapua.service.device.management.inventory.model.container.internal;

import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainer;
import org.eclipse.kapua.service.device.management.inventory.model.container.DeviceInventoryContainerState;

/**
* {@link DeviceInventoryContainer} implementation.
Expand All @@ -25,6 +26,8 @@ public class DeviceInventoryContainerImpl implements DeviceInventoryContainer {
private String version;
private String containerType;

private DeviceInventoryContainerState state;

/**
* Constructor.
*
Expand Down Expand Up @@ -62,4 +65,14 @@ public String getContainerType() {
public void setContainerType(String containerType) {
this.containerType = containerType;
}


public DeviceInventoryContainerState getState() {
return state;
}

@Override
public void setState(DeviceInventoryContainerState state) {
this.state = state;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ protected KuraRequestPayload translatePayload(InventoryRequestPayload inventoryR
kuraInventoryContainer.setName(deviceInventoryContainer.getName());
kuraInventoryContainer.setVersion(deviceInventoryContainer.getVersion());
kuraInventoryContainer.setType(deviceInventoryContainer.getContainerType());
if (deviceInventoryContainer.getState() != null) {
kuraInventoryContainer.setState(deviceInventoryContainer.getState().name());
}

kuraRequestPayload.setBody(getJsonMapper().writeValueAsString(kuraInventoryContainer).getBytes(CHAR_ENCODING));
}
Expand Down
Loading

0 comments on commit d1416e4

Please sign in to comment.