Commit ea432eb6 authored by Fotis Soldatos's avatar Fotis Soldatos
Browse files

feat(automation): implement ztpDelete()

parent fc3c3765
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -22,4 +22,6 @@ import io.smallrye.mutiny.Uni;
public interface AutomationService {

    Uni<Device> addDevice(String deviceId);

    Uni<Device> deleteDevice(String deviceId);
}
+22 −0
Original line number Diff line number Diff line
@@ -80,4 +80,26 @@ public class AutomationServiceImpl implements AutomationService {

        return deserializedDeviceUni;
    }

    @Override
    public Uni<Device> deleteDevice(String deviceId) {
        final var deserializedDeviceUni = contextService.getDevice(deviceId);

        deserializedDeviceUni
                .subscribe()
                .with(
                        device -> {
                            final var id = deviceId;

                            LOGGER.infof("Retrieved %s", device);

                            final var empty = deviceService.deleteDevice(device.getDeviceId());

                            empty
                                    .subscribe()
                                    .with(emptyMessage -> LOGGER.infof("Device [%s] has been deleted.\n", id));
                        });

        return deserializedDeviceUni;
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -73,9 +73,12 @@ public class ContextSubscriber {
                                    LOGGER.infof("Received %s for device [%s]", event, deviceId);
                                    automationService.addDevice(deviceEvent.getDeviceId());
                                    break;
                                case REMOVE:
                                    LOGGER.infof("Received %s for device [%s]", event, deviceId);
                                    automationService.deleteDevice(deviceEvent.getDeviceId());
                                    break;

                                case UPDATE:
                                case REMOVE:
                                case UNDEFINED:
                                    logWarningMessage(event, deviceId, eventType);
                                    break;
+12 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import eu.teraflow.automation.context.model.DeviceConfig;
import eu.teraflow.automation.context.model.DeviceDriverEnum;
import eu.teraflow.automation.context.model.DeviceEvent;
import eu.teraflow.automation.context.model.DeviceOperationalStatus;
import eu.teraflow.automation.context.model.Empty;
import eu.teraflow.automation.context.model.EndPoint;
import eu.teraflow.automation.context.model.EndPointId;
import eu.teraflow.automation.context.model.Event;
@@ -920,6 +921,17 @@ public class Serializer {
                deviceEndPoints);
    }

    public ContextOuterClass.Empty serializeEmpty(Empty empty) {

        final var builder = ContextOuterClass.Empty.newBuilder();

        return builder.build();
    }

    public Empty deserializeEmpty(ContextOuterClass.Empty serializedEmpty) {
        return new Empty();
    }

    public Uuid serializeUuid(String uuid) {
        return Uuid.newBuilder().setUuid(uuid).build();
    }
+24 −0
Original line number Diff line number Diff line
/*
* Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package eu.teraflow.automation.context.model;

public class Empty {

    public Empty() {
        // Empty constructor to represent the Empty rpc message of context service
    }
}
Loading