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..a6877a7f076e55376ba3f74cf15002400edace3c 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,16 @@ public class AutomationGatewayImpl implements AutomationGateway { public Uni<Automation.DeviceDeletionResult> ztpDeleteAll(Automation.Empty empty) { return Uni.createFrom().item(() -> Automation.DeviceDeletionResult.newBuilder().build()); } -} + + // TODO When `DeviceRoleState` domain object will be created, move this method to Serializer class and create related tests + 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 788e6642a34d2843248fc1e720612f7e2f32596c..18d69b05bf20b4864fe84e0ffa4354441de36dd4 100644 --- a/src/automation/target/kubernetes/kubernetes.yml +++ b/src/automation/target/kubernetes/kubernetes.yml @@ -3,20 +3,20 @@ apiVersion: v1 kind: Service metadata: annotations: - app.quarkus.io/commit-id: 500a0a232ec361b669b48cc432e9bd9c332eae8b - app.quarkus.io/build-timestamp: 2022-02-11 - 10:27:21 +0000 + app.quarkus.io/commit-id: 10192a8dd76072b7c1026824117157d672385e29 + app.quarkus.io/build-timestamp: 2022-02-11 - 16:52:33 +0000 labels: app.kubernetes.io/name: automationservice app: automationservice name: automationservice spec: ports: - - name: grpc-server - port: 9999 - targetPort: 9999 - name: http port: 8080 targetPort: 8080 + - name: grpc-server + port: 9999 + targetPort: 9999 selector: app.kubernetes.io/name: automationservice type: ClusterIP @@ -25,8 +25,8 @@ apiVersion: apps/v1 kind: Deployment metadata: annotations: - app.quarkus.io/commit-id: 500a0a232ec361b669b48cc432e9bd9c332eae8b - app.quarkus.io/build-timestamp: 2022-02-11 - 10:27:21 +0000 + app.quarkus.io/commit-id: 10192a8dd76072b7c1026824117157d672385e29 + app.quarkus.io/build-timestamp: 2022-02-11 - 16:52:33 +0000 labels: app: automationservice app.kubernetes.io/name: automationservice @@ -39,8 +39,8 @@ spec: template: metadata: annotations: - app.quarkus.io/commit-id: 500a0a232ec361b669b48cc432e9bd9c332eae8b - app.quarkus.io/build-timestamp: 2022-02-11 - 10:27:21 +0000 + app.quarkus.io/commit-id: 10192a8dd76072b7c1026824117157d672385e29 + app.quarkus.io/build-timestamp: 2022-02-11 - 16:52:33 +0000 labels: app: automationservice app.kubernetes.io/name: automationservice @@ -69,12 +69,12 @@ spec: timeoutSeconds: 10 name: automationservice ports: - - containerPort: 9999 - name: grpc-server - protocol: TCP - containerPort: 8080 name: http protocol: TCP + - containerPort: 9999 + name: grpc-server + protocol: TCP readinessProbe: failureThreshold: 3 httpGet: