diff options
author | Dilip kumar Pampana <dp583p@att.com> | 2018-01-05 15:37:36 -0500 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-01-08 18:41:41 +0000 |
commit | 38d293d605b42f88c9c82319ba848b4b81e45b64 (patch) | |
tree | 9478b5b60b90162427561e5bd0e6c97893dba6af | |
parent | 819f39b6b930d88b1fe2635deacd48867b86d011 (diff) |
Design Services updates
API to getInstarData on request from Design Tool GUI
Issue-ID: APPC-351
Change-Id: I9188f96049d7cfaf1b2987c65d3c7f92eb636f3e
Signed-off-by: Dilip kumar Pampana <dp583p@att.com>
9 files changed, 456 insertions, 195 deletions
diff --git a/appc-inbound/appc-design-services/features/src/main/resources/features.xml b/appc-inbound/appc-design-services/features/src/main/resources/features.xml index d413ad9cf..5ad41adfe 100644 --- a/appc-inbound/appc-design-services/features/src/main/resources/features.xml +++ b/appc-inbound/appc-design-services/features/src/main/resources/features.xml @@ -25,26 +25,27 @@ <features name="appc-design-services-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://karaf.apache.org/xmlns/features/v1.2.0 http://karaf.apache.org/xmlns/features/v1.2.0"> <repository>mvn:org.opendaylight.yangtools/features-yangtools/${odl.yangtools.version}/xml/features</repository> <repository>mvn:org.opendaylight.controller/features-mdsal/${odl.controller.mdsal.features.version}/xml/features</repository> - <feature name='appc-design-services' description="Application Controller Design Services" - version='${project.version}'> + <feature name='appc-design-services' description="Application Controller Design Services" + version='${project.version}'> - <feature version='${odl.mdsal.model.version}'>odl-mdsal-models</feature> - <bundle>mvn:org.onap.appc/appc-design-services-model/${project.version}</bundle> + <feature version='${odl.mdsal.model.version}'>odl-mdsal-models</feature> + <bundle>mvn:org.onap.appc/appc-design-services-model/${project.version}</bundle> - <!-- Most applications will have a dependency on the ODL MD-SAL Broker --> - <feature version='${odl.mdsal.version}'>odl-mdsal-broker</feature> - <feature>sdnc-sli</feature> - <bundle>mvn:org.onap.appc/appc-design-services-provider/${project.version}</bundle> - <bundle>wrap:mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/2.3.0</bundle> - - <feature version='${odl.mdsal.version}'>odl-restconf</feature> + <!-- Most applications will have a dependency on the ODL MD-SAL Broker --> + <feature version='${odl.mdsal.version}'>odl-mdsal-broker</feature> + <feature>sdnc-sli</feature> + <bundle>mvn:org.onap.appc/appc-design-services-provider/${project.version}</bundle> + <bundle>mvn:org.onap.appc/appc-network-inventory-client-provider/${project.version}</bundle> + <bundle>wrap:mvn:com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/2.3.0</bundle> + + <feature version='${odl.mdsal.version}'>odl-restconf</feature> - </feature> + </feature> </features> diff --git a/appc-inbound/appc-design-services/provider/pom.xml b/appc-inbound/appc-design-services/provider/pom.xml index 60a3c9e3d..31d2bbcf2 100755 --- a/appc-inbound/appc-design-services/provider/pom.xml +++ b/appc-inbound/appc-design-services/provider/pom.xml @@ -1,145 +1,156 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>appc-design-services</artifactId> - <groupId>org.onap.appc</groupId> - <version>1.3.0-SNAPSHOT</version> - </parent> - <artifactId>appc-design-services-provider</artifactId> - <packaging>bundle</packaging> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <artifactId>appc-design-services</artifactId> + <groupId>org.onap.appc</groupId> + <version>1.3.0-SNAPSHOT</version> + </parent> + <artifactId>appc-design-services-provider</artifactId> + <packaging>bundle</packaging> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Export-Package>org.onap.appc.design.services</Export-Package> - <Import-Package>*</Import-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Export-Package>org.onap.appc.design.services</Export-Package> + <Import-Package>org.onap.appc.instar,*;resolution:=optional</Import-Package> + <DynamicImport-Package>*</DynamicImport-Package> + <Embed-Transitive>true</Embed-Transitive> + </instructions> + </configuration> + </plugin> + </plugins> + </build> - <dependencies> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <version>1.9.5</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.onap.appc</groupId> - <artifactId>appc-design-services-model</artifactId> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>sli-provider</artifactId> - </dependency> + <dependencies> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>1.9.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.appc</groupId> + <artifactId>appc-design-services-model</artifactId> + </dependency> + <dependency> + <groupId>org.onap.appc</groupId> + <artifactId>appc-network-inventory-client-provider</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-provider</artifactId> + </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jasypt</groupId> + <artifactId>jasypt</artifactId> + <version>1.9.2</version> + </dependency> + <dependency> + <groupId>org.opendaylight.controller</groupId> + <artifactId>config-api</artifactId> + </dependency> + <dependency> + <groupId>org.opendaylight.controller</groupId> + <artifactId>sal-binding-config</artifactId> + </dependency> + <dependency> + <groupId>org.opendaylight.controller</groupId> + <artifactId>sal-binding-api</artifactId> + </dependency> + <dependency> + <groupId>org.opendaylight.controller</groupId> + <artifactId>sal-common-util</artifactId> + </dependency> + <dependency> + <artifactId>sal-test-model</artifactId> + <groupId>org.opendaylight.controller</groupId> + <scope>test</scope> + </dependency> + <dependency> + <artifactId>sal-rest-connector</artifactId> + <groupId>org.opendaylight.netconf</groupId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.opendaylight.controller</groupId> + <artifactId>sal-binding-broker-impl</artifactId> + <scope>test</scope> + </dependency> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>config-api</artifactId> - </dependency> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-binding-config</artifactId> - </dependency> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-binding-api</artifactId> - </dependency> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-common-util</artifactId> - </dependency> - <dependency> - <artifactId>sal-test-model</artifactId> - <groupId>org.opendaylight.controller</groupId> - <scope>test</scope> - </dependency> - <dependency> - <artifactId>sal-rest-connector</artifactId> - <groupId>org.opendaylight.netconf</groupId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.opendaylight.controller</groupId> - <artifactId>sal-binding-broker-impl</artifactId> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>com.att.eelf</groupId> - <artifactId>eelf-core</artifactId> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.sli.adaptors</groupId> - <artifactId>sql-resource-provider</artifactId> - <version>${ccsdk.sli.adaptors.version}</version> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>sli-provider</artifactId> - </dependency> - <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-client</artifactId> - <version>1.17</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.onap.ccsdk.sli.core</groupId> - <artifactId>sli-common</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.dataformat</groupId> - <artifactId>jackson-dataformat-yaml</artifactId> - <version>2.3.0</version> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - <dependency> - <groupId>org.apache.velocity</groupId> - <artifactId>velocity</artifactId> - <version>1.7</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4-rule-agent</artifactId> - <version>1.6.5</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-mockito-common</artifactId> - <version>1.6.5</version> - </dependency> - </dependencies> + <dependency> + <groupId>com.att.eelf</groupId> + <artifactId>eelf-core</artifactId> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.sli.adaptors</groupId> + <artifactId>sql-resource-provider</artifactId> + <version>${ccsdk.sli.adaptors.version}</version> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-provider</artifactId> + </dependency> + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-client</artifactId> + <version>1.17</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.onap.ccsdk.sli.core</groupId> + <artifactId>sli-common</artifactId> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.dataformat</groupId> + <artifactId>jackson-dataformat-yaml</artifactId> + <version>2.3.0</version> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </dependency> + <dependency> + <groupId>org.apache.velocity</groupId> + <artifactId>velocity</artifactId> + <version>1.7</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4-rule-agent</artifactId> + <version>1.6.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito-common</artifactId> + <version>1.6.5</version> + </dependency> + </dependencies> </project> diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java index 3b87461a2..7bb5a5f35 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java @@ -42,6 +42,7 @@ import org.onap.ccsdk.sli.core.dblib.DBResourceManager; import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -174,16 +175,16 @@ public class DesignDBService { if(!data) throw new Exception("Error while updating ProtocolReference"); - return "{\"update\" : \"success\" } "; } private String uploadArtifact(String payload, String requestID) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); JsonNode payloadObject = objectMapper.readTree(payload); log.info("Got upload Aritfact with Payload : " + payloadObject.asText()); try{ - ArtifactHandlerClient ac = new ArtifactHandlerClient(); + ArtifactHandlerClient ac = new ArtifactHandlerClient(); String requestString = ac.createArtifactData(payload, requestID); ac.execute(requestString, "POST"); int sdc_artifact_id = getSDCArtifactIDbyRequestID(requestID); @@ -377,33 +378,31 @@ public class DesignDBService { String vnfc_type = null; ObjectMapper objectMapper = new ObjectMapper(); JsonNode payloadObject = objectMapper.readTree(payload); - ArrayList<String> argList = new ArrayList<>(); + ArrayList<String> argList = new ArrayList<>(); argList.add(payloadObject.get("artifact-name").textValue()); argList.add(payloadObject.get("artifact-type").textValue()); - String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " + + String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " + " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? " ; log.info("Query String :" + queryString); ResultSet data = dbservice.getDBData(queryString, argList); String artifact_content = null; - int hightestVerion = 0 ; - while(data.next()) { + int hightestVerion = -1 ; + while(data.next()) { int version = data.getInt("INTERNAL_VERSION"); if(hightestVerion < version) - artifact_content = data.getString("ARTIFACT_CONTENT"); - } - + artifact_content = data.getString("ARTIFACT_CONTENT"); + } if(artifact_content == null || artifact_content.isEmpty()) throw new Exception("Sorry !!! I dont have any artifact Named : " + payloadObject.get("artifact-name").textValue()); DesignResponse designResponse = new DesignResponse(); - designResponse.setUserId(payloadObject.get("userID").textValue()); - List<ArtifactInfo> artifactInfoList = new ArrayList<ArtifactInfo>(); + //designResponse.setUserId(payloadObject.get("userID").textValue()); + List<ArtifactInfo> artifactInfoList = new ArrayList<ArtifactInfo>(); ArtifactInfo artifactInfo = new ArtifactInfo(); artifactInfo.setArtifact_content(artifact_content); artifactInfoList.add(artifactInfo); designResponse.setArtifactInfo(artifactInfoList); - ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(designResponse); log.info("Info : " + jsonString); @@ -584,35 +583,44 @@ public class DesignDBService { // for (Enumeration e = props.propertyNames(); e.hasMoreElements() ; ) { // String propName = (String) e.nextElement(); // log.info(propName+" = "+props.getProperty(propName)); - // + // // } // } // return requestID; - // + // // } private String getDesigns(String payload, String requestID) throws Exception { - String fn = "DBService.getDesigns "; + String fn = "DBService.getDesigns "; + String queryString; log.info("Starting getDesgins DB Operation"); try{ ObjectMapper objectMapper = new ObjectMapper(); JsonNode payloadObject = objectMapper.readTree(payload); - String UserID = payloadObject.get("userID").textValue(); + String UserID = payloadObject.get("userID").textValue(); + String filterKey =null; + if(payloadObject.hasNonNull("filter")) + filterKey = payloadObject.get("filter").textValue(); ArrayList<String> argList = new ArrayList<>(); argList.add(UserID); - String queryString = "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from " + - DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " + DesignServiceConstants.DB_SDC_REFERENCE + - " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? "; - + if(filterKey!=null){ + queryString = "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from " + + DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " + DesignServiceConstants.DB_SDC_REFERENCE + + " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? and AR.ARTIFACT_NAME like '%"+filterKey+"%' GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME"; + }else{ + queryString = "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from " + + DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " + DesignServiceConstants.DB_SDC_REFERENCE + + " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME"; + } DesignResponse designResponse = new DesignResponse(); designResponse.setUserId(UserID); List<DesignInfo> designInfoList = new ArrayList<DesignInfo>(); ResultSet data = dbservice.getDBData(queryString, argList); - while(data.next()) { + while(data.next()) { DesignInfo designInfo = new DesignInfo(); designInfo.setInCart(data.getString("IN_CART")); designInfo.setProtocol(data.getString("PROTOCOL")); diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java index 8cd7ebb1a..0d7357a4a 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java @@ -109,12 +109,13 @@ public class ArtifactHandlerClient { return String.format("{\"input\": %s}", json.toString()); } - public HashMap<String, String> execute(String payload, String rpc) throws Exception{ + public HashMap<String, String> execute(String payload, String rpc) throws Exception{ log.info("Configuring Rest Operation for Payload " + payload + " RPC : " + rpc ); HashMap<String, String> outputMessage = new HashMap<String, String>(); Client client = null; WebResource webResource = null; ClientResponse clientResponse = null; + EncryptionTool et = EncryptionTool.getInstance(); String responseDataType=MediaType.APPLICATION_JSON; String requestDataType=MediaType.APPLICATION_JSON; @@ -129,10 +130,10 @@ public class ArtifactHandlerClient { com.sun.jersey.client.urlconnection.HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new com.sun.jersey.client.urlconnection.HTTPSProperties(getHostnameVerifier(), sslContext)); client = Client.create(defaultClientConfig); - client.addFilter(new HTTPBasicAuthFilter(props.getProperty("appc.upload.user"), props.getProperty("appc.upload.pass"))); + String password = et.decrypt(props.getProperty("appc.upload.pass")); + client.addFilter(new HTTPBasicAuthFilter(props.getProperty("appc.upload.user"),password)); webResource = client.resource(new URI(props.getProperty("appc.upload.provider.url"))); webResource.setProperty("Content-Type", "application/json;charset=UTF-8"); - log.info("Starting Rest Operation....."); if(HttpMethod.GET.equalsIgnoreCase(rpc)){ clientResponse = webResource.accept(responseDataType).get(ClientResponse.class); diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java index 9ad5e10ac..8a3570be4 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java @@ -103,4 +103,8 @@ public class DesignServiceConstants { public static final String SETINCART = "setInCart"; public static final String INCART = "inCart"; public static final String STOREPASSWORD = "storeProperty"; + public static final String INSTAR_V4_ADDRESS = "v4IPAddress"; + public static final String INSTAR_V6_ADDRESS = "v6IPAddress"; + public static final String INSTAR_V4_MASK = "v4Subnet"; + public static final String INSTAR_V6_MASK = "v6Subnet"; } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/EncryptionTool.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/EncryptionTool.java new file mode 100644 index 000000000..2021a9806 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/EncryptionTool.java @@ -0,0 +1,169 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.design.services.util; + +import java.security.Provider; +import java.security.Provider.Service; +import java.security.Security; + +import org.jasypt.contrib.org.apache.commons.codec_1_3.binary.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This class is used to encapsulate the encryption and decryption support in one place and to + * provide a utility to encrypt and decrypt data. + */ +public class EncryptionTool { + + /** + * The prefix we insert onto any data we encrypt so that we can tell if it is encrpyted later and + * therefore decrypt it + */ + public static final String ENCRYPTED_VALUE_PREFIX = "enc:"; + + /** + * The instance of the encryption utility object + */ + private static EncryptionTool instance = null; + + /** + * The logger for this class. + */ + private static final Logger LOG = LoggerFactory.getLogger(EncryptionTool.class); + + /** + * The secret passphrase (PBE) that we use to perform encryption and decryption. The algorithm we + * are using is a symmetrical cipher. + */ + private static char[] secret = {'C', '_', 'z', 'l', '!', 'K', '!', '4', '?', 'O', 'z', 'E', 'K', 'E', '>', 'U', 'R', + '/', '%', 'Y', '\\', 'f', 'b', '"', 'e', 'n', '{', '"', 'l', 'U', 'F', '+', 'E', '\'', 'R', 'T', 'p', '1', + 'V', '4', 'l', 'a', '9', 'w', 'v', '5', 'Z', '#', 'i', 'V', '"', 'd', 'l', '!', 'L', 'M', 'g', 'L', 'Q', + '{', 'v', 'v', 'K', 'V'}; + + + + /** + * Get an instance of the EncryptionTool + * + * @return The encryption tool to be used + */ + public static final synchronized EncryptionTool getInstance() { + if (instance == null) { + instance = new EncryptionTool(); + } + return instance; + } + + /** + * Create the EncryptionTool instance + */ + private EncryptionTool() { + + StringBuilder sb = new StringBuilder("Found the following security algorithms:"); + for (Provider p : Security.getProviders()) { + for (Service s : p.getServices()) { + String algo = s.getAlgorithm(); + sb.append(String.format("%n -Algorithm [ %s ] in provider [ %s ] and service [ %s ]", algo, p.getName(), + s.getClassName())); + } + } + if (LOG.isDebugEnabled()) { + LOG.debug(sb.toString()); + } + } + + /** + * Decrypt the provided encrypted text + * + * @param cipherText THe cipher text to be decrypted. If the ciphertext is not encrypted, then it is + * returned as is. + * @return the clear test of the (possibly) encrypted value. The original value if the string is not + * encrypted. + */ + public synchronized String decrypt(String cipherText) { + if (isEncrypted(cipherText)) { + String encValue = cipherText.substring(ENCRYPTED_VALUE_PREFIX.length()); + byte[] plainByte = Base64.decodeBase64(encValue.getBytes()); + byte[] decryptByte = xorWithSecret(plainByte); + return new String(decryptByte); + } else { + return cipherText; + } + + } + + /** + * Encrypt the provided clear text + * + * @param clearText The clear text to be encrypted + * @return the encrypted text. If the clear text is empty (null or zero length), then an empty + * string is returned. If the clear text is already encrypted, it is not encrypted again and + * is returned as is. Otherwise, the clear text is encrypted and returned. + */ + public synchronized String encrypt(String clearText) { + if (clearText != null) { + byte[] encByte = xorWithSecret(clearText.getBytes()); + String encryptedValue = new String(Base64.encodeBase64(encByte)); + return ENCRYPTED_VALUE_PREFIX + encryptedValue; + } else { + return null; + } + } + + /** + * Is a value encrypted? A value is considered to be encrypted if it begins with the + * {@linkplain #ENCRYPTED_VALUE_PREFIX encrypted value prefix}. + * + * @param value the value to check. + * @return true/false; + */ + private static boolean isEncrypted(final String value) { + return value != null && value.startsWith(ENCRYPTED_VALUE_PREFIX); + } + + /** + * XORs the input byte array with the secret key, padding 0x0 to the end of the secret key if the + * input is longer and returns a byte array the same size as input + * + * @param inp The byte array to be XORed with secret + * @return A byte array the same size as inp or null if input is null. + */ + private byte[] xorWithSecret(byte[] inp) { + if (inp == null) { + return new byte[0]; + } + + byte[] secretBytes = new String(secret).getBytes(); + int size = inp.length; + + byte[] out = new byte[size]; + for (int i = 0; i < size; i++) { + out[i] = (byte) ((inp[i]) ^ (secretBytes[i % secretBytes.length])); + } + return out; + } + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java index 157e52937..f891f1d37 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java @@ -24,19 +24,32 @@ package org.onap.appc.design.xinterface; -import java.io.File; -import java.io.IOException; +import org.onap.appc.design.services.util.DesignServiceConstants; +import org.onap.appc.design.xinterface.XResponseProcessor; -import com.google.common.base.Charsets; -import com.google.common.io.Files; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.base.Strings; public class XInterfaceService { - - public String execute(String action, String payload) throws IOException { - //Remove this once hte interfaces are up and running - File targetFile = new File("/tmp/" + action + "-response.txt" ); - String interfaceResponse = Files.toString(targetFile, Charsets.UTF_8); + private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class); + public String execute(String action, String payload) throws Exception { + //File targetFile = new File("/tmp/" + action + "-response.txt" ); + String interfaceResponse = null; + try{ + if(Strings.isNullOrEmpty(payload)) + throw new Exception("Payload is null or empty.."); + if(DesignServiceConstants.GETINSTARDATA.equalsIgnoreCase(action)){ + XResponseProcessor xResponseProcessor = new XResponseProcessor(); + interfaceResponse = xResponseProcessor.parseResponse(payload, DesignServiceConstants.GETINSTARDATA); + } else { + throw new Exception("No Such Action, Please enter valid Action"); + } + }catch(Exception e){ + e.printStackTrace(); + throw e; + } return interfaceResponse; } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java index 9b4547b92..b1bf785d5 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java @@ -24,9 +24,72 @@ package org.onap.appc.design.xinterface; +import java.util.HashMap; + +import org.onap.appc.design.services.util.DesignServiceConstants; +import org.onap.appc.instar.dme2client.Dme2Client; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + public class XResponseProcessor { - public String parseResponse(Object execute, String action) { - return null; + private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class); + Dme2Client dme2Client; + + public String parseResponse(String execute, String action) throws Exception { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(execute); + log.info("payloadObject " + payloadObject); + + //String queryParam = null; + String instarResponse = null; + HashMap<String, String> payload = null; + String ipAddress = null; + String mask = null; + + try { + + // check the payload whether its having ipaddr along with subnet + ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null + ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue() + : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) !=null) + ?payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue().toUpperCase() + :null; + + mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null + ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue() + : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null) + ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase() + : null; + + // TODO -short format + + /*if (mask != null) { + queryParam = ipAddress + "," +mask ; + log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask ); + } else { + queryParam = "ipAddress "+ipAddress ; + log.info("Calling Instar with IpAddress "+ ipAddress); + }*/ + + payload = new HashMap<String, String>(); + payload.put("ipAddress", ipAddress); + payload.put("mask", mask); + log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask ); + dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload); + + instarResponse = dme2Client.send(); + + log.debug("Resposne from Instar = " + instarResponse); + if (instarResponse == null || instarResponse.length() < 0) + throw new Exception("No Data received from Instar for this action " + action); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + return instarResponse; } } diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestEscapeUtils.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestEscapeUtils.java index 4a99d42e9..8d04250dd 100644 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestEscapeUtils.java +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestEscapeUtils.java @@ -40,13 +40,4 @@ public class TestEscapeUtils { String str = escapeUtils.escapeSql("\\'Test Data\\'"); assert (true); } - - @Test - public void testXResponseProcessor(){ - - XResponseProcessor xr = new XResponseProcessor(); - Object o = new Object(); - xr.parseResponse(o, "Test"); - Assert.assertEquals(null, null); - } } |