iot-device-simulator icon indicating copy to clipboard operation
iot-device-simulator copied to clipboard

Deletion of deviceType&Widget synchronization

Open usmanumar2010 opened this issue 5 years ago • 4 comments
trafficstars

Simulator does not stop simulating data even if we delete the widget and device. Seems when the Queue send the message its start the ECS simulation engine but does not have a mechanism to stop when trigger(of stop) happens.

usmanumar2010 avatar Apr 15 '20 10:04 usmanumar2010

Hello, thank you for your feedback. I tried to replicate the behavior at my end. Steps:

  1. Create test scenario with weather station device type and 25 widgets as mentioned here
  2. Start simulation for the 25 widgets
  3. Monitor test data using IoT test console and subscribing to /weather/data topic

I tested the above steps in multiple scenarios, with simulation time ranging from 2 minutes to 5 hrs. In all the cases simulation data stopped within ~15-25 seconds of stopping the widget simulation from the iot device simulator console.

Can you specify the steps that we can take to replicate this behavior?

gsingh04 avatar Apr 22 '20 09:04 gsingh04

I started simulator for 1 day and when it start publishing data .I deleted its "device Type" and "device Widget" .It do deleted from DynamoDb .But if I am subscribing the topic I can see data with the deleted "device Type" and "device widget" still publishing on the IOT Core.

I you are so sure that its working .Can you tell what happens when you delete the widget and device when its publishing data what happens inside the ECS container(does it has a mechanism to listen the changes) as I dont see there is code to written to stop already running queues in the ECS.

steps: 1.Create device and widget 2. Run them for long duration 3. delete the widget and device before its duration get compete 4. check Iot Core by subscribing topic 5. I am finding its still receiving data

usmanumar2010 avatar Apr 23 '20 20:04 usmanumar2010

The application should be syncing device state across browsers/tabs. You should be correctly seeing the device state and should only be able to delete a device which is in sleeping state. However, to overcome inconsistent device state issue we can check the device state before trying to delete it, to make sure it is in needed sleeping state. I have tested following changes locally. I would recommend you to make these changes locally as well, if this is a blocker for you; while we work on pushing out the next release.

In both the changes, we are confirm device state and refreshing device when trying to delete it 1. https://github.com/awslabs/iot-device-simulator/blob/5873ba66b7d7eb5151e02a9fcf567745bf8531b2/source/console/src/app/secure/devices/widgets.component.ts#L411

Change the deleteDevice function as follows:

deleteDevice(deviceId: string) {
        const _self = this;

        // delete device only if in sleeping state
        _self.deviceService.getDevice(deviceId).then((d: Device) => {
            console.log(`current state: ${JSON.stringify(d, null, 4)}`);
            if (d.stage !== 'sleeping') {
                _self.blockUI.stop();
                swal(
                    'Oops...',
                    'Something went wrong! Cannot delete a running device',
                    'error'
                );
                _self.loadDevices();
            } else {
                swal({
                    title: 'Are you sure you want to delete this widget?',
                    text: 'You won\'t be able to revert this!',
                    type: 'question',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes, delete it!'
                }).then((result) => {
                    if (result.value) {
                        _self.blockUI.start('Deleting device...');

                        _self.deviceService.deleteDevice(deviceId).then((resp: any) => {
                            _self.loadDevices();
                        }).catch((err) => {
                            _self.blockUI.stop();
                            swal(
                                'Oops...',
                                'Something went wrong! Unable to delete the widget.',
                                'error');
                            _self.logger.error('error occurred calling deleteDevice api, show message');
                            _self.logger.error(err);
                            _self.loadDevices();
                        });
                    }
                });
            }
        });
    }

https://github.com/awslabs/iot-device-simulator/blob/5873ba66b7d7eb5151e02a9fcf567745bf8531b2/source/console/src/app/secure/devices/widget.component.ts#L161

Change the deleteDevice function as follows:

deleteDevice() {
    const _self = this;

    // delete device only if in sleeping state
    _self.deviceService.getDevice(_self.device.id).then((d: Device) => {
      console.log(`current state: ${JSON.stringify(d, null, 4)}`);
      if (d.stage !== 'sleeping') {
        _self.blockUI.stop();
        swal(
          'Oops...',
          'Something went wrong! Cannot delete a running device',
          'error'
        );
        _self.loadDevice();
      } else {
        swal({
          title: 'Are you sure you want to delete this widget?',
          text: 'You won\'t be able to revert this!',
          type: 'question',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: 'Yes, delete it!'
        }).then((result) => {
          if (result.value) {
            _self.blockUI.start('Deleting device...');

            _self.deviceService.deleteDevice(_self.device.id).then((resp: any) => {
              this.router.navigate(['/securehome/general']);
            }).catch((err) => {
              _self.blockUI.stop();
              swal(
                'Oops...',
                'Something went wrong! Unable to delete the widget.',
                'error');
              _self.logger.error('error occurred calling deleteDevice api, show message');
              _self.logger.error(err);
              _self.loadDevice();
            });
          }
        });
      }
    });
  }
  1. Local build steps https://github.com/awslabs/iot-device-simulator/blob/5873ba66b7d7eb5151e02a9fcf567745bf8531b2/deployment/build-s3-dist.sh#L64
cd $source_dir/console
rm -r ./dist
npm install
./node_modules/@angular/cli/bin/ng build --prod --aot=false

Note: These steps will build console distribution files locally. You can copy all these files to iot device simulator web site bucket. Please make sure you do not replace the appVariable.js file as it contains variables for your aws deployment

gsingh04 avatar Apr 27 '20 10:04 gsingh04

When stop functionality is not working fine issue raised : https://github.com/awslabs/iot-device-simulator/issues/13

How can I rely on Front End Checks.

usmanumar2010 avatar Apr 27 '20 10:04 usmanumar2010