Skip to content

Commit

Permalink
CARMA Cloud ambassador integration (#200)
Browse files Browse the repository at this point in the history
<!-- Thanks for the contribution, this is awesome. -->

# PR Details
## Description

This PR primarily focuses on merging a branch into develop, which
encompasses the integration testing of CARMA Cloud with CDASim. The
purpose of this integration test was to assess the communication between
CARMA Cloud and CDASim, ensuring that:

All components operate correctly within CDASim without encountering any
significant problems.
CARMA Cloud successfully registers with Ambassador.
CARMA Cloud receives and processes time synchronization messages.

## Related GitHub Issue

<!--- This project only accepts pull requests related to open GitHub
issues or Jira Keys -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please DO NOT name partially fixed issues, instead open an issue
specific to this fix -->
<!--- Please link to the issue here: -->

## Related Jira Key


[CXC-10](https://usdot-carma.atlassian.net/jira/software/c/projects/CXC/issues/CXC-10)

<!-- e.g. CAR-123 -->

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->

- [ ] Defect fix (non-breaking change that fixes an issue)
- [x] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that cause existing functionality
to change)

## Checklist:

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->

- [ ] I have added any new packages to the sonar-scanner.properties file
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the
[**CONTRIBUTING**](https://github.com/usdot-fhwa-stol/carma-platform/blob/develop/Contributing.md)
document.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.


[CXC-10]:
https://usdot-carma.atlassian.net/browse/CXC-10?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Cheng Yuan <cheng.yuan@leidos.com>
Co-authored-by: Kyle Rush <kyle.rush@leidos.com>
Co-authored-by: Cheng Yuan <84340069+chengyuan0124@users.noreply.github.com>
  • Loading branch information
4 people authored May 3, 2024
1 parent 9e6494c commit caac2ff
Show file tree
Hide file tree
Showing 34 changed files with 1,177 additions and 4 deletions.
7 changes: 6 additions & 1 deletion co-simulation/bundle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@
<artifactId>mosaic-infrastructure</artifactId>
<version>${mosaic.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.mosaic</groupId>
<artifactId>mosaic-carma-cloud</artifactId>
<version>${mosaic.version}</version>
</dependency>
<!-- Tutorial Applications -->

<dependency>
Expand Down Expand Up @@ -262,4 +267,4 @@
</build>
</profile>
</profiles>
</project>
</project>
11 changes: 11 additions & 0 deletions co-simulation/bundle/src/assembly/resources/etc/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@
<pattern>%date %-5level %C{0}:%line - %msg%n</pattern>
</encoder>
</appender>
<appender name="CarmaCloudLog" class="ch.qos.logback.core.FileAppender">
<charset>UTF-8</charset>
<file>${logDirectory}/CarmaCloud.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%date %-5level %C{0}:%line - %msg%n</pattern>
</encoder>
</appender>
<appender name="EnvironmentLog" class="ch.qos.logback.core.FileAppender">
<charset>UTF-8</charset>
<file>${logDirectory}/Environment.log</file>
Expand Down Expand Up @@ -209,6 +216,10 @@
<appender-ref ref="InfrastructureLog"/>
</logger>

<logger name="org.eclipse.mosaic.fed.carmacloud" additivity="false" level="TRACE">
<appender-ref ref="CarmaCloudLog"/>
</logger>

<logger name="org.eclipse.mosaic.fed.output" additivity="false" level="INFO">
<appender-ref ref="MosaicLog"/>
</logger>
Expand Down
14 changes: 14 additions & 0 deletions co-simulation/bundle/src/assembly/resources/etc/runtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@
],
"javaClasspathEntries": []
},
{
"id": "carma-cloud",
"classname": "org.eclipse.mosaic.fed.carmacloud.ambassador.CarmaCloudMessageAmbassador",
"configuration": "carma-cloud_config.json",
"priority": 50,
"host": "local",
"port": 0,
"deploy": false,
"start": false,
"subscriptions": [
"V2xMessageReception"
],
"javaClasspathEntries": []
},

{
"id": "mapping",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"sumo": true,
"carla": true,
"carma": true,
"infrastructure": true
"infrastructure": true,
"carma-cloud": true

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"updateInterval": 100,
"carlaUE4Path": "/opt/carla/",
"bridgePath": "/opt/carma-simulation/scenarios/Town04_test/carla; bridge.sh",
"bridgePath": "/opt/carma-simulation/scenarios/Town04_carma_cloud/carla; bridge.sh",
"carlaConnectionPort": 8913,
"carlaCDASimAdapterUrl":"http://127.0.0.1:8090/RPC2"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"updateInterval": 100
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"updateInterval": 100
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"sumo": true,
"carla": true,
"carma": true,
"infrastructure": true
"infrastructure": true,
"carma-cloud": true

}
}
105 changes: 105 additions & 0 deletions co-simulation/fed/mosaic-carma-cloud/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.mosaic</groupId>
<artifactId>mosaic-parent</artifactId>
<version>22.1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>mosaic-carma-cloud</artifactId>
<name>CARMA Cloud Ambassador</name>

