Use lombok on fields in EnEvent.
Remove unnecessary code in BBS WebClient class
Address Sonar issue in Execurot class
Issue-ID: POLICY-1791
Change-Id: If07dc4529b121f8bfcd6ab1ae6c9def4774f9f4d
Signed-off-by: liamfallon <liam.fallon@est.tech>
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.Random;
import java.util.Set;
+import lombok.Getter;
+import lombok.Setter;
+
import org.onap.policy.apex.core.engine.monitoring.EventMonitor;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
private final transient EventMonitor eventMonitor = new EventMonitor();
// The stack of execution of this event, used for monitoring
+ @Getter
+ @Setter
private AxConcept[] userArtifactStack;
private static Random rand = new Random(System.nanoTime());
// An identifier for the current event execution. The default value here will always be a random
// number, and should
// be reset
+ @Getter
+ @Setter
private long executionId = rand.nextLong();
// Event related properties used during processing of this event
+ @Getter
+ @Setter
private Properties executionProperties;
// A string holding a message that indicates why processing of this event threw an exception
+ @Getter
+ @Setter
private String exceptionMessage;
/**
return axEvent.getKey().getId();
}
- /**
- * Get the currently set value for the ExecutionID for this event. A ExecutionID in an EnEvent
- * is used identify all EnEvents (input, internal and output events) used in a single Engine
- * invocation. Therefore, a ExecutionID can be used to match which output event is the result of
- * a particular input event. The default initialized value for the ExecutionID is always unique
- * in a single JVM.
- *
- * @return the currently set value for the ExecutionID for this event.
- */
- public long getExecutionId() {
- return executionId;
- }
-
- /**
- * Set the value for the ExecutionID for this event. A ExecutionID in an EnEvent is used
- * identify all EnEvents (input, internal and output events) used in a single Engine invocation.
- * Therefore, a ExecutionID can be used to match which output event is the result of a
- * particular input event. The default initialised value for the ExecutionID is always unique in
- * a single JVM.
- *
- * @param executionId the new value for the ExecutionID for this event.
- */
- public void setExecutionId(final long executionId) {
- this.executionId = executionId;
- }
-
- /**
- * Get the event execution properties.
- *
- * @return the event execution properties
- */
- public Properties getExecutionProperties() {
- return executionProperties;
- }
-
- /**
- * Set the event execution properties.
- *
- * @param executionProperties the execution properties to set
- */
- public void setExecutionProperties(Properties executionProperties) {
- this.executionProperties = executionProperties;
- }
-
- /**
- * Gets the exception message explaining why processing of this event to fail.
- *
- * @return the exception message
- */
- public String getExceptionMessage() {
- return exceptionMessage;
- }
-
- /**
- * Sets the exception message explaining why processing of this event to fail.
- *
- * @param exceptionMessage the exception message
- */
- public void setExceptionMessage(final String exceptionMessage) {
- this.exceptionMessage = exceptionMessage;
- }
-
- /**
- * Get the user artifact stack of the event.
- *
- * @return the event user artifact stack
- */
- public AxConcept[] getUserArtifactStack() {
- return userArtifactStack;
- }
-
- /**
- * Store the user artifact stack of the event.
- *
- * @param usedArtifactStackArray the event user artifact stack
- */
- public void setUserArtifactStack(final AxConcept[] usedArtifactStackArray) {
- userArtifactStack = usedArtifactStackArray;
- }
-
/**
* {@inheritDoc}.
*/
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* @return The parent executor of this executor
*/
- Executor<?, ?, ?, ?> getParent();
+ @SuppressWarnings("rawtypes")
+ Executor getParent();
/**
* Get the subject of the executor.
* @param username Simple Username
* @param pass Simple password
* @param contentType http content type
- * @apram secureHttp flag indicating if HTTPS should be used
* @return String response message
*/
public String httpRequest(String requestUrl, String requestMethod, String outputStr, String username, String pass,
- String contentType, boolean secureHttp) {
+ String contentType) {
String result = "";
StringBuilder builder = new StringBuilder();
try {
disableCertificateValidation();
URL url = new URL(requestUrl);
- HttpURLConnection httpUrlConn = null;
- if (secureHttp) {
- httpUrlConn = (HttpsURLConnection) url.openConnection();
- }
- else {
- httpUrlConn = (HttpURLConnection) url.openConnection();
- }
+ HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection();
+
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
executor.logger.info("Query url" + urlGet);
- result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true);
+ result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
executor.logger.info("Data received From " + urlGet + " " + result);
jsonObj = JSON.parse(result.toString());
executor.logger.info("ready to putAfter Parse " + JSON.stringify(putUpddateServInstance, null, 4));
var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version;
result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
- "application/json", true);
+ "application/json");
executor.logger.info("Data received From " + urlPut + " " + result);
/* If failure to retrieve data proceed to Failure */
if (result != "") {
/* 1. Get PNF */
var urlGetPnf = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName;
- pnfResponse = client.httpRequest(urlGetPnf, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true);
+ pnfResponse = client.httpRequest(urlGetPnf, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
executor.logger.info("Data received From " + urlGetPnf + " " + pnfResponse);
/* If failure to retrieve data proceed to Failure */
if (result != "") {
pnfUpdate = JSON.parse(pnfResponse.toString());
executor.logger.info(JSON.stringify(pnfUpdate, null, 4));
- /*2. Create logical link */
+ /* 2. Create logical link */
var link_name = attachmentPoint;
var logicalLink = {
"link-name" : link_name,
var urlNewLogicalLink = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION
+ "/network/logical-links/logical-link/" + link_name;
result = client.httpRequest(urlNewLogicalLink, "PUT", JSON.stringify(logicalLink), AAI_USERNAME, AAI_PASSWORD,
- "application/json", true);
+ "application/json");
executor.logger.info("Data received From " + urlNewLogicalLink + " " + result);
/* If failure to retrieve data proceed to Failure */
if (result != "") {
aaiUpdateResult = false;
}
- /*3. Update pnf with new relation*/
+ /* 3. Update pnf with new relation */
for (var i = 0; i < pnfUpdate["relationship-list"]["relationship"].length; i++) {
if (pnfUpdate["relationship-list"]["relationship"][i]['related-to'] == 'logical-link') {
pnfUpdate["relationship-list"]["relationship"][i]['related-link'] = "/aai/" + AAI_VERSION
executor.logger.info("Put pnf to aai " + JSON.stringify(pnfUpdate, null, 4));
var urlPutPnf = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName;
result = client.httpRequest(urlPutPnf, "PUT", JSON.stringify(pnfUpdate), AAI_USERNAME, AAI_PASSWORD,
- "application/json", true);
+ "application/json");
executor.logger.info("Data received From " + urlPutPnf + " " + result);
/* If failure to retrieve data proceed to Failure */
var linkResult;
var urlOldLogicalLink = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION
+ "/network/logical-links/logical-link/" + oldLinkName;
- linkResult = client
- .httpRequest(urlOldLogicalLink, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true);
+ linkResult = client.httpRequest(urlOldLogicalLink, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
executor.logger.info("Data received From " + urlOldLogicalLink + " " + linkResult + " "
+ linkResult.hasOwnProperty("link-name"));
oldLinkResult = JSON.parse(linkResult.toString());
var urlDelOldLogicalLink = urlOldLogicalLink + "?resource-version=" + res_version;
executor.logger.info("Delete called for " + urlDelOldLogicalLink);
result = client.httpRequest(urlDelOldLogicalLink, "DELETE", null, AAI_USERNAME, AAI_PASSWORD,
- "application/json", true);
+ "application/json");
executor.logger.info("Delete called for " + urlDelOldLogicalLink + " result " + result);
}
}
executor.logger.info("Query url" + urlGet);
- result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true);
+ result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
executor.logger.info("Data received From " + urlGet + " " + result);
jsonObj = JSON.parse(result);
executor.logger.info("ready to putAfter Parse " + JSON.stringify(putUpddateServInstance, null, 4));
var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version;
result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
- "application/json", true);
+ "application/json");
executor.logger.info("Data received From " + urlPut + " " + result);
/* If failure to retrieve data proceed to Failure */
if (result != "") {
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Huawei. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
try {
var urlPost1 = HTTP_PROTOCOL + SDNC_URL + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
- result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml",
- false);
+ result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml");
executor.logger.info("Data received From " + urlPost1 + " " + result);
if (result == "") {
sdncUpdateResult = false;
if (sdncUpdateResult == true) {
var urlPost2 = HTTP_PROTOCOL + SDNC_URL
+ "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
- result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml",
- false);
+ result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml");
executor.logger.info("Data received From " + urlPost2 + " " + result);
if (result == "") {
sdncUpdateResult = false;
if (sdncUpdateResult == true) {
var urlPost3 = HTTP_PROTOCOL + SDNC_URL
+ "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
- result = client.httpRequest(urlPost3, "POST", xmlChangeProfile, SDNC_USERNAME, SDNC_PASSWORD,
- "application/xml", false);
+ result = client
+ .httpRequest(urlPost3, "POST", xmlChangeProfile, SDNC_USERNAME, SDNC_PASSWORD, "application/xml");
executor.logger.info("Data received From " + urlPost3 + " " + result);
if (result == "") {
sdncUpdateResult = false;
}
return true;
}
-/* Utility functions End */
+/* Utility functions End */
\ No newline at end of file
executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);
-var clEventType = Java.type(
- "org.onap.policy.controlloop.VirtualControlLoopEvent");
+var clEventType = Java.type("org.onap.policy.controlloop.VirtualControlLoopEvent");
var clEvent = executor.inFields.get("VirtualControlLoopEvent");
-var serviceInstanceId = clEvent.getAai().get(
- "service-information.hsia-cfs-service-instance-id");
+var serviceInstanceId = clEvent.getAai().get("service-information.hsia-cfs-service-instance-id");
var requestID = clEvent.getRequestId();
var jsonObj;
var service_instance;
var AAI_VERSION = "v14";
try {
- var br = Files.newBufferedReader(Paths.get(
- "/home/apexuser/examples/config/ONAPBBS/config.txt"));
+ var br = Files.newBufferedReader(Paths.get("/home/apexuser/examples/config/ONAPBBS/config.txt"));
var line;
while ((line = br.readLine()) != null) {
if (line.startsWith("AAI_URL")) {
} else if (line.startsWith("AAI_PASSWORD")) {
var str = line.split("=");
AAI_PASSWORD = str[str.length - 1];
- }else if (line.startsWith("AAI_VERSION")) {
+ } else if (line.startsWith("AAI_VERSION")) {
var str = line.split("=");
AAI_VERSION = str[str.length - 1];
- }
- }
+ }
+ }
} catch (err) {
executor.logger.info("Failed to retrieve data " + err);
}
/* Get service instance Id from AAI */
try {
- var urlGet = HTTP_PROTOCOL + AAI_URL +
- "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/" +
- SERVICE_INSTANCE_ID + "?format=resource_and_url"
+ var urlGet = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/"
+ + SERVICE_INSTANCE_ID + "?format=resource_and_url"
executor.logger.info("Query url" + urlGet);
- result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD,
- "application/json", true);
+ result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
executor.logger.info("Data received From " + urlGet + " " + result);
jsonObj = JSON.parse(result);
-
/* Retrieve the service instance id */
results = jsonObj['results'][0];
putUrl = results["url"];
service_instance = results['service-instance'];
resource_version = service_instance['resource-version'];
- executor.logger.info("After Parse service_instance " + JSON.stringify(
- service_instance, null, 4) + "\n url " + putUrl +
- "\n Service instace Id " + SERVICE_INSTANCE_ID);
+ executor.logger.info("After Parse service_instance " + JSON.stringify(service_instance, null, 4) + "\n url "
+ + putUrl + "\n Service instace Id " + SERVICE_INSTANCE_ID);
if (result == "") {
aaiUpdateResult = false;
putUpddateServInstance = service_instance;
if (newState == 'inService') {
putUpddateServInstance['orchestration-status'] = "active";
-}
-else
-{
+} else {
putUpddateServInstance['orchestration-status'] = "inActive";
}
try {
if (aaiUpdateResult == true) {
- executor.logger.info("ready to put After Parse " + JSON.stringify(
- putUpddateServInstance, null, 4));
- var urlPut = HTTP_PROTOCOL + AAI_URL +
- putUrl + "?resource_version=" + resource_version;
+ executor.logger.info("ready to put After Parse " + JSON.stringify(putUpddateServInstance, null, 4));
+ var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version;
result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
- "application/json", true);
+ "application/json");
executor.logger.info("Data received From " + urlPut + " " + result);
/* If failure to retrieve data proceed to Failure */
if (result != "") {
executor.logger.info(executor.outFields);
var returnValue = executor.isTrue;
executor.logger.info("End Execution ServiceUpdateStateCpeAuthTask.js");
-
@Test
public void httpsRequest() {
WebClient cl = new WebClient();
- String result = cl.httpRequest("https://some.random.url/data", "POST", null, "admin", "admin",
- "application/json", true);
+ String result =
+ cl.httpRequest("https://some.random.url/data", "POST", null, "admin", "admin", "application/json");
assertNotNull(result);
}
public void httpRequest() {
WebClient cl = new WebClient();
String result =
- cl.httpRequest("http://some.random.url/data", "GET", null, "admin", "admin", "application/json", false);
+ cl.httpRequest("http://some.random.url/data", "GET", null, "admin", "admin", "application/json");
assertNotNull(result);
}