Skip to content

Commit

Permalink
Added procesing log to Device Management Operation
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 c0ccf36 commit fdb6be5
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 16 deletions.
Expand Up @@ -303,13 +303,15 @@ deviceInstallTabHistoryTableVersion=Version
deviceInstallTabHistoryTableURI=URI
deviceInstallTabHistoryTableStartedOn=StartedOn
deviceInstallTabHistoryTableEndedOn=EndedOn
deviceInstallTabHistoryTableResource=Operation Type
deviceInstallTabHistoryTableEndedOnInProgress=In progress...
deviceInstallTabHistoryTableResource=Operation Type
deviceInstallTabHistoryTableStatus=Status
deviceInstallTabHistoryTableStatusCompleted=Completed
deviceInstallTabHistoryTableStatusRunning=Running
deviceInstallTabHistoryTableStatusStale=Stale
deviceInstallTabHistoryTableStatusFailed=Failed
deviceInstallTabHistoryTableStatusCompleted=COMPLETED
deviceInstallTabHistoryTableStatusRunning=RUNNING
deviceInstallTabHistoryTableStatusStale=STALE
deviceInstallTabHistoryTableStatusFailed=FAILED

deviceInstallTabHistoryDialogLogHeader=Log for management operation

packageInstallButton=Install
packageInstallNewPackage=Install New Package
Expand Down
Expand Up @@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.kapua.service.device.management.registry.manager;

import com.google.common.base.Strings;
import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.locator.KapuaLocator;
Expand All @@ -25,8 +26,12 @@
import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationProperty;
import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationQuery;
import org.eclipse.kapua.service.device.management.registry.operation.DeviceManagementOperationRegistryService;
import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotification;
import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationAttributes;
import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationCreator;
import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationFactory;
import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationListResult;
import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationQuery;
import org.eclipse.kapua.service.device.management.registry.operation.notification.ManagementOperationNotificationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -115,11 +120,11 @@ default void closeDeviceManagementOperation(KapuaId scopeId, KapuaId operationId
deviceManagementOperation = getDeviceManagementOperation(scopeId, operationId);
deviceManagementOperation.setEndedOn(updateOn);
deviceManagementOperation.setStatus(finalStatus);
deviceManagementOperation.setLog("Generating...");

DEVICE_MANAGEMENT_OPERATION_REGISTRY_SERVICE.update(deviceManagementOperation);
deviceManagementOperation = DEVICE_MANAGEMENT_OPERATION_REGISTRY_SERVICE.update(deviceManagementOperation);

LOG.info("Update DeviceManagementOperation {} with status {}... SUCCEEDED!", operationId, finalStatus);
break;
} catch (Exception e) {
failed = true;
attempts++;
Expand All @@ -132,14 +137,23 @@ default void closeDeviceManagementOperation(KapuaId scopeId, KapuaId operationId
}
} while (failed);

// ManagementOperationNotificationQuery query = MANAGEMENT_OPERATION_NOTIFICATION_FACTORY.newQuery(scopeId);
// query.setPredicate(query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, deviceManagementOperation.getId()));
//
// ManagementOperationNotificationListResult notifications = MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_SERVICE.query(query);
//
// for (ManagementOperationNotification mon : notifications.getItems()) {
// MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_SERVICE.delete(mon.getScopeId(), mon.getId());
// }
{
ManagementOperationNotificationQuery query = MANAGEMENT_OPERATION_NOTIFICATION_FACTORY.newQuery(scopeId);
query.setPredicate(query.attributePredicate(ManagementOperationNotificationAttributes.OPERATION_ID, deviceManagementOperation.getId()));

ManagementOperationNotificationListResult notifications = MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_SERVICE.query(query);

StringBuilder logSb = new StringBuilder();
for (ManagementOperationNotification mon : notifications.getItems()) {
if (!Strings.isNullOrEmpty(mon.getMessage())) {
logSb.append(mon.getSentOn()).append(" - ").append(mon.getMessage()).append("\n");
}
MANAGEMENT_OPERATION_NOTIFICATION_REGISTRY_SERVICE.delete(mon.getScopeId(), mon.getId());
}

deviceManagementOperation.setLog(logSb.toString());
DEVICE_MANAGEMENT_OPERATION_REGISTRY_SERVICE.update(deviceManagementOperation);
}
}

