-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.
/* (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;
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<String> checkSDCConnectivity() {
+ return HttpResponse.fallback("");
+ }
- final ToscaCsar.Builder csarBuilder = new ToscaCsar.Builder(parentModel);
- for (Map<String, Map<String, String>> imports : parentModel.getImports()) {
- for (Map.Entry<String, Map<String, String>> 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 "";
}
/**