aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/pomba/contextbuilder/sdc/model
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/pomba/contextbuilder/sdc/model')
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/sdc/model/ArtifactInfo.java122
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/sdc/model/SDCContextRequest.java109
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/sdc/model/SDCContextResponse.java69
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/sdc/model/handlers/ToscaCsarArtifactHandler.java188
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/sdc/model/handlers/ToscaModelConverter.java147
5 files changed, 635 insertions, 0 deletions
diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdc/model/ArtifactInfo.java b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/ArtifactInfo.java
new file mode 100644
index 0000000..8e3d179
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/ArtifactInfo.java
@@ -0,0 +1,122 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 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.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.sdc.model;
+
+import java.util.List;
+import lombok.Data;
+import lombok.ToString;
+import org.openecomp.sdc.api.notification.IArtifactInfo;
+
+@Data
+@ToString(includeFieldNames = true)
+public class ArtifactInfo implements IArtifactInfo {
+
+ private String artifactName;
+ private String artifactType;
+ private String artifactDescription;
+ private String artifactVersion;
+ private String artifactURL;
+ private String artifactChecksum;
+ private Integer artifactTimeout;
+ private String artifactUUID;
+ private IArtifactInfo generatedArtifact;
+ private List<IArtifactInfo> relatedArtifactsInfo;
+
+ public IArtifactInfo getGeneratedArtifact() {
+ return generatedArtifact;
+ }
+
+ public void setGeneratedArtifact(IArtifactInfo generatedArtifact) {
+ this.generatedArtifact = generatedArtifact;
+ }
+
+ public List<IArtifactInfo> getRelatedArtifacts() {
+ return relatedArtifactsInfo;
+ }
+
+ public void setRelatedArtifacts(List<IArtifactInfo> relatedArtifactsInfo) {
+ this.relatedArtifactsInfo = relatedArtifactsInfo;
+ }
+
+ public String getArtifactName() {
+ return artifactName;
+ }
+
+ public void setArtifactName(String artifactName) {
+ this.artifactName = artifactName;
+ }
+
+ public String getArtifactType() {
+ return artifactType;
+ }
+
+ public void setArtifactType(String artifactType) {
+ this.artifactType = artifactType;
+ }
+
+ public String getArtifactDescription() {
+ return artifactDescription;
+ }
+
+ public void setArtifactDescription(String artifactDescription) {
+ this.artifactDescription = artifactDescription;
+ }
+
+ public String getArtifactVersion() {
+ return artifactVersion;
+ }
+
+ public void setArtifactVersion(String artifactVersion) {
+ this.artifactVersion = artifactVersion;
+ }
+
+ public String getArtifactURL() {
+ return artifactURL;
+ }
+
+ public void setArtifactURL(String artifactURL) {
+ this.artifactURL = artifactURL;
+ }
+
+ public String getArtifactChecksum() {
+ return artifactChecksum;
+ }
+
+ public void setArtifactChecksum(String artifactChecksum) {
+ this.artifactChecksum = artifactChecksum;
+ }
+
+ public Integer getArtifactTimeout() {
+ return artifactTimeout;
+ }
+
+ public void setArtifactTimeout(Integer artifactTimeout) {
+ this.artifactTimeout = artifactTimeout;
+ }
+
+ public String getArtifactUUID() {
+ return artifactUUID;
+ }
+
+ public void setArtifactUUID(String artifactUUID) {
+ this.artifactUUID = artifactUUID;
+ }
+
+
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdc/model/SDCContextRequest.java b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/SDCContextRequest.java
new file mode 100644
index 0000000..9ba6197
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/SDCContextRequest.java
@@ -0,0 +1,109 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 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.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.sdc.model;
+
+import javax.ws.rs.core.Response.Status;
+import org.onap.pomba.contextbuilder.sdc.exception.ToscaCsarException;
+
+public class SDCContextRequest {
+
+ private String remoteAddr;
+ private String fromAppId;
+ private String transactionId;
+ private String serviceInstanceId;
+ private String modelVersionId;
+ private String modelInvariantId;
+ private String authorization;
+
+
+ public SDCContextRequest(String remoteAddr, String authorization, String fromAppId, String transactionId,
+ String serviceInstanceId, String modelVersionId, String modelInvariantId) {
+ this.remoteAddr = remoteAddr;
+ this.authorization = authorization;
+ this.fromAppId = fromAppId;
+ this.transactionId = transactionId;
+ this.serviceInstanceId = serviceInstanceId;
+ this.modelVersionId = modelVersionId;
+ this.modelInvariantId = modelInvariantId;
+
+ }
+
+
+ public String getAuthorization() {
+ return authorization;
+ }
+
+
+ public void setAuthorization(String authorization) {
+ this.authorization = authorization;
+ }
+
+
+ public String getRemoteAddr() {
+ return remoteAddr;
+ }
+
+ public String getFromAppId() {
+ return fromAppId;
+ }
+
+ public String getTransactionId() {
+ return transactionId;
+ }
+
+ public String getServiceInstanceId() {
+ return serviceInstanceId;
+ }
+
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public void validate(String httpBasicAuthorization) throws ToscaCsarException {
+
+ // validation on HTTP Authorization Header
+ if (authorization != null && !authorization.trim().isEmpty() && authorization.startsWith("Basic")) {
+ if (!authorization.equals(httpBasicAuthorization)) {
+ throw new ToscaCsarException(Status.UNAUTHORIZED, "Authorization Failed due to mismatch basic auth username or password");
+ };
+ } else {
+ throw new ToscaCsarException(Status.UNAUTHORIZED, "Missing Authorization header");
+ }
+
+ if((fromAppId == null) || fromAppId.isEmpty()) {
+ throw new ToscaCsarException(Status.BAD_REQUEST, "Missing mandatory header parameter: X-FromAppId");
+ }
+ if((transactionId == null) || transactionId.isEmpty()) {
+ throw new ToscaCsarException(Status.BAD_REQUEST, "Missing mandatory header parameter: X-TransactionId");
+ }
+ if((modelVersionId == null) || modelVersionId.isEmpty()) {
+ throw new ToscaCsarException(Status.BAD_REQUEST, "Missing mandatory parameter: modelVersionId");
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "SDCContextRequest [remoteAddr=" + remoteAddr + ", authorization=" + authorization + ", fromAppId=" + fromAppId + ", transactionId="
+ + transactionId + ", serviceInstanceId=" + serviceInstanceId + ", modelVersionId=" + modelVersionId
+ + ", modelInvariantId=" + modelInvariantId + "]";
+ }
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdc/model/SDCContextResponse.java b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/SDCContextResponse.java
new file mode 100644
index 0000000..156874f
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/SDCContextResponse.java
@@ -0,0 +1,69 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 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.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.sdc.model;
+
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+public class SDCContextResponse {
+
+ private String payload;
+ private Status httpStatus = Status.OK;
+ private String mediaType = MediaType.APPLICATION_JSON;
+
+ /**
+ * Instantiates with HTTP Status set to OK and MediaType set to APPLICATION-JSON
+ */
+ public SDCContextResponse() {
+ // Intentionally empty
+ }
+
+ /**
+ * This constructor is meant to be used when an error is encountered.
+ * MediaType is set to TEXT-PLAIN for the error message.
+ * @param httpStatus
+ * @param errorMessage
+ */
+ public SDCContextResponse(Status httpStatus, String errorMessage) {
+ this.httpStatus = httpStatus;
+ this.payload = errorMessage;
+ this.mediaType = MediaType.TEXT_PLAIN;
+ }
+
+ public String getModelData() {
+ return payload;
+ }
+
+ public void setModelData(String modelData) {
+ this.payload = modelData;
+ }
+
+ public Status getHttpStatus() {
+ return httpStatus;
+ }
+
+ public void setHttpStatus(Status httpStatus) {
+ this.httpStatus = httpStatus;
+ }
+
+ public Response buildResponse() {
+ return Response.status(httpStatus).entity(payload).type(mediaType).build();
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdc/model/handlers/ToscaCsarArtifactHandler.java b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/handlers/ToscaCsarArtifactHandler.java
new file mode 100644
index 0000000..14079a8
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/handlers/ToscaCsarArtifactHandler.java
@@ -0,0 +1,188 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 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.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.sdc.model.handlers;
+
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import groovy.util.logging.Slf4j;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+import org.onap.pomba.contextbuilder.sdc.ToscaBuilderConfig;
+import org.onap.pomba.contextbuilder.sdc.exception.ToscaCsarException;
+import org.onap.pomba.contextbuilder.sdc.model.ArtifactInfo;
+import org.onap.pomba.contextbuilder.sdc.model.SDCContextResponse;
+import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
+import org.openecomp.sdc.http.SdcConnectorClient;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.openecomp.sdc.utils.DistributionActionResultEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Slf4j
+@Component("ToscaCsarArtifactHandler")
+public class ToscaCsarArtifactHandler {
+
+ private static final String DEFAULT_CSAR_FILE_EXTENSION = ".zip";
+
+ private static Logger log = LoggerFactory.getLogger(ToscaCsarArtifactHandler.class);
+
+ private Map<String, ISdcCsarHelper> sdcCsarHelpers = new HashMap<>();
+
+ @Autowired
+ private SdcConnectorClient client;
+ @Autowired
+ private ToscaBuilderConfig config;
+
+
+ /**
+ * Retrieves a subset of the TOSCA model for the given version ID.
+ * If the model is not cached, a request to download the CSAR file is sent to SDC.
+ * @param modelVersionId
+ * @return Response containing a subset of the model data
+ * @throws ToscaCsarException
+ */
+ public SDCContextResponse getToscaModel(String modelVersionId) throws ToscaCsarException {
+
+ ISdcCsarHelper helper = sdcCsarHelpers.get(modelVersionId);
+ if(helper == null) {
+ log.debug("No CSAR file cached for " + modelVersionId);
+ helper = retrieveToscaCsarArtifact(modelVersionId);
+ if(helper != null) {
+ sdcCsarHelpers.put(modelVersionId, helper);
+ }
+ }
+
+ SDCContextResponse response = new SDCContextResponse();
+
+ if(helper == null) {
+ log.debug("CSAR artifact not found for model-version-id: " + modelVersionId);
+ response.setModelData("");
+ return response;
+ }
+
+ Gson gson = new GsonBuilder().create();
+ String modelData = gson.toJson(ToscaModelConverter.convert(helper));
+ response.setModelData(modelData);
+ return response;
+ }
+
+
+ /**
+ * Retrieves the CSAR file from SDC for the given model version ID
+ * @param modelVersionId
+ * @return Returns NULL if CSAR file couldn't be retrieved
+ * @throws ToscaCsarException
+ */
+ private ISdcCsarHelper retrieveToscaCsarArtifact(String modelVersionId) throws ToscaCsarException {
+
+ if (config.getTestToscaCsarFile() != null && !config.getTestToscaCsarFile().isEmpty()) {
+ return getSdcToscaContext(config.getTestToscaCsarFile());
+ }
+
+ String url = generateURL(modelVersionId);
+ log.debug("Downloading CSAR using URL suffix: " + url);
+
+ ArtifactInfo artifact = new ArtifactInfo();
+ artifact.setArtifactType(config.getArtifactType());
+ artifact.setArtifactURL(url);
+ artifact.setArtifactChecksum("value_not_used_by_sdc_distribution_client_lib");
+
+ String csarFile = generateTemporaryFile(modelVersionId);
+ try (OutputStream outputStream = Files.newOutputStream(Paths.get(csarFile), StandardOpenOption.CREATE);) {
+ IDistributionClientDownloadResult downloadResult = client.dowloadArtifact(artifact);
+ if (downloadResult.getDistributionActionResult() == DistributionActionResultEnum.ARTIFACT_NOT_FOUND) {
+ log.debug("Failed to retrieve CSAR artifact from SDC: " + downloadResult.getDistributionMessageResult());
+ return null;
+ } else if (downloadResult.getDistributionActionResult() != DistributionActionResultEnum.SUCCESS) {
+ throw new ToscaCsarException("Failed to retrieve CSAR artifact from SDC: " + downloadResult.getDistributionMessageResult());
+ }
+
+ byte[] payload = downloadResult.getArtifactPayload();
+ if ((payload == null) || (payload.length == 0)) {
+ log.debug("Retrieved CSAR payload is empty");
+ return null;
+ }
+ outputStream.write(payload);
+ } catch (IOException e){
+ throw new ToscaCsarException("Failed to write temporary CSAR file '" + csarFile + "'", e);
+ }
+
+ ISdcCsarHelper helper = getSdcToscaContext(csarFile);
+ try {
+ Files.delete(Paths.get(csarFile));
+ } catch (IOException e) {
+ log.error("Failed to delete temporary CSAR file '" + csarFile + "': " + e.getMessage());
+ }
+ return helper;
+ }
+
+
+ private String generateURL(String uuid) {
+ return MessageFormat.format(config.getUrlTemplate(), uuid);
+ }
+
+
+ /**
+ * Creates a temporary file for downloaded CSAR file
+ * @param uuid
+ * @return
+ * @throws ToscaCsarException
+ */
+ private String generateTemporaryFile(String uuid) throws ToscaCsarException {
+ try {
+ String fullPrefix = config.getCsarFilePrefix() + uuid + "-";
+ String suffix = (config.getCsarFileSuffix() == null ? DEFAULT_CSAR_FILE_EXTENSION : config.getCsarFileSuffix());
+ Path downloadFile = Files.createTempFile(fullPrefix, suffix);
+ log.debug("Temporary CSAR file name: " + downloadFile.toString());
+ return downloadFile.toString();
+ } catch (IOException e) {
+ throw new ToscaCsarException("Failed to create temporary CSAR file: " + e.getMessage());
+ }
+ }
+
+
+ /**
+ * Parses a CSAR file
+ * @param csarFile
+ * @return
+ * @throws ToscaCsarException
+ */
+ private ISdcCsarHelper getSdcToscaContext(String csarFile) throws ToscaCsarException {
+
+ log.info("Loading and parsing SDC csar file ...");
+ try {
+ SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
+ return factory.getSdcCsarHelper(csarFile);
+ } catch (SdcToscaParserException e) {
+ throw new ToscaCsarException("Failed to parse CSAR file", e);
+ }
+ }
+
+}
diff --git a/src/main/java/org/onap/pomba/contextbuilder/sdc/model/handlers/ToscaModelConverter.java b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/handlers/ToscaModelConverter.java
new file mode 100644
index 0000000..ba6a37b
--- /dev/null
+++ b/src/main/java/org/onap/pomba/contextbuilder/sdc/model/handlers/ToscaModelConverter.java
@@ -0,0 +1,147 @@
+/*
+ * ============LICENSE_START===================================================
+ * Copyright (c) 2018 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.
+ * ============LICENSE_END=====================================================
+ */
+package org.onap.pomba.contextbuilder.sdc.model.handlers;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.pomba.common.datatypes.ModelContext;
+import org.onap.pomba.common.datatypes.Service;
+import org.onap.pomba.common.datatypes.VF;
+import org.onap.pomba.common.datatypes.VFModule;
+import org.onap.pomba.common.datatypes.VNFC;
+import org.onap.pomba.contextbuilder.sdc.exception.ToscaCsarException;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.impl.SdcPropertyNames;
+import org.openecomp.sdc.toscaparser.api.Group;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.elements.Metadata;
+
+public class ToscaModelConverter {
+
+ private static final String PROPERTY_NAME_NFC_NAMING_CODE = "nfc_naming_code";
+
+ private ToscaModelConverter() {
+
+ }
+
+ /**
+ * Conversion from SDC model to the common model
+ * @param helper
+ * @return
+ * @throws ToscaCsarException
+ */
+ public static ModelContext convert(ISdcCsarHelper helper) throws ToscaCsarException {
+ ModelContext context = new ModelContext();
+ context.setService(generateService(helper.getServiceMetadata()));
+ context.setVf(generateVfList(helper));
+ return context;
+ }
+
+ /**
+ * Instantiates a service based on the SDC Service metadata
+ * @param serviceMetadata
+ * @return
+ * @throws ToscaCsarException
+ */
+ private static Service generateService(Metadata serviceMetadata) throws ToscaCsarException {
+ Service service = new Service();
+ if (serviceMetadata != null) {
+ service.setName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
+ service.setInvariantUuid(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+ service.setUuid(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+ }
+ return service;
+ }
+
+ /**
+ * Generates a list of VFs from the SDC VF-Resources
+ * @param helper
+ * @return
+ * @throws ToscaCsarException
+ */
+ private static List<VF> generateVfList(ISdcCsarHelper helper) throws ToscaCsarException {
+
+ List<VF> vfList = new ArrayList<>();
+ List<NodeTemplate> vfNodeTemplateList = helper.getServiceVfList();
+ for (NodeTemplate vfNodeTemplate : vfNodeTemplateList) {
+ VF vf = new VF();
+ vf.setName(vfNodeTemplate.getName());
+ vf.setType(vfNodeTemplate.getType());
+ vf.setInvariantUuid(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+ vf.setUuid(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+
+ String customizationUUID = vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
+ vf.setVnfc(generateVnfcList(helper.getVfcListByVf(customizationUUID)));
+ vf.setVfModules(generateVfModuleList(helper.getVfModulesByVf(customizationUUID)));
+
+ vfList.add(vf);
+ }
+ return vfList;
+ }
+
+ /**
+ * Generates a list of VFNCs from the SDC VF-Resources's VNFCs
+ * @param vfcNodeTemplateList
+ * @return
+ * @throws ToscaCsarException
+ */
+ private static List<VNFC> generateVnfcList(List<NodeTemplate> vfcNodeTemplateList) throws ToscaCsarException {
+ List<VNFC> vnfcList = new ArrayList<>();
+ for (NodeTemplate vfcNodeTemplate : vfcNodeTemplateList) {
+ VNFC vnfc = new VNFC();
+ vnfc.setName(vfcNodeTemplate.getName());
+ vnfc.setInvariantUuid(vfcNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+ vnfc.setUuid(vfcNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+
+ Object nfcNamingCode = vfcNodeTemplate.getPropertyValue(PROPERTY_NAME_NFC_NAMING_CODE);
+ if (nfcNamingCode != null) {
+ vnfc.setNfcNamingCode((String)nfcNamingCode);
+ }
+
+ vnfcList.add(vnfc);
+ }
+ return vnfcList;
+ }
+
+ /**
+ * Generates a list of VFModules from the SDC VF-Resource's VF-Modules
+ * @param vfModuleGroupList
+ * @return
+ * @throws ToscaCsarException
+ */
+ private static List<VFModule> generateVfModuleList(List<Group> vfModuleGroupList) throws ToscaCsarException {
+ List<VFModule> vfModuleList = new ArrayList<>();
+ for (Group moduleGroup : vfModuleGroupList) {
+ VFModule vfModule = new VFModule();
+ vfModule.setInvariantUuid(moduleGroup.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID));
+ vfModule.setUuid(moduleGroup.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
+
+ Object minInstances = moduleGroup.getPropertyValue(SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
+ if (minInstances != null) {
+ vfModule.setMinInstances((Integer)minInstances);
+ }
+ Object maxInstances = moduleGroup.getPropertyValue(SdcPropertyNames.PROPERTY_NAME_MINVFMODULEINSTANCES);
+ if (maxInstances != null) {
+ vfModule.setMaxInstances((Integer)maxInstances);
+ }
+
+ vfModuleList.add(vfModule);
+ }
+ return vfModuleList;
+ }
+}