diff options
Diffstat (limited to 'dcaedt_catalog/asdc')
9 files changed, 20 insertions, 605 deletions
diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDC.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDC.java deleted file mode 100644 index c704689..0000000 --- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDC.java +++ /dev/null @@ -1,288 +0,0 @@ -package org.onap.sdc.dcae.catalog.asdc; - -import org.apache.commons.codec.digest.DigestUtils; -import org.json.JSONArray; -import org.json.JSONObject; -import org.onap.sdc.common.onaplog.Enums.LogLevel; -import org.onap.sdc.common.onaplog.OnapLoggerDebug; -import org.onap.sdc.common.onaplog.OnapLoggerError; -import org.onap.sdc.dcae.catalog.commons.Action; -import org.onap.sdc.dcae.catalog.commons.Future; -import org.onap.sdc.dcae.catalog.commons.Futures; -import org.onap.sdc.dcae.catalog.commons.JSONHttpMessageConverter; -import org.springframework.context.annotation.Scope; -import org.springframework.http.*; -import org.springframework.http.client.AsyncClientHttpRequestExecution; -import org.springframework.http.client.AsyncClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; -import org.springframework.util.Base64Utils; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; -import org.springframework.web.client.AsyncRestTemplate; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.RestClientException; - -import javax.annotation.PostConstruct; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -@Component("asdc") -@Scope("singleton") -public class ASDC { - - public enum AssetType { - resource, - service, - product - } - - protected static OnapLoggerError errLogger = OnapLoggerError.getInstance(); - protected static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance(); - - private URI rootUri; - private String rootPath = "/sdc/v1/catalog/"; - private String user, passwd; - private String instanceId; - - public void setUri(URI theUri) { - String userInfo = theUri.getUserInfo(); - if (userInfo != null) { - String[] userInfoParts = userInfo.split(":"); - setUser(userInfoParts[0]); - if (userInfoParts.length > 1) { - setPassword(userInfoParts[1]); - } - } - String fragment = theUri.getFragment(); - if (fragment == null) { - throw new IllegalArgumentException("The URI must contain a fragment specification, to be used as ASDC instance id"); - } - setInstanceId(fragment); - - try { - this.rootUri = new URI(theUri.getScheme(), null, theUri.getHost(), theUri.getPort(), theUri.getPath(), theUri.getQuery(), null); - } - catch (URISyntaxException urix) { - throw new IllegalArgumentException("Invalid uri", urix); - } - } - - public URI getUri() { - return this.rootUri; - } - - public void setUser(String theUser) { - this.user = theUser; - } - - public String getUser() { - return this.user; - } - - public void setPassword(String thePassword) { - this.passwd = thePassword; - } - - public String getPassword() { - return this.passwd; - } - - public void setInstanceId(String theId) { - this.instanceId = theId; - } - - @Scheduled(fixedRateString = "${beans.context.scripts.updateCheckFrequency?:60000}") - public void checkForUpdates() { - // ffu - } - - @PostConstruct - public void initASDC() { - // ffu - } - - public <T> Future<T> getResources(Class<T> theType) { - return getAssets(AssetType.resource, theType); - } - - public Future<JSONArray> getResources() { - return getAssets(AssetType.resource, JSONArray.class); - } - - public <T> Future<T> getResources(Class<T> theType, String theCategory, String theSubCategory) { - return getAssets(AssetType.resource, theType, theCategory, theSubCategory); - } - - public Future<JSONArray> getResources(String category, String subCategory, String resourceType) { - return getAssets(AssetType.resource, JSONArray.class, category, subCategory, resourceType); - } - - public <T> Future<T> getAssets(AssetType theAssetType, Class<T> theType) { - return fetch(refAssets(theAssetType), theType); - } - - public <T> Future<T> getAssets(AssetType theAssetType, Class<T> theType, - String theCategory, String theSubCategory) { - return getAssets(theAssetType, theType, theCategory, theSubCategory, null); - } - - public <T> Future<T> getAssets(AssetType theAssetType, Class<T> theType, - String theCategory, String theSubCategory, String theResourceType) { - return fetch(refAssets(theAssetType) + filter(theCategory, theSubCategory, theResourceType), theType); - } - - protected String refAssets(AssetType theAssetType) { - return this.rootPath + theAssetType + "s/"; - } - - private String filter(String theCategory, String theSubCategory, String theResourceType) { - StringBuilder filter = null; - if (theCategory != null) { - filter = new StringBuilder(); - filter.append("?category=") - .append(theCategory); - if (theSubCategory != null) { - filter.append("&subCategory=") - .append(theSubCategory); - if (theResourceType != null) { - filter.append("&resourceType=") - .append(theResourceType); - } - } - } - return filter == null ? "" : filter.toString(); - } - - protected String refAsset(AssetType theAssetType, UUID theId) { - return this.rootPath + theAssetType + "s/" + theId; - } - - public <T> Future<T> getResource(UUID theId, Class<T> theType) { - return getAsset(AssetType.resource, theId, theType); - } - - public Future<JSONObject> getResource(UUID theId) { - return getAsset(AssetType.resource, theId, JSONObject.class); - } - - public <T> Future<T> getAsset(AssetType theAssetType, UUID theId, Class<T> theType) { - return fetch(refAsset(theAssetType, theId) + "/metadata", theType); - } - - public <T> Action<T> getAssetAction(AssetType theAssetType, UUID theId, Class<T> theType) { - return () -> fetch(refAsset(theAssetType, theId) + "/metadata", theType); - } - - public Future<byte[]> getAssetArchive(AssetType theAssetType, UUID theId) { - return fetch(refAsset(theAssetType, theId) + "/toscaModel", byte[].class); - } - - public Action<byte[]> getAssetArchiveAction(AssetType theAssetType, UUID theId) { - return () -> fetch(refAsset(theAssetType, theId) + "/toscaModel", byte[].class); - } - - protected String refAssetArtifact(AssetType theAssetType, UUID theAssetId, UUID theArtifactId) { - return refAsset(theAssetType, theAssetId) + "/artifacts" + (theArtifactId == null ? "" : ("/" + theArtifactId)); - } - - public <T> Future<T> getResourceArtifact(UUID theAssetId, UUID theArtifactId, Class<T> theType) { - return getAssetArtifact(AssetType.resource, theAssetId, theArtifactId, theType); - } - - public <T> Future<T> getAssetArtifact(AssetType theAssetType, UUID theAssetId, UUID theArtifactId, Class<T> theType) { - return fetch(refAssetArtifact(theAssetType, theAssetId, theArtifactId), theType); - } - - - public static JSONObject merge(JSONObject theOriginal, JSONObject thePatch) { - for (String key: (Set<String>)thePatch.keySet()) { - if (!theOriginal.has(key)) { - theOriginal.put(key, thePatch.get(key)); - } - } - return theOriginal; - } - - private HttpHeaders prepareHeaders() { - HttpHeaders headers = new HttpHeaders(); - headers.add(HttpHeaders.AUTHORIZATION, "Basic " + Base64Utils.encodeToString((this.user + ":" + this.passwd).getBytes())); - headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE); - headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_OCTET_STREAM_VALUE); - headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE); - headers.add("X-ECOMP-InstanceID", this.instanceId); - - return headers; - } - - public <T> Future<T> fetch(String theRef, Class<T> theContentType) { - return exchange(theRef, HttpMethod.GET, new HttpEntity(prepareHeaders()), theContentType); - } - - public <T> Future<T> exchange(String theRef, HttpMethod theMethod, HttpEntity theRequest, Class<T> theResponseType) { - - AsyncRestTemplate restTemplate = new AsyncRestTemplate(); - - List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters(); - converters.add(0, new JSONHttpMessageConverter()); - restTemplate.setMessageConverters(converters); - - restTemplate.setInterceptors(Collections.singletonList(new ContentMD5Interceptor())); - ASDCFuture<T> result = new ASDCFuture<T>(); - String uri = this.rootUri + theRef; - try { - restTemplate - .exchange(uri, theMethod, theRequest, theResponseType) - .addCallback(result.callback); - } - catch (RestClientException rcx) { - errLogger.log(LogLevel.WARN, this.getClass().getName(), "Failed to fetch {} {}", uri, rcx); - return Futures.failedFuture(rcx); - } - catch (Exception x) { - errLogger.log(LogLevel.WARN, this.getClass().getName(), "Failed to fetch {} {}", uri, x); - return Futures.failedFuture(x); - } - - return result; - } - - public class ASDCFuture<T> extends Futures.BasicFuture<T> { - - ListenableFutureCallback<ResponseEntity<T>> callback = new ListenableFutureCallback<ResponseEntity<T>>() { - - public void onSuccess(ResponseEntity<T> theResult) { - ASDCFuture.this.result(theResult.getBody()); - } - - public void onFailure(Throwable theError) { - if (theError instanceof HttpClientErrorException) { - ASDCFuture.this.cause(new ASDCException((HttpClientErrorException)theError)); - } - else { - ASDCFuture.this.cause(theError); - } - } - }; - } - - public class ContentMD5Interceptor implements AsyncClientHttpRequestInterceptor { - @Override - public ListenableFuture<ClientHttpResponse> intercept( - HttpRequest theRequest, byte[] theBody, AsyncClientHttpRequestExecution theExecution) - throws IOException { - if (HttpMethod.POST == theRequest.getMethod()) { - HttpHeaders headers = theRequest.getHeaders(); - headers.add("Content-MD5", Base64Utils.encodeToString(DigestUtils.md5Hex(theBody).getBytes())); - } - return theExecution.executeAsync(theRequest, theBody); - } - } -} diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCEngine.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCEngine.java deleted file mode 100644 index 73c7601..0000000 --- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCEngine.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.onap.sdc.dcae.catalog.asdc; - -import org.onap.sdc.dcae.composition.util.SystemProperties; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -@SpringBootApplication -public class ASDCEngine { - - /** - * Creates and returns a new instance of a {@link SystemProperties} class. - * - * @return New instance of {@link SystemProperties}. - */ - @Bean - public SystemProperties systemProperties() { - return new SystemProperties(); - } - - public static void main(String[] args) { - SpringApplication.run(ASDCEngine.class, args); - } - -} diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java deleted file mode 100644 index a3ea63d..0000000 --- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.onap.sdc.dcae.catalog.asdc; - -import org.apache.commons.jxpath.JXPathContext; -import org.apache.commons.lang3.StringUtils; -import org.json.JSONArray; -import org.json.JSONObject; -import org.onap.sdc.common.onaplog.Enums.LogLevel; -import org.onap.sdc.common.onaplog.OnapLoggerDebug; -import org.onap.sdc.common.onaplog.OnapLoggerError; -import org.onap.sdc.dcae.catalog.commons.Actions; -import org.onap.sdc.dcae.catalog.commons.Future; -import org.onap.sdc.dcae.catalog.commons.Futures; -import org.onap.sdc.dcae.catalog.commons.Recycler; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Scope; -import org.springframework.stereotype.Component; -import org.springframework.util.Base64Utils; - -import java.io.*; -import java.net.URI; -import java.util.List; -import java.util.Spliterators; -import java.util.UUID; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - - -@Component("asdcutils") -@Scope("singleton") -@ConfigurationProperties(prefix="asdcutils") -public class ASDCUtils { - - private static final String ARTIFACT_URL = "artifactURL"; - private static final String ARTIFACT_NAME = "artifactName"; - private static OnapLoggerError errLogger = OnapLoggerError.getInstance(); - private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance(); - - @Autowired - private ASDC asdc; - - @Autowired - private Blueprinter blueprint; - - public ASDCUtils() { - // Making sonar happy - } - - public ASDCUtils(URI theASDCURI) { - this(theASDCURI, null); - } - - public ASDCUtils(URI theASDCURI, URI theBlueprinterURI) { - this.asdc = new ASDC(); - this.asdc.setUri(theASDCURI); - if (theBlueprinterURI != null) { - this.blueprint = new Blueprinter(); - this.blueprint.setUri(theBlueprinterURI); - } - } - - public ASDCUtils(ASDC theASDC) { - this(theASDC, null); - } - - public ASDCUtils(ASDC theASDC, Blueprinter theBlueprinter) { - this.asdc = theASDC; - this.blueprint = theBlueprinter; - } - - - private static JSONObject lookupArtifactInfo(JSONArray theArtifacts, String theName) { - - for (int i = 0; theArtifacts != null && i < theArtifacts.length(); i++) { - JSONObject artifactInfo = theArtifacts.getJSONObject(i); - if (theName.equals(artifactInfo.getString(ARTIFACT_NAME))) { - debugLogger.log(LogLevel.DEBUG, ASDCUtils.class.getName(), "Found artifact info {}", artifactInfo); - return artifactInfo; - } - } - - return null; - } - - private static byte[] extractArtifactData(InputStream theEntryStream) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - byte[] buff = new byte[4096]; - int cnt = 0; - while ((cnt = theEntryStream.read(buff)) != -1) { - baos.write(buff, 0, cnt); - } - } finally { - baos.close(); - } - return baos.toByteArray(); - } - - - public Future<Future<String>> buildBlueprintViaToscaLab(Reader theCdump) { - return processCdump(theCdump, (theTemplate, theArchives) -> { - Blueprinter.BlueprintAction action = blueprint.generateBlueprint(); - processArtifacts(theArchives, (JSONObject theInfo, byte[] theData) -> new JSONObject().put(theInfo.getString(ARTIFACT_NAME).split("\\.")[0], Base64Utils.encodeToString(theData)), - (Stream<JSONObject> theAssetArtifacts) -> theAssetArtifacts.reduce(new JSONObject(), ASDC::merge)).forEach(artifactInfo -> action.withModelInfo(artifactInfo)); - - return action.withTemplateData(Recycler.toString(theTemplate).getBytes()).execute(); - - }); - } - - /* The common process of recycling, retrieving all related artifacts and then doing 'something' */ - private <T> Future<T> processCdump(Reader theCdump, BiFunction<Object, List, T> theProcessor) { - - final Recycler recycler = new Recycler(); - Object template = null; - try { - template = recycler.recycle(theCdump); - - } catch (Exception x) { - return Futures.failedFuture(x); - } - - JXPathContext jxroot = JXPathContext.newContext(template); - jxroot.setLenient(true); - - //based on the output of ASDCCatalog the node description will contain the UUID of the resource declaring it - //the desc contains the full URI and the resource uuid is the 5th path element - List uuids = (List) StreamSupport.stream(Spliterators.spliteratorUnknownSize(jxroot.iterate("topology_template/node_templates/*/description"), 16), false).distinct().filter(desc -> desc != null) - .map(desc -> desc.toString().split("/")[5]).collect(Collectors.toList()); - - //serialized fetch version - final Actions.Sequence sequencer = new Actions.Sequence(); - uuids.stream().forEach(uuid -> { - UUID rid = UUID.fromString((String) uuid); - sequencer.add(this.asdc.getAssetArchiveAction(ASDC.AssetType.resource, rid)); - sequencer.add(this.asdc.getAssetAction(ASDC.AssetType.resource, rid, JSONObject.class)); - }); - - final Object tmpl = template; - return Futures.advance(sequencer.execute(), (List theArchives) -> theProcessor.apply(tmpl, theArchives)); - } - - private static <T> Stream<T> processArtifacts(List theArtifactData, BiFunction<JSONObject, byte[], T> theProcessor, Function<Stream<T>, T> theAggregator) { - - Stream.Builder<T> assetBuilder = Stream.builder(); - - for (int i = 0; i < theArtifactData.size(); i = i + 2) { //cute old style loop - - JSONObject assetInfo = (JSONObject) theArtifactData.get(i + 1); - byte[] assetData = (byte[]) theArtifactData.get(i + 0); - - JSONArray artifacts = assetInfo.optJSONArray("artifacts"); - - Stream.Builder<T> artifactBuilder = Stream.builder(); - - try (ZipInputStream zipper = new ZipInputStream(new ByteArrayInputStream(assetData))){ - //we process the artifacts in the order they are stored in the archive .. fugly - processZipArtifacts(theProcessor, artifacts, artifactBuilder, zipper); - } catch (IOException iox) { - errLogger.log(LogLevel.ERROR, ASDC.class.getName(), "IOException: {}", iox); - return null; - } - - if (theAggregator != null) { - assetBuilder.add(theAggregator.apply(artifactBuilder.build())); - } else { - artifactBuilder.build().forEach(entry -> assetBuilder.add(entry)); - } - } - - return assetBuilder.build(); - } - - private static <T> void processZipArtifacts(BiFunction<JSONObject, byte[], T> theProcessor, JSONArray artifacts, Stream.Builder<T> artifactBuilder, ZipInputStream zipper) throws IOException { - for (ZipEntry zipped = zipper.getNextEntry(); zipped != null; zipped = zipper.getNextEntry()) { - JSONObject artifactInfo = lookupArtifactInfo(artifacts, StringUtils.substringAfterLast(zipped.getName(), "/")); - if (artifactInfo != null) { - artifactBuilder.add(theProcessor.apply(artifactInfo, extractArtifactData(zipper))); - } - zipper.closeEntry(); - } - } -} diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtilsController.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtilsController.java deleted file mode 100644 index 377e71b..0000000 --- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/ASDCUtilsController.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.onap.sdc.dcae.catalog.asdc; - -import org.onap.sdc.common.onaplog.Enums.LogLevel; -import org.onap.sdc.common.onaplog.OnapLoggerDebug; -import org.springframework.beans.BeansException; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - - -@RestController -@ConfigurationProperties(prefix="asdcUtilsController") -public class ASDCUtilsController implements ApplicationContextAware { - - private OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance(); - - public void setApplicationContext(ApplicationContext theCtx) throws BeansException { - // no use for app context - } - - @PostConstruct - public void initController() { - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(),"initASDCUtilsController"); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(),"ASDCUtilsController started"); - } - - @PreDestroy - public void cleanupController() { - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(),"cleanupASDCUtilsController"); - } - -} diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Blueprinter.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Blueprinter.java deleted file mode 100644 index 4e5349f..0000000 --- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Blueprinter.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.onap.sdc.dcae.catalog.asdc; - -import java.net.URI; - -import java.util.Collections; - -import org.json.JSONObject; -import org.onap.sdc.common.onaplog.OnapLoggerDebug; -import org.onap.sdc.common.onaplog.Enums.LogLevel; -import org.onap.sdc.dcae.catalog.commons.Action; -import org.onap.sdc.dcae.catalog.commons.Future; -import org.onap.sdc.dcae.catalog.commons.Http; - -import org.springframework.util.Base64Utils; - -import org.springframework.http.MediaType; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpEntity; -import org.springframework.stereotype.Component; -import org.springframework.context.annotation.Scope; -import org.springframework.boot.context.properties.ConfigurationProperties; - -@Component("blueprinter") -@Scope("singleton") -@ConfigurationProperties(prefix="blueprinter") -public class Blueprinter { - private URI serviceUri; - private OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance(); - - public void setUri(URI theUri) { - this.serviceUri = theUri; - } - - public BlueprintAction generateBlueprint() { - return new BlueprintAction(); - } - - public class BlueprintAction implements Action<String> { - - private JSONObject body = new JSONObject(); - - protected BlueprintAction() { - } - - public BlueprintAction withModelInfo(JSONObject theModelInfo) { - body.append("models", theModelInfo); - return this; - } - - public BlueprintAction withTemplateData(byte[] theData) { - body.put("template", Base64Utils.encodeToString(theData)); - return this; - } - - public Future<String> execute() { - - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Blueprinter::execute() | PAYLOAD to TOSCA_LAB={}", body.toString()); - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - return Http.exchange(serviceUri.toString(), HttpMethod.POST, new HttpEntity<>(body.toString(), headers), String.class); - } - } -} diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java index c389d75..9623d4c 100644 --- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java +++ b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/ISdcClient.java @@ -11,7 +11,9 @@ public interface ISdcClient { ResourceDetailed getResource(String uuid, String requestId); - ServiceDetailed getService(String uuid, String requestId); + byte[] getResourceToscaModel(String uuid, String requestId); + + ServiceDetailed getService(String uuid, String requestId); ServiceDetailed getAssetMetadata(String contextType, String uuid, String requestId); diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java index b07126e..7b89465 100644 --- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java +++ b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/client/SdcRestClient.java @@ -52,6 +52,7 @@ public class SdcRestClient implements ISdcClient { private static final String LIFECYCLE_STATE_PATH = "lifecycleState/{lifecycleOperation}"; private static final String METADATA_PATH = "metadata"; private static final String VERSION_PATH = "version"; + private static final String CSAR_PATH = "toscaModel"; private static final String MONITORING_REFERENCES_PATH = "externalReferences/monitoring"; private static OnapLoggerDebug debugLogger = OnapLoggerDebug.getInstance(); @@ -93,6 +94,12 @@ public class SdcRestClient implements ISdcClient { return getObject(url, requestId, ResourceDetailed.class); } + public byte[] getResourceToscaModel(String uuid, String requestId) { + String url = buildRequestPath(AssetType.RESOURCE.getSdcContextPath(), uuid, CSAR_PATH); + debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Get resource csar from SDC. URL={}", url); + return getObject(url, requestId, byte[].class); + } + public ServiceDetailed getService(String uuid, String requestId) { return getAssetMetadata(AssetType.SERVICE.name(), uuid, requestId); } diff --git a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java index 33c2f49..1e5102e 100644 --- a/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java +++ b/dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/utils/SdcRestClientUtils.java @@ -72,7 +72,7 @@ public class SdcRestClientUtils { return mapper.writeValueAsString(artifact); } - public static Artifact generateDeploymentArtifact(String description, String name, String type, String label, byte[] payload){ + public static Artifact generateDeploymentArtifact(String description, String name, String type, String label, byte[] payload) { Artifact artifact = new Artifact(); artifact.setDescription(description); artifact.setArtifactName(name); @@ -82,4 +82,12 @@ public class SdcRestClientUtils { artifact.setPayloadData(Base64Utils.encodeToString(payload)); return artifact; } + + public static Artifact generateCatalogDcaeToscaArtifact(String name, String path, byte[] payload) { + Artifact artifact = new Artifact(); + artifact.setArtifactName(name); + artifact.setArtifactURL(path); + artifact.setPayloadData(new String(payload)); + return artifact; + } } diff --git a/dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java b/dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java index 05eb4b1..15c4a8a 100644 --- a/dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java +++ b/dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java @@ -90,4 +90,4 @@ public class SDCResponseErrorHandlerTest { Assert.assertFalse(result); } -} +}
\ No newline at end of file |