diff options
23 files changed, 662 insertions, 526 deletions
diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceObserver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceObserver.java index 2e1a6e95..f30212dc 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceObserver.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DBResourceObserver.java @@ -23,5 +23,5 @@ package org.onap.ccsdk.sli.core.dblib; import java.util.Observer; public interface DBResourceObserver extends Observer { - public boolean isMonitorDbResponse(); + boolean isMonitorDbResponse(); } diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataAccessor.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataAccessor.java index 7921fa5c..fdfb47bc 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataAccessor.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataAccessor.java @@ -27,7 +27,7 @@ import javax.sql.rowset.CachedRowSet; public interface DataAccessor { - public abstract CachedRowSet getData(String statement, ArrayList<String> arguments, String preferredDS) - throws SQLException; + CachedRowSet getData(String statement, ArrayList<String> arguments, String preferredDS) + throws SQLException; } diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataSourceComparator.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataSourceComparator.java index bc14fb8b..4cfcc731 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataSourceComparator.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DataSourceComparator.java @@ -24,10 +24,10 @@ import java.util.Comparator; public interface DataSourceComparator extends Comparator <CachedDataSource>{ - public abstract CachedDataSource getLastUsed(); + CachedDataSource getLastUsed(); - public abstract void setLastUsed(CachedDataSource lastUsed); + void setLastUsed(CachedDataSource lastUsed); - public abstract int compare(CachedDataSource ds1, CachedDataSource ds2); + int compare(CachedDataSource ds1, CachedDataSource ds2); } diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DbLibService.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DbLibService.java index 0dea664d..b31de354 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DbLibService.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/DbLibService.java @@ -28,22 +28,22 @@ import javax.sql.rowset.CachedRowSet; public interface DbLibService { - /* (non-Javadoc) - * @see DataAccessor#getData(java.lang.String, java.util.ArrayList) - */ - public abstract CachedRowSet getData(String statement, - ArrayList<String> arguments, String preferredDS) - throws SQLException; - - /* (non-Javadoc) - * @see DataAccessor#writeData(java.lang.String, java.util.ArrayList) - */ - public abstract boolean writeData(String statement, - ArrayList<String> arguments, String preferredDS) - throws SQLException; - - public abstract boolean isActive(); - - public abstract Connection getConnection() throws SQLException; + /* (non-Javadoc) + * @see DataAccessor#getData(java.lang.String, java.util.ArrayList) + */ + CachedRowSet getData(String statement, + ArrayList<String> arguments, String preferredDS) + throws SQLException; + + /* (non-Javadoc) + * @see DataAccessor#writeData(java.lang.String, java.util.ArrayList) + */ + boolean writeData(String statement, + ArrayList<String> arguments, String preferredDS) + throws SQLException; + + boolean isActive(); + + Connection getConnection() throws SQLException; } diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java index 4b738d42..d53be0e7 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/config/BaseDBConfiguration.java @@ -22,83 +22,216 @@ package org.onap.ccsdk.sli.core.dblib.config; import java.util.Properties; +/** + * Base class responsible for parsing business logic for database configuration from given <code>Properties</code>. + */ public abstract class BaseDBConfiguration { - public static final String DATABASE_TYPE = "org.onap.ccsdk.sli.dbtype"; - public static final String DATABASE_URL = "org.onap.ccsdk.sli.jdbc.url"; - public static final String DATABASE_NAME = "org.onap.ccsdk.sli.jdbc.database"; - public static final String CONNECTION_NAME = "org.onap.ccsdk.sli.jdbc.connection.name"; - public static final String DATABASE_USER = "org.onap.ccsdk.sli.jdbc.user"; - public static final String DATABASE_PSSWD = "org.onap.ccsdk.sli.jdbc.password"; - public static final String CONNECTION_TIMEOUT="org.onap.ccsdk.sli.jdbc.connection.timeout"; - public static final String REQUEST_TIMEOUT = "org.onap.ccsdk.sli.jdbc.request.timeout"; - public static final String MIN_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.min"; - public static final String MAX_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.max"; - public static final String INIT_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.init"; - public static final String DATABASE_HOSTS = "org.onap.ccsdk.sli.jdbc.hosts"; - - - protected final Properties props; - - public BaseDBConfiguration(Properties properties) { - this.props = properties; - } - - public int getConnTimeout() { - try { - String value = props.getProperty(CONNECTION_TIMEOUT); - return Integer.parseInt(value); - } catch(Exception exc) { - return -1; - } - } - - public int getRequestTimeout() { - try { - String value = props.getProperty(REQUEST_TIMEOUT); - if(value == null) - return -1; - return Integer.parseInt(value); - } catch(Exception exc) { - return -1; - } - } - - public String getDbConnectionName() { - return props.getProperty(CONNECTION_NAME); - } - - public String getDatabaseName() { - return props.getProperty(DATABASE_NAME); - } - - public String getDbUserId() { - return props.getProperty(DATABASE_USER); - } - - public String getDbPasswd() { - return props.getProperty(DATABASE_PSSWD); - } - - public int getDbMinLimit() { - String value = props.getProperty(MIN_LIMIT); - return Integer.parseInt(value); - } - - public int getDbMaxLimit() { - String value = props.getProperty(MAX_LIMIT); - return Integer.parseInt(value); - } - - public int getDbInitialLimit() { - String value = props.getProperty(INIT_LIMIT); - return Integer.parseInt(value); - } - - public String getDbUrl() { - return props.getProperty(DATABASE_URL); - } - - public String getServerGroup() { - return null; - } + + /** + * Property key within a properties configuration File for db type + */ + public static final String DATABASE_TYPE = "org.onap.ccsdk.sli.dbtype"; + + /** + * Property key with a properties configuration File for db url + */ + public static final String DATABASE_URL = "org.onap.ccsdk.sli.jdbc.url"; + + /** + * Property key with a properties configuration File for database name + */ + public static final String DATABASE_NAME = "org.onap.ccsdk.sli.jdbc.database"; + + /** + * Property key with a properties configuration File for db database connection name + */ + public static final String CONNECTION_NAME = "org.onap.ccsdk.sli.jdbc.connection.name"; + + /** + * Property key with a properties configuration File for database user + */ + public static final String DATABASE_USER = "org.onap.ccsdk.sli.jdbc.user"; + + /** + * Property key with a properties configuration File for database password for associated with + * <code>org.onap.ccsdk.sli.jdbc.user</code>. + */ + public static final String DATABASE_PSSWD = "org.onap.ccsdk.sli.jdbc.password"; + + /** + * Property key with a properties configuration File for database connection timeout + */ + public static final String CONNECTION_TIMEOUT="org.onap.ccsdk.sli.jdbc.connection.timeout"; + + /** + * Property key with a properties configuration File for database request timeout + */ + public static final String REQUEST_TIMEOUT = "org.onap.ccsdk.sli.jdbc.request.timeout"; + + /** + * Property key with a properties configuration File for database minimum limit + */ + public static final String MIN_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.min"; + + /** + * Property key with a properties configuration File for database maximum limit + */ + public static final String MAX_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.max"; + + /** + * Property key with a properties configuration File for database initial limit + */ + public static final String INIT_LIMIT = "org.onap.ccsdk.sli.jdbc.limit.init"; + + /** + * Property key with a properties configuration File for database hosts + */ + public static final String DATABASE_HOSTS = "org.onap.ccsdk.sli.jdbc.hosts"; + + /** + * default value when the connection timeout is not present or cannot be parsed + */ + private static final int DEFAULT_CONNECTION_TIMEOUT = -1; + + /** + * default value when the request timeout is not present or cannot be parsed + */ + private static final int DEFAULT_REQUEST_TIMEOUT = -1; + + /** + * A set of properties with database configuration information. + */ + protected final Properties properties; + + /** + * Builds a configuration based on given properties + * + * @param properties properties represented by the public constant keys defined by this class + */ + public BaseDBConfiguration(final Properties properties) { + this.properties = properties; + } + + /** + * Extracts the connection timeout. + * + * @return the connection timeout, or <code>DEFAULT_CONNECTION_TIMEOUT</code> if not present + */ + public int getConnTimeout() { + return extractProperty(properties, CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT); + } + + /** + * Extracts the request timeout. + * + * @return the request timeout, or <code>DEFAULT_REQUEST_TIMEOUT</code> if not present + */ + public int getRequestTimeout() { + return extractProperty(properties, REQUEST_TIMEOUT, DEFAULT_REQUEST_TIMEOUT); + } + + /** + * A utility method to extract int property from Properties. + * + * @param properties a set of <code>Properties</code> + * @param propertyKey the key in question + * @param defaultValue the value to return if the key does not exist + * @return Either the property value for <code>propertyKey</code> or <code>defaultValue</code> if not present + */ + private static int extractProperty(final Properties properties, final String propertyKey, final int defaultValue) { + try { + final String valueString = properties.getProperty(propertyKey, Integer.toString(defaultValue)); + return Integer.parseInt(valueString); + } catch(final NumberFormatException e) { + return defaultValue; + } + } + + /** + * Extracts the db connection name. + * + * @return the db connection name, or <code>null</code> if not present + */ + public String getDbConnectionName() { + return properties.getProperty(CONNECTION_NAME); + } + + /** + * Extracts the db name. + * + * @return the db name, or <code>null</code> if not present + */ + public String getDatabaseName() { + return properties.getProperty(DATABASE_NAME); + } + + /** + * Extracts the db user id. + * + * @return the db user id, or <code>null</code> if not present + */ + public String getDbUserId() { + return properties.getProperty(DATABASE_USER); + } + + /** + * Extracts the db password. + * + * @return the db password, or <code>null</code> if not present + */ + public String getDbPasswd() { + return properties.getProperty(DATABASE_PSSWD); + } + + /** + * Extracts the db min limit. + * + * @return the db min limit + * @throws NumberFormatException if the property is not specified, or cannot be parsed as an <code>Integer</code>. + */ + public int getDbMinLimit() throws NumberFormatException { + String value = properties.getProperty(MIN_LIMIT); + return Integer.parseInt(value); + } + + /** + * Extracts the db max limit. + * + * @return the db max limit + * @throws NumberFormatException if the property is not specified, or cannot be parsed as an <code>Integer</code>. + */ + public int getDbMaxLimit() throws NumberFormatException { + String value = properties.getProperty(MAX_LIMIT); + return Integer.parseInt(value); + } + + /** + * Extracts the db initial limit. + * + * @return the db initial limit + * @throws NumberFormatException if the property is not specified, or cannot be parsed as an <code>Integer</code>. + */ + public int getDbInitialLimit() throws NumberFormatException { + String value = properties.getProperty(INIT_LIMIT); + return Integer.parseInt(value); + } + + /** + * Extracts the db url. + * + * @return the db url, or <code>null</code> if not present + */ + public String getDbUrl() { + return properties.getProperty(DATABASE_URL); + } + + /** + * Extracts the db server group. + * + * @return <code>null</code> + */ + @Deprecated + public String getServerGroup() { + return null; + } } diff --git a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitorObserver.java b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitorObserver.java index c17696a8..2fdde1ee 100644 --- a/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitorObserver.java +++ b/dblib/provider/src/main/java/org/onap/ccsdk/sli/core/dblib/pm/SQLExecutionMonitorObserver.java @@ -21,17 +21,17 @@ package org.onap.ccsdk.sli.core.dblib.pm; public interface SQLExecutionMonitorObserver { - public String getDbConnectionName(); + String getDbConnectionName(); - public long getInterval(); - public void setInterval(long value); + long getInterval(); + void setInterval(long value); - public long getInitialDelay(); - public void setInitialDelay(long value); + long getInitialDelay(); + void setInitialDelay(long value); - public long getExpectedCompletionTime(); - public void setExpectedCompletionTime(long value); + long getExpectedCompletionTime(); + void setExpectedCompletionTime(long value); - public long getUnprocessedFailoverThreshold(); - public void setUnprocessedFailoverThreshold(long value); + long getUnprocessedFailoverThreshold(); + void setUnprocessedFailoverThreshold(long value); } diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java index 41011e55..41011e55 100644 --- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibDefaultFileResolverTest.java diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java index 77589893..77589893 100644 --- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibEnvVarFileResolverTest.java diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java index 65ebfbae..65ebfbae 100644 --- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibJREFileResolverTest.java diff --git a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java index 0a032e8b..0a032e8b 100644 --- a/dblib/provider/src/test/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/propertiesfileresolver/DblibKarafRootFileResolverTest.java @@ -13,7 +13,7 @@ <parent> <groupId>org.onap.ccsdk.parent</groupId> <artifactId>odlparent-carbon-sr1</artifactId> - <version>0.0.1-SNAPSHOT</version> + <version>0.0.2-SNAPSHOT</version> </parent> <issueManagement> diff --git a/sli/common/pom.xml b/sli/common/pom.xml index f71ca35f..c367dd77 100755 --- a/sli/common/pom.xml +++ b/sli/common/pom.xml @@ -1,150 +1,157 @@ -<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> - <artifactId>sli</artifactId> - <groupId>org.onap.ccsdk.sli.core</groupId> - <version>0.1.2-SNAPSHOT</version> - </parent> - <artifactId>sli-common</artifactId> - <packaging>bundle</packaging> +<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> + <artifactId>sli</artifactId> + <groupId>org.onap.ccsdk.sli.core</groupId> + <version>0.1.2-SNAPSHOT</version> + </parent> + <artifactId>sli-common</artifactId> + <packaging>bundle</packaging> - <name>SLI - Common Classes</name> - <description>The SLI Common package includes common classes used by the various SLI subcomponents, as well as classes used by clients to interface with the service logic interpreter</description> + <name>SLI - Common Classes</name> + <description>The SLI Common package includes common classes used by the various SLI subcomponents, as well as classes used by clients to interface with the service logic interpreter</description> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.antlr</groupId> - <artifactId>antlr4</artifactId> - <version>${antlr.version}</version> - <type>jar</type> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>${slf4j.version}</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <version>1.7.5</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - <version>${commons.lang3.version}</version> - </dependency> - <dependency> - <groupId>org.opendaylight.mdsal</groupId> - <artifactId>yang-binding</artifactId> - <version>${odl.mdsal.yang.binding.version}</version> - </dependency> - <dependency> - <groupId>org.opendaylight.yangtools</groupId> - <artifactId>yang-common</artifactId> - <version>${odl.yangtools.version}</version> - </dependency> - <dependency> - <groupId>org.opendaylight.mdsal.model</groupId> - <artifactId>ietf-inet-types</artifactId> - <version>${odl.ietf-inet-types.version}</version> - </dependency> - <dependency> - <groupId>org.opendaylight.mdsal.model</groupId> - <artifactId>ietf-yang-types</artifactId> - <version>${odl.ietf-yang-types.version}</version> - </dependency> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-core-api</artifactId> - <version>${odl.mdsal.version}</version> - </dependency> - <dependency> - <groupId>org.opendaylight.yangtools</groupId> - <artifactId>yang-data-impl</artifactId> - <version>${odl.yangtools.version}</version> - </dependency> - <dependency> - <groupId>equinoxSDK381</groupId> - <artifactId>org.eclipse.osgi</artifactId> - <version>${equinox.osgi.version}</version> - </dependency> - <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - <version>${mysql.connector.version}</version> - <type>jar</type> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>dblib-provider</artifactId> - <version>${sdnctl.dblib.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>ch.vorburger.mariaDB4j</groupId> + <artifactId>mariaDB4j</artifactId> + <version>2.2.3</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.antlr</groupId> + <artifactId>antlr4</artifactId> + <version>${antlr.version}</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>${slf4j.version}</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>1.7.5</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>${commons.lang3.version}</version> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal</groupId> + <artifactId>yang-binding</artifactId> + <version>${odl.mdsal.yang.binding.version}</version> + </dependency> + <dependency> + <groupId>org.opendaylight.yangtools</groupId> + <artifactId>yang-common</artifactId> + <version>${odl.yangtools.version}</version> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal.model</groupId> + <artifactId>ietf-inet-types</artifactId> + <version>${odl.ietf-inet-types.version}</version> + </dependency> + <dependency> + <groupId>org.opendaylight.mdsal.model</groupId> + <artifactId>ietf-yang-types</artifactId> + <version>${odl.ietf-yang-types.version}</version> + </dependency> + <dependency> + <groupId>org.opendaylight.controller</groupId> + <artifactId>sal-core-api</artifactId> + <version>${odl.mdsal.version}</version> + </dependency> + <dependency> + <groupId>org.opendaylight.yangtools</groupId> + <artifactId>yang-data-impl</artifactId> + <version>${odl.yangtools.version}</version> + </dependency> + <dependency> + <groupId>equinoxSDK381</groupId> + <artifactId>org.eclipse.osgi</artifactId> + <version>${equinox.osgi.version}</version> + </dependency> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>${mysql.connector.version}</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>dblib-provider</artifactId> + <version>${sdnctl.dblib.version}</version> + </dependency> + </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.7</source> - <target>1.7</target> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>2.4</version> - <configuration> - <includes>**/*.xsd</includes> - <archive> - <manifest> - <mainClass>org.onap.ccsdk.sli.core.sli.SvcLogicParser</mainClass> - <packageName>org.onap.ccsdk.sli.core.sli</packageName> - <addDefaultImplementationEntries>true</addDefaultImplementationEntries> - </manifest> - </archive> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Export-Package>org.onap.ccsdk.sli.core.sli;version=${project.version}</Export-Package> - <Import-Package>*</Import-Package> - <Embed-Dependency>*;scope=compile;artifactId=commons-lang|commons-lang3</Embed-Dependency> - <Embed-Transitive>true</Embed-Transitive> - </instructions> - </configuration> - </plugin> - <plugin> - <groupId>org.antlr</groupId> - <artifactId>antlr4-maven-plugin</artifactId> - <version>${antlr.version}</version> - <executions> - <execution> - <configuration> - <outputDirectory>${project.basedir}/src/main/java/</outputDirectory> - </configuration> - <id>antlr</id> - <goals> - <goal>antlr4</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <configuration> + <includes>**/*.xsd</includes> + <archive> + <manifest> + <mainClass>org.onap.ccsdk.sli.core.sli.SvcLogicParser</mainClass> + <packageName>org.onap.ccsdk.sli.core.sli</packageName> + <addDefaultImplementationEntries>true</addDefaultImplementationEntries> + </manifest> + </archive> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Export-Package>org.onap.ccsdk.sli.core.sli;version=${project.version}</Export-Package> + <Import-Package>*</Import-Package> + <Embed-Dependency>*;scope=compile;artifactId=commons-lang|commons-lang3</Embed-Dependency> + <Embed-Transitive>true</Embed-Transitive> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.antlr</groupId> + <artifactId>antlr4-maven-plugin</artifactId> + <version>${antlr.version}</version> + <executions> + <execution> + <configuration> + <outputDirectory>${project.basedir}/src/main/java/</outputDirectory> + </configuration> + <id>antlr</id> + <goals> + <goal>antlr4</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/CommonConstants.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/CommonConstants.java new file mode 100644 index 00000000..d30b2b62 --- /dev/null +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/CommonConstants.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.core.sli; + +public interface CommonConstants { + + public static final String SERVICE_LOGIC_STATUS = "SvcLogic.status"; +} diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java index eaf57428..23277439 100644 --- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java +++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java @@ -8,9 +8,9 @@ * 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. @@ -38,39 +38,38 @@ import org.w3c.dom.Text; public class SvcLogicContext { - private static final Logger LOG = LoggerFactory - .getLogger(SvcLogicContext.class); - + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicContext.class); + private HashMap<String, String> attributes; - + private DOMDataBroker domDataBroker; - + private String status = "success"; - + public SvcLogicContext() { - this.attributes = new HashMap<String,String> (); - + this.attributes = new HashMap<> (); + } - + public SvcLogicContext(Properties props) { - this.attributes = new HashMap<String, String> (); - - if (props.containsKey("SvcLogic.status")) + this.attributes = new HashMap<> (); + + if (props.containsKey(CommonConstants.SERVICE_LOGIC_STATUS)) { - this.status = props.getProperty("SvcLogic.status"); + this.status = props.getProperty(CommonConstants.SERVICE_LOGIC_STATUS); } - + for (Object nameObj : props.keySet()) { String propName = (String) nameObj; attributes.put(propName, props.getProperty(propName)); } } - - - + + + public DOMDataBroker getDomDataBroker() { return domDataBroker; } @@ -83,14 +82,14 @@ public class SvcLogicContext { { if (attributes.containsKey(name)) { - return(attributes.get(name)); + return attributes.get(name); } else { - return(null); + return null; } } - + public void setAttribute(String name, String value) { if (value == null) { @@ -101,10 +100,10 @@ public class SvcLogicContext { attributes.put(name, value); } } - + public Set<String> getAttributeKeySet() { - return(attributes.keySet()); + return attributes.keySet(); } public String getStatus() { @@ -114,86 +113,88 @@ public class SvcLogicContext { public void setStatus(String status) { this.status = status; } - + public Properties toProperties() { Properties props = new Properties(); - + if (status != null) { - props.setProperty("SvcLogic.status", status); + props.setProperty(CommonConstants.SERVICE_LOGIC_STATUS, status); } - - for (String attrName : attributes.keySet()) + + String attrName; + String attrVal; + for (Map.Entry<String, String> entry : attributes.entrySet()) { - String attrVal = attributes.get(attrName); + attrName = entry.getKey(); + attrVal = entry.getValue(); if (attrVal == null) { - LOG.warn("attribute " + attrName - + "null - setting to empty string"); + LOG.warn("attribute {} value is null - setting to empty string", attrName); props.setProperty(attrName, ""); } else { - props.setProperty(attrName, attributes.get(attrName)); + props.setProperty(attrName, attrVal); } } - - return(props); + + return props; } - + public void mergeDocument(String pfx, Document doc) { String prefix = ""; - + if (pfx != null) { prefix = pfx; } - + Element root = doc.getDocumentElement(); - + mergeElement(prefix, root, null); } - + public void mergeElement(String pfx, Element element, Map<String, Integer> nodeMap) { - + // In XML, cannot tell the difference between containers and lists. // So, have to treat each element as both (ugly but necessary). - // We do this by passing a nodeMap to be used to count instance of each tag, - // which will be used to set _length and to set index - - LOG.trace("mergeElement("+pfx+","+element.getTagName()+","+nodeMap+")"); + // We do this by passing a nodeMap to be used to count instance of each tag, + // which will be used to set _length and to set index + + LOG.trace("mergeElement({},{},{})", pfx, element.getTagName(), nodeMap); String curTagName = element.getTagName(); String prefix = curTagName; - + if (pfx != null) { prefix = pfx + "." + prefix; } - + int myIdx = 0; - + if (nodeMap != null) { if (nodeMap.containsKey(curTagName)) { - myIdx = nodeMap.get(curTagName).intValue(); + myIdx = nodeMap.get(curTagName); } - nodeMap.put(curTagName, new Integer(myIdx+1)); - this.setAttribute(prefix+"_length", ""+(myIdx+1)); + nodeMap.put(curTagName, myIdx+1); + this.setAttribute(prefix+"_length", Integer.toString(myIdx+1)); } - + NodeList children = element.getChildNodes(); - + int numChildren = children.getLength(); - - Map<String, Integer> childMap = new HashMap<String, Integer>(); - Map<String, Integer> idxChildMap = new HashMap<String, Integer>(); - + + Map<String, Integer> childMap = new HashMap<>(); + Map<String, Integer> idxChildMap = new HashMap<>(); + for (int i = 0 ; i < numChildren ; i++) { Node curNode = children.item(i); - + if (curNode instanceof Text) { Text curText = (Text) curNode; String curTextValue = curText.getTextContent(); - LOG.trace("Setting ctx variable "+prefix+" = "+curTextValue); + LOG.trace("Setting ctx variable {} = {}", prefix, curTextValue); this.setAttribute(prefix, curText.getTextContent()); - + } else if (curNode instanceof Element) { mergeElement(prefix, (Element) curNode, childMap); @@ -204,9 +205,9 @@ public class SvcLogicContext { } } } - + } - + public String resolve(String ctxVarName) { if (ctxVarName.indexOf('[') == -1) { @@ -215,16 +216,15 @@ public class SvcLogicContext { } // Resolve any array references - StringBuffer sbuff = new StringBuffer(); + StringBuilder sbuff = new StringBuilder(); String[] ctxVarParts = ctxVarName.split("\\["); sbuff.append(ctxVarParts[0]); for (int i = 1; i < ctxVarParts.length; i++) { if (ctxVarParts[i].startsWith("$")) { - int endBracketLoc = ctxVarParts[i].indexOf("]"); + int endBracketLoc = ctxVarParts[i].indexOf(']'); if (endBracketLoc == -1) { // Missing end bracket ... give up parsing - LOG.warn("Variable reference " + ctxVarName - + " seems to be missing a ']'"); + LOG.warn("Variable reference {} seems to be missing a ']'", ctxVarName); return (this.getAttribute(ctxVarName)); } diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java index 0e6000fb..07f40a2e 100644 --- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java @@ -8,9 +8,9 @@ * 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. @@ -20,7 +20,7 @@ */ /** - * + * */ package org.onap.ccsdk.sli.core.sli; @@ -28,7 +28,10 @@ import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; +import java.util.Properties; +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; import junit.framework.TestCase; /** @@ -40,22 +43,43 @@ public class ITCaseSvcLogicParser extends TestCase { /** * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}. */ - - + + public void testParse() { - + try { + + URL propUrl = getClass().getResource("/svclogic.properties"); - + InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); - - SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr); - + + Properties props = new Properties(); + + props.load(propStr); + + + // Start MariaDB4j database + DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); + config.setPort(0); // 0 => autom. detect free port + DB db = DB.newEmbeddedDB(config.build()); + db.start(); + + + + // Override jdbc URL and database name + props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); + props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + + + + SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(props); + assertNotNull(store); - + store.registerNodeType("switch"); store.registerNodeType("block"); store.registerNodeType("get-resource"); @@ -69,15 +93,15 @@ public class ITCaseSvcLogicParser extends TestCase { store.registerNodeType("release"); store.registerNodeType("for"); store.registerNodeType("set"); - - + + InputStream testStr = getClass().getResourceAsStream("/parser-good.tests"); BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); String testCaseFile = null; while ((testCaseFile = testsReader.readLine()) != null) { - + testCaseFile = testCaseFile.trim(); - + if (testCaseFile.length() > 0) { if (!testCaseFile.startsWith("/")) @@ -94,23 +118,23 @@ public class ITCaseSvcLogicParser extends TestCase { SvcLogicParser.validate(testCaseUrl.getPath(), store); } catch (Exception e) { fail("Validation failure ["+e.getMessage()+"]"); - + } - - - + + + } } - + testStr = getClass().getResourceAsStream("/parser-bad.tests"); testsReader = new BufferedReader(new InputStreamReader(testStr)); testCaseFile = null; while ((testCaseFile = testsReader.readLine()) != null) { - + testCaseFile = testCaseFile.trim(); - + if (testCaseFile.length() > 0) { if (!testCaseFile.startsWith("/")) @@ -134,7 +158,7 @@ public class ITCaseSvcLogicParser extends TestCase { if (valid) { fail("Expected compiler error on "+testCaseFile+", but got success"); } - + } } @@ -148,10 +172,10 @@ public class ITCaseSvcLogicParser extends TestCase { e.printStackTrace(); fail("Caught exception processing test cases"); } - - + + } - - + + } diff --git a/sli/common/src/test/resources/svclogic.properties b/sli/common/src/test/resources/svclogic.properties index 25eb3bd4..33d7ae6e 100644 --- a/sli/common/src/test/resources/svclogic.properties +++ b/sli/common/src/test/resources/svclogic.properties @@ -8,9 +8,9 @@ # 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. @@ -20,7 +20,7 @@ ### org.onap.ccsdk.sli.dbtype = jdbc -org.onap.ccsdk.sli.jdbc.url = jdbc:mysql://localhost:3306/sdnctl -org.onap.ccsdk.sli.jdbc.database = sdnctl -org.onap.ccsdk.sli.jdbc.user = sdnctl -org.onap.ccsdk.sli.jdbc.password = gamma +org.onap.ccsdk.sli.jdbc.url = jdbc:mysql://localhost:3306/test +org.onap.ccsdk.sli.jdbc.database = test +org.onap.ccsdk.sli.jdbc.user = test +org.onap.ccsdk.sli.jdbc.password = test123 diff --git a/sli/provider/pom.xml b/sli/provider/pom.xml index f665c56a..529f9769 100755 --- a/sli/provider/pom.xml +++ b/sli/provider/pom.xml @@ -19,6 +19,12 @@ <version>3.8.1</version> <scope>test</scope> </dependency> + <dependency> + <groupId>ch.vorburger.mariaDB4j</groupId> + <artifactId>mariaDB4j</artifactId> + <version>2.2.3</version> + <scope>test</scope> + </dependency> <dependency> <groupId>org.onap.ccsdk.sli.core</groupId> <artifactId>sli-common</artifactId> diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java index 23911b68..19d985dd 100644 --- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java +++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicService.java @@ -28,49 +28,49 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; public interface SvcLogicService { - public static final String NAME = "org.onap.ccsdk.sli.core.sli.provider.SvcLogicService"; + String NAME = "org.onap.ccsdk.sli.core.sli.provider.SvcLogicService"; - // public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException; - /** - * Check for existence of a directed graph - * @param module - module name - * @param rpc - rpc name - * @param version - version. If null, looks for active version - * @param mode - mode (sync/async) - * @return true if directed graph found, false otherwise - * @throws SvcLogicException - */ - public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException; + // public SvcLogicContext execute(SvcLogicGraph graph, SvcLogicContext ctx) throws SvcLogicException; + /** + * Check for existence of a directed graph + * @param module - module name + * @param rpc - rpc name + * @param version - version. If null, looks for active version + * @param mode - mode (sync/async) + * @return true if directed graph found, false otherwise + * @throws SvcLogicException + */ + boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException; - /** - * Execute a directed graph - * - * @param module - module name - * @param rpc - rpc name - * @param version - version. If null, use active version - * @param mode - mode (sync/async) - * @param parms - parameters, used to set SvcLogicContext attributes - * @return final values of attributes from SvcLogicContext, as Properties - * @throws SvcLogicException - * - * - * @deprecated use execute(String module, String rpc, String version, String mode, DOMDataBroker dataBroker) instead - */ - @Deprecated - public Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException; + /** + * Execute a directed graph + * + * @param module - module name + * @param rpc - rpc name + * @param version - version. If null, use active version + * @param mode - mode (sync/async) + * @param parms - parameters, used to set SvcLogicContext attributes + * @return final values of attributes from SvcLogicContext, as Properties + * @throws SvcLogicException + * + * + * @deprecated use execute(String module, String rpc, String version, String mode, DOMDataBroker dataBroker) instead + */ + @Deprecated + Properties execute(String module, String rpc, String version, String mode, Properties parms) throws SvcLogicException; - /** - * Execute a directed graph - * - * @param module - module name - * @param rpc - rpc name - * @param version - version. If null, use active version - * @param mode - mode (sync/async) - * @param parms - parameters, used to set SvcLogicContext attributes - * @param domDataBroker - DOMDataBroker object - * @return final values of attributes from SvcLogicContext, as Properties - * @throws SvcLogicException - */ - public Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker domDataBroker) throws SvcLogicException; + /** + * Execute a directed graph + * + * @param module - module name + * @param rpc - rpc name + * @param version - version. If null, use active version + * @param mode - mode (sync/async) + * @param parms - parameters, used to set SvcLogicContext attributes + * @param domDataBroker - DOMDataBroker object + * @return final values of attributes from SvcLogicContext, as Properties + * @throws SvcLogicException + */ + Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker domDataBroker) throws SvcLogicException; } diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java index 5e895aa3..cdf837af 100644 --- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java +++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/ITCaseSvcLogicGraphExecutor.java @@ -8,9 +8,9 @@ * 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. @@ -31,43 +31,22 @@ import java.util.LinkedList; import java.util.Map; import java.util.Properties; -import org.onap.ccsdk.sli.core.sli.MetricLogger; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicGraph; -import org.onap.ccsdk.sli.core.sli.SvcLogicNode; import org.onap.ccsdk.sli.core.sli.SvcLogicParser; import org.onap.ccsdk.sli.core.sli.SvcLogicStore; import org.onap.ccsdk.sli.core.sli.SvcLogicStoreFactory; -import org.onap.ccsdk.sli.core.sli.provider.BlockNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.CallNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.ConfigureNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.DeleteNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.ExecuteNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.ExistsNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.ForNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.GetResourceNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.IsAvailableNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.NotifyNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.RecordNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.ReleaseNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.ReserveNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.ReturnNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.SaveNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.SetNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.SvcLogicNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.SvcLogicServiceImpl; -import org.onap.ccsdk.sli.core.sli.provider.SwitchNodeExecutor; -import org.onap.ccsdk.sli.core.sli.provider.UpdateNodeExecutor; -import org.osgi.framework.ServiceRegistration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; import junit.framework.TestCase; public class ITCaseSvcLogicGraphExecutor extends TestCase { private static final Logger LOG = LoggerFactory .getLogger(SvcLogicGraph.class); - + private static final Map<String, SvcLogicNodeExecutor> BUILTIN_NODES = new HashMap<String, SvcLogicNodeExecutor>() { { put("block", new BlockNodeExecutor()); @@ -91,19 +70,36 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { } }; - + public void testExecute() { - + try { InputStream testStr = getClass().getResourceAsStream("/executor.tests"); BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); - + InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); - - SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(propStr); - + + Properties svcprops = new Properties(); + svcprops.load(propStr); + + // Start MariaDB4j database + DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); + config.setPort(0); // 0 => autom. detect free port + DB db = DB.newEmbeddedDB(config.build()); + db.start(); + + + + // Override jdbc URL and database name + svcprops.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); + svcprops.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + + + + SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(svcprops); + assertNotNull(store); - + store.registerNodeType("switch"); store.registerNodeType("block"); store.registerNodeType("get-resource"); @@ -118,26 +114,26 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { store.registerNodeType("for"); store.registerNodeType("set"); SvcLogicParser parser = new SvcLogicParser(store); - + // Loop through executor tests SvcLogicServiceImpl svc = new SvcLogicServiceImpl(); - + for (String nodeType : BUILTIN_NODES.keySet()) { LOG.info("SLI - registering node executor for node type "+nodeType); - + svc.registerExecutor(nodeType, BUILTIN_NODES.get(nodeType)); } String testCaseLine = null; while ((testCaseLine = testsReader.readLine()) != null) { - + String[] testCaseFields = testCaseLine.split(":"); String testCaseFile = testCaseFields[0]; String testCaseMethod = testCaseFields[1]; String testCaseParameters = null; - + if (testCaseFields.length > 2) { testCaseParameters = testCaseFields[2]; } @@ -145,7 +141,7 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { SvcLogicContext ctx = new SvcLogicContext(); if (testCaseParameters != null) { String[] testCaseParameterSettings = testCaseParameters.split(","); - + for (int i = 0 ; i < testCaseParameterSettings.length ; i++) { String[] nameValue = testCaseParameterSettings[i].split("="); if (nameValue != null) { @@ -154,14 +150,14 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { if (nameValue.length > 1) { value = nameValue[1]; } - + ctx.setAttribute(name, value); } } } - + testCaseFile = testCaseFile.trim(); - + if (testCaseFile.length() > 0) { if (!testCaseFile.startsWith("/")) { testCaseFile = "/"+testCaseFile; @@ -170,12 +166,12 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { if (testCaseUrl == null) { fail("Could not resolve test case file "+testCaseFile); } - + LinkedList<SvcLogicGraph> graphs = parser.parse(testCaseUrl.getPath()); - + assertNotNull(graphs); - + for (SvcLogicGraph graph: graphs) { if (graph.getRpc().equals(testCaseMethod)) { Properties props = ctx.toProperties(); @@ -184,9 +180,9 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { String propName = (String) e1.nextElement(); LOG.info(propName+" = "+props.getProperty(propName)); } - + svc.execute(graph, ctx); - + props = ctx.toProperties(); LOG.info("SvcLogicContext after executing "+testCaseMethod+":"); for (Enumeration e2 = props.propertyNames(); e2.hasMoreElements() ; ) { @@ -197,16 +193,16 @@ public class ITCaseSvcLogicGraphExecutor extends TestCase { } } - - + + } - - + + } catch (Exception e) { LOG.error("Caught exception executing directed graphs", e); fail("Exception executing graphs"); } } - + } diff --git a/sli/recording/pom.xml b/sli/recording/pom.xml index 97c99188..f0bc0970 100755 --- a/sli/recording/pom.xml +++ b/sli/recording/pom.xml @@ -59,9 +59,7 @@ <extensions>true</extensions> <configuration> <instructions> - <Bundle-Activator>org.onap.ccsdk.sli.core.sli.recording.RecordingActivator</Bundle-Activator> <Export-Package>org.onap.ccsdk.sli.core.sli.recording;version=${project.version}</Export-Package> - <Import-Package>*</Import-Package> <Embed-Transitive>true</Embed-Transitive> </instructions> diff --git a/sli/recording/src/main/java/org/onap/ccsdk/sli/core/sli/recording/RecordingActivator.java b/sli/recording/src/main/java/org/onap/ccsdk/sli/core/sli/recording/RecordingActivator.java deleted file mode 100644 index fd857f56..00000000 --- a/sli/recording/src/main/java/org/onap/ccsdk/sli/core/sli/recording/RecordingActivator.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.core.sli.recording; - -import java.util.LinkedList; - -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -public class RecordingActivator implements BundleActivator { - - private LinkedList<ServiceRegistration> registrations = new LinkedList<>(); - - private static final Logger LOG = LoggerFactory - .getLogger(RecordingActivator.class); - - @Override - public void start(BundleContext ctx) throws Exception { - - if (registrations == null) - { - registrations = new LinkedList<>(); - } - - - FileRecorder fileRecorder = new FileRecorder(); - String regName = fileRecorder.getClass().getName(); - LOG.debug("Registering FileRecorder service "+regName); - ServiceRegistration reg =ctx.registerService(regName, fileRecorder, null); - registrations.add(reg); - - Slf4jRecorder slf4jRecorder = new Slf4jRecorder(); - regName = slf4jRecorder.getClass().getName(); - LOG.debug("Registering Slf4jRecorder service "+regName); - reg =ctx.registerService(regName, slf4jRecorder, null); - registrations.add(reg); - - } - - @Override - public void stop(BundleContext arg0) throws Exception { - if (registrations != null) { - for (ServiceRegistration reg : registrations) { - ServiceReference regRef = reg.getReference(); - reg.unregister(); - } - registrations = null; - } - } - -} diff --git a/sli/recording/src/main/resources/org/opendaylight/blueprint/recording-blueprint.xml b/sli/recording/src/main/resources/org/opendaylight/blueprint/recording-blueprint.xml new file mode 100644 index 00000000..d8035376 --- /dev/null +++ b/sli/recording/src/main/resources/org/opendaylight/blueprint/recording-blueprint.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" + xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0" + odl:use-default-for-reference-types="true"> + + <bean id="fileRecorder" class="org.onap.ccsdk.sli.core.sli.recording.FileRecorder" /> + <!-- Implementation name was chosen over interface name due to the fact that this Service + was previously registered using the implementation name rather than the interface name. + To ensure backwards compatibility with abstractions polling the Service Registry for the + fileRecorder, the implementation name was chosen here. --> + <service ref="fileRecorder" interface="org.onap.ccsdk.sli.core.sli.recording.FileRecorder" /> + + <bean id="slf4jRecorder" class="org.onap.ccsdk.sli.core.sli.recording.Slf4jRecorder" /> + <!-- Implementation name was chosen over interface name due to the fact that this Service + was previously registered using the implementation name rather than the interface name. + To ensure backwards compatibility with abstractions polling the Service Registry for the + slf4jRecorder, the implementation name was chosen here. --> + <service ref="slf4jRecorder" class="org.onap.ccsdk.sli.core.sli.recording.Slf4jRecorder" /> + +</blueprint>
\ No newline at end of file diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextObject.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextObject.java index eaa92c3f..aa41a5c6 100644 --- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextObject.java +++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextObject.java @@ -24,5 +24,5 @@ package org.onap.ccsdk.sli.core.slipluginutils; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; public interface SvcLogicContextObject { - public void writeToContext( SvcLogicContext ctx, String root ); + void writeToContext(SvcLogicContext ctx, String root ); } |