Skip to content

Commit

Permalink
Adding opc ua agent code for open source project.
Browse files Browse the repository at this point in the history
  • Loading branch information
Praveen M Vaidya committed Sep 7, 2018
1 parent 84f5c59 commit 300d447
Show file tree
Hide file tree
Showing 173 changed files with 9,165 additions and 0 deletions.
251 changes: 251 additions & 0 deletions opcua-agent/gateway/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
<?xml version="1.0"?>
<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>c8y.agents</groupId>
<artifactId>opcua-agent</artifactId>
<version>9.14.0-SNAPSHOT</version>
</parent>

<groupId>c8y-agents</groupId>
<artifactId>opcua-agent-gateway</artifactId>
<name>Cumulocity :: Agents :: OPC UA :: Gateway</name>

<properties>
<package.name>opcua-agent-server</package.name>
<package.directory>opcua</package.directory>
<agent.main.class>com.cumulocity.opcua.gateway.GatewayMain</agent.main.class>
</properties>

<dependencies>
<!-- cumulocity -->
<dependency>
<groupId>c8y-agents</groupId>
<artifactId>opcua-agent-platform</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.nsn.cumulocity.clients-java</groupId>
<artifactId>microservice-logging</artifactId>
<version>${c8y.microservice.version}</version>
</dependency>

<dependency>
<groupId>com.nsn.cumulocity.clients-java</groupId>
<artifactId>agent-framework-repositories</artifactId>
</dependency>

<!-- spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- async aspectj -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>

<!-- aspectj -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.7</version>
</dependency>

<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.7</version>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.52</version>
</dependency>

<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.52</version>
</dependency>

<!-- utils -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.mapdb</groupId>
<artifactId>mapdb</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- javax.annotations -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
<scope>provided</scope>
</dependency>

<!-- testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<!-- spock -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.9</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<complianceLevel>1.7</complianceLevel>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.9</version>
<configuration>
<forceAjcCompile>true</forceAjcCompile>
<weaveDirectories>
<weaveDirectory>${project.build.directory}/classes</weaveDirectory>
</weaveDirectories>
<sources>
<source>
<basedir>${basedir}/src/main/aspect</basedir>
</source>
</sources>
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<id>aspectj-weaver</id>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>exploded</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.nsn.cumulocity.dependencies</groupId>
<artifactId>3rd-license-maven-plugin</artifactId>
<executions>
<execution>
<id>3rd-license-generate</id>
<phase>package</phase>
<goals>
<goal>3rd-license-generate</goal>
</goals>
<configuration>
<thirdPartyLicenseFilePath>${project.basedir}/src/main/configuration/</thirdPartyLicenseFilePath>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>com.nsn.cumulocity.clients-java</groupId>
<artifactId>microservice-package-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.cumulocity.opcua.gateway.aspect;

import com.cumulocity.opcua.gateway.model.core.HasGateway;
import com.cumulocity.opcua.gateway.model.core.Credentials;
import com.cumulocity.opcua.gateway.model.gateway.Gateway;
import com.cumulocity.opcua.gateway.repository.configuration.ContextProvider;
import com.cumulocity.opcua.gateway.repository.configuration.ContextProvider.Callable;
import com.cumulocity.rest.representation.devicebootstrap.DeviceCredentialsRepresentation;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class RunWithinContextAspect {

@Pointcut("@annotation(com.cumulocity.opcua.gateway.annotations.RunWithinContext)")
public void withAnnotation() {
}

@Pointcut("execution(* *(..))")
public void atExecution() {
}

@Around("withAnnotation() && atExecution() && args(credentials,..)")
public Object runWithinContext(Credentials credentials, ProceedingJoinPoint jointPoint) throws Throwable {
return doInvoke(credentials, jointPoint);
}

@Around("withAnnotation() && atExecution() && args(credentials,..)")
public Object runWithinContext(HasGateway credentials, ProceedingJoinPoint jointPoint) throws Throwable {
return doInvoke(credentials.getGateway(), jointPoint);
}

@Around("withAnnotation() && atExecution() && args(credentials,..)")
public Object runWithinContext(DeviceCredentialsRepresentation credentials, ProceedingJoinPoint jointPoint) throws Throwable {
return doInvoke(Gateway.gateway()
.tenant(credentials.getTenantId())
.name(credentials.getUsername())
.password(credentials.getPassword())
.build(), jointPoint);
}

private Object doInvoke(Credentials credentials, final ProceedingJoinPoint jointPoint) throws Throwable {
return ContextProvider.doInvoke(credentials, new Callable<Object>() {
@Override
public Object call() throws Throwable {
return jointPoint.proceed();
}
});
}
}
30 changes: 30 additions & 0 deletions opcua-agent/gateway/src/main/configuration/cumulocity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"apiVersion":"1",
"version":"@project.version@",
"provider": {
"name":"Cumulocity GmbH"
},
"isolation":"MULTI_TENANT",
"requiredRoles": [
],
"roles":[
],
"livenessProbe":{
"httpGet":{
"path": "/health",
"port": 80

},
"initialDelaySeconds": 200,
"periodSeconds": 10
},
"readinessProbe":{
"httpGet":{
"path": "/health",
"port": 80

},
"initialDelaySeconds": 220,
"periodSeconds": 10
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
server.port=6670

gateway.identifier=opcua
gateway.bootstrapFixedDelay=10000

platform.url=http://localhost
platform.proxyHost=
platform.proxyPort=
platform.proxyPassword=
platform.proxyUsername=
platform.bootstrap.user=devicebootstrap
platform.bootstrap.tenant=management
platform.bootstrap.password=Fhdt1bb1f

client.applicationName=c8y_OPCUAGateway

# certificate configuration
client.organisation=cumulocity
client.privateKeyPassword=cumulocity
client.autoReconnect=true

Loading

0 comments on commit 300d447

Please sign in to comment.