diff options
author | priyanshu <pagarwal@amdocs.com> | 2018-09-05 18:05:36 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-09-13 13:00:27 +0000 |
commit | b65c8eeb334a2c579a2dc0241f480d81e9309f9c (patch) | |
tree | b3b3ed06b53703f771da51bec4b40e71b9e1bd1d /catalog-model | |
parent | f1e032cf4ae3505eb8acbce56ac978649d6f63d4 (diff) |
Interface operation support for service - BE
1. Interface operation support for service
2. Refactored common code of operationspa
3. ONAP Bug fixes VF operations
Change-Id: If1c4fd5f17626dbe568ee66ad997eb8ffb772e29
Issue-ID: SDC-1739
Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-model')
8 files changed, 244 insertions, 197 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java index 9e0b104986..6ba7a35836 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/config/CatalogModelSpringConfig.java @@ -10,6 +10,7 @@ import org.springframework.context.annotation.Configuration; "org.openecomp.sdc.be.model.cache", "org.openecomp.sdc.be.model.jsontitan.utils", "org.openecomp.sdc.be.model.jsontitan.operations", + "org.openecomp.sdc.be.dao.cassandra" }) public class CatalogModelSpringConfig { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java index 579dcdb074..115f084dbc 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Component.java @@ -66,6 +66,15 @@ public abstract class Component { private String derivedFromGenericVersion; private String toscaType; protected List<AdditionalInformationDefinition> additionalInformation; + private Map<String, InterfaceDefinition> interfaces; + + public Map<String, InterfaceDefinition> getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map<String, InterfaceDefinition> interfaces) { + this.interfaces = interfaces; + } public Component(ComponentMetadataDefinition componentMetadataDefinition) { this.componentMetadataDefinition = componentMetadataDefinition; @@ -545,6 +554,7 @@ public abstract class Component { result = prime * result + ((policies == null) ? 0 : policies.hashCode()); result = prime * result + ((derivedFromGenericType == null) ? 0 : derivedFromGenericType.hashCode()); result = prime * result + ((derivedFromGenericVersion == null) ? 0 : derivedFromGenericVersion.hashCode()); + result = prime * result + ((interfaces == null) ? 0 : interfaces.hashCode()); return result; } @@ -673,6 +683,14 @@ public abstract class Component { else if (!derivedFromGenericVersion.equals(other.derivedFromGenericVersion)) { return false; } + if (interfaces == null) { + if (other.interfaces != null) { + return false; + } + } + else if (!interfaces.equals(other.interfaces)) { + return false; + } return true; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java index 766cae4432..f3996ed42b 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/Resource.java @@ -23,7 +23,6 @@ package org.openecomp.sdc.be.model; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.utils.MapUtil; import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; @@ -43,8 +42,6 @@ public class Resource extends Component { private List<PropertyDefinition> attributes; - private Map<String, InterfaceDefinition> interfaces; - private List<String> defaultCapabilities; public Resource() { @@ -104,14 +101,6 @@ public class Resource extends Component { this.attributes = attributes; } - public Map<String, InterfaceDefinition> getInterfaces() { - return interfaces; - } - - public void setInterfaces(Map<String, InterfaceDefinition> interfaces) { - this.interfaces = interfaces; - } - public Boolean isAbstract() { return ((ResourceMetadataDataDefinition) getComponentMetadataDefinition().getMetadataDataDefinition()) .isAbstract(); @@ -158,7 +147,6 @@ public class Resource extends Component { result = prime * result + ((attributes == null) ? 0 : attributes.hashCode()); result = prime * result + ((defaultCapabilities == null) ? 0 : defaultCapabilities.hashCode()); result = prime * result + ((derivedFrom == null) ? 0 : derivedFrom.hashCode()); - result = prime * result + ((interfaces == null) ? 0 : interfaces.hashCode()); result = prime * result + ((properties == null) ? 0 : properties.hashCode()); result = prime * result + ((derivedList == null) ? 0 : derivedList.hashCode()); return result; @@ -194,11 +182,6 @@ public class Resource extends Component { return false; } else if (!derivedList.equals(other.derivedList)) return false; - if (interfaces == null) { - if (other.interfaces != null) - return false; - } else if (!interfaces.equals(other.interfaces)) - return false; if (properties == null) { if (other.properties != null) return false; @@ -210,7 +193,6 @@ public class Resource extends Component { @Override public String toString() { return "Resource [derivedFrom=" + derivedFrom + ", properties=" + properties + ", attributes=" + attributes - + ", interfaces=" + interfaces + ", defaultCapabilities=" + defaultCapabilities + ", additionalInformation=" + additionalInformation + "Metadata [" + getComponentMetadataDefinition().getMetadataDataDefinition().toString() + "]"; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java index 18bd13dce3..916a34c0f3 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfaceOperation.java @@ -17,7 +17,7 @@ package org.openecomp.sdc.be.model.jsontitan.operations; import fj.data.Either; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -71,7 +71,8 @@ public class InterfaceOperation extends BaseOperation { if (!isUpdateAction) { interfaceDefinition.setUniqueId(UUID.randomUUID().toString()); } - statusRes = performUpdateToscaAction(isUpdateAction, componentVertex, Arrays.asList(interfaceDefinition), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE); + statusRes = performUpdateToscaAction(isUpdateAction, componentVertex, + Collections.singletonList(interfaceDefinition), EdgeLabelEnum.INTERFACE, VertexTypeEnum.INTERFACE); if (!statusRes.equals(StorageOperationStatus.OK)) { return Either.right(statusRes); } @@ -107,8 +108,8 @@ public class InterfaceOperation extends BaseOperation { } GraphVertex interfaceVertex = getToscaElementInt.left().value(); - statusRes = performUpdateToscaAction(isUpdateAction, interfaceVertex, Arrays.asList(operation), - EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION); + statusRes = performUpdateToscaAction(isUpdateAction, interfaceVertex, + Collections.singletonList(operation), EdgeLabelEnum.INTERFACE_OPERATION, VertexTypeEnum.INTERFACE_OPERATION); if (!statusRes.equals(StorageOperationStatus.OK)) { return Either.right(statusRes); } @@ -126,7 +127,7 @@ public class InterfaceOperation extends BaseOperation { Either<GraphVertex, TitanOperationStatus> getInterfaceVertex; Either<GraphVertex, TitanOperationStatus> getComponentVertex; Operation operation = new Operation(); - StorageOperationStatus status = null; + StorageOperationStatus status; getComponentVertex = titanDao.getVertexById(componentId, JsonParseFlagEnum.NoParse); if (getComponentVertex.isRight()) { @@ -144,14 +145,16 @@ public class InterfaceOperation extends BaseOperation { Map.Entry<String, Operation> stringOperationEntry = operationToRemove.get(); operation = stringOperationEntry.getValue(); ArtifactDefinition implementationArtifact = operation.getImplementationArtifact(); - String artifactUUID = implementationArtifact.getArtifactUUID(); - CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID); - if (cassandraStatus != CassandraOperationStatus.OK) { - return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus)); + if(implementationArtifact != null){ + String artifactUUID = implementationArtifact.getArtifactUUID(); + CassandraOperationStatus cassandraStatus = artifactCassandraDao.deleteArtifact(artifactUUID); + if (cassandraStatus != CassandraOperationStatus.OK) { + return Either.right(DaoStatusConverter.convertCassandraStatusToStorageStatus(cassandraStatus)); + } } if(interfaceDef.getOperationsMap().size() > 1){ - status = deleteToscaDataElements(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, Arrays.asList(operationToDelete)); + status = deleteToscaDataElements(getInterfaceVertex.left().value(), EdgeLabelEnum.INTERFACE_OPERATION, Collections.singletonList(operationToDelete)); if (status != StorageOperationStatus.OK) { return Either.right(status); } @@ -164,7 +167,7 @@ public class InterfaceOperation extends BaseOperation { getUpdatedInterfaceDef(interfaceDef, null, operationToDelete); if (interfaceDef.getOperations().isEmpty()) { - status = deleteToscaDataElements(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, Arrays.asList(interfaceDef.getUniqueId())); + status = deleteToscaDataElements(getComponentVertex.left().value(), EdgeLabelEnum.INTERFACE, Collections.singletonList(interfaceDef.getUniqueId())); if (status != StorageOperationStatus.OK) { return Either.right(status); } @@ -192,7 +195,7 @@ public class InterfaceOperation extends BaseOperation { } } - private InterfaceDefinition getUpdatedInterfaceDef(InterfaceDefinition interfaceDef, Operation operation, String operationId){ + private void getUpdatedInterfaceDef(InterfaceDefinition interfaceDef, Operation operation, String operationId){ Map<String, Operation> operationMap = interfaceDef.getOperationsMap(); if(operation != null){ operationMap.put(operationId, operation); @@ -202,7 +205,6 @@ public class InterfaceOperation extends BaseOperation { operationMap.remove(operationId); interfaceDef.setOperationsMap(operationMap); } - return interfaceDef; } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java index 3b2cb97132..82dcfef1ee 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/utils/ModelConverter.java @@ -143,6 +143,8 @@ public class ModelConverter { convertServicePaths(topologyTemplate, service); + convertServiceInterfaces(topologyTemplate, service); + return service; } @@ -207,6 +209,17 @@ public class ModelConverter { resource.setInterfaces(copy); } + private static void convertServiceInterfaces(TopologyTemplate toscaElement, Service service) { + Map<String, InterfaceDataDefinition> interfaces = toscaElement.getInterfaces(); + Map<String, InterfaceDefinition> copy; + if (interfaces != null) { + copy = interfaces.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> new InterfaceDefinition(e.getValue()))); + } else { + copy = new HashMap<>(); + } + service.setInterfaces(copy); + } + private static void convertAttributes(NodeType nodeType, Resource resource) { Map<String, PropertyDataDefinition> attributes = nodeType.getAttributes(); if (attributes != null) { @@ -922,10 +935,21 @@ public class ModelConverter { topologyTemplate.setInterfaces(copy); } } + + private static void convertServiceInterfaces(Service service, TopologyTemplate topologyTemplate) { + Map<String, InterfaceDefinition> interfaces = service.getInterfaces(); + if (interfaces != null && !interfaces.isEmpty()) { + Map<String, InterfaceDataDefinition> copy = interfaces.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> new InterfaceDataDefinition(e.getValue()))); + topologyTemplate.setInterfaces(copy); + } + } + private static void convertServiceSpecificEntities(Service service, TopologyTemplate topologyTemplate) { convertServiceMetaData(service, topologyTemplate); convertServiceApiArtifacts(service, topologyTemplate); convertServicePaths(service,topologyTemplate); + convertServiceInterfaces(service, topologyTemplate); } private static void convertServicePaths(Service service, TopologyTemplate topologyTemplate) { diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java index f324cf83ad..0090f86f0e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiComponentDataTransfer.java @@ -20,8 +20,20 @@ package org.openecomp.sdc.be.ui.model; +import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.AdditionalInformationDefinition; +import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.CapabilityDefinition; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.ComponentInstanceInput; +import org.openecomp.sdc.be.model.ComponentInstanceProperty; +import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.InputDefinition; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.PolicyDefinition; +import org.openecomp.sdc.be.model.RequirementCapabilityRelDef; +import org.openecomp.sdc.be.model.RequirementDefinition; import org.openecomp.sdc.be.model.category.CategoryDefinition; import java.util.List; @@ -66,6 +78,25 @@ public class UiComponentDataTransfer { protected List<AdditionalInformationDefinition> additionalInformation; + private Map<String, InterfaceOperationDataDefinition> interfaceOperations; + private Map<String, InterfaceDefinition> interfaces; + + public Map<String, InterfaceOperationDataDefinition> getInterfaceOperations() { + return interfaceOperations; + } + + public void setInterfaceOperations(Map<String, InterfaceOperationDataDefinition> interfaceOperations) { + this.interfaceOperations = interfaceOperations; + } + + public Map<String, InterfaceDefinition> getInterfaces() { + return interfaces; + } + + public void setInterfaces(Map<String, InterfaceDefinition> interfaces) { + this.interfaces = interfaces; + } + public UiComponentDataTransfer() { } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java index 32e4b1002d..b3afd9617b 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UiResourceDataTransfer.java @@ -7,9 +7,9 @@ * 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. @@ -20,13 +20,10 @@ package org.openecomp.sdc.be.ui.model; -import org.openecomp.sdc.be.datatypes.elements.InterfaceOperationDataDefinition; import org.openecomp.sdc.be.model.AdditionalInformationDefinition; -import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import java.util.List; -import java.util.Map; public class UiResourceDataTransfer extends UiComponentDataTransfer{ @@ -40,11 +37,9 @@ public class UiResourceDataTransfer extends UiComponentDataTransfer{ private List<PropertyDefinition> attributes; - private Map<String, InterfaceDefinition> interfaces; private List<String> defaultCapabilities; - private Map<String, InterfaceOperationDataDefinition> interfaceOperations; public UiResourceDataTransfer(){} @@ -96,14 +91,6 @@ public class UiResourceDataTransfer extends UiComponentDataTransfer{ this.attributes = attributes; } - public Map<String, InterfaceDefinition> getInterfaces() { - return interfaces; - } - - public void setInterfaces(Map<String, InterfaceDefinition> interfaces) { - this.interfaces = interfaces; - } - public List<String> getDefaultCapabilities() { return defaultCapabilities; } @@ -111,12 +98,4 @@ public class UiResourceDataTransfer extends UiComponentDataTransfer{ public void setDefaultCapabilities(List<String> defaultCapabilities) { this.defaultCapabilities = defaultCapabilities; } - public Map<String, InterfaceOperationDataDefinition> getInterfaceOperations() { - return interfaceOperations; - } - - public void setInterfaceOperations(Map<String, InterfaceOperationDataDefinition> interfaceOperations) { - this.interfaceOperations = interfaceOperations; - } - } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java index f2aefa0aa3..375208d24e 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/InterfacesOperationTest.java @@ -1,15 +1,25 @@ package org.openecomp.sdc.be.model.jsontitan.operations; -import com.thinkaurelius.titan.core.TitanGraph; -import com.thinkaurelius.titan.core.TitanVertex; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + import fj.data.Either; -import org.junit.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Resource; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.junit.runner.RunWith; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.TitanDao; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.dao.titan.TitanGraphClient; import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition; import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition; @@ -19,145 +29,180 @@ import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.InterfaceDefinition; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.ModelTestBase; +import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.Service; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; import org.openecomp.sdc.be.model.jsontitan.datamodel.NodeType; import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate; import org.openecomp.sdc.be.model.jsontitan.utils.GraphTestUtils; -import org.openecomp.sdc.be.model.operations.api.IElementOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.common.util.ValidationUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import javax.annotation.Resource; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; -import java.util.*; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:application-context-test.xml") -public class InterfacesOperationTest extends ModelTestBase{ +public class InterfacesOperationTest extends ModelTestBase { @Resource protected TitanDao titanDao; + @Resource private InterfaceOperation interfaceOperation; - @Autowired - protected TitanGraphClient titanGraphClient; - @Resource protected NodeTypeOperation nodeTypeOperation; - @Autowired - protected ToscaOperationFacade toscaOperationFacade; @Resource protected TopologyTemplateOperation topologyTemplateOperation; - @Autowired - protected IElementOperation elementDao; - @Resource private ToscaElementLifecycleOperation lifecycleOperation; - protected static final String USER_ID = "jh0003"; - protected static final String VF_NAME = "VF_NAME"; - protected User user; + private static final String RESOURCE_NAME = "Resource Name"; + private static final String RESOURCE_ID = "resourceID"; - public static final String RESOURCE_CATEGORY = "Network Layer 2-3"; - public static final String RESOURCE_SUBCATEGORY = "Router"; - public static final String RESOURCE_NAME = "Resource Name"; + private static final String SERVICE_NAME = "Service Name"; + private static final String SERVICE_ID = "serviceID"; - private CategoryDefinition categoryDefinition; - private SubCategoryDefinition subCategoryDefinition = new SubCategoryDefinition(); - protected static final String RESOURCE_ID = "resourceID"; - protected static final String WORKFLOW_OPERATION_ID = "workflowOperationId"; - public static final String DERIVED_NAME = "derivedName"; - public static final String CSAR_UUID = "bla bla"; + private final String categoryName = "category"; + private final String subcategory = "mycategory"; + private GraphVertex ownerVertex; - String categoryName = "category"; - String subcategory = "mycategory"; - String outputDirectory = "C:\\Output"; + private final Service service = createService(); + private final org.openecomp.sdc.be.model.Resource resource = createResource(); @BeforeClass public static void initInterfacesOperation() { init(); } - private GraphVertex ownerVertex; - private GraphVertex modifierVertex; - private GraphVertex vfVertex; - private GraphVertex serviceVertex; - private GraphVertex rootVertex; - @Before public void setupBefore() { - clearGraph(); + GraphTestUtils.clearGraph(titanDao); createUsers(); createResourceCategory(); createServiceCategory(); GraphTestUtils.createRootCatalogVertex(titanDao); - rootVertex = createRootNodeType(); - createNodeType("firstVf"); - serviceVertex = createTopologyTemplate("firstService"); + createRootNodeType(); + createNodeType("resource", RESOURCE_ID); + createNodeType("service", SERVICE_ID); + createTopologyTemplate("firstService"); } @After public void cleanAfter() { - clearGraph(); + GraphTestUtils.clearGraph(titanDao); } @Test - public void testAddInterface() { - org.openecomp.sdc.be.model.Resource resource = createResource(); + public void testAddInterface_Service(){testAddInterface(service);} + + @Test + public void testAddInterface_Resource(){testAddInterface(resource);} + + @Test + public void testUpdateInterface_Service(){testUpdateInterface(service);} + + @Test + public void testUpdateInterface_Resource(){testUpdateInterface(resource);} + + @Test + public void testAddInterfaceOperation_Service(){testAddInterfaceOperation(service);} + + @Test + public void testAddInterfaceOperation_Resource(){testAddInterfaceOperation(resource);} + + @Test + public void testUpdateInterfaceOperation_Service(){testUpdateInterfaceOperation(service);} + + @Test + public void testUpdateInterfaceOperation_Resource(){testUpdateInterfaceOperation(resource);} + + @Test + public void testDeleteInterfaceOperation_Service(){testDeleteInterfaceOperation(service);} + + @Test + public void testDeleteInterfaceOperation_Resource(){testDeleteInterfaceOperation(resource);} + + @Test + public void testUpdateInterfaceShouldFailWhenNOtCreatedFirst() { + Component component = createResource(); InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); - Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(resource.getUniqueId(), + interfaceDefinition.setOperationsMap(createMockOperationMap()); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.updateInterface(component.getUniqueId(), + interfaceDefinition); + Assert.assertTrue(res.isRight()); + } + + private void testAddInterface(Component component) { + InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); Assert.assertTrue(res.isLeft()); } - @Test - public void testUpdateInterface() { - org.openecomp.sdc.be.model.Resource resource = createResource(); + private void testUpdateInterface(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); interfaceDefinition.setOperationsMap(createMockOperationMap()); - Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(resource.getUniqueId(), - interfaceDefinition); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); Assert.assertTrue(res.isLeft()); InterfaceDefinition value = res.left().value(); String new_description = "New Description"; value.setDescription(new_description); - res = interfaceOperation.updateInterface(resource.getUniqueId(), - interfaceDefinition); + res = interfaceOperation.updateInterface(component.getUniqueId(), interfaceDefinition); assertTrue(res.isLeft()); assertEquals(new_description,res.left().value().getDescription()); } - @Test - public void testUpdateInterfaceShouldFailWhenNOtCreatedFirst() { - org.openecomp.sdc.be.model.Resource resource = createResource(); + private void testAddInterfaceOperation(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); - interfaceDefinition.setOperationsMap(createMockOperationMap()); - Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.updateInterface(resource.getUniqueId(), - interfaceDefinition); - Assert.assertTrue(res.isRight()); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); + Assert.assertTrue(res.isLeft()); + InterfaceDefinition value = res.left().value(); + Operation op = createMockOperation(); + Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op); + assertTrue(addInterfaceOperationRes.isLeft()); + } + + private void testUpdateInterfaceOperation(Component component) { + InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); + Assert.assertTrue(res.isLeft()); + InterfaceDefinition value = res.left().value(); + Operation op = createMockOperation(); + Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op); + Assert.assertTrue(addInterfaceOperationRes.isLeft()); + Operation resultOp = addInterfaceOperationRes.left().value(); + resultOp.setName("New_Create"); + Either<Operation, StorageOperationStatus> updateInterfaceOperationRes = interfaceOperation.updateInterfaceOperation(component.getUniqueId(), value, resultOp); + assertTrue(updateInterfaceOperationRes.isLeft()); + assertEquals("New_Create", updateInterfaceOperationRes.left().value().getName()); + } + + private void testDeleteInterfaceOperation(Component component) { + InterfaceDefinition interfaceDefinition = buildInterfaceDefinition(); + Either<InterfaceDefinition, StorageOperationStatus> res = interfaceOperation.addInterface(component.getUniqueId(), interfaceDefinition); + Assert.assertTrue(res.isLeft()); + InterfaceDefinition value = res.left().value(); + Operation op = createMockOperation(); + Either<Operation, StorageOperationStatus> addInterfaceOperationRes = interfaceOperation.addInterfaceOperation(component.getUniqueId(), value, op); + Assert.assertTrue(addInterfaceOperationRes.isLeft()); + Operation resultOp = addInterfaceOperationRes.left().value(); + Either<Operation, StorageOperationStatus> deleteInterfaceOperationRes = interfaceOperation.deleteInterfaceOperation(component.getUniqueId(), value, resultOp.getUniqueId()); + assertTrue(deleteInterfaceOperationRes.isLeft()); } private InterfaceDefinition buildInterfaceDefinition() { InterfaceDefinition interfaceDefinition = new InterfaceDefinition(); interfaceDefinition.setType("tosca.interfaces.standard"); - interfaceDefinition.setCreationDate(new Long(101232)); - - + interfaceDefinition.setCreationDate(101232L); return interfaceDefinition; } @@ -165,12 +210,19 @@ public class InterfacesOperationTest extends ModelTestBase{ org.openecomp.sdc.be.model.Resource resource = new org.openecomp.sdc.be.model.Resource(); resource.setUniqueId(RESOURCE_ID); resource.setName(RESOURCE_NAME); - resource.addCategory(RESOURCE_CATEGORY, RESOURCE_SUBCATEGORY); resource.setDescription("My short description"); resource.setInterfaces(createMockInterfaceDefinition()); return resource; } + private Service createService() { + Service service = new Service(); + service.setUniqueId(SERVICE_ID); + service.setName(SERVICE_NAME); + service.setDescription("My short description"); + service.setInterfaces(createMockInterfaceDefinition()); + return service; + } private InterfaceDefinition createInterface(String uniqueID, String description, String type, String toscaResourceName, Map<String, Operation> op) { @@ -188,24 +240,24 @@ public class InterfacesOperationTest extends ModelTestBase{ Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>(); interfaceDefinitionMap.put("int1", createInterface("int1", "Interface 1", "lifecycle", "tosca", operationMap)); - return interfaceDefinitionMap; } private Map<String, Operation> createMockOperationMap() { - Operation operation = new Operation(); - operation.setDefinition(false); - operation.setName("create"); Map<String, Operation> operationMap = new HashMap<>(); - operationMap.put("op1", operation); + operationMap.put("op1", createMockOperation()); return operationMap; } - - + private Operation createMockOperation() { + Operation operation = new Operation(); + operation.setDefinition(false); + operation.setName("create"); + operation.setUniqueId("op1"); + return operation; + } private void createResourceCategory() { - GraphVertex cat = new GraphVertex(VertexTypeEnum.RESOURCE_CATEGORY); Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>(); String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.RESOURCE_CATEGORY); @@ -229,15 +281,11 @@ public class InterfacesOperationTest extends ModelTestBase{ subCat.updateMetadataJsonWithCurrentMetadataProperties(); Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat); - Either<GraphVertex, TitanOperationStatus> subCatRes = titanDao.createVertex(subCat); - - TitanOperationStatus status = titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>()); - assertEquals(TitanOperationStatus.OK, status); + titanDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), EdgeLabelEnum.SUB_CATEGORY, new HashMap<>()); } private void createServiceCategory() { - GraphVertex cat = new GraphVertex(VertexTypeEnum.SERVICE_CATEGORY); Map<GraphPropertyEnum, Object> metadataProperties = new HashMap<>(); String catId = UniqueIdBuilder.buildComponentCategoryUid(categoryName, VertexTypeEnum.SERVICE_CATEGORY); @@ -248,14 +296,10 @@ public class InterfacesOperationTest extends ModelTestBase{ metadataProperties.put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName)); cat.setMetadataProperties(metadataProperties); cat.updateMetadataJsonWithCurrentMetadataProperties(); - - Either<GraphVertex, TitanOperationStatus> catRes = titanDao.createVertex(cat); - - assertTrue(catRes.isLeft()); + titanDao.createVertex(cat); } - private GraphVertex createTopologyTemplate(String name) { - + private void createTopologyTemplate(String name) { TopologyTemplate service = new TopologyTemplate(); String uniqueId = UniqueIdBuilder.buildResourceUniqueId(); service.setUniqueId(uniqueId); @@ -273,20 +317,13 @@ public class InterfacesOperationTest extends ModelTestBase{ service.setComponentType(ComponentTypeEnum.SERVICE); Either<TopologyTemplate, StorageOperationStatus> createRes = topologyTemplateOperation.createTopologyTemplate(service); - assertTrue(createRes.isLeft()); - Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createRes.left().value().getUniqueId()); - assertTrue(getNodeTyeRes.isLeft()); - // serviceVertex = getNodeTyeRes.left().value(); - - return getNodeTyeRes.left().value(); + getNodeTyeRes.left().value(); } - private <T extends ToscaDataDefinition> NodeType createNodeType(String nodeTypeName) { - + private <T extends ToscaDataDefinition> void createNodeType(String nodeTypeName, String uniqueId) { NodeType vf = new NodeType(); - String uniqueId = RESOURCE_ID; // UniqueIdBuilder.buildResourceUniqueId(); vf.setUniqueId(uniqueId); vf.setCreatorUserId((String) ownerVertex.getMetadataProperty(GraphPropertyEnum.USERID)); vf.getMetadata().put(JsonPresentationFields.NAME.getPresentation(), nodeTypeName); @@ -308,15 +345,13 @@ public class InterfacesOperationTest extends ModelTestBase{ List<String> derivedFrom = new ArrayList<>(); derivedFrom.add("root"); vf.setDerivedFrom(derivedFrom); - vf.setComponentType(ComponentTypeEnum.RESOURCE); + vf.setComponentType(ComponentTypeEnum.RESOURCE); Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf); - assertTrue(createVFRes.isLeft()); Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId()); - assertTrue(getNodeTyeRes.isLeft()); - vfVertex = getNodeTyeRes.left().value(); + GraphVertex vfVertex = getNodeTyeRes.left().value(); List<PropertyDataDefinition> addProperties = new ArrayList<>(); PropertyDataDefinition prop11 = new PropertyDataDefinition(); @@ -331,21 +366,21 @@ public class InterfacesOperationTest extends ModelTestBase{ addProperties.add(prop22); StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME); - assertTrue(status == StorageOperationStatus.OK); + assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition prop33 = new PropertyDataDefinition(); prop33.setName("prop33"); prop33.setDefaultValue("def33"); status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME); - assertTrue(status == StorageOperationStatus.OK); + assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition prop44 = new PropertyDataDefinition(); prop44.setName("prop44"); prop44.setDefaultValue("def44"); status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME); - assertTrue(status == StorageOperationStatus.OK); + assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition capProp = new PropertyDataDefinition(); capProp.setName("capProp"); @@ -354,20 +389,19 @@ public class InterfacesOperationTest extends ModelTestBase{ MapDataDefinition dataToCreate = new MapPropertiesDataDefinition(); dataToCreate.put("capProp", capProp); - Map<String, MapDataDefinition> capProps = new HashMap(); + Map<String, MapDataDefinition> capProps = new HashMap<>(); capProps.put("capName", dataToCreate); - Either<GraphVertex, StorageOperationStatus> res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps); + nodeTypeOperation.associateElementToData( + vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps); List<String> pathKeys = new ArrayList<>(); pathKeys.add("capName"); capProp.setDefaultValue("BBBB"); - status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME); - return vf; + nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME); } - private GraphVertex createRootNodeType() { - + private void createRootNodeType() { NodeType vf = new NodeType(); String uniqueId = UniqueIdBuilder.buildResourceUniqueId(); vf.setUniqueId(uniqueId); @@ -399,7 +433,6 @@ public class InterfacesOperationTest extends ModelTestBase{ PropertyDataDefinition prop1 = new PropertyDataDefinition(); prop1.setName("derived1"); prop1.setDefaultValue("deriveddef1"); - properties.put("derived1", prop1); PropertyDataDefinition prop2 = new PropertyDataDefinition(); @@ -415,15 +448,12 @@ public class InterfacesOperationTest extends ModelTestBase{ vf.setProperties(properties); vf.setComponentType(ComponentTypeEnum.RESOURCE); Either<NodeType, StorageOperationStatus> createVFRes = nodeTypeOperation.createNodeType(vf); - assertTrue(createVFRes.isLeft()); Either<GraphVertex, TitanOperationStatus> getNodeTyeRes = titanDao.getVertexById(createVFRes.left().value().getUniqueId()); - assertTrue(getNodeTyeRes.isLeft()); - return getNodeTyeRes.left().value(); + getNodeTyeRes.left().value(); } private void createUsers() { - GraphVertex ownerV = new GraphVertex(VertexTypeEnum.USER); ownerV.setUniqueId("user1"); @@ -435,7 +465,6 @@ public class InterfacesOperationTest extends ModelTestBase{ ownerV.updateMetadataJsonWithCurrentMetadataProperties(); ownerV.setJson(new HashMap<>()); Either<GraphVertex, TitanOperationStatus> createUserRes = titanDao.createVertex(ownerV); - assertTrue(createUserRes.isLeft()); ownerVertex = createUserRes.left().value(); @@ -450,33 +479,14 @@ public class InterfacesOperationTest extends ModelTestBase{ modifierV.updateMetadataJsonWithCurrentMetadataProperties(); modifierV.setJson(new HashMap<>()); createUserRes = titanDao.createVertex(modifierV); - assertTrue(createUserRes.isLeft()); - - modifierVertex = createUserRes.left().value(); - - Either<GraphVertex, TitanOperationStatus> getOwnerRes = lifecycleOperation.findUser(ownerVertex.getUniqueId()); - assertTrue(getOwnerRes.isLeft()); + createUserRes.left().value(); + lifecycleOperation.findUser(ownerVertex.getUniqueId()); } @After public void teardown() { - clearGraph(); - } - - private void clearGraph() { - Either<TitanGraph, TitanOperationStatus> graphResult = titanDao.getGraph(); - TitanGraph graph = graphResult.left().value(); - - Iterable<TitanVertex> vertices = graph.query().vertices(); - if (vertices != null) { - Iterator<TitanVertex> iterator = vertices.iterator(); - while (iterator.hasNext()) { - TitanVertex vertex = iterator.next(); - vertex.remove(); - } - } - titanDao.commit(); + GraphTestUtils.clearGraph(titanDao); } } |