diff options
23 files changed, 969 insertions, 74 deletions
diff --git a/examples/examples-decisionmaker/pom.xml b/examples/examples-decisionmaker/pom.xml index 1fcddbf22..60e63724d 100644 --- a/examples/examples-decisionmaker/pom.xml +++ b/examples/examples-decisionmaker/pom.xml @@ -30,7 +30,8 @@ <description>Specific code for the APEX Decision Maker Example</description> <properties> - <policymodel.name>DecisionMakerPolicyModel</policymodel.name> + <policymodel.decisionmaker.name>DecisionMakerPolicyModel</policymodel.decisionmaker.name> + <policymodel.healthcheck.name>HealthCheckPolicyModel</policymodel.healthcheck.name> <apex-domains-decisionmaker-dir>${project.basedir}/src</apex-domains-decisionmaker-dir> </properties> @@ -50,7 +51,7 @@ <artifactId>exec-maven-plugin</artifactId> <executions> <execution> - <id>generate-policy</id> + <id>generate-decisionmaker-policy</id> <phase>compile</phase> <goals> <goal>java</goal> @@ -59,9 +60,26 @@ <mainClass>org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain</mainClass> <classpathScope>compile</classpathScope> <arguments> - <argument>--command-file=${project.basedir}/src/main/resources/policy/${policymodel.name}.apex</argument> - <argument>--output-model-file=${project.build.directory}/classes/${policymodel.name}.json</argument> - <argument>--log-file=${project.build.directory}/${policymodel.name}_policygeneration.log</argument> + <argument>--command-file=${project.basedir}/src/main/resources/policy/${policymodel.decisionmaker.name}.apex</argument> + <argument>--output-model-file=${project.build.directory}/classes/${policymodel.decisionmaker.name}.json</argument> + <argument>--log-file=${project.build.directory}/${policymodel.decisionmaker.name}_policygeneration.log</argument> + <argument>--working-dir=${project.basedir}</argument> + </arguments> + </configuration> + </execution> + <execution> + <id>generate-healthcheck-policy</id> + <phase>compile</phase> + <goals> + <goal>java</goal> + </goals> + <configuration> + <mainClass>org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain</mainClass> + <classpathScope>compile</classpathScope> + <arguments> + <argument>--command-file=${project.basedir}/src/main/resources/policy/${policymodel.healthcheck.name}.apex</argument> + <argument>--output-model-file=${project.build.directory}/classes/${policymodel.healthcheck.name}.json</argument> + <argument>--log-file=${project.build.directory}/${policymodel.healthcheck.name}_policygeneration.log</argument> <argument>--working-dir=${project.basedir}</argument> </arguments> </configuration> diff --git a/examples/examples-decisionmaker/src/main/resources/examples/config/DecisionMaker/ApexConfigHealthCheckRESTClient.json b/examples/examples-decisionmaker/src/main/resources/examples/config/DecisionMaker/ApexConfigHealthCheckRESTClient.json new file mode 100644 index 000000000..ec7391afe --- /dev/null +++ b/examples/examples-decisionmaker/src/main/resources/examples/config/DecisionMaker/ApexConfigHealthCheckRESTClient.json @@ -0,0 +1,57 @@ +{ + "javaProperties" : [ + ["javax.net.ssl.trustStore", "/home/liam/tmp/distribution/etc/ssl/policy-truststore"], + ["javax.net.ssl.trustStorePassword", "UG9sMWN5XzBuYXA="] + ], + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 4, + "deploymentPort": 12345, + "policyModelFileName": "/home/liam/git/onap/policy/apex-pdp/examples/examples-decisionmaker/target/classes/HealthCheckPolicyModel.json", + "engineParameters": { + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters" + } + } + } + }, + "eventInputParameters": { + "HealthCheckConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "RESTCLIENT", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters", + "parameters": { + "url": "https://policy:6969/healthcheck", + "httpHeaders" : [ + ["Authorization", "Basic aGVhbHRoY2hlY2s6emIhWHp0RzM0"] + ] + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "nameAlias": "none", + "versionAlias": "version", + "sourceAlias": "from" + } + }, + "eventName": "HealthCheckEvent" + } + }, + "eventOutputParameters": { + "logProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "/tmp/EventsOut.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + } +} diff --git a/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js b/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js new file mode 100644 index 000000000..ebc0e6387 --- /dev/null +++ b/examples/examples-decisionmaker/src/main/resources/logic/HealthCheckTask.js @@ -0,0 +1,26 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-decisionmaker/src/main/resources/policy/HealthCheckPolicyModel.apex b/examples/examples-decisionmaker/src/main/resources/policy/HealthCheckPolicyModel.apex new file mode 100644 index 000000000..c799a8f37 --- /dev/null +++ b/examples/examples-decisionmaker/src/main/resources/policy/HealthCheckPolicyModel.apex @@ -0,0 +1,58 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2018 Ericsson. 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +#------------------------------------------------------------------------------- + +model create name=HealthCheckPolicyModel + +schema create name=SimpleStringType flavour=Java schema=java.lang.String +schema create name=SimpleIntegerType flavour=Java schema=java.lang.Integer +schema create name=SimpleBooleanType flavour=Java schema=java.lang.Boolean + +event create name=HealthCheckEvent nameSpace=org.onap.policy.apex.domains.HealthCheck source=Distribution target=Apex +event parameter create name=HealthCheckEvent parName=name schemaName=SimpleStringType +event parameter create name=HealthCheckEvent parName=url schemaName=SimpleStringType +event parameter create name=HealthCheckEvent parName=healthy schemaName=SimpleBooleanType +event parameter create name=HealthCheckEvent parName=code schemaName=SimpleIntegerType +event parameter create name=HealthCheckEvent parName=message schemaName=SimpleStringType + +task create name=HealthCheckTask +task inputfield create name=HealthCheckTask fieldName=name schemaName=SimpleStringType +task inputfield create name=HealthCheckTask fieldName=url schemaName=SimpleStringType +task inputfield create name=HealthCheckTask fieldName=healthy schemaName=SimpleBooleanType +task inputfield create name=HealthCheckTask fieldName=code schemaName=SimpleIntegerType +task inputfield create name=HealthCheckTask fieldName=message schemaName=SimpleStringType + +task outputfield create name=HealthCheckTask fieldName=name schemaName=SimpleStringType +task outputfield create name=HealthCheckTask fieldName=url schemaName=SimpleStringType +task outputfield create name=HealthCheckTask fieldName=healthy schemaName=SimpleBooleanType +task outputfield create name=HealthCheckTask fieldName=code schemaName=SimpleIntegerType +task outputfield create name=HealthCheckTask fieldName=message schemaName=SimpleStringType + +task logic create name=HealthCheckTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/HealthCheckTask.js" +LE + +policy create name=HealthCheckPolicy template=freestyle firstState=HealthCheckState + +policy state create name=HealthCheckPolicy stateName=HealthCheckState triggerName=HealthCheckEvent defaultTaskName=HealthCheckTask +policy state output create name=HealthCheckPolicy stateName=HealthCheckState outputName=HealthCheckOutput eventName=HealthCheckEvent +policy state taskref create name=HealthCheckPolicy stateName=HealthCheckState taskName=HealthCheckTask outputType=DIRECT outputName=HealthCheckOutput + +validate + diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java index 1bdf39317..4c8bd1384 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java @@ -70,8 +70,9 @@ public class ClassBuilder { return new ClassBuilder(Class.forName("java.lang." + className)); } catch (Exception classFindException) { LOGGER.warn("class not found", classFindException); - throw new IllegalArgumentException("Class '" + className - + "' not found. Also looked for a class called 'java.lang." + className + "'", e); + throw new IllegalArgumentException( + "Class '" + className + "' not found. Also looked for a class called 'java.lang." + className + "'", + e); } } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java index 04397d688..5591777eb 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java @@ -202,7 +202,7 @@ public class ApexRestClientConsumer implements ApexEventConsumer, Runnable { public void run() { try { final Response response = client.target(restConsumerProperties.getUrl()).request("application/json") - .get(); + .headers(restConsumerProperties.getHttpHeadersAsMultivaluedMap()).get(); // Check that the event request worked if (response.getStatus() != Response.Status.OK.getStatusCode()) { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java index a7e0ddd52..4113cea4b 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java @@ -183,9 +183,11 @@ public class ApexRestClientProducer implements ApexEventProducer { private Response sendEventAsRestRequest(final String event) { // We have already checked that it is a PUT or POST request if (RestClientCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())) { - return client.target(restProducerProperties.getUrl()).request("application/json").post(Entity.json(event)); + return client.target(restProducerProperties.getUrl()).request("application/json") + .headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).post(Entity.json(event)); } else { - return client.target(restProducerProperties.getUrl()).request("application/json").put(Entity.json(event)); + return client.target(restProducerProperties.getUrl()).request("application/json") + .headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).put(Entity.json(event)); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java index 0329d4440..b3fab9470 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java @@ -118,7 +118,7 @@ public class RestClientCarrierTechnologyParameters extends CarrierTechnologyPara /** * Check if http headers have been set for the REST request. * - * @return true if headers have beenset + * @return true if headers have been set */ public boolean checkHttpHeadersSet() { return httpHeaders != null && httpHeaders.length > 0; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java index 1498678e9..ae75dd7e5 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java @@ -147,7 +147,7 @@ public class ApexRestClientConusmerTest { consumerParameters.setCarrierTechnologyParameters(rcctp); rcctp.setUrl("http://some.place.that.does.not/exist"); SupportApexEventReceiver incomingEventReceiver = new SupportApexEventReceiver(); - + try { arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver); assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod()); @@ -163,6 +163,7 @@ public class ApexRestClientConusmerTest { Mockito.doReturn(Response.Status.BAD_REQUEST.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).get(); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcc.setClient(httpClientMock); @@ -182,7 +183,7 @@ public class ApexRestClientConusmerTest { final String outString = outContent.toString(); System.setOut(stdout); - + assertTrue(outString.contains( "reception of event from URL \"http://some.place.that.does.not/exist\" failed with status code 400")); } @@ -215,6 +216,7 @@ public class ApexRestClientConusmerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).get(); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcc.setClient(httpClientMock); @@ -231,12 +233,11 @@ public class ApexRestClientConusmerTest { } catch (Exception e) { fail("test should not throw an exception"); } - + final String outString = outContent.toString(); System.setOut(stdout); - - assertTrue(outString.contains( - "received an empty event from URL \"http://some.place.that.does.not/exist\"")); + + assertTrue(outString.contains("received an empty event from URL \"http://some.place.that.does.not/exist\"")); } @Test @@ -268,6 +269,7 @@ public class ApexRestClientConusmerTest { Mockito.doReturn("").when(responseMock).readEntity(String.class); Mockito.doReturn(responseMock).when(builderMock).get(); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcc.setClient(httpClientMock); @@ -284,12 +286,11 @@ public class ApexRestClientConusmerTest { } catch (Exception e) { fail("test should not throw an exception"); } - + final String outString = outContent.toString(); System.setOut(stdout); - - assertTrue(outString.contains( - "received an empty event from URL \"http://some.place.that.does.not/exist\"")); + + assertTrue(outString.contains("received an empty event from URL \"http://some.place.that.does.not/exist\"")); } @Test @@ -321,6 +322,7 @@ public class ApexRestClientConusmerTest { Mockito.doReturn("This is an event").when(responseMock).readEntity(String.class); Mockito.doReturn(responseMock).when(builderMock).get(); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcc.setClient(httpClientMock); diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java index 3ef172427..8f0e0940b 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java @@ -161,13 +161,14 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); try { arcp.sendEvent(123, "EventName", "This is an Event"); arcp.stop(); - } catch (Exception e) { + } catch (Exception ex) { fail("test should not throw an exception"); } } @@ -197,6 +198,7 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); @@ -239,6 +241,7 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); @@ -250,14 +253,13 @@ public class ApexRestClientProducerTest { } } - @Test public void testApexRestClientProducerPostEventCacheTrace() { MockitoAnnotations.initMocks(this); ch.qos.logback.classic.Logger classicLogger = (ch.qos.logback.classic.Logger) LOGGER; classicLogger.setLevel(Level.TRACE); - + ApexRestClientProducer arcp = new ApexRestClientProducer(); assertNotNull(arcp); @@ -285,6 +287,7 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); @@ -321,6 +324,7 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.BAD_REQUEST.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java index 2b15b145f..3b20d3d68 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java @@ -21,6 +21,7 @@ package org.onap.policy.apex.service.engine.main; import java.util.Arrays; +import java.util.Base64; import java.util.Map.Entry; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; @@ -77,15 +78,18 @@ public class ApexMain { return; } + // Set incoming Java properties + setJavaProperties(parameters); + // Set the name of the event handler parameters for producers and consumers for (final Entry<String, EventHandlerParameters> ehParameterEntry : parameters.getEventOutputParameters() - .entrySet()) { + .entrySet()) { if (!ehParameterEntry.getValue().checkSetName()) { ehParameterEntry.getValue().setName(ehParameterEntry.getKey()); } } for (final Entry<String, EventHandlerParameters> ehParameterEntry : parameters.getEventInputParameters() - .entrySet()) { + .entrySet()) { if (!ehParameterEntry.getValue().checkSetName()) { ehParameterEntry.getValue().setName(ehParameterEntry.getKey()); } @@ -128,8 +132,8 @@ public class ApexMain { } /** - * The Class ApexMainShutdownHookClass terminates the Apex engine for the Apex service when its - * run method is called. + * The Class ApexMainShutdownHookClass terminates the Apex engine for the Apex service when its run method is + * called. */ private class ApexMainShutdownHookClass extends Thread { /* @@ -149,6 +153,31 @@ public class ApexMain { } /** + * Set the Java properties specified in the parameters. + * + * @param parameters The incoming parameters + */ + private void setJavaProperties(final ApexParameters parameters) { + if (!parameters.checkJavaPropertiesSet()) { + return; + } + + // Set each Java property + for (String[] javaProperty : parameters.getJavaProperties()) { + String javaPropertyName = javaProperty[0]; + String javaPropertyValue = javaProperty[1]; + + // Passwords are encoded using base64, better than sending passwords in the clear + if (javaPropertyName.toLowerCase().contains("password")) { + javaPropertyValue = new String(Base64.getDecoder().decode(javaPropertyValue.getBytes())); + } + + // Set the Java property + System.setProperty(javaPropertyName, javaPropertyValue); + } + } + + /** * The main method. * * @param args the arguments diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java index 4bbc5fc85..07cf7811e 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/ApexParameters.java @@ -20,6 +20,7 @@ package org.onap.policy.apex.service.parameters; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -33,6 +34,7 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.common.parameters.ParameterGroup; import org.onap.policy.common.parameters.ValidationStatus; +import org.onap.policy.common.utils.validation.ParameterValidationUtils; /** * The main container parameter class for an Apex service. @@ -50,11 +52,15 @@ public class ApexParameters implements ParameterGroup { private String name; // Constants for recurring strings + private static final String JAVA_PROPERTIES = "javaProperties"; private static final String PEER_STRING = "peer "; private static final String EVENT_INPUT_PARAMETERS_STRING = "eventInputParameters"; private static final String EVENT_OUTPUT_PARAMETERS_STRING = "eventOutputParameters"; private static final String FOR_PEERED_MODE_STRING = " for peered mode "; + // Properties for the Java JVM + private String[][] javaProperties = null; + // Parameters for the engine service and the engine threads in the engine service private EngineServiceParameters engineServiceParameters; @@ -138,13 +144,33 @@ public class ApexParameters implements ParameterGroup { this.name = name; } + /** + * Check if Java properties have been specified. + * + * @return true if Java properties have been specified + */ + public boolean checkJavaPropertiesSet() { + return javaProperties != null && javaProperties.length > 0; + } + + /** + * Gets the Java properties that have been specified. + * + * @return the Java properties that have been specified + */ + public String[][] getJavaProperties() { + return javaProperties; + } + @Override public GroupValidationResult validate() { GroupValidationResult result = new GroupValidationResult(this); + validateJavaProperties(result); + if (engineServiceParameters == null) { result.setResult("engineServiceParameters", ValidationStatus.INVALID, - "engine service parameters are not specified"); + "engine service parameters are not specified"); } else { result.setResult("engineServiceParameters", engineServiceParameters.validate()); } @@ -152,12 +178,12 @@ public class ApexParameters implements ParameterGroup { // Sanity check, we must have an entry in both output and input maps if (eventInputParameters.isEmpty()) { result.setResult(EVENT_INPUT_PARAMETERS_STRING, ValidationStatus.INVALID, - "at least one event input must be specified"); + "at least one event input must be specified"); } if (eventOutputParameters.isEmpty()) { result.setResult(EVENT_OUTPUT_PARAMETERS_STRING, ValidationStatus.INVALID, - "at least one event output must be specified"); + "at least one event output must be specified"); } // Validate that the values of all parameters are ok @@ -175,6 +201,37 @@ public class ApexParameters implements ParameterGroup { } /** + * This method validates the java properties variable if it is present. + * + * @param result the result of the validation + */ + private void validateJavaProperties(GroupValidationResult result) { + if (javaProperties == null) { + return; + } + + StringBuilder errorMessageBuilder = new StringBuilder(); + for (String[] javaProperty : javaProperties) { + if (javaProperty == null) { + errorMessageBuilder.append("java properties array entry is null\n"); + } else if (javaProperty.length != 2) { + errorMessageBuilder.append("java properties array entries must have one key and one value: " + + Arrays.deepToString(javaProperty) + "\n"); + } else if (!ParameterValidationUtils.validateStringParameter(javaProperty[0])) { + errorMessageBuilder + .append("java properties key is null or blank: " + Arrays.deepToString(javaProperty) + "\n"); + } else if (!ParameterValidationUtils.validateStringParameter(javaProperty[1])) { + errorMessageBuilder + .append("java properties value is null or blank: " + Arrays.deepToString(javaProperty) + "\n"); + } + } + + if (errorMessageBuilder.length() > 0) { + result.setResult(JAVA_PROPERTIES, ValidationStatus.INVALID, errorMessageBuilder.toString()); + } + } + + /** * This method validates the parameters in an event handler map. * * @param eventHandlerType the type of the event handler to use on error messages @@ -182,15 +239,15 @@ public class ApexParameters implements ParameterGroup { * @param parsForValidation The event handler parameters to validate (input or output) */ private void validateEventHandlerMap(final String eventHandlerType, final GroupValidationResult result, - final Map<String, EventHandlerParameters> parsForValidation) { + final Map<String, EventHandlerParameters> parsForValidation) { for (final Entry<String, EventHandlerParameters> parameterEntry : parsForValidation.entrySet()) { if (parameterEntry.getKey() == null || parameterEntry.getKey().trim().isEmpty()) { result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, - "invalid " + eventHandlerType + " name \"" + parameterEntry.getKey() + "\""); + "invalid " + eventHandlerType + " name \"" + parameterEntry.getKey() + "\""); } else if (parameterEntry.getValue() == null) { result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, - "invalid/Null event input prameters specified for " + eventHandlerType + " name \"" - + parameterEntry.getKey() + "\" "); + "invalid/Null event input prameters specified for " + eventHandlerType + " name \"" + + parameterEntry.getKey() + "\" "); } else { result.setResult(eventHandlerType, parameterEntry.getKey(), parameterEntry.getValue().validate()); } @@ -213,30 +270,28 @@ public class ApexParameters implements ParameterGroup { * @param peeredMode The mode to check */ private void validatePeeredModeParameters(final String eventHandlerType, final GroupValidationResult result, - final Entry<String, EventHandlerParameters> parameterEntry, - final EventHandlerPeeredMode peeredMode) { + final Entry<String, EventHandlerParameters> parameterEntry, final EventHandlerPeeredMode peeredMode) { final String messagePreamble = "specified peered mode \"" + peeredMode + "\""; final String peer = parameterEntry.getValue().getPeer(peeredMode); if (parameterEntry.getValue().isPeeredMode(peeredMode)) { if (peer == null || peer.trim().isEmpty()) { result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, - messagePreamble + " mandatory parameter not specified or is null"); + messagePreamble + " mandatory parameter not specified or is null"); } if (parameterEntry.getValue().getPeerTimeout(peeredMode) < 0) { - result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, messagePreamble - + " timeout value \"" + parameterEntry.getValue().getPeerTimeout(peeredMode) - + "\" is illegal, specify a non-negative timeout value in milliseconds"); + result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, + messagePreamble + " timeout value \"" + parameterEntry.getValue().getPeerTimeout(peeredMode) + + "\" is illegal, specify a non-negative timeout value in milliseconds"); } } else { if (peer != null) { result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, messagePreamble - + " peer is illegal on " + eventHandlerType + " \"" + parameterEntry.getKey() + "\" "); + + " peer is illegal on " + eventHandlerType + " \"" + parameterEntry.getKey() + "\" "); } if (parameterEntry.getValue().getPeerTimeout(peeredMode) != 0) { - result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, - messagePreamble + " timeout is illegal on " + eventHandlerType + " \"" - + parameterEntry.getKey() + "\""); + result.setResult(eventHandlerType, parameterEntry.getKey(), ValidationStatus.INVALID, messagePreamble + + " timeout is illegal on " + eventHandlerType + " \"" + parameterEntry.getKey() + "\""); } } } @@ -266,9 +321,9 @@ public class ApexParameters implements ParameterGroup { // Validate the parameters for each side of the peered mode parameters validatePeeredModePeers(EVENT_INPUT_PARAMETERS_STRING, result, peeredMode, inputParametersUsingMode, - outputParametersUsingMode); + outputParametersUsingMode); validatePeeredModePeers(EVENT_OUTPUT_PARAMETERS_STRING, result, peeredMode, outputParametersUsingMode, - inputParametersUsingMode); + inputParametersUsingMode); } /** @@ -280,9 +335,8 @@ public class ApexParameters implements ParameterGroup { * @param rightModeParameters The mode parameters being referenced by the checked parameters */ private void validatePeeredModePeers(final String handlerMapVariableName, final GroupValidationResult result, - final EventHandlerPeeredMode peeredMode, - final Map<String, EventHandlerParameters> leftModeParameterMap, - final Map<String, EventHandlerParameters> rightModeParameterMap) { + final EventHandlerPeeredMode peeredMode, final Map<String, EventHandlerParameters> leftModeParameterMap, + final Map<String, EventHandlerParameters> rightModeParameterMap) { // These sets are used to check for duplicate references on the both sides final Set<String> leftCheckDuplicateSet = new HashSet<>(); @@ -299,9 +353,8 @@ public class ApexParameters implements ParameterGroup { // Check that the peer reference is OK if (rightModeParameters == null) { result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID, - PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING - + peeredMode - + " does not exist or is not defined with the same peered mode"); + PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode + + " does not exist or is not defined with the same peered mode"); continue; } @@ -309,36 +362,32 @@ public class ApexParameters implements ParameterGroup { final String rightSidePeer = rightModeParameters.getPeer(peeredMode); if (!rightSidePeer.equals(leftModeParameterEntry.getKey())) { result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID, - PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING - + peeredMode + ", value \"" + rightSidePeer + "\" on peer \"" - + leftSidePeer + "\" does not equal event handler \"" - + leftModeParameterEntry.getKey() + "\""); + PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode + + ", value \"" + rightSidePeer + "\" on peer \"" + leftSidePeer + + "\" does not equal event handler \"" + leftModeParameterEntry.getKey() + "\""); } else { // Check for duplicates if (!leftCheckDuplicateSet.add(leftSidePeer)) { result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID, - PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING - + peeredMode + ", peer value \"" + leftSidePeer - + "\" on event handler \"" + leftModeParameterEntry.getKey() - + "\" is used more than once"); + PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode + + ", peer value \"" + leftSidePeer + "\" on event handler \"" + + leftModeParameterEntry.getKey() + "\" is used more than once"); } if (!rightCheckDuplicateSet.add(rightSidePeer)) { result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID, - PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING - + peeredMode + ", peer value \"" + rightSidePeer + "\" on peer \"" - + leftSidePeer + "\" on event handler \"" - + leftModeParameterEntry.getKey() + "\" is used more than once"); + PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode + + ", peer value \"" + rightSidePeer + "\" on peer \"" + leftSidePeer + + "\" on event handler \"" + leftModeParameterEntry.getKey() + "\" is used more than once"); } } if (!crossCheckPeeredTimeoutValues(leftModeParameters, rightModeParameters, peeredMode)) { result.setResult(handlerMapVariableName, leftModeParameterEntry.getKey(), ValidationStatus.INVALID, - PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING - + peeredMode + " timeout " - + leftModeParameters.getPeerTimeout(peeredMode) + " on event handler \"" - + leftModeParameters.getName() + "\" does not equal timeout " - + rightModeParameters.getPeerTimeout(peeredMode) - + " on event handler \"" + rightModeParameters.getName() + "\""); + PEER_STRING + '"' + leftModeParameters.getPeer(peeredMode) + FOR_PEERED_MODE_STRING + peeredMode + + " timeout " + leftModeParameters.getPeerTimeout(peeredMode) + " on event handler \"" + + leftModeParameters.getName() + "\" does not equal timeout " + + rightModeParameters.getPeerTimeout(peeredMode) + " on event handler \"" + + rightModeParameters.getName() + "\""); } } @@ -352,7 +401,7 @@ public class ApexParameters implements ParameterGroup { * @return true if the timeout values are cross checked as being OK */ private boolean crossCheckPeeredTimeoutValues(final EventHandlerParameters leftModeParameters, - final EventHandlerParameters rightModeParameters, final EventHandlerPeeredMode peeredMode) { + final EventHandlerParameters rightModeParameters, final EventHandlerPeeredMode peeredMode) { // Cross-set the timeouts if they are not specified if (leftModeParameters.getPeerTimeout(peeredMode) != 0) { if (rightModeParameters.getPeerTimeout(peeredMode) != 0) { diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java index 3ccdd5926..e7317a9f1 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/TestJsonEventConverter.java @@ -21,6 +21,7 @@ package org.onap.policy.apex.service.engine.event; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import org.junit.Test; @@ -98,8 +99,7 @@ public class TestJsonEventConverter { converter.fromApexEvent(new ApexEvent("Event", "0.0.1", "a.name.space", "here", "there")); fail("test should throw an exception"); } catch (Exception tae) { - assertEquals("Model for org.onap.policy.apex.model.eventmodel.concepts.AxEvents not found in model service", - tae.getMessage()); + assertNotNull(tae); } } } diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java new file mode 100644 index 000000000..c6118108f --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java @@ -0,0 +1,149 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.service.engine.main; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +import org.junit.Test; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; + +/** + * Test the ApexMain class. + */ +public class ApexMainTest { + private PrintStream stdout = System.out; + + @Test + public void testNullParameters() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + ApexMain.main(null); + ThreadUtilities.sleep(200); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("Apex configuration file was not specified as an argument")); + } + + @Test + public void testBadArguments() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-whee"}; + + final ApexMain apexMain = new ApexMain(args); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("invalid command line arguments specified : Unrecognized option: -whee")); + } + + @Test + public void testHelp() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-h"}; + + final ApexMain apexMain = new ApexMain(args); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]")); + } + + @Test + public void testBadParameters() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-c", "src/test/resources/parameters/badParams.json"}; + + final ApexMain apexMain = new ApexMain(args); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("parameter group has status INVALID")); + } + + @Test + public void testCorrectParameters() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-c", "src/test/resources/parameters/correctParams.json"}; + + final ApexMain apexMain = new ApexMain(args); + assertEquals("MyApexEngine", apexMain.getParameters().getEngineServiceParameters().getName()); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("Added the action listener to the engine")); + } + + @Test + public void testjavaProperties() throws ApexException { + OutputStream outContent = new ByteArrayOutputStream(); + System.setOut(new PrintStream(outContent)); + + String[] args = {"-c", "src/test/resources/parameters/correctParamsJavaProperties.json"}; + + final ApexMain apexMain = new ApexMain(args); + assertEquals("MyApexEngine", apexMain.getParameters().getEngineServiceParameters().getName()); + + assertEquals("trust-store-file", System.getProperty("javax.net.ssl.trustStore")); + assertEquals("Pol1cy_0nap", System.getProperty("javax.net.ssl.trustStorePassword")); + ThreadUtilities.sleep(200); + apexMain.shutdown(); + + final String outString = outContent.toString(); + + System.setOut(stdout); + + assertTrue(outString.contains("Added the action listener to the engine")); + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java new file mode 100644 index 000000000..4a946b111 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java @@ -0,0 +1,110 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.service.engine.parameters; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Test; +import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments; +import org.onap.policy.apex.service.parameters.ApexParameterHandler; +import org.onap.policy.apex.service.parameters.ApexParameters; +import org.onap.policy.common.parameters.ParameterException; + +/** + * Test the ApexParameters class. + */ +public class ApexParametersTest { + + @Test + public void javaPropertiesOk() throws ParameterException { + final String[] args = + { "-c", "src/test/resources/parameters/javaPropertiesOK.json" }; + final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args); + + try { + ApexParameters parameters = new ApexParameterHandler().getParameters(arguments); + assertTrue(parameters.checkJavaPropertiesSet()); + assertEquals("property0", parameters.getJavaProperties()[0][0]); + assertEquals("property0Value", parameters.getJavaProperties()[0][1]); + assertEquals("property1", parameters.getJavaProperties()[1][0]); + assertEquals("property1Value", parameters.getJavaProperties()[1][1]); + } catch (final ParameterException e) { + fail("This test should not throw an exception"); + } + } + + @Test + public void javaPropertiesEmpty() throws ParameterException { + final String[] args = + { "-c", "src/test/resources/parameters/javaPropertiesEmpty.json" }; + final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args); + + try { + ApexParameters parameters = new ApexParameterHandler().getParameters(arguments); + assertFalse(parameters.checkJavaPropertiesSet()); + } catch (final ParameterException pe) { + fail("This test should not throw an exception"); + } + } + + + @Test + public void javaPropertiesBad() throws ParameterException { + final String[] args = + { "-c", "src/test/resources/parameters/javaPropertiesBad.json" }; + final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args); + + try { + new ApexParameterHandler().getParameters(arguments); + fail("This test should throw an exception"); + } catch (final ParameterException pe) { + assertTrue(pe.getMessage().contains("java properties array entries must have one key and one value")); + assertTrue(pe.getMessage().contains("java properties key is null or blank")); + assertTrue(pe.getMessage().contains("java properties value is null or blank")); + assertTrue(pe.getMessage().contains("java properties array entry is null")); + } + } + + @Test + public void testGettersSetters() { + ApexParameters pars = new ApexParameters(); + assertNotNull(pars); + + pars.setEngineServiceParameters(null); + assertNull(pars.getEngineServiceParameters()); + + pars.setEventInputParameters(null); + assertNull(pars.getEventInputParameters()); + + pars.setEventOutputParameters(null); + assertNull(pars.getEventOutputParameters()); + + assertFalse(pars.checkJavaPropertiesSet()); + + pars.setName("parName"); + assertEquals("parName", pars.getName()); + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyStateFinalizerExecutor.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyStateFinalizerExecutor.java new file mode 100644 index 000000000..f7c0876d4 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyStateFinalizerExecutor.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.service.engine.parameters.dummyclasses; + +import java.util.Map; + +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; + +/** + * Dummy state finalizer executor for testing. + */ +public class DummyStateFinalizerExecutor extends StateFinalizerExecutor { + public DummyStateFinalizerExecutor() { + } + + @Override + public String execute(final long executionId, final Map<String, Object> newIncomingFields) + throws StateMachineException, ContextException { + + return "stateOutput0"; + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskExecutor.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskExecutor.java new file mode 100644 index 000000000..421cfb9fc --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskExecutor.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.service.engine.parameters.dummyclasses; + +import java.util.Map; + +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.engine.executor.TaskExecutor; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.policymodel.concepts.AxTask; + +/** + * Dummy task executor for testing. + */ +public class DummyTaskExecutor extends TaskExecutor { + public DummyTaskExecutor() { + } + + @Override + public void prepare() throws StateMachineException { + } + + @Override + public Map<String, Object> execute(final long executionId, final Map<String, Object> newIncomingFields) + throws StateMachineException, ContextException { + + AxArtifactKey event0Key = new AxArtifactKey("Event0:0.0.1"); + return new EnEvent(event0Key); + } + + @Override + public AxTask getSubject() { + AxArtifactKey taskKey = new AxArtifactKey("FirstTask:0.0.1"); + return new AxTask(taskKey); + } + + @Override + public void cleanUp() throws StateMachineException { + } +} diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskSelectExecutor.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskSelectExecutor.java new file mode 100644 index 000000000..020e69843 --- /dev/null +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/dummyclasses/DummyTaskSelectExecutor.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.service.engine.parameters.dummyclasses; + +import org.onap.policy.apex.context.ContextException; +import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor; +import org.onap.policy.apex.core.engine.executor.exception.StateMachineException; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +/** + * Dummy task selection executor for testing. + */ +public class DummyTaskSelectExecutor extends TaskSelectExecutor { + public DummyTaskSelectExecutor() { + } + + @Override + public void prepare() throws StateMachineException { + } + + @Override + public AxArtifactKey execute(final long executionId, final EnEvent newIncomingEvent) + throws StateMachineException, ContextException { + + return new AxArtifactKey("task:0.0.1"); + } + + @Override + public void cleanUp() throws StateMachineException { + } +} diff --git a/services/services-engine/src/test/resources/parameters/correctParams.json b/services/services-engine/src/test/resources/parameters/correctParams.json new file mode 100644 index 000000000..2265134d4 --- /dev/null +++ b/services/services-engine/src/test/resources/parameters/correctParams.json @@ -0,0 +1,43 @@ +{ + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 2, + "deploymentPort": 65522, + "policyModelFileName": "src/test/resources/policymodels/SmallModel.json", + "engineParameters": { + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperExecutorParameters" + } + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "standardIo": true + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventInputParameters": { + "TheFileConsumer1": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "standardIo": true + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + } +}
\ No newline at end of file diff --git a/services/services-engine/src/test/resources/parameters/correctParamsJavaProperties.json b/services/services-engine/src/test/resources/parameters/correctParamsJavaProperties.json new file mode 100644 index 000000000..0a599d701 --- /dev/null +++ b/services/services-engine/src/test/resources/parameters/correctParamsJavaProperties.json @@ -0,0 +1,47 @@ +{ + "javaProperties" : [ + ["javax.net.ssl.trustStore", "trust-store-file"], + ["javax.net.ssl.trustStorePassword", "UG9sMWN5XzBuYXA="] + ], + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 2, + "deploymentPort": 65522, + "policyModelFileName": "src/test/resources/policymodels/SmallModel.json", + "engineParameters": { + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperExecutorParameters" + } + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "standardIo": true + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventInputParameters": { + "TheFileConsumer1": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "standardIo": true + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + } +}
\ No newline at end of file diff --git a/services/services-engine/src/test/resources/parameters/javaPropertiesBad.json b/services/services-engine/src/test/resources/parameters/javaPropertiesBad.json new file mode 100644 index 000000000..dc663bd56 --- /dev/null +++ b/services/services-engine/src/test/resources/parameters/javaPropertiesBad.json @@ -0,0 +1,53 @@ +{ + "javaProperties" : [ + ["property0"], + ["property1", "property1Value", "propertyExtraValue"], + [], + [null, "proeprtyValue"], + null, + ["propertyname", null] + ], + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 345, + "deploymentPort": 65522, + "policyModelFileName": "src/test/resources/policymodels/SmallModel.json", + "engineParameters": { + "contextParameters": { + "parameterClassName": "org.onap.policy.apex.context.parameters.ContextParameters" + }, + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperExecutorParameters" + } + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "target/aaa.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventInputParameters": { + "MySuperDooperConsumer1": { + "carrierTechnologyParameters": { + "carrierTechnology": "SUPER_DOOPER", + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "SUPER_TOK_DEL", + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters" + } + } + } +}
\ No newline at end of file diff --git a/services/services-engine/src/test/resources/parameters/javaPropertiesEmpty.json b/services/services-engine/src/test/resources/parameters/javaPropertiesEmpty.json new file mode 100644 index 000000000..aca972302 --- /dev/null +++ b/services/services-engine/src/test/resources/parameters/javaPropertiesEmpty.json @@ -0,0 +1,46 @@ +{ + "javaProperties" : [], + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 345, + "deploymentPort": 65522, + "policyModelFileName": "src/test/resources/policymodels/SmallModel.json", + "engineParameters": { + "contextParameters": { + "parameterClassName": "org.onap.policy.apex.context.parameters.ContextParameters" + }, + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperExecutorParameters" + } + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "target/aaa.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventInputParameters": { + "MySuperDooperConsumer1": { + "carrierTechnologyParameters": { + "carrierTechnology": "SUPER_DOOPER", + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "SUPER_TOK_DEL", + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters" + } + } + } +}
\ No newline at end of file diff --git a/services/services-engine/src/test/resources/parameters/javaPropertiesOK.json b/services/services-engine/src/test/resources/parameters/javaPropertiesOK.json new file mode 100644 index 000000000..74b967f74 --- /dev/null +++ b/services/services-engine/src/test/resources/parameters/javaPropertiesOK.json @@ -0,0 +1,49 @@ +{ + "javaProperties" : [ + ["property0", "property0Value"], + ["property1", "property1Value"] + ], + "engineServiceParameters": { + "name": "MyApexEngine", + "version": "0.0.1", + "id": 45, + "instanceCount": 345, + "deploymentPort": 65522, + "policyModelFileName": "src/test/resources/policymodels/SmallModel.json", + "engineParameters": { + "contextParameters": { + "parameterClassName": "org.onap.policy.apex.context.parameters.ContextParameters" + }, + "executorParameters": { + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperExecutorParameters" + } + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "target/aaa.json" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventInputParameters": { + "MySuperDooperConsumer1": { + "carrierTechnologyParameters": { + "carrierTechnology": "SUPER_DOOPER", + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters" + }, + "eventProtocolParameters": { + "eventProtocol": "SUPER_TOK_DEL", + "parameterClassName": "org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters" + } + } + } +}
\ No newline at end of file |