X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=vid-app-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fvid%2Fasdc%2Flocal%2FLocalAsdcClient.java;h=ce1bbe93038ca27220eb4f90064b7b605b9020e7;hb=e601bbdc43bae9a08e2e10c5139a6f76b47860d7;hp=108d9c06aa7683ee65e3bf2e1003eb2a1f568270;hpb=c72d565bb58226b20625b2bce5f0019046bee649;p=vid.git diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java b/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java index 108d9c06a..ce1bbe930 100644 --- a/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/asdc/local/LocalAsdcClient.java @@ -1,31 +1,43 @@ -package org.onap.vid.asdc.local; +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nokia. 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========================================================= + */ -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.json.JSONArray; -import org.json.JSONObject; -import org.onap.vid.asdc.AsdcCatalogException; -import org.onap.vid.asdc.AsdcClient; -import org.onap.vid.asdc.beans.Service; -import org.onap.vid.asdc.beans.tosca.ToscaCsar; -import org.onap.vid.asdc.beans.tosca.ToscaMeta; -import org.onap.vid.asdc.beans.tosca.ToscaModel; -import org.onap.vid.exceptions.GenericUncheckedException; -import org.yaml.snakeyaml.Yaml; +package org.onap.vid.asdc.local; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.joshworks.restclient.http.HttpResponse; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.Map; import java.util.UUID; -import java.util.zip.ZipFile; +import org.json.JSONArray; +import org.json.JSONObject; +import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.asdc.AsdcClient; +import org.onap.vid.asdc.beans.Service; +import org.onap.vid.exceptions.GenericUncheckedException; /** * The Class LocalAsdcClient. @@ -117,7 +129,7 @@ public class LocalAsdcClient implements AsdcClient { /* (non-Javadoc) * @see org.onap.vid.asdc.AsdcClient#getServiceToscaModel(java.util.UUID) */ - public Path getServiceToscaModel(UUID serviceUuid) throws AsdcCatalogException { + public Path getServiceToscaModel(UUID serviceUuid) { String toscaModelURL = null; @@ -134,58 +146,26 @@ public class LocalAsdcClient implements AsdcClient { return null; } ClassLoader classLoader = getClass().getClassLoader(); - File file = new File(classLoader.getResource(toscaModelURL).getFile()); try { + File file = new File(classLoader.getResource(toscaModelURL).getFile()); //using URLDecoder.decode to convert special characters from %XX to real character //see https://stackoverflow.com/questions/32251251/java-classloader-getresource-with-special-characters-in-path return Paths.get(URLDecoder.decode(file.getPath(), "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new GenericUncheckedException(e); + } catch (RuntimeException | UnsupportedEncodingException e) { + throw new GenericUncheckedException("Can't find " + toscaModelURL, e); } } - /** - * Gets the tosca model. - * - * @param csarInputStream the csar input stream - * @return the tosca model - * @throws AsdcCatalogException the asdc catalog exception - */ - private ToscaCsar getToscaModel(InputStream csarInputStream) throws AsdcCatalogException { - final Path csarFile; - - try { - csarFile = Files.createTempFile("csar", ".zip"); - Files.copy(csarInputStream, csarFile, StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - throw new AsdcCatalogException("Caught IOException while creating CSAR", e); - } - - try (final ZipFile csar = new ZipFile(csarFile.toFile())) { - - final InputStream toscaMetaStream = csar.getInputStream(csar.getEntry("TOSCA-Metadata/TOSCA.meta")); - final ToscaMeta toscaMeta = new ToscaMeta.Builder(toscaMetaStream).build(); - final String entryDefinitions = toscaMeta.get("Entry-Definitions"); - final InputStream toscaParentEntryYamlStream = csar.getInputStream(csar.getEntry(entryDefinitions)); - - final Yaml yaml = new Yaml(); - final ToscaModel parentModel = yaml.loadAs(toscaParentEntryYamlStream, ToscaModel.class); + @Override + public HttpResponse checkSDCConnectivity() { + return HttpResponse.fallback(""); + } - final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel); - for (Map> imports : parentModel.getImports()) { - for (Map.Entry> entry : imports.entrySet()) { - final InputStream toscaChildEntryYamlStream = csar.getInputStream(csar.getEntry("Definitions/" + entry.getValue().get("file"))); - final ToscaModel childModel = yaml.loadAs(toscaChildEntryYamlStream, ToscaModel.class); - csarBuilder.addVnf(childModel); - } - } - - return csarBuilder.build(); - } catch (IOException e) { - throw new AsdcCatalogException("Caught IOException while processing CSAR", e); - } + @Override + public String getBaseUrl(){ + return ""; } /**