<dependencies>
<dependency>
<groupId>org.eclipse.mosaic</groupId>
<artifactId>mosaic-rti-api</artifactId>
<version>${mosaic.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.mosaic</groupId>
<artifactId>mosaic-objects</artifactId>
<version>${mosaic.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.mosaic</groupId>
<artifactId>mosaic-objects</artifactId>
<version>${mosaic.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>gov.dot.fhwa.saxton</groupId>
<artifactId>mosaic-carma-utils</artifactId>
<version>${mosaic.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.mosaic</groupId>
<artifactId>mosaic-interactions</artifactId>
<version>${mosaic.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.mosaic</groupId>
<artifactId>mosaic-utils</artifactId>
<version>${mosaic.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.mosaic</groupId>
<artifactId>mosaic-geomath</artifactId>
<version>${mosaic.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.mosaic</groupId>
<artifactId>mosaic-application</artifactId>
<version>22.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>

<profiles>
<profile>
<id>skip-carma-cloud-tests</id>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2023 LEIDOS.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.eclipse.mosaic.fed.carmacloud.ambassador;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.HttpURLConnection;
import com.google.gson.Gson;
import gov.dot.fhwa.saxton.TimeSyncMessage;


/**
* CarmaCloudInstance class represents a physical instance of an
* CARMA Cloud in the simulated environment.
* It contains information about the instance such as its id and target address
*/
public class CarmaCloudInstance
{
// unique simulation identifier for the CARMA Cloud instance
private final String carmaCloudId;
// URL endpoint where to send simulation time sync messages
private final String carmaCloudUrl;


/**
* Constructor for CarmaCloudInstance
*
* @param sId the ID of the CARMA Cloud instance.
* @param sUrl the receive time synchronization message port of the infrastructure.
*/
public CarmaCloudInstance(String sId, String sUrl)
{
carmaCloudId = sId;
carmaCloudUrl = sUrl;
}


/**
* Returns the URL endpoint of the CARMA Cloud instance
*
* @return String URL endpoint of the CARMA Cloud instance
*/
public String getCarmaCloudUrl()
{
return carmaCloudUrl;
}


/**
* Returns the ID of the CARMA Cloud instance
*
* @return String the ID of the CARMA Cloud instance
*/
public String getCarmaCloudId()
{
return carmaCloudId;
}


/**
* Sends time sync data to the CARMA Cloud Instance
*
* @param oMsg the JSON time sync state to transmit
* @throws IOException if there is an issue with the underlying URL connection
*/
public void sendTimeSyncMsg(TimeSyncMessage oMsg)
throws IOException
{
HttpURLConnection oHttp = (HttpURLConnection)new URL(carmaCloudUrl).openConnection();
oHttp.setRequestMethod("POST");
oHttp.setDoOutput(true);
try (DataOutputStream oOut = new DataOutputStream(oHttp.getOutputStream()))
{
oOut.write(new Gson().toJson(oMsg).getBytes());
}
if (oHttp.getResponseCode() != 200)
throw new IOException(String.format("CARMA Cloud failure %d %s", oHttp.getResponseCode(), oHttp.getResponseMessage()));
}
}
Loading

0 comments on commit caac2ff

Please sign in to comment.