diff --git a/src/automation/src/main/java/eu/teraflow/automation/AutomationGatewayImpl.java b/src/automation/src/main/java/eu/teraflow/automation/AutomationGatewayImpl.java index cbaf16d1cc02ce63a5ade27d44244cd90aa9fc49..ebadaa09122ef383074db2bcbfaae62569393912 100644 --- a/src/automation/src/main/java/eu/teraflow/automation/AutomationGatewayImpl.java +++ b/src/automation/src/main/java/eu/teraflow/automation/AutomationGatewayImpl.java @@ -2,6 +2,8 @@ package eu.teraflow.automation; import automation.Automation; import context.ContextOuterClass; +import eu.teraflow.automation.device.model.Device; +import eu.teraflow.automation.model.DeviceRoleId; import io.quarkus.grpc.GrpcService; import io.smallrye.mutiny.Uni; import javax.inject.Inject; @@ -32,18 +34,13 @@ public class AutomationGatewayImpl implements AutomationGateway { @Override public Uni<Automation.DeviceRoleState> ztpAdd(Automation.DeviceRole request) { + final var devRoleId = request.getDevRoleId().getDevRoleId().getUuid(); final var deviceId = serializer.deserialize(request.getDevRoleId().getDevId()); - // TODO tie this with return - automationService.addDevice(deviceId); - - // TODO Set all fields of device role state (create models, serializer) - return Uni.createFrom() - .item( - () -> - Automation.DeviceRoleState.newBuilder() - .setDevRoleId(request.getDevRoleId()) - .build()); + return automationService + .addDevice(deviceId) + .onItem() + .transform( device -> transformToDeviceRoleState(device, devRoleId)); } @Override @@ -70,4 +67,15 @@ public class AutomationGatewayImpl implements AutomationGateway { public Uni<Automation.DeviceDeletionResult> ztpDeleteAll(Automation.Empty empty) { return Uni.createFrom().item(() -> Automation.DeviceDeletionResult.newBuilder().build()); } -} + + private Automation.DeviceRoleState transformToDeviceRoleState(Device device, String devRoleId){ + + final var deviceRoleId = new DeviceRoleId(devRoleId, device.getDeviceId()); + final var serializeDeviceRoleId = serializer.serialize(deviceRoleId); + + return Automation.DeviceRoleState.newBuilder() + .setDevRoleId(serializeDeviceRoleId) + .setDevRoleState(Automation.ZtpDeviceState.ZTP_DEV_STATE_CREATED) + .build(); + } +} \ No newline at end of file diff --git a/src/automation/target/kubernetes/kubernetes.yml b/src/automation/target/kubernetes/kubernetes.yml index a290b69d11926eee164bd55a6cbc845c64b9cb99..055d7455f9c5cff5446551105c159445f49d22cc 100644 --- a/src/automation/target/kubernetes/kubernetes.yml +++ b/src/automation/target/kubernetes/kubernetes.yml @@ -3,8 +3,8 @@ apiVersion: v1 kind: Service metadata: annotations: - app.quarkus.io/commit-id: 74c131c1ab16a4a8b243c27ae34b4d26487c9e05 - app.quarkus.io/build-timestamp: 2022-02-10 - 13:53:38 +0000 + app.quarkus.io/commit-id: 7838f031e97cf30ca2eaf4d5f3428e32173ece12 + app.quarkus.io/build-timestamp: 2022-02-10 - 13:58:28 +0000 labels: app.kubernetes.io/name: automationservice app.kubernetes.io/version: 0.1.0 @@ -12,12 +12,12 @@ metadata: name: automationservice spec: ports: - - name: http - port: 8080 - targetPort: 8080 - name: grpc-server port: 9999 targetPort: 9999 + - name: http + port: 8080 + targetPort: 8080 selector: app.kubernetes.io/name: automationservice app.kubernetes.io/version: 0.1.0 @@ -27,28 +27,28 @@ apiVersion: apps/v1 kind: Deployment metadata: annotations: - app.quarkus.io/commit-id: 74c131c1ab16a4a8b243c27ae34b4d26487c9e05 - app.quarkus.io/build-timestamp: 2022-02-10 - 13:53:38 +0000 + app.quarkus.io/commit-id: 7838f031e97cf30ca2eaf4d5f3428e32173ece12 + app.quarkus.io/build-timestamp: 2022-02-10 - 13:58:28 +0000 labels: app: automationservice - app.kubernetes.io/version: 0.1.0 app.kubernetes.io/name: automationservice + app.kubernetes.io/version: 0.1.0 name: automationservice spec: replicas: 1 selector: matchLabels: - app.kubernetes.io/version: 0.1.0 app.kubernetes.io/name: automationservice + app.kubernetes.io/version: 0.1.0 template: metadata: annotations: - app.quarkus.io/commit-id: 74c131c1ab16a4a8b243c27ae34b4d26487c9e05 - app.quarkus.io/build-timestamp: 2022-02-10 - 13:53:38 +0000 + app.quarkus.io/commit-id: 7838f031e97cf30ca2eaf4d5f3428e32173ece12 + app.quarkus.io/build-timestamp: 2022-02-10 - 13:58:28 +0000 labels: app: automationservice - app.kubernetes.io/version: 0.1.0 app.kubernetes.io/name: automationservice + app.kubernetes.io/version: 0.1.0 spec: containers: - env: @@ -74,12 +74,12 @@ spec: timeoutSeconds: 10 name: automationservice ports: - - containerPort: 8080 - name: http - protocol: TCP - containerPort: 9999 name: grpc-server protocol: TCP + - containerPort: 8080 + name: http + protocol: TCP readinessProbe: failureThreshold: 3 httpGet: