Search in sources :

Example 6 with OtaPackageUpdateStatus

use of org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus in project thingsboard by thingsboard.

the class OtaLwM2MIntegrationTest method testSoftwareUpdateByObject9.

/**
 * This is the example how to use the AWAITILITY instead Thread.sleep()
 * Test will finish as fast as possible, but will await until TIMEOUT if a build machine is busy or slow
 * Check the detailed log output to learn how Awaitility polling the API and when exactly expected result appears
 */
@Test
public void testSoftwareUpdateByObject9() throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS_OTA, getBootstrapServerCredentialsNoSec(NONE));
    createDeviceProfile(transportConfiguration);
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA9));
    final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA9);
    createNewClient(SECURITY_NO_SEC, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA9, false, null);
    Thread.sleep(1000);
    device.setSoftwareId(createSoftware().getId());
    // sync call
    final Device savedDevice = doPost("/api/device", device, Device.class);
    Thread.sleep(1000);
    assertThat(savedDevice).as("saved device").isNotNull();
    assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice);
    final List<OtaPackageUpdateStatus> expectedStatuses = List.of(QUEUED, INITIATED, DOWNLOADING, DOWNLOADING, DOWNLOADING, DOWNLOADED, VERIFIED, UPDATED);
    log.warn("AWAIT atMost {} SECONDS on timeseries List<TsKvEntry> by API with list size {}...", TIMEOUT, expectedStatuses.size());
    List<TsKvEntry> ts = await("await on timeseries").atMost(30, TimeUnit.SECONDS).until(() -> getSwStateTelemetryFromAPI(device.getId().getId()), hasSize(expectedStatuses.size()));
    log.warn("Got the ts: {}", ts);
    ts.sort(Comparator.comparingLong(TsKvEntry::getTs));
    log.warn("Ts ordered: {}", ts);
    ts.forEach((x) -> log.warn("ts: {        Thread.sleep(1000);} ", x));
    List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
    log.warn("Converted ts to statuses: {}", statuses);
    assertThat(statuses).isEqualTo(expectedStatuses);
}
Also used : TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Device(org.thingsboard.server.common.data.Device) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) Test(org.junit.Test) AbstractOtaLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)

Example 7 with OtaPackageUpdateStatus

use of org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method onCurrentFirmwareStateUpdate.

@Override
public void onCurrentFirmwareStateUpdate(LwM2mClient client, Long stateCode) {
    log.debug("[{}] Current fw state: {}", client.getEndpoint(), stateCode);
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    FirmwareUpdateState state = FirmwareUpdateState.fromStateFwByCode(stateCode.intValue());
    if (FirmwareUpdateState.DOWNLOADED.equals(state)) {
        executeFwUpdate(client);
    }
    fwInfo.setUpdateState(state);
    Optional<OtaPackageUpdateStatus> status = toOtaPackageUpdateStatus(state);
    if (FirmwareUpdateState.IDLE.equals(state) && DOWNLOADING.equals(fwInfo.getStatus())) {
        fwInfo.setFailedPackageId(fwInfo.getTargetPackageId());
        status = Optional.of(FAILED);
    }
    status.ifPresent(otaStatus -> {
        fwInfo.setStatus(otaStatus);
        sendStateUpdateToTelemetry(client, fwInfo, otaStatus, "Firmware Update State: " + state.name());
    });
    update(fwInfo);
}
Also used : LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) FirmwareUpdateState(org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState)

Aggregations

OtaPackageUpdateStatus (org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus)7 Test (org.junit.Test)3 Device (org.thingsboard.server.common.data.Device)3 LwM2MDeviceCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials)3 Lwm2mDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)3 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)3 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)3 AbstractOtaLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)3 LwM2MClientFwOtaInfo (org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)2 LwM2MClientSwOtaInfo (org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 FirmwareUpdateResult (org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateResult)1 FirmwareUpdateState (org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState)1 SoftwareUpdateResult (org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateResult)1 SoftwareUpdateState (org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateState)1