<sonar.projectVersion>${project.version}</sonar.projectVersion>
<logback.version>1.2.3</logback.version>
<version.com.google.guava>16.0.1</version.com.google.guava>
+ <shemaUnpackVersion>onap</shemaUnpackVersion>
</properties>
<dependencies>
<version>1.3.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.onap.aai.aai-common</groupId>
+ <artifactId>aai-schema-ingest</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </dependency>
+
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<artifactItem>
<groupId>org.onap.aai.aai-common</groupId>
<artifactId>aai-schema</artifactId>
- <version>1.2.2</version>
+ <version>1.3.0-SNAPSHOT</version>
<type>jar</type>
- <includes>oxm/</includes>
- <outputDirectory>${project.build.directory}/bundleconfig-local/etc</outputDirectory>
+ <includes>/${shemaUnpackVersion}/oxm/</includes>
+ <outputDirectory>${project.build.directory}/oxm</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
COPY data-router.jar $MICRO_HOME/
COPY bundleconfig-local $MICRO_HOME/bundleconfig
COPY bundleconfig-local/etc/logback.xml $MICRO_HOME/bundleconfig/etc
+COPY oxm $MICRO_HOME/
EXPOSE 9502 9502
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.onap.aai.restclient.client.Headers;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.restclient.rest.HttpUtil;
+import org.onap.aai.setup.SchemaVersions;
import org.slf4j.MDC;
import com.fasterxml.jackson.core.JsonProcessingException;
protected Logger logger;
protected Logger metricsLogger;
protected ObjectMapper mapper;
-
-
+
public AbstractSpikeEntityEventProcessor(SpikeEventPolicyConfig config)
throws FileNotFoundException {
mapper = new ObjectMapper();
this.externalOxmModelProcessors = new ArrayList<>();
this.externalOxmModelProcessors.add(EntityOxmReferenceHelper.getInstance());
OxmModelLoader.registerExternalOxmModelProcessors(externalOxmModelProcessors);
- OxmModelLoader.loadModels();
+ OxmModelLoader.loadModels(config.getSchemaVersions(), config.getSchemaLocationsBean());
oxmVersionContextMap = OxmModelLoader.getVersionContextMap();
parseLatestOxmVersion();
}
}
- protected List<String> extractSuggestableAttr(VersionedOxmEntities oxmEntities, String entityType) {
- // Extract suggestable attributeshandleTopographicalData
- Map<String, OxmEntityDescriptor> rootDescriptor = oxmEntities.getSuggestableEntityDescriptors();
-
- if (rootDescriptor == null) {
- return Collections.emptyList();
- }
-
- OxmEntityDescriptor desc = rootDescriptor.get(entityType);
-
- if (desc == null) {
- return Collections.emptyList();
- }
-
- return desc.getSuggestableAttributes();
- }
-
}
import org.onap.aai.util.EntityOxmReferenceHelper;
import org.onap.aai.util.ExternalOxmModelProcessor;
import org.onap.aai.schema.OxmModelLoader;
+import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.util.Version;
import org.onap.aai.util.VersionedOxmEntities;
import org.onap.aai.cl.api.Logger;
/** Agent for communicating with the Search Service. */
private SearchServiceAgent searchAgent = null;
-
+
/** Search index name for storing AAI event entities. */
private String entitySearchIndex;
/** Search index name for storing topographical search data. */
private String topographicalSearchIndex;
-
+
/** Search index name for suggestive search data. */
private String aggregateGenericVnfIndex;
-
+
private String autosuggestIndex;
private String srcDomain;
topographicalSearchIndex = config.getSearchTopographySearchIndex();
aggregateGenericVnfIndex = config.getSearchAggregationVnfIndex();
autosuggestIndex = config.getSearchEntityAutoSuggestIndex();
-
+
// Instantiate the agent that we will use for interacting with the Search Service.
searchAgent = new SearchServiceAgent(config.getSearchCertName(),
config.getSearchKeystore(),
this.externalOxmModelProcessors = new ArrayList<>();
this.externalOxmModelProcessors.add(EntityOxmReferenceHelper.getInstance());
OxmModelLoader.registerExternalOxmModelProcessors(externalOxmModelProcessors);
- OxmModelLoader.loadModels();
+ OxmModelLoader.loadModels(config.getSchemaVersions(), config.getSchemaLocationsBean());
oxmVersionContextMap = OxmModelLoader.getVersionContextMap();
parseLatestOxmVersion();
}
}
public void startup() {
-
+
// Create the indexes in the search service if they do not already exist.
searchAgent.createSearchIndex(entitySearchIndex, ENTITY_SEARCH_SCHEMA);
searchAgent.createSearchIndex(topographicalSearchIndex, TOPOGRAPHICAL_SEARCH_SCHEMA);
-
+
logger.info(EntityEventPolicyMsgs.ENTITY_EVENT_POLICY_REGISTERED);
}
logger.debug(EntityEventPolicyMsgs.DISCARD_EVENT_VERBOSE, errorMsg, payload);
setResponse(exchange, ResponseType.FAILURE, additionalInfo);
}
-
+
@Override
public void process(Exchange exchange) throws Exception {
String uebPayload = exchange.getIn().getBody().toString();
- JsonNode uebAsJson =null;
+ JsonNode uebAsJson = null;
ObjectMapper mapper = new ObjectMapper();
try{
uebAsJson = mapper.readTree(uebPayload);
returnWithError(exchange, uebPayload, "Payload is missing " + EVENT_HEADER);
return;
}
-
+
JSONObject uebObjEntity = getUebContentAsJson(uebPayload, ENTITY_HEADER);
if (uebObjEntity == null) {
returnWithError(exchange, uebPayload, "Payload is missing " + ENTITY_HEADER);
* NOTES:
* 1. If the entity type is "customer", the below check will return true if any nested entityType
* in that model could contain a CER based on the OXM model version that has been loaded.
- * 2. For a DELETE operation on outer/parent entity (handled by the regular flow:
+ * 2. For a DELETE operation on outer/parent entity (handled by the regular flow:
* handleSearchServiceOperation()), ignore processing for cross-entity-reference under the
* assumption that AAI will push down all required cascade-deletes for nested entities as well
* 3. Handling the case where UEB events arrive out of order: CREATE customer is received before
* CREATE service-instance.
*/
- if (!action.equalsIgnoreCase(ACTION_DELETE) && oxmEntities != null
+ if (!action.equalsIgnoreCase(ACTION_DELETE) && oxmEntities != null
&& oxmEntities.entityModelContainsCrossEntityReference(topEntityType)) {
// We know the model "can" contain a CER reference definition, let's process a bit more
JSONObject entityJsonObject = getUebEntity(uebPayload);
- if (entityJsonObject != null) {
- JsonNode entityJsonNode = convertToJsonNode(entityJsonObject.toString());
-
- String parentEntityType = entityType;
-
- String targetEntityUrl = entityLink;
+ JsonNode entityJsonNode = convertToJsonNode(entityJsonObject.toString());
+
+ String parentEntityType = entityType;
+
+ String targetEntityUrl = entityLink;
- for (Map.Entry<String, CrossEntityReference> entry : crossEntityRefMap.entrySet()) {
+ for (Map.Entry<String, CrossEntityReference> entry : crossEntityRefMap.entrySet()) {
- /*
- * if we know service-subscription is in the tree, then we can pull our all instances and process
- * from there.
- */
-
- String key = entry.getKey();
- CrossEntityReference cerDescriptor = entry.getValue();
-
- ArrayList<JsonNode> foundNodes = new ArrayList<>();
+ /*
+ * if we know service-subscription is in the tree, then we can pull our all instances and
+ * process from there.
+ */
- RouterServiceUtil.extractObjectsByKey(entityJsonNode, key, foundNodes);
+ String key = entry.getKey();
+ CrossEntityReference cerDescriptor = entry.getValue();
- if (!foundNodes.isEmpty()) {
+ ArrayList<JsonNode> foundNodes = new ArrayList<>();
- for (JsonNode n : foundNodes) {
- if ("customer".equalsIgnoreCase(parentEntityType)) {
- /*
- * NOTES: 1. prepare to hand-create url for service-instance 2. this will break if the
- * URL structure for service-instance changes
- */
- if (n.has("service-type")) {
- targetEntityUrl += "/service-subscriptions/service-subscription/"
- + RouterServiceUtil.getNodeFieldAsText(n, "service-type")
- + "/service-instances/service-instance/";
- }
- }
+ RouterServiceUtil.extractObjectsByKey(entityJsonNode, key, foundNodes);
- List<String> extractedParentEntityAttributeValues = new ArrayList<>();
+ if (!foundNodes.isEmpty()) {
- RouterServiceUtil.extractFieldValuesFromObject(n, cerDescriptor.getAttributeNames(),
- extractedParentEntityAttributeValues);
+ for (JsonNode n : foundNodes) {
+ if ("customer".equalsIgnoreCase(parentEntityType)){
+ /*
+ * NOTES:
+ * 1. prepare to hand-create url for service-instance
+ * 2. this will break if the URL structure for service-instance changes
+ */
+ if (n.has("service-type")){
+ targetEntityUrl += "/service-subscriptions/service-subscription/"
+ + RouterServiceUtil.getNodeFieldAsText(n, "service-type")
+ + "/service-instances/service-instance/";
+ }
+
+ }
- List<JsonNode> nestedTargetEntityInstances = new ArrayList<>();
- RouterServiceUtil.extractObjectsByKey(n, cerDescriptor.getTargetEntityType(),
- nestedTargetEntityInstances);
+ List<String> extractedParentEntityAttributeValues = new ArrayList<>();
- for (JsonNode targetEntityInstance : nestedTargetEntityInstances) {
- /*
- * Now: 1. build the AAIEntityType (IndexDocument) based on the extract entity 2. Get
- * data from ES 3. Extract ETAG 4. Merge ES Doc + AAIEntityType + Extracted Parent
- * Cross-Entity-Reference Values 5. Put data into ES with ETAG + updated doc
- */
+ RouterServiceUtil.extractFieldValuesFromObject(n, cerDescriptor.getAttributeNames(),
+ extractedParentEntityAttributeValues);
- // Get the complete URL for target entity
- if (targetEntityInstance.has("link")) { // nested SI has url mentioned
- targetEntityUrl = RouterServiceUtil.getNodeFieldAsText(targetEntityInstance, "link");
- } else if ("customer".equalsIgnoreCase(parentEntityType) && targetEntityInstance.has("service-instance-id")) {
- targetEntityUrl += RouterServiceUtil.getNodeFieldAsText(targetEntityInstance, "service-instance-id");
- }
+ List<JsonNode> nestedTargetEntityInstances = new ArrayList<>();
+ RouterServiceUtil.extractObjectsByKey(n, cerDescriptor.getTargetEntityType(),
+ nestedTargetEntityInstances);
- OxmEntityDescriptor searchableDescriptor = oxmEntities.getSearchableEntityDescriptor(cerDescriptor.getTargetEntityType());
+ for (JsonNode targetEntityInstance : nestedTargetEntityInstances) {
+ /*
+ * Now:
+ * 1. build the AAIEntityType (IndexDocument) based on the extract entity
+ * 2. Get data from ES
+ * 3. Extract ETAG
+ * 4. Merge ES Doc + AAIEntityType + Extracted Parent Cross-Entity-Reference Values
+ * 5. Put data into ES with ETAG + updated doc
+ */
- if (searchableDescriptor != null) {
+ // Get the complete URL for target entity
+ if (targetEntityInstance.has("link")) { // nested SI has url mentioned
+ targetEntityUrl = RouterServiceUtil.getNodeFieldAsText(targetEntityInstance,
+ "link");
+ } else if ("customer".equalsIgnoreCase(parentEntityType) &&
+ targetEntityInstance.has("service-instance-id")){
+ targetEntityUrl += RouterServiceUtil.getNodeFieldAsText(targetEntityInstance,
+ "service-instance-id");
+ }
+
+ OxmEntityDescriptor searchableDescriptor =
+ oxmEntities.getSearchableEntityDescriptor(cerDescriptor.getTargetEntityType());
- if (!searchableDescriptor.getSearchableAttributes().isEmpty()) {
+ if (searchableDescriptor != null) {
- AaiEventEntity entityToSync = null;
+ if (!searchableDescriptor.getSearchableAttributes().isEmpty()) {
- try {
+ AaiEventEntity entityToSync = null;
- entityToSync = getPopulatedEntity(targetEntityInstance, searchableDescriptor);
+ try {
- /*
- * Ready to do some ElasticSearch ops
- */
+ entityToSync = getPopulatedEntity(targetEntityInstance, searchableDescriptor);
- for (String parentCrossEntityReferenceAttributeValue : extractedParentEntityAttributeValues) {
- entityToSync.addCrossEntityReferenceValue(parentCrossEntityReferenceAttributeValue);
- }
+ /*
+ * Ready to do some ElasticSearch ops
+ */
- entityToSync.setLink(targetEntityUrl);
- entityToSync.deriveFields();
+ for (String parentCrossEntityReferenceAttributeValue : extractedParentEntityAttributeValues) {
+ entityToSync
+ .addCrossEntityReferenceValue(parentCrossEntityReferenceAttributeValue);
+ }
- updateCerInEntity(entityToSync);
+ entityToSync.setLink(targetEntityUrl);
+ entityToSync.deriveFields();
- } catch (NoSuchAlgorithmException e) {
- logger.debug(e.getMessage());
- }
- }
- } else {
- logger.debug(EntityEventPolicyMsgs.CROSS_ENTITY_REFERENCE_SYNC,
- "failure to find searchable descriptor for type "
- + cerDescriptor.getTargetEntityType());
- }
- }
+ updateCerInEntity(entityToSync);
+ } catch (NoSuchAlgorithmException e) {
+ logger.debug(e.getMessage());
}
-
+ }
} else {
- logger.debug(EntityEventPolicyMsgs.CROSS_ENTITY_REFERENCE_SYNC,
- "failed to find 0 instances of cross-entity-reference with entity " + key);
+ logger.debug(EntityEventPolicyMsgs.CROSS_ENTITY_REFERENCE_SYNC,
+ "failure to find searchable descriptor for type "
+ + cerDescriptor.getTargetEntityType());
}
+ }
}
- } else {
- logger.info(EntityEventPolicyMsgs.FAILED_TO_PARSE_UEB_PAYLOAD, "Unable to get UEB object");
+
+ } else {
+ logger.debug(EntityEventPolicyMsgs.CROSS_ENTITY_REFERENCE_SYNC,
+ "failed to find 0 instances of cross-entity-reference with entity " + key);
+ }
+
}
} else {
- logger.info(EntityEventPolicyMsgs.CROSS_ENTITY_REFERENCE_SYNC, "skipped due to OXM model for "
- + topEntityType + " does not contain a cross-entity-reference entity");
+ logger.info(EntityEventPolicyMsgs.CROSS_ENTITY_REFERENCE_SYNC, "skipped due to OXM model for "
+ + topEntityType + " does not contain a cross-entity-reference entity");
}
/*
}
OxmEntityDescriptor desc = rootDescriptor.get(entityType);
-
+
if (desc == null) {
return Collections.emptyList();
}
if (HttpUtil.isHttpResponseClassSuccess(storedEntity.getResultCode())) {
/*
- * NOTES: aaiEventEntity (ie the nested entity) may contain a subset of properties of
- * the pre-existing object,
+ * NOTES: aaiEventEntity (ie the nested entity) may contain a subset of properties of
+ * the pre-existing object,
* so all we want to do is update the CER on the pre-existing object (if needed).
*/
-
+
List<String> etag = storedEntity.getHeaders().get(Headers.ETAG);
if (etag != null && !etag.isEmpty()) {
logger.error(EntityEventPolicyMsgs.NO_ETAG_AVAILABLE_FAILURE,
entitySearchIndex, entityId);
}
-
+
ArrayList<JsonNode> sourceObject = new ArrayList<>();
NodeUtils.extractObjectsByKey(
NodeUtils.convertJsonStrToJsonNode(storedEntity.getResult()),
if (!sourceObject.isEmpty()) {
JsonNode node = sourceObject.get(0);
- final String sourceCer = NodeUtils.extractFieldValueFromObject(node,
+ final String sourceCer = NodeUtils.extractFieldValueFromObject(node,
"crossEntityReferenceValues");
String newCer = aaiEventEntity.getCrossReferenceEntityValues();
boolean hasNewCer = true;
hasNewCer = false;
}
}
-
+
if (hasNewCer){
// Do the PUT with new CER
((ObjectNode)node).put("crossEntityReferenceValues", newCer);
/**
* Perform create, read, update or delete (CRUD) operation on search engine's suggestive search
* index
- *
+ *
* @param eventEntity Entity/data to use in operation
* @param action The operation to perform
* @param target Resource to perform the operation on
* @param allowDeleteEvent Allow delete operation to be performed on resource
*/
- protected void handleSearchServiceOperation(DocumentStoreDataEntity eventEntity,
+ protected void handleSearchServiceOperation(DocumentStoreDataEntity eventEntity,
String action,
String index) {
try {
} else if (action.equalsIgnoreCase(ACTION_CREATE)) {
// Write the entry to the search service.
searchAgent.postDocument(index, eventEntity.getAsJson(), headers);
-
+
} else if (action.equalsIgnoreCase(ACTION_DELETE)) {
// Run the GET to retrieve the ETAG from the search service
OperationResult storedEntity = searchAgent.getDocument(index, entityId);
logger.error(EntityEventPolicyMsgs.NO_ETAG_AVAILABLE_FAILURE, index,
entityId);
}
-
+
/*
* The Spring-Boot version of the search-data-service rejects the DELETE operation unless
* we specify a Content-Type.
// put this here until we find a better spot
/**
* Helper utility to concatenate substrings of a URI together to form a proper URI.
- *
+ *
* @param suburis the list of substrings to concatenate together
* @return the concatenated list of substrings
*/
*/
package org.onap.aai.datarouter.policy;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
+
public class EntityEventPolicyConfig {
private String sourceDomain;
private String searchCertName;
private String searchKeystorePwd;
private String searchKeystore;
+ private SchemaVersions schemaVersions;
+ private SchemaLocationsBean schemaLocationsBean;
public String getSourceDomain() {
public void setSearchAggregationVnfIndex(String searchAggregationVnfIndex) {
this.searchAggregationVnfIndex = searchAggregationVnfIndex;
}
+
+ public SchemaVersions getSchemaVersions() {
+ return schemaVersions;
+ }
+
+ public void setSchemaVersions(SchemaVersions schemaVersions) {
+ this.schemaVersions = schemaVersions;
+ }
+
+ public SchemaLocationsBean getSchemaLocationsBean() {
+ return schemaLocationsBean;
+ }
+
+ public void setSchemaLocationsBean(SchemaLocationsBean schemaLocationsBean) {
+ this.schemaLocationsBean = schemaLocationsBean;
+ }
}
package org.onap.aai.datarouter.policy;
import java.io.FileNotFoundException;
-import java.util.ArrayList;
import java.util.List;
import org.apache.camel.Exchange;
import org.onap.aai.datarouter.entity.SpikeAggregationEntity;
import org.onap.aai.datarouter.entity.SpikeEventMeta;
import org.onap.aai.datarouter.logging.EntityEventPolicyMsgs;
-import org.onap.aai.util.EntityOxmReferenceHelper;
-import org.onap.aai.util.Version;
-import org.onap.aai.util.VersionedOxmEntities;
import com.fasterxml.jackson.databind.JsonNode;
// Create the indexes in the search service if they do not already exist.
searchAgent.createSearchIndex(searchIndexName, searchIndexSchema, createIndexUrl);
logger.info(EntityEventPolicyMsgs.ENTITY_EVENT_POLICY_REGISTERED);
-
}
-
+
@Override
public void process(Exchange exchange) throws Exception {
long startTime = System.currentTimeMillis();
SpikeEventMeta meta = processSpikeEvent(exchange);
-
+
if (meta == null) {
return;
}
String oxmEntityType = getOxmEntityType(meta.getSpikeEventVertex().getType());
-
- VersionedOxmEntities oxmEntities =
- EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion.toLowerCase()));
-
- List<String> suggestibleAttrInPayload = new ArrayList<>();
- List<String> suggestibleAttrInOxm = extractSuggestableAttr(oxmEntities, meta.getSpikeEventVertex().getType());
- if (suggestibleAttrInOxm != null) {
- for (String attr: suggestibleAttrInOxm){
- if (meta.getVertexProperties().has(attr)) {
- suggestibleAttrInPayload.add(attr);
- }
- }
- }
- if (suggestibleAttrInPayload.isEmpty()) {
+ List<String> searchableAttr = getSearchableAttibutes(meta.getOxmJaxbContext(), oxmEntityType,
+ meta.getSpikeEventVertex().getType(), meta.getEventEntity().toString(), exchange);
+
+ if (searchableAttr == null) {
return;
}
return;
}
+ public List<String> extractSuggestableAttr(VersionedOxmEntities oxmEntities, String entityType) {
+ // Extract suggestable attributeshandleTopographicalData
+ Map<String, OxmEntityDescriptor> rootDescriptor = oxmEntities.getSuggestableEntityDescriptors();
+
+ if (rootDescriptor == null) {
+ return Collections.emptyList();
+ }
+
+ OxmEntityDescriptor desc = rootDescriptor.get(entityType);
+
+ if (desc == null) {
+ return Collections.emptyList();
+ }
+
+ return desc.getSuggestableAttributes();
+ }
+
public List<String> extractAliasForSuggestableEntity(VersionedOxmEntities oxmEntities,
String entityType) {
import org.onap.aai.util.EntityOxmReferenceHelper;
import org.onap.aai.util.ExternalOxmModelProcessor;
import org.onap.aai.schema.OxmModelLoader;
+import org.onap.aai.setup.SchemaVersions;
import org.onap.aai.restclient.client.Headers;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.restclient.rest.HttpUtil;
private Logger logger;
private Logger metricsLogger;
-
+
public enum ResponseType {
SUCCESS, PARTIAL_SUCCESS, FAILURE;
};
this.externalOxmModelProcessors = new ArrayList<>();
this.externalOxmModelProcessors.add(EntityOxmReferenceHelper.getInstance());
OxmModelLoader.registerExternalOxmModelProcessors(externalOxmModelProcessors);
- OxmModelLoader.loadModels();
+ OxmModelLoader.loadModels(config.getSchemaVersions(), config.getSchemaLocationsBean());
oxmVersionContextMap = OxmModelLoader.getVersionContextMap();
parseLatestOxmVersion();
}
*/
package org.onap.aai.datarouter.policy;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
+
public class SpikeEntityEventPolicyConfig {
private String sourceDomain;
private String searchCertName;
private String searchKeystorePwd;
private String searchKeystore;
-
+ private SchemaVersions schemaVersions;
+ private SchemaLocationsBean schemaLocationsBean;
public String getSourceDomain() {
return sourceDomain;
public void setSearchKeystorePwd(String searchKeystorePwd) {
this.searchKeystorePwd = searchKeystorePwd;
}
+
+ public SchemaVersions getSchemaVersions() {
+ return schemaVersions;
+ }
+
+ public void setSchemaVersions(SchemaVersions schemaVersions) {
+ this.schemaVersions = schemaVersions;
+ }
+
+ public SchemaLocationsBean getSchemaLocationsBean() {
+ return schemaLocationsBean;
+ }
+
+ public void setSchemaLocationsBean(SchemaLocationsBean schemaLocationsBean) {
+ this.schemaLocationsBean = schemaLocationsBean;
+ }
}
*/
package org.onap.aai.datarouter.policy;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
+
public class SpikeEventPolicyConfig {
private String sourceDomain;
private String searchCertName;
private String searchKeystorePwd;
private String searchKeystore;
-
+ private SchemaVersions schemaVersions;
+ private SchemaLocationsBean schemaLocationsBean;
public String getSourceDomain() {
return sourceDomain;
public void setSearchKeystorePwd(String searchKeystorePwd) {
this.searchKeystorePwd = searchKeystorePwd;
}
+
+ public SchemaVersions getSchemaVersions() {
+ return schemaVersions;
+ }
+
+ public void setSchemaVersions(SchemaVersions schemaVersions) {
+ this.schemaVersions = schemaVersions;
+ }
+
+ public SchemaLocationsBean getSchemaLocationsBean() {
+ return schemaLocationsBean;
+ }
+
+ public void setSchemaLocationsBean(SchemaLocationsBean schemaLocationsBean) {
+ this.schemaLocationsBean = schemaLocationsBean;
+ }
}
*/
package org.onap.aai.datarouter.policy;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
-import org.onap.aai.datarouter.policy.EntityEventPolicy;
-import org.onap.aai.datarouter.policy.EntityEventPolicyConfig;
+import org.junit.runner.RunWith;
import org.onap.aai.datarouter.util.NodeUtils;
-import org.onap.aai.datarouter.util.SearchServiceAgent;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
import org.powermock.api.mockito.PowerMockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("file:src/test/resources/spring-beans/data-router-oxm.xml")
public class EntityEventPolicyTest {
- private EntityEventPolicy policy;
- private String eventJson;
- private InMemorySearchDatastore searchDb;
-
- @SuppressWarnings("unchecked")
- @Before
- public void init() throws Exception {
- EntityEventPolicyConfig config = PowerMockito.mock(EntityEventPolicyConfig.class);
- PowerMockito.when(config.getSearchKeystorePwd()).thenReturn("password");
- PowerMockito.when(config.getSourceDomain()).thenReturn("JUNIT");
-
- searchDb = new InMemorySearchDatastore();
- policy = new EntityEventPolicyStubbed(config).withSearchDb(searchDb);
-
- FileInputStream event = new FileInputStream( new File("src/test/resources/aai_event.json"));
- eventJson = IOUtils.toString(event, "UTF-8");
-
- }
-
- @Test
- public void testProcess() throws Exception {
- policy.process(getExchangeEvent("event1","create"));
- policy.process(getExchangeEvent("event2","create"));
-
- assertNotNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event1")));
- assertNotNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event2")));
-
- policy.process(getExchangeEvent("event1","update"));
- policy.process(getExchangeEvent("event2","update"));
- assertNotNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event1")));
- assertNotNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event2")));
-
- policy.process(getExchangeEvent("event2","delete"));
- assertNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event2")));
- }
-
- private Exchange getExchangeEvent(String link,String action){
- Object obj = eventJson.replace("$LINK",link ).replace("$ACTION",action) ;
- Exchange exchange = PowerMockito.mock(Exchange.class);
- Message inMessage = PowerMockito.mock(Message.class);
- Message outMessage = PowerMockito.mock(Message.class);
- PowerMockito.when(exchange.getIn()).thenReturn(inMessage);
- PowerMockito.when(inMessage.getBody()).thenReturn(obj);
-
- PowerMockito.when(exchange.getOut()).thenReturn(outMessage);
- PowerMockito.doNothing().when(outMessage).setBody(anyObject());
- PowerMockito.doNothing().when(outMessage).setHeader(anyString(), anyObject());
-
- return exchange;
-
- }
-
-
+ private EntityEventPolicyConfig eventPolicyConfig;
+ private EntityEventPolicy policy;
+ private String eventJson;
+ private InMemorySearchDatastore searchDb;
+
+ @Autowired
+ private SchemaVersions schemaVersions;
+ @Autowired
+ private SchemaLocationsBean schemaLocationsBean;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void init() throws Exception {
+ eventPolicyConfig = new EntityEventPolicyConfig();
+ eventPolicyConfig.setSearchKeystorePwd("password");
+ eventPolicyConfig.setSourceDomain("JUNIT");
+
+ eventPolicyConfig.setSchemaVersions(schemaVersions);
+ eventPolicyConfig.setSchemaLocationsBean(schemaLocationsBean);
+
+ searchDb = new InMemorySearchDatastore();
+ policy = new EntityEventPolicyStubbed(eventPolicyConfig).withSearchDb(searchDb);
+
+ FileInputStream event = new FileInputStream(new File("src/test/resources/aai_event.json"));
+ eventJson = IOUtils.toString(event, "UTF-8");
+
+ }
+
+ @Test
+ public void testProcess() throws Exception {
+ policy.process(getExchangeEvent("event1", "create"));
+ policy.process(getExchangeEvent("event2", "create"));
+
+ assertNotNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event1")));
+ assertNotNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event2")));
+
+ policy.process(getExchangeEvent("event1", "update"));
+ policy.process(getExchangeEvent("event2", "update"));
+ assertNotNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event1")));
+ assertNotNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event2")));
+
+ policy.process(getExchangeEvent("event2", "delete"));
+ assertNull(searchDb.get(NodeUtils.generateUniqueShaDigest("event2")));
+ }
+
+ private Exchange getExchangeEvent(String link, String action) {
+ Object obj = eventJson.replace("$LINK", link).replace("$ACTION", action);
+ Exchange exchange = PowerMockito.mock(Exchange.class);
+ Message inMessage = PowerMockito.mock(Message.class);
+ Message outMessage = PowerMockito.mock(Message.class);
+ PowerMockito.when(exchange.getIn()).thenReturn(inMessage);
+ PowerMockito.when(inMessage.getBody()).thenReturn(obj);
+
+ PowerMockito.when(exchange.getOut()).thenReturn(outMessage);
+ PowerMockito.doNothing().when(outMessage).setBody(anyObject());
+ PowerMockito.doNothing().when(outMessage).setHeader(anyString(), anyObject());
+
+ return exchange;
+
+ }
+
+
}
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.onap.aai.datarouter.util.NodeUtils;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
import org.powermock.api.mockito.PowerMockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("file:src/test/resources/spring-beans/data-router-oxm.xml")
public class SpikeAggregateGenericVnfProcessorTest {
+ private SpikeEventPolicyConfig eventPolicyConfig;
private SpikeAggregateGenericVnfProcessor policy;
private InMemorySearchDatastore searchDb;
+ @Autowired
+ private SchemaVersions schemaVersions;
+ @Autowired
+ private SchemaLocationsBean schemaLocationsBean;
+
@Before
public void init() throws Exception {
- SpikeEventPolicyConfig config = PowerMockito.mock(SpikeEventPolicyConfig.class);
- PowerMockito.when(config.getSearchKeystorePwd()).thenReturn("password");
- PowerMockito.when(config.getSourceDomain()).thenReturn("JUNIT");
+ eventPolicyConfig = new SpikeEventPolicyConfig();
+ eventPolicyConfig.setSearchKeystorePwd("password");
+ eventPolicyConfig.setSourceDomain("JUNIT");
+
+ eventPolicyConfig.setSchemaVersions(schemaVersions);
+ eventPolicyConfig.setSchemaLocationsBean(schemaLocationsBean);
searchDb = new InMemorySearchDatastore();
- policy = new SpikeAggregateGenericVnfProcessorStubbed(config).withSearchDb(searchDb);
+ policy = new SpikeAggregateGenericVnfProcessorStubbed(eventPolicyConfig).withSearchDb(searchDb);
}
@Test
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.onap.aai.datarouter.util.NodeUtils;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
import org.powermock.api.mockito.PowerMockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("file:src/test/resources/spring-beans/data-router-oxm.xml")
public class SpikeAutosuggestProcessorTest {
private SpikeEventPolicyConfig eventPolicyConfig;
private SpikeAutosuggestIndexProcessor policy;
private InMemorySearchDatastore searchDb;
+ @Autowired
+ private SchemaVersions schemaVersions;
+ @Autowired
+ private SchemaLocationsBean schemaLocationsBean;
+
@Before
public void init() throws Exception {
eventPolicyConfig.setSearchKeystorePwd("password");
eventPolicyConfig.setSourceDomain("JUNIT");
+ eventPolicyConfig.setSchemaVersions(schemaVersions);
+ eventPolicyConfig.setSchemaLocationsBean(schemaLocationsBean);
+
searchDb = new InMemorySearchDatastore();
policy = new SpikeAutosuggestProcessorStubbed(eventPolicyConfig).withSearchDb(searchDb);
*/
package org.onap.aai.datarouter.policy;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.onap.aai.datarouter.util.NodeUtils;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
import org.powermock.api.mockito.PowerMockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("file:src/test/resources/spring-beans/data-router-oxm.xml")
public class SpikeEntityEventPolicyTest {
private SpikeEntityEventPolicyConfig eventPolicyConfig;
private SpikeEntityEventPolicy policy;
private InMemorySearchDatastore searchDb;
+ @Autowired
+ private SchemaVersions schemaVersions;
+ @Autowired
+ private SchemaLocationsBean schemaLocationsBean;
@Before
public void init() throws Exception {
eventPolicyConfig = new SpikeEntityEventPolicyConfig();
eventPolicyConfig.setSearchKeystorePwd("password");
eventPolicyConfig.setSourceDomain("JUNIT");
+
+ eventPolicyConfig.setSchemaVersions(schemaVersions);
+ eventPolicyConfig.setSchemaLocationsBean(schemaLocationsBean);
searchDb = new InMemorySearchDatastore();
policy = new SpikeEntityEventPolicyStubbed(eventPolicyConfig).withSearchDb(searchDb);
import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.onap.aai.datarouter.util.NodeUtils;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersions;
import org.powermock.api.mockito.PowerMockito;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("file:src/test/resources/spring-beans/data-router-oxm.xml")
public class SpikeEntitySearchProcessorTest {
+ private SpikeEventPolicyConfig eventPolicyConfig;
private SpikeEntitySearchProcessor policy;
private String eventJson;
private InMemorySearchDatastore searchDb;
+ @Autowired
+ private SchemaVersions schemaVersions;
+ @Autowired
+ private SchemaLocationsBean schemaLocationsBean;
+
@Before
public void init() throws Exception {
- SpikeEventPolicyConfig config = PowerMockito.mock(SpikeEventPolicyConfig.class);
- PowerMockito.when(config.getSearchKeystorePwd()).thenReturn("password");
- PowerMockito.when(config.getSourceDomain()).thenReturn("JUNIT");
+ eventPolicyConfig = new SpikeEventPolicyConfig();
+ eventPolicyConfig.setSearchKeystorePwd("password");
+ eventPolicyConfig.setSourceDomain("JUNIT");
+
+ eventPolicyConfig.setSchemaVersions(schemaVersions);
+ eventPolicyConfig.setSchemaLocationsBean(schemaLocationsBean);
searchDb = new InMemorySearchDatastore();
- policy = new SpikeEntitySearchProcessorStubbed(config).withSearchDb(searchDb);
+ policy = new SpikeEntitySearchProcessorStubbed(eventPolicyConfig).withSearchDb(searchDb);
}
--- /dev/null
+# Properties for the SchemaLocationsBean
+# Properties required by the aai-common - aai-schema-ingest lib as of 1.3.0
+schema.configuration.location=N/A
+schema.nodes.location=src/test/resources/oxm-reader/oxm
+schema.edges.location=
+# These versions need to exist if they are included in the list
+schema.version.list=v8,v9,v10,v11,v12,v13
+# Decalares the oxm version to load
+schema.version.api.default=v13
+
+# Don't use these properties in our application, need to be set to prevent an exception on startup (see SchemaVersions bean)
+schema.version.depth.start=v13
+schema.version.related.link.start=v13
+schema.version.app.root.start=v13
+schema.version.namespace.change.start=v13
+schema.version.edge.label.start=v13
\ No newline at end of file
--- /dev/null
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:task="http://www.springframework.org/schema/task"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
+ http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
+
+ <context:property-placeholder location="file:src/test/resources/config/schemaIngest.properties" ignore-unresolvable="true" />
+
+ <bean id="schemaVersions" class="org.onap.aai.setup.SchemaVersions"/>
+
+ <bean id="schemaLocationsBean" class="org.onap.aai.setup.SchemaLocationsBean"/>
+
+</beans>