aboutsummaryrefslogtreecommitdiffstats
path: root/common/src/main/java/org/openecomp/mso
diff options
context:
space:
mode:
authorbiniek <lukasz.biniek@nokia.com>2018-03-20 16:41:13 +0100
committerbiniek <lukasz.biniek@nokia.com>2018-03-28 11:11:25 +0200
commit5c788af30b182a75979ea30c76eb83511f5c944d (patch)
tree5135ce974b8034377a94f4d299e2b91ec514093b /common/src/main/java/org/openecomp/mso
parent9903fb12ab6b3081e8c1b680ae4088d638503776 (diff)
Added subworkflow for Pnf pnp
Change-Id: Ifeba2e74a03ce8c5a13b80f673809c3ef60bfe3f Issue-ID: SO-506 Signed-off-by: biniek <lukasz.biniek@nokia.com>
Diffstat (limited to 'common/src/main/java/org/openecomp/mso')
-rw-r--r--common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java12
-rw-r--r--common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientI.java8
-rw-r--r--common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java276
3 files changed, 171 insertions, 125 deletions
diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java
index 32c61f7fd7..c55e5e9eee 100644
--- a/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java
+++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java
@@ -28,6 +28,7 @@ import javax.ws.rs.NotFoundException;
import javax.ws.rs.client.ResponseProcessingException;
import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.Response;
import org.onap.aai.domain.yang.Relationship;
import org.openecomp.mso.client.aai.entities.AAIResultWrapper;
import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
@@ -153,7 +154,7 @@ public class AAIResourcesClient extends AAIClient {
aaiRC.patch(obj);
return;
}
-
+
/**
* Retrieves an object from A&AI and unmarshalls it into the Class specified
* @param clazz
@@ -163,6 +164,15 @@ public class AAIResourcesClient extends AAIClient {
public <T> T get(Class<T> clazz, AAIResourceUri uri) {
return this.createClient(uri).get(clazz);
}
+
+ /**
+ * Retrieves an object from A&AI and returns complete response
+ * @param uri
+ * @return
+ */
+ public Response getFullResponse(AAIResourceUri uri) {
+ return this.createClient(uri).get();
+ }
/**
* Retrieves an object from A&AI and automatically unmarshalls it into a Map or List
diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientI.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientI.java
index 801c0f91d4..6819ba1edf 100644
--- a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientI.java
+++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientI.java
@@ -23,7 +23,9 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
+import java.util.Optional;
import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.Pnf;
import org.onap.aai.domain.yang.Pserver;
import org.onap.aai.domain.yang.Pservers;
@@ -39,6 +41,10 @@ public interface AAIRestClientI {
void updateMaintenceFlag(String vnfId,boolean inMaint, String transactionLoggingUuid) throws Exception;
void updateMaintenceFlagVnfId(String vnfId, boolean inMaint, String transactionLoggingUuid) throws Exception;
-
+
GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws Exception;
+
+ Optional<Pnf> getPnfByName(String pnfId, String transactionLoggingUuid) throws Exception;
+
+ void createPnf(String pnfId, String transactionLoggingUuid, Pnf pnf) throws IOException;
}
diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java
index e27075d9dd..54aab5c296 100644
--- a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java
+++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java
@@ -20,14 +20,20 @@
package org.openecomp.mso.client.aai;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
-
+import javax.ws.rs.core.Response;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.aai.domain.yang.GenericVnfs;
+import org.onap.aai.domain.yang.Pnf;
import org.onap.aai.domain.yang.Pserver;
import org.onap.aai.domain.yang.Pservers;
import org.openecomp.mso.client.aai.entities.CustomQuery;
@@ -36,130 +42,154 @@ import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
import org.springframework.stereotype.Service;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
@Service
public class AAIRestClientImpl implements AAIRestClientI {
-
- private static final EELFLogger logger = EELFManager.getInstance().getMetricsLogger();
- private static final AAIVersion ENDPOINT_VERSION = AAIVersion.V10;
- private static final String ENDPOINT_GET_ALL = ENDPOINT_VERSION + "/cloud-infrastructure/pservers";
- private static final String ENDPOINT_GET_ALL_VNFS = ENDPOINT_VERSION + "/network/generic-vnfs";
- private static final String ENDPOINT_CUSTOM_QUERY = ENDPOINT_VERSION + "/query";
- private static final String PSERVER_VNF_QUERY = "pservers-fromVnf";
- private static final String GENERIC_VNF_PATH = ENDPOINT_VERSION + "/network/generic-vnfs/generic-vnf";
- private static final String SERVICE_TOPOLOGY_BY_SERVICE_INSTANCE_ID = "store(‘x’).union(__.in(‘subscribesTo’).has(‘aai-node-type’,’customer’).store(‘x’),__.out(‘uses’).has(‘aai-node-type’,’allotted-resource’).store(‘x’),__.in(‘hasInstance’).has(‘aai-node-type’,’generic-vnf’).store(‘x’).union("
- + ".out(‘has’).has(‘aai-node-type’,’vf-module’).store(‘x’),out(‘uses’).has(‘aai-node-type’,’volume-group’).store(‘x’),"
- + ".out(‘hasLInterface’).has(‘aai-node-type’,’l-interface’).union("
- + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv4-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’),"
- + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv6-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)"
- + ")," + ".out(‘runsOnVserver’).has(‘aai-node-type’,’vserver’).store(‘x’).union("
- + ".in(‘owns’).has(‘aai-node-type’,’tenant’).store(‘x’).in(‘has’).has(‘aai-node-type’,’cloud-region’).store(‘x’),"
- + ".out(‘runsOnPserver’).has(‘aai-node-type’,’pserver’).store(‘x’),"
- + ".out(‘hasLInterface’).has(‘aai-node-type’,’l-interface’).union("
- + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv4-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’),"
- + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv6-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)"
- + ")" + ")" + ")" + ").cap(‘x’).unfold().dedup()";
-
- public AAIRestClientImpl() {
-
-
- }
-
- public AAIRestClientImpl(final String host) {
-
-
- }
-
- @Override
- public Pservers getPhysicalServers(String hostName, String uuid) {
- UUID requestId;
- try {
- requestId = UUID.fromString(uuid);
- } catch (IllegalArgumentException e) {
- logger.warn("could not parse uuid: " + uuid + " creating valid uuid automatically");
- requestId = UUID.randomUUID();
- }
- return new AAIResourcesClient(ENDPOINT_VERSION, requestId).get(Pservers.class, AAIUriFactory.createResourceUri(AAIObjectPlurals.PSERVER));
- }
-
- @Override
- public List<Pserver> getPhysicalServerByVnfId(String vnfId, String transactionLoggingUuid)
- throws JsonParseException, JsonMappingException, IOException {
- UUID requestId;
- try {
- requestId = UUID.fromString(transactionLoggingUuid);
- } catch (IllegalArgumentException e) {
- logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
- requestId = UUID.randomUUID();
- }
- List<AAIResourceUri> startNodes = new ArrayList<>();
- startNodes.add(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId));
- String jsonInput = new AAIQueryClient(ENDPOINT_VERSION, requestId).query(Format.RESOURCE, new CustomQuery(startNodes,PSERVER_VNF_QUERY));
-
- return this.getListOfPservers(jsonInput);
-
- }
-
- protected List<Pserver> getListOfPservers(String jsonInput) throws JsonParseException, JsonMappingException, IOException {
- ObjectMapper mapper = new AAICommonObjectMapperProvider().getContext(Object.class);
- Results<Map<String, Pserver>> resultsFromJson = mapper.readValue(jsonInput,
- new TypeReference<Results<Map<String, Pserver>>>() {
- });
- List<Pserver> results = new ArrayList<>();
- for (Map<String, Pserver> m : resultsFromJson.getResult()) {
- results.add(m.get("pserver"));
- }
- return results;
- }
- @Override
- public void updateMaintenceFlag(String vnfName, boolean inMaint, String transactionLoggingUuid) throws JsonParseException, JsonMappingException, IOException {
- UUID requestId;
- try {
- requestId = UUID.fromString(transactionLoggingUuid);
- } catch (IllegalArgumentException e) {
- logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
- requestId = UUID.randomUUID();
- }
- GenericVnfs genericVnfs = new AAIResourcesClient(ENDPOINT_VERSION, requestId).get(GenericVnfs.class, AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName));
- if(genericVnfs.getGenericVnf().size() > 1)
- throw new IndexOutOfBoundsException("Multiple Generic Vnfs Returned");
-
- GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0);
- updateMaintenceFlagVnfId(genericVnf.getVnfId(), inMaint, transactionLoggingUuid);
- }
-
- @Override
- public void updateMaintenceFlagVnfId(String vnfId, boolean inMaint, String transactionLoggingUuid) throws JsonParseException, JsonMappingException, IOException {
- UUID requestId;
- try {
- requestId = UUID.fromString(transactionLoggingUuid);
- } catch (IllegalArgumentException e) {
- logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
- requestId = UUID.randomUUID();
- }
- GenericVnf genericVnf = new GenericVnf();
- genericVnf.setInMaint(inMaint);
- new AAIResourcesClient(ENDPOINT_VERSION, requestId).update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId), genericVnf);
-
- }
-
- @Override
- public GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws JsonParseException, JsonMappingException, IOException {
- UUID requestId;
- try {
- requestId = UUID.fromString(transactionLoggingUuid);
- } catch (IllegalArgumentException e) {
- logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
- requestId = UUID.randomUUID();
- }
- return new AAIResourcesClient(ENDPOINT_VERSION, requestId).get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId));
- }
+ private static final EELFLogger logger = EELFManager.getInstance().getMetricsLogger();
+ private static final AAIVersion ENDPOINT_VERSION = AAIVersion.V10;
+ private static final String ENDPOINT_GET_ALL = ENDPOINT_VERSION + "/cloud-infrastructure/pservers";
+ private static final String ENDPOINT_GET_ALL_VNFS = ENDPOINT_VERSION + "/network/generic-vnfs";
+ private static final String ENDPOINT_CUSTOM_QUERY = ENDPOINT_VERSION + "/query";
+ private static final String PSERVER_VNF_QUERY = "pservers-fromVnf";
+ private static final String GENERIC_VNF_PATH = ENDPOINT_VERSION + "/network/generic-vnfs/generic-vnf";
+ private static final String SERVICE_TOPOLOGY_BY_SERVICE_INSTANCE_ID =
+ "store(‘x’).union(__.in(‘subscribesTo’).has(‘aai-node-type’,’customer’).store(‘x’),__.out(‘uses’).has(‘aai-node-type’,’allotted-resource’).store(‘x’),__.in(‘hasInstance’).has(‘aai-node-type’,’generic-vnf’).store(‘x’).union("
+ + ".out(‘has’).has(‘aai-node-type’,’vf-module’).store(‘x’),out(‘uses’).has(‘aai-node-type’,’volume-group’).store(‘x’),"
+ + ".out(‘hasLInterface’).has(‘aai-node-type’,’l-interface’).union("
+ + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv4-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’),"
+ + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv6-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)"
+ + ")," + ".out(‘runsOnVserver’).has(‘aai-node-type’,’vserver’).store(‘x’).union("
+ + ".in(‘owns’).has(‘aai-node-type’,’tenant’).store(‘x’).in(‘has’).has(‘aai-node-type’,’cloud-region’).store(‘x’),"
+ + ".out(‘runsOnPserver’).has(‘aai-node-type’,’pserver’).store(‘x’),"
+ + ".out(‘hasLInterface’).has(‘aai-node-type’,’l-interface’).union("
+ + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv4-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’),"
+ + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv6-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)"
+ + ")" + ")" + ")" + ").cap(‘x’).unfold().dedup()";
+
+ public AAIRestClientImpl() {
+ }
+
+ @Override
+ public Pservers getPhysicalServers(String hostName, String uuid) {
+ UUID requestId;
+ try {
+ requestId = UUID.fromString(uuid);
+ } catch (IllegalArgumentException e) {
+ logger.warn("could not parse uuid: " + uuid + " creating valid uuid automatically");
+ requestId = UUID.randomUUID();
+ }
+ return new AAIResourcesClient(ENDPOINT_VERSION, requestId)
+ .get(Pservers.class, AAIUriFactory.createResourceUri(AAIObjectPlurals.PSERVER));
+ }
+
+ @Override
+ public List<Pserver> getPhysicalServerByVnfId(String vnfId, String transactionLoggingUuid) throws IOException {
+ UUID requestId;
+ try {
+ requestId = UUID.fromString(transactionLoggingUuid);
+ } catch (IllegalArgumentException e) {
+ logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
+ requestId = UUID.randomUUID();
+ }
+ List<AAIResourceUri> startNodes = new ArrayList<>();
+ startNodes.add(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId));
+ String jsonInput = new AAIQueryClient(ENDPOINT_VERSION, requestId)
+ .query(Format.RESOURCE, new CustomQuery(startNodes, PSERVER_VNF_QUERY));
+
+ return this.getListOfPservers(jsonInput);
+
+ }
+
+ protected List<Pserver> getListOfPservers(String jsonInput) throws IOException {
+ ObjectMapper mapper = new AAICommonObjectMapperProvider().getContext(Object.class);
+ Results<Map<String, Pserver>> resultsFromJson = mapper.readValue(jsonInput,
+ new TypeReference<Results<Map<String, Pserver>>>() {
+ });
+ List<Pserver> results = new ArrayList<>();
+ for (Map<String, Pserver> m : resultsFromJson.getResult()) {
+ results.add(m.get("pserver"));
+ }
+ return results;
+ }
+
+ @Override
+ public void updateMaintenceFlag(String vnfName, boolean inMaint, String transactionLoggingUuid) throws IOException {
+ UUID requestId;
+ try {
+ requestId = UUID.fromString(transactionLoggingUuid);
+ } catch (IllegalArgumentException e) {
+ logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
+ requestId = UUID.randomUUID();
+ }
+ GenericVnfs genericVnfs = new AAIResourcesClient(ENDPOINT_VERSION, requestId).get(GenericVnfs.class,
+ AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName));
+ if (genericVnfs.getGenericVnf().size() > 1) {
+ throw new IndexOutOfBoundsException("Multiple Generic Vnfs Returned");
+ }
+
+ GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0);
+ updateMaintenceFlagVnfId(genericVnf.getVnfId(), inMaint, transactionLoggingUuid);
+ }
+
+ @Override
+ public void updateMaintenceFlagVnfId(String vnfId, boolean inMaint, String transactionLoggingUuid)
+ throws IOException {
+ UUID requestId;
+ try {
+ requestId = UUID.fromString(transactionLoggingUuid);
+ } catch (IllegalArgumentException e) {
+ logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
+ requestId = UUID.randomUUID();
+ }
+ GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setInMaint(inMaint);
+ new AAIResourcesClient(ENDPOINT_VERSION, requestId)
+ .update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId), genericVnf);
+
+ }
+
+ @Override
+ public GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws IOException {
+ UUID requestId;
+ try {
+ requestId = UUID.fromString(transactionLoggingUuid);
+ } catch (IllegalArgumentException e) {
+ logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
+ requestId = UUID.randomUUID();
+ }
+ return new AAIResourcesClient(ENDPOINT_VERSION, requestId)
+ .get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId));
+ }
+
+ @Override
+ public Optional<Pnf> getPnfByName(String pnfId, String transactionLoggingUuid) throws IOException {
+ UUID requestId;
+ try {
+ requestId = UUID.fromString(transactionLoggingUuid);
+ } catch (IllegalArgumentException e) {
+ logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
+ requestId = UUID.randomUUID();
+ }
+ Response response = new AAIResourcesClient(ENDPOINT_VERSION, requestId)
+ .getFullResponse(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId));
+ if (response.getStatus() != 200) {
+ return Optional.empty();
+ } else {
+ return Optional.of(response.readEntity(Pnf.class));
+ }
+ }
+
+ @Override
+ public void createPnf(String pnfId, String transactionLoggingUuid, Pnf pnf) throws IOException {
+ UUID requestId;
+ try {
+ requestId = UUID.fromString(transactionLoggingUuid);
+ } catch (IllegalArgumentException e) {
+ logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically");
+ requestId = UUID.randomUUID();
+ }
+ new AAIResourcesClient(ENDPOINT_VERSION, requestId)
+ .createIfNotExists(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId), Optional.of(pnf));
+ }
}