summaryrefslogtreecommitdiffstats
path: root/common/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main')
-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.java73
-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/uri/HttpAwareUri.java9
5 files changed, 93 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..c8801eb00f 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
@@ -81,9 +81,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;
+ }
}
/**
@@ -148,7 +152,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 +169,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 +187,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 +205,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,17 +226,27 @@ 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) {
@@ -248,7 +295,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/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/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();
+}