Skip to content

Commit

Permalink
Added support for traking Device Management Notification messages
Browse files Browse the repository at this point in the history
Signed-off-by: coduz <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Jan 27, 2020
1 parent 4230e8f commit c0ccf36
Show file tree
Hide file tree
Showing 16 changed files with 441 additions and 67 deletions.
Expand Up @@ -15,7 +15,6 @@
import com.google.common.base.MoreObjects;
import org.apache.camel.Exchange;
import org.apache.camel.spi.UriEndpoint;

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.broker.core.message.CamelKapuaMessage;
import org.eclipse.kapua.commons.metric.MetricServiceFactory;
Expand All @@ -25,7 +24,6 @@
import org.eclipse.kapua.service.device.management.message.notification.KapuaNotifyMessage;
import org.eclipse.kapua.service.device.management.message.notification.KapuaNotifyPayload;
import org.eclipse.kapua.service.device.management.registry.manager.DeviceManagementRegistryManagerService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -77,7 +75,8 @@ public void processMessage(CamelKapuaMessage<?> message) throws KapuaException {
MoreObjects.firstNonNull(notifyMessage.getSentOn(), notifyMessage.getReceivedOn()),
notifyPayload.getResource(),
notifyPayload.getStatus(),
notifyPayload.getProgress());
notifyPayload.getProgress(),
notifyPayload.getMessage());

JOB_DEVICE_MANAGEMENT_OPERATION_MANAGER_SERVICE.processJobTargetOnNotification(
notifyMessage.getScopeId(),
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others
* Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -15,25 +15,61 @@
import org.eclipse.kapua.model.id.KapuaId;

/**
* Kapua notify message payload object definition.
* {@link KapuaNotifyMessage} {@link KapuaPayload} definition.
*
* @since 1.0
* @since 1.0.0
*/
public interface KapuaNotifyPayload extends KapuaPayload {

/**
* @return
* @since 1.0.0
*/
KapuaId getOperationId();

/**
* @since 1.0.0
*/
void setOperationId(KapuaId operationId);

/**
* @return
* @since 1.0.0
*/
String getResource();

/**
* @since 1.0.0
*/
void setResource(String resource);

/**
* @since 1.0.0
*/
OperationStatus getStatus();

/**
* @since 1.0.0
*/
void setStatus(OperationStatus status);

/**
* @since 1.0.0
*/
Integer getProgress();

/**
* @since 1.0.0
*/
void setProgress(Integer progress);

/**
* @since 1.2.0
*/
String getMessage();

/**
* @since 1.2.0
*/
void setMessage(String message);
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others
* Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -14,15 +14,33 @@
import org.eclipse.kapua.service.device.call.message.app.DeviceAppPayload;

/**
* Kapua notify message payload object definition.
* {@link DeviceNotifyMessage} {@link org.eclipse.kapua.message.KapuaPayload} definition.
*
* @since 1.0
* @since 1.0.0
*/
public interface DeviceNotifyPayload extends DeviceAppPayload {

/**
* @return
* @since 1.0.0
*/
Long getOperationId();

/**
* @return
* @since 1.0.0
*/
String getStatus();

/**
* @return
* @since 1.0.0
*/
Integer getProgress();

/**
* @return
* @since 1.2.0
*/
String getMessage();
}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2018 Eurotech and/or its affiliates and others
* Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -15,22 +15,76 @@

/**
* {@link DeviceRequestMetrics} {@link org.eclipse.kapua.service.device.call.kura.Kura} implementation
*
* @since 1.0.0
*/
public enum KuraNotifyMetrics implements DeviceRequestMetrics {

/**
* @since 1.0.0
*/
OPERATION_ID("job.id"),

/**
* @since 1.0.0
*/
DOWNLOAD_STATUS("dp.download.status"),
/**
* @since 1.0.0
*/
INSTALL_STATUS("dp.install.status"),
/**
* @since 1.0.0
*/
UNINSTALL_STATUS("dp.uninstall.status"),

/**
* @since 1.0.0
*/
DOWNLOAD_PROGRESS("dp.download.progress"),
/**
* @since 1.0.0
*/
INSTALL_PROGRESS("dp.install.progress"),
/**
* @since 1.0.0
*/
UNINSTALL_PROGRESS("dp.uninstall.progress"),

/**
* @since 1.2.0
*/
NOTIFY_MESSAGE("dp.notify.message"),
/**
* @since 1.2.0
*/
DOWNLOAD_MESSAGE("dp.download.message"),
/**
* @since 1.2.0
*/
DOWNLOAD_ERROR_MESSAGE("dp.download.error.message"),
/**
* @since 1.2.0
*/
INSTALL_MESSAGE("dp.install.message"),
/**
* @since 1.2.0
*/
INSTALL_ERROR_MESSAGE("dp.install.error.message"),
/**
* @since 1.2.0
*/
UNINSTALL_MESSAGE("dp.uninstall.message"),
/**
* @since 1.2.0
*/
UNINSTALL_ERROR_MESSAGE("dp.uninstall.error.message"),
;

private String value;

/**
* @since 1.0.0
*/
KuraNotifyMetrics(String value) {
this.value = value;
}
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2018 Eurotech and/or its affiliates and others
* Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand Down Expand Up @@ -73,6 +73,37 @@ public Integer getProgress() {
return (Integer) progress;
}

@Override
public String getMessage() {
Object message = getMetrics().get(KuraNotifyMetrics.NOTIFY_MESSAGE.getValue());

if (message == null) {
message = getMetrics().get(KuraNotifyMetrics.DOWNLOAD_MESSAGE.getValue());
}

if (message == null) {
message = getMetrics().get(KuraNotifyMetrics.DOWNLOAD_ERROR_MESSAGE.getValue());
}

if (message == null) {
message = getMetrics().get(KuraNotifyMetrics.INSTALL_MESSAGE.getValue());
}

if (message == null) {
message = getMetrics().get(KuraNotifyMetrics.INSTALL_ERROR_MESSAGE.getValue());
}

if (message == null) {
message = getMetrics().get(KuraNotifyMetrics.UNINSTALL_MESSAGE.getValue());
}

if (message == null) {
message = getMetrics().get(KuraNotifyMetrics.UNINSTALL_ERROR_MESSAGE.getValue());
}

return (String) message;
}

@Override
public String toDisplayString() {
return null;
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2018 Eurotech and/or its affiliates and others
* Copyright (c) 2016, 2019 Eurotech and/or its affiliates and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -17,16 +17,17 @@
import org.eclipse.kapua.service.device.management.message.notification.OperationStatus;

/**
* Kapua notify message payload object reference implementation.
* {@link KapuaNotifyPayload} implementation.
*
* @since 1.0
* @since 1.0.0
*/
public class KapuaNotifyPayloadImpl extends KapuaPayloadImpl implements KapuaNotifyPayload {

private KapuaId operationId;
private String resource;
private OperationStatus status;
private Integer progress;
private String message;

@Override
public KapuaId getOperationId() {
Expand Down Expand Up @@ -67,4 +68,14 @@ public Integer getProgress() {
public void setProgress(Integer progress) {
this.progress = progress;
}

@Override
public String getMessage() {
return message;
}

@Override
public void setMessage(String message) {
this.message = message;
}
}

0 comments on commit c0ccf36

Please sign in to comment.