aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/org')
-rw-r--r--common/src/main/java/org/onap/so/client/RestRequest.java6
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIClient.java9
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java99
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/AAIEdgeLabel.java21
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java28
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryEdgeLabel.java8
-rw-r--r--common/src/main/java/org/onap/so/client/graphinventory/entities/uri/HttpAwareUri.java9
7 files changed, 148 insertions, 32 deletions
diff --git a/common/src/main/java/org/onap/so/client/RestRequest.java b/common/src/main/java/org/onap/so/client/RestRequest.java
index 25bf54b643..985d7cc885 100644
--- a/common/src/main/java/org/onap/so/client/RestRequest.java
+++ b/common/src/main/java/org/onap/so/client/RestRequest.java
@@ -72,17 +72,13 @@ public class RestRequest implements Callable<Response> {
try {
mapper.get().map(response);
} catch (NotFoundException e) {
- if (this.client.props.mapNotFoundToEmpty()) {
+ if (this.client.props.mapNotFoundToEmpty() && "GET".equals(method)) {
msoLogger.error(e);
return response;
} else {
throw e;
}
}
- } else {
- if (response.getStatus() == Status.NOT_FOUND.getStatusCode() && this.client.props.mapNotFoundToEmpty()) {
- return response;
- }
}
return response;
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIClient.java b/common/src/main/java/org/onap/so/client/aai/AAIClient.java
index 39843b2263..3d2410e2a2 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIClient.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIClient.java
@@ -22,11 +22,13 @@ package org.onap.so.client.aai;
import java.net.URI;
+import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.UriBuilder;
import org.onap.so.client.RestClient;
import org.onap.so.client.graphinventory.GraphInventoryClient;
import org.onap.so.client.graphinventory.entities.uri.GraphInventoryUri;
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,7 +51,12 @@ public abstract class AAIClient extends GraphInventoryClient {
}
@Override
protected RestClient createClient(GraphInventoryUri uri) {
- return new AAIRestClient(getRestProperties(), constructPath(uri));
+ try {
+ return new AAIRestClient(getRestProperties(), constructPath(uri));
+ } catch (GraphInventoryUriComputationException | NotFoundException e) {
+ logger.debug("failed to construct A&AI uri", e);
+ throw e;
+ }
}
protected AAIVersion getVersion() {
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java
index 04757c6fc2..072534d6f6 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java
@@ -32,6 +32,7 @@ import javax.ws.rs.core.Response.Status;
import org.onap.aai.domain.yang.Relationship;
import org.onap.so.client.RestClient;
import org.onap.so.client.RestProperties;
+import org.onap.so.client.aai.entities.AAIEdgeLabel;
import org.onap.so.client.aai.entities.AAIResultWrapper;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUri;
@@ -81,9 +82,13 @@ public class AAIResourcesClient extends AAIClient {
*/
public boolean exists(AAIResourceUri uri) {
AAIUri forceMinimal = this.addParams(Optional.of(Depth.ZERO), true, uri);
- RestClient aaiRC = this.createClient(forceMinimal);
-
- return aaiRC.get().getStatus() == Status.OK.getStatusCode();
+ try {
+ RestClient aaiRC = this.createClient(forceMinimal);
+
+ return aaiRC.get().getStatus() == Status.OK.getStatusCode();
+ } catch (NotFoundException e) {
+ return false;
+ }
}
/**
@@ -100,6 +105,21 @@ public class AAIResourcesClient extends AAIClient {
}
/**
+ * Adds a relationship between two objects in A&AI
+ * with a given edge label
+ * @param uriA
+ * @param uriB
+ * @param edge label
+ * @return
+ */
+ public void connect(AAIResourceUri uriA, AAIResourceUri uriB, AAIEdgeLabel label) {
+ AAIResourceUri uriAClone = uriA.clone();
+ RestClient aaiRC = this.createClient(uriAClone.relationshipAPI());
+ aaiRC.put(this.buildRelationship(uriB, label));
+ return;
+ }
+
+ /**
* Removes relationship from two objects in A&AI
*
* @param uriA
@@ -148,7 +168,15 @@ public class AAIResourcesClient extends AAIClient {
* @return
*/
public <T> Optional<T> get(Class<T> clazz, AAIResourceUri uri) {
- return this.createClient(uri).get(clazz);
+ try {
+ return this.createClient(uri).get(clazz);
+ } catch (NotFoundException e) {
+ if (this.getRestProperties().mapNotFoundToEmpty()) {
+ return Optional.empty();
+ } else {
+ throw e;
+ }
+ }
}
/**
@@ -157,7 +185,15 @@ public class AAIResourcesClient extends AAIClient {
* @return
*/
public Response getFullResponse(AAIResourceUri uri) {
- return this.createClient(uri).get();
+ try {
+ return this.createClient(uri).get();
+ } catch (NotFoundException e) {
+ if (this.getRestProperties().mapNotFoundToEmpty()) {
+ return e.getResponse();
+ } else {
+ throw e;
+ }
+ }
}
/**
@@ -167,7 +203,15 @@ public class AAIResourcesClient extends AAIClient {
* @return
*/
public <T> Optional<T> get(GenericType<T> resultClass, AAIResourceUri uri) {
- return this.createClient(uri).get(resultClass);
+ try {
+ return this.createClient(uri).get(resultClass);
+ } catch (NotFoundException e) {
+ if (this.getRestProperties().mapNotFoundToEmpty()) {
+ return Optional.empty();
+ } else {
+ throw e;
+ }
+ }
}
/**
@@ -177,7 +221,16 @@ public class AAIResourcesClient extends AAIClient {
* @return
*/
public AAIResultWrapper get(AAIResourceUri uri) {
- String json = this.createClient(uri).get(String.class).orElse(null);
+ String json;
+ try {
+ json = this.createClient(uri).get(String.class).orElse(null);
+ } catch (NotFoundException e) {
+ if (this.getRestProperties().mapNotFoundToEmpty()) {
+ json = null;
+ } else {
+ throw e;
+ }
+ }
return new AAIResultWrapper(json);
}
@@ -189,22 +242,42 @@ public class AAIResourcesClient extends AAIClient {
* @return
*/
public AAIResultWrapper get(AAIResourceUri uri, Class<? extends RuntimeException> c) {
-
+ String json;
+ try {
+ json = this.createClient(uri).get(String.class)
+ .orElseThrow(() -> createException(c, uri.build() + " not found in A&AI"));
+ } catch (NotFoundException e) {
+ throw createException(c, "could not construct uri for use with A&AI");
+ }
+
+ return new AAIResultWrapper(json);
+ }
+
+ private RuntimeException createException(Class<? extends RuntimeException> c, String message) {
RuntimeException e;
try {
- e = c.getConstructor(String.class).newInstance(uri.build() + " not found in A&AI");
+ e = c.getConstructor(String.class).newInstance(message);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| NoSuchMethodException | SecurityException e1) {
throw new IllegalArgumentException("could not create instance for " + c.getName());
}
- String json = this.createClient(uri).get(String.class)
- .orElseThrow(() -> e);
- return new AAIResultWrapper(json);
+
+ return e;
}
private Relationship buildRelationship(AAIResourceUri uri) {
+ return buildRelationship(uri, Optional.empty());
+ }
+
+ private Relationship buildRelationship(AAIResourceUri uri, AAIEdgeLabel label) {
+ return buildRelationship(uri, Optional.of(label));
+ }
+ private Relationship buildRelationship(AAIResourceUri uri, Optional<AAIEdgeLabel> label) {
final Relationship result = new Relationship();
result.setRelatedLink(uri.build().toString());
+ if (label.isPresent()) {
+ result.setRelationshipLabel(label.toString());
+ }
return result;
}
@@ -248,7 +321,7 @@ public class AAIResourcesClient extends AAIClient {
return clone;
}
@Override
- protected <T extends RestProperties> T getRestProperties() {
+ public <T extends RestProperties> T getRestProperties() {
return super.getRestProperties();
}
}
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/AAIEdgeLabel.java b/common/src/main/java/org/onap/so/client/aai/entities/AAIEdgeLabel.java
new file mode 100644
index 0000000000..0356e86861
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/aai/entities/AAIEdgeLabel.java
@@ -0,0 +1,21 @@
+package org.onap.so.client.aai.entities;
+
+import org.onap.so.client.graphinventory.entities.GraphInventoryEdgeLabel;
+
+public enum AAIEdgeLabel implements GraphInventoryEdgeLabel {
+
+ BELONGS_TO("org.onap.relationships.inventory.BelongsTo"),
+ USES("org.onap.relationships.inventory.Uses");
+
+
+ private final String label;
+ private AAIEdgeLabel(String label) {
+ this.label = label;
+ }
+
+
+ @Override
+ public String toString() {
+ return this.label;
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java b/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java
index 093918d49b..a132e15d1f 100644
--- a/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java
+++ b/common/src/main/java/org/onap/so/client/aai/entities/uri/ServiceInstanceUri.java
@@ -22,19 +22,19 @@ package org.onap.so.client.aai.entities.uri;
import java.io.IOException;
import java.net.URI;
-import java.util.Collections;
+import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import javax.ws.rs.BadRequestException;
+import javax.ws.rs.NotFoundException;
import javax.ws.rs.core.UriBuilder;
import org.onap.so.client.aai.AAIObjectType;
-import org.onap.so.client.aai.AAIQueryClient;
-import org.onap.so.client.graphinventory.Format;
-import org.onap.so.client.aai.entities.CustomQuery;
+import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.Results;
-import org.onap.so.client.graphinventory.entities.uri.SimpleUri;
+import org.onap.so.client.graphinventory.Format;
+import org.onap.so.client.graphinventory.entities.uri.HttpAwareUri;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException;
import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException;
@@ -42,7 +42,7 @@ import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundExc
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-public class ServiceInstanceUri extends AAISimpleUri {
+public class ServiceInstanceUri extends AAISimpleUri implements HttpAwareUri {
private Optional<String> cachedValue = Optional.empty();
@@ -55,11 +55,10 @@ public class ServiceInstanceUri extends AAISimpleUri {
}
protected String getSerivceInstance(Object id) throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
if (!this.getCachedValue().isPresent()) {
- AAIResourceUri serviceInstanceUri = AAIUriFactory.createNodesUri(AAIObjectType.SERVICE_INSTANCE, id);
- CustomQuery query = new CustomQuery(Collections.singletonList(serviceInstanceUri));
+ AAIResourceUri serviceInstanceUri = AAIUriFactory.createNodesUri(AAIObjectType.SERVICE_INSTANCE, id).format(Format.PATHED);
String resultJson;
try {
- resultJson = this.getQueryClient().query(Format.PATHED, query);
+ resultJson = this.getResourcesClient().get(serviceInstanceUri, NotFoundException.class).getJson();
} catch (BadRequestException e) {
throw new GraphInventoryUriNotFoundException("Service instance " + id + " not found at: " + serviceInstanceUri.build());
@@ -99,7 +98,7 @@ public class ServiceInstanceUri extends AAISimpleUri {
protected Optional<String> getCachedValue() {
return this.cachedValue;
}
-
+
@Override
public URI build() {
try {
@@ -119,8 +118,11 @@ public class ServiceInstanceUri extends AAISimpleUri {
return new ServiceInstanceUri(this.internalURI.clone(), this.getCachedValue(), values);
}
- protected AAIQueryClient getQueryClient() {
- AAIResourceUri uri = AAIUriFactory.createNodesUri(AAIObjectType.ALLOTTED_RESOURCE, "").clone();
- return new AAIQueryClient();
+ public AAIResourcesClient getResourcesClient() {
+ return new AAIResourcesClient();
+ }
+ @Override
+ public URI buildNoNetwork() {
+ return super.build(new String[]{"NONE", "NONE", (String)this.values[0]});
}
}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryEdgeLabel.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryEdgeLabel.java
new file mode 100644
index 0000000000..1ede2f9e1b
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/GraphInventoryEdgeLabel.java
@@ -0,0 +1,8 @@
+package org.onap.so.client.graphinventory.entities;
+
+public interface GraphInventoryEdgeLabel {
+
+
+ @Override
+ public String toString();
+}
diff --git a/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/HttpAwareUri.java b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/HttpAwareUri.java
new file mode 100644
index 0000000000..145959dc73
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/graphinventory/entities/uri/HttpAwareUri.java
@@ -0,0 +1,9 @@
+package org.onap.so.client.graphinventory.entities.uri;
+
+import java.net.URI;
+
+public interface HttpAwareUri {
+
+
+ public URI buildNoNetwork();
+}