diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src')
14 files changed, 708 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfig.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfig.java new file mode 100644 index 0000000000..a68c6b614a --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfig.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig; + +import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity; +import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData; + +import java.util.Collection; + +public interface ApplicationConfig { + + ConfigurationData getConfigurationData(String namespace, String key); + + void insertValue(String namespace, String key, String value); + + Collection<ApplicationConfigEntity> getListOfConfigurationByNamespace(String namespace); +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfigFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfigFactory.java new file mode 100644 index 0000000000..e022294dfd --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/ApplicationConfigFactory.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig; + +import org.openecomp.core.factory.api.AbstractComponentFactory; +import org.openecomp.core.factory.api.AbstractFactory; + +public abstract class ApplicationConfigFactory extends AbstractComponentFactory<ApplicationConfig> { + + public static ApplicationConfigFactory getInstance() { + return AbstractFactory.getInstance(ApplicationConfigFactory.class); + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDao.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDao.java new file mode 100644 index 0000000000..a4c582744a --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDao.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig.dao; + +import org.openecomp.core.dao.BaseDao; +import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity; +import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData; + + +public interface ApplicationConfigDao extends BaseDao<ApplicationConfigEntity> { + + long getValueTimestamp(String namespace, String key); + + ConfigurationData getConfigurationData(String namespace, String key); +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDaoFactory.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDaoFactory.java new file mode 100644 index 0000000000..f60e4a9010 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/ApplicationConfigDaoFactory.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig.dao; + +import org.openecomp.core.factory.api.AbstractComponentFactory; +import org.openecomp.core.factory.api.AbstractFactory; + +public abstract class ApplicationConfigDaoFactory + extends AbstractComponentFactory<ApplicationConfigDao> { + + public static ApplicationConfigDaoFactory getInstance() { + return AbstractFactory.getInstance(ApplicationConfigDaoFactory.class); + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoCassandraImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoCassandraImpl.java new file mode 100644 index 0000000000..7fb0e2f5ae --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoCassandraImpl.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig.dao.impl; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.mapping.Mapper; +import com.datastax.driver.mapping.Result; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.dao.impl.CassandraBaseDao; +import org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao; +import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity; +import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData; + +import java.util.Collection; +import java.util.Objects; + +public class ApplicationConfigDaoCassandraImpl extends CassandraBaseDao<ApplicationConfigEntity> + implements ApplicationConfigDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static final Mapper<ApplicationConfigEntity> mapper = + noSqlDb.getMappingManager().mapper(ApplicationConfigEntity.class); + private static final ApplicationConfigAccessor accessor = + noSqlDb.getMappingManager().createAccessor(ApplicationConfigAccessor.class); + + @Override + protected Mapper<ApplicationConfigEntity> getMapper() { + return mapper; + } + + @Override + protected Object[] getKeys(ApplicationConfigEntity entity) { + return new Object[]{entity.getNamespace(), entity.getKey(), entity.getValue()}; + } + + @Override + public Collection<ApplicationConfigEntity> list(ApplicationConfigEntity entity) { + return accessor.list(entity.getNamespace()).all(); + } + + @Override + public void create(ApplicationConfigEntity entity) { + accessor.updateApplicationConfigData(entity.getNamespace(), entity.getKey(), entity.getValue()); + } + + @Override + public void update(ApplicationConfigEntity entity) { + accessor.updateApplicationConfigData(entity.getNamespace(), entity.getKey(), entity.getValue()); + } + + @Override + public ApplicationConfigEntity get(ApplicationConfigEntity entity) { + return accessor.get(entity.getNamespace(), entity.getKey()); + } + + @Override + public long getValueTimestamp(String namespace, String key) { + ResultSet resultSet = accessor.getValueAndTimestampOfConfigurationValue(namespace, key); + + return resultSet.one().getLong("writetime(value)"); + } + + @Override + public ConfigurationData getConfigurationData(String namespace, String key) { + //String value = accessor.getValue(namespace, key).one().getString("value"); + ResultSet resultSet = accessor.getValueAndTimestampOfConfigurationValue(namespace, key); + Row one = resultSet.one(); + + if (Objects.nonNull(one)) { + return new ConfigurationData(one.getString("value"), one.getLong("writetime(value)")); + } + + return null; + } + + + @Accessor + interface ApplicationConfigAccessor { + + @Query("select namespace, key, value from application_config where namespace=?") + Result<ApplicationConfigEntity> list(String namespace); + + @Query("insert into application_config (namespace, key, value) values (?,?,?)") + ResultSet updateApplicationConfigData(String namespace, String key, String value); + + @Query("select namespace, key, value from application_config where namespace=? and key=?") + ApplicationConfigEntity get(String namespace, String key); + + @Query("select value, writetime(value) from application_config where namespace=? and key=?") + ResultSet getValueAndTimestampOfConfigurationValue(String namespace, String key); + + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoFactoryImpl.java new file mode 100644 index 0000000000..cea49ea8d1 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/impl/ApplicationConfigDaoFactoryImpl.java @@ -0,0 +1,33 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig.dao.impl; + +import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao; +import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDaoFactory; + +public class ApplicationConfigDaoFactoryImpl extends ApplicationConfigDaoFactory { + private static final ApplicationConfigDao INSTANCE = new ApplicationConfigDaoCassandraImpl(); + + @Override + public ApplicationConfigDao createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/type/ApplicationConfigEntity.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/type/ApplicationConfigEntity.java new file mode 100644 index 0000000000..c73ce36744 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/dao/type/ApplicationConfigEntity.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig.dao.type; + + +import com.datastax.driver.mapping.annotations.ClusteringColumn; +import com.datastax.driver.mapping.annotations.PartitionKey; +import com.datastax.driver.mapping.annotations.Table; + +@Table(keyspace = "dox", name = "application_config") +public class ApplicationConfigEntity { + + @PartitionKey + private String namespace; + @ClusteringColumn + private String key; + private String value; + + /** + * Instantiates a new Application config entity. + * + * @param namespace the namespace + * @param key the key + * @param value the value + */ + public ApplicationConfigEntity(String namespace, String key, String value) { + this.namespace = namespace; + this.key = key; + this.value = value; + } + + + public ApplicationConfigEntity() { + } + + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigFactoryImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigFactoryImpl.java new file mode 100644 index 0000000000..cca07fc227 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigFactoryImpl.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig.impl; + +import org.openecomp.core.utilities.applicationconfig.ApplicationConfig; +import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory; + +public class ApplicationConfigFactoryImpl extends ApplicationConfigFactory { + + private static final ApplicationConfig INSTANCE = new ApplicationConfigImpl(); + + @Override + public ApplicationConfig createInterface() { + return INSTANCE; + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigImpl.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigImpl.java new file mode 100644 index 0000000000..ff9c9aea87 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/impl/ApplicationConfigImpl.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig.impl; + +import org.openecomp.core.utilities.applicationconfig.ApplicationConfig; +import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao; +import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDaoFactory; +import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity; +import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; + +import java.util.Collection; +import java.util.Objects; + +/** + * The type Application config. + */ +public class ApplicationConfigImpl implements ApplicationConfig { + private static final ApplicationConfigDao applicationConfigDao = + ApplicationConfigDaoFactory.getInstance().createInterface(); + + private static final String CONFIGURATION_SEARCH_ERROR = "CONFIGURATION_NOT_FOUND"; + private static final String CONFIGURATION_SEARCH_ERROR_MSG = + "Configuration for namespace %s and key %s was not found"; + + @Override + public ConfigurationData getConfigurationData(String namespace, String key) { + ConfigurationData configurationData = applicationConfigDao.getConfigurationData(namespace, key); + + if (Objects.isNull(configurationData)) { + throw new CoreException(new ErrorCode.ErrorCodeBuilder() + .withCategory(ErrorCategory.APPLICATION) + .withId(CONFIGURATION_SEARCH_ERROR) + .withMessage(String.format(CONFIGURATION_SEARCH_ERROR_MSG, namespace, key)) + .build()); + } + + return configurationData; + } + + @Override + public void insertValue(String namespace, String key, String value) { + ApplicationConfigEntity applicationConfigEntity = + new ApplicationConfigEntity(namespace, key, value); + applicationConfigDao.create(applicationConfigEntity); + } + + @Override + public Collection<ApplicationConfigEntity> getListOfConfigurationByNamespace(String namespace) { + ApplicationConfigEntity applicationConfigEntity = + new ApplicationConfigEntity(namespace, null, null); + return applicationConfigDao.list(applicationConfigEntity); + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/type/ConfigurationData.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/type/ConfigurationData.java new file mode 100644 index 0000000000..53d3797e53 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/java/org/openecomp/core/utilities/applicationconfig/type/ConfigurationData.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * 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.openecomp.core.utilities.applicationconfig.type; + +public class ConfigurationData { + + private String value; + private long timeStamp; + + public ConfigurationData(String value, long timeStamp) { + this.value = value; + this.timeStamp = timeStamp; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public long getTimeStamp() { + return timeStamp; + } + + public void setTimeStamp(long timeStamp) { + this.timeStamp = timeStamp; + } +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/resources/factoryConfiguration.json new file mode 100644 index 0000000000..19d2cafe8f --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/resources/factoryConfiguration.json @@ -0,0 +1,4 @@ +{ + "org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory":"org.openecomp.core.utilities.applicationconfig.impl.ApplicationConfigFactoryImpl", + "org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDaoFactory":"org.openecomp.core.utilities.applicationconfig.dao.impl.ApplicationConfigDaoFactoryImpl" +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/resources/logback.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/resources/logback.xml new file mode 100644 index 0000000000..e256e0b10a --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/main/resources/logback.xml @@ -0,0 +1,90 @@ +<!-- +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + + + <appender name="DEBUG_ROLLING" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>DOX-BE.log + </file> + + <!– No need to deny audit messages - they are INFO only, will be denied + anyway –> + <!– Transaction messages filter - deny Transaction messages, there are + some DEBUG level messages among them –> + + + <!– accept DEBUG and TRACE level –> + + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>/DOX-BE.log.%i + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>10</maxIndex> + </rollingPolicy> + + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>20MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>%level [%d{yyyy-MM-dd'T'HH:mm:ss}] - Method=%M, Desc=<%msg>%n</pattern> + </encoder> + </appender> + + + <root level="info"> + <appender-ref ref="DEBUG_ROLLING" /> + </root> +</configuration>--> +<configuration scan="true" scanPeriod="3 seconds"> + + <property name="logDir" value="logs"/> + <property name="componentName" value="ASDC"/> + <property name="ECOMP-subcomponent-name" value="ASDC-BE"/> + + <property name="defaultPattern" + value="%msg%n"/> + + <!--<property name="MetricsLogPattern" value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%X{CategoryLogLevel}|%X{Severity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{ClientIP}|%logger%n" /> + <property name="AuditLogPattern" value="%X{BeginTimestamp}|%X{EndTimestamp}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServerName}|%X{ServiceName}|%X{PartnerName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%X{CategoryLogLevel}|%X{Severity}|%X{ServerIPAddress}|%X{ElapsedTime}|%X{ServerFQDN}|%X{ClientIP}%n" /> + <property name="ErrorLogPattern" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSS, GMT}|%X{RequestId}|%thread|%X{ServiceName}|%X{PartnerName}|%X{TargetEntity}|%X{TargetServiceName}|%X{ErrorCategory}|%X{ErrorCode}|%X{ErrorDescription}|%msg%n"/> + <property name="DebugLogPattern" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSS, GMT}|%X{RequestId}||%logger|%msg%n"/>--> + + <!-- new pattern --> + <property name="default-log-pattern" + value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{BeginTimestamp}|%X{EndTimestamp}|%X{uuid}|%X{serviceInstanceID}|%thread|%X{ServerName}|%X{ServiceName}|${ECOMP-subcomponent-name}|%X{userId}|%X{TargetEntity}|%X{TargetServiceName}|%X{StatusCode}|%X{ResponseCode}|%X{ResponseDescription}|%X{InstanceUUID}|%X{ErrorCategory}|%X{ErrorCode}|%X{ErrorDescription}|%level|%X{alarmSeverity}|%X{localAddr}|%X{ElapsedTime}|%X{beFqdn}|%X{remoteAddr}|%logger{35}|%X{timer}|ActivityType=<%M>, Desc=<%msg>%n"/> + + <property name="logDirectory" value="${logDir}/${componentName}"/> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + + <appender name="DISPATCHER" class="ch.qos.logback.classic.sift.SiftingAppender"> + <discriminator class="org.openecomp.core.logging.logback.EventTypeDiscriminator"/> + <sift> + <appender name="${eventType}" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${eventType}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${eventType}.%i.log.zip</fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${default-log-pattern}</pattern> + </encoder> + </appender> + </sift> + </appender> + + <root level="DEBUG"> + <appender-ref ref="DISPATCHER"/> + </root> + +</configuration>
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/test/java/org/openecomp/sdc/applicationconfig/dao/ApplicationConfigImplDaoTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/test/java/org/openecomp/sdc/applicationconfig/dao/ApplicationConfigImplDaoTest.java new file mode 100644 index 0000000000..40cde1ecb2 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/test/java/org/openecomp/sdc/applicationconfig/dao/ApplicationConfigImplDaoTest.java @@ -0,0 +1,88 @@ +package org.openecomp.sdc.applicationconfig.dao; + +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.ErrorCategory; +import org.openecomp.sdc.common.errors.ErrorCode; +import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType; +import org.openecomp.core.utilities.applicationconfig.ApplicationConfig; +import org.openecomp.core.utilities.applicationconfig.ApplicationConfigFactory; +import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDao; +import org.openecomp.core.utilities.applicationconfig.dao.ApplicationConfigDaoFactory; +import org.openecomp.core.utilities.applicationconfig.dao.type.ApplicationConfigEntity; +import org.openecomp.core.utilities.applicationconfig.type.ConfigurationData; +import org.openecomp.core.utilities.file.FileUtils; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class ApplicationConfigImplDaoTest { + + private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR = + "SCHEMA_GENERATOR_INITIALIZATION_ERROR"; + private static final String SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG = + "Error occurred while loading questionnaire schema templates"; + private static ApplicationConfigDao applicationConfigDao = + ApplicationConfigDaoFactory.getInstance().createInterface(); + private static ApplicationConfig applicationConfig = + ApplicationConfigFactory.getInstance().createInterface(); + +// @BeforeClass + public static void init() { + try { + + ApplicationConfigEntity applicationConfigEntity1 = + new ApplicationConfigEntity("test - namespace", "vsp", "vspTemplate"); + ApplicationConfigEntity applicationConfigEntity2 = + new ApplicationConfigEntity("test - namespace", "nic", "nicTemplate"); + ApplicationConfigEntity applicationConfigEntity3 = + new ApplicationConfigEntity("test - namespace", "component", "componentTemplate"); + + applicationConfigDao.create(applicationConfigEntity1); + applicationConfigDao.create(applicationConfigEntity2); + applicationConfigDao.create(applicationConfigEntity3); + + } catch (Exception e) { + throw new CoreException(new ErrorCode.ErrorCodeBuilder(). + withCategory(ErrorCategory.APPLICATION). + withId(SCHEMA_GENERATOR_INITIALIZATION_ERROR). + withMessage(SCHEMA_GENERATOR_INITIALIZATION_ERROR_MSG). + build()); + } + } + + private static String loadFileToString(String path) { + return new String(FileUtils.toByteArray(FileUtils.loadFileToInputStream(path))); + } + +// @Test + public void testApplicationConfigTimestampValue() { + ConfigurationData configurationData = applicationConfig + .getConfigurationData("test - namespace", CompositionEntityType.vsp.name()); + + Assert.assertNotNull(configurationData); + Assert.assertNotEquals(configurationData.getTimeStamp(), 0); + + } + +// @Test(dependsOnMethods = "testApplicationConfigTimestampValue") + public void testNotExistingApplicationConfigTimestampValue() { + try { + applicationConfig.getConfigurationData("test - namespace", "aaa"); + } catch (CoreException ce) { + Assert.assertEquals(ce.getMessage(), + "Configuration for namespace test - namespace and key aaa was not found"); + } + + } + +// @Test(dependsOnMethods = "testApplicationConfigTimestampValue") + public void testInsertApplicationConfiguration() { + String testTemplate = loadFileToString("questionnaire/testTemplate.txt"); + applicationConfig.insertValue("test_namespace", "test_key", testTemplate); + + Assert.assertEquals(testTemplate, + applicationConfig.getConfigurationData("test_namespace", "test_key").getValue()); + } + +} diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/test/resources/questionnaire/testTemplate.txt b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/test/resources/questionnaire/testTemplate.txt new file mode 100644 index 0000000000..0bb19c5984 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-config-lib/src/test/resources/questionnaire/testTemplate.txt @@ -0,0 +1,12 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "general": { + "type": "object", + "properties": { + "testObject":{ + "type": "string" + } + } +}
\ No newline at end of file |