diff options
31 files changed, 273 insertions, 218 deletions
diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java index 9cbd2050f..fd5fe131f 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,7 @@ import org.slf4j.ext.XLoggerFactory; * @author Liam Fallon */ public class ApexEngineImpl implements ApexEngine { + // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEngineImpl.class); @@ -68,6 +69,7 @@ public class ApexEngineImpl implements ApexEngine { // The state of this engine private AxEngineState state = AxEngineState.STOPPED; + private final Object stateLockObj = new Object(); // call back listeners private final Map<String, EnEventListener> eventListeners = new LinkedHashMap<>(); @@ -89,7 +91,7 @@ public class ApexEngineImpl implements ApexEngine { protected ApexEngineImpl(final AxArtifactKey key) { argumentNotNull(key, "AxArtifactKey may not be null"); - LOGGER.entry("ApexEngine()->" + key.getId() + "," + state); + LOGGER.entry("ApexEngine()->{}, {}", key.getId(), state); this.key = key; @@ -106,16 +108,18 @@ public class ApexEngineImpl implements ApexEngine { @Override public void updateModel(final AxPolicyModel apexModel, final boolean isSubsequentInstance) throws ApexException { if (apexModel != null) { - LOGGER.entry("updateModel()->" + key.getId() + ", apexPolicyModel=" + apexModel.getKey().getId()); + LOGGER.entry("updateModel()->{}, apexPolicyModel {}", key.getId(), apexModel.getKey().getId()); } else { - LOGGER.warn(UPDATE_MODEL + key.getId() + ", Apex model not set"); throw new ApexException(UPDATE_MODEL + key.getId() + ", Apex model is not defined, it has a null value"); } // The engine must be stopped in order to do a model update - if (!state.equals(AxEngineState.STOPPED)) { - throw new ApexException(UPDATE_MODEL + key.getId() - + ", cannot update model, engine should be stopped but is in state " + state); + synchronized (stateLockObj) { + if (!state.equals(AxEngineState.STOPPED)) { + throw new ApexException( + UPDATE_MODEL + key.getId() + ", cannot update model, engine should be stopped but is in state " + + state); + } } // Create new internal context or update the existing one @@ -128,10 +132,8 @@ public class ApexEngineImpl implements ApexEngine { internalContext.update(apexModel, isSubsequentInstance); } } catch (final ContextException e) { - LOGGER.warn(UPDATE_MODEL + key.getId() + ", error setting the context for engine \"" + key.getId() + "\"", - e); - throw new ApexException(UPDATE_MODEL + key.getId() + ", error setting the context for engine \"" - + key.getId() + "\"", e); + throw new ApexException( + UPDATE_MODEL + key.getId() + ", error setting the context for engine \"" + key.getId() + "\"", e); } // Set up the state machines @@ -140,10 +142,8 @@ public class ApexEngineImpl implements ApexEngine { // always set up as new stateMachineHandler = new StateMachineHandler(internalContext); } catch (final StateMachineException e) { - LOGGER.warn(UPDATE_MODEL + key.getId() + ", error setting up the engine state machines \"" + key.getId() - + "\"", e); - throw new ApexException(UPDATE_MODEL + key.getId() + ", error setting up the engine state machines \"" - + key.getId() + "\"", e); + throw new ApexException( + UPDATE_MODEL + key.getId() + ", error setting up the engine state machines \"" + key.getId() + "\"", e); } LOGGER.exit(UPDATE_MODEL + key.getId()); @@ -154,20 +154,18 @@ public class ApexEngineImpl implements ApexEngine { */ @Override public void start() throws ApexException { - LOGGER.entry("start()" + key); - - if (state != AxEngineState.STOPPED) { - String message = START + key.getId() + "," + state + ", cannot start engine, engine not in state STOPPED"; - LOGGER.warn(message); - throw new ApexException(message); + LOGGER.entry("start() {}", key); + synchronized (stateLockObj) { + if (state != AxEngineState.STOPPED) { + String message = + START + key.getId() + "," + state + ", cannot start engine, engine not in state STOPPED"; + throw new ApexException(message); + } } if (stateMachineHandler == null || internalContext == null) { - String message = START + key.getId() + "," + state - + ", cannot start engine, engine has not been initialized, its model is not loaded"; - LOGGER.warn(message); throw new ApexException(START + key.getId() + "," + state - + ", cannot start engine, engine has not been initialized, its model is not loaded"); + + ", cannot start engine, engine has not been initialized, its model is not loaded"); } // Set up the state machines @@ -176,9 +174,8 @@ public class ApexEngineImpl implements ApexEngine { stateMachineHandler.start(); engineStats.engineStart(); } catch (final StateMachineException e) { - String message = UPDATE_MODEL + key.getId() + ", error starting the engine state machines \"" + key.getId() - + "\""; - LOGGER.warn(message, e); + String message = + UPDATE_MODEL + key.getId() + ", error starting the engine state machines \"" + key.getId() + "\""; throw new ApexException(message, e); } @@ -193,20 +190,21 @@ public class ApexEngineImpl implements ApexEngine { */ @Override public void stop() throws ApexException { - LOGGER.entry("stop()->" + key); + LOGGER.entry("stop()-> {}", key); // Check if the engine is already stopped - if (state == AxEngineState.STOPPED) { - throw new ApexException( - STOP + key.getId() + "," + state + ", cannot stop engine, engine is already stopped"); + synchronized (stateLockObj) { + if (state == AxEngineState.STOPPED) { + throw new ApexException( + STOP + key.getId() + "," + state + ", cannot stop engine, engine is already stopped"); + } } - // Stop the engine if it is in state READY, if it is in state EXECUTING, wait for execution to finish - for (int increment = ApexEngineConstants.STOP_EXECUTION_WAIT_TIMEOUT; - increment > 0; increment -= ApexEngineConstants.APEX_ENGINE_STOP_EXECUTION_WAIT_INCREMENT) { + for (int increment = ApexEngineConstants.STOP_EXECUTION_WAIT_TIMEOUT; increment > 0; + increment -= ApexEngineConstants.APEX_ENGINE_STOP_EXECUTION_WAIT_INCREMENT) { ThreadUtilities.sleep(ApexEngineConstants.APEX_ENGINE_STOP_EXECUTION_WAIT_INCREMENT); - synchronized (state) { + synchronized (stateLockObj) { switch (state) { // Engine is OK to stop or has been stopped on return of an event case READY: @@ -227,14 +225,14 @@ public class ApexEngineImpl implements ApexEngine { break; default: - throw new ApexException(STOP + key.getId() + "," + state - + ", cannot stop engine, engine is in an undefined state"); + throw new ApexException( + STOP + key.getId() + "," + state + ", cannot stop engine, engine is in an undefined state"); } } } // Force the engine to STOPPED state - synchronized (state) { + synchronized (stateLockObj) { state = AxEngineState.STOPPED; } @@ -246,10 +244,12 @@ public class ApexEngineImpl implements ApexEngine { */ @Override public void clear() throws ApexException { - LOGGER.entry("clear()->" + key); - if (state != AxEngineState.STOPPED) { - throw new ApexException("clear" + "()<-" + key.getId() + "," + state - + ", cannot clear engine, engine is not stopped"); + LOGGER.entry("clear()-> {}", key); + synchronized (stateLockObj) { + if (state != AxEngineState.STOPPED) { + throw new ApexException( + "clear" + "()<-" + key.getId() + "," + state + ", cannot clear engine, engine is not stopped"); + } } // Clear everything @@ -267,16 +267,18 @@ public class ApexEngineImpl implements ApexEngine { */ @Override public EnEvent createEvent(final AxArtifactKey eventKey) { - if (state != AxEngineState.READY && state != AxEngineState.EXECUTING) { - LOGGER.warn("createEvent()<-{},{}, cannot create event, engine not in state READY", key.getId(), state); - return null; + synchronized (stateLockObj) { + if (state != AxEngineState.READY && state != AxEngineState.EXECUTING) { + LOGGER.warn("createEvent()<-{},{}, cannot create event, engine not in state READY", key.getId(), state); + return null; + } } try { // Create an event using the internal context return new EnEvent(eventKey); } catch (final Exception e) { - LOGGER.warn("createEvent()<-" + key.getId() + "," + state + ", error on event creation", e); + LOGGER.warn("createEvent()<-{},{}, error on event creation: ", key.getId(), state, e); return null; } } @@ -292,7 +294,7 @@ public class ApexEngineImpl implements ApexEngine { return ret; } - synchronized (state) { + synchronized (stateLockObj) { if (state != AxEngineState.READY) { LOGGER.warn("handleEvent()<-{},{}, cannot run engine, engine not in state READY", key.getId(), state); return ret; @@ -323,17 +325,17 @@ public class ApexEngineImpl implements ApexEngine { synchronized (eventListeners) { if (eventListeners.isEmpty()) { LOGGER.debug("handleEvent()<-{},{}, There is no listener registered to recieve outgoing event: {}", - key.getId(), state, outgoingEvent); + key.getId(), state, outgoingEvent); } for (final EnEventListener axEventListener : eventListeners.values()) { axEventListener.onEnEvent(outgoingEvent); } } } catch (final ApexException e) { - LOGGER.warn("handleEvent()<-" + key.getId() + "," + state + ", outgoing event publishing error: ", e); + LOGGER.warn("handleEvent()<-{},{}, outgoing event publishing error: ", key.getId(), state, e); ret = false; } - synchronized (state) { + synchronized (stateLockObj) { // Only go to READY if we are still in state EXECUTING, we go to state STOPPED if we were STOPPING if (state == AxEngineState.EXECUTING) { state = AxEngineState.READY; @@ -351,13 +353,11 @@ public class ApexEngineImpl implements ApexEngine { public void addEventListener(final String listenerName, final EnEventListener listener) { if (listenerName == null) { String message = "addEventListener()<-" + key.getId() + "," + state + ", listenerName is null"; - LOGGER.warn(message); throw new ApexRuntimeException(message); } if (listener == null) { String message = "addEventListener()<-" + key.getId() + "," + state + ", listener is null"; - LOGGER.warn(message); throw new ApexRuntimeException(message); } @@ -371,7 +371,6 @@ public class ApexEngineImpl implements ApexEngine { public void removeEventListener(final String listenerName) { if (listenerName == null) { String message = "removeEventListener()<-" + key.getId() + "," + state + ", listenerName is null"; - LOGGER.warn(message); throw new ApexRuntimeException(message); } @@ -418,7 +417,7 @@ public class ApexEngineImpl implements ApexEngine { } for (final Entry<AxArtifactKey, ContextAlbum> contextAlbumEntry : internalContext.getContextAlbums() - .entrySet()) { + .entrySet()) { currentContext.put(contextAlbumEntry.getKey(), contextAlbumEntry.getValue()); } @@ -437,7 +436,7 @@ public class ApexEngineImpl implements ApexEngine { /** * Create an exception event from the incoming event including the exception information on the event. * - * @param incomingEvent The incoming event that caused the exception + * @param incomingEvent The incoming event that caused the exception * @param eventException The exception that was thrown * @return the exception event */ diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java index 08046c924..a9c57f385 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +23,7 @@ package org.onap.policy.apex.core.infrastructure.xml; import java.io.InputStream; +import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; @@ -39,6 +41,7 @@ import org.w3c.dom.Document; * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) */ public class XPathReader { + // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(XPathReader.class); @@ -73,18 +76,17 @@ public class XPathReader { private void init() { try { LOGGER.info("Initializing XPath reader"); + DocumentBuilderFactory df = DocumentBuilderFactory.newInstance(); + df.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); // Check if this is operating on a file if (xmlFileName != null) { - xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlFileName); - } - // Check if this is operating on a stream - else if (xmlStream != null) { - xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlStream); - - } - // We have an error - else { + xmlDocument = df.newDocumentBuilder().parse(xmlFileName); + } else if (xmlStream != null) { + // Check if this is operating on a stream + xmlDocument = df.newDocumentBuilder().parse(xmlStream); + } else { + // We have an error LOGGER.error("XPath reader not initialized with either a file or a stream"); return; } diff --git a/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java b/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java index e4186f131..edaff6b52 100644 --- a/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java +++ b/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Huawei. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,9 @@ import java.nio.charset.StandardCharsets; import java.util.Base64; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; +import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; @@ -56,6 +58,7 @@ import org.xml.sax.InputSource; * The Class WebClient act as rest client for BBS usecase. */ public class WebClient { + private static final XLogger LOGGER = XLoggerFactory.getXLogger(WebClient.class); // Duplicated string constants @@ -64,20 +67,20 @@ public class WebClient { /** * Send simple https rest request. * - * @param requestUrl url + * @param requestUrl url * @param requestMethod method eg POST/GET/PUT - * @param outputStr Data - * @param username Simple Username - * @param pass Simple password - * @param contentType http content type + * @param outputStr Data + * @param username Simple Username + * @param pass Simple password + * @param contentType http content type * @return String response message */ public String httpRequest(String requestUrl, String requestMethod, String outputStr, String username, String pass, - String contentType) { + String contentType) { String result = ""; StringBuilder builder = new StringBuilder(); try { - LOGGER.info("httpsRequest starts " + requestUrl + " method " + requestMethod); + LOGGER.info("httpsRequest starts {} method {}", requestUrl, requestMethod); disableCertificateValidation(); URL url = new URL(requestUrl); @@ -109,8 +112,8 @@ public class WebClient { outputStream.close(); } - try (BufferedReader bufferedReader = - new BufferedReader(new InputStreamReader(httpUrlConn.getInputStream(), StandardCharsets.UTF_8))) { + try (BufferedReader bufferedReader = new BufferedReader( + new InputStreamReader(httpUrlConn.getInputStream(), StandardCharsets.UTF_8))) { String str; while ((str = bufferedReader.readLine()) != null) { builder.append(str); @@ -118,9 +121,9 @@ public class WebClient { httpUrlConn.disconnect(); result = builder.toString(); } - LOGGER.info("httpsRequest success "); + LOGGER.info("httpsRequest success"); } catch (Exception ce) { - LOGGER.error("httpsRequest Exception " + ce); + LOGGER.error("httpsRequest Exception", ce); } return result; } @@ -128,20 +131,22 @@ public class WebClient { /** * Pretty print xml string. * - * @param xml Input string + * @param xml Input string * @param indent Indent number * @return Indented xml string */ public String toPrettyString(String xml, int indent) { try { try (ByteArrayInputStream br = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8))) { - Document document = - DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(br)); + + DocumentBuilderFactory df = DocumentBuilderFactory.newInstance(); + df.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + Document document = df.newDocumentBuilder().parse(new InputSource(br)); document.normalize(); XPath path = XPathFactory.newInstance().newXPath(); - NodeList nodeList = - (NodeList) path.evaluate("//text()[normalize-space()='']", document, XPathConstants.NODESET); + NodeList nodeList = (NodeList) path + .evaluate("//text()[normalize-space()='']", document, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); ++i) { Node node = nodeList.item(i); @@ -160,7 +165,7 @@ public class WebClient { return stringWriter.toString(); } } catch (Exception e) { - throw new ApexRuntimeException("pretiffication failed", e); + throw new ApexRuntimeException("Convert to Pretty string failed", e); } } @@ -171,14 +176,19 @@ public class WebClient { try { TrustManager[] trustAllCerts = NetworkUtil.getAlwaysTrustingManager(); - SSLContext sc = SSLContext.getInstance("SSL"); + SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - - HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true); - + HttpsURLConnection.setDefaultHostnameVerifier((String hostname, SSLSession session) -> { + if (!hostname.equalsIgnoreCase(session.getPeerHost())) { + LOGGER.warn("Warning: URL host \"{}\" is different to SSLSession host \"{}\".", hostname, + session.getPeerHost()); + return false; + } + return true; + }); } catch (Exception e) { - LOGGER.error("certificate validation Exception " + e); + LOGGER.error("certificate validation Exception", e); } } diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AAILookupTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AAILookupTask.js index fcb39052d..7d0178261 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AAILookupTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AAILookupTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,17 +29,18 @@ executor.logger.info("Executing A&AI Lookup"); executor.logger.info(vcpeClosedLoopStatus); var aaiInfo = vcpeClosedLoopStatus.get("AAI"); +var returnValue = true; if (aaiInfo.get("vserverName") == null) { executor.message = "the field vserver.vserver-name must exist in the onset control loop event"; executor.logger.warn(executor.message); - var returnValue = executor.isFalse; + returnValue = false; } else if (aaiInfo.get("genericVnfVnfId") == null && aaiInfo.get("genericVnfVnfName") == null) { executor.message = "either the field generic-vnf.vnf-id or generic-vnf.vnf-name must exist" + " in the onset control loop event"; executor.logger.warn(executor.message); - var returnValue = executor.isFalse; + returnValue = false; } else { var restManager = new org.onap.policy.rest.RestManager; @@ -46,7 +48,7 @@ else { // We need to instantiate the type in order to trigger the static JAXB handling // in the AaiCqResponse class - var aaiCqResponseType = Java.type("org.onap.policy.aai.AaiCqResponse"); + var aaiCqResponseType = org.onap.policy.aai.AaiCqResponse; var aaiResponse = aaiManager.getCustomQueryResponse( "http://localhost:54321/OnapVCpeSim/sim", @@ -80,6 +82,6 @@ else { executor.outFields.put("vnfID", executor.inFields.get("vnfID")); executor.logger.info(executor.outFields); - - var returnValue = executor.isTrue; } + +returnValue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFRequestTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFRequestTask.js index dd69dcb1d..9ee928fca 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFRequestTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFRequestTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -64,4 +65,4 @@ executor.outFields.put("APPCLCMRequestEvent", appcRequest); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFResponseTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFResponseTask.js index 75ab6a3af..ac22abbff 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFResponseTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFResponseTask.js @@ -1,26 +1,27 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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. - * + * * APPC LCM Response code: 100 ACCEPTED * 200 ERROR UNEXPECTED ERROR means failure * 312 REJECTED DUPLICATE REQUEST - * 400 SUCCESS + * 400 SUCCESS * * Note: Sometimes the corelationId has a -1 at the tail, need to get rid of it when present. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -38,7 +39,7 @@ executor.logger.info("Size of RequestIDVNFIDAlbum = " + executor.getContextAlbum("RequestIDVNFIDAlbum").size()); executor.logger.info("vnfID = " + vnfID); -var returnValue = executor.isTrue; +var returnValue = true; if (vnfID != null) { var vcpeClosedLoopStatus = executor.getContextAlbum( @@ -82,7 +83,9 @@ if (vnfID != null) { } else { executor.message = "VNF ID not found in context album for request ID " + requestIDString; - returnValue = executor.isFalse; + returnValue = false } executor.logger.info(executor.outFields); + +returnValue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AbatedTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AbatedTask.js index f37b6f1b5..e19b8b1f4 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AbatedTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AbatedTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -21,7 +22,7 @@ executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var vcpeClosedLoopStatus = null; +var vcpeClosedLoopStatus = null; if( executor.inFields.get("vnfID") == null) { executor.logger.info("AbatedTask: vnfID is null"); var vnfName = executor.inFields.get("vnfName"); @@ -38,4 +39,4 @@ vcpeClosedLoopStatus.put("message", "situation has been abated"); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/ControlLoopLogTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/ControlLoopLogTask.js index a5a692cbc..3e2771a74 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/ControlLoopLogTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/ControlLoopLogTask.js @@ -63,6 +63,7 @@ clNotification.getAai().put("generic-vnf.orchestration-status", aaiInfo.get(" clNotification.getAai().put("generic-vnf.vnf-type", aaiInfo.get("genericVnfVnfType")); clNotification.getAai().put("generic-vnf.in-maint", aaiInfo.get("genericVnfInMaint")); clNotification.getAai().put("generic-vnf.service-id", aaiInfo.get("genericVnfServiceId")); + if(vnfID != null) { clNotification.getAai().put("generic-vnf.vnf-id", aaiInfo.get("genericVnfVnfId")); } @@ -70,4 +71,4 @@ executor.outFields.put("VirtualControlLoopNotification", clNotification); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/DeniedTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/DeniedTask.js index 353c21ef6..73b989f5e 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/DeniedTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/DeniedTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -29,4 +30,4 @@ vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis( executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GetVCPEStateTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GetVCPEStateTask.js index f4f6d908d..9882a434f 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GetVCPEStateTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GetVCPEStateTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,9 +26,9 @@ executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var clEventType = Java.type("org.onap.policy.controlloop.VirtualControlLoopEvent"); -var longType = Java.type("java.lang.Long"); -var uuidType = Java.type("java.util.UUID"); +var clEventType = org.onap.policy.controlloop.VirtualControlLoopEvent; +var longType = java.lang.Long; +var uuidType = java.util.UUID; var clEvent = executor.inFields.get("VirtualControlLoopEvent"); @@ -146,4 +147,4 @@ else { executor.logger.info(executor.outFields); } -returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardRequestTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardRequestTask.js index d247f8a65..66c6213e1 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardRequestTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardRequestTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -41,4 +42,4 @@ executor.getContextAlbum("ControlLoopExecutionIDAlbum").put(executor.executionId executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardResponseTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardResponseTask.js index 2a9100b7f..55fee56dd 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardResponseTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardResponseTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -29,17 +30,18 @@ var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum") executor.logger.info(vcpeClosedLoopStatus); var guardResult = executor.inFields.get("decision"); +var returnValue = true; -if (guardResult === "PERMIT") { +if (guardResult == "PERMIT") { vcpeClosedLoopStatus.put("notification", "OPERATION: GUARD_PERMIT"); -} else if (guardResult === "DENY") { +} else if (guardResult == "DENY") { vcpeClosedLoopStatus.put("notification", "OPERATION: GUARD_DENY"); } else { executor.message = "guard result must be either \"PERMIT\" or \"DENY\""; - returnValue = executor.FALSE; + returnValue = false; } -var uuidType = Java.type("java.util.UUID"); +var uuidType = java.util.UUID; var requestID = uuidType.fromString(vcpeClosedLoopStatus.get("requestID")); executor.outFields.put("requestID", requestID); @@ -47,4 +49,5 @@ executor.outFields.put("vnfID", vnfID); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; + +returnValue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/NoAAILookupTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/NoAAILookupTask.js index ebc0e6387..7b3d5c478 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/NoAAILookupTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/NoAAILookupTask.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -23,4 +24,4 @@ executor.logger.info(executor.inFields); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/OnsetOrAbatedStateTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/OnsetOrAbatedStateTSL.js index c8a3bfba8..4f6c32120 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/OnsetOrAbatedStateTSL.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/OnsetOrAbatedStateTSL.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -21,7 +22,7 @@ executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var returnValue = executor.isTrue; +var returnValue = true; var status = null; if( executor.inFields.get("vnfID") == null) { @@ -36,16 +37,16 @@ if( executor.inFields.get("vnfID") == null) { status = vcpeClosedLoopStatus.get("closedLoopEventStatus").toString(); } -var returnValue = executor.isTrue; - -if (status === "ONSET") { +if (status == "ONSET") { executor.subject.getTaskKey("GuardRequestTask").copyTo(executor.selectedTask); -} else if (status === "ABATED") { +} else if (status == "ABATED") { executor.subject.getTaskKey("AbatedTask").copyTo(executor.selectedTask); onsetFlag = executor.isFalse; } else { executor.message = "closedLoopEventStatus is \"" + status + "\", it must be either \"ONSET\" or \"ABATED\""; - returnValue = executor.isFalse; + returnValue = false; } executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask); + +returnValue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/RestartAPPCRequestPolicyPermitOrDenyTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/RestartAPPCRequestPolicyPermitOrDenyTSL.js index a1bac6546..7ab346f53 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/RestartAPPCRequestPolicyPermitOrDenyTSL.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/RestartAPPCRequestPolicyPermitOrDenyTSL.js @@ -1,19 +1,20 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -26,7 +27,7 @@ var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum") var guardResult = vcpeClosedLoopStatus.get("notification"); -if (guardResult === "OPERATION: GUARD_PERMIT") { +if (guardResult == "OPERATION: GUARD_PERMIT") { executor.subject.getTaskKey("APPCRestartVNFRequestTask").copyTo(executor.selectedTask); } else { executor.subject.getTaskKey("DeniedTask").copyTo(executor.selectedTask); @@ -34,4 +35,4 @@ if (guardResult === "OPERATION: GUARD_PERMIT") { executor.logger.info("RestartAPPCRequestPolicyPermitOrDenyTSL State Selected Task:" + executor.selectedTask); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckServiceIdTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckServiceIdTask.js index 88bf72671..6d5df84c3 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckServiceIdTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckServiceIdTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +29,8 @@ var blackFlag = executor.getContextAlbum("ServiceIdWhiteBlackListAlbum").get(ser executor.logger.info("vnfId=" + vnfId + ", serviceId=" + serviceId + ", blackFlag=" + blackFlag); -if (blackFlag != null && blackFlag === true) { - vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); +if (blackFlag != null && blackFlag == true) { + vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now())); vcpeClosedLoopStatus.put("notification", "BLACKLIST"); var message = vcpeClosedLoopStatus.get("message"); @@ -43,4 +44,5 @@ if (blackFlag != null && blackFlag === true) { executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; + diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVNFIdTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVNFIdTask.js index d4e3f30dc..7bca8659b 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVNFIdTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVNFIdTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +27,9 @@ var blackFlag = executor.getContextAlbum("VnfIdWhiteBlackListAlbum").get(vnfId); executor.logger.info("vnfId=" + vnfId + ", blackFlag=" + blackFlag); -if (blackFlag != null && blackFlag === true) { +if (blackFlag != null && blackFlag == true) { var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId); - vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now())); vcpeClosedLoopStatus.put("notification", "BLACKLIST"); var message = vcpeClosedLoopStatus.get("message"); @@ -42,4 +43,4 @@ if (blackFlag != null && blackFlag === true) { executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVServerIdTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVServerIdTask.js index 785d93f25..843011024 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVServerIdTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVServerIdTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +29,8 @@ var blackFlag = executor.getContextAlbum("VServerIdWhiteBlackListAlbum").get(vSe executor.logger.info("vnfId=" + vnfId + ", vServerId=" + vServerId + ", blackFlag=" + blackFlag); -if (blackFlag != null && blackFlag === true) { - vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); +if (blackFlag != null && blackFlag == true) { + vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now())); vcpeClosedLoopStatus.put("notification", "BLACKLIST"); var message = vcpeClosedLoopStatus.get("message"); @@ -43,4 +44,5 @@ if (blackFlag != null && blackFlag === true) { executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; + diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ConfigureBlackWhiteListTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ConfigureBlackWhiteListTask.js index 2d41e5f90..b16404292 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ConfigureBlackWhiteListTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ConfigureBlackWhiteListTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,21 +30,24 @@ var targetType = executor.inFields.get("targetType"); var target = executor.inFields.get("target"); var black = executor.inFields.get("black"); -var returnValue = executor.isTrue; +var returnValue = true; -if (targetType === "VNF") { +if (targetType == "VNF") { executor.getContextAlbum("VnfIdWhiteBlackListAlbum").put(target, black); executor.logger.info("added VNF ID \"" + target + "\" with black flag \"" + black + "\" to VNF ID list"); } -else if (targetType === "Service") { +else if (targetType == "Service") { executor.getContextAlbum("ServiceIdWhiteBlackListAlbum").put(target, black); executor.logger.info("added Service ID \"" + target + "\" with black flag \"" + black + "\" to Service ID list"); } -else if (targetType === "VServer") { +else if (targetType == "VServer") { executor.getContextAlbum("VServerIdWhiteBlackListAlbum").put(target, black); executor.logger.info("added VServer ID \"" + target + "\" with black flag \"" + black + "\" to VServer ID list"); } else { executor.logger.warn("unknown target type \"" + targetType + "\" specified"); - returnValue = executor.isFalse; + returnValue = false; } + +returnValue; + diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControlLoopLogTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControlLoopLogTask.js index ca2166c75..615901c4b 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControlLoopLogTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControlLoopLogTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -72,4 +73,4 @@ executor.outFields.put("VirtualControlLoopNotification", clNotification); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerRequestTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerRequestTask.js index b6d4cae38..457b80193 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerRequestTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerRequestTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +45,7 @@ controllerRequestBodyInput.put("action", "Restart"); controllerRequestBodyInput.put("action_DasH_identifiers", new java.util.HashMap()); controllerRequestBodyInput.get("action_DasH_identifiers").put("vnf-id", executor.inFields.get("vnfID").toString()); -controllerRequestBodyInputCommonHeader.put("timestamp", java.lang.System.currentTimeMillis()); +controllerRequestBodyInputCommonHeader.put("timestamp", java.lang.Long.valueOf(Date.now())); controllerRequestBodyInputCommonHeader.put("api_DasH_ver", "2.00"); controllerRequestBodyInputCommonHeader.put("originator_DasH_id", executor.inFields.get("requestID").toString()); controllerRequestBodyInputCommonHeader.put("request_DasH_id", executor.inFields.get("requestID").toString()); @@ -62,10 +63,11 @@ executor.getContextAlbum("RequestIDVNFIDAlbum").put(executor.inFields.get("reque executor.inFields.get("vnfID")); vcpeClosedLoopStatus.put("notification", "OPERATION"); -vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); +vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now())); executor.outFields.put("ControllerRequest", controllerRequest); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; + diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerResponseTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerResponseTask.js index 5a8703780..8cb3e4e41 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerResponseTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerResponseTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,13 +36,13 @@ executor.logger.info("requestIDString =\"" + requestIDString + "\""); var vnfID = executor.getContextAlbum("RequestIDVNFIDAlbum").get(requestIDString); executor.logger.info("vnfID = " + vnfID); -var returnValue = executor.isTrue; +var returnValue = true if (vnfID != null) { var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID.toString()); var requestId = java.util.UUID.fromString(vcpeClosedLoopStatus.get("requestID")); - vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now())); var returnedCode = controllerResponse.get("body").get("output").get("status").get("code"); var responseStatus = null; @@ -66,11 +67,11 @@ if (vnfID != null) { executor.logger.info("Got from APPC code: " + responseStatus); - if (responseStatus === "SUCCESS") { + if (responseStatus == "SUCCESS") { vcpeClosedLoopStatus.put("notification", "OPERATION_SUCCESS"); vcpeClosedLoopStatus.put("message", "vCPE restarted"); executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString); - } else if (responseStatus === "ACCEPTED" || responseStatus === "REJECT") { + } else if (responseStatus == "ACCEPTED" || responseStatus == "REJECT") { executor.logger.info("Got ACCEPTED 100 or REJECT 312, keep the context, wait for next response. Code is: " + responseStatus); } else { @@ -84,7 +85,9 @@ if (vnfID != null) { executor.outFields.put("vnfID", vnfID); } else { executor.message = "VNF ID not found in context album for request ID " + requestIDString; - returnValue = executor.isFalse; + returnValue = false; } executor.logger.info(executor.outFields); + +returnValue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoControllerRequestActionTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoControllerRequestActionTask.js index c24e76523..998f6a20a 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoControllerRequestActionTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoControllerRequestActionTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,4 +25,4 @@ executor.logger.info(executor.inFields); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoLogActionTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoLogActionTask.js index 003942e22..77155645d 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoLogActionTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoLogActionTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,4 +26,4 @@ executor.logger.info(executor.inFields); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ExecuteActionsPolicyActionStateTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ExecuteActionsPolicyActionStateTSL.js index a8bb40c80..a74f39789 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ExecuteActionsPolicyActionStateTSL.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ExecuteActionsPolicyActionStateTSL.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,13 +22,14 @@ executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var returnValue = executor.isTrue; var status = null; -if (executor.inFields.get("action") === "ControllerRequestAction") { +if (executor.inFields.get("action") == "ControllerRequestAction") { executor.subject.getTaskKey("DoControllerRequestActionTask").copyTo(executor.selectedTask); } else { executor.subject.getTaskKey("DoLogActionTask").copyTo(executor.selectedTask); } executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask); + +true; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js index 1567608bb..13129f224 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +26,8 @@ executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var utf8Type = Java.type("org.apache.avro.util.Utf8"); -var uuidType = Java.type("java.util.UUID"); +var utf8Type = org.apache.avro.util.Utf8; +var uuidType = java.util.UUID; var clEvent = executor.inFields.get("VirtualControlLoopEvent"); @@ -61,7 +62,7 @@ if (clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")) != vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel"); vcpeClosedLoopStatus.put("policyVersion", "0.0.1"); vcpeClosedLoopStatus.put("notification", "ACTIVE"); - vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now())); vcpeClosedLoopStatus.put("message", ""); var aaiInfo = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewSubInstance( @@ -130,7 +131,7 @@ if (clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")) != vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel"); vcpeClosedLoopStatus.put("policyVersion", "0.0.1"); vcpeClosedLoopStatus.put("notification", "ACTIVE"); - vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now())); vcpeClosedLoopStatus.put("message", ""); var aaiInfo = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewSubInstance( @@ -154,4 +155,5 @@ if (clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")) != executor.logger.info(executor.outFields); } -var returnValue = executor.isTrue; +true; + diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/InitiateActionsTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/InitiateActionsTask.js index 0303bc9a4..d5c3999b6 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/InitiateActionsTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/InitiateActionsTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +27,7 @@ var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").ge var eventList = executor.subject.getOutFieldSchemaHelper("ActionEventList").createNewInstance(); -var eventType = Java.type("org.onap.policy.apex.service.engine.event.ApexEvent"); +var eventType = org.onap.policy.apex.service.engine.event.ApexEvent; var controllerRequestActionEvent = new eventType("ActionEvent", "0.0.1", "org.onap.policy.apex.onap.vcpe", "APEX", "APEX"); @@ -51,4 +52,5 @@ executor.outFields.put("ActionEventList", eventList); executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; + diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ReceiveEventPolicyExecuteOrLogStateTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ReceiveEventPolicyExecuteOrLogStateTSL.js index 46a65add3..a291f6afb 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ReceiveEventPolicyExecuteOrLogStateTSL.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ReceiveEventPolicyExecuteOrLogStateTSL.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +22,7 @@ executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -var returnValue = executor.isTrue; +var returnValue = true; if( executor.inFields.get("vnfID") == null) { executor.logger.info("ControlLoopStatusAlbum: vnfID is null"); @@ -36,20 +37,20 @@ if( executor.inFields.get("vnfID") == null) { var status = vcpeClosedLoopStatus.get("closedLoopEventStatus").toString(); var notification = vcpeClosedLoopStatus.get("notification"); -var returnValue = executor.isTrue; - -if (notification != null && notification === "BLACKLIST") { +if (notification != null && notification == "BLACKLIST") { executor.subject.getTaskKey("StopAndLogTask").copyTo(executor.selectedTask); } else { - if (status === "ONSET") { + if (status == "ONSET") { executor.subject.getTaskKey("InitiateActionsTask").copyTo(executor.selectedTask); - } else if (status === "ABATED") { + } else if (status == "ABATED") { executor.subject.getTaskKey("StopAndLogTask").copyTo(executor.selectedTask); } else { executor.message = "closedLoopEventStatus is \"" + status + "\", it must be either \"ONSET\" or \"ABATED\""; - returnValue = executor.isFalse; + returnValue = false; } } executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask); + +returnValue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/StopAndLogTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/StopAndLogTask.js index af57bf1f7..2b062fd8e 100644 --- a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/StopAndLogTask.js +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/StopAndLogTask.js @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,10 +33,10 @@ if (executor.inFields.get("vnfID") == null) { .get(executor.inFields.get("vnfID").toString()); } -vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); +vcpeClosedLoopStatus.put("notificationTime", java.lang.Long.valueOf(Date.now())); var message = vcpeClosedLoopStatus.get("message"); -if (message == null || message === "") { +if (message == null || message == "") { vcpeClosedLoopStatus.put("message", "situation has been abated"); } else { @@ -44,4 +45,4 @@ else { executor.logger.info(executor.outFields); -var returnValue = executor.isTrue; +true; diff --git a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java index 35c458eaa..8d6c01e4e 100644 --- a/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java +++ b/model/basic-model/src/main/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriter.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import java.io.Writer; import java.util.Set; import java.util.TreeSet; +import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -53,10 +54,11 @@ import org.w3c.dom.Document; /** * This class writes an Apex concept to an XML file or JSON file from a Java Apex Concept. * - * @author John Keeney (john.keeney@ericsson.com) * @param <C> the type of Apex concept to write, must be a sub class of {@link AxConcept} + * @author John Keeney (john.keeney@ericsson.com) */ public class ApexModelWriter<C extends AxConcept> { + private static final String CONCEPT_MAY_NOT_BE_NULL = "concept may not be null"; private static final String CONCEPT_WRITER_MAY_NOT_BE_NULL = "concept writer may not be null"; private static final String CONCEPT_STREAM_MAY_NOT_BE_NULL = "concept stream may not be null"; @@ -87,15 +89,13 @@ public class ApexModelWriter<C extends AxConcept> { System.setProperty("javax.xml.bind.context.factory", "org.eclipse.persistence.jaxb.JAXBContextFactory"); try { - final JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[] - { rootConceptClass }, null); + final JAXBContext jaxbContext = JAXBContextFactory.createContext(new Class[]{rootConceptClass}, null); // Set up the unmarshaller to carry out validation marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler()); } catch (final JAXBException e) { - LOGGER.error("JAXB marshaller creation exception", e); throw new ApexModelException("JAXB marshaller creation exception", e); } } @@ -133,14 +133,12 @@ public class ApexModelWriter<C extends AxConcept> { marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON); marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, true); } catch (final Exception e) { - LOGGER.warn("JAXB error setting marshaller for JSON output", e); throw new ApexModelException("JAXB error setting marshaller for JSON output", e); } } else { try { marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML); } catch (final Exception e) { - LOGGER.warn("JAXB error setting marshaller for XML output", e); throw new ApexModelException("JAXB error setting marshaller for XML output", e); } } @@ -149,7 +147,7 @@ public class ApexModelWriter<C extends AxConcept> { /** * This method validates the Apex concept then writes it into a stream. * - * @param concept the concept to write + * @param concept the concept to write * @param apexConceptStream the stream to write to * @throws ApexModelException on validation or writing exceptions */ @@ -163,7 +161,7 @@ public class ApexModelWriter<C extends AxConcept> { /** * This method validates the Apex concept then writes it into a writer. * - * @param concept the concept to write + * @param concept the concept to write * @param apexConceptWriter the writer to write to * @throws ApexModelException on validation or writing exceptions */ @@ -176,9 +174,9 @@ public class ApexModelWriter<C extends AxConcept> { // Validate the concept first final AxValidationResult validationResult = concept.validate(new AxValidationResult()); if (!validationResult.isValid()) { - String message = "Apex concept xml (" + concept.getKey().getId() + ") validation failed: " - + validationResult.toString(); - LOGGER.warn(message); + String message = + "Apex concept xml (" + concept.getKey().getId() + ") validation failed: " + validationResult + .toString(); throw new ApexModelException(message); } } @@ -193,7 +191,7 @@ public class ApexModelWriter<C extends AxConcept> { /** * This method writes the Apex concept into a writer in XML format. * - * @param concept the concept to write + * @param concept the concept to write * @param apexConceptWriter the writer to write to * @throws ApexModelException on validation or writing exceptions */ @@ -206,6 +204,7 @@ public class ApexModelWriter<C extends AxConcept> { // Write the concept into a DOM document, then transform to add CDATA fields and pretty // print, then write out the result final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); + docBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); final Document document = docBuilderFactory.newDocumentBuilder().newDocument(); // Marshal the concept into the empty document. @@ -215,10 +214,9 @@ public class ApexModelWriter<C extends AxConcept> { // Convert the cDataFieldSet into a space delimited string domTransformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, - cdataFieldSet.toString().replaceAll("[\\[\\]\\,]", " ")); + cdataFieldSet.toString().replaceAll("[\\[\\]\\,]", " ")); domTransformer.transform(new DOMSource(document), new StreamResult(apexConceptWriter)); } catch (JAXBException | TransformerException | ParserConfigurationException e) { - LOGGER.warn("Unable to marshal Apex concept to XML", e); throw new ApexModelException("Unable to marshal Apex concept to XML", e); } LOGGER.debug("wrote Apex concept XML"); @@ -243,7 +241,7 @@ public class ApexModelWriter<C extends AxConcept> { /** * This method writes the Apex concept into a writer in JSON format. * - * @param concept the concept to write + * @param concept the concept to write * @param apexConceptWriter the writer to write to * @throws ApexModelException on validation or writing exceptions */ @@ -255,7 +253,6 @@ public class ApexModelWriter<C extends AxConcept> { try { marshaller.marshal(concept, apexConceptWriter); } catch (final JAXBException e) { - LOGGER.warn("Unable to marshal Apex concept to JSON", e); throw new ApexModelException("Unable to marshal Apex concept to JSON", e); } LOGGER.debug("wrote Apex concept JSON"); diff --git a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java index ed624fb83..3d5adfc09 100644 --- a/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java +++ b/testsuites/performance/performance-benchmark-test/src/main/java/org/onap/policy/apex/testsuites/performance/benchmark/eventgenerator/EventGeneratorEndpoint.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +25,7 @@ import com.google.gson.Gson; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; import javax.inject.Provider; import javax.ws.rs.GET; @@ -42,11 +44,13 @@ import org.slf4j.ext.XLoggerFactory; */ @Path("/") public class EventGeneratorEndpoint { + // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(EventGeneratorEndpoint.class); // Parameters for event generation - private static EventGeneratorParameters parameters = new EventGeneratorParameters(); + private static AtomicReference<EventGeneratorParameters> parameters = new AtomicReference<>( + new EventGeneratorParameters()); // The map of event batches sent in the test private static ConcurrentHashMap<Integer, EventBatch> batchMap = new ConcurrentHashMap<>(); @@ -59,6 +63,7 @@ public class EventGeneratorEndpoint { /** * Inject the HTTP request with a constructor. + * * @param httpRequest the current request */ @Inject @@ -72,9 +77,7 @@ public class EventGeneratorEndpoint { * @param incomingParameters the new parameters */ public static void setParameters(EventGeneratorParameters incomingParameters) { - synchronized (parameters) { - parameters = incomingParameters; - } + parameters.set(incomingParameters); } /** @@ -96,7 +99,7 @@ public class EventGeneratorEndpoint { @Path("/GetEvents") @GET public Response getEvents() { - ThreadUtilities.sleep(parameters.getDelayBetweenBatches()); + ThreadUtilities.sleep(parameters.get().getDelayBetweenBatches()); // Check if event generation is finished if (isFinished()) { @@ -104,12 +107,12 @@ public class EventGeneratorEndpoint { } // A batch count of 0 means to continue to handle events for ever - if (parameters.getBatchCount() > 0 && batchMap.size() >= parameters.getBatchCount()) { + if (parameters.get().getBatchCount() > 0 && batchMap.size() >= parameters.get().getBatchCount()) { setFinished(true); return Response.status(204).build(); } - EventBatch batch = new EventBatch(parameters.getBatchSize(), getApexClient()); + EventBatch batch = new EventBatch(parameters.get().getBatchSize(), getApexClient()); batchMap.put(batch.getBatchNumber(), batch); return Response.status(200).entity(batch.getBatchAsJsonString()).build(); @@ -144,12 +147,13 @@ public class EventGeneratorEndpoint { * @return the Apex client */ private String getApexClient() { - return httpRequest.get().getRemoteHost() + '(' + httpRequest.get().getRemoteAddr() + "):" - + httpRequest.get().getRemotePort(); + return httpRequest.get().getRemoteHost() + '(' + httpRequest.get().getRemoteAddr() + "):" + httpRequest.get() + .getRemotePort(); } /** * Get event generation statistics. + * * @return the statistics on event generation */ protected static String getEventGenerationStats() { @@ -165,6 +169,7 @@ public class EventGeneratorEndpoint { /** * Check if event generation has finished. + * * @return true if event generation has finished */ protected static boolean isFinished() { |