default DeviceManagementOperation getDeviceManagementOperation(KapuaId scopeId, KapuaId operationId) throws KapuaException {
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 Eurotech and/or its affiliates and others
* Copyright (c) 2018, 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 @@ -29,6 +29,9 @@
import java.util.Date;
import java.util.List;

/**
* @since 1.0.0
*/
@XmlRootElement(name = "deviceManagementOperation")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(factoryClass = DeviceManagementOperationXmlRegistry.class, factoryMethod = "newDeviceManagementOperation")
Expand All @@ -41,56 +44,140 @@ default String getType() {
return TYPE;
}

/**
* @return
* @since 1.0.0
*/
@XmlElement(name = "startedOn")
@XmlJavaTypeAdapter(DateXmlAdapter.class)
Date getStartedOn();

/**
* @param startedOn
* @since 1.0.0
*/
void setStartedOn(Date startedOn);

/**
* @return
* @since 1.0.0
*/
@XmlElement(name = "endedOn")
@XmlJavaTypeAdapter(DateXmlAdapter.class)
Date getEndedOn();

/**
* @param endedOn
* @since 1.0.0
*/
void setEndedOn(Date endedOn);

/**
* @return
* @since 1.0.0
*/
@XmlElement(name = "deviceId")
@XmlJavaTypeAdapter(KapuaIdAdapter.class)
@ApiModelProperty(dataType = "string")
KapuaId getDeviceId();

/**
* @param deviceId
* @since 1.0.0
*/
void setDeviceId(KapuaId deviceId);

/**
* @return
* @since 1.0.0
*/
@XmlElement(name = "operationId")
@XmlJavaTypeAdapter(KapuaIdAdapter.class)
@ApiModelProperty(dataType = "string")
KapuaId getOperationId();

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

/**
* @return
*/
@XmlElement(name = "appId")
String getAppId();

/**
* @param appId
* @since 1.0.0
*/
void setAppId(String appId);

/**
* @return
* @since 1.0.0
*/
@XmlElement(name = "action")
KapuaMethod getAction();

/**
* @param action
* @since 1.0.0
*/
void setAction(KapuaMethod action);

/**
* @return
* @since 1.0.0
*/
@XmlElement(name = "resource")
String getResource();

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

/**
* @return
* @since 1.0.0
*/
@XmlElement(name = "status")
OperationStatus getStatus();

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

/**
* @param <P>
* @return
* @since 1.0.0
*/
@XmlElementWrapper(name = "operationProperties")
@XmlElement(name = "operationProperty")
<P extends DeviceManagementOperationProperty> List<P> getInputProperties();

/**
* @param inputProperties
* @since 1.0.0
*/
void setInputProperties(List<DeviceManagementOperationProperty> inputProperties);

/**
* @return
* @since 1.2.0
*/
String getLog();

/**
* @param log
* @since 1.2.0
*/
void setLog(String log);

}
Expand Up @@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.kapua.service.device.management.registry.operation.internal;

import com.google.common.base.Strings;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.model.AbstractKapuaUpdatableEntity;
import org.eclipse.kapua.commons.model.id.KapuaEid;
Expand Down Expand Up @@ -82,6 +83,10 @@ public class DeviceManagementOperationImpl extends AbstractKapuaUpdatableEntity
@CollectionTable(name = "dvcm_device_management_operation_input_property", joinColumns = @JoinColumn(name = "operation_id", referencedColumnName = "id"))
private List<DeviceManagementOperationPropertyImpl> inputProperties;

@Basic
@Column(name = "log", nullable = true, updatable = true)
private String log;

/**
* Constructor.
*
Expand Down Expand Up @@ -220,4 +225,16 @@ public void setInputProperties(List<DeviceManagementOperationProperty> inputProp
}
}
}

@Override
public String getLog() {
// Setting to empty if null to avoid checking for null and empty when using this value.
return Strings.nullToEmpty(log);
}

@Override
public void setLog(String log) {
// Setting to null to avoid storing empty string in database
this.log = Strings.emptyToNull(log);
}
}
Expand Up @@ -18,5 +18,6 @@
logicalFilePath="KapuaDB/changelog-device_management_registry-1.2.0.xml">

<include relativeToChangelogFile="true" file="./device_management_operation_notification-add_message.xml"/>
<include relativeToChangelogFile="true" file="./device_management_operation-add_log.xml"/>

</databaseChangeLog>
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 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
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Eurotech - initial API and implementation
-->
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd"

logicalFilePath="KapuaDB/changelog-device-management-registry-1.2.0.xml">

<include relativeToChangelogFile="true" file="../common-properties.xml"/>

<changeSet id="changelog-dvcm-mgt-operation-1.2.0_add-log" author="eurotech">
<addColumn tableName="dvcm_device_management_operation">
<column name="log" type="text"/>
</addColumn>
</changeSet>

</databaseChangeLog>

0 comments on commit fdb6be5

Please sign in to comment.