Change-Id: I453fdb5f2aa1488adbf0664a624a98b239d4a927
Issue-ID: SDC-1954
Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
/**
import java.util.HashMap;
import java.util.Map;
/**
@Singleton
public class ArtifactExternalServlet extends AbstractValidationsServlet {
@Singleton
public class ArtifactExternalServlet extends AbstractValidationsServlet {
+ private static final String FAILED_TO_UPDATE_ARTIFACT = "failed to update artifact";
+
@Context
private HttpServletRequest request;
@Context
private HttpServletRequest request;
Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request, componentType, uuid, artifactUUID, operationUUID,
resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
if (uploadArtifactEither.isRight()) {
Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnInterfaceOperationByResourceUUID(data, request, componentType, uuid, artifactUUID, operationUUID,
resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
if (uploadArtifactEither.isRight()) {
- log.debug("failed to update artifact");
+ log.debug(FAILED_TO_UPDATE_ARTIFACT);
responseFormat = uploadArtifactEither.right().value();
responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
} else {
responseFormat = uploadArtifactEither.right().value();
responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
} else {
Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnComponentByUUID(data, request, componentType, uuid, artifactUUID,
resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
if (uploadArtifactEither.isRight()) {
Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnComponentByUUID(data, request, componentType, uuid, artifactUUID,
resourceCommonInfo, artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
if (uploadArtifactEither.isRight()) {
- log.debug("failed to update artifact");
+ log.debug(FAILED_TO_UPDATE_ARTIFACT);
responseFormat = uploadArtifactEither.right().value();
responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
} else {
responseFormat = uploadArtifactEither.right().value();
responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
} else {
Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnRiByUUID(data, request, componentType, uuid, resourceInstanceName, artifactUUID,
artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
if (uploadArtifactEither.isRight()) {
Either<ArtifactDefinition, ResponseFormat> uploadArtifactEither = artifactsLogic.updateArtifactOnRiByUUID(data, request, componentType, uuid, resourceInstanceName, artifactUUID,
artifactsLogic.new ArtifactOperationInfo(true, false, ArtifactOperationEnum.UPDATE));
if (uploadArtifactEither.isRight()) {
- log.debug("failed to update artifact");
+ log.debug(FAILED_TO_UPDATE_ARTIFACT);
responseFormat = uploadArtifactEither.right().value();
responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
} else {
responseFormat = uploadArtifactEither.right().value();
responseWrapper.setInnerElement(buildErrorResponse(responseFormat));
} else {
private NodeTypeEnum label;
private NodeTypeEnum label;
+ protected GraphNode(NodeTypeEnum label) {
+ super(GraphElementTypeEnum.Node);
+
+ this.label = label;
+ }
+
protected Gson getGson() {
return gson;
}
protected Gson getGson() {
return gson;
}
- protected GraphNode(NodeTypeEnum label) {
- super(GraphElementTypeEnum.Node);
-
- this.label = label;
- }
-
public String getLabel() {
return label.getName();
}
public String getLabel() {
return label.getName();
}
@Component("auditingDao")
public class AuditingDao extends ESTimeBasedDao {
@Component("auditingDao")
public class AuditingDao extends ESTimeBasedDao {
- private static final String SERVICE_INSTANCE_ID_FIELD = AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID
+ 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";
.getDisplayName(); // "serviceInstanceId";
private static final String STATUS_FIELD = AuditingFieldsKey.AUDIT_STATUS.getDisplayName(); // "status";
private static final String ACTION_FIELD = AuditingFieldsKey.AUDIT_ACTION.getDisplayName(); // "action";
remainingElements = customFindEvent(AuditingTypesConstants.RESOURCE_ADMIN_EVENT_TYPE,
remainingElementQueryBuilder, null);
} catch (Exception e) {
remainingElements = customFindEvent(AuditingTypesConstants.RESOURCE_ADMIN_EVENT_TYPE,
remainingElementQueryBuilder, null);
} catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Service DistributionStatuses List");
- log.debug("failed to get distribution statuses for action {}",
+ 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);
}
AuditingActionEnum.DISTRIBUTION_STATE_CHANGE_REQUEST.getName(), e);
return Either.right(ActionStatus.GENERAL_ERROR);
}
dResultElements = customFindEvent(AuditingTypesConstants.DISTRIBUTION_DEPLOY_EVENT_TYPE,
remainingElementQueryBuilder, null);
} catch (Exception e) {
dResultElements = customFindEvent(AuditingTypesConstants.DISTRIBUTION_DEPLOY_EVENT_TYPE,
remainingElementQueryBuilder, null);
} catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Service DistributionStatuses List");
+ 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);
log.debug("failed to get distribution statuses for action {}",
AuditingActionEnum.DISTRIBUTION_DEPLOY.getName(), e);
return Either.right(ActionStatus.GENERAL_ERROR);
dNotifyElements = customFindEvent(AuditingTypesConstants.DISTRIBUTION_NOTIFICATION_EVENT_TYPE,
remainingElementQueryBuilder, null);
} catch (Exception e) {
dNotifyElements = customFindEvent(AuditingTypesConstants.DISTRIBUTION_NOTIFICATION_EVENT_TYPE,
remainingElementQueryBuilder, null);
} catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeDaoSystemError("Get Service DistributionStatuses List");
+ 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);
log.debug("failed to get distribution statuses for action {}",
AuditingActionEnum.DISTRIBUTION_NOTIFY.getName(), e);
return Either.right(ActionStatus.GENERAL_ERROR);
private static Logger log = Logger.getLogger(ESCatalogDAO.class.getName());
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");
//TODO use LoggerMetric instead
private static Logger healthCheckLogger = Logger.getLogger("elasticsearch.healthcheck");
- // Index Checking Variables
- private boolean initCompleted = false;
-
- public void writeArtifact(ESArtifactData artifactData) throws ResourceDAOException {
+ public void writeArtifact(ESArtifactData artifactData) {
try {
saveResourceData(artifactData);
} catch (Exception e) {
try {
saveResourceData(artifactData);
} catch (Exception e) {
private Map<String, String> indexPrefix2CreationPeriod;
private ConfigurationManager configurationManager;
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();
protected ESTimeBasedDao() {
gson = new GsonBuilder().setPrettyPrinting().create();
configurationManager = ConfigurationManager.getConfigurationManager();
this.configurationManager = configurationManager;
}
this.configurationManager = configurationManager;
}
- @Resource(name = "elasticsearch-client")
- private ElasticSearchClient esClient;
-
- protected final Map<String, Class<?>> typesToClasses = new HashMap<>();
-
public abstract String getIndexPrefix();
public ActionStatus write(String typeName, ESTimeBasedEvent data) {
public abstract String getIndexPrefix();
public ActionStatus write(String typeName, ESTimeBasedEvent data) {
- public List<ESTimeBasedEvent> customFindEvent(String typeName, QueryBuilder query, SortBuilder sortBuilder)
- throws JSONException {
+ 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<>();
List<ESTimeBasedEvent> results = doCustomFindForEvent(typeName, query, sortBuilder, MAX_SEARCH_SIZE);
if (results == null) {
results = new ArrayList<>();
}
private boolean somethingFound(final SearchResponse searchResponse) {
}
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;
+ return !(searchResponse == null || searchResponse.getHits() == null || searchResponse.getHits().getHits() == null
+ || searchResponse.getHits().getHits().length == 0);
}
public String getEsHost() {
}
public String getEsHost() {
//@Component("users-dao")
public class Neo4jUsersDAO implements IUsersDAO {
//@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());
Neo4jClient neo4jClient;
private static Logger logger = Logger.getLogger(Neo4jUsersDAO.class.getName());
if (createIndexStatus.equals(Neo4jOperationStatus.OK)) {
logger.info("Users indexes created in Neo4j");
List<String> propertyUnique = new ArrayList<>();
if (createIndexStatus.equals(Neo4jOperationStatus.OK)) {
logger.info("Users indexes created in Neo4j");
List<String> propertyUnique = new ArrayList<>();
- propertyUnique.add("userId");
+ propertyUnique.add(USER_ID);
logger.info("Start create Users constraints in Neo4jGraph");
Neo4jOperationStatus createUniquenessStatus = neo4jClient
logger.info("Start create Users constraints in Neo4jGraph");
Neo4jOperationStatus createUniquenessStatus = neo4jClient
@Override
public Either<UserData, ActionStatus> getUserData(String id) {
MatchFilter filter = new MatchFilter();
@Override
public Either<UserData, ActionStatus> getUserData(String id) {
MatchFilter filter = new MatchFilter();
- filter.addToMatch("userId", id);
+ filter.addToMatch(USER_ID, id);
Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
NodeTypeEnum.User.getName(), filter);
if (status.isRight()) {
Either<List<GraphElement>, Neo4jOperationStatus> status = neo4jClient.getByFilter(GraphElementTypeEnum.Node,
NodeTypeEnum.User.getName(), filter);
if (status.isRight()) {
@Override
public ActionStatus updateUserData(UserData userData) {
UpdateFilter filter = new UpdateFilter();
@Override
public ActionStatus updateUserData(UserData userData) {
UpdateFilter filter = new UpdateFilter();
- filter.addToMatch("userId", userData.getUserId());
+ filter.addToMatch(USER_ID, userData.getUserId());
filter.setToUpdate(userData.toGraphMap());
Neo4jOperationStatus status = neo4jClient.updateElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(),
filter);
filter.setToUpdate(userData.toGraphMap());
Neo4jOperationStatus status = neo4jClient.updateElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(),
filter);
@Override
public ActionStatus deleteUserData(String id) {
MatchFilter filter = new MatchFilter();
@Override
public ActionStatus deleteUserData(String id) {
MatchFilter filter = new MatchFilter();
- filter.addToMatch("userId", id);
+ filter.addToMatch(USER_ID, id);
Neo4jOperationStatus status = neo4jClient.deleteElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(),
filter);
if (status.equals(Neo4jOperationStatus.OK)) {
Neo4jOperationStatus status = neo4jClient.deleteElement(GraphElementTypeEnum.Node, NodeTypeEnum.User.getName(),
filter);
if (status.equals(Neo4jOperationStatus.OK)) {
- public void setVertexProperties(Vertex vertex, Map<String, Object> properties) throws IOException {
+ public void setVertexProperties(Vertex vertex, Map<String, Object> properties) {
for (Map.Entry<String, Object> entry : properties.entrySet()) {
if (entry.getValue() != null) {
vertex.property(entry.getKey(), entry.getValue());
for (Map.Entry<String, Object> entry : properties.entrySet()) {
if (entry.getValue() != null) {
vertex.property(entry.getKey(), entry.getValue());
@Component("titan-generic-dao")
public class TitanGenericDao {
@Component("titan-generic-dao")
public class TitanGenericDao {
- private TitanGraphClient titanClient;
+ 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 TitanGraphClient titanClient;
private static Logger log = Logger.getLogger(TitanGenericDao.class.getName());
private static final String LOCK_NODE_PREFIX = "lock_";
private static Logger log = Logger.getLogger(TitanGenericDao.class.getName());
private static final String LOCK_NODE_PREFIX = "lock_";
return Either.left(newRelation);
} catch (Exception e) {
return Either.left(newRelation);
} catch (Exception e) {
- log.debug("Failed to create edge from [{}] to [{}]", from, to, e);
+ log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, from, to, e);
return Either.right(TitanGraphClient.handleTitanException(e));
}
} else {
return Either.right(TitanGraphClient.handleTitanException(e));
}
} else {
try {
Edge edge = addEdge(vertexOut, vertexIn, type, properties);
} catch (Exception e) {
try {
Edge edge = addEdge(vertexOut, vertexIn, type, properties);
} catch (Exception e) {
- log.debug("Failed to create edge from [{}] to [{}]", vertexOut, vertexIn, e);
+ log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, vertexOut, vertexIn, e);
return TitanGraphClient.handleTitanException(e);
}
return TitanOperationStatus.OK;
return TitanGraphClient.handleTitanException(e);
}
return TitanOperationStatus.OK;
Edge edge = addEdge(vertexOut, vertexIn, type, properties);
return Either.left(edge);
} catch (Exception e) {
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);
+ log.debug(FAILED_TO_CREATE_EDGE_FROM_TO, vertexOut, vertexIn, e);
return Either.right(TitanGraphClient.handleTitanException(e));
}
return Either.right(TitanGraphClient.handleTitanException(e));
}
Edge matchingEdge = null;
Iterable<TitanEdge> edges = query.edges();
if (edges == null) {
Edge matchingEdge = null;
Iterable<TitanEdge> 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(TitanOperationStatus.NOT_FOUND);
}
Iterator<TitanEdge> eIter = edges.iterator();
return Either.right(TitanOperationStatus.NOT_FOUND);
}
Iterator<TitanEdge> eIter = edges.iterator();
}
if (matchingEdge == null) {
}
if (matchingEdge == null) {
- log.debug("No edges in graph for criteria");
+ log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
return Either.right(TitanOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);
return Either.right(TitanOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);
if (vertexFrom.isRight()) {
return Either.right(vertexFrom.right().value());
}
if (vertexFrom.isRight()) {
return Either.right(vertexFrom.right().value());
}
- Iterable<TitanEdge> edges = ((TitanVertex) vertexFrom.left().value()).query().labels(label).edges();
+ Iterable<TitanEdge> edges = vertexFrom.left().value().query().labels(label).edges();
Iterator<TitanEdge> eIter = edges.iterator();
while (eIter.hasNext()) {
Edge edge = eIter.next();
Iterator<TitanEdge> eIter = edges.iterator();
while (eIter.hasNext()) {
Edge edge = eIter.next();
Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.getGraph();
if (graphRes.isRight()) {
Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.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());
}
return Either.right(graphRes.right().value());
}
Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.getGraph();
if (graphRes.isRight()) {
Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.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());
}
return Either.right(graphRes.right().value());
}
Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.getGraph();
if (graphRes.isRight()) {
Either<TitanGraph, TitanOperationStatus> graphRes = titanClient.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());
}
return Either.right(graphRes.right().value());
}
Edge matchingEdge = null;
Iterable<TitanEdge> edges = query.edges();
if (edges == null) {
Edge matchingEdge = null;
Iterable<TitanEdge> 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(TitanOperationStatus.NOT_FOUND);
}
Iterator<TitanEdge> eIter = edges.iterator();
return Either.right(TitanOperationStatus.NOT_FOUND);
}
Iterator<TitanEdge> eIter = edges.iterator();
}
if (matchingEdge == null) {
}
if (matchingEdge == null) {
- log.debug("No edges in graph for criteria");
+ log.debug(NO_EDGES_IN_GRAPH_FOR_CRITERIA);
return Either.right(TitanOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);
return Either.right(TitanOperationStatus.NOT_FOUND);
}
return Either.left(matchingEdge);