summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main/java
diff options
context:
space:
mode:
authorzhaoxiangjun666 <xjzhaop@isoftstone.com>2020-09-10 14:01:50 +0800
committerzhaoxiangjun666 <xjzhaop@isoftstone.com>2020-09-21 20:39:48 +0800
commita8d3e1b8c759c21227690a425552a245da883e97 (patch)
tree4e9731f7e7c4df8088187e7501a0d9a8a516f215 /catalog-model/src/main/java
parent591810df468a8e2c59569e701f514bff61203940 (diff)
Support for Test Topology Auto Design- Service Import
Add some test code and use lombok in catalog-model Test Topology Auto Design (NFV Testing Automatic Platform) Delete useless test code and add test code for new function Issue-ID: SDC-3179 Issue-ID: SDC-3085 Signed-off-by: zhaoxiangjun666 <xjzhaop@isoftstone.com> Change-Id: I7f555633a00848c273014caa18ea0e30d0b22113
Diffstat (limited to 'catalog-model/src/main/java')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java21
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java144
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java19
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java98
4 files changed, 279 insertions, 3 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java
index 3e33fd490c..2e326ce691 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Service.java
@@ -46,6 +46,7 @@ public class Service extends Component {
private Map<String, ArtifactDefinition> serviceApiArtifacts;
private Map<String, ForwardingPathDataDefinition> forwardingPaths;
+ private String toscaServiceName;
public Service() {
super(new ServiceMetadataDefinition());
@@ -178,4 +179,24 @@ public class Service extends Component {
public void setSpecificComponetTypeArtifacts(Map<String, ArtifactDefinition> specificComponentTypeArtifacts) {
setServiceApiArtifacts(specificComponentTypeArtifacts);
}
+
+
+ public void setServiceVendorModelNumber(String serviceVendorModelNumber) {
+ getServiceMetadataDefinition().setServiceVendorModelNumber(serviceVendorModelNumber);
+ }
+
+ public void setAbstract(Boolean isAbstract) {
+ ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
+ .setIsAbstract(isAbstract);
+ }
+
+ public void setVendorName(String vendorName) {
+ ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
+ .setVendorName(vendorName);
+ }
+
+ public void setVendorRelease(String vendorRelease) {
+ ((ServiceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition())
+ .setVendorRelease(vendorRelease);
+ }
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java
new file mode 100644
index 0000000000..29d6fa40fd
--- /dev/null
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadServiceInfo.java
@@ -0,0 +1,144 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 CMCC Intellectual Property. 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=========================================================
+ */
+
+package org.openecomp.sdc.be.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.common.api.UploadArtifactInfo;
+
+@Getter
+@Setter
+public class UploadServiceInfo {
+
+ private String payloadData;
+ private String payloadName;
+ private String description;
+ private List<String> tags;
+ private List<CategoryDefinition> categories;
+
+ private String invariantUUID;
+ private String UUID;
+ private String type;
+ private String category;
+ private String subcategory;
+ private String resourceVendor;
+ private String resourceVendorRelease;
+ private String serviceRole;
+ private String serviceEcompNaming;
+ private String ecompGeneratedNaming;
+ private String namingPolicy;
+ private String projectCode;
+
+
+ private List<UploadArtifactInfo> artifactList;
+ private String contactId, name, serviceIconPath, icon, vendorName, vendorRelease, serviceVendorModelNumber;
+
+ private String serviceType = "";
+
+ public UploadServiceInfo(String payloadData, String payloadName, String description,
+ List<String> tags, String invariantUUID, String UUID, String type,
+ String category, String subcategory, String resourceVendor,
+ String resourceVendorRelease, String serviceRole, String serviceEcompNaming,
+ String ecompGeneratedNaming, String namingPolicy,
+ List<UploadArtifactInfo> artifactList, String contactId, String name,
+ String resourceIconPath, String icon, String vendorName, String vendorRelease,
+ String serviceVendorModelNumber, String serviceType, String projectCode) {
+ this.payloadData = payloadData;
+ this.payloadName = payloadName;
+ this.description = description;
+ this.tags = tags;
+ this.invariantUUID = invariantUUID;
+ this.UUID = UUID;
+ this.type = type;
+ this.category = category;
+ this.subcategory = subcategory;
+ this.resourceVendor = resourceVendor;
+ this.resourceVendorRelease = resourceVendorRelease;
+ this.serviceRole = serviceRole;
+ this.serviceEcompNaming = serviceEcompNaming;
+ this.ecompGeneratedNaming = ecompGeneratedNaming;
+ this.namingPolicy = namingPolicy;
+ this.artifactList = artifactList;
+ this.contactId = contactId;
+ this.name = name;
+ this.serviceIconPath = serviceIconPath;
+ this.icon = icon;
+ this.vendorName = vendorName;
+ this.vendorRelease = vendorRelease;
+ this.serviceVendorModelNumber = serviceVendorModelNumber;
+ this.serviceType = serviceType;
+ this.projectCode = projectCode;
+
+ if (category != null) {
+ String[] arr = category.split("/");
+ if (arr.length >= 2) {
+ categories = new ArrayList<>();
+ CategoryDefinition catDef = new CategoryDefinition();
+ catDef.setName(arr[0]);
+ SubCategoryDefinition subCat = new SubCategoryDefinition();
+ subCat.setName(arr[1]);
+ catDef.addSubCategory(subCat);
+ categories.add(catDef);
+ }
+ }
+ }
+
+ public UploadServiceInfo() {
+ }
+ public void addSubCategory(String category, String subCategory) {
+ if (category != null || subCategory != null) {
+ if (categories == null) {
+ categories = new ArrayList<>();
+ }
+ CategoryDefinition selectedCategory = null;
+ for (CategoryDefinition categoryDef : categories) {
+ if (categoryDef.getName().equals(category)) {
+ selectedCategory = categoryDef;
+ }
+ }
+ if (selectedCategory == null) {
+ selectedCategory = new CategoryDefinition();
+ selectedCategory.setName(category);
+ categories.add(selectedCategory);
+ }
+ List<SubCategoryDefinition> subcategories = selectedCategory.getSubcategories();
+ if (subcategories == null) {
+ subcategories = new ArrayList<>();
+ selectedCategory.setSubcategories(subcategories);
+ }
+ SubCategoryDefinition selectedSubcategory = null;
+ for (SubCategoryDefinition subcategory : subcategories) {
+ if (subcategory.getName().equals(subCategory)) {
+ selectedSubcategory = subcategory;
+ }
+ }
+ if (selectedSubcategory == null) {
+ selectedSubcategory = new SubCategoryDefinition();
+ selectedSubcategory.setName(subCategory);
+ subcategories.add(selectedSubcategory);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
index 7a399a1f69..5fb07a01b3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperation.java
@@ -776,8 +776,14 @@ public class NodeTemplateOperation extends BaseOperation {
listCapabilities.forEach(cap -> {
cap.setSource(componentInstance.getComponentUid());
cap.addToPath(componentInstance.getUniqueId());
+ log.debug("enter populateCapability,get Capability OwnerId:{},get componentInstance UniqueId:{}",
+ cap.getOwnerId(), componentInstance.getUniqueId());
cap.setOwnerId(componentInstance.getUniqueId());
- cap.setOwnerName(componentInstance.getName());
+ log.debug("enter populateCapability,get Capability OwnerName:{},get componentInstance Name:{}",
+ cap.getOwnerName(), componentInstance.getName());
+ if (cap.getOwnerName() == null || cap.getOwnerName().isEmpty()) {
+ cap.setOwnerName(componentInstance.getName());
+ }
cap.setLeftOccurrences(cap.getMaxOccurrences());
allCalculatedCap.add(key, cap);
});
@@ -803,8 +809,15 @@ public class NodeTemplateOperation extends BaseOperation {
listRequirements.forEach(req -> {
req.setSource(componentInstance.getComponentUid());
req.addToPath(componentInstance.getUniqueId());
- req.setOwnerId(componentInstance.getUniqueId());
- req.setOwnerName(componentInstance.getName());
+ log.debug("enter populateRequirement,get init Requirements OwnerId:{},get componentInstance UniqueId:{}",
+ req.getOwnerId(), componentInstance.getUniqueId());
+ if (req.getOwnerId() == null || req.getOwnerId().isEmpty()) {
+ req.setOwnerId(componentInstance.getUniqueId());
+ }
+ log.debug("enter populateRequirement,get init Requirements OwnerName:{}", req.getOwnerName());
+ if (req.getOwnerName() == null || req.getOwnerName().isEmpty()) {
+ req.setOwnerName(componentInstance.getName());
+ }
req.setLeftOccurrences(req.getMaxOccurrences());
allCalculatedReq.add(key, req);
});
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
index dc9174e464..50b2ae45b4 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java
@@ -405,6 +405,52 @@ public class ToscaOperationFacade {
}
);
}
+
+ public Either<Resource, StorageOperationStatus> getLatestResourceByToscaResourceName(String toscaResourceName) {
+ if (toscaResourceName != null && toscaResourceName.contains("org.openecomp.resource.vf"))
+ return getLatestResourceByToscaResourceName(toscaResourceName, VertexTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.ParseMetadata);
+ else
+ return getLatestResourceByToscaResourceName(toscaResourceName, VertexTypeEnum.NODE_TYPE, JsonParseFlagEnum.ParseMetadata);
+ }
+
+ public Either<Resource, StorageOperationStatus> getLatestResourceByToscaResourceName(String toscaResourceName, VertexTypeEnum vertexType, JsonParseFlagEnum parseFlag) {
+
+ Either<Resource, StorageOperationStatus> result = null;
+ Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
+ props.put(GraphPropertyEnum.TOSCA_RESOURCE_NAME, toscaResourceName);
+ props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true);
+ if (!toscaResourceName.contains("org.openecomp.resource.vf")) {
+ props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+ }
+
+ Either<List<GraphVertex>, JanusGraphOperationStatus> getLatestRes = janusGraphDao.getByCriteria(vertexType, props, parseFlag);
+
+ if (getLatestRes.isRight()) {
+ JanusGraphOperationStatus status = getLatestRes.right().value();
+ CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, "Failed to fetch {} with name {}. status={} ", vertexType, toscaResourceName, status);
+ result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
+ }
+ if (result == null) {
+ List<GraphVertex> resources = getLatestRes.left().value();
+ double version = 0.0;
+ GraphVertex highestResource = null;
+ for (GraphVertex resource : resources) {
+ double resourceVersion = Double.parseDouble((String) resource.getJsonMetadataField(JsonPresentationFields.VERSION));
+ if (resourceVersion > version) {
+ version = resourceVersion;
+ highestResource = resource;
+ }
+ }
+
+ if (highestResource != null) {
+ result = getToscaFullElement(highestResource.getUniqueId());
+ } else {
+ log.debug("The vertex with the highest version could not be found for {}", toscaResourceName);
+ result = Either.right(StorageOperationStatus.GENERAL_ERROR);
+ }
+ }
+ return result;
+ }
public Either<Boolean, StorageOperationStatus> validateToscaResourceNameExists(String templateName) {
Either<Boolean, StorageOperationStatus> validateUniquenessRes = validateToscaResourceNameUniqueness(templateName);
@@ -1429,6 +1475,53 @@ public class ToscaOperationFacade {
return Optional.empty();
}
+ public StorageOperationStatus associateCapabilitiesToService(Map<String,ListCapabilityDataDefinition> capabilities, String componentId) {
+
+ Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug(COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, componentId, getVertexEither.right().value());
+ return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getVertexEither.right().value());
+
+ }
+
+ GraphVertex vertex = getVertexEither.left().value();
+ if(MapUtils.isNotEmpty(capabilities)) {
+ Either<GraphVertex, StorageOperationStatus> associateElementToData = topologyTemplateOperation.
+ associateElementToData(vertex, VertexTypeEnum.CAPABILITIES,
+ EdgeLabelEnum.CAPABILITIES, capabilities);
+ if (associateElementToData.isRight()) {
+ return associateElementToData.right().value();
+ }
+ }
+
+
+ return StorageOperationStatus.OK;
+
+ }
+
+ public StorageOperationStatus associateRequirementsToService(Map<String, ListRequirementDataDefinition> requirements, String componentId) {
+
+ Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(componentId, JsonParseFlagEnum.NoParse);
+ if (getVertexEither.isRight()) {
+ log.debug(COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, componentId, getVertexEither.right().value());
+ return DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getVertexEither.right().value());
+
+ }
+
+ GraphVertex vertex = getVertexEither.left().value();
+ if(MapUtils.isNotEmpty(requirements)) {
+ Either<GraphVertex, StorageOperationStatus> associateElementToData = topologyTemplateOperation.
+ associateElementToData(vertex, VertexTypeEnum.REQUIREMENTS,
+ EdgeLabelEnum.REQUIREMENTS, requirements);
+ if (associateElementToData.isRight()) {
+ return associateElementToData.right().value();
+ }
+ }
+
+ return StorageOperationStatus.OK;
+
+ }
+
public StorageOperationStatus associateDeploymentArtifactsToInstances(Map<String, Map<String, ArtifactDefinition>> instDeploymentArtifacts, Component component, User user) {
Either<GraphVertex, JanusGraphOperationStatus> getVertexEither = janusGraphDao.getVertexById(component.getUniqueId(), JsonParseFlagEnum.NoParse);
@@ -2886,4 +2979,9 @@ public class ToscaOperationFacade {
topologyTemplateOperation
.updateCapReqPropertiesOwnerId(componentId, getTopologyTemplate(componentId));
}
+
+ public <T extends Component> Either<T, StorageOperationStatus> getLatestByServiceName(String serviceName) {
+ return getLatestByName(GraphPropertyEnum.NAME, serviceName);
+
+ }
}