summaryrefslogtreecommitdiffstats
path: root/common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java')
-rw-r--r--common/src/main/java/org/onap/so/client/RestClient.java2
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java3
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIObjectType.java3
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIPatchConverter.java81
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java9
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIRestClient.java53
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAISingleTransactionClient.java267
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java39
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/bulkprocess/OperationBody.java3
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/bulkprocess/OperationBodySerializer.java54
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyRequest.java88
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyRequestSerializer.java54
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyResponse.java71
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/singletransaction/SingleTransactionRequest.java45
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/singletransaction/SingleTransactionResponse.java47
-rw-r--r--common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java21
16 files changed, 784 insertions, 56 deletions
diff --git a/common/src/main/java/org/onap/so/client/RestClient.java b/common/src/main/java/org/onap/so/client/RestClient.java
index 631850a01f..1a453c6b2f 100644
--- a/common/src/main/java/org/onap/so/client/RestClient.java
+++ b/common/src/main/java/org/onap/so/client/RestClient.java
@@ -271,7 +271,7 @@ public abstract class RestClient {
return format(method("DELETE", obj), resultClass).orElse(null);
}
- private Response method(String method, Object entity) {
+ public Response method(String method, Object entity) {
RetryPolicy policy = new RetryPolicy();
List<Predicate<Throwable>> items = retryOn();
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java
index c50653a203..553c1e0db0 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectPlurals.java
@@ -33,7 +33,8 @@ public enum AAIObjectPlurals implements GraphInventoryObjectPlurals {
SERVICE_SUBSCRIPTION(AAIObjectType.CUSTOMER.uriTemplate(), "/service-subscriptions"),
SERVICE_INSTANCE(AAIObjectType.SERVICE_SUBSCRIPTION.uriTemplate(), "/service-instances"),
OWNING_ENTITIES(AAINamespaceConstants.BUSINESS, "/owning-entities"),
- VOLUME_GROUP(AAIObjectType.CLOUD_REGION.uriTemplate(), "/volume-groups/");
+ VOLUME_GROUP(AAIObjectType.CLOUD_REGION.uriTemplate(), "/volume-groups/"),
+ AVAILIBILITY_ZONE(AAIObjectType.CLOUD_REGION.uriTemplate(), "/availability-zones/");
private final String uriTemplate;
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
index a5d8f12e83..4b646f9ed7 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
@@ -27,6 +27,7 @@ import org.onap.aai.annotations.Metadata;
import org.onap.aai.domain.yang.AllottedResource;
import org.onap.aai.domain.yang.CloudRegion;
import org.onap.aai.domain.yang.Collection;
+import org.onap.aai.domain.yang.Complex;
import org.onap.aai.domain.yang.Configuration;
import org.onap.aai.domain.yang.Customer;
import org.onap.aai.domain.yang.GenericVnf;
@@ -64,6 +65,7 @@ public enum AAIObjectType implements GraphInventoryObjectType {
CUSTOMER(AAINamespaceConstants.BUSINESS, Customer.class),
GENERIC_QUERY("/search", "/generic-query"),
BULK_PROCESS("/bulkprocess", ""),
+ SINGLE_TRANSACTION("/bulk/single-transaction", ""),
GENERIC_VNF(AAINamespaceConstants.NETWORK, GenericVnf.class),
VF_MODULE(AAIObjectType.GENERIC_VNF.uriTemplate(), VfModule.class),
L3_NETWORK(AAINamespaceConstants.NETWORK, L3Network.class),
@@ -98,6 +100,7 @@ public enum AAIObjectType implements GraphInventoryObjectType {
COLLECTION(AAINamespaceConstants.NETWORK, Collection.class),
VNFC(AAINamespaceConstants.NETWORK, Vnfc.class),
VLAN_TAG(AAINamespaceConstants.NETWORK, VlanTag.class),
+ COMPLEX(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, Complex.class),
UNKNOWN("", "");
private final String uriTemplate;
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIPatchConverter.java b/common/src/main/java/org/onap/so/client/aai/AAIPatchConverter.java
new file mode 100644
index 0000000000..6ccb592409
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/aai/AAIPatchConverter.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.onap.so.client.aai;
+
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import org.onap.so.client.graphinventory.exceptions.GraphInventoryPatchDepthExceededException;
+import org.onap.so.jsonpath.JsonPathUtil;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class AAIPatchConverter {
+
+ private static final AAICommonObjectMapperProvider standardProvider = new AAICommonObjectMapperProvider();
+ private static final AAICommonObjectMapperPatchProvider patchProvider = new AAICommonObjectMapperPatchProvider();
+ private static final Pattern LOCATE_COMPLEX_OBJECT = Pattern.compile("^((?!relationship-list).)+?\\['[^\\[\\]]+?'\\]$");
+
+
+ protected String convertPatchFormat(Object obj) {
+ return validatePatchObject(marshallObjectToPatchFormat(obj));
+ }
+
+ protected String validatePatchObject(String payload) {
+ if (hasComplexObject(payload)) {
+ throw new GraphInventoryPatchDepthExceededException(payload);
+ }
+
+ return payload;
+ }
+
+ /** validates client side that json does not include any complex objects
+ * relationship-list is omitted from this validation
+ */
+ protected boolean hasComplexObject(String json) {
+ if (json.isEmpty()) {
+ return false;
+ }
+ String complex = "$.*.*";
+ String array = "$.*.*.*";
+ List<String> result = JsonPathUtil.getInstance().getPathList(json, complex);
+ List<String> result2 = JsonPathUtil.getInstance().getPathList(json, array);
+
+ result.addAll(result2);
+ return result.stream().anyMatch(item -> LOCATE_COMPLEX_OBJECT.matcher(item).find());
+ }
+
+ protected String marshallObjectToPatchFormat(Object obj) {
+ Object value = obj;
+ try {
+ if (!(obj instanceof Map || obj instanceof String)) {
+ value = patchProvider.getMapper().writeValueAsString(obj);
+ } else if (obj instanceof Map) {
+ value = standardProvider.getMapper().writeValueAsString(obj);
+ }
+ } catch (JsonProcessingException e) {
+ value = "{}";
+ }
+
+ return (String)value;
+ }
+}
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 072534d6f6..7e4397ec29 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
@@ -309,6 +309,15 @@ public class AAIResourcesClient extends AAIClient {
return new AAITransactionalClient(this.getVersion());
}
+ /**
+ * Starts a transaction groups multiple A&AI mutations
+ *
+ * @return
+ */
+ public AAISingleTransactionClient beginSingleTransaction() {
+ return new AAISingleTransactionClient(this.getVersion());
+ }
+
private AAIUri addParams(Optional<Depth> depth, boolean nodesOnly, AAIUri uri) {
AAIUri clone = uri.clone();
if (depth.isPresent()) {
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java b/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java
index 2bd5f118c0..ac6e939e9e 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIRestClient.java
@@ -20,6 +20,8 @@
package org.onap.so.client.aai;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+
import java.net.URI;
import java.util.List;
import java.util.Map;
@@ -41,9 +43,9 @@ public class AAIRestClient extends RestClientSSL {
private final AAIProperties aaiProperties;
private static final AAICommonObjectMapperProvider standardProvider = new AAICommonObjectMapperProvider();
- private static final AAICommonObjectMapperPatchProvider patchProvider = new AAICommonObjectMapperPatchProvider();
- private static final Pattern LOCATE_COMPLEX_OBJECT = Pattern.compile("^((?!relationship-list).)+?\\['[^\\[\\]]+?'\\]$");
+ private final AAIPatchConverter patchConverter = new AAIPatchConverter();
+
protected AAIRestClient(AAIProperties props, URI uri) {
super(props, Optional.of(uri));
this.aaiProperties = props;
@@ -79,53 +81,20 @@ public class AAIRestClient extends RestClientSSL {
@Override
public Response patch(Object obj) {
- String value = convertObjectToPatchFormat(obj);
- validatePatchObject(value);
- return super.patch(value);
+ return super.patch(convertToPatchFormat(obj));
}
@Override
public <T> T patch(Object obj, Class<T> resultClass) {
- String value = convertObjectToPatchFormat(obj);
- validatePatchObject(value);
- return super.patch(value, resultClass);
+ return super.patch(convertToPatchFormat(obj), resultClass);
}
- protected String convertObjectToPatchFormat(Object obj) {
- Object value = obj;
- try {
- if (!(obj instanceof Map || obj instanceof String)) {
- value = patchProvider.getMapper().writeValueAsString(obj);
- } else if (obj instanceof Map) {
- value = standardProvider.getMapper().writeValueAsString(obj);
- }
- } catch (JsonProcessingException e) {
- value = "{}";
- }
-
- return (String)value;
+ protected AAIPatchConverter getPatchConverter() {
+ return this.patchConverter;
}
-
- protected void validatePatchObject(String payload) {
- if (hasComplexObject(payload)) {
- throw new GraphInventoryPatchDepthExceededException(payload);
- }
- }
-
- /** validates client side that json does not include any complex objects
- * relationship-list is omitted from this validation
- */
- protected boolean hasComplexObject(String json) {
- if (json.isEmpty()) {
- return false;
- }
- String complex = "$.*.*";
- String array = "$.*.*.*";
- List<String> result = JsonPathUtil.getInstance().getPathList(json, complex);
- List<String> result2 = JsonPathUtil.getInstance().getPathList(json, array);
-
- result.addAll(result2);
- return result.stream().anyMatch(item -> LOCATE_COMPLEX_OBJECT.matcher(item).find());
+ protected String convertToPatchFormat(Object obj) {
+ return getPatchConverter().convertPatchFormat(obj);
}
+
}
diff --git a/common/src/main/java/org/onap/so/client/aai/AAISingleTransactionClient.java b/common/src/main/java/org/onap/so/client/aai/AAISingleTransactionClient.java
new file mode 100644
index 0000000000..2ecdb7c480
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/aai/AAISingleTransactionClient.java
@@ -0,0 +1,267 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.onap.so.client.aai;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.core.GenericType;
+
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.so.client.RestClient;
+import org.onap.so.client.aai.entities.AAIEdgeLabel;
+import org.onap.so.client.aai.entities.AAIError;
+import org.onap.so.client.aai.entities.bulkprocess.Transactions;
+import org.onap.so.client.aai.entities.singletransaction.OperationBodyRequest;
+import org.onap.so.client.aai.entities.singletransaction.OperationBodyResponse;
+import org.onap.so.client.aai.entities.singletransaction.SingleTransactionRequest;
+import org.onap.so.client.aai.entities.singletransaction.SingleTransactionResponse;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Joiner;
+
+public class AAISingleTransactionClient extends AAIClient {
+
+ private final SingleTransactionRequest request;
+ private final AAIVersion version;
+ private int actionCount = 0;
+
+ private final AAIPatchConverter patchConverter = new AAIPatchConverter();
+
+ protected AAISingleTransactionClient(AAIVersion version) {
+ super();
+ this.version = version;
+ this.request = new SingleTransactionRequest();
+ }
+
+ /**
+ * creates a new object in A&AI
+ *
+ * @param obj - can be any object which will marshal into a valid A&AI payload
+ * @param uri
+ * @return
+ */
+ public AAISingleTransactionClient create(AAIResourceUri uri, Object obj) {
+ request.getOperations().add(new OperationBodyRequest().withAction("put").withUri(uri.build().toString()).withBody(obj));
+ incrementActionAmount();
+ return this;
+ }
+
+ /**
+ * creates a new object in A&AI with no payload body
+ *
+ * @param uri
+ * @return
+ */
+ public AAISingleTransactionClient createEmpty(AAIResourceUri uri) {
+ request.getOperations().add(new OperationBodyRequest().withAction("put").withUri(uri.build().toString()).withBody(new HashMap<String, String>()));
+ incrementActionAmount();
+ return this;
+ }
+
+ /**
+ * Adds a relationship between two objects in A&AI
+ * @param uriA
+ * @param uriB
+ * @return
+ */
+ public AAISingleTransactionClient connect(AAIResourceUri uriA, AAIResourceUri uriB) {
+ AAIResourceUri uriAClone = uriA.clone();
+ request.getOperations().add(new OperationBodyRequest().withAction("put").withUri(uriAClone.relationshipAPI().build().toString()).withBody(this.buildRelationship(uriB)));
+ incrementActionAmount();
+ return this;
+ }
+
+ /**
+ * relationship between multiple objects in A&AI - connects A to all objects specified in list
+ *
+ * @param uriA
+ * @param uris
+ * @return
+ */
+ public AAISingleTransactionClient connect(AAIResourceUri uriA, List<AAIResourceUri> uris) {
+ for (AAIResourceUri uri : uris) {
+ this.connect(uriA, uri);
+ }
+ return this;
+ }
+
+ public AAISingleTransactionClient connect(AAIResourceUri uriA, AAIResourceUri uriB, AAIEdgeLabel label) {
+ AAIResourceUri uriAClone = uriA.clone();
+ RestClient aaiRC = this.createClient(uriAClone.relationshipAPI());
+ aaiRC.put(this.buildRelationship(uriB, label));
+ return this;
+ }
+
+ public AAISingleTransactionClient connect(AAIResourceUri uriA, List<AAIResourceUri> uris, AAIEdgeLabel label) {
+ for (AAIResourceUri uri : uris) {
+ this.connect(uriA, uri, label);
+ }
+ return this;
+ }
+
+ /**
+ * Removes relationship from two objects in A&AI
+ *
+ * @param uriA
+ * @param uriB
+ * @return
+ */
+ public AAISingleTransactionClient disconnect(AAIResourceUri uriA, AAIResourceUri uriB) {
+ AAIResourceUri uriAClone = uriA.clone();
+ request.getOperations().add(new OperationBodyRequest().withAction("delete").withUri(uriAClone.relationshipAPI().build().toString()).withBody(this.buildRelationship(uriB)));
+ incrementActionAmount();
+ return this;
+ }
+
+ /**
+ * Removes relationship from multiple objects - disconnects A from all objects specified in list
+ * @param uriA
+ * @param uris
+ * @return
+ */
+ public AAISingleTransactionClient disconnect(AAIResourceUri uriA, List<AAIResourceUri> uris) {
+ for (AAIResourceUri uri : uris) {
+ this.disconnect(uriA, uri);
+ }
+ return this;
+ }
+ /**
+ * Deletes object from A&AI. Automatically handles resource-version.
+ *
+ * @param uri
+ * @return
+ */
+ public AAISingleTransactionClient delete(AAIResourceUri uri) {
+ AAIResourcesClient client = new AAIResourcesClient();
+ AAIResourceUri clone = uri.clone();
+ Map<String, Object> result = client.get(new GenericType<Map<String, Object>>(){}, clone)
+ .orElseThrow(() -> new NotFoundException(clone.build() + " does not exist in A&AI"));
+ String resourceVersion = (String) result.get("resource-version");
+ request.getOperations().add(new OperationBodyRequest().withAction("delete").withUri(clone.resourceVersion(resourceVersion).build().toString()).withBody(""));
+ incrementActionAmount();
+ return this;
+ }
+
+ /**
+ * @param obj - can be any object which will marshal into a valid A&AI payload
+ * @param uri
+ * @return
+ */
+ public AAISingleTransactionClient update(AAIResourceUri uri, Object obj) {
+
+ final String payload = getPatchConverter().convertPatchFormat(obj);
+ request.getOperations().add(new OperationBodyRequest().withAction("patch").withUri(uri.build().toString()).withBody(payload));
+ incrementActionAmount();
+ return this;
+ }
+
+ private void incrementActionAmount() {
+ actionCount++;
+ }
+ /**
+ * Executes all created transactions in A&AI
+ * @throws BulkProcessFailed
+ */
+ public void execute() throws BulkProcessFailed {
+ RestClient client = this.createClient(AAIUriFactory.createResourceUri(AAIObjectType.SINGLE_TRANSACTION));
+ try {
+ SingleTransactionResponse response = client.post(this.request, SingleTransactionResponse.class);
+ if (response != null) {
+ final Optional<String> errorMessage = this.locateErrorMessages(response);
+ if (errorMessage.isPresent()) {
+ throw new BulkProcessFailed("One or more transactions failed in A&AI. Check logs for payloads.\nMessages:\n" + errorMessage.get());
+ }
+ } else {
+ throw new BulkProcessFailed("Transactions acccepted by A&AI, but there was no response. Unsure of result.");
+ }
+ } finally {
+ this.request.getOperations().clear();
+ this.actionCount = 0;
+ }
+ }
+
+ protected Optional<String> locateErrorMessages(SingleTransactionResponse response) {
+ final List<String> errorMessages = new ArrayList<>();
+ final ObjectMapper mapper = new ObjectMapper();
+
+ for (OperationBodyResponse body : response.getOperationResponses()) {
+ if (Optional.ofNullable(body.getResponseStatusCode()).orElse(400) > 300) {
+ AAIError error;
+ try {
+ error = mapper.readValue(mapper.writeValueAsString(body.getResponseBody()), AAIError.class);
+ } catch (IOException e) {
+ logger.error("could not parse error object from A&AI", e);
+ error = new AAIError();
+ }
+ AAIErrorFormatter formatter = new AAIErrorFormatter(error);
+ String outputMessage = formatter.getMessage();
+ errorMessages.add(outputMessage);
+ }
+ }
+
+ if (!errorMessages.isEmpty()) {
+ return Optional.of(Joiner.on("\n").join(errorMessages));
+ } else {
+ return Optional.empty();
+ }
+ }
+
+ 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;
+ }
+
+ @Override
+ protected AAIVersion getVersion() {
+ return this.version;
+ }
+
+ protected SingleTransactionRequest getRequest() {
+ return this.request;
+ }
+
+ protected AAIPatchConverter getPatchConverter() {
+ return this.patchConverter;
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java b/common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java
index 884d2aaec6..118a3edf1c 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAITransactionalClient.java
@@ -20,6 +20,8 @@
package org.onap.so.client.aai;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -34,6 +36,7 @@ import javax.ws.rs.core.Response;
import org.onap.aai.domain.yang.Relationship;
import org.onap.so.client.RestClient;
+import org.onap.so.client.aai.entities.AAIEdgeLabel;
import org.onap.so.client.aai.entities.AAIError;
import org.onap.so.client.aai.entities.bulkprocess.OperationBody;
import org.onap.so.client.aai.entities.bulkprocess.Transaction;
@@ -54,6 +57,9 @@ public class AAITransactionalClient extends AAIClient {
private Transaction currentTransaction;
private final AAIVersion version;
private int actionCount = 0;
+
+ private final AAIPatchConverter patchConverter = new AAIPatchConverter();
+
protected AAITransactionalClient(AAIVersion version) {
super();
this.version = version;
@@ -129,6 +135,20 @@ public class AAITransactionalClient extends AAIClient {
return this;
}
+ public AAITransactionalClient connect(AAIResourceUri uriA, AAIResourceUri uriB, AAIEdgeLabel label) {
+ AAIResourceUri uriAClone = uriA.clone();
+ RestClient aaiRC = this.createClient(uriAClone.relationshipAPI());
+ aaiRC.put(this.buildRelationship(uriB, label));
+ return this;
+ }
+
+ public AAITransactionalClient connect(AAIResourceUri uriA, List<AAIResourceUri> uris, AAIEdgeLabel label) {
+ for (AAIResourceUri uri : uris) {
+ this.connect(uriA, uri, label);
+ }
+ return this;
+ }
+
/**
* Removes relationship from two objects in A&AI
*
@@ -178,7 +198,8 @@ public class AAITransactionalClient extends AAIClient {
* @return
*/
public AAITransactionalClient update(AAIResourceUri uri, Object obj) {
- currentTransaction.getPatch().add(new OperationBody().withUri(uri.build().toString()).withBody(obj));
+ final String payload = getPatchConverter().convertPatchFormat(obj);
+ currentTransaction.getPatch().add(new OperationBody().withUri(uri.build().toString()).withBody(payload));
incrementActionAmount();
return this;
}
@@ -247,9 +268,19 @@ public class AAITransactionalClient extends AAIClient {
return Optional.empty();
}
}
- private Relationship buildRelationship(AAIUri uri) {
+ 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;
}
@@ -261,4 +292,8 @@ public class AAITransactionalClient extends AAIClient {
protected Transactions getTransactions() {
return this.transactions;
}
+
+ protected AAIPatchConverter getPatchConverter() {
+ return this.patchConverter;
+ }
}
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/bulkprocess/OperationBody.java b/common/src/main/java/org/onap/so/client/aai/entities/bulkprocess/OperationBody.java
index 1803440edd..4b2aac1364 100644
--- a/common/src/main/java/org/onap/so/client/aai/entities/bulkprocess/OperationBody.java
+++ b/common/src/main/java/org/onap/so/client/aai/entities/bulkprocess/OperationBody.java
@@ -23,6 +23,8 @@ package org.onap.so.client.aai.entities.bulkprocess;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.annotation.JsonRawValue;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({
@@ -34,6 +36,7 @@ public class OperationBody {
@JsonProperty("uri")
private String uri;
@JsonProperty("body")
+@JsonSerialize(using = OperationBodySerializer.class)
private Object body;
@JsonProperty("uri")
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/bulkprocess/OperationBodySerializer.java b/common/src/main/java/org/onap/so/client/aai/entities/bulkprocess/OperationBodySerializer.java
new file mode 100644
index 0000000000..2981e0deef
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/aai/entities/bulkprocess/OperationBodySerializer.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.onap.so.client.aai.entities.bulkprocess;
+
+import java.io.IOException;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+
+public class OperationBodySerializer extends StdSerializer<Object> {
+
+ private static final long serialVersionUID = 5367385969270400106L;
+
+ public OperationBodySerializer() {
+ this(null);
+ }
+ public OperationBodySerializer(Class<Object> t) {
+ super(t);
+ }
+
+ @Override
+ public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers)
+ throws IOException, JsonProcessingException {
+
+ if (value instanceof String) {
+ gen.writeRawValue((String)value);
+ } else {
+ gen.writeObject(value);
+ }
+
+ }
+
+}
+
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyRequest.java b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyRequest.java
new file mode 100644
index 0000000000..f2626e9e43
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyRequest.java
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * 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.onap.so.client.aai.entities.singletransaction;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.annotation.JsonRawValue;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({
+"action",
+"uri",
+"body"
+})
+public class OperationBodyRequest {
+
+@JsonProperty("action")
+private String action;
+@JsonProperty("uri")
+private String uri;
+@JsonProperty("body")
+@JsonSerialize(using = OperationBodyRequestSerializer.class)
+private Object body;
+
+
+public String getAction() {
+ return action;
+}
+
+public void setAction(String action) {
+ this.action = action;
+}
+
+public OperationBodyRequest withAction(String action) {
+ this.action = action;
+ return this;
+}
+@JsonProperty("uri")
+public String getUri() {
+return uri;
+}
+
+@JsonProperty("uri")
+public void setUri(String uri) {
+this.uri = uri;
+}
+
+public OperationBodyRequest withUri(String uri) {
+this.uri = uri;
+return this;
+}
+
+@JsonProperty("body")
+public Object getBody() {
+return body;
+}
+
+@JsonProperty("body")
+public void setBody(Object body) {
+this.body = body;
+}
+
+public OperationBodyRequest withBody(Object body) {
+this.body = body;
+return this;
+}
+
+}
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyRequestSerializer.java b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyRequestSerializer.java
new file mode 100644
index 0000000000..170719962e
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyRequestSerializer.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.onap.so.client.aai.entities.singletransaction;
+
+import java.io.IOException;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+
+public class OperationBodyRequestSerializer extends StdSerializer<Object> {
+
+ private static final long serialVersionUID = 5367385969270400106L;
+
+ public OperationBodyRequestSerializer() {
+ this(null);
+ }
+ public OperationBodyRequestSerializer(Class<Object> t) {
+ super(t);
+ }
+
+ @Override
+ public void serialize(Object value, JsonGenerator gen, SerializerProvider serializers)
+ throws IOException, JsonProcessingException {
+
+ if (value instanceof String) {
+ gen.writeRawValue((String)value);
+ } else {
+ gen.writeObject(value);
+ }
+
+ }
+
+}
+
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyResponse.java b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyResponse.java
new file mode 100644
index 0000000000..71f65b50db
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/OperationBodyResponse.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.onap.so.client.aai.entities.singletransaction;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
+@JsonPropertyOrder({
+"action",
+"uri",
+"response-status-code",
+"response-body"
+})
+public class OperationBodyResponse {
+
+ @JsonProperty("action")
+ public String action;
+ @JsonProperty("uri")
+ public String uri;
+ @JsonProperty("response-status-code")
+ public Integer responseStatusCode;
+ @JsonProperty("response-body")
+ public Object responseBody;
+
+ public String getAction() {
+ return action;
+ }
+ public void setAction(String action) {
+ this.action = action;
+ }
+ public String getUri() {
+ return uri;
+ }
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+ @JsonProperty("response-status-code")
+ public Integer getResponseStatusCode() {
+ return responseStatusCode;
+ }
+ @JsonProperty("response-status-code")
+ public void setResponseStatusCode(Integer responseStatusCode) {
+ this.responseStatusCode = responseStatusCode;
+ }
+ @JsonProperty("response-body")
+ public Object getResponseBody() {
+ return responseBody;
+ }
+ @JsonProperty("response-body")
+ public void getResponseBody(Object responseBody) {
+ this.responseBody = responseBody;
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/SingleTransactionRequest.java b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/SingleTransactionRequest.java
new file mode 100644
index 0000000000..0d392c453f
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/SingleTransactionRequest.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.onap.so.client.aai.entities.singletransaction;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class SingleTransactionRequest {
+
+ @JsonProperty("operations")
+ public List<OperationBodyRequest> operations;
+
+ public List<OperationBodyRequest> getOperations() {
+
+ if (operations == null) {
+ operations = new ArrayList<>();
+ }
+
+ return operations;
+ }
+
+ public void setOperations(List<OperationBodyRequest> operations) {
+ this.operations = operations;
+ }
+}
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/SingleTransactionResponse.java b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/SingleTransactionResponse.java
new file mode 100644
index 0000000000..db251b5b3b
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/aai/entities/singletransaction/SingleTransactionResponse.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2018 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.onap.so.client.aai.entities.singletransaction;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class SingleTransactionResponse {
+
+ @JsonProperty("operation-responses")
+ public List<OperationBodyResponse> operationResponses;
+
+ @JsonProperty("operation-responses")
+ public List<OperationBodyResponse> getOperationResponses() {
+ if (operationResponses == null) {
+ operationResponses = new ArrayList<>();
+ }
+ return operationResponses;
+ }
+
+ @JsonProperty("operation-responses")
+ public void setOperationResponses(List<OperationBodyResponse> operationResponses) {
+ this.operationResponses = operationResponses;
+ }
+
+
+}
diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java
index 1697a4eb5f..e89c5c7e6a 100644
--- a/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java
+++ b/common/src/main/java/org/onap/so/serviceinstancebeans/RequestParameters.java
@@ -43,6 +43,8 @@ public class RequestParameters implements Serializable {
private List<Map<String, Object>> userParams = new ArrayList<>();
@JsonProperty("aLaCarte")
private Boolean aLaCarte;
+ @JsonProperty("payload")
+ private String payload;
// DONOT USE. It is intended to handle older VID requests(prior to 1802)
@Deprecated
@@ -57,9 +59,7 @@ public class RequestParameters implements Serializable {
@JsonProperty("usePreload")
private Boolean usePreload; // usePreload would always be true for Update
@JsonProperty("rebuildVolumeGroups")
- private Boolean rebuildVolumeGroups;
- @JsonProperty("payload")
- private String payload;
+ private Boolean rebuildVolumeGroups;
public String getSubscriptionServiceType() {
return subscriptionServiceType;
@@ -80,6 +80,13 @@ public class RequestParameters implements Serializable {
public Boolean isaLaCarte() {
return aLaCarte;
}
+
+ public String getPayload(){
+ return payload;
+ }
+ public void setPayload(String value){
+ this.payload = value;
+ }
@Deprecated
@Transient
@@ -151,13 +158,7 @@ public class RequestParameters implements Serializable {
public void setRebuildVolumeGroups(Boolean rebuildVolumeGroups) {
this.rebuildVolumeGroups = rebuildVolumeGroups;
- }
- public String getPayload(){
- return payload;
- }
- public void setPayload(String value){
- this.payload = value;
- }
+ }
@Override
public String toString() {