summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/crud/dao/DataRouterDAO.java51
-rw-r--r--src/main/java/org/onap/crud/dao/champ/ChampDao.java34
-rw-r--r--src/main/java/org/onap/crud/service/AbstractGraphDataService.java18
-rw-r--r--src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java12
-rw-r--r--src/main/java/org/onap/crud/service/CrudGraphDataService.java17
-rw-r--r--src/main/java/org/onap/crud/util/CrudServiceConstants.java1
6 files changed, 104 insertions, 29 deletions
diff --git a/src/main/java/org/onap/crud/dao/DataRouterDAO.java b/src/main/java/org/onap/crud/dao/DataRouterDAO.java
new file mode 100644
index 0000000..910fcf2
--- /dev/null
+++ b/src/main/java/org/onap/crud/dao/DataRouterDAO.java
@@ -0,0 +1,51 @@
+/**
+ * ============LICENSE_START=======================================================
+ * Gizmo
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property.
+ * Copyright © 2017 Amdocs
+ * 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.crud.dao;
+
+import org.eclipse.jetty.util.security.Password;
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.restclient.client.RestClient;
+import org.onap.aai.restclient.enums.RestAuthenticationMode;
+import org.onap.crud.dao.champ.ChampDao;
+import org.onap.crud.util.CrudServiceConstants;
+
+public class DataRouterDAO extends ChampDao {
+ private Logger logger = LoggerFactory.getInstance().getLogger(DataRouterDAO.class.getName());
+
+ public DataRouterDAO(String url, String certPassword) {
+ try {
+ client = new RestClient().authenticationMode(RestAuthenticationMode.SSL_CERT).validateServerHostname(false)
+ .validateServerCertChain(false).clientCertFile(CrudServiceConstants.CRD_DATAROUTER_AUTH_FILE)
+ .clientCertPassword(Password.deobfuscate(certPassword));
+
+ baseObjectUrl = url + OBJECT_SUB_URL;
+ baseRelationshipUrl = url + RELATIONSHIP_SUB_URL;
+ } catch (Exception e) {
+ System.out.println("Error setting up datarouter configuration");
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+}
diff --git a/src/main/java/org/onap/crud/dao/champ/ChampDao.java b/src/main/java/org/onap/crud/dao/champ/ChampDao.java
index 0bf8368..cd0e66f 100644
--- a/src/main/java/org/onap/crud/dao/champ/ChampDao.java
+++ b/src/main/java/org/onap/crud/dao/champ/ChampDao.java
@@ -57,26 +57,29 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
public class ChampDao implements GraphDao {
- private RestClient client;
- private String baseObjectUrl;
- private String baseRelationshipUrl;
- private String baseTransactionUrl;
-
- private static final String HEADER_FROM_APP = "X-FromAppId";
- private static final String HEADER_TRANS_ID = "X-TransactionId";
- private static final String FROM_APP_NAME = "Gizmo";
- private static final String OBJECT_SUB_URL = "objects";
- private static final String RELATIONSHIP_SUB_URL = "relationships";
- private static final String TRANSACTION_SUB_URL = "transaction";
+ protected RestClient client;
+ protected String baseObjectUrl;
+ protected String baseRelationshipUrl;
+ protected String baseTransactionUrl;
+
+ protected static final String HEADER_FROM_APP = "X-FromAppId";
+ protected static final String HEADER_TRANS_ID = "X-TransactionId";
+ protected static final String FROM_APP_NAME = "Gizmo";
+ protected static final String OBJECT_SUB_URL = "objects";
+ protected static final String RELATIONSHIP_SUB_URL = "relationships";
+ protected static final String TRANSACTION_SUB_URL = "transaction";
private Logger logger = LoggerFactory.getInstance().getLogger(ChampDao.class.getName());
// We use a custom vertex serializer for champ because it expects "key"
// instead of "id"
- private static final Gson champGson = new GsonBuilder()
+ protected static final Gson champGson = new GsonBuilder()
.registerTypeAdapterFactory(new GsonJava8TypeAdapterFactory())
.registerTypeAdapter(Vertex.class, new ChampVertexSerializer())
.registerTypeAdapter(Edge.class, new ChampEdgeSerializer()).create();
+
+ public ChampDao() {
+ }
public ChampDao(String champUrl, String certPassword) {
try {
@@ -94,6 +97,13 @@ public class ChampDao implements GraphDao {
}
}
+ public ChampDao(RestClient client, String baseObjectUrl, String baseRelationshipUrl, String baseTransactionUrl) {
+ this.client = client;
+ this.baseObjectUrl = baseObjectUrl;
+ this.baseRelationshipUrl = baseRelationshipUrl;
+ this.baseTransactionUrl = baseTransactionUrl;
+ }
+
@Override
public Vertex getVertex(String id, String version) throws CrudException {
String url = baseObjectUrl + "/" + id;
diff --git a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
index 1163623..5ad4b7d 100644
--- a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
@@ -44,45 +44,44 @@ import org.onap.schema.RelationshipSchemaValidator;
import com.google.gson.JsonElement;
public abstract class AbstractGraphDataService {
+ protected GraphDao daoForGet;
protected GraphDao dao;
- public AbstractGraphDataService(GraphDao dao) throws CrudException {
- this.dao = dao;
-
+ public AbstractGraphDataService() throws CrudException {
CrudServiceUtil.loadModels();
}
public String getEdge(String version, String id, String type) throws CrudException {
RelationshipSchemaValidator.validateType(version, type);
- Edge edge = dao.getEdge(id, type);
+ Edge edge = daoForGet.getEdge(id, type);
return CrudResponseBuilder.buildGetEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, edge), version);
}
public String getEdges(String version, String type, Map<String, String> filter) throws CrudException {
RelationshipSchemaValidator.validateType(version, type);
- List<Edge> items = dao.getEdges(type, RelationshipSchemaValidator.resolveCollectionfilter(version, type, filter));
+ List<Edge> items = daoForGet.getEdges(type, RelationshipSchemaValidator.resolveCollectionfilter(version, type, filter));
return CrudResponseBuilder.buildGetEdgesResponse(items, version);
}
public String getVertex(String version, String id, String type) throws CrudException {
type = OxmModelValidator.resolveCollectionType(version, type);
- Vertex vertex = dao.getVertex(id, type, version);
- List<Edge> edges = dao.getVertexEdges(id);
+ Vertex vertex = daoForGet.getVertex(id, type, version);
+ List<Edge> edges = daoForGet.getVertexEdges(id);
return CrudResponseBuilder.buildGetVertexResponse(OxmModelValidator.validateOutgoingPayload(version, vertex), edges,
version);
}
public String getVertices(String version, String type, Map<String, String> filter, HashSet<String> properties) throws CrudException {
type = OxmModelValidator.resolveCollectionType(version, type);
- List<Vertex> items = dao.getVertices(type, OxmModelValidator.resolveCollectionfilter(version, type, filter), properties);
+ List<Vertex> items = daoForGet.getVertices(type, OxmModelValidator.resolveCollectionfilter(version, type, filter), properties);
return CrudResponseBuilder.buildGetVerticesResponse(items, version);
}
public String addBulk(String version, BulkPayload payload, HttpHeaders headers) throws CrudException {
HashMap<String, Vertex> vertices = new HashMap<String, Vertex>();
HashMap<String, Edge> edges = new HashMap<String, Edge>();
-
+
String txId = dao.openTransaction();
try {
@@ -269,4 +268,5 @@ public abstract class AbstractGraphDataService {
protected abstract Edge addBulkEdge(Edge edge, String version, String dbTransId) throws CrudException;
protected abstract Edge updateBulkEdge(Edge edge, String version, String dbTransId) throws CrudException;
protected abstract void deleteBulkEdge(String id, String version, String type, String dbTransId) throws CrudException;
+
}
diff --git a/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java b/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
index b3e7551..5e264b5 100644
--- a/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
@@ -84,12 +84,21 @@ public class CrudAsyncGraphDataService extends AbstractGraphDataService {
public static Integer getRequestTimeOut() {
return requestTimeOut;
}
+
+ public CrudAsyncGraphDataService(GraphDao dao,
+ EventPublisher asyncRequestPublisher,
+ EventConsumer asyncResponseConsumer) throws CrudException {
+ this(dao,dao,asyncRequestPublisher,asyncResponseConsumer);
+ }
public CrudAsyncGraphDataService(GraphDao dao,
+ GraphDao daoForGet,
EventPublisher asyncRequestPublisher,
EventConsumer asyncResponseConsumer) throws CrudException {
- super(dao);
+ super();
+ this.dao = dao;
+ this.daoForGet = daoForGet;
requestTimeOut = DEFAULT_REQUEST_TIMEOUT;
try {
@@ -443,5 +452,4 @@ public class CrudAsyncGraphDataService extends AbstractGraphDataService {
+ " , operation: " + event.getOperation().toString() + " , result: "
+ response.getResult() + " , error: " + response.getErrorMessage());
}
-
} \ No newline at end of file
diff --git a/src/main/java/org/onap/crud/service/CrudGraphDataService.java b/src/main/java/org/onap/crud/service/CrudGraphDataService.java
index 61550b2..3eeac3f 100644
--- a/src/main/java/org/onap/crud/service/CrudGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/CrudGraphDataService.java
@@ -35,9 +35,18 @@ import org.onap.schema.RelationshipSchemaValidator;
public class CrudGraphDataService extends AbstractGraphDataService {
-
+
+
public CrudGraphDataService(GraphDao dao) throws CrudException {
- super(dao);
+ super();
+ this.dao = dao;
+ this.daoForGet = dao;
+ }
+
+ public CrudGraphDataService(GraphDao dao, GraphDao daoForGet) throws CrudException {
+ super();
+ this.dao = dao;
+ this.daoForGet = daoForGet;
}
public String addVertex(String version, String type, VertexPayload payload) throws CrudException {
@@ -112,10 +121,6 @@ public class CrudGraphDataService extends AbstractGraphDataService {
}
- public Vertex getVertex(String id, String version) throws CrudException {
- return dao.getVertex(id, version);
- }
-
@Override
protected Vertex addBulkVertex(Vertex vertex, String version, String dbTransId) throws CrudException {
return dao.addVertex(vertex.getType(), vertex.getProperties(), version, dbTransId);
diff --git a/src/main/java/org/onap/crud/util/CrudServiceConstants.java b/src/main/java/org/onap/crud/util/CrudServiceConstants.java
index 262623c..bad5180 100644
--- a/src/main/java/org/onap/crud/util/CrudServiceConstants.java
+++ b/src/main/java/org/onap/crud/util/CrudServiceConstants.java
@@ -35,6 +35,7 @@ public class CrudServiceConstants {
public static final String CRD_HOME_AUTH = CRD_SPECIFIC_CONFIG + "auth" + CRD_FILESEP;
public static final String CRD_AUTH_FILE = CRD_HOME_AUTH + "crud_policy.json";
public static final String CRD_CHAMP_AUTH_FILE = CRD_HOME_AUTH + "champ-cert.p12";
+ public static final String CRD_DATAROUTER_AUTH_FILE = CRD_HOME_AUTH + "datalayer-client-cert.p12";
public static final String CRD_AUTH_POLICY_NAME = "crud";
public static final String CRD_ASYNC_REQUEST_TIMEOUT = "crud.async.request.timeout";
public static final String CRD_ASYNC_RESPONSE_PROCESS_POLL_INTERVAL = "crud.async.response.process.poll.interval";