*/
public void validate() throws PdpSimulatorException {
validateReadableFile("pdp simulator configuration", configurationFilePath);
- validateReadableFile("pdp simulator properties", propertyFilePath);
}
/**
package org.onap.policy.models.sim.pdp;
-import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Properties;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
import org.onap.policy.models.sim.pdp.parameters.PdpSimulatorParameterGroup;
}
// Read the properties
- final Properties topicProperties = new Properties();
- try {
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- topicProperties.load(stream);
- }
- } catch (final Exception e) {
- LOGGER.error(PDP_SIMULATOR_FAIL_MSG, e);
- return;
- }
+ Properties topicProperties = ParameterUtils.getTopicProperties(parameterGroup.getTopicParameterGroup());
// create the activator
activator = new PdpSimulatorActivator(parameterGroup, topicProperties);
package org.onap.policy.models.sim.pdp.parameters;
import lombok.Getter;
-
+import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.ParameterGroupImpl;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
@Getter
public class PdpSimulatorParameterGroup extends ParameterGroupImpl {
private PdpStatusParameters pdpStatusParameters;
+ private TopicParameterGroup topicParameterGroup;
/**
* Create the pdp simulator parameter group.
TRUSTSTORE="${PDP_SIM_HOME}/etc/ssl/policy-truststore"
TRUSTSTORE_PASSWD="Pol1cy_0nap"
-if [ "$#" -eq 2 ]
+if [ "$#" -eq 1 ]
then
CONFIG_FILE=$1
- PROPERTIES_FILE=$2
else
CONFIG_FILE=${CONFIG_FILE}
- PROPERTIES_FILE=${PROPERTIES_FILE}
fi
if [ -z "$CONFIG_FILE" ]
CONFIG_FILE="$PDP_SIM_HOME/etc/config/OnapPfConfig.json"
fi
-if [ -z "$PROPERTIES_FILE" ]
-then
- PROPERTIES_FILE="$PDP_SIM_HOME/etc/config/topic.properties"
-fi
-
-echo "PDP simulatior configuration file: $CONFIG_FILE and properties file: $PROPERTIES_FILE"
+echo "PDP simulatior configuration file: $CONFIG_FILE
$JAVA_HOME/bin/java \
-cp "$PDP_SIM_HOME/etc:$PDP_SIM_HOME/lib/*" \
-Djavax.net.ssl.trustStorePassword="$TRUSTSTORE_PASSWD" \
-Dlogback.configurationFile=$PDP_SIM_HOME/etc/logback.xml \
org.onap.policy.models.sim.pdp.PdpSimulatorMain \
- -c $CONFIG_FILE -p $PROPERTIES_FILE
+ -c $CONFIG_FILE
</directory>
<includes>
<include>OnapPfConfig.json</include>
- <include>topic.properties</include>
</includes>
<outputDirectory>etc/config</outputDirectory>
<lineEnding>unix</lineEnding>
"pdpType":"apex",
"description":"Pdp Heartbeat",
"supportedPolicyTypes":[{"name":"onap.policies.controlloop.operational.Apex","version":"1.0.0"}]
+ },
+ "topicParameterGroup": {
+ "topicSources" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "message-router:3904" ],
+ "topicCommInfrastructure" : "dmaap"
+ }],
+ "topicSinks" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "message-router:3904" ],
+ "topicCommInfrastructure" : "dmaap"
+ }]
}
}
\ No newline at end of file
+++ /dev/null
-# ============LICENSE_START=======================================================
-# Copyright (C) 2019 Nordix Foundation.
-# ================================================================================
-# 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.
-#
-# SPDX-License-Identifier: Apache-2.0
-# ============LICENSE_END=========================================================
-
-dmaap.source.topics=POLICY-PDP-PAP
-dmaap.sink.topics=POLICY-PDP-PAP
-dmaap.source.topics.POLICY-PDP-PAP.servers= message-router:3904
-dmaap.sink.topics.POLICY-PDP-PAP.servers= message-router:3904
\ No newline at end of file
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.sim.pdp.exception.PdpSimulatorException;
@Before
public void setUp() throws Exception {
Registry.newRegistry();
- final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" };
final PdpSimulatorCommandLineArguments arguments =
new PdpSimulatorCommandLineArguments(pdpSimulatorConfigParameters);
final PdpSimulatorParameterGroup parGroup = new PdpSimulatorParameterHandler().getParameters(arguments);
- final Properties props = new Properties();
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- props.load(stream);
- }
-
+ final Properties props = ParameterUtils.getTopicProperties(parGroup.getTopicParameterGroup());
activator = new PdpSimulatorActivator(parGroup, props);
}
@Test
public void testPdpSimulator() throws PdpSimulatorException {
- final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" };
pdpSimulator = new PdpSimulatorMain(pdpSimulatorConfigParameters);
assertTrue(pdpSimulator.getParameters().isValid());
assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulator.getParameters().getName());
import static org.junit.Assert.assertEquals;
-import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
pdpUpdateMessageListener = new PdpUpdateListener();
pdpStateChangeListener = new PdpStateChangeListener();
Registry.newRegistry();
- final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" };
final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments();
PdpSimulatorParameterGroup pdpSimulatorParameterGroup;
// The arguments return a string if there is a message to print and we should
pdpSimulatorParameterGroup = new PdpSimulatorParameterHandler().getParameters(arguments);
// Read the properties
- final Properties topicProperties = new Properties();
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- topicProperties.load(stream);
- }
+ final Properties topicProperties =
+ ParameterUtils.getTopicProperties(pdpSimulatorParameterGroup.getTopicParameterGroup());
activator = new PdpSimulatorActivator(pdpSimulatorParameterGroup, topicProperties);
Registry.register(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR, activator);
activator.initialize();
import static org.junit.Assert.assertEquals;
-import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
@Before
public void setUp() throws Exception {
Registry.newRegistry();
- final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] pdpSimulatorConfigParameters = { "-c", "src/test/resources/PdpSimulatorConfigParameters.json" };
final PdpSimulatorCommandLineArguments arguments = new PdpSimulatorCommandLineArguments();
PdpSimulatorParameterGroup pdpSimulatorParameterGroup;
// The arguments return a string if there is a message to print and we should
pdpSimulatorParameterGroup = new PdpSimulatorParameterHandler().getParameters(arguments);
// Read the properties
- final Properties topicProperties = new Properties();
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- topicProperties.load(stream);
- }
+ final Properties topicProperties =
+ ParameterUtils.getTopicProperties(pdpSimulatorParameterGroup.getTopicParameterGroup());
activator = new PdpSimulatorActivator(pdpSimulatorParameterGroup, topicProperties);
Registry.register(PdpSimulatorConstants.REG_PDP_SIMULATOR_ACTIVATOR, activator);
activator.initialize();
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-
+import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.parameters.ParameterGroup;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
public static final String POLICY_VERSION = "0.0.1";
protected static final List<ToscaPolicyTypeIdentifierParameters> SUPPORTED_POLICY_TYPES =
Arrays.asList(getSupportedPolicyTypes(POLICY_NAME, POLICY_VERSION));
+ public static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParams());
private static final String REST_SERVER_PASS = "zb!XztG34";
private static final String REST_SERVER_USER = "healthcheck";
private static final int REST_SERVER_PORT = 6969;
return policyTypeIdentParameters;
}
+ /**
+ * Returns topic parameters for test cases.
+ *
+ * @return topic parameters
+ */
+ public static TopicParameters getTopicParams() {
+ final TopicParameters topicParams = new TopicParameters();
+ topicParams.setTopic("POLICY-PDP-PAP");
+ topicParams.setTopicCommInfrastructure("dmaap");
+ topicParams.setServers(Arrays.asList("message-router"));
+ return topicParams;
+ }
+
/**
* Converts the contents of a map to a parameter class.
*
map.put("name", name);
map.put("restServerParameters", getRestServerParametersMap(false));
map.put("pdpStatusParameters", getPdpStatusParametersMap(false));
-
+ map.put("topicParameterGroup", getTopicParametersMap(false));
return map;
}
return map;
}
+
+ /**
+ * Returns a property map for a TopicParameters map for test cases.
+ *
+ * @param isEmpty boolean value to represent that object created should be empty or not
+ * @return a property map suitable for constructing an object
+ */
+ public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
+ final Map<String, Object> map = new TreeMap<>();
+ if (!isEmpty) {
+ map.put("topicSources", TOPIC_PARAMS);
+ map.put("topicSinks", TOPIC_PARAMS);
+ }
+ return map;
+ }
}
import java.util.Map;
import org.junit.Test;
+import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.GroupValidationResult;
/**
commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME),
PdpSimulatorParameterGroup.class);
final PdpStatusParameters pdpStatusParameters = pdpSimulatorParameters.getPdpStatusParameters();
+ final TopicParameterGroup topicParameterGroup = pdpSimulatorParameters.getTopicParameterGroup();
final GroupValidationResult validationResult = pdpSimulatorParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.PDP_SIMULATOR_GROUP_NAME, pdpSimulatorParameters.getName());
assertEquals(CommonTestData.PDP_TYPE, pdpStatusParameters.getPdpType());
assertEquals(CommonTestData.DESCRIPTION, pdpStatusParameters.getDescription());
assertEquals(CommonTestData.SUPPORTED_POLICY_TYPES, pdpStatusParameters.getSupportedPolicyTypes());
+ assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSinks());
+ assertEquals(CommonTestData.TOPIC_PARAMS, topicParameterGroup.getTopicSources());
}
@Test
+ "parameter group has status INVALID"));
}
+ @Test
+ public void testApexStarterParameterGroupp_EmptyTopicParameters() {
+ final Map<String, Object> map =
+ commonTestData.getPdpSimulatorParameterGroupMap(CommonTestData.PDP_SIMULATOR_GROUP_NAME);
+ map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true));
+
+ final PdpSimulatorParameterGroup parGroup =
+ commonTestData.toObject(map, PdpSimulatorParameterGroup.class);
+ final GroupValidationResult validationResult = parGroup.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
+ + "parameter group has status INVALID"));
+ }
+
}
"pdpType":"apex",
"description":"Pdp Heartbeat",
"supportedPolicyTypes":[{"name":"onap.policies.controlloop.operational.Apex","version":"1.0.0"}]
+ },
+ "topicParameterGroup": {
+ "topicSources" : [ {
+ "topic" : "ueb-source",
+ "servers" : [ "my-server" ],
+ "topicCommInfrastructure" : "ueb"
+ },{
+ "topic" : "POLICY-PDP-PAP1",
+ "servers" : [ "message-router1, message-router2" ],
+ "topicCommInfrastructure" : "dmaap"
+ },{
+ "topic" : "POLICY-PDP-PAP2",
+ "servers" : [ "message-router2, message-router3" ],
+ "topicCommInfrastructure" : "dmaap"
+ }],
+ "topicSinks" : [ {
+ "topic" : "ueb-sink",
+ "servers" : [ "my-server" ],
+ "topicCommInfrastructure" : "ueb"
+ },{
+ "topic" : "POLICY-PDP-PAP2",
+ "servers" : [ "message-router1, message-router2" ],
+ "topicCommInfrastructure" : "dmaap"
+ },{
+ "topic" : "POLICY-PDP-PAP3",
+ "servers" : [ "message-router2, message-router3" ],
+ "topicCommInfrastructure" : "dmaap"
+ }]
}
}
\ No newline at end of file
"pdpType":"apex",
"description":"Pdp Heartbeat",
"supportedPolicyTypes":[{"name":"onap.policies.controlloop.operational.Apex","version":"1.0.0"}]
+ },
+ "topicParameterGroup": {
+ "topicSources" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "localhost:6845" ],
+ "topicCommInfrastructure" : "dmaap"
+ }],
+ "topicSinks" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "localhost:6845" ],
+ "topicCommInfrastructure" : "dmaap"
+ }]
}
}
"pdpType":"apex",
"description":"Pdp heartbeat",
"supportedPolicyTypes":[{"name":"onap.policies.controlloop.operational.Apex","version":"1.0.0"}]
+ },
+ "topicParameterGroup": {
+ "topicSources" : [ {
+ "topic" : "ueb-source",
+ "servers" : [ "my-server" ],
+ "topicCommInfrastructure" : "ueb"
+ },{
+ "topic" : "POLICY-PDP-PAP1",
+ "servers" : [ "message-router1, message-router2" ],
+ "topicCommInfrastructure" : "dmaap"
+ },{
+ "topic" : "POLICY-PDP-PAP2",
+ "servers" : [ "message-router2, message-router3" ],
+ "topicCommInfrastructure" : "dmaap"
+ }],
+ "topicSinks" : [ {
+ "topic" : "ueb-sink",
+ "servers" : [ "my-server" ],
+ "topicCommInfrastructure" : "ueb"
+ },{
+ "topic" : "POLICY-PDP-PAP2",
+ "servers" : [ "message-router1, message-router2" ],
+ "topicCommInfrastructure" : "dmaap"
+ },{
+ "topic" : "POLICY-PDP-PAP3",
+ "servers" : [ "message-router2, message-router3" ],
+ "topicCommInfrastructure" : "dmaap"
+ }]
}
}
\ No newline at end of file
+++ /dev/null
-# ============LICENSE_START=======================================================
-# Copyright (C) 2019 Nordix Foundation.
-# ================================================================================
-# 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.
-#
-# SPDX-License-Identifier: Apache-2.0
-# ============LICENSE_END=========================================================
-
-noop.sink.topics=POLICY-PDP-PAP
-noop.sink.topics.POLICY-PDP-PAP.servers=anyserver
-noop.source.topics=POLICY-PDP-PAP
-noop.source.topics.POLICY-PDP-PAP.servers=anyserver
\ No newline at end of file
+++ /dev/null
-# ============LICENSE_START=======================================================
-# Copyright (C) 2019 Nordix Foundation.
-# ================================================================================
-# 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.
-#
-# SPDX-License-Identifier: Apache-2.0
-# ============LICENSE_END=========================================================
-
-dmaap.sink.topics=POLICY-PDP-PAP
-dmaap.sink.topics.POLICY-PDP-PAP.servers=localhost:6845
-dmaap.source.topics=POLICY-PDP-PAP
-dmaap.source.topics.POLICY-PDP-PAP.servers=localhost:6845