<version.kafka>1.1.1</version.kafka>
<version.jersey>2.26</version.jersey>
<version.hibernate>5.3.7.Final</version.hibernate>
- <version.policy.common>1.5.0</version.policy.common>
+ <version.policy.common>1.5.1-SNAPSHOT</version.policy.common>
<version.policy.models>2.1.0</version.policy.models>
<!-- sonar/jacoco overrides -->
<!-- Overriding oparent default sonar/jacoco settings Combine all our reports
*/
public void validate() throws ApexStarterException {
validateReadableFile("apex starter configuration", configurationFilePath);
- validateReadableFile("apex starter properties", propertyFilePath);
}
/**
package org.onap.policy.apex.services.onappf;
-import java.io.FileInputStream;
import java.util.Arrays;
import java.util.Properties;
-
import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.common.utils.services.Registry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
// 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(APEX_STARTER_FAIL_MSG, e);
- return;
- }
+ Properties topicProperties = ParameterUtils.getTopicProperties(parameterGroup.getTopicParameterGroup());
// create the activator
activator = new ApexStarterActivator(parameterGroup, topicProperties);
package org.onap.policy.apex.services.onappf.parameters;
import lombok.Getter;
-
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
+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;
public class ApexStarterParameterGroup extends ParameterGroupImpl {
private RestServerParameters restServerParameters;
private PdpStatusParameters pdpStatusParameters;
-
+ private TopicParameterGroup topicParameterGroup;
/**
* Create the apex starter parameter group.
*
+++ /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=========================================================
- */
-
-package org.onap.policy.apex.services.onappf.parameters;
-
-import lombok.Getter;
-
-import org.onap.policy.common.parameters.ParameterGroupImpl;
-import org.onap.policy.common.parameters.annotations.Min;
-import org.onap.policy.common.parameters.annotations.NotBlank;
-import org.onap.policy.common.parameters.annotations.NotNull;
-
-/**
- * Class to hold all parameters needed for services-onappf rest server.
- *
- * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
- */
-@NotNull
-@NotBlank
-@Getter
-public class RestServerParameters extends ParameterGroupImpl {
- private String host;
-
- @Min(value = 1)
- private int port;
-
- private String userName;
- private String password;
- private boolean https;
- private boolean aaf;
-
- public RestServerParameters() {
- super("RestServerParameters");
- }
-}
import java.util.List;
import java.util.Properties;
-import org.onap.policy.apex.services.onappf.parameters.RestServerParameters;
import org.onap.policy.common.capabilities.Startable;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.slf4j.Logger;
"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" ],
+ "topicCommInfrastructure" : "dmaap"
+ }],
+ "topicSinks" : [{
+ "topic" : "POLICY-PDP-PAP",
+ "servers" : [ "message-router" ],
+ "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
-dmaap.sink.topics.POLICY-PDP-PAP.servers= message-router
\ No newline at end of file
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.io.FileInputStream;
import java.util.Properties;
import org.junit.After;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
import org.onap.policy.apex.services.onappf.parameters.CommonTestData;
+import org.onap.policy.common.endpoints.utils.ParameterUtils;
import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.pdp.concepts.PdpStatus;
@Before
public void setUp() throws Exception {
Registry.newRegistry();
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json"};
final ApexStarterCommandLineArguments arguments =
new ApexStarterCommandLineArguments(apexStarterConfigParameters);
final ApexStarterParameterGroup parGroup = new ApexStarterParameterHandler().getParameters(arguments);
-
- final Properties props = new Properties();
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- props.load(stream);
- }
-
- activator = new ApexStarterActivator(parGroup, props);
+ Properties topicProperties = ParameterUtils.getTopicProperties(parGroup.getTopicParameterGroup());
+ activator = new ApexStarterActivator(parGroup, topicProperties);
}
/**
@Test
public void testApexStarter() throws ApexStarterException {
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json"};
apexStarter = new ApexStarterMain(apexStarterConfigParameters);
assertTrue(apexStarter.getParameters().isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarter.getParameters().getName());
import static org.junit.Assert.assertEquals;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
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[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json" };
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
- ApexStarterParameterGroup apexStarterParameterGroup;
+ ApexStarterParameterGroup parameterGroup;
// The arguments return a string if there is a message to print and we should
// exit
final String argumentMessage = arguments.parse(apexStarterConfigParameters);
arguments.validate();
// Read the parameters
- apexStarterParameterGroup = new ApexStarterParameterHandler().getParameters(arguments);
+ parameterGroup = new ApexStarterParameterHandler().getParameters(arguments);
// Read the properties
- final Properties topicProperties = new Properties();
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- topicProperties.load(stream);
- }
- activator = new ApexStarterActivator(apexStarterParameterGroup, topicProperties);
+ Properties topicProperties = ParameterUtils.getTopicProperties(parameterGroup.getTopicParameterGroup());
+ activator = new ApexStarterActivator(parameterGroup, topicProperties);
Registry.register(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, activator);
activator.initialize();
}
import static org.junit.Assert.assertEquals;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
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 ApexStarterException, FileNotFoundException, IOException {
Registry.newRegistry();
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json",
- "-p", "src/test/resources/topic.properties" };
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json" };
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
- ApexStarterParameterGroup apexStarterParameterGroup;
+ ApexStarterParameterGroup parameterGroup;
// The arguments return a string if there is a message to print and we should
// exit
final String argumentMessage = arguments.parse(apexStarterConfigParameters);
arguments.validate();
// Read the parameters
- apexStarterParameterGroup = new ApexStarterParameterHandler().getParameters(arguments);
+ parameterGroup = new ApexStarterParameterHandler().getParameters(arguments);
// Read the properties
- final Properties topicProperties = new Properties();
- final String propFile = arguments.getFullPropertyFilePath();
- try (FileInputStream stream = new FileInputStream(propFile)) {
- topicProperties.load(stream);
- }
- activator = new ApexStarterActivator(apexStarterParameterGroup, topicProperties);
+ Properties topicProperties = ParameterUtils.getTopicProperties(parameterGroup.getTopicParameterGroup());
+ activator = new ApexStarterActivator(parameterGroup, topicProperties);
Registry.register(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, activator);
activator.initialize();
pdpUpdateMessageListener = new PdpUpdateListener();
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";
public 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_PASSWORD = "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.RestServerParameters;
+import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.GroupValidationResult;
/**
ApexStarterParameterGroup.class);
final RestServerParameters restServerParameters = apexStarterParameters.getRestServerParameters();
final PdpStatusParameters pdpStatusParameters = apexStarterParameters.getPdpStatusParameters();
+ final TopicParameterGroup topicParameterGroup = apexStarterParameters.getTopicParameterGroup();
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarterParameters.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());
assertEquals(restServerParameters.getHost(), apexStarterParameters.getRestServerParameters().getHost());
assertEquals(restServerParameters.getPort(), apexStarterParameters.getRestServerParameters().getPort());
assertEquals(restServerParameters.getUserName(), apexStarterParameters.getRestServerParameters().getUserName());
final GroupValidationResult validationResult = apexStarterParameters.validate();
assertFalse(validationResult.isValid());
assertTrue(validationResult.getResult()
- .contains("\"org.onap.policy.apex.services.onappf.parameters.RestServerParameters\" INVALID, "
+ .contains("\"org.onap.policy.common.endpoints.parameters.RestServerParameters\" INVALID, "
+ + "parameter group has status INVALID"));
+ }
+
+
+ @Test
+ public void testApexStarterParameterGroupp_EmptyTopicParameters() {
+ final Map<String, Object> map =
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
+ map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true));
+
+ final ApexStarterParameterGroup apexStarterParameters =
+ commonTestData.toObject(map, ApexStarterParameterGroup.class);
+ final GroupValidationResult validationResult = apexStarterParameters.validate();
+ assertFalse(validationResult.isValid());
+ assertTrue(validationResult.getResult()
+ .contains("\"org.onap.policy.common.endpoints.parameters.TopicParameterGroup\" INVALID, "
+ "parameter group has status INVALID"));
}
}
systemProps.put("javax.net.ssl.keyStorePassword", "Pol1cy_0nap");
System.setProperties(systemProps);
- // @formatter:off
- final String[] apexStarterConfigParameters = {
- "-c", "src/test/resources/TestConfigParams.json",
- "-p", "src/test/resources/topic.properties"
- };
- // @formatter:on
+ final String[] apexStarterConfigParameters = { "-c", "src/test/resources/TestConfigParams.json" };
main = new ApexStarterMain(apexStarterConfigParameters);
"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"
+ }]
}
-}
+}
\ No newline at end of file
"pdpStatusParameters":{
"timeIntervalMs": 120000,
"pdpType":"apex",
- "description":"Pdp heartbeat",
+ "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