Skip to content

Commit

Permalink
List Kura component factories
Browse files Browse the repository at this point in the history
  • Loading branch information
reda-alaoui committed Jan 5, 2025
1 parent 1ddca6c commit 6ec87ef
Show file tree
Hide file tree
Showing 15 changed files with 328 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2025 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.configuration;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


@XmlRootElement(name = "configurationFactories")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = DeviceConfigurationXmlRegistry.class, factoryMethod = "newComponentConfigurationFactories")
public interface DeviceComponentConfigurationFactories {

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

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement(name = "configurationFactory")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = DeviceConfigurationXmlRegistry.class, factoryMethod = "newComponentConfigurationFactory")
public interface DeviceComponentConfigurationFactory {

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ public interface DeviceConfigurationFactory extends KapuaObjectFactory {
* @return
*/
DeviceConfiguration newConfigurationInstance();

DeviceComponentConfigurationFactory newComponentConfigurationFactory();

DeviceComponentConfigurationFactories newComponentConfigurationFactories();
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ DeviceConfiguration get(KapuaId scopeId, KapuaId deviceId,
Long timeout)
throws KapuaException;

DeviceComponentConfigurationFactories getFactories(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException;

void create(KapuaId scopeId, KapuaId deviceId, String componentFactoryId, String componentId, Long timeout) throws KapuaException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ public DeviceConfiguration newConfiguration() {
public DeviceComponentConfiguration newComponentConfiguration() {
return deviceConfigurationFactory.newComponentConfigurationInstance(null);
}

public DeviceComponentConfigurationFactory newComponentConfigurationFactory() {
return deviceConfigurationFactory.newComponentConfigurationFactory();
}

public DeviceComponentConfigurationFactories newComponentConfigurationFactories() {
return deviceConfigurationFactory.newComponentConfigurationFactories();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2025 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.configuration.internal;

import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfigurationFactories;

public class DeviceComponentConfigurationFactoriesImpl implements DeviceComponentConfigurationFactories {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*******************************************************************************
* Copyright (c) 2025 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.configuration.internal;

import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfigurationFactory;

public class DeviceComponentConfigurationFactoryImpl implements DeviceComponentConfigurationFactory {

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package org.eclipse.kapua.service.device.management.configuration.internal;

import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfiguration;
import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfigurationFactories;
import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfigurationFactory;
import org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration;
import org.eclipse.kapua.service.device.management.configuration.DeviceConfigurationFactory;

Expand All @@ -36,4 +38,14 @@ public DeviceConfiguration newConfigurationInstance() {
return new DeviceConfigurationImpl();
}

@Override
public DeviceComponentConfigurationFactory newComponentConfigurationFactory() {
return new DeviceComponentConfigurationFactoryImpl();
}

@Override
public DeviceComponentConfigurationFactories newComponentConfigurationFactories() {
return new DeviceComponentConfigurationFactoriesImpl();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@
import org.eclipse.kapua.service.device.management.commons.AbstractDeviceManagementTransactionalServiceImpl;
import org.eclipse.kapua.service.device.management.commons.call.DeviceCallBuilder;
import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfiguration;
import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfigurationFactories;
import org.eclipse.kapua.service.device.management.configuration.DeviceConfiguration;
import org.eclipse.kapua.service.device.management.configuration.DeviceConfigurationFactory;
import org.eclipse.kapua.service.device.management.configuration.DeviceConfigurationManagementService;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationCreationRequestMessage;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationCreationRequestPayload;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationCreationResponseMessage;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationFactoriesRequestMessage;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationFactoriesRequestPayload;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationFactoriesResponseMessage;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationRequestChannel;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationRequestMessage;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationRequestPayload;
Expand Down Expand Up @@ -166,6 +170,48 @@ public DeviceConfiguration get(KapuaId scopeId, KapuaId deviceId, String configu
}
}

@Override
public DeviceComponentConfigurationFactories getFactories(KapuaId scopeId, KapuaId deviceId, Long timeout) throws KapuaException {
// Argument Validation
ArgumentValidator.notNull(scopeId, SCOPE_ID);
ArgumentValidator.notNull(deviceId, DEVICE_ID);
// Check Access
authorizationService.checkPermission(permissionFactory.newPermission(Domains.DEVICE_MANAGEMENT, Actions.read, scopeId));
// Prepare the request
ConfigurationRequestChannel channel = new ConfigurationRequestChannel();
channel.setAppName(DeviceConfigurationAppProperties.APP_NAME);
channel.setVersion(DeviceConfigurationAppProperties.APP_VERSION);
channel.setMethod(KapuaMethod.READ);

ConfigurationFactoriesRequestMessage requestMessage = new ConfigurationFactoriesRequestMessage();
requestMessage.setScopeId(scopeId);
requestMessage.setDeviceId(deviceId);
requestMessage.setCapturedOn(new Date());
requestMessage.setPayload(new ConfigurationFactoriesRequestPayload());
requestMessage.setChannel(channel);

// Build request
DeviceCallBuilder<ConfigurationRequestChannel, ConfigurationFactoriesRequestPayload, ConfigurationFactoriesRequestMessage, ConfigurationFactoriesResponseMessage> callBuilder =
DeviceCallBuilder
.newBuilder()
.withRequestMessage(requestMessage)
.withTimeoutOrDefault(timeout);

// Do get
ConfigurationFactoriesResponseMessage responseMessage;
try {
responseMessage = callBuilder.send();
} catch (Exception e) {
LOG.error("Error while getting component configuration factories for Device {}. Error: {}", deviceId, e.getMessage(), e);
throw e;
}

// Create event
createDeviceEvent(scopeId, deviceId, requestMessage, responseMessage);

return checkResponseAcceptedOrThrowError(responseMessage, () -> responseMessage.getPayload().get());
}

@Override
public void create(KapuaId scopeId, KapuaId deviceId, String componentFactoryId, String componentId, Long timeout) throws KapuaException {
// Argument Validation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2025 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
* Red Hat Inc
*******************************************************************************/
package org.eclipse.kapua.service.device.management.configuration.message.internal;

import org.eclipse.kapua.message.internal.KapuaMessageImpl;
import org.eclipse.kapua.service.device.management.message.request.KapuaRequestMessage;

public class ConfigurationFactoriesRequestMessage extends KapuaMessageImpl<ConfigurationRequestChannel, ConfigurationFactoriesRequestPayload>
implements KapuaRequestMessage<ConfigurationRequestChannel, ConfigurationFactoriesRequestPayload> {

@Override
public Class<ConfigurationFactoriesRequestMessage> getRequestClass() {
return ConfigurationFactoriesRequestMessage.class;
}

@Override
public Class<ConfigurationFactoriesResponseMessage> getResponseClass() {
return ConfigurationFactoriesResponseMessage.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2025 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.configuration.message.internal;

import org.eclipse.kapua.message.internal.KapuaPayloadImpl;
import org.eclipse.kapua.service.device.management.message.request.KapuaRequestPayload;

public class ConfigurationFactoriesRequestPayload extends KapuaPayloadImpl implements KapuaRequestPayload {

private static final long serialVersionUID = 1400605735748313538L;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2025 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
* Red Hat Inc
*******************************************************************************/
package org.eclipse.kapua.service.device.management.configuration.message.internal;

import org.eclipse.kapua.service.device.management.commons.message.response.KapuaResponseMessageImpl;
import org.eclipse.kapua.service.device.management.message.response.KapuaResponseMessage;

public class ConfigurationFactoriesResponseMessage extends KapuaResponseMessageImpl<ConfigurationResponseChannel, ConfigurationFactoriesResponsePayload>
implements KapuaResponseMessage<ConfigurationResponseChannel, ConfigurationFactoriesResponsePayload> {

private static final long serialVersionUID = -211188083735456147L;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2025 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
* Red Hat Inc
*******************************************************************************/
package org.eclipse.kapua.service.device.management.configuration.message.internal;

import org.eclipse.kapua.service.device.management.commons.message.response.KapuaResponsePayloadImpl;
import org.eclipse.kapua.service.device.management.configuration.DeviceComponentConfigurationFactories;
import org.eclipse.kapua.service.device.management.message.response.KapuaResponsePayload;

public class ConfigurationFactoriesResponsePayload extends KapuaResponsePayloadImpl implements KapuaResponsePayload {

private final DeviceComponentConfigurationFactories factories;

public ConfigurationFactoriesResponsePayload(DeviceComponentConfigurationFactories factories) {
this.factories = factories;
}

public DeviceComponentConfigurationFactories get() {
return factories;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.kapua.translator.kapua.kura.TranslatorAppBundleKapuaKura;
import org.eclipse.kapua.translator.kapua.kura.TranslatorAppCommandKapuaKura;
import org.eclipse.kapua.translator.kapua.kura.TranslatorAppConfigurationCreationKapuaKura;
import org.eclipse.kapua.translator.kapua.kura.TranslatorAppConfigurationFactoriesKapuaKura;
import org.eclipse.kapua.translator.kapua.kura.TranslatorAppConfigurationKapuaKura;
import org.eclipse.kapua.translator.kapua.kura.TranslatorAppPackageKapuaKura;
import org.eclipse.kapua.translator.kapua.kura.TranslatorAppRequestKapuaKura;
Expand Down Expand Up @@ -77,6 +78,7 @@ protected void configureModule() {
translatorMultibinder.addBinding().to(TranslatorAppBundleKapuaKura.class);
translatorMultibinder.addBinding().to(TranslatorAppCommandKapuaKura.class);
translatorMultibinder.addBinding().to(TranslatorAppConfigurationKapuaKura.class);
translatorMultibinder.addBinding().to(TranslatorAppConfigurationFactoriesKapuaKura.class);
translatorMultibinder.addBinding().to(TranslatorAppConfigurationCreationKapuaKura.class);
translatorMultibinder.addBinding().to(TranslatorAppPackageKapuaKura.class);
translatorMultibinder.addBinding().to(TranslatorAppRequestKapuaKura.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2025 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
* Red Hat Inc
*******************************************************************************/
package org.eclipse.kapua.translator.kapua.kura;

import org.eclipse.kapua.service.device.call.kura.model.configuration.ConfigurationMetrics;
import org.eclipse.kapua.service.device.call.message.kura.app.request.KuraRequestChannel;
import org.eclipse.kapua.service.device.call.message.kura.app.request.KuraRequestMessage;
import org.eclipse.kapua.service.device.call.message.kura.app.request.KuraRequestPayload;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationFactoriesRequestMessage;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationFactoriesRequestPayload;
import org.eclipse.kapua.service.device.management.configuration.message.internal.ConfigurationRequestChannel;
import org.eclipse.kapua.translator.exception.InvalidChannelException;
import org.eclipse.kapua.translator.exception.InvalidPayloadException;

public class TranslatorAppConfigurationFactoriesKapuaKura extends AbstractTranslatorKapuaKura<ConfigurationRequestChannel, ConfigurationFactoriesRequestPayload, ConfigurationFactoriesRequestMessage> {

@Override
protected KuraRequestChannel translateChannel(ConfigurationRequestChannel kapuaChannel) throws InvalidChannelException {
try {
KuraRequestChannel channel = TranslatorKapuaKuraUtils.buildBaseRequestChannel(ConfigurationMetrics.APP_ID, ConfigurationMetrics.APP_VERSION_2, kapuaChannel.getMethod());
channel.setResources(new String[]{"factoryComponents"});
return channel;
} catch (Exception e) {
throw new InvalidChannelException(e, kapuaChannel);
}
}

@Override
protected KuraRequestPayload translatePayload(ConfigurationFactoriesRequestPayload kapuaPayload) throws InvalidPayloadException {
try {
// Return Kura Payload
return new KuraRequestPayload();
} catch (Exception e) {
throw new InvalidPayloadException(e, kapuaPayload);
}
}

@Override
public Class<ConfigurationFactoriesRequestMessage> getClassFrom() {
return ConfigurationFactoriesRequestMessage.class;
}

@Override
public Class<KuraRequestMessage> getClassTo() {
return KuraRequestMessage.class;
}
}

0 comments on commit 6ec87ef

Please sign in to comment.