diff --git a/bin/build/horton_build.py b/bin/build/horton_build.py index 15a5ad36..86a3249c 100644 --- a/bin/build/horton_build.py +++ b/bin/build/horton_build.py @@ -13,7 +13,7 @@ colorama.init(autoreset=True) default_repo = "(Azure/azure-iot-sdk-BLAH)" -all_languages = ["c", "csharp", "pythonv2", "node", "java"] +all_languages = ["c", "csharp", "pythonv2", "node", "java", "javalite"] print_separator = "".join("/\\" for _ in range(80)) diff --git a/docker_images/javalite/Dockerfile b/docker_images/javalite/Dockerfile new file mode 100644 index 00000000..62465339 --- /dev/null +++ b/docker_images/javalite/Dockerfile @@ -0,0 +1,48 @@ +from mcr.microsoft.com/openjdk/jdk:11-mariner + +ENV MAVEN_CONFIG=/usr/share/maven/ref + +RUN yum install -y \ + maven \ + git +COPY javalite/settings-docker.xml /usr/share/maven/ref/settings-docker.xml + +RUN git config --global user.email "you@example.com" \ +&& git config --global user.name "Your Name" + +EXPOSE 8080 + +# force container rebuild when switching from master to main +RUN echo "switch to main" > /horton_tag.txt + +# phase 1: grab the base branch and run prebuild +ARG HORTON_REPO +WORKDIR /sdk +RUN git clone https://github.com/$HORTON_REPO . + +COPY javalite/prebuild.sh / +RUN /prebuild.sh + +# phase 2: grab the code we want to test and rebuild +ARG HORTON_COMMIT_NAME +ARG HORTON_COMMIT_SHA +WORKDIR /sdk +RUN git pull +RUN git checkout $HORTON_COMMIT_SHA + +COPY javalite/patchfile / +# our base image might have some files checked out. revert these. +RUN git reset HEAD && git checkout . && git clean -df +RUN if [ -s /patchfile ]; then git apply --index /patchfile; fi + +RUN rm -r /sdk/edge-e2e +COPY javalite/wrapper /sdk/edge-e2e + +COPY javalite/rebuild.sh / +RUN /rebuild.sh + +ENV HORTON_REPO=$HORTON_REPO +ENV HORTON_COMMIT_NAME=$HORTON_COMMIT_NAME +ENV HORTON_COMMIT_SHA=$HORTON_COMMIT_SHA + +ENTRYPOINT ["/usr/bin/java", "-jar", "/sdk/iot-e2e-tests/edge-e2e/target/iot-edge-e2e-wrapper-1.0.0-with-deps.jar"] diff --git a/docker_images/javalite/patchfile b/docker_images/javalite/patchfile new file mode 100644 index 00000000..e69de29b diff --git a/docker_images/javalite/prebuild.sh b/docker_images/javalite/prebuild.sh new file mode 100644 index 00000000..c74f7b75 --- /dev/null +++ b/docker_images/javalite/prebuild.sh @@ -0,0 +1,9 @@ +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +cd /sdk +[ $? -eq 0 ] || { echo "cd sdk failed"; exit 1; } + +mvn -s /usr/share/maven/ref/settings-docker.xml -Dmaven.test.skip=true -Dmaven.javadoc.skip=true --projects :iot-edge-e2e-wrapper --also-make install +[ $? -eq 0 ] || { echo "build sdk failed"; exit 1; } + diff --git a/docker_images/javalite/rebuild.sh b/docker_images/javalite/rebuild.sh new file mode 100644 index 00000000..c74f7b75 --- /dev/null +++ b/docker_images/javalite/rebuild.sh @@ -0,0 +1,9 @@ +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. + +cd /sdk +[ $? -eq 0 ] || { echo "cd sdk failed"; exit 1; } + +mvn -s /usr/share/maven/ref/settings-docker.xml -Dmaven.test.skip=true -Dmaven.javadoc.skip=true --projects :iot-edge-e2e-wrapper --also-make install +[ $? -eq 0 ] || { echo "build sdk failed"; exit 1; } + diff --git a/docker_images/javalite/settings-docker.xml b/docker_images/javalite/settings-docker.xml new file mode 100644 index 00000000..294444c1 --- /dev/null +++ b/docker_images/javalite/settings-docker.xml @@ -0,0 +1,6 @@ + + /usr/share/maven/ref/repository + diff --git a/docker_images/javalite/wrapper/README.md b/docker_images/javalite/wrapper/README.md new file mode 100644 index 00000000..10032633 --- /dev/null +++ b/docker_images/javalite/wrapper/README.md @@ -0,0 +1 @@ +Project generated on : 2019-12-25T14:46:26.604Z diff --git a/docker_images/javalite/wrapper/pom.xml b/docker_images/javalite/wrapper/pom.xml new file mode 100644 index 00000000..34d11e59 --- /dev/null +++ b/docker_images/javalite/wrapper/pom.xml @@ -0,0 +1,119 @@ + + + iot-device-client-lite-parent + com.microsoft.azure.sdk.iot + 1.0.0 + + 4.0.0 + + iot-edge-e2e-wrapper + 1.0.0 + + + UTF-8 + + + + + junit + junit + 4.13.1 + + + + io.vertx + vertx-unit + 3.9.9 + + + + com.github.phiz71 + vertx-swagger-router + 1.6.0 + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + 2.12.2 + + + + org.slf4j + slf4j-simple + 1.7.25 + + + + com.microsoft.azure.sdk.iot + ${iot-device-client-artifact-id} + ${iot-device-client-version} + + + + com.microsoft.azure.sdk.iot + iot-service-client + 2.1.6 + + + + com.github.jnr + jnr-unixsocket + 0.23 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + true + com.microsoft.azure.sdk.iot.e2e.Main + + + + + + maven-shade-plugin + 2.4 + + + package + + shade + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + true + with-deps + + + + + + + + diff --git a/docker_images/javalite/wrapper/src/main/java/com/microsoft/azure/sdk/iot/e2e/Main.java b/docker_images/javalite/wrapper/src/main/java/com/microsoft/azure/sdk/iot/e2e/Main.java new file mode 100644 index 00000000..80ac23b3 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/com/microsoft/azure/sdk/iot/e2e/Main.java @@ -0,0 +1,22 @@ +package com.microsoft.azure.sdk.iot.e2e; + +import io.swagger.server.api.MainApiVerticle; +import io.vertx.core.Vertx; + +public class Main { + + public static void main(String[] args) { + Vertx vertx = Vertx.vertx(); + + MainApiVerticle myVerticle = new MainApiVerticle(); + + vertx.deployVerticle(myVerticle, res -> { + if (res.succeeded()) { + System.out.println("Deployment id is: " + res.result()); + System.out.println("Listening on port " + myVerticle.getServerPort()); + } else { + System.out.println("Deployment failed!"); + } + }); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/glue/ControlGlue.java b/docker_images/javalite/wrapper/src/main/java/glue/ControlGlue.java new file mode 100644 index 00000000..e5b2800d --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/glue/ControlGlue.java @@ -0,0 +1,35 @@ +package glue; + +import io.swagger.server.api.model.LogMessage; +import io.swagger.server.api.verticle.ModuleApiImpl; +import io.swagger.server.api.verticle.RegistryApiImpl; +import io.swagger.server.api.verticle.ServiceApiImpl; +import io.vertx.core.AsyncResult; +import io.vertx.core.Future; +import io.vertx.core.Handler; +import io.vertx.core.json.JsonObject; + +public class ControlGlue +{ + public void Cleanup(Handler> handler) + { + ModuleApiImpl._moduleGlue.Cleanup(); + RegistryApiImpl._registryGlue.Cleanup(); + ServiceApiImpl._serviceGlue.Cleanup(); + handler.handle(Future.succeededFuture()); + } + + public void outputMessage(LogMessage logMessage, Handler> handler) + { + System.out.println(logMessage.getMessage()); + handler.handle(Future.succeededFuture()); + } + + public void getCapabilities(Handler> handler) + { + JsonObject caps = new JsonObject("{"+ + "\"flags\": {}"+ + "}"); + handler.handle(Future.succeededFuture(caps)); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/glue/ModuleGlue.java b/docker_images/javalite/wrapper/src/main/java/glue/ModuleGlue.java new file mode 100644 index 00000000..17049421 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/glue/ModuleGlue.java @@ -0,0 +1,551 @@ +package glue; + +import com.microsoft.azure.sdk.iot.device.ClientOptions; +import com.microsoft.azure.sdk.iot.device.IotHubClientProtocol; +import com.microsoft.azure.sdk.iot.device.ModuleClient; +import com.microsoft.azure.sdk.iot.device.authentication.IotHubSSLContext; +import com.microsoft.azure.sdk.iot.device.delegates.MessageCallback; +import com.microsoft.azure.sdk.iot.device.delegates.MethodCallback; +import com.microsoft.azure.sdk.iot.device.models.DirectMethodPayload; +import com.microsoft.azure.sdk.iot.device.models.DirectMethodResponse; +import com.microsoft.azure.sdk.iot.device.models.Message; +import com.microsoft.azure.sdk.iot.device.models.TwinCollection; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.*; +import io.vertx.core.AsyncResult; +import io.vertx.core.Future; +import io.vertx.core.Handler; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonObject; +import org.eclipse.paho.client.mqttv3.MqttException; + +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + + +public class ModuleGlue +{ + private IotHubClientProtocol transportFromString(String protocolStr) + { + IotHubClientProtocol protocol = null; + + if (protocolStr.equals("mqtt")) + { + protocol = IotHubClientProtocol.TCP; + } + else + { + throw new RuntimeException("Only MQTT is implemented"); + } + + return protocol; + } + + HashMap _map = new HashMap<>(); + int _clientCount = 0; + + public void connectFromEnvironment(String transportType, Handler> handler) + { + System.out.printf("ConnectFromEnvironment called with transport %s%n", transportType); + + IotHubClientProtocol protocol = this.transportFromString(transportType); + if (protocol == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid transport"))); + return; + } + + try + { + ModuleClient client = ModuleClient.createFromEnvironment(new UnixDomainSocketChannelImpl(), protocol); + client.open(); + + this._clientCount++; + String connectionId = "moduleClient_" + this._clientCount; + this._map.put(connectionId, client); + + ConnectResponse cr = new ConnectResponse(); + cr.setConnectionId(connectionId); + handler.handle(Future.succeededFuture(cr)); + } catch (Exception e) + { + handler.handle(Future.failedFuture(e)); + } + } + + private ModuleClient getClient(String connectionId) + { + return this._map.getOrDefault(connectionId, null); + } + + public void connect(String transportType, String connectionString, Certificate caCertificate, Handler> handler) + { + System.out.printf("Connect called with transport %s%n", transportType); + + IotHubClientProtocol protocol = this.transportFromString(transportType); + if (protocol == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid transport"))); + return; + } + + try + { + String cert = caCertificate.getCert(); + ClientOptions.ClientOptionsBuilder clientOptionsBuilder = ClientOptions.builder(); + if (cert != null && !cert.isEmpty()) + { + clientOptionsBuilder.sslContext(IotHubSSLContext.getSSLContextFromFile(cert)); + } + + ModuleClient client = new ModuleClient(connectionString, protocol, clientOptionsBuilder.build()); + + client.open(); + + this._clientCount++; + String connectionId = "moduleClient_" + this._clientCount; + this._map.put(connectionId, client); + + ConnectResponse cr = new ConnectResponse(); + cr.setConnectionId(connectionId); + handler.handle(Future.succeededFuture(cr)); + } catch (Exception e) + { + handler.handle(Future.failedFuture(e)); + } + } + + + public void invokeDeviceMethod(String connectionId, String deviceId, MethodInvoke methodInvokeParameters, Handler> handler) + { + handler.handle(Future.failedFuture(new MainApiException(500, "Module to device methods are not supported in this SDK"))); + } + + private void _closeConnection(String connectionId) + { + System.out.printf("Disconnect for %s%n", connectionId); + ModuleClient client = getClient(connectionId); + if (client != null) + { + try + { + client.close(); + } + catch (Exception e) + { + //Ignore + } + this._map.remove(connectionId); + } + } + + public void disconnect(String connectionId, Handler> handler) + { + this._closeConnection(connectionId); + handler.handle(Future.succeededFuture()); + } + + public void enableInputMessages(String connectionId, Handler> handler) + { + ModuleClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + handler.handle(Future.succeededFuture()); + } + } + + private Twin _twin = null; + private Handler> _twinHandler; + private Timer _timer = null; + + public void setTwinHandler(Handler> handler) + { + if (handler == null) + { + this._twin = null; + } + else + { + this._twin = new Twin(new JsonObject(), new JsonObject()); + + } + this._twinHandler = handler; + } + + public void onPropertyChanged(String key, Object value, int version, boolean isReported) + { + System.out.println( + "onProperty callback for " + (isReported ? "reported" : "desired") + + " property " + key + + " to " + value + + ", Properties version:" + version); + if (this._twin == null) + { + System.out.println("nobody is listening for desired properties. ignoring."); + } + else + { + if (isReported) + { + ((JsonObject) this._twin.getReported()).getMap().put(key, value); + } + else + { + ((JsonObject) this._twin.getDesired()).getMap().put(key, value); + } + System.out.println(this._twin.toString()); + System.out.println("scheduling timer"); + this.rescheduleTwinHandler(); + } + } + + private void rescheduleTwinHandler() + { + if (_twinHandler == null) + { + return; + } + // call _handler 2 seconds after the last designed property change + if (this._timer != null) + { + this._timer.cancel(); + this._timer = null; + } + this._timer = new Timer(); + this._timer.schedule(new TimerTask() + { + @Override + public void run() + { + _timer = null; + if (_twinHandler != null && _twin != null) + { + System.out.println("It's been 2 seconds since last desired property arrived. Calling handler"); + System.out.println(_twin.toString()); + _twinHandler.handle(Future.succeededFuture(_twin)); + _twinHandler = null; + } + } + }, 2000); + } + + public void enableTwin(String connectionId, final Handler> handler) + { + final ModuleClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + try + { + System.out.println("calling subscribeToDesiredProperties to start twin"); + client.subscribeToDesiredProperties( + (desiredProperties) -> + { + for (String key : desiredProperties.keySet()) + { + onPropertyChanged(key, desiredProperties.get(key), desiredProperties.getVersion(), true); + } + }); + + handler.handle(Future.succeededFuture()); + } + catch (Exception e) + { + handler.handle(Future.failedFuture((e))); + } + } + } + + private void sendEventHelper(String connectionId, Message msg, Handler> handler) + { + System.out.println("inside sendEventHelper"); + + ModuleClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + System.out.printf("calling sendEvent%n"); + try + { + client.sendEvent(msg); + } + catch (Exception e) + { + handler.handle(Future.failedFuture(new MainApiException(500, e.getMessage()))); + } + } + } + + public void sendEvent(String connectionId, EventBody eventBody, Handler> handler) + { + System.out.printf("moduleConnectionIdEventPut called for %s%n", connectionId); + System.out.println(eventBody); + this.sendEventHelper(connectionId, new Message(Json.encode(eventBody.getBody())), handler); + } + + protected static class InputMessageCallback implements MessageCallback + { + ModuleClient _client; + Handler> _handler; + String _inputName; + + public InputMessageCallback(ModuleClient client, String inputName, Handler> handler) + { + this._client = client; + this._inputName = inputName; + this._handler = handler; + } + + public synchronized void onMessageReceived(Message msg) + { + System.out.println("MessageCallback called"); + String result = new String(msg.getPayload(), StandardCharsets.UTF_8); + System.out.printf("result = %s%n", result); + if (this._handler != null) + { + if (this._inputName.equals(msg.getInputName())) + { + this._handler.handle(Future.succeededFuture(new EventBody(new JsonObject(result), new JsonObject(), new JsonObject()))); + } + else + { + this._handler.handle(Future.failedFuture(new MainApiException(500, "Received the an input message with the wrong input name"))); + } + } + } + } + + public void waitForInputMessage(String connectionId, String inputName, Handler> handler) + { + System.out.printf("waitForInputMessage with %s, %s%n", connectionId, inputName); + + ModuleClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + MessageCallback callback = new InputMessageCallback(client, inputName, handler); + System.out.printf("calling setMessageCallback%n"); + try + { + client.subscribeToInputMessages(callback); + } + catch (Exception e) + { + handler.handle(Future.failedFuture(new MainApiException(500, e.getMessage()))); + } + } + } + + private static class DeviceMethodCallbackImpl implements MethodCallback + { + public Handler> _handler; + public String _requestBody; + public String _responseBody; + public String _methodName; + public int _statusCode; + public ModuleClient _client; + + public void reset() + { + this._methodName = null; + this._handler = null; + } + + @Override + public DirectMethodResponse onMethodInvoked(String methodName, DirectMethodPayload methodData, Object context) + { + System.out.printf("method %s called%n", methodName); + if (methodName.equals(this._methodName)) + { + System.out.println("Received payload:"); + System.out.println(methodData.getPayloadAsJsonString()); + + Object methodDataObject = methodData.getPayload(Map.class); + System.out.printf("methodData: %s%n", methodDataObject); + + if (methodDataObject.equals(this._requestBody) || + Json.encode(methodDataObject).equals(this._requestBody)) + { + System.out.printf("Method data looks correct. Returning result: %s%n", _responseBody); + this._handler.handle(Future.succeededFuture()); + this.reset(); + return new DirectMethodResponse(this._statusCode, this._responseBody); + } + else + { + System.out.printf("method data does not match. Expected %s%n", this._requestBody); + this._handler.handle(Future.failedFuture("methodData does not match")); + this.reset(); + return new DirectMethodResponse(500, "methodData not received as expected"); + } + } + else + { + this._handler.handle(Future.failedFuture("unexpected call: " + methodName)); + this.reset(); + return new DirectMethodResponse(404, "method " + methodName + " not handled"); + } + } + } + + DeviceMethodCallbackImpl _methodCallback = new DeviceMethodCallbackImpl(); + + public void enableMethods(String connectionId, Handler> handler) + { + ModuleClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + try + { + client.subscribeToMethods(this._methodCallback); + } + catch (Exception e) + { + handler.handle(Future.failedFuture(new MainApiException(500, e.getMessage()))); + } + } + } + + public void WaitForMethodAndReturnResponse(String connectionId, String methodName, MethodRequestAndResponse requestAndResponse, Handler> handler) + { + ModuleClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + _methodCallback._handler = handler; + _methodCallback._requestBody = Json.encode(((LinkedHashMap) requestAndResponse.getRequestPayload()).get("payload")); + _methodCallback._responseBody = Json.encode(requestAndResponse.getResponsePayload()); + _methodCallback._statusCode = requestAndResponse.getStatusCode(); + _methodCallback._client = client; + _methodCallback._methodName = methodName; + } + } + + public void invokeModuleMethod(String connectionId, String deviceId, String moduleId, MethodInvoke methodInvokeParameters, Handler> handler) + { + handler.handle(Future.failedFuture(new MainApiException(500, "Module to device methods are not supported in this SDK"))); + } + + public void sendOutputEvent(String connectionId, String outputName, EventBody eventBody, Handler> handler) + { + System.out.printf("sendOutputEvent called for %s, %s%n", connectionId, outputName); + System.out.println(eventBody); + Message msg = new Message(Json.encode(eventBody.getBody())); + msg.setOutputName(outputName); + this.sendEventHelper(connectionId, msg, handler); + } + + public void waitForDesiredPropertyPatch(String connectionId, Handler> handler) + { + System.out.printf("waitForDesiredPropertyPatch with %s%n", connectionId); + + ModuleClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + this.setTwinHandler(res -> { + if (res.succeeded()) + { + handler.handle(Future.succeededFuture(res.result())); + } + else + { + handler.handle(res); + } + }); + + } + } + + public void getTwin(String connectionId, Handler> handler) + { + System.out.printf("getTwin with %s%n", connectionId); + + ModuleClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + this.setTwinHandler(handler); + try + { + com.microsoft.azure.sdk.iot.device.models.Twin twin = client.getTwin(); + TwinCollection desiredProperties = twin.getDesiredProperties(); + for (String key : desiredProperties.keySet()) + { + onPropertyChanged(key, desiredProperties.get(key), twin.getDesiredProperties().getVersion(), false); + } + } + catch (Exception e) + { + this.setTwinHandler(null); + handler.handle(Future.failedFuture(e)); + } + } + } + + public void sendTwinPatch(String connectionId, Twin twin, Handler> handler) + { + System.out.printf("sendTwinPatch called for %s%n", connectionId); + System.out.println(twin.toString()); + + ModuleClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + TwinCollection reportedProperties = new TwinCollection((LinkedHashMap)twin.getReported()); + try + { + reportedProperties.setVersion(client.getTwin().getReportedProperties().getVersion()); + client.updateReportedProperties(reportedProperties); + handler.handle(Future.succeededFuture()); + } + catch (Exception e) + { + handler.handle(Future.failedFuture(e)); + } + } + } + + public void Cleanup() + { + Set keys = this._map.keySet(); + if (!keys.isEmpty()) + { + for (String key : keys) + { + this._closeConnection(key); + } + } + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/glue/RegistryGlue.java b/docker_images/javalite/wrapper/src/main/java/glue/RegistryGlue.java new file mode 100644 index 00000000..ef61edc2 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/glue/RegistryGlue.java @@ -0,0 +1,125 @@ +package glue; + +import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException; +import com.microsoft.azure.sdk.iot.service.twin.TwinClient; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.Twin; +import io.vertx.core.AsyncResult; +import io.vertx.core.Future; +import io.vertx.core.Handler; +import io.vertx.core.json.JsonObject; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class RegistryGlue +{ + HashMap _map = new HashMap<>(); + int _clientCount = 0; + + public void connect(String connectionString, Handler> handler) + { + System.out.printf("Connect called%n"); + TwinClient client = new TwinClient(connectionString); + + this._clientCount++; + String connectionId = "registryClient_" + this._clientCount; + this._map.put(connectionId, client); + + ConnectResponse cr = new ConnectResponse(); + cr.setConnectionId(connectionId); + handler.handle(Future.succeededFuture(cr)); + } + + private TwinClient getClient(String connectionId) + { + return this._map.getOrDefault(connectionId, null); + } + + private void _closeConnection(String connectionId) + { + System.out.printf("Disconnect for %s%n", connectionId); + TwinClient client = getClient(connectionId); + if (client != null) + { + this._map.remove(connectionId); + } + } + + public void disconnect(String connectionId, Handler> handler) + { + this._closeConnection(connectionId); + handler.handle(Future.succeededFuture()); + } + + public void getModuleTwin(String connectionId, String deviceId, String moduleId, Handler> handler) + { + System.out.printf("getModuleTwin called for %s with deviceId = %s and moduleId = %s%n", connectionId, deviceId, moduleId); + + TwinClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + com.microsoft.azure.sdk.iot.service.twin.Twin twin; + try + { + twin = client.get(deviceId, moduleId); + Twin hortonTwin = new Twin(new JsonObject(twin.getDesiredProperties()), new JsonObject(twin.getReportedProperties())); + handler.handle(Future.succeededFuture(hortonTwin)); + } + catch (Exception e) + { + handler.handle(Future.failedFuture(e)); + } + } + } + + public void sendModuleTwinPatch(String connectionId, String deviceId, String moduleId, Twin twin, Handler> handler) + { + System.out.printf("sendModuleTwinPatch called for %s with deviceId = %s and moduleId = %s%n", connectionId, deviceId, moduleId); + System.out.println(twin.toString()); + + TwinClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + com.microsoft.azure.sdk.iot.service.twin.Twin serviceTwin = new com.microsoft.azure.sdk.iot.service.twin.Twin(deviceId, moduleId); + + Map desiredProps = (Map)twin.getDesired(); + serviceTwin.getDesiredProperties().putAll(desiredProps); + + try + { + client.patch(serviceTwin); + } + catch (Exception e) + { + handler.handle(Future.failedFuture(e)); + } + + + handler.handle(Future.succeededFuture()); + } + } + + public void Cleanup() + { + Set keys = this._map.keySet(); + if (!keys.isEmpty()) + { + for (String key : keys) + { + this._closeConnection(key); + } + } + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/glue/ServiceGlue.java b/docker_images/javalite/wrapper/src/main/java/glue/ServiceGlue.java new file mode 100644 index 00000000..4d278ebd --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/glue/ServiceGlue.java @@ -0,0 +1,155 @@ +package glue; + +import com.google.gson.JsonSyntaxException; +import com.microsoft.azure.sdk.iot.service.exceptions.IotHubException; +import com.microsoft.azure.sdk.iot.service.methods.DirectMethodRequestOptions; +import com.microsoft.azure.sdk.iot.service.methods.DirectMethodsClient; +import com.microsoft.azure.sdk.iot.service.methods.DirectMethodResponse; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.MethodInvoke; +import io.vertx.core.AsyncResult; +import io.vertx.core.Future; +import io.vertx.core.Handler; +import io.vertx.core.json.JsonObject; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class ServiceGlue +{ + HashMap _map = new HashMap<>(); + int _clientCount = 0; + + public void connect(String connectionString, Handler> handler) + { + System.out.printf("connect called%n"); + DirectMethodsClient client = new DirectMethodsClient(connectionString); + + this._clientCount++; + String connectionId = "serviceClient_" + this._clientCount; + this._map.put(connectionId, client); + + ConnectResponse cr = new ConnectResponse(); + cr.setConnectionId(connectionId); + handler.handle(Future.succeededFuture(cr)); + } + + private DirectMethodsClient getClient(String connectionId) + { + return this._map.getOrDefault(connectionId, null); + } + + + private void _closeConnection(String connectionId) + { + System.out.printf("Disconnect for %s%n", connectionId); + DirectMethodsClient client = getClient(connectionId); + if (client != null) + { + this._map.remove(connectionId); + } + } + + public void disconnect(String connectionId, Handler> handler) + { + _closeConnection(connectionId); + handler.handle(Future.succeededFuture()); + } + + private void invokeMethodCommon(String connectionId, String deviceId, String moduleId, MethodInvoke methodInvokeParameters, Handler> handler) + { + System.out.printf("invoking method on %s with deviceId = %s moduleId = %s%n", connectionId, deviceId, moduleId); + System.out.println(methodInvokeParameters); + + DirectMethodsClient client = getClient(connectionId); + if (client == null) + { + handler.handle(Future.failedFuture(new MainApiException(500, "invalid connection id"))); + } + else + { + String methodName = methodInvokeParameters.getMethodName(); + Object payload = methodInvokeParameters.getPayload(); + + System.out.println("The payload type is: " + payload.getClass()); + + DirectMethodRequestOptions requestOptions = + DirectMethodRequestOptions.builder() + .methodResponseTimeoutSeconds(methodInvokeParameters.getResponseTimeoutInSeconds()) + .methodConnectTimeoutSeconds(methodInvokeParameters.getConnectTimeoutInSeconds()) + .payload(payload) + .build(); + + DirectMethodResponse result = null; + System.out.printf("invoking%n"); + try + { + if (moduleId == null) + { + result = client.invoke(deviceId, methodName, requestOptions); + } + else + { + result = client.invoke(deviceId, moduleId, methodName, requestOptions); + } + } + catch (Exception e) + { + handler.handle(Future.failedFuture(e)); + } + System.out.printf("invoke returned%n"); + System.out.println(result); + handler.handle(Future.succeededFuture(makeMethodResultThatEncodesCorrectly(result))); + } + } + + private JsonObject makeMethodResultThatEncodesCorrectly(DirectMethodResponse result) + { + // Our JSON encoder doesn't like the way the MethodClass implements getPayload. The easiest + // workaround is to make an empty JsonObject and copy the values over manually. I'm sure + // there's a better way, but this is test code. + JsonObject fixedObject = new JsonObject(); + fixedObject.put("status", result.getStatus()); + + System.out.println("Received payload:"); + System.out.println(result.getPayloadAsJsonString()); + + try + { + fixedObject.put("payload", result.getPayload(String.class)); + } + catch (JsonSyntaxException e) + { + System.out.println("Could not parse payload as a string, will try to parse it as a map"); + fixedObject.put("payload", result.getPayload(Map.class)); + } + + return fixedObject; + } + + public void invokeDeviceMethod(String connectionId, String deviceId, MethodInvoke methodInvokeParameters, Handler> handler) + { + invokeMethodCommon(connectionId, deviceId, null, methodInvokeParameters, handler); + + } + + public void invokeModuleMethod(String connectionId, String deviceId, String moduleId, MethodInvoke methodInvokeParameters, Handler> handler) + { + invokeMethodCommon(connectionId, deviceId, moduleId, methodInvokeParameters, handler); + } + + public void Cleanup() + { + Set keys = this._map.keySet(); + if (!keys.isEmpty()) + { + for (String key : keys) + { + this._closeConnection(key); + } + } + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/glue/UnixDomainSocketChannelImpl.java b/docker_images/javalite/wrapper/src/main/java/glue/UnixDomainSocketChannelImpl.java new file mode 100644 index 00000000..a7be505d --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/glue/UnixDomainSocketChannelImpl.java @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package glue; + +import com.microsoft.azure.sdk.iot.device.edge.hsm.UnixDomainSocketChannel; +import jnr.unixsocket.UnixSocketAddress; +import jnr.unixsocket.UnixSocketChannel; + +import java.io.IOException; +import java.nio.ByteBuffer; + +public class UnixDomainSocketChannelImpl implements UnixDomainSocketChannel +{ + private UnixSocketChannel channel; + + @Override + public void open(String address) throws IOException + { + this.channel = UnixSocketChannel.open(new UnixSocketAddress(address)); + } + + @Override + public void write(byte[] output) throws IOException + { + this.channel.write(ByteBuffer.wrap(output)); + } + + @Override + public int read(byte[] inputBuffer) throws IOException + { + ByteBuffer inputByteBuffer = ByteBuffer.wrap(inputBuffer); + int bytesRead = this.channel.read(inputByteBuffer); + System.arraycopy(inputByteBuffer.array(), 0, inputBuffer, 0, inputByteBuffer.capacity()); + return bytesRead; + } + + @Override + public void close() throws IOException + { + this.channel.close(); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/MainApiException.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/MainApiException.java new file mode 100644 index 00000000..f06a480b --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/MainApiException.java @@ -0,0 +1,22 @@ +package io.swagger.server.api; + +public class MainApiException extends Exception { + private int statusCode; + private String statusMessage; + + public MainApiException(int statusCode, String statusMessage) { + super(); + this.statusCode = statusCode; + this.statusMessage = statusMessage; + } + + public int getStatusCode() { + return statusCode; + } + + public String getStatusMessage() { + return statusMessage; + } + + public static final MainApiException INTERNAL_SERVER_ERROR = new MainApiException(500, "Internal Server Error"); +} \ No newline at end of file diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/MainApiVerticle.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/MainApiVerticle.java new file mode 100644 index 00000000..28ba25b1 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/MainApiVerticle.java @@ -0,0 +1,134 @@ +package io.swagger.server.api; + +import java.nio.charset.Charset; + +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import com.github.phiz71.vertx.swagger.router.OperationIdServiceIdResolver; +import com.github.phiz71.vertx.swagger.router.SwaggerRouter; + +import io.swagger.models.Swagger; +import io.swagger.parser.SwaggerParser; +import io.vertx.core.AbstractVerticle; +import io.vertx.core.Context; +import io.vertx.core.Future; +import io.vertx.core.file.FileSystem; +import io.vertx.core.json.Json; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; +import io.vertx.core.Vertx; +import io.vertx.ext.web.Router; + +// Added 3 lines in merge +import java.util.function.Function; +import io.vertx.core.eventbus.DeliveryOptions; +import io.vertx.ext.web.RoutingContext; + +public class MainApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(MainApiVerticle.class); + + private int serverPort = 8080; + protected Router router; + + public int getServerPort() { + return serverPort; + } + + public void setServerPort(int serverPort) { + this.serverPort = serverPort; + } + + @Override + public void init(Vertx vertx, Context context) { + super.init(vertx, context); + router = Router.router(vertx); + } + + @Override + public void start(Future startFuture) throws Exception { + Json.mapper.registerModule(new JavaTimeModule()); + FileSystem vertxFileSystem = vertx.fileSystem(); + vertxFileSystem.readFile("swagger.json", readFile -> { + if (readFile.succeeded()) { + Swagger swagger = new SwaggerParser().parse(readFile.result().toString(Charset.forName("utf-8"))); + // Changed constructor in merge to add setSendTimeout() + Router swaggerRouter = SwaggerRouter.swaggerRouter(router, swagger, vertx.eventBus(), new OperationIdServiceIdResolver(), new Function() { + @Override + public DeliveryOptions apply(RoutingContext t) { + return new DeliveryOptions().setSendTimeout(90000); + } + }); + deployVerticles(startFuture); + + vertx.createHttpServer() + .requestHandler(swaggerRouter::accept) + .listen(serverPort, h -> { + if (h.succeeded()) { + startFuture.complete(); + } else { + startFuture.fail(h.cause()); + } + }); + } else { + startFuture.fail(readFile.cause()); + } + }); + } + + public void deployVerticles(Future startFuture) { + + vertx.deployVerticle("io.swagger.server.api.verticle.ControlApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("ControlApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("ControlApiVerticle : Deployment failed"); + } + }); + + vertx.deployVerticle("io.swagger.server.api.verticle.DeviceApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("DeviceApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("DeviceApiVerticle : Deployment failed"); + } + }); + + vertx.deployVerticle("io.swagger.server.api.verticle.ModuleApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("ModuleApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("ModuleApiVerticle : Deployment failed"); + } + }); + + vertx.deployVerticle("io.swagger.server.api.verticle.NetApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("NetApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("NetApiVerticle : Deployment failed"); + } + }); + + vertx.deployVerticle("io.swagger.server.api.verticle.RegistryApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("RegistryApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("RegistryApiVerticle : Deployment failed"); + } + }); + + vertx.deployVerticle("io.swagger.server.api.verticle.ServiceApiVerticle", res -> { + if (res.succeeded()) { + LOGGER.info("ServiceApiVerticle : Deployed"); + } else { + startFuture.fail(res.cause()); + LOGGER.error("ServiceApiVerticle : Deployment failed"); + } + }); + + } +} \ No newline at end of file diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/Certificate.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/Certificate.java new file mode 100644 index 00000000..5676865c --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/Certificate.java @@ -0,0 +1,70 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * certificate in the body of a message + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Certificate { + + private String cert = null; + + public Certificate () { + + } + + public Certificate (String cert) { + this.cert = cert; + } + + + @JsonProperty("cert") + public String getCert() { + return cert; + } + public void setCert(String cert) { + this.cert = cert; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Certificate certificate = (Certificate) o; + return Objects.equals(cert, certificate.cert); + } + + @Override + public int hashCode() { + return Objects.hash(cert); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Certificate {\n"); + + sb.append(" cert: ").append(toIndentedString(cert)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/ConnectResponse.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/ConnectResponse.java new file mode 100644 index 00000000..a699baf0 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/ConnectResponse.java @@ -0,0 +1,70 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * result of a connection to a service, device, or module client + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ConnectResponse { + + private String connectionId = null; + + public ConnectResponse () { + + } + + public ConnectResponse (String connectionId) { + this.connectionId = connectionId; + } + + + @JsonProperty("connectionId") + public String getConnectionId() { + return connectionId; + } + public void setConnectionId(String connectionId) { + this.connectionId = connectionId; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ConnectResponse connectResponse = (ConnectResponse) o; + return Objects.equals(connectionId, connectResponse.connectionId); + } + + @Override + public int hashCode() { + return Objects.hash(connectionId); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ConnectResponse {\n"); + + sb.append(" connectionId: ").append(toIndentedString(connectionId)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/EventBody.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/EventBody.java new file mode 100644 index 00000000..5f52eb85 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/EventBody.java @@ -0,0 +1,96 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * body for an invoming or outgoing event or message + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class EventBody { + + private Object body = null; + private Object hortonFlags = null; + private Object attributes = null; + + public EventBody () { + + } + + public EventBody (Object body, Object hortonFlags, Object attributes) { + this.body = body; + this.hortonFlags = hortonFlags; + this.attributes = attributes; + } + + + @JsonProperty("body") + public Object getBody() { + return body; + } + public void setBody(Object body) { + this.body = body; + } + + + @JsonProperty("horton_flags") + public Object getHortonFlags() { + return hortonFlags; + } + public void setHortonFlags(Object hortonFlags) { + this.hortonFlags = hortonFlags; + } + + + @JsonProperty("attributes") + public Object getAttributes() { + return attributes; + } + public void setAttributes(Object attributes) { + this.attributes = attributes; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + EventBody eventBody = (EventBody) o; + return Objects.equals(body, eventBody.body) && + Objects.equals(hortonFlags, eventBody.hortonFlags) && + Objects.equals(attributes, eventBody.attributes); + } + + @Override + public int hashCode() { + return Objects.hash(body, hortonFlags, attributes); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class EventBody {\n"); + + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" hortonFlags: ").append(toIndentedString(hortonFlags)).append("\n"); + sb.append(" attributes: ").append(toIndentedString(attributes)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/LogMessage.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/LogMessage.java new file mode 100644 index 00000000..687211e0 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/LogMessage.java @@ -0,0 +1,70 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * message from the test script to output to the log + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class LogMessage { + + private String message = null; + + public LogMessage () { + + } + + public LogMessage (String message) { + this.message = message; + } + + + @JsonProperty("message") + public String getMessage() { + return message; + } + public void setMessage(String message) { + this.message = message; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + LogMessage logMessage = (LogMessage) o; + return Objects.equals(message, logMessage.message); + } + + @Override + public int hashCode() { + return Objects.hash(message); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class LogMessage {\n"); + + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/MethodInvoke.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/MethodInvoke.java new file mode 100644 index 00000000..87f4bc91 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/MethodInvoke.java @@ -0,0 +1,109 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * parameters used to invoke a method + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class MethodInvoke { + + private String methodName = null; + private Object payload = null; + private Integer responseTimeoutInSeconds = null; + private Integer connectTimeoutInSeconds = null; + + public MethodInvoke () { + + } + + public MethodInvoke (String methodName, Object payload, Integer responseTimeoutInSeconds, Integer connectTimeoutInSeconds) { + this.methodName = methodName; + this.payload = payload; + this.responseTimeoutInSeconds = responseTimeoutInSeconds; + this.connectTimeoutInSeconds = connectTimeoutInSeconds; + } + + + @JsonProperty("methodName") + public String getMethodName() { + return methodName; + } + public void setMethodName(String methodName) { + this.methodName = methodName; + } + + + @JsonProperty("payload") + public Object getPayload() { + return payload; + } + public void setPayload(Object payload) { + this.payload = payload; + } + + + @JsonProperty("responseTimeoutInSeconds") + public Integer getResponseTimeoutInSeconds() { + return responseTimeoutInSeconds; + } + public void setResponseTimeoutInSeconds(Integer responseTimeoutInSeconds) { + this.responseTimeoutInSeconds = responseTimeoutInSeconds; + } + + + @JsonProperty("connectTimeoutInSeconds") + public Integer getConnectTimeoutInSeconds() { + return connectTimeoutInSeconds; + } + public void setConnectTimeoutInSeconds(Integer connectTimeoutInSeconds) { + this.connectTimeoutInSeconds = connectTimeoutInSeconds; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MethodInvoke methodInvoke = (MethodInvoke) o; + return Objects.equals(methodName, methodInvoke.methodName) && + Objects.equals(payload, methodInvoke.payload) && + Objects.equals(responseTimeoutInSeconds, methodInvoke.responseTimeoutInSeconds) && + Objects.equals(connectTimeoutInSeconds, methodInvoke.connectTimeoutInSeconds); + } + + @Override + public int hashCode() { + return Objects.hash(methodName, payload, responseTimeoutInSeconds, connectTimeoutInSeconds); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MethodInvoke {\n"); + + sb.append(" methodName: ").append(toIndentedString(methodName)).append("\n"); + sb.append(" payload: ").append(toIndentedString(payload)).append("\n"); + sb.append(" responseTimeoutInSeconds: ").append(toIndentedString(responseTimeoutInSeconds)).append("\n"); + sb.append(" connectTimeoutInSeconds: ").append(toIndentedString(connectTimeoutInSeconds)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/MethodRequestAndResponse.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/MethodRequestAndResponse.java new file mode 100644 index 00000000..c7a9f272 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/MethodRequestAndResponse.java @@ -0,0 +1,96 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * parameters and response for a sync method call + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class MethodRequestAndResponse { + + private Object requestPayload = null; + private Object responsePayload = null; + private Integer statusCode = null; + + public MethodRequestAndResponse () { + + } + + public MethodRequestAndResponse (Object requestPayload, Object responsePayload, Integer statusCode) { + this.requestPayload = requestPayload; + this.responsePayload = responsePayload; + this.statusCode = statusCode; + } + + + @JsonProperty("requestPayload") + public Object getRequestPayload() { + return requestPayload; + } + public void setRequestPayload(Object requestPayload) { + this.requestPayload = requestPayload; + } + + + @JsonProperty("responsePayload") + public Object getResponsePayload() { + return responsePayload; + } + public void setResponsePayload(Object responsePayload) { + this.responsePayload = responsePayload; + } + + + @JsonProperty("statusCode") + public Integer getStatusCode() { + return statusCode; + } + public void setStatusCode(Integer statusCode) { + this.statusCode = statusCode; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MethodRequestAndResponse methodRequestAndResponse = (MethodRequestAndResponse) o; + return Objects.equals(requestPayload, methodRequestAndResponse.requestPayload) && + Objects.equals(responsePayload, methodRequestAndResponse.responsePayload) && + Objects.equals(statusCode, methodRequestAndResponse.statusCode); + } + + @Override + public int hashCode() { + return Objects.hash(requestPayload, responsePayload, statusCode); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MethodRequestAndResponse {\n"); + + sb.append(" requestPayload: ").append(toIndentedString(requestPayload)).append("\n"); + sb.append(" responsePayload: ").append(toIndentedString(responsePayload)).append("\n"); + sb.append(" statusCode: ").append(toIndentedString(statusCode)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/Twin.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/Twin.java new file mode 100644 index 00000000..86733f99 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/model/Twin.java @@ -0,0 +1,83 @@ +package io.swagger.server.api.model; + +import java.util.Objects; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * device twin or module twin + **/ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Twin { + + private Object desired = null; + private Object reported = null; + + public Twin () { + + } + + public Twin (Object desired, Object reported) { + this.desired = desired; + this.reported = reported; + } + + + @JsonProperty("desired") + public Object getDesired() { + return desired; + } + public void setDesired(Object desired) { + this.desired = desired; + } + + + @JsonProperty("reported") + public Object getReported() { + return reported; + } + public void setReported(Object reported) { + this.reported = reported; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Twin twin = (Twin) o; + return Objects.equals(desired, twin.desired) && + Objects.equals(reported, twin.reported); + } + + @Override + public int hashCode() { + return Objects.hash(desired, reported); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Twin {\n"); + + sb.append(" desired: ").append(toIndentedString(desired)).append("\n"); + sb.append(" reported: ").append(toIndentedString(reported)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApi.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApi.java new file mode 100644 index 00000000..350b3b2a --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApi.java @@ -0,0 +1,28 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.LogMessage; +import io.swagger.server.api.MainApiException; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +public interface ControlApi { + //Control_Cleanup + void controlCleanup(Handler> handler); + + //Control_GetCapabilities + void controlGetCapabilities(Handler> handler); + + //Control_LogMessage + void controlLogMessage(LogMessage logMessage, Handler> handler); + + //Control_SendCommand + void controlSendCommand(String cmd, Handler> handler); + + //Control_SetFlags + void controlSetFlags(Object flags, Handler> handler); + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApiException.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApiException.java new file mode 100644 index 00000000..b0a575a3 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApiException.java @@ -0,0 +1,13 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.LogMessage; +import io.swagger.server.api.MainApiException; + +public final class ControlApiException extends MainApiException { + public ControlApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + + +} \ No newline at end of file diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApiImpl.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApiImpl.java new file mode 100644 index 00000000..50ec65eb --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApiImpl.java @@ -0,0 +1,58 @@ +package io.swagger.server.api.verticle; + +// Added 1 line in merge +import glue.ControlGlue; + +import io.swagger.server.api.MainApiException; + +import io.swagger.server.api.model.LogMessage; +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +// Added all Override annotations and method bodies in merge + +// Changed from interface to class in merge +public class ControlApiImpl implements ControlApi +{ + // Added 1 line in merge + private ControlGlue _ControlGlue= new ControlGlue(); + + //Control_Cleanup + @Override + public void controlCleanup(Handler> handler) + { + this._ControlGlue.Cleanup(handler); + } + + //Control_GetCapabilities + @Override + public void controlGetCapabilities(Handler> handler) + { + _ControlGlue.getCapabilities(handler); + } + + //Control_LogMessage + @Override + public void controlLogMessage(LogMessage logMessage, Handler> handler) + { + this._ControlGlue.outputMessage(logMessage, handler); + } + + //Control_SendCommand + @Override + public void controlSendCommand(String cmd, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Control_SetFlags + @Override + public void controlSetFlags(Object flags, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApiVerticle.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApiVerticle.java new file mode 100644 index 00000000..13301516 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ControlApiVerticle.java @@ -0,0 +1,172 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.model.LogMessage; +import io.swagger.server.api.MainApiException; + +import java.util.List; +import java.util.Map; + +public class ControlApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(ControlApiVerticle.class); + + final static String CONTROL_CLEANUP_SERVICE_ID = "Control_Cleanup"; + final static String CONTROL_GETCAPABILITIES_SERVICE_ID = "Control_GetCapabilities"; + final static String CONTROL_LOGMESSAGE_SERVICE_ID = "Control_LogMessage"; + final static String CONTROL_SENDCOMMAND_SERVICE_ID = "Control_SendCommand"; + final static String CONTROL_SETFLAGS_SERVICE_ID = "Control_SetFlags"; + + final ControlApi service; + + public ControlApiVerticle() { + try { + Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.ControlApiImpl"); + service = (ControlApi)serviceImplClass.newInstance(); + } catch (Exception e) { + logUnexpectedError("ControlApiVerticle constructor", e); + throw new RuntimeException(e); + } + } + + @Override + public void start() throws Exception { + + //Consumer for Control_Cleanup + vertx.eventBus(). consumer(CONTROL_CLEANUP_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Control_Cleanup"; + service.controlCleanup(result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Control_Cleanup"); + } + }); + } catch (Exception e) { + logUnexpectedError("Control_Cleanup", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Control_GetCapabilities + vertx.eventBus(). consumer(CONTROL_GETCAPABILITIES_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Control_GetCapabilities"; + service.controlGetCapabilities(result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Control_GetCapabilities"); + } + }); + } catch (Exception e) { + logUnexpectedError("Control_GetCapabilities", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Control_LogMessage + vertx.eventBus(). consumer(CONTROL_LOGMESSAGE_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Control_LogMessage"; + JsonObject logMessageParam = message.body().getJsonObject("logMessage"); + if (logMessageParam == null) { + manageError(message, new MainApiException(400, "logMessage is required"), serviceId); + return; + } + LogMessage logMessage = Json.mapper.readValue(logMessageParam.encode(), LogMessage.class); + service.controlLogMessage(logMessage, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Control_LogMessage"); + } + }); + } catch (Exception e) { + logUnexpectedError("Control_LogMessage", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Control_SendCommand + vertx.eventBus(). consumer(CONTROL_SENDCOMMAND_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Control_SendCommand"; + String cmdParam = message.body().getString("cmd"); + if(cmdParam == null) { + manageError(message, new MainApiException(400, "cmd is required"), serviceId); + return; + } + String cmd = cmdParam; + service.controlSendCommand(cmd, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Control_SendCommand"); + } + }); + } catch (Exception e) { + logUnexpectedError("Control_SendCommand", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Control_SetFlags + vertx.eventBus(). consumer(CONTROL_SETFLAGS_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Control_SetFlags"; + String flagsParam = message.body().getString("flags"); + if(flagsParam == null) { + manageError(message, new MainApiException(400, "flags is required"), serviceId); + return; + } + Object flags = Json.mapper.readValue(flagsParam, Object.class); + service.controlSetFlags(flags, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Control_SetFlags"); + } + }); + } catch (Exception e) { + logUnexpectedError("Control_SetFlags", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApi.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApi.java new file mode 100644 index 00000000..7fa1805a --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApi.java @@ -0,0 +1,74 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.Certificate; +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.MethodRequestAndResponse; +import io.swagger.server.api.model.Twin; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +public interface DeviceApi { + //Device_Connect + void deviceConnect(String transportType, String connectionString, Certificate caCertificate, Handler> handler); + + //Device_Connect2 + void deviceConnect2(String connectionId, Handler> handler); + + //Device_CreateFromConnectionString + void deviceCreateFromConnectionString(String transportType, String connectionString, Certificate caCertificate, Handler> handler); + + //Device_CreateFromX509 + void deviceCreateFromX509(String transportType, Object x509, Handler> handler); + + //Device_Destroy + void deviceDestroy(String connectionId, Handler> handler); + + //Device_Disconnect + void deviceDisconnect(String connectionId, Handler> handler); + + //Device_Disconnect2 + void deviceDisconnect2(String connectionId, Handler> handler); + + //Device_EnableC2dMessages + void deviceEnableC2dMessages(String connectionId, Handler> handler); + + //Device_EnableMethods + void deviceEnableMethods(String connectionId, Handler> handler); + + //Device_EnableTwin + void deviceEnableTwin(String connectionId, Handler> handler); + + //Device_GetConnectionStatus + void deviceGetConnectionStatus(String connectionId, Handler> handler); + + //Device_GetTwin + void deviceGetTwin(String connectionId, Handler> handler); + + //Device_PatchTwin + void devicePatchTwin(String connectionId, Twin twin, Handler> handler); + + //Device_Reconnect + void deviceReconnect(String connectionId, Boolean forceRenewPassword, Handler> handler); + + //Device_SendEvent + void deviceSendEvent(String connectionId, EventBody eventBody, Handler> handler); + + //Device_WaitForC2dMessage + void deviceWaitForC2dMessage(String connectionId, Handler> handler); + + //Device_WaitForConnectionStatusChange + void deviceWaitForConnectionStatusChange(String connectionId, Handler> handler); + + //Device_WaitForDesiredPropertiesPatch + void deviceWaitForDesiredPropertiesPatch(String connectionId, Handler> handler); + + //Device_WaitForMethodAndReturnResponse + void deviceWaitForMethodAndReturnResponse(String connectionId, String methodName, MethodRequestAndResponse requestAndResponse, Handler> handler); + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApiException.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApiException.java new file mode 100644 index 00000000..aaaa29a1 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApiException.java @@ -0,0 +1,17 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.Certificate; +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.MethodRequestAndResponse; +import io.swagger.server.api.model.Twin; + +public final class DeviceApiException extends MainApiException { + public DeviceApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + + +} \ No newline at end of file diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApiImpl.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApiImpl.java new file mode 100644 index 00000000..ea8ebaa0 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApiImpl.java @@ -0,0 +1,151 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.*; +import io.swagger.server.api.MainApiException; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +// Added all Override annotations and method bodies in merge + +// Changed from interface to class in merge +public class DeviceApiImpl implements DeviceApi +{ + //Device_Connect + @Override + public void deviceConnect(String transportType, String connectionString, Certificate caCertificate, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_Connect2 + @Override + public void deviceConnect2(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_CreateFromConnectionString + @Override + public void deviceCreateFromConnectionString(String transportType, String connectionString, Certificate caCertificate, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_CreateFromX509 + @Override + public void deviceCreateFromX509(String transportType, Object x509, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_Destroy + @Override + public void deviceDestroy(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_Disconnect + @Override + public void deviceDisconnect(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_Disconnect2 + @Override + public void deviceDisconnect2(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_EnableC2dMessages + @Override + public void deviceEnableC2dMessages(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_EnableMethods + @Override + public void deviceEnableMethods(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_EnableTwin + @Override + public void deviceEnableTwin(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_GetConnectionStatus + @Override + public void deviceGetConnectionStatus(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_GetTwin + @Override + public void deviceGetTwin(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_PatchTwin + @Override + public void devicePatchTwin(String connectionId, Twin twin, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_Reconnect + @Override + public void deviceReconnect(String connectionId, Boolean forceRenewPassword, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_WaitForMethodAndReturnResponse + @Override + public void deviceWaitForMethodAndReturnResponse(String connectionId, String methodName, MethodRequestAndResponse requestAndResponse, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_SendEvent + @Override + public void deviceSendEvent(String connectionId, EventBody eventBody, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_WaitForC2dMessage + @Override + public void deviceWaitForC2dMessage(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_WaitForConnectionStatusChange + @Override + public void deviceWaitForConnectionStatusChange(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Device_WaitForDesiredPropertiesPatch + @Override + public void deviceWaitForDesiredPropertiesPatch(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApiVerticle.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApiVerticle.java new file mode 100644 index 00000000..fa76156f --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/DeviceApiVerticle.java @@ -0,0 +1,608 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.model.Certificate; +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.MethodRequestAndResponse; +import io.swagger.server.api.model.Twin; + +import java.util.List; +import java.util.Map; + +public class DeviceApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(DeviceApiVerticle.class); + + final static String DEVICE_CONNECT_SERVICE_ID = "Device_Connect"; + final static String DEVICE_CONNECT2_SERVICE_ID = "Device_Connect2"; + final static String DEVICE_CREATEFROMCONNECTIONSTRING_SERVICE_ID = "Device_CreateFromConnectionString"; + final static String DEVICE_CREATEFROMX509_SERVICE_ID = "Device_CreateFromX509"; + final static String DEVICE_DESTROY_SERVICE_ID = "Device_Destroy"; + final static String DEVICE_DISCONNECT_SERVICE_ID = "Device_Disconnect"; + final static String DEVICE_DISCONNECT2_SERVICE_ID = "Device_Disconnect2"; + final static String DEVICE_ENABLEC2DMESSAGES_SERVICE_ID = "Device_EnableC2dMessages"; + final static String DEVICE_ENABLEMETHODS_SERVICE_ID = "Device_EnableMethods"; + final static String DEVICE_ENABLETWIN_SERVICE_ID = "Device_EnableTwin"; + final static String DEVICE_GETCONNECTIONSTATUS_SERVICE_ID = "Device_GetConnectionStatus"; + final static String DEVICE_GETTWIN_SERVICE_ID = "Device_GetTwin"; + final static String DEVICE_PATCHTWIN_SERVICE_ID = "Device_PatchTwin"; + final static String DEVICE_RECONNECT_SERVICE_ID = "Device_Reconnect"; + final static String DEVICE_SENDEVENT_SERVICE_ID = "Device_SendEvent"; + final static String DEVICE_WAITFORC2DMESSAGE_SERVICE_ID = "Device_WaitForC2dMessage"; + final static String DEVICE_WAITFORCONNECTIONSTATUSCHANGE_SERVICE_ID = "Device_WaitForConnectionStatusChange"; + final static String DEVICE_WAITFORDESIREDPROPERTIESPATCH_SERVICE_ID = "Device_WaitForDesiredPropertiesPatch"; + final static String DEVICE_WAITFORMETHODANDRETURNRESPONSE_SERVICE_ID = "Device_WaitForMethodAndReturnResponse"; + + final DeviceApi service; + + public DeviceApiVerticle() { + try { + Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.DeviceApiImpl"); + service = (DeviceApi)serviceImplClass.newInstance(); + } catch (Exception e) { + logUnexpectedError("DeviceApiVerticle constructor", e); + throw new RuntimeException(e); + } + } + + @Override + public void start() throws Exception { + + //Consumer for Device_Connect + vertx.eventBus(). consumer(DEVICE_CONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_Connect"; + String transportTypeParam = message.body().getString("transportType"); + if(transportTypeParam == null) { + manageError(message, new MainApiException(400, "transportType is required"), serviceId); + return; + } + String transportType = transportTypeParam; + String connectionStringParam = message.body().getString("connectionString"); + if(connectionStringParam == null) { + manageError(message, new MainApiException(400, "connectionString is required"), serviceId); + return; + } + String connectionString = connectionStringParam; + JsonObject caCertificateParam = message.body().getJsonObject("caCertificate"); + if (caCertificateParam == null) { + manageError(message, new MainApiException(400, "caCertificate is required"), serviceId); + return; + } + Certificate caCertificate = Json.mapper.readValue(caCertificateParam.encode(), Certificate.class); + service.deviceConnect(transportType, connectionString, caCertificate, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_Connect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_Connect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_Connect2 + vertx.eventBus(). consumer(DEVICE_CONNECT2_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_Connect2"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceConnect2(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_Connect2"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_Connect2", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_CreateFromConnectionString + vertx.eventBus(). consumer(DEVICE_CREATEFROMCONNECTIONSTRING_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_CreateFromConnectionString"; + String transportTypeParam = message.body().getString("transportType"); + if(transportTypeParam == null) { + manageError(message, new MainApiException(400, "transportType is required"), serviceId); + return; + } + String transportType = transportTypeParam; + String connectionStringParam = message.body().getString("connectionString"); + if(connectionStringParam == null) { + manageError(message, new MainApiException(400, "connectionString is required"), serviceId); + return; + } + String connectionString = connectionStringParam; + JsonObject caCertificateParam = message.body().getJsonObject("caCertificate"); + if (caCertificateParam == null) { + manageError(message, new MainApiException(400, "caCertificate is required"), serviceId); + return; + } + Certificate caCertificate = Json.mapper.readValue(caCertificateParam.encode(), Certificate.class); + service.deviceCreateFromConnectionString(transportType, connectionString, caCertificate, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_CreateFromConnectionString"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_CreateFromConnectionString", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_CreateFromX509 + vertx.eventBus(). consumer(DEVICE_CREATEFROMX509_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_CreateFromX509"; + String transportTypeParam = message.body().getString("transportType"); + if(transportTypeParam == null) { + manageError(message, new MainApiException(400, "transportType is required"), serviceId); + return; + } + String transportType = transportTypeParam; + String x509Param = message.body().getString("X509"); + if(x509Param == null) { + manageError(message, new MainApiException(400, "X509 is required"), serviceId); + return; + } + Object x509 = Json.mapper.readValue(x509Param, Object.class); + service.deviceCreateFromX509(transportType, x509, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_CreateFromX509"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_CreateFromX509", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_Destroy + vertx.eventBus(). consumer(DEVICE_DESTROY_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_Destroy"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceDestroy(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_Destroy"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_Destroy", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_Disconnect + vertx.eventBus(). consumer(DEVICE_DISCONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_Disconnect"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceDisconnect(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_Disconnect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_Disconnect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_Disconnect2 + vertx.eventBus(). consumer(DEVICE_DISCONNECT2_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_Disconnect2"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceDisconnect2(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_Disconnect2"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_Disconnect2", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_EnableC2dMessages + vertx.eventBus(). consumer(DEVICE_ENABLEC2DMESSAGES_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_EnableC2dMessages"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceEnableC2dMessages(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_EnableC2dMessages"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_EnableC2dMessages", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_EnableMethods + vertx.eventBus(). consumer(DEVICE_ENABLEMETHODS_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_EnableMethods"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceEnableMethods(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_EnableMethods"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_EnableMethods", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_EnableTwin + vertx.eventBus(). consumer(DEVICE_ENABLETWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_EnableTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceEnableTwin(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_EnableTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_EnableTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_GetConnectionStatus + vertx.eventBus(). consumer(DEVICE_GETCONNECTIONSTATUS_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_GetConnectionStatus"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceGetConnectionStatus(connectionId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_GetConnectionStatus"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_GetConnectionStatus", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_GetTwin + vertx.eventBus(). consumer(DEVICE_GETTWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_GetTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceGetTwin(connectionId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_GetTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_GetTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_PatchTwin + vertx.eventBus(). consumer(DEVICE_PATCHTWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_PatchTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + JsonObject twinParam = message.body().getJsonObject("twin"); + if (twinParam == null) { + manageError(message, new MainApiException(400, "twin is required"), serviceId); + return; + } + Twin twin = Json.mapper.readValue(twinParam.encode(), Twin.class); + service.devicePatchTwin(connectionId, twin, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_PatchTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_PatchTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_Reconnect + vertx.eventBus(). consumer(DEVICE_RECONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_Reconnect"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String forceRenewPasswordParam = message.body().getString("forceRenewPassword"); + Boolean forceRenewPassword = (forceRenewPasswordParam == null) ? null : Json.mapper.readValue(forceRenewPasswordParam, Boolean.class); + service.deviceReconnect(connectionId, forceRenewPassword, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_Reconnect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_Reconnect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_SendEvent + vertx.eventBus(). consumer(DEVICE_SENDEVENT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_SendEvent"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + JsonObject eventBodyParam = message.body().getJsonObject("eventBody"); + if (eventBodyParam == null) { + manageError(message, new MainApiException(400, "eventBody is required"), serviceId); + return; + } + EventBody eventBody = Json.mapper.readValue(eventBodyParam.encode(), EventBody.class); + service.deviceSendEvent(connectionId, eventBody, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_SendEvent"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_SendEvent", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_WaitForC2dMessage + vertx.eventBus(). consumer(DEVICE_WAITFORC2DMESSAGE_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_WaitForC2dMessage"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceWaitForC2dMessage(connectionId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_WaitForC2dMessage"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_WaitForC2dMessage", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_WaitForConnectionStatusChange + vertx.eventBus(). consumer(DEVICE_WAITFORCONNECTIONSTATUSCHANGE_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_WaitForConnectionStatusChange"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceWaitForConnectionStatusChange(connectionId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_WaitForConnectionStatusChange"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_WaitForConnectionStatusChange", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_WaitForDesiredPropertiesPatch + vertx.eventBus(). consumer(DEVICE_WAITFORDESIREDPROPERTIESPATCH_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_WaitForDesiredPropertiesPatch"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.deviceWaitForDesiredPropertiesPatch(connectionId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_WaitForDesiredPropertiesPatch"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_WaitForDesiredPropertiesPatch", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Device_WaitForMethodAndReturnResponse + vertx.eventBus(). consumer(DEVICE_WAITFORMETHODANDRETURNRESPONSE_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Device_WaitForMethodAndReturnResponse"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String methodNameParam = message.body().getString("methodName"); + if(methodNameParam == null) { + manageError(message, new MainApiException(400, "methodName is required"), serviceId); + return; + } + String methodName = methodNameParam; + JsonObject requestAndResponseParam = message.body().getJsonObject("requestAndResponse"); + if (requestAndResponseParam == null) { + manageError(message, new MainApiException(400, "requestAndResponse is required"), serviceId); + return; + } + MethodRequestAndResponse requestAndResponse = Json.mapper.readValue(requestAndResponseParam.encode(), MethodRequestAndResponse.class); + service.deviceWaitForMethodAndReturnResponse(connectionId, methodName, requestAndResponse, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Device_WaitForMethodAndReturnResponse"); + } + }); + } catch (Exception e) { + logUnexpectedError("Device_WaitForMethodAndReturnResponse", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApi.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApi.java new file mode 100644 index 00000000..c2447766 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApi.java @@ -0,0 +1,90 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.Certificate; +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.MethodInvoke; +import io.swagger.server.api.model.MethodRequestAndResponse; +import io.swagger.server.api.model.Twin; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +public interface ModuleApi { + //Module_Connect + void moduleConnect(String transportType, String connectionString, Certificate caCertificate, Handler> handler); + + //Module_Connect2 + void moduleConnect2(String connectionId, Handler> handler); + + //Module_ConnectFromEnvironment + void moduleConnectFromEnvironment(String transportType, Handler> handler); + + //Module_CreateFromConnectionString + void moduleCreateFromConnectionString(String transportType, String connectionString, Certificate caCertificate, Handler> handler); + + //Module_CreateFromEnvironment + void moduleCreateFromEnvironment(String transportType, Handler> handler); + + //Module_CreateFromX509 + void moduleCreateFromX509(String transportType, Object x509, Handler> handler); + + //Module_Destroy + void moduleDestroy(String connectionId, Handler> handler); + + //Module_Disconnect + void moduleDisconnect(String connectionId, Handler> handler); + + //Module_Disconnect2 + void moduleDisconnect2(String connectionId, Handler> handler); + + //Module_EnableInputMessages + void moduleEnableInputMessages(String connectionId, Handler> handler); + + //Module_EnableMethods + void moduleEnableMethods(String connectionId, Handler> handler); + + //Module_EnableTwin + void moduleEnableTwin(String connectionId, Handler> handler); + + //Module_GetConnectionStatus + void moduleGetConnectionStatus(String connectionId, Handler> handler); + + //Module_GetTwin + void moduleGetTwin(String connectionId, Handler> handler); + + //Module_InvokeDeviceMethod + void moduleInvokeDeviceMethod(String connectionId, String deviceId, MethodInvoke methodInvokeParameters, Handler> handler); + + //Module_InvokeModuleMethod + void moduleInvokeModuleMethod(String connectionId, String deviceId, String moduleId, MethodInvoke methodInvokeParameters, Handler> handler); + + //Module_PatchTwin + void modulePatchTwin(String connectionId, Twin twin, Handler> handler); + + //Module_Reconnect + void moduleReconnect(String connectionId, Boolean forceRenewPassword, Handler> handler); + + //Module_SendEvent + void moduleSendEvent(String connectionId, EventBody eventBody, Handler> handler); + + //Module_SendOutputEvent + void moduleSendOutputEvent(String connectionId, String outputName, EventBody eventBody, Handler> handler); + + //Module_WaitForConnectionStatusChange + void moduleWaitForConnectionStatusChange(String connectionId, Handler> handler); + + //Module_WaitForDesiredPropertiesPatch + void moduleWaitForDesiredPropertiesPatch(String connectionId, Handler> handler); + + //Module_WaitForInputMessage + void moduleWaitForInputMessage(String connectionId, String inputName, Handler> handler); + + //Module_WaitForMethodAndReturnResponse + void moduleWaitForMethodAndReturnResponse(String connectionId, String methodName, MethodRequestAndResponse requestAndResponse, Handler> handler); + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApiException.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApiException.java new file mode 100644 index 00000000..7d86e6bf --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApiException.java @@ -0,0 +1,18 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.Certificate; +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.MethodInvoke; +import io.swagger.server.api.model.MethodRequestAndResponse; +import io.swagger.server.api.model.Twin; + +public final class ModuleApiException extends MainApiException { + public ModuleApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + + +} \ No newline at end of file diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApiImpl.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApiImpl.java new file mode 100644 index 00000000..d265bca6 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApiImpl.java @@ -0,0 +1,193 @@ +package io.swagger.server.api.verticle; + + +// Added 1 lines in merge +import glue.ModuleGlue; + +import io.swagger.server.api.model.*; +import io.swagger.server.api.MainApiException; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +// Added all Override annotations and method bodies in merge + +// Changed from interface to class in merge +public class ModuleApiImpl implements ModuleApi +{ + // Added 1 line in merge + public static ModuleGlue _moduleGlue = new ModuleGlue(); + + //Module_Connect + @Override + public void moduleConnect(String transportType, String connectionString, Certificate caCertificate, Handler> handler) + { + this._moduleGlue.connect(transportType, connectionString, caCertificate, handler); + } + + //Module_Connect2 + @Override + public void moduleConnect2(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Module_ConnectFromEnvironment + @Override + public void moduleConnectFromEnvironment(String transportType, Handler> handler) + { + this._moduleGlue.connectFromEnvironment(transportType, handler); + } + + //Module_CreateFromConnectionString + @Override + public void moduleCreateFromConnectionString(String transportType, String connectionString, Certificate caCertificate, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Module_CreateFromEnvironment + @Override + public void moduleCreateFromEnvironment(String transportType, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Module_CreateFromX509 + @Override + public void moduleCreateFromX509(String transportType, Object x509, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Module_Destroy + @Override + public void moduleDestroy(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Module_Disconnect + @Override + public void moduleDisconnect(String connectionId, Handler> handler) + { + this._moduleGlue.disconnect(connectionId, handler); + } + + //Module_Disconnect2 + @Override + public void moduleDisconnect2(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Module_EnableInputMessages + @Override + public void moduleEnableInputMessages(String connectionId, Handler> handler) + { + this._moduleGlue.enableInputMessages(connectionId, handler); + } + + //Module_EnableMethods + @Override + public void moduleEnableMethods(String connectionId, Handler> handler) + { + this._moduleGlue.enableMethods(connectionId, handler); + } + + //Module_EnableTwin + @Override + public void moduleEnableTwin(String connectionId, Handler> handler) + { + this._moduleGlue.enableTwin(connectionId, handler); + } + + //Module_GetConnectionStatus + @Override + public void moduleGetConnectionStatus(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Module_GetTwin + @Override + public void moduleGetTwin(String connectionId, Handler> handler) + { + this._moduleGlue.getTwin(connectionId, handler); + } + + //Module_InvokeDeviceMethod + @Override + public void moduleInvokeDeviceMethod(String connectionId, String deviceId, MethodInvoke methodInvokeParameters, Handler> handler) + { + this._moduleGlue.invokeDeviceMethod(connectionId, deviceId, methodInvokeParameters, handler); + } + + //Module_InvokeModuleMethod + @Override + public void moduleInvokeModuleMethod(String connectionId, String deviceId, String moduleId, MethodInvoke methodInvokeParameters, Handler> handler) + { + this._moduleGlue.invokeModuleMethod(connectionId, deviceId, moduleId, methodInvokeParameters, handler); + } + + //Module_PatchTwin + @Override + public void modulePatchTwin(String connectionId, Twin twin, Handler> handler) + { + this._moduleGlue.sendTwinPatch(connectionId, twin, handler); + } + + //Module_Reconnect + @Override + public void moduleReconnect(String connectionId, Boolean forceRenewPassword, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Module_SendEvent + @Override + public void moduleSendEvent(String connectionId, EventBody eventBody, Handler> handler) + { + this._moduleGlue.sendEvent(connectionId, eventBody, handler); + } + + //Module_SendOutputEvent + @Override + public void moduleSendOutputEvent(String connectionId, String outputName, EventBody eventBody, Handler> handler) + { + this._moduleGlue.sendOutputEvent(connectionId, outputName, eventBody, handler); + } + + //Module_WaitForConnectionStatusChange + @Override + public void moduleWaitForConnectionStatusChange(String connectionId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Module_WaitForDesiredPropertiesPatch + @Override + public void moduleWaitForDesiredPropertiesPatch(String connectionId, Handler> handler) + { + this._moduleGlue.waitForDesiredPropertyPatch(connectionId, handler); + } + + //Module_WaitForInputMessage + @Override + public void moduleWaitForInputMessage(String connectionId, String inputName, Handler> handler) + { + this._moduleGlue.waitForInputMessage(connectionId, inputName, handler); + } + + //Module_WaitForMethodAndReturnResponse + @Override + public void moduleWaitForMethodAndReturnResponse(String connectionId, String methodName, MethodRequestAndResponse requestAndResponse, Handler> handler) + { + this._moduleGlue.WaitForMethodAndReturnResponse(connectionId, methodName, requestAndResponse, handler); + } + + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApiVerticle.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApiVerticle.java new file mode 100644 index 00000000..e6d2cc44 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ModuleApiVerticle.java @@ -0,0 +1,787 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.model.Certificate; +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.MethodInvoke; +import io.swagger.server.api.model.MethodRequestAndResponse; +import io.swagger.server.api.model.Twin; + +import java.util.List; +import java.util.Map; + +public class ModuleApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(ModuleApiVerticle.class); + + final static String MODULE_CONNECT_SERVICE_ID = "Module_Connect"; + final static String MODULE_CONNECT2_SERVICE_ID = "Module_Connect2"; + final static String MODULE_CONNECTFROMENVIRONMENT_SERVICE_ID = "Module_ConnectFromEnvironment"; + final static String MODULE_CREATEFROMCONNECTIONSTRING_SERVICE_ID = "Module_CreateFromConnectionString"; + final static String MODULE_CREATEFROMENVIRONMENT_SERVICE_ID = "Module_CreateFromEnvironment"; + final static String MODULE_CREATEFROMX509_SERVICE_ID = "Module_CreateFromX509"; + final static String MODULE_DESTROY_SERVICE_ID = "Module_Destroy"; + final static String MODULE_DISCONNECT_SERVICE_ID = "Module_Disconnect"; + final static String MODULE_DISCONNECT2_SERVICE_ID = "Module_Disconnect2"; + final static String MODULE_ENABLEINPUTMESSAGES_SERVICE_ID = "Module_EnableInputMessages"; + final static String MODULE_ENABLEMETHODS_SERVICE_ID = "Module_EnableMethods"; + final static String MODULE_ENABLETWIN_SERVICE_ID = "Module_EnableTwin"; + final static String MODULE_GETCONNECTIONSTATUS_SERVICE_ID = "Module_GetConnectionStatus"; + final static String MODULE_GETTWIN_SERVICE_ID = "Module_GetTwin"; + final static String MODULE_INVOKEDEVICEMETHOD_SERVICE_ID = "Module_InvokeDeviceMethod"; + final static String MODULE_INVOKEMODULEMETHOD_SERVICE_ID = "Module_InvokeModuleMethod"; + final static String MODULE_PATCHTWIN_SERVICE_ID = "Module_PatchTwin"; + final static String MODULE_RECONNECT_SERVICE_ID = "Module_Reconnect"; + final static String MODULE_SENDEVENT_SERVICE_ID = "Module_SendEvent"; + final static String MODULE_SENDOUTPUTEVENT_SERVICE_ID = "Module_SendOutputEvent"; + final static String MODULE_WAITFORCONNECTIONSTATUSCHANGE_SERVICE_ID = "Module_WaitForConnectionStatusChange"; + final static String MODULE_WAITFORDESIREDPROPERTIESPATCH_SERVICE_ID = "Module_WaitForDesiredPropertiesPatch"; + final static String MODULE_WAITFORINPUTMESSAGE_SERVICE_ID = "Module_WaitForInputMessage"; + final static String MODULE_WAITFORMETHODANDRETURNRESPONSE_SERVICE_ID = "Module_WaitForMethodAndReturnResponse"; + + final ModuleApi service; + + public ModuleApiVerticle() { + try { + Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.ModuleApiImpl"); + service = (ModuleApi)serviceImplClass.newInstance(); + } catch (Exception e) { + logUnexpectedError("ModuleApiVerticle constructor", e); + throw new RuntimeException(e); + } + } + + @Override + public void start() throws Exception { + + //Consumer for Module_Connect + vertx.eventBus(). consumer(MODULE_CONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_Connect"; + String transportTypeParam = message.body().getString("transportType"); + if(transportTypeParam == null) { + manageError(message, new MainApiException(400, "transportType is required"), serviceId); + return; + } + String transportType = transportTypeParam; + String connectionStringParam = message.body().getString("connectionString"); + if(connectionStringParam == null) { + manageError(message, new MainApiException(400, "connectionString is required"), serviceId); + return; + } + String connectionString = connectionStringParam; + JsonObject caCertificateParam = message.body().getJsonObject("caCertificate"); + if (caCertificateParam == null) { + manageError(message, new MainApiException(400, "caCertificate is required"), serviceId); + return; + } + Certificate caCertificate = Json.mapper.readValue(caCertificateParam.encode(), Certificate.class); + service.moduleConnect(transportType, connectionString, caCertificate, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_Connect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_Connect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_Connect2 + vertx.eventBus(). consumer(MODULE_CONNECT2_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_Connect2"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleConnect2(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_Connect2"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_Connect2", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_ConnectFromEnvironment + vertx.eventBus(). consumer(MODULE_CONNECTFROMENVIRONMENT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_ConnectFromEnvironment"; + String transportTypeParam = message.body().getString("transportType"); + if(transportTypeParam == null) { + manageError(message, new MainApiException(400, "transportType is required"), serviceId); + return; + } + String transportType = transportTypeParam; + service.moduleConnectFromEnvironment(transportType, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_ConnectFromEnvironment"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_ConnectFromEnvironment", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_CreateFromConnectionString + vertx.eventBus(). consumer(MODULE_CREATEFROMCONNECTIONSTRING_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_CreateFromConnectionString"; + String transportTypeParam = message.body().getString("transportType"); + if(transportTypeParam == null) { + manageError(message, new MainApiException(400, "transportType is required"), serviceId); + return; + } + String transportType = transportTypeParam; + String connectionStringParam = message.body().getString("connectionString"); + if(connectionStringParam == null) { + manageError(message, new MainApiException(400, "connectionString is required"), serviceId); + return; + } + String connectionString = connectionStringParam; + JsonObject caCertificateParam = message.body().getJsonObject("caCertificate"); + if (caCertificateParam == null) { + manageError(message, new MainApiException(400, "caCertificate is required"), serviceId); + return; + } + Certificate caCertificate = Json.mapper.readValue(caCertificateParam.encode(), Certificate.class); + service.moduleCreateFromConnectionString(transportType, connectionString, caCertificate, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_CreateFromConnectionString"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_CreateFromConnectionString", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_CreateFromEnvironment + vertx.eventBus(). consumer(MODULE_CREATEFROMENVIRONMENT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_CreateFromEnvironment"; + String transportTypeParam = message.body().getString("transportType"); + if(transportTypeParam == null) { + manageError(message, new MainApiException(400, "transportType is required"), serviceId); + return; + } + String transportType = transportTypeParam; + service.moduleCreateFromEnvironment(transportType, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_CreateFromEnvironment"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_CreateFromEnvironment", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_CreateFromX509 + vertx.eventBus(). consumer(MODULE_CREATEFROMX509_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_CreateFromX509"; + String transportTypeParam = message.body().getString("transportType"); + if(transportTypeParam == null) { + manageError(message, new MainApiException(400, "transportType is required"), serviceId); + return; + } + String transportType = transportTypeParam; + String x509Param = message.body().getString("X509"); + if(x509Param == null) { + manageError(message, new MainApiException(400, "X509 is required"), serviceId); + return; + } + Object x509 = Json.mapper.readValue(x509Param, Object.class); + service.moduleCreateFromX509(transportType, x509, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_CreateFromX509"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_CreateFromX509", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_Destroy + vertx.eventBus(). consumer(MODULE_DESTROY_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_Destroy"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleDestroy(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_Destroy"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_Destroy", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_Disconnect + vertx.eventBus(). consumer(MODULE_DISCONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_Disconnect"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleDisconnect(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_Disconnect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_Disconnect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_Disconnect2 + vertx.eventBus(). consumer(MODULE_DISCONNECT2_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_Disconnect2"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleDisconnect2(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_Disconnect2"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_Disconnect2", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_EnableInputMessages + vertx.eventBus(). consumer(MODULE_ENABLEINPUTMESSAGES_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_EnableInputMessages"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleEnableInputMessages(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_EnableInputMessages"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_EnableInputMessages", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_EnableMethods + vertx.eventBus(). consumer(MODULE_ENABLEMETHODS_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_EnableMethods"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleEnableMethods(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_EnableMethods"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_EnableMethods", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_EnableTwin + vertx.eventBus(). consumer(MODULE_ENABLETWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_EnableTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleEnableTwin(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_EnableTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_EnableTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_GetConnectionStatus + vertx.eventBus(). consumer(MODULE_GETCONNECTIONSTATUS_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_GetConnectionStatus"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleGetConnectionStatus(connectionId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_GetConnectionStatus"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_GetConnectionStatus", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_GetTwin + vertx.eventBus(). consumer(MODULE_GETTWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_GetTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleGetTwin(connectionId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_GetTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_GetTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_InvokeDeviceMethod + vertx.eventBus(). consumer(MODULE_INVOKEDEVICEMETHOD_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_InvokeDeviceMethod"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String deviceIdParam = message.body().getString("deviceId"); + if(deviceIdParam == null) { + manageError(message, new MainApiException(400, "deviceId is required"), serviceId); + return; + } + String deviceId = deviceIdParam; + JsonObject methodInvokeParametersParam = message.body().getJsonObject("methodInvokeParameters"); + if (methodInvokeParametersParam == null) { + manageError(message, new MainApiException(400, "methodInvokeParameters is required"), serviceId); + return; + } + MethodInvoke methodInvokeParameters = Json.mapper.readValue(methodInvokeParametersParam.encode(), MethodInvoke.class); + service.moduleInvokeDeviceMethod(connectionId, deviceId, methodInvokeParameters, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_InvokeDeviceMethod"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_InvokeDeviceMethod", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_InvokeModuleMethod + vertx.eventBus(). consumer(MODULE_INVOKEMODULEMETHOD_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_InvokeModuleMethod"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String deviceIdParam = message.body().getString("deviceId"); + if(deviceIdParam == null) { + manageError(message, new MainApiException(400, "deviceId is required"), serviceId); + return; + } + String deviceId = deviceIdParam; + String moduleIdParam = message.body().getString("moduleId"); + if(moduleIdParam == null) { + manageError(message, new MainApiException(400, "moduleId is required"), serviceId); + return; + } + String moduleId = moduleIdParam; + JsonObject methodInvokeParametersParam = message.body().getJsonObject("methodInvokeParameters"); + if (methodInvokeParametersParam == null) { + manageError(message, new MainApiException(400, "methodInvokeParameters is required"), serviceId); + return; + } + MethodInvoke methodInvokeParameters = Json.mapper.readValue(methodInvokeParametersParam.encode(), MethodInvoke.class); + service.moduleInvokeModuleMethod(connectionId, deviceId, moduleId, methodInvokeParameters, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_InvokeModuleMethod"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_InvokeModuleMethod", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_PatchTwin + vertx.eventBus(). consumer(MODULE_PATCHTWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_PatchTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + JsonObject twinParam = message.body().getJsonObject("twin"); + if (twinParam == null) { + manageError(message, new MainApiException(400, "twin is required"), serviceId); + return; + } + Twin twin = Json.mapper.readValue(twinParam.encode(), Twin.class); + service.modulePatchTwin(connectionId, twin, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_PatchTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_PatchTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_Reconnect + vertx.eventBus(). consumer(MODULE_RECONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_Reconnect"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String forceRenewPasswordParam = message.body().getString("forceRenewPassword"); + Boolean forceRenewPassword = (forceRenewPasswordParam == null) ? null : Json.mapper.readValue(forceRenewPasswordParam, Boolean.class); + service.moduleReconnect(connectionId, forceRenewPassword, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_Reconnect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_Reconnect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_SendEvent + vertx.eventBus(). consumer(MODULE_SENDEVENT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_SendEvent"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + JsonObject eventBodyParam = message.body().getJsonObject("eventBody"); + if (eventBodyParam == null) { + manageError(message, new MainApiException(400, "eventBody is required"), serviceId); + return; + } + EventBody eventBody = Json.mapper.readValue(eventBodyParam.encode(), EventBody.class); + service.moduleSendEvent(connectionId, eventBody, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_SendEvent"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_SendEvent", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_SendOutputEvent + vertx.eventBus(). consumer(MODULE_SENDOUTPUTEVENT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_SendOutputEvent"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String outputNameParam = message.body().getString("outputName"); + if(outputNameParam == null) { + manageError(message, new MainApiException(400, "outputName is required"), serviceId); + return; + } + String outputName = outputNameParam; + JsonObject eventBodyParam = message.body().getJsonObject("eventBody"); + if (eventBodyParam == null) { + manageError(message, new MainApiException(400, "eventBody is required"), serviceId); + return; + } + EventBody eventBody = Json.mapper.readValue(eventBodyParam.encode(), EventBody.class); + service.moduleSendOutputEvent(connectionId, outputName, eventBody, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_SendOutputEvent"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_SendOutputEvent", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_WaitForConnectionStatusChange + vertx.eventBus(). consumer(MODULE_WAITFORCONNECTIONSTATUSCHANGE_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_WaitForConnectionStatusChange"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleWaitForConnectionStatusChange(connectionId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_WaitForConnectionStatusChange"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_WaitForConnectionStatusChange", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_WaitForDesiredPropertiesPatch + vertx.eventBus(). consumer(MODULE_WAITFORDESIREDPROPERTIESPATCH_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_WaitForDesiredPropertiesPatch"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.moduleWaitForDesiredPropertiesPatch(connectionId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_WaitForDesiredPropertiesPatch"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_WaitForDesiredPropertiesPatch", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_WaitForInputMessage + vertx.eventBus(). consumer(MODULE_WAITFORINPUTMESSAGE_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_WaitForInputMessage"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String inputNameParam = message.body().getString("inputName"); + if(inputNameParam == null) { + manageError(message, new MainApiException(400, "inputName is required"), serviceId); + return; + } + String inputName = inputNameParam; + service.moduleWaitForInputMessage(connectionId, inputName, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_WaitForInputMessage"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_WaitForInputMessage", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Module_WaitForMethodAndReturnResponse + vertx.eventBus(). consumer(MODULE_WAITFORMETHODANDRETURNRESPONSE_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Module_WaitForMethodAndReturnResponse"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String methodNameParam = message.body().getString("methodName"); + if(methodNameParam == null) { + manageError(message, new MainApiException(400, "methodName is required"), serviceId); + return; + } + String methodName = methodNameParam; + JsonObject requestAndResponseParam = message.body().getJsonObject("requestAndResponse"); + if (requestAndResponseParam == null) { + manageError(message, new MainApiException(400, "requestAndResponse is required"), serviceId); + return; + } + MethodRequestAndResponse requestAndResponse = Json.mapper.readValue(requestAndResponseParam.encode(), MethodRequestAndResponse.class); + service.moduleWaitForMethodAndReturnResponse(connectionId, methodName, requestAndResponse, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Module_WaitForMethodAndReturnResponse"); + } + }); + } catch (Exception e) { + logUnexpectedError("Module_WaitForMethodAndReturnResponse", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApi.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApi.java new file mode 100644 index 00000000..a535c1a6 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApi.java @@ -0,0 +1,27 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +public interface NetApi { + //Net_Disconnect + void netDisconnect(String disconnectType, Handler> handler); + + //Net_DisconnectAfterC2d + void netDisconnectAfterC2d(String disconnectType, Handler> handler); + + //Net_DisconnectAfterD2c + void netDisconnectAfterD2c(String disconnectType, Handler> handler); + + //Net_Reconnect + void netReconnect(Handler> handler); + + //Net_SetDestination + void netSetDestination(String ip, String transportType, Handler> handler); + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApiException.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApiException.java new file mode 100644 index 00000000..fbaa5d24 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApiException.java @@ -0,0 +1,12 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; + +public final class NetApiException extends MainApiException { + public NetApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + + +} \ No newline at end of file diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApiImpl.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApiImpl.java new file mode 100644 index 00000000..af7cce5d --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApiImpl.java @@ -0,0 +1,52 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.MainApiException; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +// Added all Override annotations and method bodies in merge + +// Changed from interface to class in merge +public class NetApiImpl implements NetApi +{ + //Net_Disconnect + @Override + public void netDisconnect(String disconnectType, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + + //Net_DisconnectAfterC2d + @Override + public void netDisconnectAfterC2d(String disconnectType, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Net_DisconnectAfterD2c + @Override + public void netDisconnectAfterD2c(String disconnectType, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Net_Reconnect + @Override + public void netReconnect(Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Net_SetDestination + @Override + public void netSetDestination(String ip, String transportType, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApiVerticle.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApiVerticle.java new file mode 100644 index 00000000..ad58d74b --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/NetApiVerticle.java @@ -0,0 +1,183 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.MainApiException; + +import java.util.List; +import java.util.Map; + +public class NetApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(NetApiVerticle.class); + + final static String NET_DISCONNECT_SERVICE_ID = "Net_Disconnect"; + final static String NET_DISCONNECTAFTERC2D_SERVICE_ID = "Net_DisconnectAfterC2d"; + final static String NET_DISCONNECTAFTERD2C_SERVICE_ID = "Net_DisconnectAfterD2c"; + final static String NET_RECONNECT_SERVICE_ID = "Net_Reconnect"; + final static String NET_SETDESTINATION_SERVICE_ID = "Net_SetDestination"; + + final NetApi service; + + public NetApiVerticle() { + try { + Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.NetApiImpl"); + service = (NetApi)serviceImplClass.newInstance(); + } catch (Exception e) { + logUnexpectedError("NetApiVerticle constructor", e); + throw new RuntimeException(e); + } + } + + @Override + public void start() throws Exception { + + //Consumer for Net_Disconnect + vertx.eventBus(). consumer(NET_DISCONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Net_Disconnect"; + String disconnectTypeParam = message.body().getString("disconnectType"); + if(disconnectTypeParam == null) { + manageError(message, new MainApiException(400, "disconnectType is required"), serviceId); + return; + } + String disconnectType = disconnectTypeParam; + service.netDisconnect(disconnectType, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Net_Disconnect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Net_Disconnect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Net_DisconnectAfterC2d + vertx.eventBus(). consumer(NET_DISCONNECTAFTERC2D_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Net_DisconnectAfterC2d"; + String disconnectTypeParam = message.body().getString("disconnectType"); + if(disconnectTypeParam == null) { + manageError(message, new MainApiException(400, "disconnectType is required"), serviceId); + return; + } + String disconnectType = disconnectTypeParam; + service.netDisconnectAfterC2d(disconnectType, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Net_DisconnectAfterC2d"); + } + }); + } catch (Exception e) { + logUnexpectedError("Net_DisconnectAfterC2d", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Net_DisconnectAfterD2c + vertx.eventBus(). consumer(NET_DISCONNECTAFTERD2C_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Net_DisconnectAfterD2c"; + String disconnectTypeParam = message.body().getString("disconnectType"); + if(disconnectTypeParam == null) { + manageError(message, new MainApiException(400, "disconnectType is required"), serviceId); + return; + } + String disconnectType = disconnectTypeParam; + service.netDisconnectAfterD2c(disconnectType, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Net_DisconnectAfterD2c"); + } + }); + } catch (Exception e) { + logUnexpectedError("Net_DisconnectAfterD2c", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Net_Reconnect + vertx.eventBus(). consumer(NET_RECONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Net_Reconnect"; + service.netReconnect(result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Net_Reconnect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Net_Reconnect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Net_SetDestination + vertx.eventBus(). consumer(NET_SETDESTINATION_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Net_SetDestination"; + String ipParam = message.body().getString("ip"); + if(ipParam == null) { + manageError(message, new MainApiException(400, "ip is required"), serviceId); + return; + } + String ip = ipParam; + String transportTypeParam = message.body().getString("transportType"); + if(transportTypeParam == null) { + manageError(message, new MainApiException(400, "transportType is required"), serviceId); + return; + } + String transportType = transportTypeParam; + service.netSetDestination(ip, transportType, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Net_SetDestination"); + } + }); + } catch (Exception e) { + logUnexpectedError("Net_SetDestination", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApi.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApi.java new file mode 100644 index 00000000..9aa4700d --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApi.java @@ -0,0 +1,32 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.Twin; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +public interface RegistryApi { + //Registry_Connect + void registryConnect(String connectionString, Handler> handler); + + //Registry_Disconnect + void registryDisconnect(String connectionId, Handler> handler); + + //Registry_GetDeviceTwin + void registryGetDeviceTwin(String connectionId, String deviceId, Handler> handler); + + //Registry_GetModuleTwin + void registryGetModuleTwin(String connectionId, String deviceId, String moduleId, Handler> handler); + + //Registry_PatchDeviceTwin + void registryPatchDeviceTwin(String connectionId, String deviceId, Twin twin, Handler> handler); + + //Registry_PatchModuleTwin + void registryPatchModuleTwin(String connectionId, String deviceId, String moduleId, Twin twin, Handler> handler); + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApiException.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApiException.java new file mode 100644 index 00000000..4cc8d3b4 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApiException.java @@ -0,0 +1,14 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.Twin; + +public final class RegistryApiException extends MainApiException { + public RegistryApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + + +} \ No newline at end of file diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApiImpl.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApiImpl.java new file mode 100644 index 00000000..e6c32c13 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApiImpl.java @@ -0,0 +1,65 @@ +package io.swagger.server.api.verticle; + +// Added 1 line in merge +import glue.RegistryGlue; + +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.MainApiException; + +import io.swagger.server.api.model.Twin; +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +// Added all Override annotations and method bodies in merge + +// Changed from interface to class in merge +public class RegistryApiImpl implements RegistryApi +{ + // Added 1 line in merge + public static RegistryGlue _registryGlue = new RegistryGlue(); + + //Registry_Connect + @Override + public void registryConnect(String connectionString, Handler> handler) + { + this._registryGlue.connect(connectionString, handler); + } + + //Registry_Disconnect + @Override + public void registryDisconnect(String connectionId, Handler> handler) + { + this._registryGlue.disconnect(connectionId, handler); + } + + //Registry_GetDeviceTwin + @Override + public void registryGetDeviceTwin(String connectionId, String deviceId, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Registry_GetModuleTwin + public void registryGetModuleTwin(String connectionId, String deviceId, String moduleId, Handler> handler) + { + this._registryGlue.getModuleTwin(connectionId, deviceId, moduleId, handler); + } + + //Registry_PatchDeviceTwin + @Override + public void registryPatchDeviceTwin(String connectionId, String deviceId, Twin twin, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + + //Registry_PatchModuleTwin + @Override + public void registryPatchModuleTwin(String connectionId, String deviceId, String moduleId, Twin twin, Handler> handler) + { + this._registryGlue.sendModuleTwinPatch(connectionId, deviceId, moduleId, twin, handler); + } + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApiVerticle.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApiVerticle.java new file mode 100644 index 00000000..17f9ddf5 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/RegistryApiVerticle.java @@ -0,0 +1,259 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.Twin; + +import java.util.List; +import java.util.Map; + +public class RegistryApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(RegistryApiVerticle.class); + + final static String REGISTRY_CONNECT_SERVICE_ID = "Registry_Connect"; + final static String REGISTRY_DISCONNECT_SERVICE_ID = "Registry_Disconnect"; + final static String REGISTRY_GETDEVICETWIN_SERVICE_ID = "Registry_GetDeviceTwin"; + final static String REGISTRY_GETMODULETWIN_SERVICE_ID = "Registry_GetModuleTwin"; + final static String REGISTRY_PATCHDEVICETWIN_SERVICE_ID = "Registry_PatchDeviceTwin"; + final static String REGISTRY_PATCHMODULETWIN_SERVICE_ID = "Registry_PatchModuleTwin"; + + final RegistryApi service; + + public RegistryApiVerticle() { + try { + Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.RegistryApiImpl"); + service = (RegistryApi)serviceImplClass.newInstance(); + } catch (Exception e) { + logUnexpectedError("RegistryApiVerticle constructor", e); + throw new RuntimeException(e); + } + } + + @Override + public void start() throws Exception { + + //Consumer for Registry_Connect + vertx.eventBus(). consumer(REGISTRY_CONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Registry_Connect"; + String connectionStringParam = message.body().getString("connectionString"); + if(connectionStringParam == null) { + manageError(message, new MainApiException(400, "connectionString is required"), serviceId); + return; + } + String connectionString = connectionStringParam; + service.registryConnect(connectionString, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Registry_Connect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Registry_Connect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Registry_Disconnect + vertx.eventBus(). consumer(REGISTRY_DISCONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Registry_Disconnect"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.registryDisconnect(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Registry_Disconnect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Registry_Disconnect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Registry_GetDeviceTwin + vertx.eventBus(). consumer(REGISTRY_GETDEVICETWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Registry_GetDeviceTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String deviceIdParam = message.body().getString("deviceId"); + if(deviceIdParam == null) { + manageError(message, new MainApiException(400, "deviceId is required"), serviceId); + return; + } + String deviceId = deviceIdParam; + service.registryGetDeviceTwin(connectionId, deviceId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Registry_GetDeviceTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Registry_GetDeviceTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Registry_GetModuleTwin + vertx.eventBus(). consumer(REGISTRY_GETMODULETWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Registry_GetModuleTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String deviceIdParam = message.body().getString("deviceId"); + if(deviceIdParam == null) { + manageError(message, new MainApiException(400, "deviceId is required"), serviceId); + return; + } + String deviceId = deviceIdParam; + String moduleIdParam = message.body().getString("moduleId"); + if(moduleIdParam == null) { + manageError(message, new MainApiException(400, "moduleId is required"), serviceId); + return; + } + String moduleId = moduleIdParam; + service.registryGetModuleTwin(connectionId, deviceId, moduleId, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Registry_GetModuleTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Registry_GetModuleTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Registry_PatchDeviceTwin + vertx.eventBus(). consumer(REGISTRY_PATCHDEVICETWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Registry_PatchDeviceTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String deviceIdParam = message.body().getString("deviceId"); + if(deviceIdParam == null) { + manageError(message, new MainApiException(400, "deviceId is required"), serviceId); + return; + } + String deviceId = deviceIdParam; + JsonObject twinParam = message.body().getJsonObject("twin"); + if (twinParam == null) { + manageError(message, new MainApiException(400, "twin is required"), serviceId); + return; + } + Twin twin = Json.mapper.readValue(twinParam.encode(), Twin.class); + service.registryPatchDeviceTwin(connectionId, deviceId, twin, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Registry_PatchDeviceTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Registry_PatchDeviceTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Registry_PatchModuleTwin + vertx.eventBus(). consumer(REGISTRY_PATCHMODULETWIN_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Registry_PatchModuleTwin"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String deviceIdParam = message.body().getString("deviceId"); + if(deviceIdParam == null) { + manageError(message, new MainApiException(400, "deviceId is required"), serviceId); + return; + } + String deviceId = deviceIdParam; + String moduleIdParam = message.body().getString("moduleId"); + if(moduleIdParam == null) { + manageError(message, new MainApiException(400, "moduleId is required"), serviceId); + return; + } + String moduleId = moduleIdParam; + JsonObject twinParam = message.body().getJsonObject("twin"); + if (twinParam == null) { + manageError(message, new MainApiException(400, "twin is required"), serviceId); + return; + } + Twin twin = Json.mapper.readValue(twinParam.encode(), Twin.class); + service.registryPatchModuleTwin(connectionId, deviceId, moduleId, twin, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Registry_PatchModuleTwin"); + } + }); + } catch (Exception e) { + logUnexpectedError("Registry_PatchModuleTwin", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApi.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApi.java new file mode 100644 index 00000000..6fb1d2fd --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApi.java @@ -0,0 +1,30 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.MethodInvoke; + +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +public interface ServiceApi { + //Service_Connect + void serviceConnect(String connectionString, Handler> handler); + + //Service_Disconnect + void serviceDisconnect(String connectionId, Handler> handler); + + //Service_InvokeDeviceMethod + void serviceInvokeDeviceMethod(String connectionId, String deviceId, MethodInvoke methodInvokeParameters, Handler> handler); + + //Service_InvokeModuleMethod + void serviceInvokeModuleMethod(String connectionId, String deviceId, String moduleId, MethodInvoke methodInvokeParameters, Handler> handler); + + //Service_SendC2d + void serviceSendC2d(String connectionId, String deviceId, EventBody eventBody, Handler> handler); + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApiException.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApiException.java new file mode 100644 index 00000000..e3133cfc --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApiException.java @@ -0,0 +1,15 @@ +package io.swagger.server.api.verticle; + +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.MethodInvoke; + +public final class ServiceApiException extends MainApiException { + public ServiceApiException(int statusCode, String statusMessage) { + super(statusCode, statusMessage); + } + + + +} \ No newline at end of file diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApiImpl.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApiImpl.java new file mode 100644 index 00000000..9d6acd30 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApiImpl.java @@ -0,0 +1,60 @@ +package io.swagger.server.api.verticle; + +// Added 1 line in merge +import glue.ServiceGlue; + +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.MainApiException; + +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.model.MethodInvoke; +import io.vertx.core.AsyncResult; +import io.vertx.core.Handler; + +import java.util.List; +import java.util.Map; + +// Added all Override annotations and method bodies in merge + +// Changed from interface to class in merge +public class ServiceApiImpl implements ServiceApi +{ + // Added 1 line in merge + public static ServiceGlue _serviceGlue = new ServiceGlue(); + + //Service_Connect + @Override + public void serviceConnect(String connectionString, Handler> handler) + { + this._serviceGlue.connect(connectionString, handler); + } + + //Service_Disconnect + @Override + public void serviceDisconnect(String connectionId, Handler> handler) + { + this._serviceGlue.disconnect(connectionId, handler); + } + + //Service_InvokeDeviceMethod + @Override + public void serviceInvokeDeviceMethod(String connectionId, String deviceId, MethodInvoke methodInvokeParameters, Handler> handler) + { + this._serviceGlue.invokeDeviceMethod(connectionId, deviceId, methodInvokeParameters, handler); + } + + //Service_InvokeModuleMethod + @Override + public void serviceInvokeModuleMethod(String connectionId, String deviceId, String moduleId, MethodInvoke methodInvokeParameters, Handler> handler) + { + this._serviceGlue.invokeModuleMethod(connectionId, deviceId, moduleId, methodInvokeParameters, handler); + } + + //Service_SendC2d + @Override + public void serviceSendC2d(String connectionId, String deviceId, EventBody eventBody, Handler> handler) + { + throw new java.lang.UnsupportedOperationException("Not supported yet"); + } + +} diff --git a/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApiVerticle.java b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApiVerticle.java new file mode 100644 index 00000000..e5643f06 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/java/io/swagger/server/api/verticle/ServiceApiVerticle.java @@ -0,0 +1,228 @@ +package io.swagger.server.api.verticle; + +import io.vertx.core.AbstractVerticle; +import io.vertx.core.eventbus.Message; +import io.vertx.core.json.Json; +import io.vertx.core.json.JsonArray; +import io.vertx.core.json.JsonObject; +import io.vertx.core.logging.Logger; +import io.vertx.core.logging.LoggerFactory; + +import io.swagger.server.api.model.ConnectResponse; +import io.swagger.server.api.model.EventBody; +import io.swagger.server.api.MainApiException; +import io.swagger.server.api.model.MethodInvoke; + +import java.util.List; +import java.util.Map; + +public class ServiceApiVerticle extends AbstractVerticle { + final static Logger LOGGER = LoggerFactory.getLogger(ServiceApiVerticle.class); + + final static String SERVICE_CONNECT_SERVICE_ID = "Service_Connect"; + final static String SERVICE_DISCONNECT_SERVICE_ID = "Service_Disconnect"; + final static String SERVICE_INVOKEDEVICEMETHOD_SERVICE_ID = "Service_InvokeDeviceMethod"; + final static String SERVICE_INVOKEMODULEMETHOD_SERVICE_ID = "Service_InvokeModuleMethod"; + final static String SERVICE_SENDC2D_SERVICE_ID = "Service_SendC2d"; + + final ServiceApi service; + + public ServiceApiVerticle() { + try { + Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.ServiceApiImpl"); + service = (ServiceApi)serviceImplClass.newInstance(); + } catch (Exception e) { + logUnexpectedError("ServiceApiVerticle constructor", e); + throw new RuntimeException(e); + } + } + + @Override + public void start() throws Exception { + + //Consumer for Service_Connect + vertx.eventBus(). consumer(SERVICE_CONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Service_Connect"; + String connectionStringParam = message.body().getString("connectionString"); + if(connectionStringParam == null) { + manageError(message, new MainApiException(400, "connectionString is required"), serviceId); + return; + } + String connectionString = connectionStringParam; + service.serviceConnect(connectionString, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Service_Connect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Service_Connect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Service_Disconnect + vertx.eventBus(). consumer(SERVICE_DISCONNECT_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Service_Disconnect"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + service.serviceDisconnect(connectionId, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Service_Disconnect"); + } + }); + } catch (Exception e) { + logUnexpectedError("Service_Disconnect", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Service_InvokeDeviceMethod + vertx.eventBus(). consumer(SERVICE_INVOKEDEVICEMETHOD_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Service_InvokeDeviceMethod"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String deviceIdParam = message.body().getString("deviceId"); + if(deviceIdParam == null) { + manageError(message, new MainApiException(400, "deviceId is required"), serviceId); + return; + } + String deviceId = deviceIdParam; + JsonObject methodInvokeParametersParam = message.body().getJsonObject("methodInvokeParameters"); + if (methodInvokeParametersParam == null) { + manageError(message, new MainApiException(400, "methodInvokeParameters is required"), serviceId); + return; + } + MethodInvoke methodInvokeParameters = Json.mapper.readValue(methodInvokeParametersParam.encode(), MethodInvoke.class); + service.serviceInvokeDeviceMethod(connectionId, deviceId, methodInvokeParameters, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Service_InvokeDeviceMethod"); + } + }); + } catch (Exception e) { + logUnexpectedError("Service_InvokeDeviceMethod", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Service_InvokeModuleMethod + vertx.eventBus(). consumer(SERVICE_INVOKEMODULEMETHOD_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Service_InvokeModuleMethod"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String deviceIdParam = message.body().getString("deviceId"); + if(deviceIdParam == null) { + manageError(message, new MainApiException(400, "deviceId is required"), serviceId); + return; + } + String deviceId = deviceIdParam; + String moduleIdParam = message.body().getString("moduleId"); + if(moduleIdParam == null) { + manageError(message, new MainApiException(400, "moduleId is required"), serviceId); + return; + } + String moduleId = moduleIdParam; + JsonObject methodInvokeParametersParam = message.body().getJsonObject("methodInvokeParameters"); + if (methodInvokeParametersParam == null) { + manageError(message, new MainApiException(400, "methodInvokeParameters is required"), serviceId); + return; + } + MethodInvoke methodInvokeParameters = Json.mapper.readValue(methodInvokeParametersParam.encode(), MethodInvoke.class); + service.serviceInvokeModuleMethod(connectionId, deviceId, moduleId, methodInvokeParameters, result -> { + if (result.succeeded()) + message.reply(new JsonObject(Json.encode(result.result())).encodePrettily()); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Service_InvokeModuleMethod"); + } + }); + } catch (Exception e) { + logUnexpectedError("Service_InvokeModuleMethod", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + //Consumer for Service_SendC2d + vertx.eventBus(). consumer(SERVICE_SENDC2D_SERVICE_ID).handler(message -> { + try { + // Workaround for #allParams section clearing the vendorExtensions map + String serviceId = "Service_SendC2d"; + String connectionIdParam = message.body().getString("connectionId"); + if(connectionIdParam == null) { + manageError(message, new MainApiException(400, "connectionId is required"), serviceId); + return; + } + String connectionId = connectionIdParam; + String deviceIdParam = message.body().getString("deviceId"); + if(deviceIdParam == null) { + manageError(message, new MainApiException(400, "deviceId is required"), serviceId); + return; + } + String deviceId = deviceIdParam; + JsonObject eventBodyParam = message.body().getJsonObject("eventBody"); + if (eventBodyParam == null) { + manageError(message, new MainApiException(400, "eventBody is required"), serviceId); + return; + } + EventBody eventBody = Json.mapper.readValue(eventBodyParam.encode(), EventBody.class); + service.serviceSendC2d(connectionId, deviceId, eventBody, result -> { + if (result.succeeded()) + message.reply(null); + else { + Throwable cause = result.cause(); + manageError(message, cause, "Service_SendC2d"); + } + }); + } catch (Exception e) { + logUnexpectedError("Service_SendC2d", e); + message.fail(MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(), MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage()); + } + }); + + } + + private void manageError(Message message, Throwable cause, String serviceName) { + int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode(); + String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage(); + if (cause instanceof MainApiException) { + code = ((MainApiException)cause).getStatusCode(); + statusMessage = ((MainApiException)cause).getStatusMessage(); + } else { + logUnexpectedError(serviceName, cause); + } + + message.fail(code, statusMessage); + } + + private void logUnexpectedError(String serviceName, Throwable cause) { + LOGGER.error("Unexpected error in "+ serviceName, cause); + } +} diff --git a/docker_images/javalite/wrapper/src/main/resources/swagger.json b/docker_images/javalite/wrapper/src/main/resources/swagger.json new file mode 100644 index 00000000..611c9fc6 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/resources/swagger.json @@ -0,0 +1,1828 @@ +{ + "swagger" : "2.0", + "info" : { + "description" : "REST API definition for End-to-end testing of the Azure IoT SDKs. All SDK APIs that are tested by our E2E tests need to be defined in this file. This file takes some liberties with the API definitions. In particular, response schemas are undefined, and error responses are also undefined.", + "version" : "1.0.0", + "title" : "Azure IOT End-to-End Test Wrapper Rest Api" + }, + "tags" : [ { + "name" : "control", + "description" : "Control APIs that aren't tied to any specific SDK" + }, { + "name" : "module", + "description" : "ModuleClient APIs" + }, { + "name" : "device", + "description" : "DeviceClient APIs" + }, { + "name" : "service", + "description" : "ServiceClient APIs" + }, { + "name" : "registry", + "description" : "registry APIs" + }, { + "name" : "net", + "description" : "network control APIs" + } ], + "schemes" : [ "https" ], + "produces" : [ "application/json" ], + "paths" : { + "/control/capabilities" : { + "get" : { + "tags" : [ "control" ], + "summary" : "Get capabilities for the objects in this server", + "operationId" : "Control_GetCapabilities", + "produces" : [ "application/json" ], + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "type" : "object" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/control/cleanup" : { + "put" : { + "tags" : [ "control" ], + "summary" : "verify that the clients have cleaned themselves up completely", + "operationId" : "Control_Cleanup", + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/control/message" : { + "put" : { + "tags" : [ "control" ], + "summary" : "log a message to output", + "operationId" : "Control_LogMessage", + "consumes" : [ "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "logMessage", + "required" : true, + "schema" : { + "$ref" : "#/definitions/logMessage" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/control/flags" : { + "put" : { + "tags" : [ "control" ], + "summary" : "set flags for the objects in this server to use", + "operationId" : "Control_SetFlags", + "consumes" : [ "application/json" ], + "parameters" : [ { + "in" : "body", + "name" : "flags", + "required" : true, + "schema" : { + "type" : "object" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/control/command" : { + "put" : { + "tags" : [ "control" ], + "summary" : "send an arbitrary command", + "operationId" : "Control_SendCommand", + "parameters" : [ { + "name" : "cmd", + "in" : "query", + "description" : "command string", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/registry/connect" : { + "put" : { + "tags" : [ "registry" ], + "summary" : "Connect to registry", + "description" : "Connect to the Azure IoTHub registry. More specifically, the SDK saves the connection string that is passed in for future use.", + "operationId" : "Registry_Connect", + "parameters" : [ { + "name" : "connectionString", + "in" : "query", + "description" : "connection string", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/registry/{connectionId}/disconnect/" : { + "put" : { + "tags" : [ "registry" ], + "summary" : "Disconnect from the registry", + "description" : "Disconnects from the Azure IoTHub registry. More specifically, closes all connections and cleans up all resources for the active connection", + "operationId" : "Registry_Disconnect", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/registry/{connectionId}/moduleTwin/{deviceId}/{moduleId}" : { + "get" : { + "tags" : [ "registry" ], + "summary" : "gets the module twin for the given deviceid and moduleid", + "operationId" : "Registry_GetModuleTwin", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "deviceId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "name" : "moduleId", + "in" : "path", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/twin" + } + } + }, + "x-accepts" : "application/json" + }, + "patch" : { + "tags" : [ "registry" ], + "summary" : "update the module twin for the given deviceId and moduleId", + "operationId" : "Registry_PatchModuleTwin", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "deviceId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "name" : "moduleId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "twin", + "required" : true, + "schema" : { + "$ref" : "#/definitions/twin" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/registry/{connectionId}/deviceTwin/{deviceId}" : { + "get" : { + "tags" : [ "registry" ], + "summary" : "gets the device twin for the given deviceid", + "operationId" : "Registry_GetDeviceTwin", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "deviceId", + "in" : "path", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/twin" + } + } + }, + "x-accepts" : "application/json" + }, + "patch" : { + "tags" : [ "registry" ], + "summary" : "update the device twin for the given deviceId", + "operationId" : "Registry_PatchDeviceTwin", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "deviceId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "twin", + "required" : true, + "schema" : { + "$ref" : "#/definitions/twin" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/connect/{transportType}" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Connect to the azure IoT Hub as a module", + "operationId" : "Module_Connect", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "transportType", + "in" : "path", + "description" : "Transport to use", + "required" : true, + "type" : "string", + "enum" : [ "amqp", "amqpws", "mqtt", "mqttws", "http" ] + }, { + "name" : "connectionString", + "in" : "query", + "description" : "connection string", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "caCertificate", + "required" : false, + "schema" : { + "$ref" : "#/definitions/certificate" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/disconnect" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Disconnect the module", + "operationId" : "Module_Disconnect", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/module/connectFromEnvironment/{transportType}" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Connect to the azure IoT Hub as a module using the environment variables", + "operationId" : "Module_ConnectFromEnvironment", + "parameters" : [ { + "name" : "transportType", + "in" : "path", + "description" : "Transport to use", + "required" : true, + "type" : "string", + "enum" : [ "amqp", "amqpws", "mqtt", "mqttws", "http" ] + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/module/createFromConnectionstring/{transportType}" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Create a module client from a connection string", + "operationId" : "Module_CreateFromConnectionString", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "transportType", + "in" : "path", + "description" : "Transport to use", + "required" : true, + "type" : "string", + "enum" : [ "amqp", "amqpws", "mqtt", "mqttws", "http" ] + }, { + "name" : "connectionString", + "in" : "query", + "description" : "connection string", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "caCertificate", + "required" : false, + "schema" : { + "$ref" : "#/definitions/certificate" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/createFromEnvironment/{transportType}" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Create a module client using the EdgeHub environment", + "operationId" : "Module_CreateFromEnvironment", + "parameters" : [ { + "name" : "transportType", + "in" : "path", + "description" : "Transport to use", + "required" : true, + "type" : "string", + "enum" : [ "amqp", "amqpws", "mqtt", "mqttws", "http" ] + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/module/createFromX509/{transportType}" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Create a module client from X509 credentials", + "operationId" : "Module_CreateFromX509", + "parameters" : [ { + "name" : "transportType", + "in" : "path", + "description" : "Transport to use", + "required" : true, + "type" : "string", + "enum" : [ "amqp", "amqpws", "mqtt", "mqttws", "http" ] + }, { + "in" : "body", + "name" : "X509", + "required" : true, + "schema" : { + "type" : "object" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/connect2" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Connect the module", + "operationId" : "Module_Connect2", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/reconnect" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Reconnect the module", + "operationId" : "Module_Reconnect", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "forceRenewPassword", + "in" : "query", + "description" : "True to force SAS renewal", + "required" : false, + "type" : "boolean" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/disconnect2" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Disonnect the module", + "operationId" : "Module_Disconnect2", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/destroy" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Disonnect and destroy the module client", + "operationId" : "Module_Destroy", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/enableTwin" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Enable module twins", + "operationId" : "Module_EnableTwin", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/enableMethods" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Enable methods", + "operationId" : "Module_EnableMethods", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/enableInputMessages" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Enable input messages", + "operationId" : "Module_EnableInputMessages", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/twin" : { + "get" : { + "tags" : [ "module" ], + "summary" : "Get the device twin", + "operationId" : "Module_GetTwin", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/twin" + } + } + }, + "x-accepts" : "application/json" + }, + "patch" : { + "tags" : [ "module" ], + "summary" : "Updates the device twin", + "operationId" : "Module_PatchTwin", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "twin", + "required" : true, + "schema" : { + "$ref" : "#/definitions/twin" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/twinDesiredPropPatch" : { + "get" : { + "tags" : [ "module" ], + "summary" : "Wait for the next desired property patch", + "operationId" : "Module_WaitForDesiredPropertiesPatch", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/twin" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/event" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Send an event", + "operationId" : "Module_SendEvent", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "eventBody", + "required" : true, + "schema" : { + "$ref" : "#/definitions/eventBody" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/outputEvent/{outputName}" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Send an event to a module output", + "operationId" : "Module_SendOutputEvent", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "outputName", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "eventBody", + "required" : true, + "schema" : { + "$ref" : "#/definitions/eventBody" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/inputMessage/{inputName}" : { + "get" : { + "tags" : [ "module" ], + "summary" : "Wait for a message on a module input", + "operationId" : "Module_WaitForInputMessage", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "inputName", + "in" : "path", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/eventBody" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/waitForMethodAndReturnResponse/{methodName}" : { + "put" : { + "tags" : [ "module" ], + "summary" : "Wait for a method call, verify the request, and return the response.", + "description" : "This is a workaround to deal with SDKs that only have method call operations that are sync. This function responds to the method with the payload of this function, and then returns the method parameters. Real-world implemenatations would never do this, but this is the only same way to write our test code right now (because the method handlers for C, Java, and probably Python all return the method response instead of supporting an async method call)", + "operationId" : "Module_WaitForMethodAndReturnResponse", + "consumes" : [ "application/json" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "methodName", + "in" : "path", + "description" : "name of the method to handle", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "requestAndResponse", + "required" : true, + "schema" : { + "$ref" : "#/definitions/methodRequestAndResponse" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/moduleMethod/{deviceId}/{moduleId}" : { + "put" : { + "tags" : [ "module" ], + "summary" : "call the given method on the given module", + "operationId" : "Module_InvokeModuleMethod", + "consumes" : [ "application/json" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "deviceId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "name" : "moduleId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "methodInvokeParameters", + "required" : true, + "schema" : { + "$ref" : "#/definitions/methodInvoke" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "type" : "object" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/deviceMethod/{deviceId}" : { + "put" : { + "tags" : [ "module" ], + "summary" : "call the given method on the given device", + "operationId" : "Module_InvokeDeviceMethod", + "consumes" : [ "application/json" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "deviceId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "methodInvokeParameters", + "required" : true, + "schema" : { + "$ref" : "#/definitions/methodInvoke" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "type" : "object" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/connectionStatus" : { + "get" : { + "tags" : [ "module" ], + "summary" : "get the current connection status", + "operationId" : "Module_GetConnectionStatus", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "type" : "string" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/module/{connectionId}/connectionStatusChange" : { + "get" : { + "tags" : [ "module" ], + "summary" : "wait for the current connection status to change and return the changed status", + "operationId" : "Module_WaitForConnectionStatusChange", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "type" : "string" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/service/connect" : { + "put" : { + "tags" : [ "service" ], + "summary" : "Connect to service", + "description" : "Connect to the Azure IoTHub service. More specifically, the SDK saves the connection string that is passed in for future use.", + "operationId" : "Service_Connect", + "parameters" : [ { + "name" : "connectionString", + "in" : "query", + "description" : "connection string", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/service/{connectionId}/disconnect/" : { + "put" : { + "tags" : [ "service" ], + "summary" : "Disconnect from the service", + "description" : "Disconnects from the Azure IoTHub service. More specifically, closes all connections and cleans up all resources for the active connection", + "operationId" : "Service_Disconnect", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/service/{connectionId}/moduleMethod/{deviceId}/{moduleId}" : { + "put" : { + "tags" : [ "service" ], + "summary" : "call the given method on the given module", + "operationId" : "Service_InvokeModuleMethod", + "consumes" : [ "application/json" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "deviceId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "name" : "moduleId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "methodInvokeParameters", + "required" : true, + "schema" : { + "$ref" : "#/definitions/methodInvoke" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "type" : "object" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/service/{connectionId}/deviceMethod/{deviceId}" : { + "put" : { + "tags" : [ "service" ], + "summary" : "call the given method on the given device", + "operationId" : "Service_InvokeDeviceMethod", + "consumes" : [ "application/json" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "deviceId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "methodInvokeParameters", + "required" : true, + "schema" : { + "$ref" : "#/definitions/methodInvoke" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "type" : "object" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/service/{connectionId}/sendC2d/{deviceId}" : { + "put" : { + "tags" : [ "service" ], + "summary" : "Send a c2d message", + "operationId" : "Service_SendC2d", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "deviceId", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "eventBody", + "required" : true, + "schema" : { + "$ref" : "#/definitions/eventBody" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/device/connect/{transportType}" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Connect to the azure IoT Hub as a device", + "operationId" : "Device_Connect", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "transportType", + "in" : "path", + "description" : "Transport to use", + "required" : true, + "type" : "string", + "enum" : [ "amqp", "amqpws", "mqtt", "mqttws", "http" ] + }, { + "name" : "connectionString", + "in" : "query", + "description" : "connection string", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "caCertificate", + "required" : false, + "schema" : { + "$ref" : "#/definitions/certificate" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/disconnect" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Disconnect the device", + "operationId" : "Device_Disconnect", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/device/createFromConnectionString/{transportType}" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Create a device client from a connection string", + "operationId" : "Device_CreateFromConnectionString", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "transportType", + "in" : "path", + "description" : "Transport to use", + "required" : true, + "type" : "string", + "enum" : [ "amqp", "amqpws", "mqtt", "mqttws", "http" ] + }, { + "name" : "connectionString", + "in" : "query", + "description" : "connection string", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "caCertificate", + "required" : false, + "schema" : { + "$ref" : "#/definitions/certificate" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/device/createFromX509/{transportType}" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Create a device client from X509 credentials", + "operationId" : "Device_CreateFromX509", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "transportType", + "in" : "path", + "description" : "Transport to use", + "required" : true, + "type" : "string", + "enum" : [ "amqp", "amqpws", "mqtt", "mqttws", "http" ] + }, { + "in" : "body", + "name" : "X509", + "required" : true, + "schema" : { + "type" : "object" + } + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/connectResponse" + } + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/connect2" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Connect the device", + "operationId" : "Device_Connect2", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/reconnect" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Reconnect the device", + "operationId" : "Device_Reconnect", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "forceRenewPassword", + "in" : "query", + "description" : "True to force SAS renewal", + "required" : false, + "type" : "boolean" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/disconnect2" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Disconnect the device", + "operationId" : "Device_Disconnect2", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/destroy" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Disconnect and destroy the device client", + "operationId" : "Device_Destroy", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/enableMethods" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Enable methods", + "operationId" : "Device_EnableMethods", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/waitForMethodAndReturnResponse/{methodName}" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Wait for a method call, verify the request, and return the response.", + "description" : "This is a workaround to deal with SDKs that only have method call operations that are sync. This function responds to the method with the payload of this function, and then returns the method parameters. Real-world implemenatations would never do this, but this is the only same way to write our test code right now (because the method handlers for C, Java, and probably Python all return the method response instead of supporting an async method call)", + "operationId" : "Device_WaitForMethodAndReturnResponse", + "consumes" : [ "application/json" ], + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "name" : "methodName", + "in" : "path", + "description" : "name of the method to handle", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "requestAndResponse", + "required" : true, + "schema" : { + "$ref" : "#/definitions/methodRequestAndResponse" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/enableC2dMessages" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Enable c2d messages", + "operationId" : "Device_EnableC2dMessages", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/event" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Send an event", + "operationId" : "Device_SendEvent", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "eventBody", + "required" : true, + "schema" : { + "$ref" : "#/definitions/eventBody" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/c2dMessage" : { + "get" : { + "tags" : [ "device" ], + "summary" : "Wait for a c2d message", + "operationId" : "Device_WaitForC2dMessage", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/eventBody" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/enableTwin" : { + "put" : { + "tags" : [ "device" ], + "summary" : "Enable device twins", + "operationId" : "Device_EnableTwin", + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/twin" : { + "get" : { + "tags" : [ "device" ], + "summary" : "Get the device twin", + "operationId" : "Device_GetTwin", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/twin" + } + } + }, + "x-accepts" : "application/json" + }, + "patch" : { + "tags" : [ "device" ], + "summary" : "Updates the device twin", + "operationId" : "Device_PatchTwin", + "consumes" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + }, { + "in" : "body", + "name" : "twin", + "required" : true, + "schema" : { + "$ref" : "#/definitions/twin" + } + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-contentType" : "application/json", + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/twinDesiredPropPatch" : { + "get" : { + "tags" : [ "device" ], + "summary" : "Wait for the next desired property patch", + "operationId" : "Device_WaitForDesiredPropertiesPatch", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "$ref" : "#/definitions/twin" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/connectionStatus" : { + "get" : { + "tags" : [ "device" ], + "summary" : "get the current connection status", + "operationId" : "Device_GetConnectionStatus", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "type" : "string" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/device/{connectionId}/connectionStatusChange" : { + "get" : { + "tags" : [ "device" ], + "summary" : "wait for the current connection status to change and return the changed status", + "operationId" : "Device_WaitForConnectionStatusChange", + "produces" : [ "application/json" ], + "parameters" : [ { + "name" : "connectionId", + "in" : "path", + "description" : "Id for the connection", + "required" : true, + "type" : "string" + } ], + "responses" : { + "200" : { + "description" : "OK", + "schema" : { + "type" : "string" + } + } + }, + "x-accepts" : "application/json" + } + }, + "/net/setDestination/{ip}/{transportType}" : { + "put" : { + "tags" : [ "net" ], + "summary" : "Set destination for net disconnect ops", + "operationId" : "Net_SetDestination", + "parameters" : [ { + "name" : "ip", + "in" : "path", + "required" : true, + "type" : "string" + }, { + "name" : "transportType", + "in" : "path", + "description" : "Transport to use", + "required" : true, + "type" : "string", + "enum" : [ "amqp", "amqpws", "mqtt", "mqttws", "http" ] + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/net/disconnect/{disconnectType}" : { + "put" : { + "tags" : [ "net" ], + "summary" : "Simulate a network disconnection", + "operationId" : "Net_Disconnect", + "parameters" : [ { + "name" : "disconnectType", + "in" : "path", + "description" : "disconnect method for dropped connection tests", + "required" : true, + "type" : "string", + "enum" : [ "DROP", "REJECT" ] + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/net/reconnect" : { + "put" : { + "tags" : [ "net" ], + "summary" : "Reconnect the network after a simulated network disconnection", + "operationId" : "Net_Reconnect", + "parameters" : [ ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/net/disconnectAfterC2d/{disconnectType}" : { + "put" : { + "tags" : [ "net" ], + "summary" : "Simulate a disconnect after the next C2D transfer", + "operationId" : "Net_DisconnectAfterC2d", + "parameters" : [ { + "name" : "disconnectType", + "in" : "path", + "description" : "disconnect method for dropped connection tests", + "required" : true, + "type" : "string", + "enum" : [ "DROP", "REJECT" ] + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + }, + "/net/disconnectAfterD2c/{disconnectType}" : { + "put" : { + "tags" : [ "net" ], + "summary" : "Simulate a disconnect after the next D2C transfer", + "operationId" : "Net_DisconnectAfterD2c", + "parameters" : [ { + "name" : "disconnectType", + "in" : "path", + "description" : "disconnect method for dropped connection tests", + "required" : true, + "type" : "string", + "enum" : [ "DROP", "REJECT" ] + } ], + "responses" : { + "200" : { + "description" : "OK" + } + }, + "x-accepts" : "application/json" + } + } + }, + "definitions" : { + "logMessage" : { + "type" : "object", + "properties" : { + "message" : { + "type" : "string", + "description" : "text of message" + } + }, + "description" : "message from the test script to output to the log" + }, + "connectResponse" : { + "type" : "object", + "properties" : { + "connectionId" : { + "type" : "string", + "description" : "unique identifier for this connection" + } + }, + "description" : "result of a connection to a service, device, or module client" + }, + "twin" : { + "type" : "object", + "properties" : { + "desired" : { + "type" : "object", + "description" : "desired properties", + "properties" : { } + }, + "reported" : { + "type" : "object", + "description" : "reported properties", + "properties" : { } + } + }, + "description" : "device twin or module twin" + }, + "certificate" : { + "type" : "object", + "properties" : { + "cert" : { + "type" : "string", + "description" : "unique identifier for this connection" + } + }, + "description" : "certificate in the body of a message" + }, + "eventBody" : { + "type" : "object", + "properties" : { + "body" : { + "type" : "object", + "description" : "payload to send to the method", + "properties" : { } + }, + "horton_flags" : { + "type" : "object", + "description" : "flags used by horton", + "properties" : { } + }, + "attributes" : { + "type" : "object", + "description" : "Message attributes", + "properties" : { } + } + }, + "description" : "body for an invoming or outgoing event or message" + }, + "methodRequestAndResponse" : { + "type" : "object", + "properties" : { + "requestPayload" : { + "type" : "object", + "description" : "payload for the request that arrived from the service. Used to verify that the correct request arrived.", + "properties" : { } + }, + "responsePayload" : { + "type" : "object", + "description" : "payload for the response to return to the service. Used to verify that the correct request arrived.", + "properties" : { } + }, + "statusCode" : { + "type" : "integer", + "description" : "status code to return to the service" + } + }, + "description" : "parameters and response for a sync method call" + }, + "methodInvoke" : { + "type" : "object", + "properties" : { + "methodName" : { + "type" : "string", + "description" : "name of method to invoke" + }, + "payload" : { + "type" : "object", + "description" : "payload to send to the method", + "properties" : { } + }, + "responseTimeoutInSeconds" : { + "type" : "integer", + "description" : "number of seconds to wait for a response" + }, + "connectTimeoutInSeconds" : { + "type" : "integer", + "description" : "number of seconds to wait for the module to connect" + } + }, + "description" : "parameters used to invoke a method" + } + } +} \ No newline at end of file diff --git a/docker_images/javalite/wrapper/src/main/resources/vertx-default-jul-logging.properties b/docker_images/javalite/wrapper/src/main/resources/vertx-default-jul-logging.properties new file mode 100644 index 00000000..866e12f8 --- /dev/null +++ b/docker_images/javalite/wrapper/src/main/resources/vertx-default-jul-logging.properties @@ -0,0 +1,30 @@ +# +# Copyright 2014 Red Hat, Inc. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# and Apache License v2.0 which accompanies this distribution. +# +# The Eclipse Public License is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# The Apache License v2.0 is available at +# http://www.opensource.org/licenses/apache2.0.php +# +# You may elect to redistribute this code under either of these licenses. +# +handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler +java.util.logging.SimpleFormatter.format=%5$s %6$s\n +java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter +java.util.logging.ConsoleHandler.level=FINEST +java.util.logging.FileHandler.level=INFO +java.util.logging.FileHandler.formatter=io.vertx.core.logging.VertxLoggerFormatter + +# Put the log in the system temporary directory +java.util.logging.FileHandler.pattern=vertx.log + +.level=INFO +# for detailed routing info: io.vertx.ext.web.level=FINEST +io.vertx.level=INFO +com.hazelcast.level=INFO +io.netty.util.internal.PlatformDependent.level=SEVERE \ No newline at end of file diff --git a/swagger/generate.sh b/swagger/generate.sh index ecbb2612..0f31ac35 100755 --- a/swagger/generate.sh +++ b/swagger/generate.sh @@ -8,7 +8,7 @@ function usage { echo " $0 [lang]" echo " example: $0 node" echo "" - echo "lang can be one of [node, csharp, c, java, pythonv2]" + echo "lang can be one of [node, csharp, c, java, pythonv2, javalite]" echo "" } @@ -22,6 +22,10 @@ case $language in swagger_language=java-vertx tags="control device module service registry" ;; + javalite) + swagger_language=java-vertx + tags="control device module service registry" + ;; c) swagger_language=restbed tags="control device module service registry" diff --git a/vsts/gate-horton.yaml b/vsts/gate-horton.yaml index 074ed73b..2603044e 100644 --- a/vsts/gate-horton.yaml +++ b/vsts/gate-horton.yaml @@ -11,6 +11,7 @@ jobs: node18: { variant: node18 } c: { language: c } java: { language: java } + javalite: { language: javalite } csharp: { language: csharp } py38: { variant: py38 } steps: @@ -39,6 +40,7 @@ jobs: py38_mqtt_edgehub_module_async: { suite: py38_mqtt_edgehub_module_async } py38_mqtt_edgehub_module: { suite: py38_mqtt_edgehub_module } py38_mqtt_iothub_module_quick_drop: { suite: py38_mqtt_iothub_device_quick_drop } + javalite_mqtt_edgehub_module: { suite: javalite_mqtt_edgehub_module } steps: - template: templates/steps-deploy-and-run-pytest.yaml parameters: diff --git a/vsts/gate-java-lite.yaml b/vsts/gate-java-lite.yaml new file mode 100644 index 00000000..5b65f2ee --- /dev/null +++ b/vsts/gate-java-lite.yaml @@ -0,0 +1,5 @@ +name: $(BuildID)_java_$(Horton.Commit)_$(BuildDefinitionName) +variables: + Horton.FrameworkRoot: $(Build.SourcesDirectory) +jobs: +- template: templates/jobs-gate-javalite.yaml diff --git a/vsts/templates/jobs-gate-java-lite.yaml b/vsts/templates/jobs-gate-java-lite.yaml new file mode 100644 index 00000000..926b9dd3 --- /dev/null +++ b/vsts/templates/jobs-gate-java-lite.yaml @@ -0,0 +1,28 @@ +jobs: +- job: "build_linux_amd64" + pool: + vmImage: 'ubuntu-20.04' + steps: + - template: steps-build-docker-image.yaml + parameters: + language: javalite + +- job: "test_linux_amd64" + pool: + vmImage: 'ubuntu-20.04' + dependsOn: + - "build_linux_amd64" + strategy: + matrix: + # ModuleClient to IotHub tests are disabled for Java because Java e2e tests outside of Horton already run these scenarios + # javalite_mqtt_iothub_module: { suite: javalite_mqtt_iothub_module } + # javalite_mqttws_iothub_module: { suite: javalite_mqttws_iothub_module } + javalite_mqtt_edgehub_module: { suite: javalite_mqtt_edgehub_module } + #javalite_mqttws_edgehub_module: { suite: javalite_mqttws_edgehub_module } + + steps: + - template: steps-deploy-and-run-pytest.yaml + parameters: + forced_image: $(Horton.ForcedImage) + suite: $(suite) + diff --git a/vsts/templates/steps-build-docker-image.yaml b/vsts/templates/steps-build-docker-image.yaml index 9eacc149..40c900f8 100644 --- a/vsts/templates/steps-build-docker-image.yaml +++ b/vsts/templates/steps-build-docker-image.yaml @@ -67,6 +67,8 @@ steps: $RepoToPass="Azure/azure-iot-sdk-node" } elseif ($LanguageToPass -like 'csharp') { $RepoToPass="Azure/azure-iot-sdk-csharp" + } elseif ($LanguageToPass -like 'javalite') { + $RepoToPass="Azure/azure-iot-sdk-lite-java" } elseif ($LanguageToPass -like 'java') { $RepoToPass="Azure/azure-iot-sdk-java" } elseif ($LanguageToPass -like 'pythonv2') {