summaryrefslogtreecommitdiffstats
path: root/catalog-dao/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-dao/src/main')
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java18
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/BasicDao.java176
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericIdDAO.java163
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericSearchDAO.java130
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IBasicDAO.java64
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ICatalogDAO.java71
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IEsHealthCheckDao.java29
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IGenericIdDAO.java66
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IResourceDAO.java56
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ResourceUploadStatus.java25
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java12
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCacheAccessor.java (renamed from catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTable.java)51
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleAccessor.java (renamed from catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IPropertyDAO.java)20
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleDao.java89
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java7
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java2
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java54
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java137
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java4
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ConsumerEventTableDefinition.java101
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/FeatureToggleEventTableDesc.java97
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/config/DAOSpringConfig.java4
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/es/ElasticSearchClient.java191
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/GraphElementFactory.java11
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java17
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/AuditingDao.java254
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESCatalogDAO.java205
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESTimeBasedDao.java298
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/EsHealthCheckDao.java49
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/MonitoringDao.java41
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jElementDAO.java107
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jPropertyDAO.java49
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jResourceDAO.java217
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java165
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphClient.java8
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java50
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/GraphVertex.java10
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/HealingJanusGraphDao.java4
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java69
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java50
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTemplates.java52
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTranslator.java251
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java302
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionaryExtractor.java188
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jClient.java983
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java73
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jGraphBatchBuilder.java179
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatus.java77
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java70
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/MatchFilter.java51
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveByRelationFilter.java81
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveFilter.java68
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/UpdateFilter.java56
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/dao/utils/ElasticSearchUtil.java48
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/api/IResourceUploader.java70
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentCacheData.java153
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentMetadataData.java67
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ConsumerData.java148
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/DAOArtifactData.java (renamed from catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ESArtifactData.java)10
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ProductMetadataData.java17
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ResourceMetadataData.java22
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceArtifactsDataCollection.java45
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceMetadataData.java11
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingActionEnum.java2
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEvent.java37
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingTypesConstants.java1
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/EcompOperationalEnvironmentEvent.java3
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/ResourceAdminEvent.java2
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java120
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/ToggleableFeature.java (renamed from catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IGenericSearchDAO.java)41
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/exception/ResourceDAOException.java58
-rw-r--r--catalog-dao/src/main/java/org/openecomp/sdc/be/resources/impl/ResourceUploader.java172
72 files changed, 1299 insertions, 5330 deletions
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
index dc4da54ff6..bbd9db3a7b 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ActionStatus.java
@@ -31,7 +31,7 @@ public enum ActionStatus {
// Resource related
RESOURCE_NOT_FOUND, MISSING_DERIVED_FROM_TEMPLATE, PARENT_RESOURCE_NOT_FOUND, PARENT_RESOURCE_DOES_NOT_EXTEND, INVALID_DEFAULT_VALUE, INVALID_COMPLEX_DEFAULT_VALUE, MULTIPLE_PARENT_RESOURCE_FOUND, INVALID_RESOURCE_PAYLOAD, INVALID_TOSCA_FILE_EXTENSION, INVALID_YAML_FILE, INVALID_TOSCA_TEMPLATE, NOT_RESOURCE_TOSCA_TEMPLATE, NOT_SINGLE_RESOURCE, INVALID_RESOURCE_NAMESPACE, RESOURCE_ALREADY_EXISTS, INVALID_RESOURCE_CHECKSUM, RESOURCE_CANNOT_CONTAIN_RESOURCE_INSTANCES, NO_ASSETS_FOUND, GENERIC_TYPE_NOT_FOUND, INVALID_RESOURCE_TYPE, TOSCA_PARSE_ERROR,
// Service related
- SERVICE_TYPE_EXCEEDS_LIMIT, INVALID_SERVICE_TYPE, SERVICE_ROLE_EXCEEDS_LIMIT, INVALID_SERVICE_ROLE, INVALID_INSTANTIATION_TYPE,
+ UNSUPPORTED_DISTRIBUTION_STATUS, INVALID_NAMING_POLICY, INVALID_ENVIRONMENT_CONTEXT, NAMING_POLICY_EXCEEDS_LIMIT, MISSING_ECOMP_GENERATED_NAMING, PROPERTY_EXCEEDS_LIMIT, INVALID_PROPERY, INVALID_INSTANTIATION_TYPE,
// Component name related
COMPONENT_NAME_ALREADY_EXIST, COMPONENT_NAME_EXCEEDS_LIMIT, MISSING_COMPONENT_NAME, INVALID_COMPONENT_NAME,
// Component description related
@@ -51,7 +51,7 @@ public enum ActionStatus {
// Service API URL
INVALID_SERVICE_API_URL,
// Property related
- PROPERTY_ALREADY_EXIST, PROPERTY_NAME_ALREADY_EXISTS, PROPERTY_NOT_FOUND, INVALID_PROPERTY, INVALID_PROPERTY_TYPE, INVALID_PROPERTY_INNER_TYPE,
+ PROPERTY_ALREADY_EXIST, PROPERTY_NAME_ALREADY_EXISTS, PROPERTY_NOT_FOUND, INVALID_PROPERTY, INVALID_PROPERTY_TYPE, INVALID_PROPERTY_INNER_TYPE, MISSING_PROPERTY_NAME, MISSING_PROPERTY_VALUE,
// Attribute related
ATTRIBUTE_ALREADY_EXIST, ATTRIBUTE_NOT_FOUND,
// State related
@@ -119,6 +119,7 @@ public enum ActionStatus {
COMPONENT_IS_NOT_HIHGEST_CERTIFIED,
NO_INSTANCES_TO_UPGRADE,
ARCHIVED_ORIGINS_FOUND,
+ UPDATE_CATALOG_FAILED,
//Interface
INTERFACE_NOT_FOUND_IN_COMPONENT,
@@ -151,6 +152,15 @@ public enum ActionStatus {
INVALID_PROPERTY_NAME,
+ //Property Constraints
+ INVALID_PROPERTY_CONSTRAINTS, INVALID_PROPERTY_CONSTRAINTS_FORMAT, CANNOT_DELETE_VALID_VALUES,
+
+ //Container
+ CONTAINER_CANNOT_CONTAIN_COMPONENT_IN_STATE,
+ CONTAINER_CANNOT_CONTAIN_INSTANCE,
+ MISSING_MANDATORY_PROPERTY,
+ MANDATORY_PROPERTY_MISSING_VALUE,
+
//Capability related
CAPABILITY_NOT_FOUND, CAPABILITY_NAME_MANDATORY, CAPABILITY_TYPE_MANDATORY,CAPABILITY_NAME_ALREADY_IN_USE,
MAX_OCCURRENCES_SHOULD_BE_GREATER_THAN_MIN_OCCURRENCES, CAPABILITY_DELETION_NOT_ALLOWED_USED_IN_COMPOSITION,
@@ -164,4 +174,6 @@ public enum ActionStatus {
REQUIREMENT_NOT_FOUND, REQUIREMENT_NAME_MANDATORY, REQUIREMENT_CAPABILITY_MANDATORY,REQUIREMENT_NAME_ALREADY_IN_USE,
REQUIREMENT_DELETION_NOT_ALLOWED_USED_IN_COMPOSITION, REQUIREMENT_UPDATE_NOT_ALLOWED_USED_IN_COMPOSITION, INVALID_REQUIREMENT_NAME
;
-}
+
+
+ }
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/BasicDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/BasicDao.java
deleted file mode 100644
index cccb7d0b4b..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/BasicDao.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.api;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElement;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
-import org.openecomp.sdc.be.dao.impl.Neo4jResourceDAO;
-import org.openecomp.sdc.be.dao.neo4j.*;
-import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-public abstract class BasicDao implements IBasicDAO {
-
- Neo4jGraphBatchBuilder graphBatchBuilder = new Neo4jGraphBatchBuilder();
-
- Neo4jClient neo4jClient;
-
- private static Logger logger = Logger.getLogger(Neo4jResourceDAO.class.getName());
-
- public <T extends GraphNode> Either<T, Neo4jOperationStatus> create(GraphNeighbourTable graphNeighbourTable,
- Class<T> clazz, NodeTypeEnum nodeType) {
-
- if (graphNeighbourTable != null) {
-
- Either<BatchBuilder, Neo4jOperationStatus> bbResult = graphBatchBuilder
- .buildBatchBuilderFromTable(graphNeighbourTable);
-
- if (bbResult.isLeft()) {
-
- BatchBuilder batchBuilder = bbResult.left().value();
- // Neo4jOperationStatus neo4jOperationStatus =
- // neo4jClient.execute(batchBuilder);
- Either<List<List<GraphElement>>, Neo4jOperationStatus> executeResult = neo4jClient
- .execute(batchBuilder);
-
- if (executeResult.isRight()) {
- return Either.right(executeResult.right().value());
- }
-
- T result = null;
- List<List<GraphElement>> listOfResults = executeResult.left().value();
- if (listOfResults != null) {
- for (List<GraphElement> listOfElements : listOfResults) {
- if (listOfElements != null && !listOfElements.isEmpty()) {
- for (GraphElement element : listOfElements) {
- logger.debug("element {} was returned after running batch operation {}",
- element, batchBuilder);
- if (element instanceof GraphNode) {
- GraphNode neo4jNode = (GraphNode) element;
- if (NodeTypeEnum.getByName(neo4jNode.getLabel()) == nodeType) {
- result = clazz.cast(neo4jNode);
- }
- }
- }
- }
- }
- }
-
- return Either.left(result);
-
- } else {
- return Either.right(bbResult.right().value());
- }
-
- } else {
- logger.error("The table sent in order to create resource is empty.");
- return Either.right(Neo4jOperationStatus.BAD_REQUEST);
- }
-
- }
-
- @Override
- public <T extends GraphNode> Either<T, Neo4jOperationStatus> getNodeData(String uniqueid, Class<T> clazz,
- NodeTypeEnum nodeTypeEnum) {
-
- MatchFilter filter = new MatchFilter();
- filter.addToMatch(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), uniqueid);
-
- return getNodeData(filter, clazz, nodeTypeEnum);
-
- }
-
- @Override
- public <T extends GraphNode> Either<T, Neo4jOperationStatus> getNodeData(String keyName, String uniqueid,
- Class<T> clazz, NodeTypeEnum nodeTypeEnum) {
-
- MatchFilter filter = new MatchFilter();
- filter.addToMatch(keyName, uniqueid);
-
- return getNodeData(filter, clazz, nodeTypeEnum);
-
- }
-
- private <T extends GraphNode> Either<T, Neo4jOperationStatus> getNodeData(MatchFilter filter, Class<T> clazz,
- NodeTypeEnum nodeTypeEnum) {
-
- Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
- nodeTypeEnum.getName(), filter);
-
- if (status.isRight()) {
- return Either.right(status.right().value());
- } else {
- List<GraphElement> value = status.left().value();
- if (value == null || value.isEmpty()) {
- return Either.right(Neo4jOperationStatus.NOT_FOUND);
- } else {
- return Either.left(clazz.cast(value.get(0)));
- }
- }
- }
-
- @Override
- public <T extends GraphNode> Either<List<T>, Neo4jOperationStatus> getNodesData(
- Map<String, Object> propertiesToMatch, Class<T> clazz, NodeTypeEnum nodeTypeEnum) {
-
- MatchFilter filter = new MatchFilter();
- if (propertiesToMatch != null) {
- for (Entry<String, Object> property : propertiesToMatch.entrySet()) {
- filter.addToMatch(property.getKey(), property.getValue());
- }
- }
-
- Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
- nodeTypeEnum.getName(), filter);
-
- if (status.isRight()) {
- return Either.right(status.right().value());
- } else {
- List<GraphElement> value = status.left().value();
- if (value == null || value.isEmpty()) {
- return Either.right(Neo4jOperationStatus.NOT_FOUND);
- } else {
- List<T> list = new ArrayList<>();
- for (GraphElement element : value) {
- list.add(clazz.cast(element));
- }
- return Either.left(list);
- }
- }
- }
-
- public Neo4jClient getNeo4jClient() {
- return neo4jClient;
- }
-
- public void setNeo4jClient(Neo4jClient neo4jClient) {
- this.neo4jClient = neo4jClient;
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericIdDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericIdDAO.java
deleted file mode 100644
index 9c534d0be8..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericIdDAO.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.api;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
-import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
-import org.elasticsearch.action.get.GetResponse;
-import org.elasticsearch.action.get.MultiGetItemResponse;
-import org.elasticsearch.action.get.MultiGetResponse;
-import org.elasticsearch.client.Client;
-import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.openecomp.sdc.exception.IndexingServiceException;
-
-import javax.annotation.Resource;
-import java.io.IOException;
-import java.util.*;
-
-public abstract class ESGenericIdDAO implements IGenericIdDAO {
-
- private static Logger log = Logger.getLogger(ESGenericIdDAO.class.getName());
-
- @Resource(name = "elasticsearch-client")
- private ElasticSearchClient esClient;
-
- private ObjectMapper jsonMapper = new ObjectMapper();
- private final Map<String, String> typesToIndices = new HashMap<>();
-
- public Client getClient() {
- return this.esClient.getClient();
- }
-
- public ElasticSearchClient getEsClient() {
- return esClient;
- }
-
- public ObjectMapper getJsonMapper() {
- return jsonMapper;
- }
-
- public void setJsonMapper(ObjectMapper jsonMapper) {
- this.jsonMapper = jsonMapper;
- }
-
- public void addToIndicesMap(String type, String index) {
- typesToIndices.put(type, index);
- }
-
- public String getIndexForType(String type) {
- return typesToIndices.get(type);
- }
-
- @Override
- public <T> T findById(String typeName, String id, Class<T> clazz) {
-
- String indexName = getIndexForType(typeName);
- GetResponse response = getClient().prepareGet(indexName, typeName, id).execute().actionGet();
-
- if (response == null || !response.isExists()) {
- log.debug("Nothing found in index <{}>, type <{}>, for Id <{}>.", indexName, typeName, id);
- return null;
- }
-
- log.debug("Found one in index <{}>, type <{}>, for Id <{}>.", indexName, typeName, id);
-
- T ret = null;
- try {
- ret = jsonMapper.readValue(response.getSourceAsString(), clazz);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return ret;
- }
-
- @Override
- public <T> List<T> findByIds(String typeName, Class<T> clazz, String... ids) {
- String indexName = getIndexForType(typeName);
- MultiGetResponse response = getClient().prepareMultiGet().add(indexName, typeName, ids).execute().actionGet();
-
- if (response == null || response.getResponses() == null || response.getResponses().length == 0) {
- log.debug("Nothing found in index <{}>, type <{}>, for Ids <{}>.", indexName, typeName,
- Arrays.toString(ids));
- return null;
- }
-
- List<T> result = new ArrayList<>();
- for (MultiGetItemResponse getItemResponse : response.getResponses()) {
- if (getItemResponse.getResponse().isExists()) {
- T val = null;
- try {
- val = jsonMapper.readValue(getItemResponse.getResponse().getSourceAsString(), clazz);
- result.add(val);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- return result;
- }
-
- protected void saveResourceData(String typeName, Object data, String id) throws JsonProcessingException {
- String indexName = getIndexForType(typeName);
-
- log.debug("ESGenericIdDAO saveResourceData resource indexName: {} | typeName is: {}", indexName, typeName);
-
- String json = getJsonMapper().writeValueAsString(data);
- log.debug("ESGenericIdDAO saveResourceData resource id is: {}", id);
- try {
- getClient().prepareIndex(indexName, typeName, id).setSource(json).setRefresh(true).execute().actionGet();
- } catch (Exception e) {
- log.error("failed to write data with id {} to elasticsearch type {}. error: {}", id, typeName,
- e.getMessage(), e);
- throw e;
- }
- }
-
- @Override
- public void delete(String typeName, String id) {
- assertIdNotNullFor(id, "delete");
- String indexName = getIndexForType(typeName);
- getClient().prepareDelete(indexName, typeName, id).setRefresh(true).execute().actionGet();
- }
-
- public void deleteIndex(String indexName) {
- DeleteIndexResponse actionGet = getClient().admin().indices().delete(new DeleteIndexRequest(indexName))
- .actionGet();
- if (!actionGet.isAcknowledged()) {
- log.error("failed to delete index {}", indexName);
- }
- }
-
- private void assertIdNotNullFor(String id, String operation) {
- if (id == null || id.trim().isEmpty()) {
- log.error("Null or empty Id is not allowed for operation <{}>.", operation);
- throw new IndexingServiceException("Null or empty Id is not allowed for operation <" + operation + ">.");
- }
- }
-
- public static String indexTypeFromClass(Class<?> clazz) {
- return clazz.getSimpleName().toLowerCase();
- }
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericSearchDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericSearchDAO.java
deleted file mode 100644
index 4dc57201fb..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ESGenericSearchDAO.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.api;
-
-import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.search.sort.SortBuilder;
-import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
-
-import javax.annotation.Resource;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Elastic search dao that manages search operations.
- *
- * @author luc boutier
- */
-public class ESGenericSearchDAO extends ESGenericIdDAO implements IGenericSearchDAO {
-
- private static final int MAX_SEARCH_SIZE = 1000;
-
- @Resource(name = "elasticsearch-client")
- private ElasticSearchClient esClient;
-
- @Override
- public long count(String indexName, String typeName, QueryBuilder query) {
-
- SearchRequestBuilder searchRequestBuilder = esClient.getClient().prepareSearch(indexName).setTypes(typeName)
- .setSize(0);
- if (query != null) {
- searchRequestBuilder.setQuery(query);
- }
-
- SearchResponse response = searchRequestBuilder.execute().actionGet();
- if (!somethingFound(response)) {
- return 0;
- } else {
- return response.getHits().getTotalHits();
- }
- }
-
- /**
- * Convert a SearchResponse into a list of objects (json deserialization.)
- *
- * @param searchResponse
- * The actual search response from elastic-search.
- * @param clazz
- * The type of objects to de-serialize.
- * @return A list of instances that contains de-serialized data.
- */
- public <T> List<T> toGetListOfData(SearchResponse searchResponse, Class<T> clazz) {
- // return null if no data has been found in elastic search.
- if (!somethingFound(searchResponse)) {
- return null;
- }
-
- List<T> result = new ArrayList<>();
-
- for (int i = 0; i < searchResponse.getHits().getHits().length; i++) {
- try {
- result.add(getJsonMapper().readValue(searchResponse.getHits().getAt(i).getSourceAsString(), clazz));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- return result;
- }
-
- public <T> List<T> doCustomFind(Class<T> clazz, String indexName, String typeName, QueryBuilder query,
- SortBuilder sortBuilder) {
-
- List<T> result = new ArrayList<>();
- SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(indexName).setTypes(typeName)
- .setSize(MAX_SEARCH_SIZE);
- if (query != null) {
- searchRequestBuilder.setQuery(query);
- }
- if (sortBuilder != null) {
- searchRequestBuilder.addSort(sortBuilder);
- }
- SearchResponse response = searchRequestBuilder.execute().actionGet();
- if (!somethingFound(response)) {
- return null;
- } else {
- for (int i = 0; i < response.getHits().getHits().length; i++) {
- String hit = response.getHits().getAt(i).sourceAsString();
-
- T val = null;
- try {
- val = getJsonMapper().readValue(hit, clazz);
- result.add(val);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- return result;
- }
- }
-
- private boolean somethingFound(final SearchResponse searchResponse) {
- if (searchResponse == null || searchResponse.getHits() == null || searchResponse.getHits().getHits() == null
- || searchResponse.getHits().getHits().length == 0) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IBasicDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IBasicDAO.java
deleted file mode 100644
index 5666f059b9..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IBasicDAO.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.api;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
-import org.openecomp.sdc.be.dao.neo4j.GraphNeighbourTable;
-import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-
-import java.util.List;
-import java.util.Map;
-
-public interface IBasicDAO {
-
- /**
- * add the content of the graph neighbour table to the graph.
- *
- * @param graphNeighbourTable
- * @param clazz
- * - the type of the object to be returned
- * @param nodeType
- * - label of the node
- * @return Neo4jNode implementation
- */
- public <T extends GraphNode> Either<T, Neo4jOperationStatus> create(GraphNeighbourTable graphNeighbourTable,
- Class<T> clazz, NodeTypeEnum nodeType);
-
- /**
- * return the node data by unique id.
- *
- * @param id
- * - unique id of the node
- * @param clazz
- * @param nodeType
- * @return
- */
- public <T extends GraphNode> Either<T, Neo4jOperationStatus> getNodeData(String id, Class<T> clazz,
- NodeTypeEnum nodeType);
-
- public <T extends GraphNode> Either<T, Neo4jOperationStatus> getNodeData(String keyName, String id, Class<T> clazz,
- NodeTypeEnum nodeType);
-
- public <T extends GraphNode> Either<List<T>, Neo4jOperationStatus> getNodesData(
- Map<String, Object> propertiesToMatch, Class<T> clazz, NodeTypeEnum nodeTypeEnum);
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ICatalogDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ICatalogDAO.java
deleted file mode 100644
index c463cc32e2..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ICatalogDAO.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.api;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.resources.exception.ResourceDAOException;
-
-import java.util.List;
-
-public interface ICatalogDAO {
-
- public static final String TOSCA_ELEMENT_INDEX = "toscaelement";
- public static final String RESOURCES_INDEX = "resources";
- public final static String REF_NAME_FIELD = "refName";
- public final static String REF_VERSION_FIELD = "refVersion";
- public final static String ARTIFACT_NAME_FIELD = "artifactName";
-
- void addToIndicesMap(String typeName, String indexName);
-
- /**
- * Save an artifact in the DAO layer.
- *
- * @param imageData
- */
- void writeArtifact(ESArtifactData artifactData) throws ResourceDAOException;
-
- /**
- * Get an artifact as a byte array based on the artifact id.
- *
- * @param id
- * The id of the artifact to read.
- * @param id2
- * @return The artifact as a byte array.
- */
- Either<ESArtifactData, ResourceUploadStatus> getArtifact(String id);
-
- Either<List<ESArtifactData>, ResourceUploadStatus> getArtifacts(String[] ids);
-
- /**
- * Delete the given image.
- *
- * @param id
- * Id of the image to delete.
- */
- void deleteArtifact(String id);
-
- /**
- * delete all artifacts
- */
- void deleteAllArtifacts();
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IEsHealthCheckDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IEsHealthCheckDao.java
deleted file mode 100644
index e1ab8a7ba9..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IEsHealthCheckDao.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.api;
-
-import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
-
-public interface IEsHealthCheckDao {
-
- public HealthCheckStatus getClusterHealthStatus();
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IGenericIdDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IGenericIdDAO.java
deleted file mode 100644
index 2bc11dfcf4..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IGenericIdDAO.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.api;
-
-import java.util.List;
-
-/**
- * A DAO that allows accessing data by Id or / and multiple Ids.
- *
- * @author Igor Ngouagna
- */
-public interface IGenericIdDAO {
-
- /**
- * Find an instance from the given class.
- *
- * @param clazz
- * The class of the object to find.
- * @param id
- * The id of the object.
- * @return The object that has the given id or null if no object matching
- * the request is found.
- */
- <T> T findById(String typeName, String id, Class<T> clazz);
-
- /**
- * Find instances by id
- *
- * @param clazz
- * The class for which to find an instance.
- * @param ids
- * array of id of the data to find.
- * @return List of Objects that has the given ids or empty list if no object
- * matching the request is found.
- */
- <T> List<T> findByIds(String typeName, Class<T> clazz, String... ids);
-
- /**
- * Delete an instance from the given class.
- *
- * @param clazz
- * The class of the object to delete.
- * @param id
- * The id of the object to delete.
- */
- void delete(String typeName, String id);
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IResourceDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IResourceDAO.java
deleted file mode 100644
index c349224feb..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IResourceDAO.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.api;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.neo4j.Neo4jClient;
-import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-
-import java.util.List;
-import java.util.Map;
-
-public interface IResourceDAO extends IBasicDAO {
-
- Either<ResourceMetadataData, Neo4jOperationStatus> getResourceData(String id);
-
- // Either<ResourceData, Neo4jOperationStatus>
- // createResourceData(GraphNeighbourTable graphNeighbourTable);
-
- /**
- * the method retrieves all the resources according to the supplied
- * properties, if none or null is supplied all the resources will be
- * returned.
- *
- * @param propertiesToMatch
- * a map of properties to match.
- * @return
- */
- Either<List<ResourceMetadataData>, Neo4jOperationStatus> getAllResourcesData(Map<String, Object> propertiesToMatch);
-
- // ActionStatus updateUserData(UserData userData);
- //
- // ActionStatus deleteUserData(String id);
-
- void setNeo4jClient(Neo4jClient client);
-
- Either<Integer, Neo4jOperationStatus> getNumberOfResourcesByName(String name);
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ResourceUploadStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ResourceUploadStatus.java
deleted file mode 100644
index 88ef319657..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/ResourceUploadStatus.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.api;
-
-public enum ResourceUploadStatus {
- OK, ALREADY_EXIST, NOT_EXIST, ERROR, COMPONENT_NOT_EXIST, SERVICE_NOT_EXIST
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java
index 30da6bce6e..3b1fca4cd0 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ArtifactCassandraDao.java
@@ -25,7 +25,7 @@ import com.datastax.driver.core.Session;
import com.datastax.driver.mapping.MappingManager;
import fj.data.Either;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
+import org.openecomp.sdc.be.resources.data.DAOArtifactData;
import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -67,16 +67,16 @@ public class ArtifactCassandraDao extends CassandraDao {
}
}
- public CassandraOperationStatus saveArtifact(ESArtifactData artifact) {
- return client.save(artifact, ESArtifactData.class, manager);
+ public CassandraOperationStatus saveArtifact(DAOArtifactData artifact) {
+ return client.save(artifact, DAOArtifactData.class, manager);
}
- public Either<ESArtifactData, CassandraOperationStatus> getArtifact(String artifactId) {
- return client.getById(artifactId, ESArtifactData.class, manager);
+ public Either<DAOArtifactData, CassandraOperationStatus> getArtifact(String artifactId) {
+ return client.getById(artifactId, DAOArtifactData.class, manager);
}
public CassandraOperationStatus deleteArtifact(String artifactId) {
- return client.delete(artifactId, ESArtifactData.class, manager);
+ return client.delete(artifactId, DAOArtifactData.class, manager);
}
/**
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTable.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCacheAccessor.java
index 9a62e07a2d..a8f21c9922 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphNeighbourTable.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/ComponentCacheAccessor.java
@@ -18,47 +18,30 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.be.dao.neo4j;
+package org.openecomp.sdc.be.dao.cassandra;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
+import com.datastax.driver.mapping.Result;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Param;
+import com.datastax.driver.mapping.annotations.Query;
+import org.openecomp.sdc.be.resources.data.ComponentCacheData;
-import java.util.ArrayList;
import java.util.List;
-public class GraphNeighbourTable {
+@Accessor
+public interface ComponentCacheAccessor {
- List<GraphNode> nodes = new ArrayList<>();
+ @Query("SELECT * FROM sdccomponent.componentcache WHERE id IN :ids ALLOW FILTERING")
+ Result<ComponentCacheData> getComponents(@Param("ids") List<String> ids);
- List<NodeRelation> directedEdges = new ArrayList<>();
+ @Query("SELECT * FROM sdccomponent.componentcache WHERE id = :id ALLOW FILTERING")
+ Result<ComponentCacheData> getComponent(@Param("id") String id);
- public List<GraphNode> getNodes() {
- return nodes;
- }
+ @Query("SELECT id,modification_time,type FROM sdccomponent.componentcache ALLOW FILTERING")
+ Result<ComponentCacheData> getAllComponentIdTimeAndType();
- public void setNodes(List<GraphNode> nodes) {
- this.nodes = nodes;
- }
-
- public List<NodeRelation> getDirectedEdges() {
- return directedEdges;
- }
-
- public void setDirectedEdges(List<NodeRelation> directedEdges) {
- this.directedEdges = directedEdges;
- }
-
- public int addNode(GraphNode node) {
- this.nodes.add(node);
- return this.nodes.size() - 1;
- }
-
- public void addEdge(NodeRelation directedEdge) {
- this.directedEdges.add(directedEdge);
- }
-
- @Override
- public String toString() {
- return "GraphNeighbourTable [nodes=" + nodes + ", directedEdges=" + directedEdges + "]";
- }
+ // @Query("SELECT * FROM sdcartifact.resources LIMIT 2000")
+ // Result<DAOArtifactData> getListOfResources();
+ // Result<DAOArtifactData> getListOfResources(List<String> dids);
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IPropertyDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleAccessor.java
index 17bded535c..9c639b6cca 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IPropertyDAO.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleAccessor.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,11 +18,15 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.be.dao.api;
+package org.openecomp.sdc.be.dao.cassandra;
-public interface IPropertyDAO extends IBasicDAO {
-
- // Either<PropertyData, Neo4jOperationStatus>
- // createPropertyData(GraphNeighbourTable graphNeighbourTable);
+import com.datastax.driver.mapping.Result;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Query;
+import org.openecomp.sdc.be.resources.data.togglz.FeatureToggleEvent;
+@Accessor
+public interface FeatureToggleAccessor {
+ @Query("SELECT * FROM sdcrepository.featuretogglestate")
+ Result<FeatureToggleEvent> getAllFeatures();
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleDao.java
new file mode 100644
index 0000000000..dae34ae8e7
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/FeatureToggleDao.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.dao.cassandra;
+
+import com.datastax.driver.core.Session;
+import com.datastax.driver.mapping.MappingManager;
+import fj.data.Either;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
+import org.openecomp.sdc.be.resources.data.togglz.FeatureToggleEvent;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+
+@Component("feature_toggle_dao")
+public class FeatureToggleDao extends CassandraDao {
+
+ private FeatureToggleAccessor featureToggleAccessor;
+ private static Logger logger = Logger.getLogger(FeatureToggleDao.class.getName());
+
+ public FeatureToggleDao(CassandraClient cassandraClient) {
+ super(cassandraClient);
+ }
+
+
+ @PostConstruct
+ public void init() {
+ String keyspace = AuditingTypesConstants.REPO_KEYSPACE;
+ if (client.isConnected()) {
+ Either<ImmutablePair<Session, MappingManager>, CassandraOperationStatus> result = client.connect(keyspace);
+ if (result.isLeft()) {
+ session = result.left().value().left;
+ manager = result.left().value().right;
+ featureToggleAccessor = manager.createAccessor(FeatureToggleAccessor.class);
+ logger.info("** FeatureToggleDao created");
+ } else {
+ logger.info("** FeatureToggleDao failed");
+ throw new RuntimeException(
+ "Repo keyspace [" + keyspace + "] failed to connect with error : " + result.right().value());
+ }
+ } else {
+ logger.info("** Cassandra client isn't connected");
+ logger.info("** FeatureToggleDao created, but not connected");
+ }
+ }
+
+ public CassandraOperationStatus save(FeatureToggleEvent featureToggleEvent) {
+ return client.save(featureToggleEvent, FeatureToggleEvent.class, manager);
+ }
+
+ public FeatureToggleEvent get(String feature_name) {
+ return client.getById(feature_name, FeatureToggleEvent.class, manager)
+ .left()
+ .on(r -> {
+ logger.debug("Failed to retrieve state of feature [{}] due to error {}", feature_name, r.toString());
+ return null;
+ });
+ }
+
+ public CassandraOperationStatus delete(String feature_name) {
+ return client.delete(feature_name, FeatureToggleEvent.class, manager);
+ }
+
+ public List<FeatureToggleEvent> getAllFeatures() {
+ return featureToggleAccessor.getAllFeatures().all();
+ }
+
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java
index 22fa3646bd..e009ea6251 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/OperationalEnvironmentDao.java
@@ -39,7 +39,6 @@ import java.util.List;
@Component("operational-environment-dao")
public class OperationalEnvironmentDao extends CassandraDao {
- private static final String OPERATIONAL_ENVIRONMENT_DAO = "OperationalEnvironmentDao";
private static Logger logger = Logger.getLogger(OperationalEnvironmentDao.class.getName());
private OperationalEnvironmentsAccessor operationalEnvironmentsAccessor;
@@ -59,13 +58,13 @@ public class OperationalEnvironmentDao extends CassandraDao {
operationalEnvironmentsAccessor = manager.createAccessor(OperationalEnvironmentsAccessor.class);
logger.debug("** OperationalEnvironmentDao created");
} else {
- logger.error(EcompLoggerErrorCode.DATA_ERROR, OPERATIONAL_ENVIRONMENT_DAO, OPERATIONAL_ENVIRONMENT_DAO, "** OperationalEnvironmentDao failed");
+ logger.error(EcompLoggerErrorCode.DATA_ERROR, "OperationalEnvironmentDao", "OperationalEnvironmentDao", "** OperationalEnvironmentDao failed");
throw new RuntimeException("OperationalEnvironment keyspace [" + keyspace + "] failed to connect with error : "
+ result.right().value());
}
} else {
- logger.error(EcompLoggerErrorCode.DATA_ERROR, OPERATIONAL_ENVIRONMENT_DAO, OPERATIONAL_ENVIRONMENT_DAO, "** Cassandra client isn't connected");
- logger.error(EcompLoggerErrorCode.DATA_ERROR, OPERATIONAL_ENVIRONMENT_DAO, OPERATIONAL_ENVIRONMENT_DAO, "** OperationalEnvironmentDao created, but not connected");
+ logger.error(EcompLoggerErrorCode.DATA_ERROR, "OperationalEnvironmentDao", "OperationalEnvironmentDao", "** Cassandra client isn't connected");
+ logger.error(EcompLoggerErrorCode.DATA_ERROR, "OperationalEnvironmentDao", "OperationalEnvironmentDao", "** OperationalEnvironmentDao created, but not connected");
}
}
public CassandraOperationStatus save(OperationalEnvironmentEntry operationalEnvironmentEntry) {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java
index 76aaad95a5..b2d9b5c7ea 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/SdcSchemaFilesCassandraDao.java
@@ -44,7 +44,7 @@ public class SdcSchemaFilesCassandraDao extends CassandraDao {
public SdcSchemaFilesCassandraDao(CassandraClient cassandraClient) {
super(cassandraClient);
}
-
+
@PostConstruct
public void init() {
String keyspace = AuditingTypesConstants.ARTIFACT_KEYSPACE;
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java
index 53d71fe3cf..8c09e55c9d 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaBuilder.java
@@ -7,9 +7,9 @@
* 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.
@@ -40,17 +40,6 @@ import java.util.function.Supplier;
public class SdcSchemaBuilder {
- /**
- * creat key space statment for SimpleStrategy
- */
- private static final String CREATE_KEYSPACE_SIMPLE_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'SimpleStrategy', %s};";
- /**
- * creat key space statment for NetworkTopologyStrategy
- */
- private static final String CREATE_KEYSPACE_NETWORK_TOPOLOGY_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'NetworkTopologyStrategy', %s};";
-
- private static Logger log = Logger.getLogger(SdcSchemaBuilder.class.getName());
-
private SdcSchemaUtils sdcSchemaUtils;
private Supplier<Configuration.CassandrConfig> cassandraConfigSupplier;
@@ -58,6 +47,16 @@ public class SdcSchemaBuilder {
this.sdcSchemaUtils = sdcSchemaUtils;
this.cassandraConfigSupplier = cassandraConfigSupplier;
}
+ /**
+ * creat key space statment for SimpleStrategy
+ */
+ private static final String CREATE_KEYSPACE_SIMPLE_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'SimpleStrategy', %s};";
+ /**
+ * creat key space statment for NetworkTopologyStrategy
+ */
+ private static final String CREATE_KEYSPACE_NETWORK_TOPOLOGY_STRATEGY = "CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class':'NetworkTopologyStrategy', %s};";
+
+ private static Logger log = Logger.getLogger(SdcSchemaBuilder.class.getName());
//TODO remove after 1707_OS migration
private static void handle1707OSMigration(Map<String, Map<String, List<String>>> cassndraMetadata, Map<String, List<ITableDescription>> schemeData){
@@ -66,12 +65,12 @@ public class SdcSchemaBuilder {
list.add(new OldExternalApiEventTableDesc());
schemeData.put("attaudit", list);
}
-
+
}
/**
* the method creates all keyspaces, tables and indexes in case they do not
* already exist. the method can be run multiple times. the method uses the
- * internal enums and external configuration for its operation *
+ * internal enums and external configuration for its operation *
* @return true if the create operation was successful
*/
public boolean createSchema() {
@@ -142,7 +141,7 @@ public class SdcSchemaBuilder {
* creation of a map conting the names of keyspaces tabls and indexes
* already defined in the cassandra keyspacename -> tablename -> list of
* indexes info
- *
+ *
* @param keyspacesMetadata
* cassndra mmetadata
* @return a map of maps of lists holding parsed info
@@ -156,7 +155,7 @@ public class SdcSchemaBuilder {
.map(IndexMetadata::getName)
.collect(Collectors.toList())))));
}
-
+
private static Map<String, Map<String, List<String>>> getMetadataTablesStructure(
List<KeyspaceMetadata> keyspacesMetadata) {
return keyspacesMetadata.stream()
@@ -172,7 +171,7 @@ public class SdcSchemaBuilder {
* the method builds an index name according to a defined logic
* <table>
* _<column>_idx
- *
+ *
* @param table: table name
* @param column: column name
* @return string name of the index
@@ -187,7 +186,7 @@ public class SdcSchemaBuilder {
* @param iTableDescriptions: a list of table description we want to create
* @param keyspaceMetadate: the current tables that exist in the cassandra under this keyspace
* @param session: the session object used for the execution of the query.
- * @param existingTablesMetadata
+ * @param existingTablesMetadata
* the current tables columns that exist in the cassandra under this
* keyspace
*/
@@ -250,8 +249,8 @@ public class SdcSchemaBuilder {
* @param columnDescription
*/
private static void alterTable(Session session, Map<String, List<String>> existingTablesMetadata,
- ITableDescription tableDescription, String tableName,
- Map<String, ImmutablePair<DataType, Boolean>> columnDescription) {
+ ITableDescription tableDescription, String tableName,
+ Map<String, ImmutablePair<DataType, Boolean>> columnDescription) {
List<String> definedTableColumns = existingTablesMetadata.get(tableName);
//add column to casandra if was added to table definition
for (Map.Entry<String, ImmutablePair<DataType, Boolean>> column : columnDescription.entrySet()) {
@@ -269,7 +268,7 @@ public class SdcSchemaBuilder {
/**
* the method create the keyspace in case it does not already exists the
* method uses configurtion to select the needed replication strategy
- *
+ *
* @param keyspace: name of the keyspace we want to create
* @param cassndraMetadata: cassndra metadata
* @param session: the session object used for the execution of the query.
@@ -307,7 +306,7 @@ public class SdcSchemaBuilder {
/**
* the method retries the schem info from the enums describing the tables
- *
+ *
* @return a map of keyspaces to there table info
*/
private static Map<String, List<ITableDescription>> getSchemeData() {
@@ -326,14 +325,14 @@ public class SdcSchemaBuilder {
}
/**
- * the methoed creates the query string for the given keyspace the methoed
+ * the methoed creates the query string for the given keyspace the methoed
* valides the given data according the the requirments of the replication
* strategy SimpleStrategy: "CREATE KEYSPACE IF NOT EXISTS
* <keyspaceName></keyspaceName> WITH replication =
* {'class':'SimpleStrategy', 'replication_factor':2};" SimpleStrategy:
* "CREATE KEYSPACE IF NOT EXISTS <keyspaceName></keyspaceName> WITH
* replication = {'class':'NetworkTopologyStrategy', 'dc1' : 2 ,dc2 : 2 };"
- *
+ *
* @param keyspace
* name of the keyspace we want to create
* @param keyspaceInfo
@@ -390,9 +389,9 @@ public class SdcSchemaBuilder {
public enum ReplicationStrategy {
NETWORK_TOPOLOGY_STRATEGY("NetworkTopologyStrategy"), SIMPLE_STRATEGY("SimpleStrategy");
- private String strategyName;
+ public String strategyName;
- ReplicationStrategy(String strategyName) {
+ private ReplicationStrategy(String strategyName) {
this.strategyName = strategyName;
}
@@ -400,4 +399,5 @@ public class SdcSchemaBuilder {
return strategyName;
}
}
+
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java
index e6b091b72f..3d68980d73 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/SdcSchemaUtils.java
@@ -22,8 +22,13 @@
package org.openecomp.sdc.be.dao.cassandra.schema;
import com.datastax.driver.core.Cluster;
+import com.datastax.driver.core.Metadata;
+import com.datastax.driver.core.ProtocolVersion;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SocketOptions;
+import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
+import com.datastax.driver.core.policies.LoadBalancingPolicy;
+import com.datastax.driver.core.policies.TokenAwarePolicy;
import org.openecomp.sdc.be.config.Configuration;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.common.log.wrappers.Logger;
@@ -34,12 +39,31 @@ import java.util.function.Supplier;
public class SdcSchemaUtils {
private static Logger log = Logger.getLogger(SdcSchemaUtils.class.getName());
+ private Cluster cluster;
+ private boolean isConnected;
+
+
+
+ public SdcSchemaUtils() {
+ super();
+ try {
+ isConnected = false;
+ cluster = createCluster();
+ isConnected = true;
+ } catch (Exception e) {
+ log.info("** CassandraClient isn't connected. error is {}", e);
+ }
+
+ log.info("** cluster created");
+ }
/**
* the method creates the cluster object using the supplied cassandra nodes
* in the configuration
*
* @return cluster object our null in case of an invalid configuration
+ *
+ *
*/
public Cluster createCluster() {
final Configuration.CassandrConfig config = getCassandraConfig();
@@ -53,41 +77,104 @@ public class SdcSchemaUtils {
Cluster.Builder clusterBuilder = Cluster.builder();
nodes.forEach(node -> clusterBuilder.addContactPoint(node).withPort(cassandraPort));
- clusterBuilder.withMaxSchemaAgreementWaitSeconds(60);
-
- if (config.isAuthenticate()) {
- String username = config.getUsername();
- String password = config.getPassword();
- if (username == null || password == null) {
- log.info("authentication is enabled but username or password were not supplied.");
- return null;
+ clusterBuilder.withMaxSchemaAgreementWaitSeconds(60);
+
+ setSocketOptions(clusterBuilder, config);
+ if(!enableAuthentication(clusterBuilder, config)){
+ return null;
+ }
+
+ if(!enableSsl(clusterBuilder, config)){
+ return null;
+ }
+ setLocalDc(clusterBuilder, config);
+
+ return clusterBuilder.build();
+ }
+
+ /**
+ *
+ * @return
+ */
+ public Session connect() {
+ Session session = null;
+ if (cluster != null) {
+ try {
+ session = cluster.connect();
+
+ } catch (Throwable e) {
+ log.debug("Failed to connect cluster, error :", e);
+
}
- clusterBuilder.withCredentials(username, password);
}
- if (config.isSsl()) {
+ return session;
+ }
+
+ public Metadata getMetadata(){
+ if (cluster != null){
+ return cluster.getMetadata();
+ }
+ return null;
+ }
+
+ private void setLocalDc(Cluster.Builder clusterBuilder, Configuration.CassandrConfig config) {
+ String localDataCenter = config.getLocalDataCenter();
+ if (localDataCenter != null) {
+ log.info("localDatacenter was provided, setting Cassndra clint to use datacenter: {} as local.",
+ localDataCenter);
+ LoadBalancingPolicy tokenAwarePolicy = new TokenAwarePolicy(
+ DCAwareRoundRobinPolicy.builder().withLocalDc(localDataCenter).build());
+ clusterBuilder.withLoadBalancingPolicy(tokenAwarePolicy);
+ } else {
+ log.info(
+ "localDatacenter was provided, the driver will use the datacenter of the first contact point that was reached at initialization");
+ }
+ }
+
+ private boolean enableSsl(Cluster.Builder clusterBuilder, Configuration.CassandrConfig config) {
+ boolean ssl = config.isSsl();
+ if (ssl) {
String truststorePath = config.getTruststorePath();
String truststorePassword = config.getTruststorePassword();
if (truststorePath == null || truststorePassword == null) {
- log.info("ssl is enabled but truststorePath or truststorePassword were not supplied.");
- return null;
+ log.error("ssl is enabled but truststorePath or truststorePassword were not supplied.");
+ return false;
+ } else {
+ System.setProperty("javax.net.ssl.trustStore", truststorePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword);
+ clusterBuilder.withSSL();
}
- System.setProperty("javax.net.ssl.trustStore", truststorePath);
- System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword);
- clusterBuilder.withSSL();
+
}
+ return true;
+ }
+
+
+ private void setSocketOptions(Cluster.Builder clusterBuilder, Configuration.CassandrConfig config) {
SocketOptions socketOptions =new SocketOptions();
Integer socketConnectTimeout = config.getSocketConnectTimeout();
if( socketConnectTimeout!=null ){
log.info("SocketConnectTimeout was provided, setting Cassandra client to use SocketConnectTimeout: {} .",socketConnectTimeout);
socketOptions.setConnectTimeoutMillis(socketConnectTimeout);
}
- Integer socketReadTimeout = config.getSocketReadTimeout();
- if( socketReadTimeout != null ){
- log.info("SocketReadTimeout was provided, setting Cassandra client to use SocketReadTimeout: {} .",socketReadTimeout);
- socketOptions.setReadTimeoutMillis(socketReadTimeout);
- }
clusterBuilder.withSocketOptions(socketOptions);
- return clusterBuilder.build();
+ }
+
+ private boolean enableAuthentication(Cluster.Builder clusterBuilder, Configuration.CassandrConfig config) {
+ boolean authenticate = config.isAuthenticate();
+
+ if (authenticate) {
+ String username = config.getUsername();
+ String password = config.getPassword();
+ if (username == null || password == null) {
+ log.error("authentication is enabled but username or password were not supplied.");
+ return false;
+ } else {
+ clusterBuilder.withCredentials(username, password);
+ }
+
+ }
+ return true;
}
public boolean executeStatement(String statement) {
@@ -118,5 +205,13 @@ public class SdcSchemaUtils {
Configuration.CassandrConfig getCassandraConfig() {
return ConfigurationManager.getConfigurationManager().getConfiguration().getCassandraConfig();
}
+
+
+ public void closeCluster() {
+ if (isConnected) {
+ cluster.close();
+ }
+ log.info("** CassandraClient cluster closed");
+ }
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java
index b0209d2a13..a11bcb3881 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/Table.java
@@ -35,7 +35,6 @@ public enum Table {
DISTRIBUTION_DEPLOY_EVENT(new DistribDeployEventTableDesc()),
DISTRIBUTION_GET_UEB_CLUSTER_EVENT(new GetUebClusterEventTableDesc()),
AUTH_EVENT(new AuthEventTableDescription()),
- CONSUMER_EVENT(new ConsumerEventTableDefinition()),
CATEGORY_EVENT(new CategoryEventTableDescription()),
GET_USERS_LIST_EVENT(new GetUsersListEventTableDesc()),
GET_CATEGORY_HIERARCHY_EVENT(new GetCatHierEventTableDesc()),
@@ -43,7 +42,8 @@ public enum Table {
SDC_SCHEMA_FILES(new SdcSchemaFilesTableDescription()),
SDC_REPO(new MigrationTasksTableDescription()),
SDC_OPERATIONAL_ENVIRONMENT(new OperationalEnvironmentsTableDescription()),
- AUDIT_ECOMP_OPERATIONAL_ENVIRONMENT(new EcompOperationalEnvironmentEventTableDesc());
+ AUDIT_ECOMP_OPERATIONAL_ENVIRONMENT(new EcompOperationalEnvironmentEventTableDesc()),
+ FEATURE_TOGGLE_STATE(new FeatureToggleEventTableDesc());
ITableDescription tableDescription;
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ConsumerEventTableDefinition.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ConsumerEventTableDefinition.java
deleted file mode 100644
index f829724f4e..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/ConsumerEventTableDefinition.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.cassandra.schema.tables;
-
-import com.datastax.driver.core.DataType;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class ConsumerEventTableDefinition implements ITableDescription {
-
- @Override
- public List<ImmutablePair<String, DataType>> primaryKeys() {
- List<ImmutablePair<String, DataType>> keys = new ArrayList<>();
- keys.add(new ImmutablePair<>(TIMEBASED_UUID_FIELD, DataType.timeuuid()));
- return keys;
- }
-
- @Override
- public List<ImmutablePair<String, DataType>> clusteringKeys() {
- List<ImmutablePair<String, DataType>> keys = new ArrayList<>();
- keys.add(new ImmutablePair<>(TIMESTAMP_FIELD, DataType.timestamp()));
- return keys;
- }
-
- @Override
- public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
- Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
-
- for (DEEFieldsDescription field : DEEFieldsDescription.values()) {
- columns.put(field.getName(), new ImmutablePair<>(field.type, field.indexed));
- }
-
- return columns;
- }
-
- @Override
- public String getKeyspace() {
- return AuditingTypesConstants.AUDIT_KEYSPACE;
- }
-
- @Override
- public String getTableName() {
- return AuditingTypesConstants.CONSUMER_EVENT_TYPE;
- }
-
- enum DEEFieldsDescription {
- ACTION("action", DataType.varchar(), true),
- STATUS("status", DataType.varchar(), false),
- DESCRIPTION("description", DataType.varchar(), false),
- ECOMP_USER("ecomp_user", DataType.varchar(), false),
- MODIFIER("modifier", DataType.varchar(), false),
- REQUEST_ID("request_id", DataType.varchar(), false);
-
- private String name;
- private DataType type;
- private boolean indexed;
-
- DEEFieldsDescription(String name, DataType type, boolean indexed) {
- this.name = name;
- this.type = type;
- this.indexed = indexed;
- }
-
- public String getName() {
- return name;
- }
-
- public DataType getType() {
- return type;
- }
-
- public boolean isIndexed() {
- return indexed;
- }
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/FeatureToggleEventTableDesc.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/FeatureToggleEventTableDesc.java
new file mode 100644
index 0000000000..4c18f98179
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/cassandra/schema/tables/FeatureToggleEventTableDesc.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.dao.cassandra.schema.tables;
+
+import com.datastax.driver.core.DataType;
+import com.google.common.collect.Lists;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.openecomp.sdc.be.dao.cassandra.schema.ITableDescription;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class FeatureToggleEventTableDesc implements ITableDescription {
+
+ private static final String FEATURE_NAME = "feature_name";
+
+ @Override
+ public List<ImmutablePair<String, DataType>> primaryKeys() {
+ List<ImmutablePair<String, DataType>> keys = new ArrayList<>();
+ keys.add(new ImmutablePair<>(FEATURE_NAME, DataType.varchar()));
+ return keys;
+ }
+
+ @Override
+ public List<ImmutablePair<String, DataType>> clusteringKeys() {
+ return Lists.newArrayList();
+ }
+
+ @Override
+ public Map<String, ImmutablePair<DataType, Boolean>> getColumnDescription() {
+ Map<String, ImmutablePair<DataType, Boolean>> columns = new HashMap<>();
+ Arrays.stream(FeatureToggleEventFieldsDescription.values())
+ .forEach(column -> columns.put(column.getName(), ImmutablePair.of(column.getType(), column.isIndexed())));
+ return columns;
+ }
+
+ @Override
+ public String getKeyspace() {
+ return AuditingTypesConstants.REPO_KEYSPACE;
+ }
+
+ @Override
+ public String getTableName() {
+ return AuditingTypesConstants.FEATURE_TOGGLE_STATE;
+ }
+
+ enum FeatureToggleEventFieldsDescription {
+ ENABLED("enabled", DataType.varchar(), false),
+ STRATEGY_ID("strategy_id", DataType.varchar(), false),
+ PARAMETERS("parameters", DataType.varchar(), false);
+
+ private String name;
+ private DataType type;
+ private boolean indexed;
+
+ FeatureToggleEventFieldsDescription(String name, DataType type, boolean indexed) {
+ this.name = name;
+ this.type = type;
+ this.indexed = indexed;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public DataType getType() {
+ return type;
+ }
+
+ public boolean isIndexed() {
+ return indexed;
+ }
+
+ }
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/config/DAOSpringConfig.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/config/DAOSpringConfig.java
index e40b5aa237..d57ae29b1b 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/config/DAOSpringConfig.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/config/DAOSpringConfig.java
@@ -30,9 +30,7 @@ import org.springframework.context.annotation.PropertySource;
@ComponentScan({
"org.openecomp.sdc.be.dao.cassandra",
"org.openecomp.sdc.be.dao.neo4j",
- "org.openecomp.sdc.be.dao.es",
- "org.openecomp.sdc.be.dao.impl",
- "org.openecomp.sdc.be.resources.impl"
+ "org.openecomp.sdc.be.dao.impl"
})
@PropertySource("classpath:dao.properties")
public class DAOSpringConfig {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/es/ElasticSearchClient.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/es/ElasticSearchClient.java
deleted file mode 100644
index 1547d01ac2..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/es/ElasticSearchClient.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.es;
-
-import org.apache.commons.lang.SystemUtils;
-import org.elasticsearch.client.Client;
-import org.elasticsearch.client.transport.TransportClient;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.common.transport.InetSocketTransportAddress;
-import org.elasticsearch.node.Node;
-import org.elasticsearch.node.NodeBuilder;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import java.net.InetSocketAddress;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-
-/**
- * Prepare the node to work with elastic search.
- *
- * @author luc boutier
- */
-@Component("elasticsearch-client")
-public class ElasticSearchClient {
-
- private static Logger log = Logger.getLogger(ElasticSearchClient.class.getName());
-
- private Node node;
- private boolean isLocal;
- private String clusterName;
- private Client client;
-
- String serverHost;
- String serverPort;
-
- ArrayList<String> nodes = new ArrayList<>();
-
- private boolean isTransportClient;
-
- @PostConstruct
- public void initialize() throws URISyntaxException {
-
- URL url = null;
- Settings settings = null;
- URL systemResourceElasticsearchPath = ClassLoader.getSystemResource("elasticsearch.yml");
-
- if (systemResourceElasticsearchPath != null) {
- log.debug("try to create URI for {}", systemResourceElasticsearchPath.toString());
- Path classpathConfig = Paths.get(systemResourceElasticsearchPath.toURI());
- settings = Settings.settingsBuilder().loadFromPath(classpathConfig).build();
- }
- String configHome = System.getProperty("config.home");
- if (configHome != null && !configHome.isEmpty()) {
- try {
- if (SystemUtils.IS_OS_WINDOWS) {
- url = new URL("file:///" + configHome + "/elasticsearch.yml");
- } else {
- url = new URL("file:" + configHome + "/elasticsearch.yml");
- }
-
- log.debug("URL {}", url);
- settings = Settings.settingsBuilder().loadFromPath(Paths.get(url.toURI())).build();
- } catch (MalformedURLException | URISyntaxException e1) {
- log.error("Failed to create URL in order to load elasticsearch yml");
- System.err.println("Failed to create URL in order to load elasticsearch yml from " + configHome);
- }
- }
- if (settings == null) {
- log.error("Failed to find settings of elasticsearch yml");
- System.err.println("Failed to create URL in order to load elasticsearch yml from " + configHome);
- }
- if (isTransportClient()) {
- log.info("******* ElasticSearchClient type is Transport Client *****");
- TransportClient transportClient = TransportClient.builder().settings(settings)
- .build();
-
- String[] nodesArray = transportClient.settings().getAsArray("transport.client.initial_nodes");
- for (String host : nodesArray) {
- int port = 9300;
-
- // or parse it from the host string...
- String[] splitHost = host.split(":", 2);
- if (splitHost.length == 2) {
- host = splitHost[0];
- port = Integer.parseInt(splitHost[1]);
- }
-
- transportClient.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress(host, port)));
-
- }
- this.client = transportClient;
- serverHost = Arrays.toString(nodesArray);
-
- } else {
- log.info("******* ElasticSearchClient type is Node Client *****");
- this.node = NodeBuilder.nodeBuilder().settings(settings).client(!isLocal).clusterName(this.clusterName)
- .local(isLocal).node();
- this.client = node.client();
-
- serverHost = this.client.settings().get("discovery.zen.ping.unicast.hosts");
- if (serverHost == null) {
- serverHost = "['localhost:9200']";
- }
-
- }
-
- serverPort = this.client.settings().get("http.port");
- if (serverPort == null) {
- serverPort = "9200";
- }
-
- log.info("Initialized ElasticSearch client for cluster <{}> with nodes: {}", this.clusterName, serverHost);
- }
-
- @PreDestroy
- public void close() {
- if (client != null) {
- client.close();
- }
- if (node != null) {
- node.close();
- }
- log.info("Closed ElasticSearch client for cluster <{}>", this.clusterName);
- }
-
- /**
- * Get the elastic search client.
- *
- * @return The elastic search client.
- */
- public Client getClient() {
- return this.client;
- }
-
- public String getServerHost() {
- return serverHost;
- }
-
- public String getServerPort() {
- return serverPort;
- }
-
- @Value("#{elasticsearchConfig['cluster.name']}")
- public void setClusterName(final String clusterName) {
- this.clusterName = clusterName;
- }
-
- @Value("#{elasticsearchConfig['elasticSearch.local']}")
- public void setLocal(final String strIsLocal) {
- if (strIsLocal != null && !strIsLocal.isEmpty())
- this.isLocal = Boolean.parseBoolean(strIsLocal);
- }
-
- public boolean isTransportClient() {
- return isTransportClient;
- }
-
- @Value("#{elasticsearchConfig['elasticSearch.transportclient']}")
- public void setTransportClient(final String strIsTransportclient) {
- if (strIsTransportclient != null && !strIsTransportclient.isEmpty())
- this.isTransportClient = Boolean.parseBoolean(strIsTransportclient);
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/GraphElementFactory.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/GraphElementFactory.java
index 350909e66d..3a0a42c2cd 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/GraphElementFactory.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/GraphElementFactory.java
@@ -24,6 +24,7 @@ import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
import org.openecomp.sdc.be.dao.graph.datatype.RelationEndPoint;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.resources.data.*;
import org.openecomp.sdc.be.resources.data.category.CategoryData;
@@ -84,10 +85,10 @@ public class GraphElementFactory {
element = new TagData(properties);
break;
case Service:
- element = new ServiceMetadataData(properties);
+ element = new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
break;
case Resource:
- element = new ResourceMetadataData(properties);
+ element = new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
break;
case Property:
element = new PropertyData(properties);
@@ -133,13 +134,13 @@ public class GraphElementFactory {
element = clazz.cast(new TagData(properties));
break;
case Service:
- element = clazz.cast(new ServiceMetadataData(properties));
+ element = clazz.cast(new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
break;
case Product:
- element = clazz.cast(new ProductMetadataData(properties));
+ element = clazz.cast(new ProductMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
break;
case Resource:
- element = clazz.cast(new ResourceMetadataData(properties));
+ element = clazz.cast(new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
break;
case Attribute:
element = clazz.cast(new AttributeData(properties));
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java
index 3375719535..174416281b 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/graph/datatype/GraphNode.java
@@ -35,16 +35,16 @@ public abstract class GraphNode extends GraphElement {
private NodeTypeEnum label;
- protected GraphNode(NodeTypeEnum label) {
- super(GraphElementTypeEnum.Node);
-
- this.label = label;
- }
-
protected Gson getGson() {
return gson;
}
+ protected GraphNode(NodeTypeEnum label) {
+ super(GraphElementTypeEnum.Node);
+
+ this.label = label;
+ }
+
public String getLabel() {
return label.getName();
}
@@ -53,6 +53,11 @@ public abstract class GraphNode extends GraphElement {
return new ImmutablePair<>(getUniqueIdKey(), getUniqueId());
}
+
+ public ImmutablePair<String, Object> getKeyValueIdForLog() {
+ return getKeyValueId();
+ }
+
protected void addIfExists(Map<String, Object> map, GraphPropertiesDictionary property, Object value) {
if (value != null) {
if (value instanceof List || value instanceof Map) {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/AuditingDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/AuditingDao.java
deleted file mode 100644
index 26b821a3d4..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/AuditingDao.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.impl;
-
-import fj.data.Either;
-import org.elasticsearch.index.query.BoolQueryBuilder;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
-import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
-import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
-import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
-import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.PostConstruct;
-import java.util.*;
-import java.util.Map.Entry;
-
-@Component("auditingDao")
-public class AuditingDao extends ESTimeBasedDao {
-
- private static final String FAILED_TO_GET_DISTRIBUTION_STATUSES_FOR_ACTION = "failed to get distribution statuses for action {}";
- private static final String GET_SERVICE_DISTRIBUTION_STATUSES_LIST = "Get Service DistributionStatuses List";
- private static final String SERVICE_INSTANCE_ID_FIELD = AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID
- .getDisplayName(); // "serviceInstanceId";
- private static final String STATUS_FIELD = AuditingFieldsKey.AUDIT_STATUS.getDisplayName(); // "status";
- private static final String ACTION_FIELD = AuditingFieldsKey.AUDIT_ACTION.getDisplayName(); // "action";
- private static final String DISTRIBUTION_ID_FIELD = AuditingFieldsKey.AUDIT_DISTRIBUTION_ID.getDisplayName(); // "distributionId";
- private static Logger log = Logger.getLogger(AuditingDao.class.getName());
- public static final String AUDITING_INDEX = "auditingevents";
-
- @PostConstruct
- private void init() {
- AuditingActionEnum[] values = AuditingActionEnum.values();
- for (AuditingActionEnum value : values) {
- typesToClasses.put(value.getAuditingEsType(), ESTimeBasedEvent.class);
- }
- }
-
- @Override
- public String getIndexPrefix() {
- return AUDITING_INDEX;
- }
-
- public ActionStatus addRecord(Map<AuditingFieldsKey, Object> params, String type) {
-
- // TODO rhalili - remove? check debugEnabled?
- Map<String, Object> displayFields = new HashMap<>();
- StringBuilder sb = new StringBuilder();
- for (Entry<AuditingFieldsKey, Object> entry : params.entrySet()) {
- displayFields.put(entry.getKey().getDisplayName(), entry.getValue());
- sb.append(entry.getKey().getDisplayName()).append(" = ").append(entry.getValue()).append(",");
- }
-
- // Persisiting
- // String type = clazz.getSimpleName().toLowerCase();
- AuditingGenericEvent auditingGenericEvent = new AuditingGenericEvent();
- populateCommonFields(params, auditingGenericEvent);
- auditingGenericEvent.getFields().putAll(displayFields);
-
- log.debug("Auditing: Persisting object of type {}, fields: {}", type, sb.toString());
-
- return write(type, auditingGenericEvent);
- }
-
- public ActionStatus addRecord(AuditingGenericEvent auditEvent, String type) {
-
- log.debug("Auditing: Persisting object of type {}, fields: {}", type, auditEvent.getAction());
-// auditEvent.fillFields();
- return write(type, auditEvent);
- }
-
- public Either<List<ESTimeBasedEvent>, ActionStatus> getListOfDistributionStatuses(String did) {
-
- QueryBuilder componentNameMatch = QueryBuilders.matchQuery(DISTRIBUTION_ID_FIELD, did);
- QueryBuilder componentVersionMatch = QueryBuilders.matchQuery(ACTION_FIELD,
- AuditingActionEnum.DISTRIBUTION_STATUS.getName());
- QueryBuilder remainingElementQueryBuilder = QueryBuilders.boolQuery().must(componentNameMatch)
- .must(componentVersionMatch);
- List<ESTimeBasedEvent> remainingElements = null;
- try {
- remainingElements = customFindEvent(AuditingTypesConstants.DISTRIBUTION_STATUS_EVENT_TYPE,
- remainingElementQueryBuilder, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Get DistributionStatuses List");
- log.debug("failed to get distribution statuses for ", e);
- return Either.right(ActionStatus.GENERAL_ERROR);
- }
- if (remainingElements != null && !remainingElements.isEmpty()) {
- return Either.left(remainingElements);
- } else {
- log.debug("not found distribution statuses for did {}", did);
- remainingElements = new ArrayList<>();
- return Either.left(remainingElements);
- }
-
- }
-
- public Either<List<ESTimeBasedEvent>, ActionStatus> getServiceDistributionStatusesList(String serviceInstanceId) {
-
- List<ESTimeBasedEvent> resList = new ArrayList<>();
- QueryBuilder componentNameMatch = QueryBuilders.matchQuery(SERVICE_INSTANCE_ID_FIELD, serviceInstanceId);
- QueryBuilder componentVersionMatch = QueryBuilders.matchQuery(ACTION_FIELD,
- AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName());
- QueryBuilder remainingElementQueryBuilder = QueryBuilders.boolQuery().must(componentNameMatch)
- .must(componentVersionMatch);
- List<ESTimeBasedEvent> remainingElements = null;
- try {
- remainingElements = customFindEvent(AuditingTypesConstants.RESOURCE_ADMIN_EVENT_TYPE,
- remainingElementQueryBuilder, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError(GET_SERVICE_DISTRIBUTION_STATUSES_LIST);
- log.debug(FAILED_TO_GET_DISTRIBUTION_STATUSES_FOR_ACTION,
- AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName(), e);
- return Either.right(ActionStatus.GENERAL_ERROR);
- }
- if (remainingElements != null && !remainingElements.isEmpty()) {
- resList.addAll(remainingElements);
- }
-
- componentVersionMatch = QueryBuilders.matchQuery(ACTION_FIELD,
- AuditingActionEnum.DISTRIBUTION_DEPLOY.getName());
- remainingElementQueryBuilder = QueryBuilders.boolQuery().must(componentNameMatch).must(componentVersionMatch);
- List<ESTimeBasedEvent> dResultElements = null;
- try {
- dResultElements = customFindEvent(AuditingTypesConstants.DISTRIBUTION_DEPLOY_EVENT_TYPE,
- remainingElementQueryBuilder, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError(GET_SERVICE_DISTRIBUTION_STATUSES_LIST);
- log.debug("failed to get distribution statuses for action {}",
- AuditingActionEnum.DISTRIBUTION_DEPLOY.getName(), e);
- return Either.right(ActionStatus.GENERAL_ERROR);
- }
- if (dResultElements != null && !dResultElements.isEmpty()) {
- resList.addAll(dResultElements);
- }
-
- componentVersionMatch = QueryBuilders.matchQuery(ACTION_FIELD,
- AuditingActionEnum.DISTRIBUTION_NOTIFY.getName());
- remainingElementQueryBuilder = QueryBuilders.boolQuery().must(componentNameMatch).must(componentVersionMatch);
- List<ESTimeBasedEvent> dNotifyElements = null;
- try {
- dNotifyElements = customFindEvent(AuditingTypesConstants.DISTRIBUTION_NOTIFICATION_EVENT_TYPE,
- remainingElementQueryBuilder, null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError(GET_SERVICE_DISTRIBUTION_STATUSES_LIST);
- log.debug("failed to get distribution statuses for action {}",
- AuditingActionEnum.DISTRIBUTION_NOTIFY.getName(), e);
- return Either.right(ActionStatus.GENERAL_ERROR);
- }
- if (remainingElements != null && !remainingElements.isEmpty()) {
- resList.addAll(dNotifyElements);
- }
-
- return Either.left(resList);
-
- }
-
- public Either<List<ESTimeBasedEvent>, ActionStatus> getFilteredResourceAdminAuditingEvents(
- Map<AuditingFieldsKey, Object> filterMap) {
-
- Iterator<Entry<AuditingFieldsKey, Object>> filterItr = filterMap.entrySet().iterator();
- BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
- while (filterItr.hasNext()) {
- Entry<AuditingFieldsKey, Object> curr = filterItr.next();
- boolQuery = boolQuery.must(QueryBuilders.termQuery(curr.getKey().getDisplayName(), curr.getValue()));
- }
-
- try {
- List<ESTimeBasedEvent> customFindEvent = customFindEvent(
- ResourceAdminEvent.class.getSimpleName().toLowerCase(), boolQuery, null);
- return Either.left(customFindEvent);
- } catch (Exception e) {
- log.debug("Failed to query AuditRecords in es");
- return Either.right(ActionStatus.GENERAL_ERROR);
- }
-
- }
-
- public Either<List<ESTimeBasedEvent>, ActionStatus> getListOfDistributionByAction(String did, String actionType,
- String requestedStatus, Class<? extends AuditingGenericEvent> clazz) {
-
- QueryBuilder distributionIdMatch = QueryBuilders.matchQuery(DISTRIBUTION_ID_FIELD, did);
- QueryBuilder distributionActionMatch = QueryBuilders.matchQuery(ACTION_FIELD, actionType);
- QueryBuilder remainingElementQueryBuilder;
-
- if (requestedStatus != null && !requestedStatus.isEmpty()) {
- QueryBuilder statusMatch = QueryBuilders.matchQuery(STATUS_FIELD, requestedStatus);
- remainingElementQueryBuilder = QueryBuilders.boolQuery().must(distributionIdMatch)
- .must(distributionActionMatch).must(statusMatch);
- } else {
- remainingElementQueryBuilder = QueryBuilders.boolQuery().must(distributionIdMatch)
- .must(distributionActionMatch);
- }
-
- List<ESTimeBasedEvent> remainingElements = null;
- try {
- remainingElements = customFindEvent(clazz.getSimpleName().toLowerCase(), remainingElementQueryBuilder,
- null);
- } catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Get DistributionStatuses List");
- log.debug("failed to get distribution statuses for action {}", actionType, e);
- return Either.right(ActionStatus.GENERAL_ERROR);
- }
-
- return Either.left(remainingElements);
-
- }
-
- private void populateCommonFields(Map<AuditingFieldsKey, Object> params,
- AuditingGenericEvent timeBasedIndexedData) {
- String dateStr = (String) params.get(AuditingFieldsKey.AUDIT_TIMESTAMP);
- if (dateStr != null) {
- timeBasedIndexedData.setTimestamp(dateStr);
- }
- timeBasedIndexedData.setAction((String) params.get(AuditingFieldsKey.AUDIT_ACTION));
- Object statusObj = params.get(AuditingFieldsKey.AUDIT_STATUS);
- // For BC. status was Integer and is String
- if (statusObj != null) {
- timeBasedIndexedData.setStatus(String.valueOf(statusObj));
- } else {
- timeBasedIndexedData.setStatus(null);
- }
- // timeBasedIndexedData.setStatus((String)params.get(AuditingFieldsKey.AUDIT_STATUS));
- timeBasedIndexedData.setDesc((String) params.get(AuditingFieldsKey.AUDIT_DESC));
- timeBasedIndexedData
- .setServiceInstanceId((String) params.get(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID));
- timeBasedIndexedData.setRequestId((String) params.get(AuditingFieldsKey.AUDIT_REQUEST_ID));
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESCatalogDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESCatalogDAO.java
deleted file mode 100644
index 8d8e0ba50c..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESCatalogDAO.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.impl;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import fj.data.Either;
-import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
-import org.elasticsearch.cluster.health.ClusterHealthStatus;
-import org.elasticsearch.common.unit.TimeValue;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.api.ESGenericSearchDAO;
-import org.openecomp.sdc.be.dao.api.ICatalogDAO;
-import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.resources.exception.ResourceDAOException;
-import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.PostConstruct;
-import java.util.List;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
-
-@Component("resource-dao")
-public class ESCatalogDAO extends ESGenericSearchDAO implements ICatalogDAO {
-
- private static Logger log = Logger.getLogger(ESCatalogDAO.class.getName());
-
- // Index Checking Variables
- private boolean initCompleted = false;
-
- //TODO use LoggerMetric instead
- private static Logger healthCheckLogger = Logger.getLogger("elasticsearch.healthcheck");
-
- ///// HealthCheck/////////
- private static final String ES_HEALTH_CHECK_STR = "elasticsearchHealthCheck";
-
- private ScheduledExecutorService healthCheckScheduler = Executors
- .newSingleThreadScheduledExecutor(new ThreadFactory() {
- @Override
- public Thread newThread(Runnable r) {
- return new Thread(r, "ES-Health-Check-Thread");
- }
- });
-
- private class HealthCheckScheduledTask implements Runnable {
- @Override
- public void run() {
- log.trace("Executing ELASTICSEARCH Health Check Task - Start");
-
- HealthCheckStatus healthStatus = null;
- try {
- healthStatus = isInitCompleted() ? checkHealth() : HealthCheckStatus.DOWN;
- } catch (Exception e) {
- log.error("Error while trying to connect to elasticsearch. host: {} | port: {} | error: {}",
- getEsClient().getServerHost(), getEsClient().getServerPort(), e.getMessage(), e);
- healthStatus = HealthCheckStatus.DOWN;
- }
- log.trace("Executed ELASTICSEARCH Health Check Task - Status = {}", healthStatus);
- if (healthStatus != lastHealthState) {
- log.trace("ELASTICSEARCH Health State Changed to {}. Issuing alarm / recovery alarm...", healthStatus);
- lastHealthState = healthStatus;
- logAlarm();
- }
- }
- }
-
- private HealthCheckScheduledTask healthCheckScheduledTask = new HealthCheckScheduledTask();
- private volatile HealthCheckStatus lastHealthState = HealthCheckStatus.DOWN;
-
- /**
- * Get ES cluster status string rep
- *
- * @return "GREEN", "YELLOW" or "RED"
- */
- private HealthCheckStatus checkHealth() {
- if (!isInitCompleted()) {
- return HealthCheckStatus.DOWN;
- }
- ClusterHealthRequest healthRequest = new ClusterHealthRequest("_all");
- healthRequest.masterNodeTimeout(TimeValue.timeValueSeconds(2));
- ClusterHealthStatus status = getClient().admin().cluster().health(healthRequest).actionGet().getStatus();
- healthCheckLogger.debug("ES cluster health status is {}", status);
- if (status == null || status.equals(ClusterHealthStatus.RED)) {
- return HealthCheckStatus.DOWN;
- }
- return HealthCheckStatus.UP;
- }
-
- private void logAlarm() {
- if (lastHealthState == HealthCheckStatus.UP) {
- BeEcompErrorManager.getInstance().logBeHealthCheckElasticSearchRecovery(ES_HEALTH_CHECK_STR);
- } else {
- BeEcompErrorManager.getInstance().logBeHealthCheckElasticSearchError(ES_HEALTH_CHECK_STR);
- }
- }
-
- @PostConstruct
- public void initCompleted() {
- long interval = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getEsReconnectIntervalInSeconds(5);
- this.healthCheckScheduler.scheduleAtFixedRate(healthCheckScheduledTask, 0, interval, TimeUnit.SECONDS);
- initCompleted = true;
- }
-
- @Override
- public void writeArtifact(ESArtifactData artifactData) {
- try {
- saveResourceData(artifactData);
- } catch (Exception e) {
- throw new ResourceDAOException("Error to save ArtifactData with " + artifactData.getId());
- }
- }
-
- @Override
- public Either<ESArtifactData, ResourceUploadStatus> getArtifact(String id) {
- ESArtifactData resData = null;
-
- try {
- resData = findById(getTypeFromClass(ESArtifactData.class), id, ESArtifactData.class);
- } catch (Exception e) {
- resData = null;
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Artifact from database");
- log.debug("ESCatalogDAO:getArtifact failed with exception ", e);
- return Either.right(ResourceUploadStatus.ERROR);
- }
-
- if (resData != null) {
- return Either.left(resData);
- } else {
- return Either.right(ResourceUploadStatus.NOT_EXIST);
- }
- }
-
- private <T> String getTypeFromClass(Class<T> clazz) {
-
- return clazz.getSimpleName().toLowerCase();
- }
-
- @Override
- public void deleteArtifact(String id) {
- delete(getTypeFromClass(ESArtifactData.class), id);
- }
-
- @Override
- public Either<List<ESArtifactData>, ResourceUploadStatus> getArtifacts(String[] ids) {
- List<ESArtifactData> resData = null;
- try {
- resData = findByIds(getTypeFromClass(ESArtifactData.class), ESArtifactData.class, ids);
- } catch (Exception e) {
- resData = null;
- return Either.right(ResourceUploadStatus.ERROR);
- }
-
- if (resData != null && !resData.isEmpty()) {
- return Either.left(resData);
- } else {
- return Either.right(ResourceUploadStatus.NOT_EXIST);
- }
- }
-
- private void saveResourceData(ESArtifactData data) throws JsonProcessingException {
- String typeName = getTypeFromClass(data.getClass());
- saveResourceData(typeName, data, data.getId());
- }
-
- @Override
- public void deleteAllArtifacts() {
- String typeName = getTypeFromClass(ESArtifactData.class);
- String indexName = getIndexForType(typeName);
- deleteIndex(indexName);
-
- }
-
- public boolean isInitCompleted() {
- return initCompleted;
- }
-
- public HealthCheckStatus getHealth() {
- return lastHealthState;
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESTimeBasedDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESTimeBasedDao.java
deleted file mode 100644
index 556f8c1381..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/ESTimeBasedDao.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.impl;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import org.codehaus.jettison.json.JSONException;
-import org.codehaus.jettison.json.JSONObject;
-import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.action.search.SearchRequestBuilder;
-import org.elasticsearch.action.search.SearchResponse;
-import org.elasticsearch.common.unit.TimeValue;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.search.sort.SortBuilder;
-import org.openecomp.sdc.be.config.Configuration.ElasticSearchConfig.IndicesTimeFrequencyEntry;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
-import org.openecomp.sdc.common.api.Constants;
-import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public abstract class ESTimeBasedDao {
- private static final String SCORE_SCRIPT = "_score * ((doc.containsKey('alienScore') && !doc['alienScore'].empty) ? doc['alienScore'].value : 1)";
- private static final int MAX_SEARCH_SIZE = 1000;
- private static Logger log = Logger.getLogger(ESTimeBasedDao.class.getName());
-
- private Gson gson;
-
- private Map<String, String> indexPrefix2CreationPeriod;
-
- private ConfigurationManager configurationManager;
-
- @Resource(name = "elasticsearch-client")
- private ElasticSearchClient esClient;
-
- protected final Map<String, Class<?>> typesToClasses = new HashMap<>();
-
- protected ESTimeBasedDao() {
- gson = new GsonBuilder().setPrettyPrinting().create();
- configurationManager = ConfigurationManager.getConfigurationManager();
- setIndexPrefix2CreationPeriod();
- }
-
- public void setConfigurationManager(ConfigurationManager configurationManager) {
- this.configurationManager = configurationManager;
- }
-
- public abstract String getIndexPrefix();
-
- public ActionStatus write(String typeName, ESTimeBasedEvent data) {
-
- String indexPrefix = getIndexPrefix();
- String indexSuffix = getIndexSuffix(indexPrefix, data);
- StringBuilder sb = new StringBuilder();
- sb.append(indexPrefix);
- if (indexSuffix != null) {
- sb.append("-").append(indexSuffix);
- }
-
- ActionStatus res = ActionStatus.OK;
- JSONObject json = new JSONObject(data.getFields());
- try {
- IndexResponse actionGet = esClient.getClient().prepareIndex(sb.toString(), typeName)
- .setSource(json.toString()).setRefresh(true).execute().actionGet(TimeValue.timeValueSeconds(15));
-
- if (actionGet.isCreated()) {
- log.debug("Created record {}", data.toString());
- // typesToClasses.put(typeName, data.getClass());
- } else {
- log.error("Record {} couldn't be created", data.toString());
- res = ActionStatus.GENERAL_ERROR;
- }
- } catch (Exception e) {
- log.error("Couldn't serialize object of type {}", typeName, e.getMessage());
- res = ActionStatus.GENERAL_ERROR;
- }
- return res;
- }
-
- public ActionStatus write(ESTimeBasedEvent data) {
-
- String indexPrefix = getIndexPrefix();
- String indexSuffix = getIndexSuffix(indexPrefix, data);
- StringBuilder sb = new StringBuilder();
- sb.append(indexPrefix);
- if (indexSuffix != null) {
- sb.append("-").append(indexSuffix);
- }
-
- String typeName = data.getClass().getSimpleName().toLowerCase();
- ActionStatus res = ActionStatus.OK;
- String json = gson.toJson(data);
- try {
- IndexResponse actionGet = esClient.getClient().prepareIndex(sb.toString(), typeName).setSource(json)
- .setRefresh(true).execute().actionGet(TimeValue.timeValueSeconds(15));
-
- if (actionGet.isCreated()) {
- log.debug("Created record {}", data.toString());
- // typesToClasses.put(typeName, data.getClass());
- } else {
- log.error("Record {} couldn't be created", data.toString());
- res = ActionStatus.GENERAL_ERROR;
- }
- } catch (Exception e) {
- log.debug("Couldn't serialize object of type {}", typeName);
- res = ActionStatus.GENERAL_ERROR;
- }
- return res;
- }
-
- private void setIndexPrefix2CreationPeriod() {
- indexPrefix2CreationPeriod = new HashMap<>();
- List<IndicesTimeFrequencyEntry> indicesTimeFrequencyEntries = configurationManager.getConfiguration()
- .getElasticSearch().getIndicesTimeFrequency();
- for (IndicesTimeFrequencyEntry entry : indicesTimeFrequencyEntries) {
- indexPrefix2CreationPeriod.put(entry.getIndexPrefix(), entry.getCreationPeriod());
-
- }
- }
-
- private String getIndexSuffix(String indexPrefix, ESTimeBasedEvent data) {
- String indexSuffix = indexPrefix2CreationPeriod.get(indexPrefix);
- String res = null;
- if (indexSuffix != null) {
- if (indexSuffix.equalsIgnoreCase(Constants.YEAR)) {
- res = data.calculateYearIndexSuffix();
- } else if (indexSuffix.equalsIgnoreCase(Constants.MONTH)) {
- res = data.calculateMonthIndexSuffix();
- } else if (indexSuffix.equalsIgnoreCase(Constants.DAY)) {
- res = data.calculateDayIndexSuffix();
- } else if (indexSuffix.equalsIgnoreCase(Constants.HOUR)) {
- res = data.calculateHourIndexSuffix();
- } else if (indexSuffix.equalsIgnoreCase(Constants.MINUTE)) {
- res = data.calculateMinuteIndexSuffix();
- } else if (indexSuffix.equalsIgnoreCase(Constants.NONE)) {
- // do nothing - no time-based behaviour. I wanted to ensure
- // proper syntax, that's why this clause is needed.
- }
- } else {
- // Default behaviour - time-based with month period
- res = data.calculateMonthIndexSuffix();
- }
- return res;
- }
-
- public <T> long count(Class<T> clazz, QueryBuilder query) {
- String indexName = getIndexPrefix() + "*";
- String typeName = clazz.getSimpleName().toLowerCase();
- SearchRequestBuilder searchRequestBuilder = esClient.getClient().prepareSearch(indexName).setTypes(typeName)
- .setSize(0);
- if (query != null) {
- searchRequestBuilder.setQuery(query);
- }
-
- SearchResponse response = searchRequestBuilder.execute().actionGet();
- return response.getHits().getTotalHits();
- }
-
- private <T> List<T> doCustomFind(Class<T> clazz, QueryBuilder query, SortBuilder sortBuilder, int size) {
- String indexName = getIndexPrefix() + "*";
- String typeName = clazz.getSimpleName().toLowerCase();
- SearchRequestBuilder searchRequestBuilder = esClient.getClient().prepareSearch(indexName).setTypes(typeName)
- .setSize(size);
- if (query != null) {
- searchRequestBuilder.setQuery(query);
- }
- if (sortBuilder != null) {
- searchRequestBuilder.addSort(sortBuilder);
- }
- SearchResponse response = searchRequestBuilder.execute().actionGet();
- if (!somethingFound(response)) {
- return null;
- } else {
- List<T> hits = new ArrayList<>();
- for (int i = 0; i < response.getHits().getHits().length; i++) {
- String hit = response.getHits().getAt(i).sourceAsString();
-
- hits.add((T) gson.fromJson(hit, clazz));
-
- }
- return hits;
- }
- }
-
- private List<ESTimeBasedEvent> doCustomFindForEvent(String typeName, QueryBuilder query, SortBuilder sortBuilder,
- int size) {
- String indexName = getIndexPrefix() + "*";
- // String typeName = clazz.getSimpleName().toLowerCase();
- SearchRequestBuilder searchRequestBuilder = esClient.getClient().prepareSearch(indexName).setTypes(typeName)
- .setSize(size);
- if (query != null) {
- searchRequestBuilder.setQuery(query);
- }
- if (sortBuilder != null) {
- searchRequestBuilder.addSort(sortBuilder);
- }
- SearchResponse response = searchRequestBuilder.execute().actionGet();
- if (!somethingFound(response)) {
- return null;
- } else {
- List<ESTimeBasedEvent> hits = new ArrayList<>();
- for (int i = 0; i < response.getHits().getHits().length; i++) {
- String hit = response.getHits().getAt(i).sourceAsString();
-
- ESTimeBasedEvent event;
- try {
- event = ESTimeBasedEvent.createEventFromJson(hit);
- hits.add(event);
- } catch (JSONException e) {
- log.warn("failed to parse hit from audit index. error: {}", e.getMessage());
- log.debug("failed to parse hit from audit. hit = {}", hit, e);
- }
- }
- return hits;
- }
- }
-
- public List<ESTimeBasedEvent> customFindEvent(String typeName, QueryBuilder query, SortBuilder sortBuilder) {
- List<ESTimeBasedEvent> results = doCustomFindForEvent(typeName, query, sortBuilder, MAX_SEARCH_SIZE);
- if (results == null) {
- results = new ArrayList<>();
- }
- return results;
- }
-
- public <T> T customFind(Class<T> clazz, QueryBuilder query) {
- return customFind(clazz, query, null);
- }
-
- public <T> T customFind(Class<T> clazz, QueryBuilder query, SortBuilder sortBuilder) {
- List<T> results = doCustomFind(clazz, query, sortBuilder, 1);
- if (results == null || results.isEmpty()) {
- return null;
- } else {
- return results.iterator().next();
- }
- }
-
- public <T> List<T> customFindAll(Class<T> clazz, QueryBuilder query) {
- return customFindAll(clazz, query, null);
- }
-
- public <T> List<T> customFindAll(Class<T> clazz, QueryBuilder query, SortBuilder sortBuilder) {
- return doCustomFind(clazz, query, sortBuilder, Integer.MAX_VALUE);
- }
-
- private boolean somethingFound(final SearchResponse searchResponse) {
- return !(searchResponse == null || searchResponse.getHits() == null || searchResponse.getHits().getHits() == null
- || searchResponse.getHits().getHits().length == 0);
- }
-
- public String getEsHost() {
- String host = null;
- if (this.esClient != null) {
- host = this.esClient.getServerHost();
- } else {
- log.error("esClient is unavilable could not get host.");
- }
- return host;
- }
-
- public String getEsPort() {
- String port = null;
- if (this.esClient != null) {
- port = this.esClient.getServerPort();
- } else {
- log.error("esClient is unavilable could not get port.");
- }
-
- return port;
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/EsHealthCheckDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/EsHealthCheckDao.java
deleted file mode 100644
index d6502b71c8..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/EsHealthCheckDao.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.impl;
-
-import org.openecomp.sdc.be.dao.api.IEsHealthCheckDao;
-import org.openecomp.sdc.be.dao.es.ElasticSearchClient;
-import org.openecomp.sdc.common.api.HealthCheckInfo.HealthCheckStatus;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-
-@Component("esHealthCheckDao")
-public class EsHealthCheckDao implements IEsHealthCheckDao {
-
- private static Logger logger = Logger.getLogger(EsHealthCheckDao.class.getName());
-
- @Resource(name = "elasticsearch-client")
- private ElasticSearchClient esClient;
-
- @Resource
- private ESCatalogDAO esCatalogDao;
-
- public EsHealthCheckDao() {
- }
-
- public HealthCheckStatus getClusterHealthStatus() {
- return this.esCatalogDao.getHealth();
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/MonitoringDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/MonitoringDao.java
deleted file mode 100644
index 1c16c155a5..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/MonitoringDao.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.impl;
-
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.common.monitoring.MonitoringEvent;
-import org.springframework.stereotype.Component;
-
-@Component("monitoringDao")
-public class MonitoringDao extends ESTimeBasedDao {
-
- public static final String MONITORING_INDEX = "monitoring_events";
-
- @Override
- public String getIndexPrefix() {
- return MONITORING_INDEX;
- }
-
- public ActionStatus addRecord(MonitoringEvent monitoringEvent) {
- return write(monitoringEvent);
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jElementDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jElementDAO.java
deleted file mode 100644
index 7a5f873549..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jElementDAO.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.impl;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.api.IElementDAO;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElement;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
-import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
-import org.openecomp.sdc.be.dao.neo4j.Neo4jClient;
-import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus;
-import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import java.util.List;
-
-//@Component("elements-dao")
-public class Neo4jElementDAO implements IElementDAO {
-
- // @Resource
- Neo4jClient neo4jClient;
-
- private static Logger logger = Logger.getLogger(Neo4jElementDAO.class.getName());
-
- @Override
- public Either<List<GraphElement>, ActionStatus> getAllCategories() {
- MatchFilter filter = new MatchFilter();
- Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
- NodeTypeEnum.ResourceCategory.getName(), filter);
- if (status.isRight()) {
- return Either.right(ActionStatus.GENERAL_ERROR);
- } else {
- List<GraphElement> value = status.left().value();
- if (value == null || value.isEmpty()) {
- return Either.right(ActionStatus.GENERAL_ERROR);
- } else {
- return Either.left(value);
- }
- }
- }
-
- @Override
- public Either<List<GraphElement>, ActionStatus> getAllTags() {
- MatchFilter filter = new MatchFilter();
- Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
- NodeTypeEnum.Tag.getName(), filter);
- if (status.isRight()) {
- return Either.right(ActionStatus.GENERAL_ERROR);
- } else {
- List<GraphElement> value = status.left().value();
- if (value == null) {
- return Either.right(ActionStatus.GENERAL_ERROR);
- } else {
- return Either.left(value);
- }
- }
- }
-
- @Override
- public Either<GraphElement, ActionStatus> getCategory(String name) {
- MatchFilter filter = new MatchFilter();
- filter.addToMatch(GraphPropertiesDictionary.NAME.getProperty(), name);
- Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
- NodeTypeEnum.ResourceCategory.getName(), filter);
- if (status.isRight()) {
- return Either.right(ActionStatus.GENERAL_ERROR);
- } else {
- List<GraphElement> value = status.left().value();
- if (value == null) {
- return Either.right(ActionStatus.GENERAL_ERROR);
- } else {
- return Either.left(value.get(0));
- }
- }
-
- }
-
- /**
- * FOR TEST ONLY
- *
- * @param neo4jClient
- */
- public void setNeo4jClient(Neo4jClient neo4jClient) {
- this.neo4jClient = neo4jClient;
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jPropertyDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jPropertyDAO.java
deleted file mode 100644
index 8c3c5795a9..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jPropertyDAO.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.impl;
-
-import org.openecomp.sdc.be.dao.api.BasicDao;
-import org.openecomp.sdc.be.dao.api.IPropertyDAO;
-import org.openecomp.sdc.be.dao.neo4j.Neo4jClient;
-import org.openecomp.sdc.be.dao.neo4j.Neo4jGraphBatchBuilder;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import javax.annotation.PostConstruct;
-
-//@Component("neo4j-property-dao")
-public class Neo4jPropertyDAO extends BasicDao implements IPropertyDAO {
-
- // @Resource
- Neo4jClient neo4jClient;
-
- private static Logger logger = Logger.getLogger(Neo4jPropertyDAO.class.getName());
-
- Neo4jGraphBatchBuilder graphBatchBuilder = new Neo4jGraphBatchBuilder();
-
- public Neo4jPropertyDAO() {
-
- }
-
- @PostConstruct
- public void init() {
- setNeo4jClient(neo4jClient);
- }
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jResourceDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jResourceDAO.java
deleted file mode 100644
index 9cf75f15e3..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jResourceDAO.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.impl;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.api.BasicDao;
-import org.openecomp.sdc.be.dao.api.IResourceDAO;
-import org.openecomp.sdc.be.dao.graph.datatype.*;
-import org.openecomp.sdc.be.dao.neo4j.*;
-import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter;
-import org.openecomp.sdc.be.dao.neo4j.filters.RecursiveFilter;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import javax.annotation.PostConstruct;
-import java.util.List;
-import java.util.Map;
-
-//@Component("neo4j-resource-dao")
-public class Neo4jResourceDAO extends BasicDao implements IResourceDAO {
-
- // @Resource
- Neo4jClient neo4jClient;
-
- private static Logger logger = Logger.getLogger(Neo4jResourceDAO.class.getName());
-
- Neo4jGraphBatchBuilder graphBatchBuilder = new Neo4jGraphBatchBuilder();
-
- public Neo4jResourceDAO() {
-
- }
-
- @PostConstruct
- public void init() {
- super.setNeo4jClient(neo4jClient);
- }
-
- private String findResourceDataIdFromNodes(List<GraphNode> nodes) {
-
- if (nodes != null) {
-
- for (GraphNode neo4jNode : nodes) {
- String label = neo4jNode.getLabel();
- if (label.equals(NodeTypeEnum.Resource.getName())) {
- return neo4jNode.getUniqueId().toString();
- }
- }
- }
-
- return null;
- }
-
- private GraphRelation addStateRelation(RelationEndPoint from, RelationEndPoint to, GraphEdgeLabels edgeLabel,
- String value) {
-
- GraphRelation relationState = new GraphRelation();
- relationState.setFrom(from);
- relationState.setTo(to);
- relationState.setType(edgeLabel.name());
- relationState.setAction(ActionEnum.Create);
- return relationState;
- }
-
- // private ActionStatus convertNeo4jOperationStatusToActionStatus(
- // Neo4jOperationStatus value) {
- //
- // if (value == null) {
- // return ActionStatus.GENERAL_ERROR;
- // }
- //
- // switch (value) {
- // case NOT_FOUND:
- // return ActionStatus.RESOURCE_NOT_FOUND;
- // case ERROR:
- // return ActionStatus.GENERAL_ERROR;
- // case NOT_SUPPORTED:
- // return ActionStatus.INVALID_CONTENT;
- // case WRONG_INPUT:
- // return ActionStatus.INVALID_CONTENT;
- // case OK:
- // return ActionStatus.OK;
- // default:
- // return ActionStatus.GENERAL_ERROR;
- // }
- //
- // }
-
- @Override
- public Either<ResourceMetadataData, Neo4jOperationStatus> getResourceData(String id) {
-
- MatchFilter filter = new MatchFilter();
- filter.addToMatch(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), id);
- Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
- NodeTypeEnum.Resource.getName(), filter);
-
- if (status.isRight()) {
- return Either.right(status.right().value());
- } else {
- List<GraphElement> value = status.left().value();
- if (value == null || value.isEmpty()) {
- return Either.right(Neo4jOperationStatus.NOT_FOUND);
- } else {
- return Either.left((ResourceMetadataData) value.get(0));
- }
- }
- }
-
- @Override
- public Either<Integer, Neo4jOperationStatus> getNumberOfResourcesByName(String name) {
-
- MatchFilter filter = new MatchFilter();
- filter.addToMatch(GraphPropertiesDictionary.NAME.getProperty(), name);
- Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
- NodeTypeEnum.Resource.getName(), filter);
-
- if (status.isRight() || (status.left().value() == null)) {
- return Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- } else {
- List<GraphElement> value = status.left().value();
- return Either.left(value.size());
- }
- }
-
- @Override
- public void setNeo4jClient(Neo4jClient client) {
- this.neo4jClient = client;
- super.setNeo4jClient(client);
- }
-
- @Override
- public Either<List<ResourceMetadataData>, Neo4jOperationStatus> getAllResourcesData(
- Map<String, Object> propertiesToMatch) {
-
- RecursiveFilter filter = new RecursiveFilter(NodeTypeEnum.Resource);
- // filter.addRelationType("typeof").addRelationType("belong").setProperties(propertiesToMatch);
-
- Either<List<List<GraphElement>>, Neo4jOperationStatus> ret = neo4jClient.executeGet(filter);
- if (ret.isRight()) {
- return Either.right(ret.right().value());
- }
- List<List<GraphElement>> listOfListOfNeo4jElement = ret.left().value();
-
- for (List<GraphElement> row : listOfListOfNeo4jElement) {
-
- for (GraphElement elem : row) {
-
- }
- }
- return Either.right(null);
-
- /*
- * MatchFilter filter = new MatchFilter(); if(propertiesToMatch !=
- * null){ for (Entry<String,Object> propertie :
- * propertiesToMatch.entrySet()){ filter.addToMatch(propertie.getKey(),
- * propertie.getValue()); } } Either<List<GraphElement>,
- * Neo4jOperationStatus> status =
- * neo4jClient.getByFilter(GraphElementTypeEnum.Node,
- * NodeTypeEnum.Resource.getName(), filter); if (status.isRight()) {
- * return Either.right(status.right().value()); } else {
- * List<GraphElement> value = status.left().value(); if (value == null
- * || value.isEmpty()) { return
- * Either.right(Neo4jOperationStatus.NOT_FOUND); } else {
- * List<ResourceData> result=new ArrayList<>(); for(GraphElement element
- * : value ){ result.add((ResourceData)element); } return
- * Either.left(result); } }
- */
- }
-
- // @Override
- // public ActionStatus updateUserData(UserData userData) {
- // UpdateFilter filter = new UpdateFilter();
- // filter.addToMatch("userId", userData.getUserId());
- // filter.setToUpdate(userData.toMap());
- // Neo4jOperationStatus status =
- // neo4jClient.updateElement(Neo4JElementTypeEnum.Node,
- // NodeTypeEnum.User.getName(), filter);
- // if (status.equals(Neo4jOperationStatus.OK)) {
- // return ActionStatus.OK;
- // } else {
- // return ActionStatus.GENERAL_ERROR;
- // }
- // }
- //
- // @Override
- // public ActionStatus deleteUserData(String id) {
- // MatchFilter filter = new MatchFilter();
- // filter.addToMatch("userId", id);
- // Neo4jOperationStatus status =
- // neo4jClient.deleteElement(Neo4JElementTypeEnum.Node,
- // NodeTypeEnum.User.getName(), filter);
- // if (status.equals(Neo4jOperationStatus.OK)) {
- // return ActionStatus.OK;
- // } else {
- // return ActionStatus.GENERAL_ERROR;
- // }
- // }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java
deleted file mode 100644
index 5b2498a531..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/impl/Neo4jUsersDAO.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.impl;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.api.ActionStatus;
-import org.openecomp.sdc.be.dao.api.IUsersDAO;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElement;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
-import org.openecomp.sdc.be.dao.neo4j.Neo4jClient;
-import org.openecomp.sdc.be.dao.neo4j.Neo4jOperationStatus;
-import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter;
-import org.openecomp.sdc.be.dao.neo4j.filters.UpdateFilter;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.resources.data.UserData;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import javax.annotation.PostConstruct;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-//@Component("users-dao")
-public class Neo4jUsersDAO implements IUsersDAO {
-
- private static final String USER_ID = "userId";
-
- // @Resource
- Neo4jClient neo4jClient;
-
- private static Logger logger = Logger.getLogger(Neo4jUsersDAO.class.getName());
-
- public Neo4jUsersDAO() {
-
- }
-
- @PostConstruct
- public void init() {
- }
-
- private void createIndexesAndConstraints() {
- Either<Map<String, List<String>>, Neo4jOperationStatus> statusInd = neo4jClient
- .getIndexes(NodeTypeEnum.User.getName());
- if (statusInd.isRight()) {
- logger.error("Failed to get indexes from Neo4j graph");
- throw new RuntimeException("Failed to initialize Neo4jUsersDAO - Failed to get indexes from Neo4j graph");
- }
- Map<String, List<String>> indexes = statusInd.left().value();
- if (indexes == null || indexes.isEmpty()) {
- logger.info("Define users indexes in Neo4j");
- List<String> propertyNames = new ArrayList<>();
- propertyNames.add("firstName");
- propertyNames.add("lastName");
- propertyNames.add("email");
- propertyNames.add("role");
- logger.info("Start create Users indexes in Neo4jGraph");
- Neo4jOperationStatus createIndexStatus = neo4jClient.createIndex(NodeTypeEnum.User.getName(),
- propertyNames);
- if (createIndexStatus.equals(Neo4jOperationStatus.OK)) {
- logger.info("Users indexes created in Neo4j");
- List<String> propertyUnique = new ArrayList<>();
- propertyUnique.add(USER_ID);
-
- logger.info("Start create Users constraints in Neo4jGraph");
- Neo4jOperationStatus createUniquenessStatus = neo4jClient
- .createUniquenessConstraints(NodeTypeEnum.User.getName(), propertyUnique);
- if (createUniquenessStatus.equals(Neo4jOperationStatus.OK)) {
- logger.info("Users constraints creatyed in Neo4j");
- } else {
- logger.error("Failed to create constraints in Neo4j graph [{}]", createUniquenessStatus);
- throw new RuntimeException(
- "Failed to initialize Neo4jUsersDAO - Failed to create constraints in Neo4j graph");
- }
- } else {
- logger.error("Failed to create indexes in Neo4j graph [{}]", createIndexStatus);
- throw new RuntimeException(
- "Failed to initialize Neo4jUsersDAO - Failed to create indexes in Neo4j graph");
- }
- } else {
- logger.info("Users indexes already defined in Neo4j");
- }
- }
-
- @Override
- public Either<UserData, ActionStatus> getUserData(String id) {
- MatchFilter filter = new MatchFilter();
- filter.addToMatch(USER_ID, id);
- Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
- NodeTypeEnum.User.getName(), filter);
- if (status.isRight()) {
- return Either.right(ActionStatus.GENERAL_ERROR);
- } else {
- List<GraphElement> value = status.left().value();
- if (value == null || value.isEmpty()) {
- return Either.right(ActionStatus.USER_NOT_FOUND);
- } else {
- return Either.left((UserData) value.get(0));
- }
- }
- }
-
- @Override
- public ActionStatus saveUserData(UserData userData) {
- Neo4jOperationStatus status = neo4jClient.createElement(userData);
- if (status.equals(Neo4jOperationStatus.OK)) {
- return ActionStatus.OK;
- } else {
- return ActionStatus.GENERAL_ERROR;
- }
- }
-
- @Override
- public ActionStatus updateUserData(UserData userData) {
- UpdateFilter filter = new UpdateFilter();
- filter.addToMatch(USER_ID, userData.getUserId());
- filter.setToUpdate(userData.toGraphMap());
- Neo4jOperationStatus status = neo4jClient.updateElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(),
- filter);
- if (status.equals(Neo4jOperationStatus.OK)) {
- return ActionStatus.OK;
- } else {
- return ActionStatus.GENERAL_ERROR;
- }
- }
-
- @Override
- public ActionStatus deleteUserData(String id) {
- MatchFilter filter = new MatchFilter();
- filter.addToMatch(USER_ID, id);
- Neo4jOperationStatus status = neo4jClient.deleteElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(),
- filter);
- if (status.equals(Neo4jOperationStatus.OK)) {
- return ActionStatus.OK;
- } else {
- return ActionStatus.GENERAL_ERROR;
- }
- }
-
- public Neo4jClient getNeo4jClient() {
- return neo4jClient;
- }
-
- public void setNeo4jClient(Neo4jClient neo4jClient) {
- this.neo4jClient = neo4jClient;
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphClient.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphClient.java
index 5be907cc86..a44bbd8e12 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphClient.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphClient.java
@@ -42,6 +42,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.*;
@@ -58,6 +59,13 @@ public class JanusGraphClient {
public JanusGraphClient() {
}
+ @PreDestroy
+ public void closeSession(){
+ if ( graph.isOpen() ){
+ graph.close();
+ logger.info("** JanusGraphClient session closed");
+ }
+ }
private class HealthCheckTask implements Callable<Vertex> {
@Override
public Vertex call() {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java
index f679a5c103..2174c8d295 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/janusgraph/JanusGraphGenericDao.java
@@ -58,12 +58,10 @@ import org.openecomp.sdc.be.resources.data.GraphNodeLock;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Qualifier;
+import javax.validation.constraints.NotNull;
public class JanusGraphGenericDao {
- private static final String FAILED_TO_RETRIEVE_GRAPH_STATUS_IS = "Failed to retrieve graph. status is {}";
- private static final String NO_EDGES_IN_GRAPH_FOR_CRITERIA = "No edges in graph for criteria";
- private static final String FAILED_TO_CREATE_EDGE_FROM_TO = "Failed to create edge from [{}] to [{}]";
- private JanusGraphClient janusGraphClient;
+ private JanusGraphClient janusGraphClient;
private static Logger log = Logger.getLogger(JanusGraphGenericDao.class.getName());
private static final String LOCK_NODE_PREFIX = "lock_";
@@ -108,7 +106,7 @@ public class JanusGraphGenericDao {
* @return
*/
public <T extends GraphNode> Either<T, JanusGraphOperationStatus> createNode(T node, Class<T> clazz) {
- log.debug("try to create node for ID [{}]", node.getKeyValueId());
+ log.debug("try to create node for ID [{}]", node.getKeyValueIdForLog());
Either<JanusGraph, JanusGraphOperationStatus> graph = janusGraphClient.getGraph();
if (graph.isLeft()) {
T newNode;
@@ -126,7 +124,7 @@ public class JanusGraphGenericDao {
Map<String, Object> newProps = getProperties(vertex);
newNode = GraphElementFactory.createElement(node.getLabel(), GraphElementTypeEnum.Node, newProps, clazz);
log.debug("created node for props : {}", newProps);
- log.debug("Node was created for ID [{}]", node.getKeyValueId());
+ log.debug("Node was created for ID [{}]", node.getKeyValueIdForLog());
return Either.left(newNode);
} catch (Exception e) {
@@ -135,7 +133,7 @@ public class JanusGraphGenericDao {
}
} else {
- log.debug("Failed to create Node for ID [{}] {}", node.getKeyValueId(), graph.right().value());
+ log.debug("Failed to create Node for ID [{}] {}", node.getKeyValueIdForLog(), graph.right().value());
return Either.right(graph.right().value());
}
}
@@ -229,8 +227,8 @@ public class JanusGraphGenericDao {
return Either.left(newRelation);
} catch (Exception e) {
- log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, from, to, e);
- return Either.right(JanusGraphClient.handleJanusGraphException(e));
+ log.debug("Failed to create edge from [{}] to [{}]", from, to, e);
+ return Either.right(janusGraphClient.handleJanusGraphException(e));
}
} else {
log.debug("Failed to create edge from [{}] to [{}] {}", from, to, graph.right().value());
@@ -242,8 +240,8 @@ public class JanusGraphGenericDao {
try {
Edge edge = addEdge(vertexOut, vertexIn, type, properties);
} catch (Exception e) {
- log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, vertexOut, vertexIn, e);
- return JanusGraphClient.handleJanusGraphException(e);
+ log.debug("Failed to create edge from [{}] to [{}]", vertexOut, vertexIn, e);
+ return janusGraphClient.handleJanusGraphException(e);
}
return JanusGraphOperationStatus.OK;
@@ -279,8 +277,8 @@ public class JanusGraphGenericDao {
Edge edge = addEdge(vertexOut, vertexIn, type, properties);
return Either.left(edge);
} catch (Exception e) {
- log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, vertexOut, vertexIn, e);
- return Either.right(JanusGraphClient.handleJanusGraphException(e));
+ log.debug("Failed to create edge from [{}] to [{}]", vertexOut, vertexIn, e);
+ return Either.right(janusGraphClient.handleJanusGraphException(e));
}
}
@@ -471,7 +469,7 @@ public class JanusGraphGenericDao {
Edge matchingEdge = null;
Iterable<JanusGraphEdge> edges = query.edges();
if (edges == null) {
- log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
+ log.debug("No edges in graph for criteria");
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
Iterator<JanusGraphEdge> eIter = edges.iterator();
@@ -480,7 +478,7 @@ public class JanusGraphGenericDao {
}
if (matchingEdge == null) {
- log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
+ log.debug("No edges in graph for criteria");
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);
@@ -495,7 +493,7 @@ public class JanusGraphGenericDao {
if (vertexFrom.isRight()) {
return Either.right(vertexFrom.right().value());
}
- Iterable<JanusGraphEdge> edges = vertexFrom.left().value().query().labels(label).edges();
+ Iterable<JanusGraphEdge> edges = ((JanusGraphVertex) vertexFrom.left().value()).query().labels(label).edges();
Iterator<JanusGraphEdge> eIter = edges.iterator();
while (eIter.hasNext()) {
Edge edge = eIter.next();
@@ -925,7 +923,7 @@ public class JanusGraphGenericDao {
* @return
*/
public <T extends GraphNode> Either<T, JanusGraphOperationStatus> updateNode(GraphNode node, Class<T> clazz) {
- log.debug("Try to update node for {}", node.getKeyValueId());
+ log.debug("Try to update node for {}", node.getKeyValueIdForLog());
ImmutablePair<String, Object> keyValueId = node.getKeyValueId();
Either<Vertex, JanusGraphOperationStatus> vertexByProperty = getVertexByPropertyAndLabel(keyValueId.getKey(), keyValueId.getValue(), node.getLabel());
@@ -958,7 +956,7 @@ public class JanusGraphGenericDao {
}
} else {
if (log.isDebugEnabled()) {
- log.debug("Failed to update node for {} error :{}", node.getKeyValueId(), vertexByProperty.right().value());
+ log.debug("Failed to update node for {} error :{}", node.getKeyValueIdForLog(), vertexByProperty.right().value());
}
return Either.right(vertexByProperty.right().value());
}
@@ -1314,7 +1312,7 @@ public class JanusGraphGenericDao {
Either<JanusGraph, JanusGraphOperationStatus> graphRes = janusGraphClient.getGraph();
if (graphRes.isRight()) {
- log.error(FAILED_TO_RETRIEVE_GRAPH_STATUS_IS, graphRes);
+ log.error("Failed to retrieve graph. status is {}", graphRes);
return Either.right(graphRes.right().value());
}
@@ -1362,7 +1360,7 @@ public class JanusGraphGenericDao {
Either<JanusGraph, JanusGraphOperationStatus> graphRes = janusGraphClient.getGraph();
if (graphRes.isRight()) {
- log.error(FAILED_TO_RETRIEVE_GRAPH_STATUS_IS, graphRes);
+ log.error("Failed to retrieve graph. status is {}", graphRes);
return Either.right(graphRes.right().value());
}
@@ -1487,7 +1485,7 @@ public class JanusGraphGenericDao {
Either<JanusGraph, JanusGraphOperationStatus> graphRes = janusGraphClient.getGraph();
if (graphRes.isRight()) {
- log.error(FAILED_TO_RETRIEVE_GRAPH_STATUS_IS, graphRes);
+ log.error("Failed to retrieve graph. status is {}", graphRes);
return Either.right(graphRes.right().value());
}
@@ -1610,7 +1608,7 @@ public class JanusGraphGenericDao {
Edge matchingEdge = null;
Iterable<JanusGraphEdge> edges = query.edges();
if (edges == null) {
- log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
+ log.debug("No edges in graph for criteria");
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
Iterator<JanusGraphEdge> eIter = edges.iterator();
@@ -1619,7 +1617,7 @@ public class JanusGraphGenericDao {
}
if (matchingEdge == null) {
- log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
+ log.debug("No edges in graph for criteria");
return Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);
@@ -1732,7 +1730,7 @@ public class JanusGraphGenericDao {
return Either.left(result);
}
- public Either<List<Edge>, JanusGraphOperationStatus> getOutgoingEdgesByCriteria(Vertex vertexFrom, GraphEdgeLabels label, Map<String, Object> props) {
+ public @NotNull Either<List<Edge>, JanusGraphOperationStatus> getOutgoingEdgesByCriteria(Vertex vertexFrom, GraphEdgeLabels label, Map<String, Object> props) {
List<Edge> edgesResult = new ArrayList<>();
@@ -1749,9 +1747,9 @@ public class JanusGraphGenericDao {
Iterable<JanusGraphEdge> edges = query.edges();
Iterator<JanusGraphEdge> eIter = edges.iterator();
- if (edges == null || !eIter.hasNext()) {
+ if (!eIter.hasNext()) {
log.debug("No edges found in graph for criteria (label = {} properties={})", label.getProperty(), props);
- return Either.right(JanusGraphOperationStatus.NOT_FOUND);
+ return Either.left(edgesResult);
}
while (eIter.hasNext()) {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/GraphVertex.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/GraphVertex.java
index 2db22a72b0..11dcdceaaf 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/GraphVertex.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/GraphVertex.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.dao.jsongraph;
import org.janusgraph.core.JanusGraphVertex;
+import com.google.common.base.Strings;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
@@ -87,6 +88,13 @@ public class GraphVertex {
}
public ComponentTypeEnum getType() {
+ if(getMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE) == null) {
+ if (getMetadataProperty(GraphPropertyEnum.RESOURCE_TYPE) != null) {
+ return ComponentTypeEnum.RESOURCE;
+ }
+ return null;
+ }
+
return ComponentTypeEnum.valueOf((String) getMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE));
}
@@ -121,7 +129,7 @@ public class GraphVertex {
public void getOrSetDefaultInstantiationTypeForToscaElementJson(){
String toscaVertexJsonInstantiationType;
toscaVertexJsonInstantiationType = (String)(this.getJsonMetadataField(JsonPresentationFields.INSTANTIATION_TYPE));
- if (toscaVertexJsonInstantiationType == StringUtils.EMPTY || toscaVertexJsonInstantiationType == null){
+ if (Strings.isNullOrEmpty(toscaVertexJsonInstantiationType)) {
this.setJsonMetadataField(JsonPresentationFields.INSTANTIATION_TYPE, InstantiationTypes.A_LA_CARTE.getValue());
};
};
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/HealingJanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/HealingJanusGraphDao.java
index 90c0d9157a..510accdd12 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/HealingJanusGraphDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/HealingJanusGraphDao.java
@@ -41,10 +41,10 @@ public class HealingJanusGraphDao extends JanusGraphDao {
}
@Override
- public Either<List<GraphVertex>, JanusGraphOperationStatus> getChildrenVertecies(GraphVertex parentVertex,
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> getChildrenVertices(GraphVertex parentVertex,
EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies =
- super.getChildrenVertecies(parentVertex, edgeLabel, parseFlag);
+ super.getChildrenVertices(parentVertex, edgeLabel, parseFlag);
return Either.iif(childrenVertecies.isRight(), () -> childrenVertecies.right().value(),
() -> childrenVertecies.left().value().stream()
.map(graphVertex -> transformVertex(graphVertex, edgeLabel))
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
index 5917b14fd3..65b6c618d8 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/JanusGraphDao.java
@@ -252,7 +252,7 @@ public class JanusGraphDao {
}
}
- public void setVertexProperties(Vertex vertex, Map<String, Object> properties) {
+ public void setVertexProperties(Vertex vertex, Map<String, Object> properties) throws IOException {
for (Map.Entry<String, Object> entry : properties.entrySet()) {
if (entry.getValue() != null) {
vertex.property(entry.getKey(), entry.getValue());
@@ -351,6 +351,7 @@ public class JanusGraphDao {
result.put(valueOf, value);
}
}
+ // add print to properties that can't be converted by enum
}
return result;
}
@@ -574,7 +575,7 @@ public class JanusGraphDao {
* @return
*/
public Either<GraphVertex, JanusGraphOperationStatus> getChildVertex(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
- Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies = getChildrenVertecies(parentVertex, edgeLabel, parseFlag);
+ Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies = getChildrenVertices(parentVertex, edgeLabel, parseFlag);
if (childrenVertecies.isRight()) {
return Either.right(childrenVertecies.right().value());
}
@@ -589,7 +590,7 @@ public class JanusGraphDao {
* @return
*/
public Either<Vertex, JanusGraphOperationStatus> getChildVertex(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
- Either<List<Vertex>, JanusGraphOperationStatus> childrenVertecies = getChildrenVertecies(parentVertex, edgeLabel, parseFlag);
+ Either<List<Vertex>, JanusGraphOperationStatus> childrenVertecies = getChildrenVertices(parentVertex, edgeLabel, parseFlag);
if (childrenVertecies.isRight()) {
return Either.right(childrenVertecies.right().value());
}
@@ -597,7 +598,7 @@ public class JanusGraphDao {
}
public Either<GraphVertex, JanusGraphOperationStatus> getParentVertex(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
- Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies = getParentVertecies(parentVertex, edgeLabel, parseFlag);
+ Either<List<GraphVertex>, JanusGraphOperationStatus> childrenVertecies = getParentVertices(parentVertex, edgeLabel, parseFlag);
if (childrenVertecies.isRight()) {
return Either.right(childrenVertecies.right().value());
}
@@ -608,7 +609,7 @@ public class JanusGraphDao {
}
public Either<Vertex, JanusGraphOperationStatus> getParentVertex(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
- Either<List<Vertex>, JanusGraphOperationStatus> childrenVertecies = getParentVertecies(parentVertex, edgeLabel, parseFlag);
+ Either<List<Vertex>, JanusGraphOperationStatus> childrenVertecies = getParentVertices(parentVertex, edgeLabel, parseFlag);
if (childrenVertecies.isRight() ) {
return Either.right(childrenVertecies.right().value());
}
@@ -625,19 +626,19 @@ public class JanusGraphDao {
* @param parseFlag
* @return
*/
- public Either<List<GraphVertex>, JanusGraphOperationStatus> getChildrenVertecies(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
- return getAdjacentVerticies(parentVertex, edgeLabel, parseFlag, Direction.OUT);
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> getChildrenVertices(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ return getAdjacentVertices(parentVertex, edgeLabel, parseFlag, Direction.OUT);
}
- public Either<List<GraphVertex>, JanusGraphOperationStatus> getParentVertecies(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
- return getAdjacentVerticies(parentVertex, edgeLabel, parseFlag, Direction.IN);
+ public Either<List<GraphVertex>, JanusGraphOperationStatus> getParentVertices(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ return getAdjacentVertices(parentVertex, edgeLabel, parseFlag, Direction.IN);
}
- public Either<List<Vertex>, JanusGraphOperationStatus> getParentVertecies(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
- return getAdjacentVerticies(parentVertex, edgeLabel, parseFlag, Direction.IN);
+ public Either<List<Vertex>, JanusGraphOperationStatus> getParentVertices(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ return getAdjacentVertices(parentVertex, edgeLabel, parseFlag, Direction.IN);
}
- private Either<List<Vertex>, JanusGraphOperationStatus> getAdjacentVerticies(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag, Direction direction) {
+ private Either<List<Vertex>, JanusGraphOperationStatus> getAdjacentVertices(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag, Direction direction) {
List<Vertex> list = new ArrayList<>();
try {
Either<JanusGraph, JanusGraphOperationStatus> graphRes = janusGraphClient.getGraph();
@@ -678,14 +679,14 @@ public class JanusGraphDao {
* @param parseFlag
* @return
*/
- public Either<List<Vertex>, JanusGraphOperationStatus> getChildrenVertecies(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
- return getAdjacentVerticies(parentVertex, edgeLabel, parseFlag, Direction.OUT);
+ public Either<List<Vertex>, JanusGraphOperationStatus> getChildrenVertices(Vertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag) {
+ return getAdjacentVertices(parentVertex, edgeLabel, parseFlag, Direction.OUT);
}
- private Either<List<GraphVertex>, JanusGraphOperationStatus> getAdjacentVerticies(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag, Direction direction) {
+ private Either<List<GraphVertex>, JanusGraphOperationStatus> getAdjacentVertices(GraphVertex parentVertex, EdgeLabelEnum edgeLabel, JsonParseFlagEnum parseFlag, Direction direction) {
List<GraphVertex> list = new ArrayList<>();
- Either<List<Vertex>, JanusGraphOperationStatus> adjacentVerticies = getAdjacentVerticies(parentVertex.getVertex(), edgeLabel, parseFlag, direction);
+ Either<List<Vertex>, JanusGraphOperationStatus> adjacentVerticies = getAdjacentVertices(parentVertex.getVertex(), edgeLabel, parseFlag, direction);
if (adjacentVerticies.isRight()) {
return Either.right(adjacentVerticies.right().value());
}
@@ -816,12 +817,45 @@ public class JanusGraphDao {
public Either<Edge, JanusGraphOperationStatus> deleteEdge(JanusGraphVertex fromVertex, JanusGraphVertex toVertex, EdgeLabelEnum label, String uniqueIdFrom, String uniqueIdTo, boolean deleteAll) {
Either<Edge, JanusGraphOperationStatus> result = null;
+ Vertex problemV = null;
try {
Iterable<JanusGraphEdge> edges = fromVertex.query().labels(label.name()).edges();
Iterator<JanusGraphEdge> eIter = edges.iterator();
while (eIter.hasNext()) {
Edge edge = eIter.next();
- String currVertexUniqueId = edge.inVertex().value(GraphPropertyEnum.UNIQUE_ID.getProperty());
+ problemV = edge.inVertex();
+ String currVertexUniqueId = null;
+ try {
+ currVertexUniqueId = edge.inVertex().value(GraphPropertyEnum.UNIQUE_ID.getProperty());
+ }catch (Exception e){
+ // AutoHealing procedure
+ logger.info( "Corrupted vertex and edge were found and deleted {}",e);
+ if ( problemV != null ) {
+ Map<GraphPropertyEnum, Object> props = getVertexProperties(problemV);
+ logger.debug( "problematic Vertex properties:");
+ logger.debug( "props size: {}", props.size());
+ for (Map.Entry<GraphPropertyEnum, Object> entry : props.entrySet()) {
+ logger.debug( "{}{}",entry.getKey() + ":" + entry.getValue());
+ }
+ Either<List<Vertex>, JanusGraphOperationStatus> childrenVertices = getChildrenVertices(problemV, EdgeLabelEnum.VERSION, JsonParseFlagEnum.NoParse);
+ if(childrenVertices.isLeft()){
+ childrenVertices.left().value().size();
+ logger.debug( "number of children that problematic Vertex has: {}", props.size());
+ }
+ try {
+ edge.remove();
+ }catch (Exception e1){
+ logger.debug( "failed to remove problematic edge. {}", e1);
+ }
+ try {
+ problemV.remove();
+ }catch (Exception e2){
+ logger.debug( "failed to remove problematic vertex . {}", e2);
+ }
+ }
+ continue;
+ }
+
if (currVertexUniqueId != null && currVertexUniqueId.equals(uniqueIdTo)) {
CommonUtility.addRecordToLog(logger, LogLevelEnum.TRACE, "Going to delete an edge with the label {} between vertices {} and {}. ", label.name(), uniqueIdFrom, uniqueIdTo);
edge.remove();
@@ -836,6 +870,7 @@ public class JanusGraphDao {
result = Either.right(JanusGraphOperationStatus.NOT_FOUND);
}
} catch (Exception e) {
+
CommonUtility.addRecordToLog(logger, LogLevelEnum.DEBUG, "Exception occured during deleting an edge with the label {} between vertices {} and {}. {}", label.name(), uniqueIdFrom, uniqueIdTo, e);
return Either.right(JanusGraphClient.handleJanusGraphException(e));
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java
deleted file mode 100644
index a13c23140e..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/BatchBuilder.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j;
-
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElement;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class BatchBuilder {
-
- private List<GraphElement> elements;
-
- protected BatchBuilder() {
- elements = new ArrayList<>();
- }
-
- public static BatchBuilder getBuilder() {
- return new BatchBuilder();
- }
-
- public BatchBuilder add(GraphElement element) {
- elements.add(element);
- return this;
- }
-
- public List<GraphElement> getElements() {
- return elements;
- }
-
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTemplates.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTemplates.java
deleted file mode 100644
index b0b2cc20bb..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTemplates.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j;
-
-public interface CypherTemplates {
-
- public static final String CypherUrlTemplate = "http://$host$:$port$/db/data/transaction/commit";
- public static final String batchTemplate = "http://$host$:$port$/db/data/batch";
- public static final String getAllIndexsTemplate = "http://$host$:$port$/db/data/schema/index";
-
- public static final String CypherCreateNodeTemplate = "{\n\"statements\" : [ {\n \"statement\" : \"CREATE (n:$label$ { props } ) RETURN n\",\n \"parameters\" : { \n \"props\" : $props$ \n } } ] }";
-
- public static final String CypherMatchTemplate = "{\"statements\": [{\"statement\": \"MATCH (n:$label$ {$filter$}) RETURN ($type$) \" }]}";
-
- public static final String CypherUpdateTemplate = "{\"statements\": [{\"statement\": \"MATCH (n:$label$ {$filter$}) SET n += {props} RETURN ($type$) \",\"parameters\" : {\"props\" : {$props$}}}]}";
- public static final String CypherDeleteNodeTemplate = "{\"statements\": [{\"statement\": \"MATCH ( n:$label$ {$filter$} ) DELETE n \" }]}";
-
- public static final String BatchTemplate = "{ \"statements\" : [ $statementList$ ] }";
-
- public static final String RegularStatementTemplate = "{ \"statement\" : $statement$ }";
-
- public static final String CreateSingleNodeTemplate = " \"CREATE (n:$label$ { props } ) RETURN n, labels(n)\", \"parameters\" : { \"props\" : $props$ }";
-
- public static final String CreateRelationTemplate = "\"MATCH (a:$labelFrom$),(b:$labelTo$) WHERE a.$idNameFrom$ = '$idValueFrom$' AND b.$idNameTo$ = '$idvalueTo$' CREATE (a)-[r:$type$ { props } ]->(b) RETURN a, labels(a), b, labels(b), r, type(r)\", \"parameters\": {\"props\": $props$ } ";
-
- public static final String CreateRelationTemplateNoProps = "\"MATCH (a:$labelFrom$),(b:$labelTo$) WHERE a.$idNameFrom$ = '$idValueFrom$' AND b.$idNameTo$ = '$idvalueTo$' CREATE (a)-[r:$type$ ]->(b) RETURN a,labels(a), b, labels(b), r, type(r)\"";
-
- public static final String UpdateNodeStatementTemplate = "\"MATCH (n:$label$ {$filter$}) SET n += {props} \",\"parameters\" : {\"props\" : $props$}";
-
- public static final String GetNodeRecursiveTemplate = "\"MATCH (m:$label$ {$filter$} )-[f$typesList$]->l RETURN m, labels(m), l, labels(l),f, type(f)\"";
-
- public static final String GetByRelationNodeRecursiveTemplate = "\"MATCH (n:$labelNode$ ($propsNode$} )-[r:$type$ {$propsRel$}]->(m:$labelSrc$)-[f$typesList$]->l RETURN n, labels(n), r, type(r), m, labels(m), l, labels(l),f, type(f)\"";
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTranslator.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTranslator.java
deleted file mode 100644
index 2f53736c59..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/CypherTranslator.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j;
-
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElement;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
-import org.openecomp.sdc.be.dao.graph.datatype.RelationEndPoint;
-import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter;
-import org.openecomp.sdc.be.dao.neo4j.filters.RecursiveByRelationFilter;
-import org.openecomp.sdc.be.dao.neo4j.filters.RecursiveFilter;
-import org.openecomp.sdc.be.dao.utils.DaoUtils;
-
-import java.util.List;
-import java.util.Map;
-
-public class CypherTranslator {
-
- public String translate(BatchBuilder builder) {
- String json = null;
- StringBuilder statementList = new StringBuilder();
-
- List<GraphElement> elements = builder.getElements();
- int statementCounter = 0;
- for (GraphElement element : elements) {
- String singleStatementBody = null;
- switch (element.getElementType()) {
- case Node:
- singleStatementBody = prepareNodeStatement(element);
- break;
- case Relationship:
- singleStatementBody = prepareRelationStatement(element);
- break;
- }
- if (singleStatementBody != null && !singleStatementBody.isEmpty()) {
-
- String singleStatement = CypherTemplates.RegularStatementTemplate.replace("$statement$",
- singleStatementBody);
-
- statementList.append(singleStatement);
- }
- ++statementCounter;
- if (statementCounter < elements.size() && singleStatementBody != null) {
- statementList.append(",");
- }
-
- }
- json = CypherTemplates.BatchTemplate.replace("$statementList$", statementList.toString());
- return json;
- }
-
- private String prepareNodeStatement(GraphElement element) {
- if (element instanceof GraphNode) {
- GraphNode node = (GraphNode) element;
-
- switch (node.getAction()) {
- case Create:
- return createNodeStatement(node);
- case Update:
- return updateNodeStatement(node);
- case Delete:
- // TODO
- break;
- default:
- break;
- }
- }
- return null;
- }
-
- private String updateNodeStatement(GraphNode node) {
- String singleStatement = CypherTemplates.UpdateNodeStatementTemplate.replace("$label$", node.getLabel());
- String filter = prepareKeyValueFilter(node);
-
- singleStatement = singleStatement.replace("$filter$", filter);
-
- singleStatement = singleStatement.replace("$props$", DaoUtils.convertToJson(node.toGraphMap()));
-
- return singleStatement;
- }
-
- private String createNodeStatement(GraphNode node) {
- String singleStatement = CypherTemplates.CreateSingleNodeTemplate.replace("$label$", node.getLabel());
-
- singleStatement = singleStatement.replace("$props$", DaoUtils.convertToJson(node.toGraphMap()));
- return singleStatement;
- }
-
- private String prepareRelationStatement(GraphElement element) {
- if (element instanceof GraphRelation) {
-
- GraphRelation relation = (GraphRelation) element;
-
- switch (relation.getAction()) {
- case Create:
- return createRelationStatement(relation);
- case Update:
- return updateRelationStatement(relation);
- case Delete:
- // TODO
- break;
- default:
- break;
- }
- }
- return null;
- }
-
- private String createRelationStatement(GraphRelation relation) {
- RelationEndPoint from = relation.getFrom();
- String singleStatement;
-
- Map<String, Object> props = relation.toGraphMap();
- if (props == null || props.isEmpty()) {
- singleStatement = CypherTemplates.CreateRelationTemplateNoProps.replace("$labelFrom$",
- from.getLabel().getName());
- } else {
- singleStatement = CypherTemplates.CreateRelationTemplate.replace("$labelFrom$", from.getLabel().getName());
- singleStatement = singleStatement.replace("$props$", DaoUtils.convertToJson(props));
- }
-
- singleStatement = singleStatement.replace("$idNameFrom$", from.getIdName());
- singleStatement = singleStatement.replace("$idValueFrom$", from.getIdValue().toString());
-
- RelationEndPoint to = relation.getTo();
- singleStatement = singleStatement.replace("$labelTo$", to.getLabel().getName());
- singleStatement = singleStatement.replace("$idNameTo$", to.getIdName());
- singleStatement = singleStatement.replace("$idvalueTo$", to.getIdValue().toString());
-
- singleStatement = singleStatement.replace("$type$", relation.getType());
- return singleStatement;
- }
-
- private String updateRelationStatement(GraphRelation relation) {
- // TODO
- return null;
- }
-
- private String prepareKeyValueFilter(GraphNode node) {
- StringBuilder sb = new StringBuilder();
-
- ImmutablePair<String, Object> keyValueId = node.getKeyValueId();
-
- sb.append(keyValueId.getKey()).append(":");
- if (keyValueId.getValue() instanceof String) {
- sb.append("'");
- }
- sb.append(keyValueId.getValue());
-
- if (keyValueId.getValue() instanceof String) {
- sb.append("'");
- }
-
- return sb.toString();
- }
-
- public String translateGet(RecursiveFilter filter) {
- String requestJson = null;
- String statement;
-
- if (filter instanceof RecursiveByRelationFilter) {
- RecursiveByRelationFilter byRelationFilter = (RecursiveByRelationFilter) filter;
-
- statement = CypherTemplates.GetByRelationNodeRecursiveTemplate.replace("$labelNode$",
- byRelationFilter.getNode().getLabel());
- String keyValueId = prepareKeyValueFilter(byRelationFilter.getNode());
-
- statement = statement.replace("$propsNode$", keyValueId);
-
- statement = statement.replace("$type$", byRelationFilter.getRelationType());
-
- String relationProps = prepareFilterBody(filter);
- statement = statement.replace("$propsRel$", relationProps);
- statement = statement.replace("$labelSrc$", filter.getNodeType().getName());
-
- } else {
-
- statement = CypherTemplates.GetNodeRecursiveTemplate.replace("$label$", filter.getNodeType().getName());
-
- // replace filter
- if (filter.getProperties().isEmpty()) {
- // get all records by label
- statement = statement.replace("{$filter$}", "");
- } else {
- String filterStr = prepareFilterBody(filter);
- statement = statement.replace("$filter$", filterStr);
- }
- }
-
- if (filter.getChildRelationTypes() == null || filter.getChildRelationTypes().isEmpty()) {
- statement = statement.replace("$typesList$", "");
-
- } else {
- StringBuilder typesList = new StringBuilder();
- int count = 0;
- for (String type : filter.getChildRelationTypes()) {
- typesList.append(":").append(type);
- ++count;
- if (count < filter.getChildRelationTypes().size()) {
- typesList.append("|");
- }
- }
- statement = statement.replace("$typesList$", typesList.toString());
- }
- String singleStatement = CypherTemplates.RegularStatementTemplate.replace("$statement$", statement);
- requestJson = CypherTemplates.BatchTemplate.replace("$statementList$", singleStatement);
-
- return requestJson;
- }
-
- public static String prepareFilterBody(MatchFilter filter) {
- StringBuilder sb = new StringBuilder();
- int count = 0;
- int size = filter.getProperties().entrySet().size();
- for (Map.Entry<String, Object> entry : filter.getProperties().entrySet()) {
- sb.append(entry.getKey()).append(":");
- if (entry.getValue() instanceof String) {
- sb.append("'");
- }
- sb.append(entry.getValue());
- if (entry.getValue() instanceof String) {
- sb.append("'");
- }
- ++count;
- if (count < size) {
- sb.append(",");
- }
- }
- return sb.toString();
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java
index b3f9037ea6..f0806291c7 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionary.java
@@ -21,162 +21,162 @@
package org.openecomp.sdc.be.dao.neo4j;
public enum GraphPropertiesDictionary {
-// field name class type unique indexed
+// field name class type unique indexed
// stored in graph index
- // Common
- LABEL("nodeLabel", String.class, false, true),
- HEALTH_CHECK("healthcheckis", String.class, true, true),
- // Resource
- NAME("name", String.class, false, true),
- TOSCA_RESOURCE_NAME("toscaResourceName", String.class, false, true),
- CATEGORY_NAME("categoryName", String.class, false, true),
- VERSION("version", String.class, false, true),
- CREATION_DATE("creationDate", Long.class, false, false),
- LAST_UPDATE_DATE("modificationDate", Long.class, false, false),
- IS_HIGHEST_VERSION("highestVersion", Boolean.class, false, true),
- IS_ABSTRACT("abstract", Boolean.class, false, true),
- DESCRIPTION("description", String.class, false, false),
- UNIQUE_ID("uid", String.class, true, true),
- STATE("state", String.class, false, true),
- TYPE("type", String.class, false, true),
- REQUIRED("required", Boolean.class, false, false),
- DEFAULT_VALUE("defaultValue", String.class, false, false),
- CONSTRAINTS("constraints", String.class, false, false),
- CONTACT_ID("contactId", String.class, false, false),
- VENDOR_NAME("vendorName", String.class, false, false),
- VENDOR_RELEASE("vendorRelease", String.class, false, false),
- CONFORMANCE_LEVEL("conformanceLevel", String.class, false, false),
- ICON("icon", String.class, false, false),
- TAGS("tags", String.class, false, false),
- UUID("uuid", String.class, false, true),
- COST("cost", String.class, false, false),
- LICENSE_TYPE("licenseType", String.class, false, false),
- NORMALIZED_NAME("normalizedName", String.class, false, true),
- SYSTEM_NAME("systemName", String.class, false, true),
- IS_DELETED("deleted", Boolean.class, false, true),
- RESOURCE_TYPE("resourceType", String.class, false, true),
- ENTRY_SCHEMA("entry_schema", String.class, false, false),
- CSAR_UUID("csarUuid", String.class, false, true),
- CSAR_VERSION("csarVersion", String.class, false, true),
- IMPORTED_TOSCA_CHECKSUM("importedToscaChecksum", String.class, false, true),
- GENERATED("generated", Boolean.class, false, false),
- // User
- USERID("userId", String.class, true, true),
- EMAIL("email", String.class, false, false),
- FIRST_NAME("firstName", String.class, false, false),
- LAST_NAME("lastName", String.class, false, false),
- ROLE("role", String.class, false, true),
- USER_STATUS("status", String.class, false, true),
- VALID_SOURCE_TYPES("validSourceTypes", String.class, false, false),
- VALID_TARGET_TYPES("validTargetTypes", String.class, false, false),
- NODE("node", String.class, false, false),
- VALUE("value", String.class, false, false),
- HIDDEN("Hidden", Boolean.class, false, false),
- PROPERTIES("properties", String.class, false, false),
- POSITION_X("positionX", String.class, false, false),
- POSITION_Y("positionY", String.class, false, false),
- RELATIONSHIP_TYPE("relationshipType", String.class, false, false),
- ARTIFACT_TYPE("artifactType", String.class, false, true),
- ARTIFACT_REF("artifactRef", String.class, false, false),
- ARTIFACT_REPOSITORY("artifactRepository", String.class, false, false),
- ARTIFACT_CHECKSUM("artifactChecksum", String.class, false, false),
- CREATOR("creator", String.class, false, false),
- CREATOR_ID("creatorId", String.class, false, false),
- LAST_UPDATER("lastUpdater", String.class, false, false),
- CREATOR_FULL_NAME("creatorFullName", String.class, false, false),
- UPDATER_FULL_NAME("updaterFullName", String.class, false, false),
- ES_ID("esId", String.class, false, false),
- ARTIFACT_LABEL("artifactLabel", String.class, false, true),
- ARTIFACT_DISPLAY_NAME("artifactDisplayName", String.class, false, true),
- INSTANCE_COUNTER("instanceCounter", Integer.class, false, false),
- PROJECT_CODE("projectCode", String.class, false, false),
- DISTRIBUTION_STATUS("distributionStatus", String.class, false, false),
- IS_VNF("isVNF", Boolean.class, false, false),
- LAST_LOGIN_TIME("lastLoginTime", Long.class, false, true),
- ATTRIBUTE_COUNTER("attributeCounter", Integer.class, false, false),
- INPUT_COUNTER("inputCounter", Integer.class, false, false),
- PROPERTY_COUNTER("propertyCounter", Integer.class, false, false),
- API_URL("apiUrl", String.class, false, false),
- SERVICE_API("serviceApi", Boolean.class, false, true),
- ADDITIONAL_INFO_PARAMS("additionalInfo", String.class, false, false),
- ADDITIONAL_INFO_ID_TO_KEY("idToKey", String.class, false, false),
- ARTIFACT_GROUP_TYPE("artifactGroupType", String.class, false, true),
- ARTIFACT_TIMEOUT("timeout", Integer.class, false, false),
- IS_ACTIVE("isActive", Boolean.class, false, true),
- PROPERTY_VALUE_RULES("propertyValueRules", String.class, false, false),
- //authantication
- CONSUMER_NAME("consumerName", String.class, true, true),
- CONSUMER_PASSWORD("consumerPassword", String.class, false, false),
- CONSUMER_SALT("consumerSalt", String.class, false, false),
- CONSUMER_LAST_AUTHENTICATION_TIME("consumerLastAuthenticationTime", Long.class, false, false),
- CONSUMER_DETAILS_LAST_UPDATED_TIME("consumerDetailsLastupdatedtime", Long.class, false, false),
- LAST_MODIFIER_USER_ID("lastModfierUserId", String.class, false, false),
- ARTIFACT_VERSION("artifactVersion", String.class, false, false),
- ARTIFACT_UUID("artifactUUID", String.class, false, false),
- PAYLOAD_UPDATE_DATE("payloadUpdateDate", Long.class, false, false),
- HEAT_PARAMS_UPDATE_DATE("heatParamsUpdateDate", Long.class, false, false),
- //product
- FULL_NAME("fullName", String.class, false, true),
- //was changed as part of migration from 1602 to 1602 ( in 1602 was defined as unique. it's problem to reconfigure the index )
- CONSTANT_UUID("constantUuidNew", String.class, false, true),
- CONTACTS("contacts", String.class, false, false),
- //categorys
- ICONS("icons", String.class, false, false),
- //relation
- CAPABILITY_OWNER_ID("capOwnerId", String.class, false, false),
- REQUIREMENT_OWNER_ID("reqOwnerId", String.class, false, false),
- CAPABILITY_ID("capabiltyId", String.class, false, false),
- REQUIREMENT_ID("requirementId", String.class, false, false),
- PROPERTY_ID("propertyId", String.class, false, false),
- PROPERTY_NAME("propertyName", String.class, false, false),
- //component instance
- ORIGIN_TYPE("originType", String.class, false, false),
- //requirement & capabilty
- MIN_OCCURRENCES("minOccurrences", String.class, false, false),
- MAX_OCCURRENCES("maxOccurrences", String.class, false, false),
- //Data type
- DERIVED_FROM("derivedFrom", String.class, false, false),
- MEMBERS("members", String.class, false, false),
- TARGETS("targets ", String.class, false, false),
- METADATA("metadata", String.class, false, false),
- INVARIANT_UUID("invariantUuid", String.class, false, true),
- IS_BASE("isBase", Boolean.class, false, true),
- GROUP_UUID("groupUuid", String.class, false, true),
- STATUS("status", String.class, false, false),
- FUNCTIONAL_MENU("functionalMenu", String.class, false, false),
- REQUIRED_ARTIFACTS("requiredArtifacts", String.class, false, false),
- CUSTOMIZATION_UUID("customizationUUID", String.class, false, false),
- IS_ARCHIVED("isArchived", Boolean.class, false, true),
- IS_VSP_ARCHIVED("isVspArchived", Boolean.class, false, true),
- ARCHIVE_TIME("archiveTime", Long.class, false, true);
+ // Common
+ LABEL ("nodeLabel", String.class, false, true),
+ HEALTH_CHECK ("healthcheckis", String.class, true, true),
+ // Resource
+ NAME ("name", String.class, false, true),
+ TOSCA_RESOURCE_NAME ("toscaResourceName", String.class, false, true),
+ CATEGORY_NAME ("categoryName", String.class, false, true),
+ VERSION ("version", String.class, false, true),
+ CREATION_DATE ("creationDate", Long.class, false, false),
+ LAST_UPDATE_DATE ("modificationDate", Long.class, false, false),
+ IS_HIGHEST_VERSION ("highestVersion", Boolean.class, false, true),
+ IS_ABSTRACT ("abstract", Boolean.class, false, true),
+ DESCRIPTION ("description", String.class, false, false),
+ UNIQUE_ID ("uid", String.class, true, true),
+ STATE ("state", String.class, false, true),
+ TYPE ("type", String.class, false, true),
+ REQUIRED ("required", Boolean.class, false, false),
+ DEFAULT_VALUE ("defaultValue", String.class, false, false),
+ CONSTRAINTS ("constraints", String.class, false, false),
+ CONTACT_ID ("contactId", String.class, false, false),
+ VENDOR_NAME ("vendorName", String.class, false, false),
+ VENDOR_RELEASE ("vendorRelease", String.class, false, false),
+ CONFORMANCE_LEVEL ("conformanceLevel", String.class, false, false),
+ ICON ("icon", String.class, false, false),
+ TAGS ("tags", String.class, false, false),
+ UUID ("uuid", String.class, false, true),
+ COST ("cost", String.class, false, false),
+ LICENSE_TYPE ("licenseType", String.class, false, false),
+ NORMALIZED_NAME ("normalizedName", String.class, false, true),
+ SYSTEM_NAME ("systemName", String.class, false, true),
+ IS_DELETED ("deleted", Boolean.class, false, true),
+ RESOURCE_TYPE ("resourceType", String.class, false, true),
+ ENTRY_SCHEMA ("entry_schema", String.class, false, false),
+ CSAR_UUID ("csarUuid", String.class, false, true),
+ CSAR_VERSION ("csarVersion", String.class, false, true),
+ IMPORTED_TOSCA_CHECKSUM ("importedToscaChecksum", String.class, false, true),
+ GENERATED ("generated", Boolean.class, false, false),
+ // User
+ USERID ("userId", String.class, true, true),
+ EMAIL ("email", String.class, false, false),
+ FIRST_NAME ("firstName", String.class, false, false),
+ LAST_NAME ("lastName", String.class, false, false),
+ ROLE ("role", String.class, false, true),
+ USER_STATUS ("status", String.class, false, true),
+ VALID_SOURCE_TYPES ("validSourceTypes", String.class, false, false),
+ VALID_TARGET_TYPES ("validTargetTypes", String.class, false, false),
+ NODE ("node", String.class, false, false),
+ VALUE ("value", String.class, false, false),
+ HIDDEN ("Hidden", Boolean.class, false, false),
+ PROPERTIES ("properties", String.class, false, false),
+ POSITION_X ("positionX", String.class, false, false),
+ POSITION_Y ("positionY", String.class, false, false),
+ RELATIONSHIP_TYPE ("relationshipType", String.class, false, false),
+ ARTIFACT_TYPE ("artifactType", String.class, false, true),
+ ARTIFACT_REF ("artifactRef", String.class, false, false),
+ ARTIFACT_REPOSITORY ("artifactRepository", String.class, false, false),
+ ARTIFACT_CHECKSUM ("artifactChecksum", String.class, false, false),
+ CREATOR ("creator", String.class, false, false),
+ CREATOR_ID ("creatorId", String.class, false, false),
+ LAST_UPDATER ("lastUpdater", String.class, false, false),
+ CREATOR_FULL_NAME ("creatorFullName", String.class, false, false),
+ UPDATER_FULL_NAME ("updaterFullName", String.class, false, false),
+ ES_ID ("esId", String.class, false, false),
+ ARTIFACT_LABEL ("artifactLabel", String.class, false, true),
+ ARTIFACT_DISPLAY_NAME("artifactDisplayName", String.class, false, true),
+ INSTANCE_COUNTER ("instanceCounter", Integer.class, false, false),
+ PROJECT_CODE ("projectCode", String.class, false, false),
+ DISTRIBUTION_STATUS ("distributionStatus", String.class, false, false),
+ IS_VNF ("isVNF", Boolean.class, false, false),
+ LAST_LOGIN_TIME ("lastLoginTime", Long.class, false, true),
+ ATTRIBUTE_COUNTER ("attributeCounter", Integer.class, false, false),
+ INPUT_COUNTER ("inputCounter", Integer.class, false, false),
+ PROPERTY_COUNTER ("propertyCounter", Integer.class, false, false),
+ API_URL ("apiUrl", String.class, false, false),
+ SERVICE_API ("serviceApi", Boolean.class, false, true),
+ ADDITIONAL_INFO_PARAMS ("additionalInfo", String.class, false, false),
+ ADDITIONAL_INFO_ID_TO_KEY ("idToKey", String.class, false, false),
+ ARTIFACT_GROUP_TYPE ("artifactGroupType", String.class, false, true),
+ ARTIFACT_TIMEOUT ("timeout", Integer.class, false, false),
+ IS_ACTIVE ("isActive", Boolean.class, false, true),
+ PROPERTY_VALUE_RULES ("propertyValueRules", String.class, false, false),
+ //authantication
+ CONSUMER_NAME ("consumerName", String.class, true, true),
+ CONSUMER_PASSWORD ("consumerPassword", String.class, false, false),
+ CONSUMER_SALT ("consumerSalt", String.class, false, false),
+ CONSUMER_LAST_AUTHENTICATION_TIME ("consumerLastAuthenticationTime", Long.class, false, false),
+ CONSUMER_DETAILS_LAST_UPDATED_TIME ("consumerDetailsLastupdatedtime", Long.class, false, false),
+ LAST_MODIFIER_USER_ID("lastModfierUserId", String.class, false, false),
+ ARTIFACT_VERSION ("artifactVersion", String.class, false, false),
+ ARTIFACT_UUID ("artifactUUID", String.class, false, false),
+ PAYLOAD_UPDATE_DATE ("payloadUpdateDate", Long.class, false, false),
+ HEAT_PARAMS_UPDATE_DATE ("heatParamsUpdateDate",Long.class, false, false),
+ //product
+ FULL_NAME ("fullName", String.class, false, true),
+ //was changed as part of migration from 1602 to 1602 ( in 1602 was defined as unique. it's problem to reconfigure the index )
+ CONSTANT_UUID ("constantUuidNew", String.class, false, true),
+ CONTACTS ("contacts", String.class, false, false),
+ //categorys
+ ICONS ("icons", String.class, false, false),
+ //relation
+ CAPABILITY_OWNER_ID ("capOwnerId", String.class, false, false),
+ REQUIREMENT_OWNER_ID ("reqOwnerId", String.class, false, false),
+ CAPABILITY_ID ("capabiltyId", String.class, false, false),
+ REQUIREMENT_ID ("requirementId", String.class, false, false),
+ PROPERTY_ID ("propertyId", String.class, false, false),
+ PROPERTY_NAME ("propertyName", String.class, false, false),
+ //component instance
+ ORIGIN_TYPE ("originType", String.class, false, false),
+ //requirement & capabilty
+ MIN_OCCURRENCES ("minOccurrences", String.class, false, false),
+ MAX_OCCURRENCES ("maxOccurrences", String.class, false, false),
+ //Data type
+ DERIVED_FROM ("derivedFrom", String.class, false, false),
+ MEMBERS ("members", String.class, false, false),
+ TARGETS ("targets ", String.class, false, false),
+ METADATA ("metadata", String.class, false, false),
+ INVARIANT_UUID ("invariantUuid", String.class, false, true),
+ IS_BASE ("isBase", Boolean.class, false, true),
+ GROUP_UUID ("groupUuid", String.class, false, true),
+ STATUS ("status", String.class, false, false),
+ FUNCTIONAL_MENU ("functionalMenu", String.class, false, false),
+ REQUIRED_ARTIFACTS ("requiredArtifacts", String.class, false, false),
+ CUSTOMIZATION_UUID ("customizationUUID", String.class, false, false),
+ IS_ARCHIVED ("isArchived", Boolean.class, false, true),
+ IS_VSP_ARCHIVED ("isVspArchived", Boolean.class, false, true),
+ ARCHIVE_TIME ("archiveTime", Long.class, false, true);
- private final String property;
- private final Class clazz;
- private final boolean unique;
- private final boolean indexed;
+ private final String property;
+ private final Class clazz;
+ private final boolean unique;
+ private final boolean indexed;
+
+ GraphPropertiesDictionary(String property,Class clazz, boolean unique,boolean indexed) {
+ this.property = property;
+ this.clazz = clazz;
+ this.unique = unique;
+ this.indexed = indexed;
+ }
+
- GraphPropertiesDictionary(String property, Class clazz, boolean unique, boolean indexed) {
- this.property = property;
- this.clazz = clazz;
- this.unique = unique;
- this.indexed = indexed;
- }
+ public String getProperty() {
+ return property;
+ }
+ public Class getClazz() {
+ return clazz;
+ }
- public String getProperty() {
- return property;
- }
+ public boolean isUnique() {
+ return unique;
+ }
- public Class getClazz() {
- return clazz;
- }
-
- public boolean isUnique() {
- return unique;
- }
-
- public boolean isIndexed() {
- return indexed;
- }
+ public boolean isIndexed() {
+ return indexed;
+ }
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionaryExtractor.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionaryExtractor.java
new file mode 100644
index 0000000000..1a7ff29298
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/GraphPropertiesDictionaryExtractor.java
@@ -0,0 +1,188 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.dao.neo4j;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+
+public class GraphPropertiesDictionaryExtractor {
+
+ private Map<String, Object> properties;
+
+ private Gson gson = new Gson();
+
+ public GraphPropertiesDictionaryExtractor(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+ public String getUniqueId() {
+ return (String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty());
+ }
+
+ public String getName() {
+ return (String) properties.get(GraphPropertiesDictionary.NAME.getProperty());
+ }
+
+ public String getVersion() {
+ return (String) properties.get(GraphPropertiesDictionary.VERSION.getProperty());
+ }
+
+ public Boolean isHighestVersion() {
+ return (Boolean) properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty());
+ }
+
+ public Long getCreationDate() {
+ return (Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty());
+ }
+
+ public Long getLastUpdateDate() {
+ return (Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty());
+ }
+
+ public String getDescription() {
+ return (String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty());
+ }
+
+ public String getConformanceLevel() {
+ return (String) properties.get(GraphPropertiesDictionary.CONFORMANCE_LEVEL.getProperty());
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<String> getTags() {
+ List<String> tagsFromJson;
+ if(properties.get(GraphPropertiesDictionary.TAGS.getProperty()) instanceof List<?>){
+ tagsFromJson = (List<String>) properties.get(GraphPropertiesDictionary.TAGS.getProperty());
+ } else {
+ Type listType = new TypeToken<List<String>>() {}.getType();
+ tagsFromJson = gson.fromJson((String) properties.get(GraphPropertiesDictionary.TAGS.getProperty()), listType);
+ }
+ return tagsFromJson;
+ }
+
+ public String getIcon() {
+ return (String) properties.get(GraphPropertiesDictionary.ICON.getProperty());
+ }
+
+ public String getState() {
+ return (String) properties.get(GraphPropertiesDictionary.STATE.getProperty());
+ }
+
+ public String getContactId() {
+ return (String) properties.get(GraphPropertiesDictionary.CONTACT_ID.getProperty());
+ }
+
+ public String getUUID() {
+ return (String) properties.get(GraphPropertiesDictionary.UUID.getProperty());
+ }
+
+ public String getNormalizedName() {
+ return (String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty());
+ }
+
+ public String getSystemName() {
+ return (String) properties.get(GraphPropertiesDictionary.SYSTEM_NAME.getProperty());
+ }
+
+ public Boolean isDeleted() {
+ return (Boolean) properties.get(GraphPropertiesDictionary.IS_DELETED.getProperty());
+ }
+
+ public String getProjectCode() {
+ return (String) properties.get(GraphPropertiesDictionary.PROJECT_CODE.getProperty());
+ }
+
+ public String getCsarUuid() {
+ return (String) properties.get(GraphPropertiesDictionary.CSAR_UUID.getProperty());
+ }
+
+ public String getCsarVersion() {
+ return (String) properties.get(GraphPropertiesDictionary.CSAR_VERSION.getProperty());
+ }
+
+ public String getImportedToscaChecksum() {
+ return (String) properties.get(GraphPropertiesDictionary.IMPORTED_TOSCA_CHECKSUM.getProperty());
+ }
+
+ public String getInvariantUuid() {
+ return (String) properties.get(GraphPropertiesDictionary.INVARIANT_UUID.getProperty());
+ }
+
+ public String getVendorName() {
+ return (String) properties.get(GraphPropertiesDictionary.VENDOR_NAME.getProperty());
+ }
+
+ public String getVendorRelease() {
+ return (String) properties.get(GraphPropertiesDictionary.VENDOR_RELEASE.getProperty());
+ }
+
+ public Boolean isAbstract() {
+ return (Boolean) properties.get(GraphPropertiesDictionary.IS_ABSTRACT.getProperty());
+ }
+
+ public ResourceTypeEnum getResourceType() {
+ if (properties.get(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty()) != null) {
+ return ResourceTypeEnum.valueOf((String) properties.get(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty()));
+ } else {
+ return null;
+ }
+ }
+
+ public String getToscaResourceName() {
+ return (String) properties.get(GraphPropertiesDictionary.TOSCA_RESOURCE_NAME.getProperty());
+ }
+
+ public Integer getInstanceCounter() {
+ return (Integer) properties.get(GraphPropertiesDictionary.INSTANCE_COUNTER.getProperty());
+ }
+
+ public String getCost() {
+ return (String) properties.get(GraphPropertiesDictionary.COST.getProperty());
+ }
+
+ public String getLicenseType() {
+ return (String) properties.get(GraphPropertiesDictionary.LICENSE_TYPE.getProperty());
+ }
+
+ public String getDistributionStatus() {
+ return (String) properties.get(GraphPropertiesDictionary.DISTRIBUTION_STATUS.getProperty());
+ }
+
+ public String getFullName() {
+ return (String) properties.get(GraphPropertiesDictionary.FULL_NAME.getProperty());
+ }
+
+ public List<String> getContacts() {
+ Type listType = new TypeToken<List<String>>() {}.getType();
+ return gson.fromJson((String) properties.get(GraphPropertiesDictionary.CONTACTS.getProperty()), listType);
+ }
+
+ public Boolean isActive() {
+ return (Boolean) properties.get(GraphPropertiesDictionary.IS_ACTIVE.getProperty());
+ }
+
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jClient.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jClient.java
deleted file mode 100644
index cc7a3fceb3..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jClient.java
+++ /dev/null
@@ -1,983 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j;
-
-import fj.data.Either;
-import org.apache.http.HttpEntity;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.HttpResponseException;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.BasicResponseHandler;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.util.EntityUtils;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.graph.GraphElementFactory;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElement;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
-import org.openecomp.sdc.be.dao.neo4j.filters.MatchFilter;
-import org.openecomp.sdc.be.dao.neo4j.filters.RecursiveFilter;
-import org.openecomp.sdc.be.dao.neo4j.filters.UpdateFilter;
-import org.openecomp.sdc.be.dao.utils.DaoUtils;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import java.io.IOException;
-import java.util.*;
-
-//@Component("neo4j-client")
-public class Neo4jClient {
- private CloseableHttpClient httpClient;
- private JSONParser jsonParser;
-
- private CypherTranslator cypherTranslator;
-
- private static Logger logger = Logger.getLogger(Neo4jClient.class.getName());
-
- private static final String getServiceRoot = "http://$host$:$port$/db/data/";
- // Error's Classification templates
- private static final String ClientError = "ClientError";
- private static final String DatabaseError = "DatabaseError";
- private static final String TransientError = "TransientError";
-
- // Error's Category templates
- private static final String General = "General";
- private static final String LegacyIndex = "LegacyIndex";
- private static final String Request = "Request";
- private static final String Schema = "Schema";
- private static final String Security = "Security";
- private static final String Statement = "Statement";
- private static final String Transaction = "Transaction";
-
- // Error's Title templates
- private static final String EntityNotFound = "EntityNotFound";
- private static final String ConstraintViolation = "ConstraintViolation";
-
- @PostConstruct
- public void init() {
-
- PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
- connectionManager.setMaxTotal(100);
- connectionManager.setDefaultMaxPerRoute(20);
- connectionManager.setValidateAfterInactivity(15000);
- this.httpClient = HttpClients.custom().setConnectionManager(connectionManager).build();
- jsonParser = new JSONParser();
- cypherTranslator = new CypherTranslator();
-
- }
-
- @PreDestroy
- public void shutdown() {
- try {
- httpClient.close();
- logger.debug("Http client to Neo4j Graph closed");
- } catch (Exception e) {
- logger.info("Failed to close http client", e);
- }
- }
-
- /**
- *
- * @param builder
- * @return
- */
- public Either<List<List<GraphElement>>, Neo4jOperationStatus> execute(BatchBuilder builder) {
-
- String json = cypherTranslator.translate(builder);
- logger.debug("Try to execute cypher request [{}]", json);
-
- Either<String, Neo4jOperationStatus> result = sendPostCypher(json);
- if (result.isRight()) {
- return Either.right(result.right().value());
- }
- List<List<GraphElement>> batchResult;
- try {
- batchResult = parseResult(result.left().value(), false);
- } catch (ParseException e) {
- logger.error("Failed to parse batchresponse", e);
- return Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- }
-
- return Either.left(batchResult);
- }
-
- public Either<List<List<GraphElement>>, Neo4jOperationStatus> executeGet(RecursiveFilter filter) {
- String json = cypherTranslator.translateGet(filter);
- logger.debug("Try to execute cypher request [{}]", json);
-
- Either<String, Neo4jOperationStatus> result = sendPostCypher(json);
- if (result.isRight()) {
- return Either.right(result.right().value());
- }
- List<List<GraphElement>> batchResult;
- try {
- batchResult = parseResult(result.left().value(), true);
- } catch (ParseException e) {
- logger.error("Failed to parse batchresponse", e);
- return Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- }
-
- return Either.left(batchResult);
-
- }
-
- /**
- *
- * @param element
- * @param ip
- * @param user
- * @param password
- * @return
- */
- public Neo4jOperationStatus createElement(GraphElement element) {
- Neo4jOperationStatus result = Neo4jOperationStatus.OK;
- switch (element.getElementType()) {
- case Node:
- Either<String, Neo4jOperationStatus> status = createNode(element);
- if (status.isRight()) {
- result = status.right().value();
- }
- break;
- case Relationship:
- // TODO
- break;
-
- default:
- break;
- }
-
- return result;
- }
-
- public Either<GraphElement, Neo4jOperationStatus> createSingleElement(GraphElement element) {
- switch (element.getElementType()) {
- case Node:
- Either<String, Neo4jOperationStatus> status = createNode(element);
- if (status.isRight()) {
- return Either.right(status.right().value());
- }
- // parse response
- String response = status.left().value();
- try {
- List<GraphElement> listElements = parseGetResponse(element.getElementType(),
- ((GraphNode) element).getLabel(), response);
- if (listElements == null || listElements.isEmpty()) {
- return Either.right(Neo4jOperationStatus.NOT_FOUND);
- } else {
- return Either.left(listElements.get(0));
- }
- } catch (Exception e) {
- logger.error("Failed to parse fetched data from graph", e);
- return Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- }
- case Relationship:
- // TODO
- break;
-
- default:
- break;
- }
-
- return Either.right(Neo4jOperationStatus.NOT_SUPPORTED);
- }
-
- /**
- *
- * @param type
- * @param label
- * @param filter
- * @param ip
- * @param user
- * @param password
- * @return
- */
- public Either<List<GraphElement>, Neo4jOperationStatus> getByFilter(GraphElementTypeEnum type, String label,
- MatchFilter filter) {
-
- List<GraphElement> result = null;
-
- String requestJson;
- // replace return type
- if (type.equals(GraphElementTypeEnum.Node)) {
- requestJson = CypherTemplates.CypherMatchTemplate.replace("$type$", "n");
- } else {
- requestJson = CypherTemplates.CypherMatchTemplate.replace("$type$", "r");
- }
- // replace label
- if (label != null && !label.isEmpty()) {
- requestJson = requestJson.replace("$label$", label);
- } else {
- requestJson = requestJson.replace("$label$", "");
- }
-
- // replace filter
- if (filter.getProperties().isEmpty()) {
- // get all records by label
- requestJson = requestJson.replace("{$filter$}", "");
- } else {
- String filterStr = CypherTranslator.prepareFilterBody(filter);
- requestJson = requestJson.replace("$filter$", filterStr);
- }
- logger.debug("Try to perform request []", requestJson);
-
- Either<String, Neo4jOperationStatus> status = sendPostCypher(requestJson);
- if (status.isRight()) {
- return Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- }
- // parse response
- String response = status.left().value();
- try {
- result = parseGetResponse(type, label, response);
- } catch (Exception e) {
- logger.error("Failed to parse fetched data from graph", e);
- Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- }
-
- return Either.left(result);
- }
-
- /**
- *
- * @param type
- * @param label
- * @param toMatch
- * @param toUpdate
- * @param ip
- * @param user
- * @param password
- * @return
- */
- public Neo4jOperationStatus updateElement(GraphElementTypeEnum type, String label, UpdateFilter toUpdate) {
-
- String requestJson;
- // replace return type
- if (type.equals(GraphElementTypeEnum.Node)) {
- requestJson = CypherTemplates.CypherUpdateTemplate.replace("$type$", "n");
- } else {
- requestJson = CypherTemplates.CypherUpdateTemplate.replace("$type$", "r");
- }
- // replace label
- if (label != null && !label.isEmpty()) {
- requestJson = requestJson.replace("$label$", label);
- } else {
- requestJson = requestJson.replace("$label$", "");
- }
-
- // replace filter
- if (toUpdate.getProperties().isEmpty()) {
- // get all records by label
- requestJson = requestJson.replace("{$filter$}", "");
- } else {
- String filterStr = CypherTranslator.prepareFilterBody(toUpdate);
- requestJson = requestJson.replace("$filter$", filterStr);
- }
- String props = preparePropertiesInStatement(toUpdate.getToUpdate());
- requestJson = requestJson.replace("$props$", props);
-
- logger.debug("Try to perform request [{}]", requestJson);
-
- Either<String, Neo4jOperationStatus> result = sendPostCypher(requestJson);
- if (result.isRight()) {
- return Neo4jOperationStatus.GENERAL_ERROR;
- }
- return Neo4jOperationStatus.OK;
- }
-
- /**
- *
- * @param type
- * @param label
- * @param response
- * @return
- * @throws ParseException
- */
-
- private List<GraphElement> parseGetResponse(GraphElementTypeEnum type, String label, String response)
- throws ParseException {
- List<GraphElement> result = new ArrayList<>();
- JSONObject responseData = (JSONObject) jsonParser.parse(response);
- JSONArray results = (JSONArray) responseData.get("results");
- Iterator<JSONObject> iteratorResults = results.iterator();
- while (iteratorResults.hasNext()) {
- JSONObject elementResult = iteratorResults.next();
- // JSONArray data = (JSONArray) elementResult.get("row");
- JSONArray data = (JSONArray) elementResult.get("data");
-
- Iterator<JSONObject> iterator = data.iterator();
- JSONObject element;
- while (iterator.hasNext()) {
- element = (JSONObject) iterator.next();
- JSONArray row = (JSONArray) element.get("row");
-
- Iterator<JSONObject> iteratorRow = row.iterator();
- while (iteratorRow.hasNext()) {
- JSONObject rowElement = iteratorRow.next();
-
- Map<String, Object> props = new HashMap<>();
-
- for (Map.Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) rowElement.entrySet()) {
- // props.put(entry.getKey(),
- // rowElement.get(entry.getValue()));
- props.put(entry.getKey(), entry.getValue());
- }
- GraphElement newElement = GraphElementFactory.createElement(label, type, props);
- result.add(newElement);
- }
- }
- }
- return result;
- }
-
- private List<List<GraphElement>> parseResult(String response, boolean storeRelationNode) throws ParseException {
-
- List<List<GraphElement>> batchList = new ArrayList<>();
-
- JSONObject responseData = (JSONObject) jsonParser.parse(response);
- JSONArray results = (JSONArray) responseData.get("results");
- Iterator<JSONObject> iteratorResults = results.iterator();
-
- while (iteratorResults.hasNext()) {
- JSONObject elementResult = iteratorResults.next();
- JSONArray data = (JSONArray) elementResult.get("data");
- JSONArray columns = (JSONArray) elementResult.get("columns");
- Iterator<JSONObject> iteratorData = data.iterator();
- List<GraphElement> singleDataList = new ArrayList<>();
- while (iteratorData.hasNext()) {
-
- JSONObject singleData = iteratorData.next();
- JSONArray row = (JSONArray) singleData.get("row");
- if (columns.size() == 2) {
- // node
- JSONArray labelArray = (JSONArray) row.get(1);
- JSONObject node = (JSONObject) row.get(0);
-
- Map<String, Object> props = jsonObjectToMap(node);
- // get only first label on node. Now single label supported
- GraphElement newElement = GraphElementFactory.createElement((String) labelArray.get(0),
- GraphElementTypeEnum.Node, props);
- singleDataList.add(newElement);
- }
- if (columns.size() == 10) {
- // relation
- JSONObject startNode = (JSONObject) row.get(0);
- JSONArray startNodeArray = (JSONArray) row.get(1);
-
- JSONObject relationFromStart = (JSONObject) row.get(2);
- String relationFromStartType = (String) row.get(3);
-
- JSONObject nodeFrom = (JSONObject) row.get(4);
- JSONArray labelFromArray = (JSONArray) row.get(5);
-
- JSONObject nodeTo = (JSONObject) row.get(6);
- JSONArray labelToArray = (JSONArray) row.get(7);
-
- JSONObject relation = (JSONObject) row.get(8);
- String type = (String) row.get(9);
-
- Map<String, Object> propsStartNode = jsonObjectToMap(startNode);
- Map<String, Object> propsRelationStartNode = jsonObjectToMap(relationFromStart);
-
- Map<String, Object> propsFrom = jsonObjectToMap(nodeFrom);
- Map<String, Object> propsTo = jsonObjectToMap(nodeTo);
- Map<String, Object> propsRelation = jsonObjectToMap(relation);
-
- GraphNode startN = (GraphNode) GraphElementFactory.createElement((String) startNodeArray.get(0),
- GraphElementTypeEnum.Node, propsStartNode);
-
- GraphNode from = (GraphNode) GraphElementFactory.createElement((String) labelFromArray.get(0),
- GraphElementTypeEnum.Node, propsFrom);
- GraphNode to = (GraphNode) GraphElementFactory.createElement((String) labelToArray.get(0),
- GraphElementTypeEnum.Node, propsTo);
-
- singleDataList.add(startN);
-
- GraphElement relationFromStartNode = GraphElementFactory.createRelation(type,
- propsRelationStartNode, startN, from);
- singleDataList.add(relationFromStartNode);
-
- singleDataList.add(from);
- singleDataList.add(to);
- // get only first type on relationship. Now single type
- // supported
- GraphElement newElement = GraphElementFactory.createRelation(type, propsRelation, from, to);
- singleDataList.add(newElement);
- }
- if (columns.size() == 8) {
-
- }
- }
- batchList.add(singleDataList);
- }
- return batchList;
- }
-
- private Map<String, Object> jsonObjectToMap(JSONObject node) {
- Map<String, Object> props = new HashMap<>();
-
- for (Map.Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) node.entrySet()) {
- props.put(entry.getKey(), entry.getValue());
- }
- return props;
- }
-
- private String preparePropertiesInStatement(Map<String, Object> properties) {
- StringBuilder sb = new StringBuilder();
- int count = 0;
- int size = properties.entrySet().size();
- for (Map.Entry<String, Object> entry : properties.entrySet()) {
- sb.append("\"").append(entry.getKey()).append("\"").append(":");
- if (entry.getValue() instanceof String) {
- sb.append("\"");
- }
- sb.append(entry.getValue());
- if (entry.getValue() instanceof String) {
- sb.append("\"");
- }
- ++count;
- if (count < size) {
- sb.append(",");
- }
- }
- return sb.toString();
- }
-
- private Either<String, Neo4jOperationStatus> createNode(GraphElement element) {
- Either<String, Neo4jOperationStatus> status;
- if (element instanceof GraphNode) {
- GraphNode node = (GraphNode) element;
- String json = prepareCreateNodeBody(node);
-
- logger.debug("Try to save Node [{}] on graph", json);
-
- status = sendPostCypher(json);
-
- return status;
-
- } else {
- return Either.right(Neo4jOperationStatus.WRONG_INPUT);
- }
- }
-
- private Either<String, Neo4jOperationStatus> sendPostCypher(String json) {
- Map<String, Object> neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration().getNeo4j();
- String host = (String) neo4jParams.get("host");
- Integer port = (Integer) neo4jParams.get("port");
- String user = (String) neo4jParams.get("user");
- String password = (String) neo4jParams.get("password");
-
- String uri = CypherTemplates.CypherUrlTemplate.replace("$host$", host);
- uri = uri.replace("$port$", port.toString());
-
- HttpClientContext context = creatClientContext(host, user, password);
- CloseableHttpResponse response = null;
-
- HttpPost post = new HttpPost(uri);
- try {
- StringEntity input = new StringEntity(json);
- input.setContentType("application/json");
- post.setEntity(input);
-
- response = httpClient.execute(post, context);
-
- int status = response.getStatusLine().getStatusCode();
- String responseString;
- responseString = new BasicResponseHandler().handleResponse(response);
- logger.debug("response [{}]", responseString);
-
- if (status == 200 || status == 201) {
- logger.debug("cypher request [{}] was succeeded", json);
- Neo4jOperationStatus responseStatus = checkResponse(responseString);
- if (Neo4jOperationStatus.OK.equals(responseStatus)) {
- return Either.left(responseString);
- } else {
- return Either.right(responseStatus);
- }
- } else {
- logger.debug("cypher request [{}] was failed : [{}]", json, responseString);
- return Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- }
-
- } catch (HttpResponseException e) {
- logger.debug("failed to perform cypher request [{}]", json, e);
- if (e.getStatusCode() == 401) {
- return Either.right(Neo4jOperationStatus.NOT_AUTHORIZED);
- } else {
- return Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- }
- } catch (ClientProtocolException e) {
- logger.debug("failed to perform cypher request [{}]", json, e);
- return Either.right(Neo4jOperationStatus.HTTP_PROTOCOL_ERROR);
- } catch (IOException e) {
- logger.debug("failed to perform cypher request [{}]", json, e);
- return Either.right(Neo4jOperationStatus.NOT_CONNECTED);
- } finally {
- releaseResource(response);
- }
- }
-
- private Neo4jOperationStatus checkResponse(String responseString) {
- try {
- JSONObject response = (JSONObject) jsonParser.parse(responseString);
- JSONArray errors = (JSONArray) response.get("errors");
- if (errors.size() == 0) {
- return Neo4jOperationStatus.OK;
- } else {
- Iterator<JSONObject> iterator = errors.iterator();
- JSONObject error;
- while (iterator.hasNext()) {
- error = (JSONObject) iterator.next();
- String code = (String) error.get("code");
- String message = (String) error.get("message");
-
- return mapToNeoError(code, message);
- }
- return Neo4jOperationStatus.GENERAL_ERROR;
- }
- } catch (ParseException e) {
- logger.error("Failed to parse response", e);
- return Neo4jOperationStatus.GENERAL_ERROR;
- }
- }
-
- private Neo4jOperationStatus mapToNeoError(String code, String message) {
- Neo4jOperationStatus error;
-
- String[] errorCode = code.split("\\.");
- if (errorCode.length < 4) {
- error = Neo4jOperationStatus.GENERAL_ERROR;
- } else {
- // by Classification
- switch (errorCode[1]) {
- case ClientError:
- // by Category
- switch (errorCode[2]) {
- case General:
- error = Neo4jOperationStatus.DB_READ_ONLY;
- break;
- case LegacyIndex:
- error = Neo4jOperationStatus.LEGACY_INDEX_ERROR;
- break;
- case Request:
- error = Neo4jOperationStatus.BAD_REQUEST;
- break;
- case Schema:
- if (errorCode[3].equals(ConstraintViolation)) {
- error = Neo4jOperationStatus.ENTITY_ALREADY_EXIST;
- } else {
- error = Neo4jOperationStatus.SCHEMA_ERROR;
- }
- break;
- case Security:
- error = Neo4jOperationStatus.NOT_AUTHORIZED;
- break;
- case Statement:
- // by Title
- if (errorCode[3].equals(EntityNotFound)) {
- error = Neo4jOperationStatus.NOT_FOUND;
- } else {
- if (errorCode[3].equals(ConstraintViolation)) {
- error = Neo4jOperationStatus.ENTITY_ALREADY_EXIST;
- } else {
- error = Neo4jOperationStatus.BAD_REQUEST;
- }
- }
- break;
- case Transaction:
- error = Neo4jOperationStatus.TRANSACTION_ERROR;
- break;
- default:
- error = Neo4jOperationStatus.GENERAL_ERROR;
- break;
- }
- break;
- case DatabaseError:
- // by Category
- switch (errorCode[2]) {
- case General:
- error = Neo4jOperationStatus.GENERAL_ERROR;
- break;
- case Schema:
- error = Neo4jOperationStatus.SCHEMA_ERROR;
- break;
- case Statement:
- error = Neo4jOperationStatus.EXECUTION_FAILED;
- break;
- case Transaction:
- error = Neo4jOperationStatus.TRANSACTION_ERROR;
- break;
- default:
- error = Neo4jOperationStatus.GENERAL_ERROR;
- break;
- }
- break;
- case TransientError:
- error = Neo4jOperationStatus.DB_NOT_AVAILABLE;
- break;
- default:
- error = Neo4jOperationStatus.GENERAL_ERROR;
- break;
- }
- error.setOriginError(code).setMessage(message);
- String errorFromCfg = code.replace(".", "_");
- String helpMessage = ConfigurationManager.getConfigurationManager().getNeo4jErrorsConfiguration()
- .getErrorMessage(errorFromCfg);
- if (helpMessage != null && !helpMessage.isEmpty()) {
- error.setHelpErrorMsg(helpMessage);
- }
- }
- return error;
- }
-
- private String prepareCreateNodeBody(GraphNode node) {
-
- String body = CypherTemplates.CypherCreateNodeTemplate.replace("$label$", node.getLabel());
-
- body = body.replace("$props$", DaoUtils.convertToJson(node.toGraphMap()));
-
- return body;
- }
-
- /**
- * the method returns all the indexes for the given label if no label is
- * supplied ( null or "") all indexes will be returned
- *
- * @param label
- * the name of the label
- * @param ip
- * @param user
- * @param password
- * @return a map of labels and there properties
- */
- public Either<Map<String, List<String>>, Neo4jOperationStatus> getIndexes(String label) {
- Map<String, Object> neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration().getNeo4j();
- String host = (String) neo4jParams.get("host");
- Integer port = (Integer) neo4jParams.get("port");
- String user = (String) neo4jParams.get("user");
- String password = (String) neo4jParams.get("password");
-
- String uri = null;
- if (label == null || "".equals(label)) {
- uri = CypherTemplates.getAllIndexsTemplate.replace("$host$", host);
- } else {
- uri = CypherTemplates.getAllIndexsTemplate.replace("$host$", host) + "/" + label;
- }
- uri = uri.replace("$port$", port.toString());
-
- HttpClientContext context = creatClientContext(host, user, password);
- CloseableHttpResponse response = null;
-
- HttpGet get = new HttpGet(uri);
- get.setHeader("Content-Type", "application/json");
- get.setHeader("Accept", "application/json; charset=UTF-8");
-
- try {
-
- response = httpClient.execute(get, context);
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode != 200) {
- logger.error("failed to get indexes requeste returned {}", statusCode);
- return Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- } else {
- Map<String, List<String>> labels = getLeablesFromJson(response);
- return Either.left(labels);
- }
- } catch (Exception e) {
- logger.debug("failed to get indexes ", e);
- return Either.right(Neo4jOperationStatus.GENERAL_ERROR);
- } finally {
- releaseResource(response);
-
- }
-
- }
-
- private Map<String, List<String>> getLeablesFromJson(CloseableHttpResponse response)
- throws HttpResponseException, IOException, ParseException {
- Map<String, List<String>> labels = new HashMap<>();
- String responseString = new BasicResponseHandler().handleResponse(response);
- JSONArray results = (JSONArray) jsonParser.parse(responseString);
- Iterator<JSONObject> iteratorResults = results.iterator();
- while (iteratorResults.hasNext()) {
- JSONObject elementResult = iteratorResults.next();
- String label = (String) elementResult.get("label");
- List<String> props = labels.get(label);
- if (props == null) {
- props = new ArrayList<>();
- labels.put(label, props);
- }
- JSONArray properties = (JSONArray) elementResult.get("property_keys");
- Iterator<String> iterator = properties.iterator();
- while (iterator.hasNext()) {
- props.add(iterator.next());
- }
- }
- return labels;
- }
-
- public Neo4jOperationStatus createIndex(String label, List<String> propertyNames) {
-
- Neo4jOperationStatus result = Neo4jOperationStatus.OK;
- if (propertyNames != null && !propertyNames.isEmpty()) {
-
- Map<String, Object> neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getNeo4j();
- String host = (String) neo4jParams.get("host");
- Integer port = (Integer) neo4jParams.get("port");
- String user = (String) neo4jParams.get("user");
- String password = (String) neo4jParams.get("password");
-
- String uri = CypherTemplates.batchTemplate.replace("$host$", host);
- uri = uri.replace("$port$", port.toString());
-
- String opertionUri = "/schema/index/" + label;
-
- HttpClientContext context = creatClientContext(host, user, password);
-
- CloseableHttpResponse response = null;
-
- HttpPost post = new HttpPost(uri);
-
- String json = createBatchJson(HttpMethod.POST, opertionUri, propertyNames);
-
- try {
- StringEntity input = new StringEntity(json);
- input.setContentType("application/json");
- post.setEntity(input);
- response = httpClient.execute(post, context);
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode != 200) {
- logger.error("failed to create index for label [{}] with properties:{} requeste returned {}",label,propertyNames,statusCode);
- result = Neo4jOperationStatus.GENERAL_ERROR;
- } else {
- logger.debug("index for label [{}] with properties: {} created", label, propertyNames);
- }
- } catch (Exception e) {
- logger.debug("failed to create index for label [{}] with properties: {}", label, propertyNames);
- result = Neo4jOperationStatus.GENERAL_ERROR;
- } finally {
-
- releaseResource(response);
-
- }
-
- }
-
- else {
- logger.debug("no index was created for label :{} the recived propertyNames list: {} is invalide",label,propertyNames);
- return Neo4jOperationStatus.WRONG_INPUT;
- }
-
- return result;
- }
-
- public Neo4jOperationStatus createUniquenessConstraints(String label, List<String> propertyNames) {
- Neo4jOperationStatus result = Neo4jOperationStatus.OK;
- if (propertyNames != null && !propertyNames.isEmpty()) {
-
- Map<String, Object> neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration()
- .getNeo4j();
- String host = (String) neo4jParams.get("host");
- Integer port = (Integer) neo4jParams.get("port");
- String user = (String) neo4jParams.get("user");
- String password = (String) neo4jParams.get("password");
-
- String uri = CypherTemplates.batchTemplate.replace("$host$", host);
- uri = uri.replace("$port$", port.toString());
-
- String opertionUri = "/schema/constraint/" + label + "/uniqueness/";
-
- HttpClientContext context = creatClientContext(host, user, password);
-
- CloseableHttpResponse response = null;
-
- HttpPost post = new HttpPost(uri);
-
- String json = createBatchJson(HttpMethod.POST, opertionUri, propertyNames);
-
- try {
- StringEntity input = new StringEntity(json);
- input.setContentType("application/json");
- post.setEntity(input);
- response = httpClient.execute(post, context);
-
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode != 200) {
- logger.error("failed to create uniqueness constraint for label [{}] on properties:{}. request returned ",
- label,propertyNames,statusCode);
- result = Neo4jOperationStatus.GENERAL_ERROR;
- } else {
- logger.debug("uniqueness constraint for label [{}] on properties:{} created",label,propertyNames);
- }
- } catch (Exception e) {
- logger.error("failed to create uniqueness constraint [{}] with properties:{}",label,propertyNames,e);
- result = Neo4jOperationStatus.GENERAL_ERROR;
- } finally {
- releaseResource(response);
- }
-
- }
-
- else {
- logger.debug("no index was created for label :{} the recived propertyNames list: {} is invalide",label,propertyNames);
- return Neo4jOperationStatus.WRONG_INPUT;
- }
-
- return result;
- }
-
- public Neo4jOperationStatus deleteElement(GraphElementTypeEnum type, String label, MatchFilter filter) {
-
- String requestJson;
- // replace return type
- if (type.equals(GraphElementTypeEnum.Node)) {
- logger.debug("removing node label: {}", label);
- requestJson = createDeleteNodeStatment(label, filter);
-
- } else {
- logger.error(" delete on type {} is not yet supported", type);
- throw new RuntimeException(" delete on type " + type + " is not yet supported");
- }
-
- logger.debug("Try to perform request [{}]", requestJson);
-
- Either<String, Neo4jOperationStatus> status = sendPostCypher(requestJson);
- if (status.isRight()) {
- logger.error(" delete request failed with: {}", status.right());
- return Neo4jOperationStatus.GENERAL_ERROR;
- } else {
- return Neo4jOperationStatus.OK;
- }
- }
-
- public String getNeo4jVersion() throws Exception {
- Map<String, Object> neo4jParams = ConfigurationManager.getConfigurationManager().getConfiguration().getNeo4j();
- String host = (String) neo4jParams.get("host");
- Integer port = (Integer) neo4jParams.get("port");
- String user = (String) neo4jParams.get("user");
- String password = (String) neo4jParams.get("password");
-
- String uri = getServiceRoot.replace("$host$", host).replace("$port$", port.toString());
-
- HttpClientContext context = creatClientContext(host, user, password);
- CloseableHttpResponse response = null;
- String result = null;
-
- HttpGet get = new HttpGet(uri);
- get.setHeader("Content-Type", "application/json");
- get.setHeader("Accept", "application/json; charset=UTF-8");
-
- try {
- response = httpClient.execute(get, context);
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode != 200) {
- throw new Exception("Couldn't get Neo4j service root, HTTP status " + statusCode);
- } else {
- // Parse response
- String responseString = new BasicResponseHandler().handleResponse(response);
- JSONObject responseData = (JSONObject) jsonParser.parse(responseString);
- Object obj = responseData.get("neo4j_version");
- if (obj != null) {
- result = (String) obj;
- }
- return result;
- }
- } finally {
- releaseResource(response);
- }
- }
-
- private String createDeleteNodeStatment(String label, MatchFilter filter) {
- String requestJson;
- requestJson = CypherTemplates.CypherDeleteNodeTemplate;
-
- if (label != null && !label.isEmpty()) {
- requestJson = requestJson.replace("$label$", label);
- } else {
- requestJson = requestJson.replace("$label$", "");
- }
-
- // replace filter
- if (filter.getProperties().isEmpty()) {
- // get all records by label
- requestJson = requestJson.replace("{$filter$}", "");
- } else {
- String filterStr = CypherTranslator.prepareFilterBody(filter);
- requestJson = requestJson.replace("$filter$", filterStr);
- }
- return requestJson;
- }
-
- /*
- * removed do to fortify scan CredentialsProvider cp = new
- * BasicCredentialsProvider(); cp.setCredentials(AuthScope.ANY, new
- * UsernamePasswordCredentials(user, password)); AuthCache authCache = new
- * BasicAuthCache(); BasicScheme basicAuth = new BasicScheme();
- * authCache.put(new HttpHost(ip, 7474, "http"), basicAuth);
- * context.setAuthCache(authCache); context.setCredentialsProvider(cp);
- *
- */
- private HttpClientContext creatClientContext(String ip, String user, String password) {
-
- return HttpClientContext.create();
- }
-
- private void releaseResource(CloseableHttpResponse response) {
- if (response != null) {
- try {
- HttpEntity entity = response.getEntity();
- EntityUtils.consume(entity);
- response.close();
- } catch (Exception e) {
- logger.error("failed to close connection exception", e);
- }
- }
- }
-
- private String createBatchJson(HttpMethod method, String opertionUri, List<String> propertyNames) {
- StringBuilder sb = new StringBuilder();
- sb.append("[ ");
- for (int i = 0; i < propertyNames.size(); i++) {
- sb.append("{ \"method\" : \"" + method + "\" , \"to\" : \"" + opertionUri
- + "\" , \"body\" : { \"property_keys\" : [ \"" + propertyNames.get(i) + "\" ] } }");
- if (i + 1 < propertyNames.size()) {
- sb.append(",");
- }
- }
- sb.append(" ]");
- return sb.toString();
- }
-
- enum HttpMethod {
- GET, PUT, POST, DELETE
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java
deleted file mode 100644
index 3e2cf9c8d4..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jEdge.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.openecomp.sdc.be.dao.graph.datatype.ActionEnum;
-
-import java.util.Map;
-
-public class Neo4jEdge {
-
- private GraphEdgeLabels edgeType;
- private Map<String, Object> properties;
- private ActionEnum action;
-
- @VisibleForTesting
- Neo4jEdge() {}
-
- public Neo4jEdge(GraphEdgeLabels edgeType, Map<String, Object> properties, ActionEnum actionEnum) {
- super();
- this.edgeType = edgeType;
- this.properties = properties;
- this.action = actionEnum;
- }
-
- public GraphEdgeLabels getEdgeType() {
- return edgeType;
- }
-
- public void setEdgeType(GraphEdgeLabels edgeType) {
- this.edgeType = edgeType;
- }
-
- public Map<String, Object> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, Object> properties) {
- this.properties = properties;
- }
-
- public ActionEnum getAction() {
- return action;
- }
-
- public void setAction(ActionEnum action) {
- this.action = action;
- }
-
- @Override
- public String toString() {
- return "Neo4jEdge [edgeType=" + edgeType + ", properties=" + properties + ", action=" + action + "]";
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jGraphBatchBuilder.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jGraphBatchBuilder.java
deleted file mode 100644
index f28baf0017..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jGraphBatchBuilder.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.graph.datatype.*;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-
-import java.util.*;
-
-public class Neo4jGraphBatchBuilder {
-
- private static Logger logger = Logger.getLogger(Neo4jGraphBatchBuilder.class.getName());
-
- public Either<BatchBuilder, Neo4jOperationStatus> buildBatchBuilderFromTable(
- GraphNeighbourTable graphNeighbourTable) {
-
- logger.debug("The table sent in order to build BatchBuilder is {}", graphNeighbourTable);
-
- List<GraphNode> nodes = graphNeighbourTable.getNodes();
- if (nodes != null && nodes.size() > 0) {
- List<NodeRelation> directedEdges = graphNeighbourTable.getDirectedEdges();
-
- List<RelationEndPoint> relationEndPoints = new ArrayList<>(nodes.size());
- Set<Integer> nodesInRelations = findDistinctNodesIndex(directedEdges);
-
- buildRelationEndPoints(nodes, nodesInRelations, relationEndPoints);
-
- BatchBuilder batchBuilder = BatchBuilder.getBuilder();
-
- for (GraphElement neo4jElement : nodes) {
- if (neo4jElement.getAction() != ActionEnum.Delete) {
- logger.debug("Goint to add node {} to batch builder.", neo4jElement);
- batchBuilder.add(neo4jElement);
- }
- }
-
- if (directedEdges != null) {
- for (NodeRelation nodeRelation : directedEdges) {
- GraphRelation relation = buildNeo4jRelation(relationEndPoints, nodeRelation);
- logger.debug("Goint to add relation {} to batch builder.", relation);
- batchBuilder.add(relation);
- }
- }
-
- for (GraphElement neo4jElement : nodes) {
- if (neo4jElement.getAction() == ActionEnum.Delete) {
- logger.debug("Goint to add node {} to batch builder.", neo4jElement);
- batchBuilder.add(neo4jElement);
- }
- }
-
- return Either.left(batchBuilder);
-
- } else {
- logger.error("No node was sent in order to create the resource.");
- return Either.right(Neo4jOperationStatus.BAD_REQUEST);
- }
- }
-
- private Pair<String, String> getUniqueIdKeyValue(GraphNode neo4jNode) {
-
- // String label = neo4jNode.getLabel();
- // NodeTypeEnum nodeTypeEnum = NodeTypeEnum.getByName(label);
- //
- return Pair.createPair(neo4jNode.getUniqueIdKey(), neo4jNode.getUniqueId().toString());
- }
-
- private Set<Integer> findDistinctNodesIndex(List<NodeRelation> directedEdges) {
-
- HashSet<Integer> nodesIndex = new HashSet<>();
-
- if (directedEdges != null) {
- for (NodeRelation nodeRelation : directedEdges) {
- nodesIndex.add(nodeRelation.getFromIndex());
- nodesIndex.add(nodeRelation.getToIndex());
- }
- }
-
- return nodesIndex;
- }
-
- private String findResourceDataIdFromNodes(List<GraphNode> nodes) {
-
- if (nodes != null) {
-
- for (GraphNode neo4jNode : nodes) {
- String label = neo4jNode.getLabel();
- if (label.equals(NodeTypeEnum.Resource.getName())) {
- return neo4jNode.getUniqueId().toString();
- }
- }
- }
-
- return null;
- }
-
- private GraphRelation buildNeo4jRelation(List<RelationEndPoint> relationEndPoints, NodeRelation nodeRelation) {
- GraphRelation relation = new GraphRelation();
- int fromIndex = nodeRelation.getFromIndex();
- int toIndex = nodeRelation.getToIndex();
- Neo4jEdge neo4jEdge = nodeRelation.getEdge();
- relation.setFrom(relationEndPoints.get(fromIndex));
- relation.setTo(relationEndPoints.get(toIndex));
- relation.setType(neo4jEdge.getEdgeType().getProperty());
-
- // TODO: fix it after change
- Map<String, Object> edgeProps = neo4jEdge.getProperties();
- if (edgeProps != null && !edgeProps.isEmpty()) {
- relation.addPropertis(edgeProps);
- }
-
- relation.setAction(neo4jEdge.getAction());
- return relation;
- }
-
- private void buildRelationEndPoints(List<GraphNode> nodes, Set<Integer> nodesInRelations,
- List<RelationEndPoint> relationEndPoints) {
-
- if (nodesInRelations != null) {
- for (Integer nodeIndex : nodesInRelations) {
-
- GraphElement neo4jElement = nodes.get(nodeIndex);
- GraphNode neo4jNode = (GraphNode) neo4jElement;
- String label = neo4jNode.getLabel();
- Pair<String, String> uniqueKeyValue = getUniqueIdKeyValue(neo4jNode);
-
- RelationEndPoint endPoint = new RelationEndPoint(NodeTypeEnum.getByName(label), uniqueKeyValue.getKey(),
- uniqueKeyValue.getValue());
- relationEndPoints.add(nodeIndex, endPoint);
-
- }
- }
-
- }
-
- public static class Pair<K, V> {
-
- private final K key;
- private final V value;
-
- public static <K, V> Pair<K, V> createPair(K key, V value) {
- return new Pair<>(key, value);
- }
-
- public Pair(K key, V value) {
- this.key = key;
- this.value = value;
- }
-
- public K getKey() {
- return key;
- }
-
- public V getValue() {
- return value;
- }
-
- }
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatus.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatus.java
deleted file mode 100644
index 154449b521..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/Neo4jOperationStatus.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j;
-
-public enum Neo4jOperationStatus {
-
- OK, NOT_CONNECTED, NOT_AUTHORIZED, HTTP_PROTOCOL_ERROR, DB_NOT_AVAILABLE, DB_READ_ONLY, BAD_REQUEST, LEGACY_INDEX_ERROR, SCHEMA_ERROR, TRANSACTION_ERROR, EXECUTION_FAILED, ENTITY_ALREADY_EXIST,
-
- WRONG_INPUT, GENERAL_ERROR, NOT_SUPPORTED, NOT_FOUND;
-
- private String originError;
- private String message;
- private String helpErrorMsg;
-
- private static final String NA = "NA";
-
- Neo4jOperationStatus() {
- originError = NA;
- message = NA;
- helpErrorMsg = NA;
- }
-
- public Neo4jOperationStatus setOriginError(String originError) {
- this.originError = originError;
- return this;
- }
-
- public Neo4jOperationStatus setMessage(String message) {
- if (message != null && !message.isEmpty()) {
- this.message = message;
- }
- return this;
- }
-
- public Neo4jOperationStatus setHelpErrorMsg(String helpErrorMsg) {
- this.helpErrorMsg = helpErrorMsg;
- return this;
- }
-
- public String getOriginError() {
- return originError;
- }
-
- public String getMessage() {
- return message;
- }
-
- public String getHelpErrorMsg() {
- return helpErrorMsg;
- }
-
- public String printError() {
- StringBuilder sb = new StringBuilder();
- sb.append("[").append(toString()).append("-").append(originError).append("-").append(helpErrorMsg).append("-")
- .append(message).append("]");
- return sb.toString();
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java
deleted file mode 100644
index 089bbdbba3..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/NodeRelation.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j;
-
-import com.google.common.annotations.VisibleForTesting;
-
-public class NodeRelation {
-
- private int fromIndex;
- private int toIndex;
- private Neo4jEdge edge;
-
- @VisibleForTesting
- NodeRelation() {}
-
- public NodeRelation(int fromIndex, int toIndex, Neo4jEdge edge) {
- super();
- this.fromIndex = fromIndex;
- this.toIndex = toIndex;
- this.edge = edge;
- }
-
- public int getFromIndex() {
- return fromIndex;
- }
-
- public void setFromIndex(int fromIndex) {
- this.fromIndex = fromIndex;
- }
-
- public int getToIndex() {
- return toIndex;
- }
-
- public void setToIndex(int toIndex) {
- this.toIndex = toIndex;
- }
-
- public Neo4jEdge getEdge() {
- return edge;
- }
-
- public void setEdge(Neo4jEdge edge) {
- this.edge = edge;
- }
-
- @Override
- public String toString() {
- return "NodeRelation [fromIndex=" + fromIndex + ", toIndex=" + toIndex + ", edge=" + edge + "]";
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/MatchFilter.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/MatchFilter.java
deleted file mode 100644
index 7933efbb84..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/MatchFilter.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j.filters;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class MatchFilter {
- private Map<String, Object> toMatchProperties;
-
- public MatchFilter() {
- toMatchProperties = new HashMap<>();
- }
-
- public MatchFilter(Map<String, Object> toMatchProperties) {
- super();
- this.toMatchProperties = toMatchProperties;
- }
-
- public Map<String, Object> getProperties() {
- return toMatchProperties;
- }
-
- public void setProperties(Map<String, Object> properties) {
- this.toMatchProperties = properties;
- }
-
- public MatchFilter addToMatch(String propName, Object value) {
- toMatchProperties.put(propName, value);
- return this;
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveByRelationFilter.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveByRelationFilter.java
deleted file mode 100644
index 698077d45b..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveByRelationFilter.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j.filters;
-
-import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-
-public class RecursiveByRelationFilter extends RecursiveFilter {
-
- private GraphNode node;
- private String relationType;
-
- public RecursiveByRelationFilter() {
- super();
- }
-
- public RecursiveByRelationFilter(NodeTypeEnum nodeType, GraphNode node) {
- super(nodeType);
- this.node = node;
- }
-
- public RecursiveByRelationFilter(NodeTypeEnum nodeType) {
- super(nodeType);
- }
-
- public RecursiveByRelationFilter(NodeTypeEnum nodeType, GraphNode node, String relationType) {
- super(nodeType);
- this.node = node;
- this.relationType = relationType;
- }
-
- public RecursiveByRelationFilter addNode(GraphNode node) {
- this.node = node;
- return this;
- }
-
- public RecursiveByRelationFilter addRelation(String relationType) {
- this.relationType = relationType;
- return this;
- }
-
- public GraphNode getNode() {
- return node;
- }
-
- public void setNode(GraphNode node) {
- this.node = node;
- }
-
- public String getRelationType() {
- return relationType;
- }
-
- public void setRelationType(String relationType) {
- this.relationType = relationType;
- }
-
- @Override
- public String toString() {
- return "RecursiveByRelationFilter [node=" + node + ", relationType=" + relationType + "]";
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveFilter.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveFilter.java
deleted file mode 100644
index 6dafd51930..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/RecursiveFilter.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j.filters;
-
-import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class RecursiveFilter extends MatchFilter {
-
- private List<String> childRelationTypes;
- NodeTypeEnum nodeType;
-
- public RecursiveFilter() {
- childRelationTypes = new ArrayList<>();
- }
-
- public RecursiveFilter(NodeTypeEnum nodeType) {
- childRelationTypes = new ArrayList<>();
- this.nodeType = nodeType;
- }
-
- public RecursiveFilter addChildRelationType(String type) {
- childRelationTypes.add(type);
- return this;
- }
-
- public List<String> getChildRelationTypes() {
- return childRelationTypes;
- }
-
- public void setChildRelationTypes(List<String> childRelationTypes) {
- this.childRelationTypes = childRelationTypes;
- }
-
- public NodeTypeEnum getNodeType() {
- return nodeType;
- }
-
- public void setNodeType(NodeTypeEnum nodeType) {
- this.nodeType = nodeType;
- }
-
- @Override
- public String toString() {
- return "RecursiveFilter [childRelationTypes=" + childRelationTypes + ", nodeType=" + nodeType + "]";
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/UpdateFilter.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/UpdateFilter.java
deleted file mode 100644
index 190993668d..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/neo4j/filters/UpdateFilter.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.neo4j.filters;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class UpdateFilter extends MatchFilter {
-
- private Map<String, Object> toUpdate;
-
- public UpdateFilter(Map<String, Object> toUpdate) {
- super();
- this.toUpdate = toUpdate;
- }
-
- public UpdateFilter() {
- super();
- toUpdate = new HashMap<>();
- }
-
- public UpdateFilter(Map<String, Object> toMatch, Map<String, Object> toUpdate) {
- super(toMatch);
- this.toUpdate = toUpdate;
- }
-
- public Map<String, Object> getToUpdate() {
- return toUpdate;
- }
-
- public void setToUpdate(Map<String, Object> toUpdate) {
- this.toUpdate = toUpdate;
- }
-
- public void addToUpdate(String property, Object value) {
- toUpdate.put(property, value);
- }
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/utils/ElasticSearchUtil.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/utils/ElasticSearchUtil.java
deleted file mode 100644
index f20b523a4d..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/utils/ElasticSearchUtil.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.dao.utils;
-
-import org.elasticsearch.action.search.SearchResponse;
-
-/**
- * Utility class to work with elastic search responses.
- *
- */
-public final class ElasticSearchUtil {
- private ElasticSearchUtil() {
- }
-
- /**
- * Checks if a search response from elastic search contains results or not.
- *
- * @param searchResponse
- * The ES search response object.
- * @return True if the response does not contain any result, false if the
- * response does contains results.
- */
- public static boolean isResponseEmpty(SearchResponse searchResponse) {
- if (searchResponse == null || searchResponse.getHits() == null || searchResponse.getHits().getHits() == null
- || searchResponse.getHits().getHits().length == 0) {
- return true;
- }
- return false;
- }
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/api/IResourceUploader.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/api/IResourceUploader.java
deleted file mode 100644
index cbac24ad3d..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/api/IResourceUploader.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.resources.api;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-
-/**
- * DAO to manage image upload and retrieval.
- *
- * @author luc boutier
- */
-public interface IResourceUploader {
-
- /**
- * Save an artifact in the DAO layer.
- *
- * @param imageData
- */
- ResourceUploadStatus saveArtifact(ESArtifactData artifactData, boolean isReload);
-
- /**
- * Save an artifact in the DAO layer.
- *
- * @param imageData
- */
- ResourceUploadStatus updateArtifact(ESArtifactData artifactData);
-
- /**
- * Get an artifact as a byte array based on the artifact id.
- *
- * @param id
- * The id of the artifact to read.
- * @return The artifact as a byte array.
- */
- Either<ESArtifactData, ResourceUploadStatus> getArtifact(String id);
-
- /**
- * Delete the given image.
- *
- * @param id
- * Id of the image to delete.
- */
- void deleteArtifact(String id);
-
- /**
- * delete all artifacts
- */
- public void deleteAllArtifacts();
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentCacheData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentCacheData.java
new file mode 100644
index 0000000000..bf17383c07
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentCacheData.java
@@ -0,0 +1,153 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.resources.data;
+
+import com.datastax.driver.mapping.annotations.Column;
+import com.datastax.driver.mapping.annotations.PartitionKey;
+import com.datastax.driver.mapping.annotations.Table;
+
+import java.nio.ByteBuffer;
+import java.util.Date;
+
+@Table(keyspace = "sdccomponent", name = "componentcache")
+public class ComponentCacheData {
+ public final static String RRESOURCE_ID_FIELD = "resourceId";
+
+ public final static String SERVICE_NAME_FIELD = "serviceName";
+ public final static String SERVICE_VERSION_FIELD = "serviceVersion";
+ public final static String ARTIFACT_NAME_FIELD = "artifactName";
+
+ public static String delim = ":";
+
+ @PartitionKey
+ @Column(name = "id")
+ private String id;
+
+ @Column
+ private ByteBuffer data;
+
+ @Column(name = "modification_time")
+ private Date modificationTime;
+
+ @Column
+ private String type;
+
+ @Column(name = "is_dirty")
+ private boolean isDirty;
+
+ @Column(name = "is_zipped")
+ private boolean isZipped;
+
+ public ComponentCacheData() {
+
+ }
+
+ public ComponentCacheData(String id, byte[] data, Date modificationTime, String type, boolean isDirty,
+ boolean isZipped) {
+ super();
+ this.id = id;
+ if (data != null) {
+ this.data = ByteBuffer.wrap(data.clone());
+ }
+ this.modificationTime = modificationTime;
+ this.type = type;
+ this.isDirty = isDirty;
+ this.isZipped = isZipped;
+ }
+
+ public ComponentCacheData(String id) {
+
+ this.id = id;
+ }
+
+ public ComponentCacheData(String artifactId, byte[] data) {
+ super();
+ this.id = artifactId;
+ if (data != null) {
+ this.data = ByteBuffer.wrap(data.clone());
+ // this.data = data.clone();
+ }
+ }
+
+ public byte[] getDataAsArray() {
+ if (data != null) {
+ return data.array();
+ }
+ return null;
+ }
+
+ public void setDataAsArray(byte[] data) {
+ if (data != null) {
+ this.data = ByteBuffer.wrap(data.clone());
+ }
+ }
+
+ public ByteBuffer getData() {
+ return data;
+ }
+
+ public void setData(ByteBuffer data) {
+ if (data != null) {
+ this.data = data.duplicate();
+ }
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public Date getModificationTime() {
+ return modificationTime;
+ }
+
+ public void setModificationTime(Date modificationTime) {
+ this.modificationTime = modificationTime;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public boolean getIsDirty() {
+ return isDirty;
+ }
+
+ public void setIsDirty(boolean isDirty) {
+ this.isDirty = isDirty;
+ }
+
+ public boolean getIsZipped() {
+ return isZipped;
+ }
+
+ public void setIsZipped(boolean isZipped) {
+ this.isZipped = isZipped;
+ }
+
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentMetadataData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentMetadataData.java
index 32a6c18d0d..d2612b9db7 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentMetadataData.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ComponentMetadataData.java
@@ -20,15 +20,13 @@
package org.openecomp.sdc.be.resources.data;
-import com.google.gson.reflect.TypeToken;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor;
import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import java.lang.reflect.Type;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
public abstract class ComponentMetadataData extends GraphNode {
@@ -42,47 +40,30 @@ public abstract class ComponentMetadataData extends GraphNode {
this.componentInstanceCounter = 0;
}
- @SuppressWarnings("unchecked")
- public ComponentMetadataData(NodeTypeEnum label, ComponentMetadataDataDefinition metadataDataDefinition, Map<String, Object> properties) {
+ public ComponentMetadataData(NodeTypeEnum label, ComponentMetadataDataDefinition metadataDataDefinition, GraphPropertiesDictionaryExtractor extractor) {
this(label, metadataDataDefinition);
- metadataDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
- metadataDataDefinition.setCreationDate((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
- metadataDataDefinition.setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
- metadataDataDefinition.setConformanceLevel((String) properties.get(GraphPropertiesDictionary.CONFORMANCE_LEVEL.getProperty()));
- metadataDataDefinition.setIcon((String) properties.get(GraphPropertiesDictionary.ICON.getProperty()));
- metadataDataDefinition.setHighestVersion((Boolean) properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()));
- metadataDataDefinition.setLastUpdateDate((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
- metadataDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
- metadataDataDefinition.setState((String) properties.get(GraphPropertiesDictionary.STATE.getProperty()));
- List<String> tagsFromJson;
- if(properties.get(GraphPropertiesDictionary.TAGS.getProperty()) instanceof List<?>){
- tagsFromJson = (List<String>) properties.get(GraphPropertiesDictionary.TAGS.getProperty());
- } else {
- Type listType = new TypeToken<List<String>>() {}.getType();
- tagsFromJson = getGson().fromJson((String) properties.get(GraphPropertiesDictionary.TAGS.getProperty()), listType);
- }
- metadataDataDefinition.setTags(tagsFromJson);
- metadataDataDefinition.setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty()));
- metadataDataDefinition.setContactId((String) properties.get(GraphPropertiesDictionary.CONTACT_ID.getProperty()));
- metadataDataDefinition.setUUID((String) properties.get(GraphPropertiesDictionary.UUID.getProperty()));
- metadataDataDefinition.setNormalizedName((String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty()));
- metadataDataDefinition.setSystemName((String) properties.get(GraphPropertiesDictionary.SYSTEM_NAME.getProperty()));
- metadataDataDefinition.setIsDeleted((Boolean) properties.get(GraphPropertiesDictionary.IS_DELETED.getProperty()));
- metadataDataDefinition.setProjectCode((String) properties.get(GraphPropertiesDictionary.PROJECT_CODE.getProperty()));
- metadataDataDefinition.setCsarUUID((String) properties.get(GraphPropertiesDictionary.CSAR_UUID.getProperty()));
- metadataDataDefinition.setCsarVersion((String) properties.get(GraphPropertiesDictionary.CSAR_VERSION.getProperty()));
- metadataDataDefinition.setImportedToscaChecksum((String) properties.get(GraphPropertiesDictionary.IMPORTED_TOSCA_CHECKSUM.getProperty()));
- metadataDataDefinition.setInvariantUUID((String) properties.get(GraphPropertiesDictionary.INVARIANT_UUID.getProperty()));
-// metadataDataDefinition.setComponentType(ComponentTypeEnum.valueOf((String) properties.get(GraphPropertyEnum.COMPONENT_TYPE.getProperty())));
- metadataDataDefinition.setArchived((Boolean) properties.get(GraphPropertiesDictionary.IS_ARCHIVED.getProperty()));
- metadataDataDefinition.setVspArchived((Boolean) properties.get(GraphPropertiesDictionary.IS_VSP_ARCHIVED.getProperty()));
- Object archiveTime = properties.get(GraphPropertiesDictionary.ARCHIVE_TIME.getProperty());
- if (archiveTime instanceof Integer){
- metadataDataDefinition.setArchiveTime(new Long((Integer) archiveTime));
- } else if (archiveTime instanceof Long) {
- metadataDataDefinition.setArchiveTime((Long)archiveTime);
- }
- componentInstanceCounter = (Integer) properties.get(GraphPropertiesDictionary.INSTANCE_COUNTER.getProperty());
+ metadataDataDefinition.setUniqueId(extractor.getUniqueId());
+ metadataDataDefinition.setCreationDate(extractor.getCreationDate());
+ metadataDataDefinition.setDescription(extractor.getDescription());
+ metadataDataDefinition.setConformanceLevel(extractor.getConformanceLevel());
+ metadataDataDefinition.setIcon(extractor.getIcon());
+ metadataDataDefinition.setHighestVersion(extractor.isHighestVersion());
+ metadataDataDefinition.setLastUpdateDate(extractor.getLastUpdateDate());
+ metadataDataDefinition.setName(extractor.getName());
+ metadataDataDefinition.setState(extractor.getState());
+ metadataDataDefinition.setTags(extractor.getTags());
+ metadataDataDefinition.setVersion(extractor.getVersion());
+ metadataDataDefinition.setContactId(extractor.getContactId());
+ metadataDataDefinition.setUUID(extractor.getUUID());
+ metadataDataDefinition.setNormalizedName(extractor.getNormalizedName());
+ metadataDataDefinition.setSystemName(extractor.getSystemName());
+ metadataDataDefinition.setIsDeleted(extractor.isDeleted());
+ metadataDataDefinition.setProjectCode(extractor.getProjectCode());
+ metadataDataDefinition.setCsarUUID(extractor.getCsarUuid());
+ metadataDataDefinition.setCsarVersion(extractor.getCsarVersion());
+ metadataDataDefinition.setImportedToscaChecksum(extractor.getImportedToscaChecksum());
+ metadataDataDefinition.setInvariantUUID(extractor.getInvariantUuid());
+ componentInstanceCounter = extractor.getInstanceCounter();
}
@Override
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ConsumerData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ConsumerData.java
index 97a3ade391..e23b134f44 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ConsumerData.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ConsumerData.java
@@ -1,3 +1,4 @@
+package org.openecomp.sdc.be.resources.data;
/*-
* ============LICENSE_START=======================================================
* SDC
@@ -7,9 +8,9 @@
* 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.
@@ -18,8 +19,7 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.be.resources.data;
-
+import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
import org.openecomp.sdc.be.datatypes.elements.ConsumerDataDefinition;
@@ -30,70 +30,78 @@ import java.util.Map;
public class ConsumerData extends GraphNode {
- private ConsumerDataDefinition consumerDataDefinition;
-
- public ConsumerData() {
- super(NodeTypeEnum.ConsumerCredentials);
- consumerDataDefinition = new ConsumerDataDefinition();
- }
-
- public ConsumerData(ConsumerDataDefinition consumerDataDefinition) {
- super(NodeTypeEnum.ConsumerCredentials);
- this.consumerDataDefinition = consumerDataDefinition;
-
- }
-
- public ConsumerData(Map<String, Object> properties) {
- super(NodeTypeEnum.ConsumerCredentials);
- consumerDataDefinition = new ConsumerDataDefinition();
- consumerDataDefinition.setConsumerDetailsLastupdatedtime(
- (Long) properties.get(GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME.getProperty()));
- consumerDataDefinition.setConsumerLastAuthenticationTime(
- (Long) properties.get(GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME.getProperty()));
- consumerDataDefinition
- .setConsumerName((String) properties.get(GraphPropertiesDictionary.CONSUMER_NAME.getProperty()));
- consumerDataDefinition.setConsumerPassword(
- (String) properties.get(GraphPropertiesDictionary.CONSUMER_PASSWORD.getProperty()));
- consumerDataDefinition
- .setConsumerSalt((String) properties.get(GraphPropertiesDictionary.CONSUMER_SALT.getProperty()));
- consumerDataDefinition.setLastModfierAtuid(
- (String) properties.get(GraphPropertiesDictionary.LAST_MODIFIER_USER_ID.getProperty()));
-
- }
-
- @Override
- public String getUniqueIdKey() {
- return GraphPropertiesDictionary.CONSUMER_NAME.getProperty();
- }
-
- @Override
- public String getUniqueId() {
- return consumerDataDefinition.getConsumerName();
- }
-
- public ConsumerDataDefinition getConsumerDataDefinition() {
- return consumerDataDefinition;
- }
-
- @Override
- public Map<String, Object> toGraphMap() {
- Map<String, Object> map = new HashMap<>();
- addIfExists(map, GraphPropertiesDictionary.CONSUMER_NAME, this.consumerDataDefinition.getConsumerName());
- addIfExists(map, GraphPropertiesDictionary.CONSUMER_PASSWORD,
- this.consumerDataDefinition.getConsumerPassword());
- addIfExists(map, GraphPropertiesDictionary.CONSUMER_SALT, this.consumerDataDefinition.getConsumerSalt());
- addIfExists(map, GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME,
- this.consumerDataDefinition.getConsumerLastAuthenticationTime());
- addIfExists(map, GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME,
- this.consumerDataDefinition.getConsumerDetailsLastupdatedtime());
- addIfExists(map, GraphPropertiesDictionary.LAST_MODIFIER_USER_ID,
- this.consumerDataDefinition.getLastModfierAtuid());
-
- return map;
- }
-
- @Override
- public String toString() {
- return "ConsumerData [consumerDataDefinition=" + consumerDataDefinition + "]";
- }
+ private ConsumerDataDefinition consumerDataDefinition;
+
+ public ConsumerData() {
+ super(NodeTypeEnum.ConsumerCredentials);
+ consumerDataDefinition = new ConsumerDataDefinition();
+ }
+
+ public ConsumerData(ConsumerDataDefinition consumerDataDefinition) {
+ super(NodeTypeEnum.ConsumerCredentials);
+ this.consumerDataDefinition = consumerDataDefinition;
+
+ }
+
+ public ConsumerData(Map<String, Object> properties) {
+ super(NodeTypeEnum.ConsumerCredentials);
+ consumerDataDefinition = new ConsumerDataDefinition();
+ consumerDataDefinition.setConsumerDetailsLastupdatedtime(
+ (Long) properties.get(GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME.getProperty()));
+ consumerDataDefinition.setConsumerLastAuthenticationTime(
+ (Long) properties.get(GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME.getProperty()));
+ consumerDataDefinition
+ .setConsumerName((String) properties.get(GraphPropertiesDictionary.CONSUMER_NAME.getProperty()));
+ consumerDataDefinition.setConsumerPassword(
+ (String) properties.get(GraphPropertiesDictionary.CONSUMER_PASSWORD.getProperty()));
+ consumerDataDefinition
+ .setConsumerSalt((String) properties.get(GraphPropertiesDictionary.CONSUMER_SALT.getProperty()));
+ consumerDataDefinition.setLastModfierAtuid(
+ (String) properties.get(GraphPropertiesDictionary.LAST_MODIFIER_USER_ID.getProperty()));
+
+ }
+
+ @Override
+ public String getUniqueIdKey() {
+ return GraphPropertiesDictionary.CONSUMER_NAME.getProperty();
+ }
+
+ @Override
+ public String getUniqueId() {
+ return consumerDataDefinition.getConsumerName();
+ }
+
+ public ConsumerDataDefinition getConsumerDataDefinition() {
+ return consumerDataDefinition;
+ }
+
+ @Override
+ public Map<String, Object> toGraphMap() {
+ Map<String, Object> map = new HashMap<>();
+ addIfExists(map, GraphPropertiesDictionary.CONSUMER_NAME, this.consumerDataDefinition.getConsumerName());
+ addIfExists(map, GraphPropertiesDictionary.CONSUMER_PASSWORD,
+ this.consumerDataDefinition.getConsumerPassword());
+ addIfExists(map, GraphPropertiesDictionary.CONSUMER_SALT, this.consumerDataDefinition.getConsumerSalt());
+ addIfExists(map, GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME,
+ this.consumerDataDefinition.getConsumerLastAuthenticationTime());
+ addIfExists(map, GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME,
+ this.consumerDataDefinition.getConsumerDetailsLastupdatedtime());
+ addIfExists(map, GraphPropertiesDictionary.LAST_MODIFIER_USER_ID,
+ this.consumerDataDefinition.getLastModfierAtuid());
+
+ return map;
+ }
+
+ //added to handle fortify security violation - t avoid printing consumer data to log
+ @Override
+ public ImmutablePair<String, Object> getKeyValueIdForLog() {
+ return new ImmutablePair<>(getUniqueIdKey(), "consumerName");
+ }
+
+ @Override
+ public String toString() {
+ return "ConsumerData [consumerDataDefinition=" + consumerDataDefinition + "]";
+ }
}
+
+
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ESArtifactData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/DAOArtifactData.java
index fca13d5f74..64fac358bf 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ESArtifactData.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/DAOArtifactData.java
@@ -27,14 +27,14 @@ import com.datastax.driver.mapping.annotations.Table;
import java.nio.ByteBuffer;
@Table(keyspace = "sdcartifact", name = "resources")
-public class ESArtifactData {
+public class DAOArtifactData {
public static final String RRESOURCE_ID_FIELD = "resourceId";
public static final String SERVICE_NAME_FIELD = "serviceName";
public static final String SERVICE_VERSION_FIELD = "serviceVersion";
public static final String ARTIFACT_NAME_FIELD = "artifactName";
- public final static String delim = ":";
+ public static String delim = ":";
@PartitionKey
@Column(name = "id")
@@ -49,16 +49,16 @@ public class ESArtifactData {
// private byte[] data;
- public ESArtifactData() {
+ public DAOArtifactData() {
}
- public ESArtifactData(String id) {
+ public DAOArtifactData(String id) {
this.id = id;
}
- public ESArtifactData(String artifactId, byte[] data) {
+ public DAOArtifactData(String artifactId, byte[] data) {
super();
this.id = artifactId;
if (data != null) {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ProductMetadataData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ProductMetadataData.java
index 77f2d90632..fac80b439d 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ProductMetadataData.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ProductMetadataData.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.be.resources.data;
import com.google.gson.reflect.TypeToken;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor;
import org.openecomp.sdc.be.datatypes.elements.ProductMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -39,17 +40,11 @@ public class ProductMetadataData extends ComponentMetadataData {
super(NodeTypeEnum.Product, metadataDataDefinition);
}
- public ProductMetadataData(Map<String, Object> properties) {
- super(NodeTypeEnum.Product, new ProductMetadataDataDefinition(), properties);
- ((ProductMetadataDataDefinition) metadataDataDefinition)
- .setFullName((String) properties.get(GraphPropertiesDictionary.FULL_NAME.getProperty()));
- Type listType = new TypeToken<List<String>>() {
- }.getType();
- List<String> contactsfromJson = getGson()
- .fromJson((String) properties.get(GraphPropertiesDictionary.CONTACTS.getProperty()), listType);
- ((ProductMetadataDataDefinition) metadataDataDefinition).setContacts(contactsfromJson);
- ((ProductMetadataDataDefinition) metadataDataDefinition)
- .setIsActive((Boolean) properties.get(GraphPropertiesDictionary.IS_ACTIVE.getProperty()));
+ public ProductMetadataData(GraphPropertiesDictionaryExtractor extractor) {
+ super(NodeTypeEnum.Product, new ProductMetadataDataDefinition(), extractor);
+ ((ProductMetadataDataDefinition) metadataDataDefinition).setFullName(extractor.getFullName());
+ ((ProductMetadataDataDefinition) metadataDataDefinition).setContacts(extractor.getContacts());
+ ((ProductMetadataDataDefinition) metadataDataDefinition).setIsActive(extractor.isActive());
}
@Override
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ResourceMetadataData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ResourceMetadataData.java
index bc7f34c125..ddb3b9883d 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ResourceMetadataData.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ResourceMetadataData.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.resources.data;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor;
import org.openecomp.sdc.be.datatypes.components.ComponentMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -38,18 +39,15 @@ public class ResourceMetadataData extends ComponentMetadataData {
super(NodeTypeEnum.Resource, metadataDataDefinition);
}
- public ResourceMetadataData(Map<String, Object> properties) {
- super(NodeTypeEnum.Resource, new ResourceMetadataDataDefinition(), properties);
- ((ResourceMetadataDataDefinition) metadataDataDefinition).setVendorName((String) properties.get(GraphPropertiesDictionary.VENDOR_NAME.getProperty()));
- ((ResourceMetadataDataDefinition) metadataDataDefinition).setVendorRelease((String) properties.get(GraphPropertiesDictionary.VENDOR_RELEASE.getProperty()));
- if (properties.get(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty()) != null) {
- ((ResourceMetadataDataDefinition) metadataDataDefinition).setResourceType(ResourceTypeEnum.valueOf((String) properties.get(GraphPropertiesDictionary.RESOURCE_TYPE.getProperty())));
- }
- ((ResourceMetadataDataDefinition) metadataDataDefinition).setAbstract((Boolean) properties.get(GraphPropertiesDictionary.IS_ABSTRACT.getProperty()));
- ((ResourceMetadataDataDefinition) metadataDataDefinition).setCost((String) properties.get(GraphPropertiesDictionary.COST.getProperty()));
- ((ResourceMetadataDataDefinition) metadataDataDefinition).setLicenseType((String) properties.get(GraphPropertiesDictionary.LICENSE_TYPE.getProperty()));
- ((ResourceMetadataDataDefinition) metadataDataDefinition).setToscaResourceName((String) properties.get(GraphPropertiesDictionary.TOSCA_RESOURCE_NAME.getProperty()));
-
+ public ResourceMetadataData(GraphPropertiesDictionaryExtractor extractor) {
+ super(NodeTypeEnum.Resource, new ResourceMetadataDataDefinition(), extractor);
+ ((ResourceMetadataDataDefinition) metadataDataDefinition).setVendorName(extractor.getVendorName());
+ ((ResourceMetadataDataDefinition) metadataDataDefinition).setVendorRelease(extractor.getVendorRelease());
+ ((ResourceMetadataDataDefinition) metadataDataDefinition).setResourceType(extractor.getResourceType());
+ ((ResourceMetadataDataDefinition) metadataDataDefinition).setAbstract(extractor.isAbstract());
+ ((ResourceMetadataDataDefinition) metadataDataDefinition).setCost(extractor.getCost());
+ ((ResourceMetadataDataDefinition) metadataDataDefinition).setLicenseType(extractor.getLicenseType());
+ ((ResourceMetadataDataDefinition) metadataDataDefinition).setToscaResourceName(extractor.getToscaResourceName());
}
@Override
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceArtifactsDataCollection.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceArtifactsDataCollection.java
deleted file mode 100644
index 6d01268434..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceArtifactsDataCollection.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.resources.data;
-
-import java.util.List;
-import java.util.Map;
-
-public class ServiceArtifactsDataCollection {
-
- private Map<String, List<ESArtifactData>> serviceArtifactDataMap;
-
- public Map<String, List<ESArtifactData>> getServiceArtifactDataMap() {
- return serviceArtifactDataMap;
- }
-
- public void setServiceArtifactDataMap(Map<String, List<ESArtifactData>> serviceArtifactDataMap) {
- this.serviceArtifactDataMap = serviceArtifactDataMap;
- }
-
- public List<ESArtifactData> getNodeTemplateArtifacts(String nodeTemplateName) {
- if (serviceArtifactDataMap != null && serviceArtifactDataMap.containsKey(nodeTemplateName))
- return serviceArtifactDataMap.get(nodeTemplateName);
- else
- return null;
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceMetadataData.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceMetadataData.java
index a50d7ff6c8..01e4ca4eb4 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceMetadataData.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/ServiceMetadataData.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.be.resources.data;
import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
+import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor;
import org.openecomp.sdc.be.datatypes.components.ServiceMetadataDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
@@ -36,12 +37,10 @@ public class ServiceMetadataData extends ComponentMetadataData {
super(NodeTypeEnum.Service, serviceMetadataDataDefinition);
}
- public ServiceMetadataData(Map<String, Object> properties) {
- super(NodeTypeEnum.Service, new ServiceMetadataDataDefinition(), properties);
- ((ServiceMetadataDataDefinition) metadataDataDefinition)
- .setProjectCode((String) properties.get(GraphPropertiesDictionary.PROJECT_CODE.getProperty()));
- ((ServiceMetadataDataDefinition) metadataDataDefinition).setDistributionStatus(
- (String) properties.get(GraphPropertiesDictionary.DISTRIBUTION_STATUS.getProperty()));
+ public ServiceMetadataData(GraphPropertiesDictionaryExtractor extractor) {
+ super(NodeTypeEnum.Service, new ServiceMetadataDataDefinition(), extractor);
+ metadataDataDefinition.setProjectCode(extractor.getProjectCode());
+ ((ServiceMetadataDataDefinition) metadataDataDefinition).setDistributionStatus(extractor.getDistributionStatus());
}
@Override
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingActionEnum.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingActionEnum.java
index 3e2b95b129..4203c9f4d8 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingActionEnum.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingActionEnum.java
@@ -25,7 +25,7 @@ import org.openecomp.sdc.common.log.wrappers.Logger;
//TODO rename to AuditAction
public enum AuditingActionEnum {
- // User admininstration
+ // User administration
ADD_USER("AddUser", AuditingTypesConstants.USER_ADMIN_EVENT_TYPE),
UPDATE_USER("UpdateUser", AuditingTypesConstants.USER_ADMIN_EVENT_TYPE),
DELETE_USER("DeleteUser", AuditingTypesConstants.USER_ADMIN_EVENT_TYPE),
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEvent.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEvent.java
index 92e5f4bf2f..57bab5977e 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEvent.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingGenericEvent.java
@@ -20,20 +20,36 @@
package org.openecomp.sdc.be.resources.data.auditing;
-import org.openecomp.sdc.common.datastructure.ESTimeBasedEvent;
+import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
+
+import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TimeZone;
+
+public class AuditingGenericEvent {
+ protected SimpleDateFormat simpleDateFormat;
+ protected static String dateFormatPattern = "yyyy-MM-dd HH:mm:ss.SSS z";
-public class AuditingGenericEvent extends ESTimeBasedEvent {
protected String requestId;
protected String serviceInstanceId;
protected String action;
protected String status;
+ protected String timestamp;
protected String desc;
+ protected Map<String, Object> fields = new HashMap<>();
+
public AuditingGenericEvent() {
super();
+ simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
+ simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ this.timestamp = simpleDateFormat.format(new Date());
+ fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), this.timestamp);
+
}
public String getRequestId() {
@@ -90,4 +106,21 @@ public class AuditingGenericEvent extends ESTimeBasedEvent {
}
}
+ public String getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(String timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public Map<String, Object> getFields() {
+ return fields;
+ }
+
+ public void setFields(Map<String, Object> fields) {
+ this.fields = fields;
+ }
+
+
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingTypesConstants.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingTypesConstants.java
index c6c609b189..2716621cae 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingTypesConstants.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/AuditingTypesConstants.java
@@ -49,5 +49,6 @@ public interface AuditingTypesConstants {
String GET_CATEGORY_HIERARCHY_EVENT_TYPE = "getcategoryhierarchyevent";
String EXTERNAL_API_EVENT_TYPE = "externalapievent";
String ENVIRONMENT_ENGINE_EVENT_TYPE = "environmentengineevent";
+ String FEATURE_TOGGLE_STATE = "featuretogglestate";
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/EcompOperationalEnvironmentEvent.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/EcompOperationalEnvironmentEvent.java
index b8d3bdd03f..7635d8f779 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/EcompOperationalEnvironmentEvent.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/EcompOperationalEnvironmentEvent.java
@@ -36,6 +36,7 @@ import java.util.TimeZone;
public class EcompOperationalEnvironmentEvent extends AuditingGenericEvent {
@PartitionKey
+ @Column(name = "operational_environment_id")
protected String operationalEnvironmentId;
@ClusteringColumn
@@ -101,7 +102,7 @@ public class EcompOperationalEnvironmentEvent extends AuditingGenericEvent {
return operationalEnvironmentType;
}
- public void setOperational_environment_type(String operationalEnvironmentType) {
+ public void setOperationalEnvironmentType(String operationalEnvironmentType) {
this.operationalEnvironmentType = operationalEnvironmentType;
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/ResourceAdminEvent.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/ResourceAdminEvent.java
index 82e1fca9ca..226e0f0588 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/ResourceAdminEvent.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/auditing/ResourceAdminEvent.java
@@ -169,7 +169,7 @@ public class ResourceAdminEvent extends AuditingGenericEvent {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
+ fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), timestamp1.getTime());
}
public String getResourceName() {
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java
new file mode 100644
index 0000000000..86bd60a75a
--- /dev/null
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/FeatureToggleEvent.java
@@ -0,0 +1,120 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.resources.data.togglz;
+
+import com.datastax.driver.mapping.annotations.Column;
+import com.datastax.driver.mapping.annotations.PartitionKey;
+import com.datastax.driver.mapping.annotations.Table;
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+import org.openecomp.sdc.be.resources.data.auditing.AuditingTypesConstants;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
+import org.openecomp.sdc.common.log.wrappers.Logger;
+import org.togglz.core.Feature;
+import org.togglz.core.repository.FeatureState;
+
+import java.util.Map;
+
+@Table(keyspace = AuditingTypesConstants.REPO_KEYSPACE, name = AuditingTypesConstants.FEATURE_TOGGLE_STATE)
+public class FeatureToggleEvent {
+ private static final Logger logger = Logger.getLogger(FeatureToggleEvent.class);
+
+ @PartitionKey
+ @Column(name = "feature_name")
+ private String featureName;
+
+ @Column(name = "enabled")
+ private String enabled;
+
+ @Column(name = "strategy_id")
+ private String strategyId;
+
+ @Column(name = "parameters")
+ private String parameters;
+
+ public void setFeatureName(String featureName) {
+ this.featureName = featureName;
+ }
+
+ public void setEnabled(String enabled) {
+ this.enabled = enabled;
+ }
+
+ public void setStrategyId(String strategyId) {
+ this.strategyId = strategyId;
+ }
+
+ public void setParameters(String parameters) {
+ this.parameters = parameters;
+ }
+
+ public String getFeatureName() {
+ return featureName;
+ }
+
+ public String getEnabled() {
+ return enabled;
+ }
+
+ public String getStrategyId() {
+ return strategyId;
+ }
+
+ public String getParameters() {
+ return parameters;
+ }
+
+ public FeatureToggleEvent() {}
+
+ public FeatureToggleEvent(FeatureState featureState) {
+ this();
+ this.featureName = featureState.getFeature().name();
+ this.enabled = String.valueOf(featureState.isEnabled());
+ this.strategyId = featureState.getStrategyId();
+ this.parameters = Joiner.on(",").withKeyValueSeparator("=").join(featureState.getParameterMap());
+ }
+
+ public FeatureState getFeatureState() {
+ Feature feature = ToggleableFeature.getFeatureByName(featureName);
+ if (feature == null) {
+ return null;
+ }
+ FeatureState featureState = new FeatureState(feature, Boolean.valueOf(enabled));
+ featureState.setStrategyId(strategyId);
+
+ setParameters(featureState);
+ return featureState;
+
+ }
+
+ private void setParameters(FeatureState featureState) {
+ try {
+ Map<String, String> paramMap = Splitter.on(",").withKeyValueSeparator("=").split(parameters);
+ paramMap.keySet().forEach(p->featureState.setParameter(p, paramMap.get(p)));
+ }
+ catch(IllegalArgumentException e) {
+ logger.warn(EcompLoggerErrorCode.DATA_ERROR, "FeatureToggle",
+ "FeatureState Object generating", e.getMessage());
+ }
+ }
+
+
+}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IGenericSearchDAO.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/ToggleableFeature.java
index 1e0cdace2c..2fd2c80b02 100644
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/api/IGenericSearchDAO.java
+++ b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/data/togglz/ToggleableFeature.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,25 +18,26 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.sdc.be.dao.api;
+package org.openecomp.sdc.be.resources.data.togglz;
-import org.elasticsearch.index.query.QueryBuilder;
+import org.togglz.core.Feature;
+import org.togglz.core.annotation.Label;
+import org.togglz.core.context.FeatureContext;
-/**
- * A Dao that supports search and/or filter based queries.
- *
- * @author luc boutier
- */
-public interface IGenericSearchDAO extends IGenericIdDAO {
+import java.util.Arrays;
+
+public enum ToggleableFeature implements Feature{
+ @Label("Default feature")
+ DEFAULT_FEATURE;
- /**
- * Get the index in which a class belongs.
- *
- * @param clazz
- * The class for which to get the index.
- * @return The name of the index in which the class lies.
- */
- String getIndexForType(String type);
+ public static Feature getFeatureByName(String featureName) {
+ return Arrays.stream(values()).
+ filter(e -> e.name().equals(featureName))
+ .findFirst()
+ .orElse(null);
+ }
- long count(String indexName, String typeName, QueryBuilder query);
+ public boolean isActive() {
+ return FeatureContext.getFeatureManager().isActive(this);
+ }
}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/exception/ResourceDAOException.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/exception/ResourceDAOException.java
deleted file mode 100644
index cae5c47699..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/exception/ResourceDAOException.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.resources.exception;
-
-import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
-import org.openecomp.sdc.exception.TechnicalException;
-
-public class ResourceDAOException extends TechnicalException {
-
- private static final long serialVersionUID = 171917520842336653L;
-
- private ResourceUploadStatus status;
-
- public ResourceDAOException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public ResourceDAOException(String message) {
- super(message);
- }
-
- public ResourceDAOException(ResourceUploadStatus status, String message, Throwable cause) {
- super(message, cause);
- this.status = status;
- }
-
- public ResourceDAOException(ResourceUploadStatus status, String message) {
- super(message);
- this.status = status;
- }
-
- public ResourceUploadStatus getStatus() {
- return status;
- }
-
- public void setStatus(ResourceUploadStatus status) {
- this.status = status;
- }
-
-}
diff --git a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/impl/ResourceUploader.java b/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/impl/ResourceUploader.java
deleted file mode 100644
index 5b9f548b46..0000000000
--- a/catalog-dao/src/main/java/org/openecomp/sdc/be/resources/impl/ResourceUploader.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.sdc.be.resources.impl;
-
-import fj.data.Either;
-import org.openecomp.sdc.be.config.BeEcompErrorManager;
-import org.openecomp.sdc.be.config.ConfigurationManager;
-import org.openecomp.sdc.be.dao.api.ICatalogDAO;
-import org.openecomp.sdc.be.dao.api.ResourceUploadStatus;
-import org.openecomp.sdc.be.resources.api.IResourceUploader;
-import org.openecomp.sdc.be.resources.data.ESArtifactData;
-import org.openecomp.sdc.be.resources.exception.ResourceDAOException;
-import org.openecomp.sdc.common.log.wrappers.Logger;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
-
-@Component("resource-upload")
-public class ResourceUploader implements IResourceUploader {
-
- private static final String DEFAULT_ARTIFACT_INDEX_NAME = "resources";
-
- @Resource
- private ICatalogDAO resourceDAO;
- private static Logger log = Logger.getLogger(ResourceUploader.class.getName());
-
- @PostConstruct
- public void init() {
- ConfigurationManager configMgr = ConfigurationManager.getConfigurationManager();
- String artifactsIndex = null;
- artifactsIndex = configMgr.getConfiguration().getArtifactsIndex();
- if (artifactsIndex == null || artifactsIndex.isEmpty()) {
- artifactsIndex = DEFAULT_ARTIFACT_INDEX_NAME;
- }
- resourceDAO.addToIndicesMap(ESArtifactData.class.getSimpleName().toLowerCase(), artifactsIndex);
- }
-
- public ResourceUploader() {
- super();
- }
-
- public ResourceUploader(ICatalogDAO resourcetDAO) {
- super();
- this.resourceDAO = resourcetDAO;
- }
-
- public ICatalogDAO getResourceDAO() {
- return resourceDAO;
- }
-
- public void setResourceDAO(ICatalogDAO resourceDAO) {
- this.resourceDAO = resourceDAO;
- }
-
- @Override
- public ResourceUploadStatus saveArtifact(ESArtifactData artifactData, boolean isReload) {
- ResourceUploadStatus status = ResourceUploadStatus.OK;
- if (resourceDAO == null) {
- BeEcompErrorManager.getInstance()
- .logBeInitializationError("Save Artifact - internal object not initialized");
- log.debug("update artifact failed - resourceDAO is null");
- return ResourceUploadStatus.ERROR;
- }
-
- Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = getArtifact(artifactData.getId());
- if (getArtifactStatus.isLeft()) {
- status = ResourceUploadStatus.ALREADY_EXIST;
- log.debug("ResourceUploadStatus:saveArtifact artifact with id {} already exist.", artifactData.getId());
- if (isReload) {
- status = updateArtifact(artifactData, getArtifactStatus.left().value());
- }
- } else {
- try {
-
- resourceDAO.writeArtifact(artifactData);
- status = ResourceUploadStatus.OK;
-
- } catch (ResourceDAOException e) {
- status = ResourceUploadStatus.ERROR;
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Save Artifact to database");
- log.debug("ResourceUploadStatus:saveArtifact failed with exception ", e);
- }
-
- }
-
- return status;
- }
-
- @Override
- public ResourceUploadStatus updateArtifact(ESArtifactData artifactUpdateData) {
- ResourceUploadStatus status = ResourceUploadStatus.OK;
- if (resourceDAO == null)
- return ResourceUploadStatus.ERROR;
-
- Either<ESArtifactData, ResourceUploadStatus> getArtifactStatus = getArtifact(artifactUpdateData.getId());
- if (getArtifactStatus.isRight()) {
- status = getArtifactStatus.right().value();
- log.debug("ResourceUploadStatus:updateArtifactt artifact with id {}", artifactUpdateData.getId()
- + " not exist.");
- }
- if (getArtifactStatus.isLeft()) {
- status = updateArtifact(artifactUpdateData, getArtifactStatus.left().value());
- }
-
- return status;
- }
-
- @Override
- public Either<ESArtifactData, ResourceUploadStatus> getArtifact(String id) {
- if (resourceDAO == null)
- return Either.right(ResourceUploadStatus.ERROR);
-
- return resourceDAO.getArtifact(id);
- }
-
- @Override
- public void deleteArtifact(String id) {
- if (resourceDAO != null) {
- resourceDAO.deleteArtifact(id);
- }
-
- }
-
- private ResourceUploadStatus updateArtifact(ESArtifactData artifactUpdateData, ESArtifactData existData) {
- ResourceUploadStatus status;
-
- updateData(artifactUpdateData, existData);
-
- try {
- resourceDAO.writeArtifact(artifactUpdateData);
- status = ResourceUploadStatus.OK;
-
- } catch (ResourceDAOException e) {
- status = ResourceUploadStatus.ERROR;
- log.debug("ResourceUploadStatus:updateArtifact failed with exception ", e);
- }
- return status;
- }
-
- private void updateData(ESArtifactData artifactUpdateData, ESArtifactData existData) {
-
- if (artifactUpdateData.getData() == null) {
- artifactUpdateData.setData(existData.getData());
- }
-
- }
-
- @Override
- public void deleteAllArtifacts() {
- resourceDAO.deleteAllArtifacts();
- }
-
-}