Search in sources :

Example 1 with DeviceSnapshotManagementService

use of org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotManagementService in project kapua by eclipse.

the class GwtDeviceManagementServiceImpl method findDeviceSnapshots.

// 
// Snapshots
// 
@Override
public ListLoadResult<GwtSnapshot> findDeviceSnapshots(GwtDevice gwtDevice) throws GwtKapuaException {
    List<GwtSnapshot> snapshots = new ArrayList<GwtSnapshot>();
    try {
        // execute the command
        KapuaLocator locator = KapuaLocator.getInstance();
        DeviceSnapshotManagementService deviceSnapshotManagementService = locator.getService(DeviceSnapshotManagementService.class);
        KapuaId scopeId = KapuaEid.parseShortId(gwtDevice.getScopeId());
        KapuaId deviceId = KapuaEid.parseShortId(gwtDevice.getId());
        DeviceSnapshots snapshotIds = deviceSnapshotManagementService.get(scopeId, deviceId, null);
        // sort them by most recent first
        // sort the list alphabetically by service name
        Collections.sort(snapshotIds.getSnapshots(), new Comparator<DeviceSnapshot>() {

            @Override
            public int compare(DeviceSnapshot arg0, DeviceSnapshot arg1) {
                DeviceSnapshot snapshotId0 = arg0;
                DeviceSnapshot snapshotId1 = arg1;
                // Descending order
                return -1 * snapshotId0.getTimestamp().compareTo(snapshotId1.getTimestamp());
            }
        });
        for (DeviceSnapshot snapshot : snapshotIds.getSnapshots()) {
            Long timestamp = snapshot.getTimestamp();
            GwtSnapshot gwtSnapshot = new GwtSnapshot();
            gwtSnapshot.setCreatedOn(new Date(timestamp));
            snapshots.add(gwtSnapshot);
        }
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
    return new BaseListLoadResult<GwtSnapshot>(snapshots);
}
Also used : GwtSnapshot(org.eclipse.kapua.app.console.shared.model.GwtSnapshot) KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) ArrayList(java.util.ArrayList) Date(java.util.Date) BaseListLoadResult(com.extjs.gxt.ui.client.data.BaseListLoadResult) DeviceSnapshotManagementService(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotManagementService) KapuaId(org.eclipse.kapua.model.id.KapuaId) DeviceSnapshot(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshot) DeviceSnapshots(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshots)

Example 2 with DeviceSnapshotManagementService

use of org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotManagementService in project kapua by eclipse.

the class GwtDeviceManagementServiceImpl method rollbackDeviceSnapshot.

@Override
public void rollbackDeviceSnapshot(GwtXSRFToken xsrfToken, GwtDevice gwtDevice, GwtSnapshot snapshot) throws GwtKapuaException {
    // 
    // Checking validity of the given XSRF Token
    checkXSRFToken(xsrfToken);
    try {
        KapuaLocator locator = KapuaLocator.getInstance();
        DeviceSnapshotManagementService deviceService = locator.getService(DeviceSnapshotManagementService.class);
        KapuaId scopeId = KapuaEid.parseShortId(gwtDevice.getScopeId());
        KapuaId deviceId = KapuaEid.parseShortId(gwtDevice.getId());
        deviceService.rollback(scopeId, deviceId, String.valueOf(snapshot.getSnapshotId()), null);
    } catch (Throwable t) {
        KapuaExceptionHandler.handle(t);
    }
}
Also used : KapuaLocator(org.eclipse.kapua.locator.KapuaLocator) DeviceSnapshotManagementService(org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotManagementService) KapuaId(org.eclipse.kapua.model.id.KapuaId)

Aggregations

KapuaLocator (org.eclipse.kapua.locator.KapuaLocator)2 KapuaId (org.eclipse.kapua.model.id.KapuaId)2 DeviceSnapshotManagementService (org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshotManagementService)2 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GwtSnapshot (org.eclipse.kapua.app.console.shared.model.GwtSnapshot)1 DeviceSnapshot (org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshot)1 DeviceSnapshots (org.eclipse.kapua.service.device.management.snapshot.DeviceSnapshots)1