diff options
-rw-r--r-- | pom.xml | 6 | ||||
-rw-r--r-- | src/main/bin/start.sh | 28 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java | 8 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java | 6 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/datarouter/policy/GapEventTransformer.java | 105 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/datarouter/policy/OxmEntityTypeConverter.java | 42 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java | 6 | ||||
-rw-r--r-- | src/test/java/org/onap/aai/datarouter/entity/SuggestionSearchEntityTest.java (renamed from src/test/java/org/openecomp/datarouter/entity/SuggestionSearchEntityTest.java) | 2 | ||||
-rw-r--r-- | src/test/java/org/onap/aai/datarouter/policy/GapEventTransformerTest.java | 68 | ||||
-rw-r--r-- | src/test/java/org/onap/aai/datarouter/policy/OxmEntityTypeConverterTest.java | 41 | ||||
-rw-r--r-- | src/test/resources/gap_event.json | 50 | ||||
-rw-r--r-- | src/test/resources/gap_event_wrong.json | 50 |
12 files changed, 370 insertions, 42 deletions
@@ -130,6 +130,12 @@ limitations under the License. <scope>test</scope> </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>3.10.0</version> + <scope>test</scope> + </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito</artifactId> diff --git a/src/main/bin/start.sh b/src/main/bin/start.sh index ced887a..bb219b8 100644 --- a/src/main/bin/start.sh +++ b/src/main/bin/start.sh @@ -2,7 +2,7 @@ BASEDIR="/opt/app/data-router/" AJSC_HOME="$BASEDIR" -AJSC_CONF_HOME="$AJSC_HOME/bundleconfig/" + if [ -z "$CONFIG_HOME" ]; then echo "CONFIG_HOME must be set in order to start up process" @@ -12,35 +12,15 @@ fi if [ -z "$KEY_STORE_PASSWORD" ]; then echo "KEY_STORE_PASSWORD must be set in order to start up process" exit 1 -else - ## Extract java jar to DEOBFUSCATE the password. - CURR_D=`pwd` - cd $BASEDIR - jar xf data-router.jar - sudo java -cp ./BOOT-INF/lib/jetty-util-9.4.8.v20171121.jar org.eclipse.jetty.util.security.Password $KEY_STORE_PASSWORD > pass.txt 2>> pass.txt - PASS=`sed "2q;d" pass.txt` - sudo rm pass.txt - cd $CURR_D fi -## tomcat_keystore to p12 -keytool -importkeystore -noprompt -deststorepass $PASS -destkeypass $PASS -srckeystore $BASEDIR/config/auth/tomcat_keystore -destkeystore $BASEDIR/config/auth/onap.p12 -deststoretype PKCS12 -srcstorepass $PASS - -## import into cacerts -sudo keytool -importkeystore -noprompt -deststorepass changeit -destkeypass changeit -destkeystore /$JAVA_HOME/jre/lib/security/cacerts -srckeystore $BASEDIR/config/auth/onap.p12 -srcstoretype PKCS12 -srcstorepass $PASS -alias tomcat - -PROPS="-DBASEDIR=$BASEDIR" PROPS="-DAJSC_HOME=$AJSC_HOME" -PROPS="$PROPS -DAJSC_CONF_HOME=$AJSC_CONF_HOME" PROPS="$PROPS -Dlogging.config=$BASEDIR/bundleconfig/etc/logback.xml" -PROPS="$PROPS -DAJSC_SHARED_CONFIG=$AJSC_CONF_HOME" -PROPS="$PROPS -DAJSC_SERVICE_NAMESPACE=data-router" -PROPS="$PROPS -DAJSC_SERVICE_VERSION=v1" -PROPS="$PROPS -Dserver.port=9502" PROPS="$PROPS -DCONFIG_HOME=$CONFIG_HOME" -JVM_MAX_HEAP=${MAX_HEAP:-1024} +PROPS="$PROPS -DKEY_STORE_PASSWORD=$KEY_STORE_PASSWORD" + -echo $CLASSPATH +JVM_MAX_HEAP=${MAX_HEAP:-1024} cd ${MICRO_HOME} jar uf0 $MICRO_HOME/data-router.jar BOOT-INF/lib/* diff --git a/src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java b/src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java index 7a4884a..ca8caf4 100644 --- a/src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java +++ b/src/main/java/org/onap/aai/datarouter/policy/AbstractSpikeEntityEventProcessor.java @@ -407,13 +407,7 @@ public abstract class AbstractSpikeEntityEventProcessor implements Processor { protected String getOxmEntityType(String entityType) { - - String[] entityTypeArr = entityType.split("-"); - String oxmEntityType = ""; - for (String entityWord : entityTypeArr) { - oxmEntityType += entityWord.substring(0, 1).toUpperCase() + entityWord.substring(1); - } - return oxmEntityType; + return new OxmEntityTypeConverter().convert(entityType); } protected List<String> getSearchableAttibutes(DynamicJAXBContext oxmJaxbContext, String oxmEntityType, diff --git a/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java b/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java index c1a1f2e..ae5d0e6 100644 --- a/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java +++ b/src/main/java/org/onap/aai/datarouter/policy/EntityEventPolicy.java @@ -314,11 +314,7 @@ public class EntityEventPolicy implements Processor { // Process for building AaiEventEntity object - String[] entityTypeArr = entityType.split("-"); - String oxmEntityType = ""; - for (String entityWord : entityTypeArr) { - oxmEntityType += entityWord.substring(0, 1).toUpperCase() + entityWord.substring(1); - } + String oxmEntityType = new OxmEntityTypeConverter().convert(entityType); List<String> searchableAttr = getOxmAttributes(uebPayload, oxmJaxbContext, oxmEntityType, entityType, "searchable"); diff --git a/src/main/java/org/onap/aai/datarouter/policy/GapEventTransformer.java b/src/main/java/org/onap/aai/datarouter/policy/GapEventTransformer.java new file mode 100644 index 0000000..6565fc2 --- /dev/null +++ b/src/main/java/org/onap/aai/datarouter/policy/GapEventTransformer.java @@ -0,0 +1,105 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.datarouter.policy; + +import java.io.FileNotFoundException; + +import org.apache.camel.Exchange; +import org.json.JSONException; +import org.json.JSONObject; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; +import org.onap.aai.datarouter.logging.EntityEventPolicyMsgs; + + + +public class GapEventTransformer { + protected Logger logger; + protected static final String additionalInfo = "Response of GapEvent to transform"; + + protected enum ResponseType { + SUCCESS, PARTIAL_SUCCESS, FAILURE; + } + + public GapEventTransformer() throws FileNotFoundException { + LoggerFactory loggerFactoryInstance = LoggerFactory.getInstance(); + logger = loggerFactoryInstance.getLogger(AbstractSpikeEntityEventProcessor.class.getName()); + } + + + public void process(Exchange exchange) throws Exception { + + String payload = getExchangeBody(exchange); + JSONObject newPayload = transformToSpikePattern(payload); + exchange.getOut().setBody(newPayload.toString()); + + } + + protected JSONObject transformToSpikePattern(String payload) { + JSONObject payloadJson = new JSONObject(payload); + JSONObject payloadEntity = payloadJson.getJSONObject("entity"); + JSONObject payloadProperties = payloadEntity.getJSONObject("properties"); + String payloadId = payloadEntity.getString("id"); + String payloadType = payloadEntity.getString("type"); + + JSONObject newPayload = new JSONObject(); + newPayload.put("operation", "UPDATE"); + JSONObject newPayloadVertex = new JSONObject(); + newPayloadVertex.put("key", payloadId); + newPayloadVertex.put("type", payloadType); + newPayloadVertex.put("properties", payloadProperties); + newPayload.put("vertex", newPayloadVertex); + return newPayload; + } + + protected String getExchangeBody(Exchange exchange) { + String uebPayload = exchange.getIn().getBody().toString(); + if (uebPayload == null || !isJSONValid(uebPayload)) { + uebPayload = exchange.getIn().getBody(String.class); + if (uebPayload == null || !isJSONValid(uebPayload)) { + returnWithError(exchange, uebPayload, "Invalid Payload"); + return null; + } + } + return uebPayload; + } + + private boolean isJSONValid(String test) { + try { + new JSONObject(test); + } catch (JSONException ex) { + return false; + } + return true; + } + + protected void returnWithError(Exchange exchange, String payload, String errorMsg) { + logger.error(EntityEventPolicyMsgs.DISCARD_EVENT_NONVERBOSE, errorMsg); + logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, errorMsg, payload); + setResponse(exchange, ResponseType.FAILURE, additionalInfo); + } + + protected void setResponse(Exchange exchange, ResponseType responseType, String additionalInfo) { + + exchange.getOut().setHeader("ResponseType", responseType.toString()); + exchange.getOut().setBody(additionalInfo); + } +} diff --git a/src/main/java/org/onap/aai/datarouter/policy/OxmEntityTypeConverter.java b/src/main/java/org/onap/aai/datarouter/policy/OxmEntityTypeConverter.java new file mode 100644 index 0000000..d05ebc9 --- /dev/null +++ b/src/main/java/org/onap/aai/datarouter/policy/OxmEntityTypeConverter.java @@ -0,0 +1,42 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Nokia + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.datarouter.policy; + +import org.apache.commons.lang.StringUtils; + +/** + * Created by Bogumil Zebek on 6/21/18. + */ +public class OxmEntityTypeConverter { + + private static final String DELIMITER = "-"; + + public String convert(String entityType) { + + String[] entityTypeArr = entityType.split(DELIMITER); + + StringBuilder oxmEntityType = new StringBuilder(); + for (String entityWord : entityTypeArr) { + oxmEntityType.append(StringUtils.capitalize(entityWord)); + } + return oxmEntityType.toString(); + } +} diff --git a/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java b/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java index 8f0e426..67db407 100644 --- a/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java +++ b/src/main/java/org/onap/aai/datarouter/policy/SpikeEntityEventPolicy.java @@ -338,11 +338,7 @@ public class SpikeEntityEventPolicy implements Processor { eventPayload); // Process for building SpikeEventEntity object - String[] entityTypeArr = entityType.split("-"); - String oxmEntityType = ""; - for (String entityWord : entityTypeArr) { - oxmEntityType += entityWord.substring(0, 1).toUpperCase() + entityWord.substring(1); - } + String oxmEntityType = new OxmEntityTypeConverter().convert(entityType); List<String> searchableAttr = getOxmAttributes(oxmJaxbContext, oxmEntityType, entityType, "searchable"); diff --git a/src/test/java/org/openecomp/datarouter/entity/SuggestionSearchEntityTest.java b/src/test/java/org/onap/aai/datarouter/entity/SuggestionSearchEntityTest.java index 4d48e83..3c56dc8 100644 --- a/src/test/java/org/openecomp/datarouter/entity/SuggestionSearchEntityTest.java +++ b/src/test/java/org/onap/aai/datarouter/entity/SuggestionSearchEntityTest.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ -package org.openecomp.datarouter.entity; +package org.onap.aai.datarouter.entity; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/org/onap/aai/datarouter/policy/GapEventTransformerTest.java b/src/test/java/org/onap/aai/datarouter/policy/GapEventTransformerTest.java new file mode 100644 index 0000000..355756b --- /dev/null +++ b/src/test/java/org/onap/aai/datarouter/policy/GapEventTransformerTest.java @@ -0,0 +1,68 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.datarouter.policy; + +import static org.junit.Assert.*; + +import java.io.File; +import java.io.FileInputStream; + +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; + + + +public class GapEventTransformerTest { + GapEventTransformer policy; + String eventJson; + String eventJson2; + + @SuppressWarnings("unchecked") + @Before + public void init() throws Exception { + policy = new GapEventTransformer(); + FileInputStream event = new FileInputStream(new File("src/test/resources/gap_event.json")); + eventJson = IOUtils.toString(event, "UTF-8"); + FileInputStream event2 = + new FileInputStream(new File("src/test/resources/gap_event_wrong.json")); + eventJson2 = IOUtils.toString(event2, "UTF-8"); + + } + + @Test + public void testTransform_success() throws Exception { + JSONObject newPayloadJson = policy.transformToSpikePattern(eventJson.toString()); + JSONObject payloadEntity = newPayloadJson.getJSONObject("vertex"); + assertTrue(newPayloadJson.has("vertex")); + assertTrue(newPayloadJson.has("operation")); + assertEquals(newPayloadJson.get("operation"), "UPDATE"); + + + } + + @Test(expected = Exception.class) + public void testTransform_badPayload_fail() throws Exception { + policy.transformToSpikePattern(eventJson2.toString()); + } + +} diff --git a/src/test/java/org/onap/aai/datarouter/policy/OxmEntityTypeConverterTest.java b/src/test/java/org/onap/aai/datarouter/policy/OxmEntityTypeConverterTest.java new file mode 100644 index 0000000..12e23be --- /dev/null +++ b/src/test/java/org/onap/aai/datarouter/policy/OxmEntityTypeConverterTest.java @@ -0,0 +1,41 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Nokia + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.datarouter.policy; + + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +/** + * Created by Bogumil Zebek on 6/21/18. + */ +public class OxmEntityTypeConverterTest { + + private OxmEntityTypeConverter oxmEntityTypeConverter = new OxmEntityTypeConverter(); + + @Test + public void shouldConvertEntityTypeToOxmEntityType(){ + Assertions.assertThat(oxmEntityTypeConverter.convert("generic-vnf")).isEqualTo("GenericVnf"); + Assertions.assertThat(oxmEntityTypeConverter.convert("pserver")).isEqualTo("Pserver"); + Assertions.assertThat(oxmEntityTypeConverter.convert("optical-router")).isEqualTo("OpticalRouter"); + } + +}
\ No newline at end of file diff --git a/src/test/resources/gap_event.json b/src/test/resources/gap_event.json new file mode 100644 index 0000000..05e8fc3 --- /dev/null +++ b/src/test/resources/gap_event.json @@ -0,0 +1,50 @@ +{ + "event-header":{ + "entity-type":"pserver", + "top-entity-type":"pserver", + "entity-link":"/services/inventory/v11/pservers?properties=all", + "event-type":"${crud.event.type.api}", + "domain":"dev", + "topic-name":"CRUD-DATA-EXPORT-SDWAN", + "event-id":"7445ecab-40fc-46a9-a595-42d940488b02" + }, + "entity":{ + "in":[ + { + "id":"9387d038-1e4f-4a08-ac5e-97c09530bbd8", + "source":"services/inventory/v11/vserver/ad7c5ad8-142f-4cd1-b38a-11fd7d98239d", + "type":"tosca.relationships.HostedOn", + "url":"services/inventory/relationships/v12/tosca.relationships.HostedOn/9387d038-1e4f-4a08-ac5e-97c09530bbd8" + } + ], + "id":"441d5a1e-a107-4fc3-b885-ccf683e3513b", + "type":"pserver", + "url":"services/inventory/v11/pserver/441d5a1e-a107-4fc3-b885-ccf683e3513b", + "properties":{ + "aai-last-mod-ts":"1522935511411", + "equip-type":"Rack Server", + "equip-vendor":"HP", + "serial-number":"S4MPLEDDD456D", + "pserver-id":"Pserver-AMT-8", + "aai-created-ts":"1522935511411", + "source-of-truth":"RO", + "number-of-cpus":10, + "aai-node-type":"pserver", + "hostname":"10_aaingenvnf-pserver-fw-8", + "equip-model":"PowerEdge R930", + "in-maint":false, + "resource-version":"64684545", + "disk-in-gigabytes":146, + "ram-in-megabytes":62914556, + "last-mod-source-of-truth":"RO" + }, + "out":[ + { + "id":"bfa7ec57-cfa6-4bda-b1dc-a11a192bacaa", + "type":"org.onap.relationships.inventory.LocatedIn", + "url":"services/inventory/relationships/v12/org.onap.relationships.inventory.LocatedIn/bfa7ec57-cfa6-4bda-b1dc-a11a192bacaa", + "target":"services/inventory/v11/complex/90564f64-d3c4-47f8-847d-553497f6b04a" + } + ] + } +}
\ No newline at end of file diff --git a/src/test/resources/gap_event_wrong.json b/src/test/resources/gap_event_wrong.json new file mode 100644 index 0000000..bf4135f --- /dev/null +++ b/src/test/resources/gap_event_wrong.json @@ -0,0 +1,50 @@ +{ + "event-header":{ + "entity-type":"pserver", + "top-entity-type":"pserver", + "entity-link":"/services/inventory/v11/pservers?properties=all", + "event-type":"${crud.event.type.api}", + "domain":"dev", + "topic-name":"CRUD-DATA-EXPORT-SDWAN", + "event-id":"7445ecab-40fc-46a9-a595-42d940488b02" + }, + "entity2":{ + "in":[ + { + "id":"9387d038-1e4f-4a08-ac5e-97c09530bbd8", + "source":"services/inventory/v11/vserver/ad7c5ad8-142f-4cd1-b38a-11fd7d98239d", + "type":"tosca.relationships.HostedOn", + "url":"services/inventory/relationships/v12/tosca.relationships.HostedOn/9387d038-1e4f-4a08-ac5e-97c09530bbd8" + } + ], + "id":"441d5a1e-a107-4fc3-b885-ccf683e3513b", + "type":"pserver", + "url":"services/inventory/v11/pserver/441d5a1e-a107-4fc3-b885-ccf683e3513b", + "properties":{ + "aai-last-mod-ts":"1522935511411", + "equip-type":"Rack Server", + "equip-vendor":"HP", + "serial-number":"S4MPLEDDD456D", + "pserver-id":"Pserver-AMT-8", + "aai-created-ts":"1522935511411", + "source-of-truth":"RO", + "number-of-cpus":10, + "aai-node-type":"pserver", + "hostname":"10_aaingenvnf-pserver-fw-8", + "equip-model":"PowerEdge R930", + "in-maint":false, + "resource-version":"64684545", + "disk-in-gigabytes":146, + "ram-in-megabytes":62914556, + "last-mod-source-of-truth":"RO" + }, + "out":[ + { + "id":"bfa7ec57-cfa6-4bda-b1dc-a11a192bacaa", + "type":"org.onap.relationships.inventory.LocatedIn", + "url":"services/inventory/relationships/v12/org.onap.relationships.inventory.LocatedIn/bfa7ec57-cfa6-4bda-b1dc-a11a192bacaa", + "target":"services/inventory/v11/complex/90564f64-d3c4-47f8-847d-553497f6b04a" + } + ] + } +}
\ No newline at end of file |