From ade7fd243fe41b5056ba63d3584ea616ee8bf808 Mon Sep 17 00:00:00 2001 From: shrek2000 Date: Tue, 29 Jan 2019 13:04:42 +0200 Subject: Add dependent child service to service Add dependent child service to service Issue-ID: SDC-1987 Change-Id: Ic542fe1bc13f2b77df9944f05421a42b4b21c437 Signed-off-by: shrek2000 --- .../java/org/openecomp/sdc/be/model/Component.java | 13 ++ .../openecomp/sdc/be/model/ComponentInstance.java | 11 ++ .../be/model/UploadNodeFilterCapabilitiesInfo.java | 40 +++++ .../sdc/be/model/UploadNodeFilterInfo.java | 62 +++++++ .../sdc/be/model/UploadNodeFilterPropertyInfo.java | 48 ++++++ .../jsontitan/operations/NodeFilterOperation.java | 179 +++++++++++++++++++++ .../be/model/tosca/constraints/ConstraintType.java | 2 + .../openecomp/sdc/be/ui/model/UIConstraint.java | 117 ++++++++++++++ .../openecomp/sdc/be/ui/model/UINodeFilter.java | 31 ++++ 9 files changed, 503 insertions(+) create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterCapabilitiesInfo.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterInfo.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterPropertyInfo.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeFilterOperation.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java create mode 100644 catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UINodeFilter.java (limited to 'catalog-model/src') 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 115f084dbc..7c5368887b 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,7 @@ public abstract class Component { private String derivedFromGenericVersion; private String toscaType; protected List additionalInformation; + protected List properties; private Map interfaces; public Map getInterfaces() { @@ -533,6 +534,14 @@ public abstract class Component { this.policies = policies; } + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } + @Override public int hashCode() { final int prime = 31; @@ -555,6 +564,7 @@ public abstract class Component { result = prime * result + ((derivedFromGenericType == null) ? 0 : derivedFromGenericType.hashCode()); result = prime * result + ((derivedFromGenericVersion == null) ? 0 : derivedFromGenericVersion.hashCode()); result = prime * result + ((interfaces == null) ? 0 : interfaces.hashCode()); + result = prime * result + ((properties == null) ? 0 : properties.hashCode()); return result; } @@ -691,6 +701,9 @@ public abstract class Component { else if (!interfaces.equals(other.interfaces)) { return false; } + else if (!properties.equals(other.properties)) { + return false; + } return true; } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java index 4a622866ff..ef9b409735 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/ComponentInstance.java @@ -23,6 +23,7 @@ package org.openecomp.sdc.be.model; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertiesOwner; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; +import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import java.util.Collections; import java.util.List; @@ -35,6 +36,7 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement private Map deploymentArtifacts; private Map artifacts; private List groupInstances; + private CINodeFilterDataDefinition nodeFilter; public ComponentInstance() { super(); @@ -106,4 +108,13 @@ public class ComponentInstance extends ComponentInstanceDataDefinition implement } return safeGetInformationalArtifacts().get(artifactLabel) != null; } + + public CINodeFilterDataDefinition getNodeFilter() { + return nodeFilter; + } + + public void setNodeFilter(CINodeFilterDataDefinition nodeFilter) { + this.nodeFilter = nodeFilter; + } + } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterCapabilitiesInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterCapabilitiesInfo.java new file mode 100644 index 0000000000..2339534266 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterCapabilitiesInfo.java @@ -0,0 +1,40 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ +package org.openecomp.sdc.be.model; + +import java.util.List; + +public class UploadNodeFilterCapabilitiesInfo { + + private String name; + private List properties; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterInfo.java new file mode 100644 index 0000000000..2b228d930c --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterInfo.java @@ -0,0 +1,62 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.model; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class UploadNodeFilterInfo { + + private String name; + private Object tosca_id; + private List properties = new ArrayList<>(); + private Map capabilities = new HashMap<>(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } + + public Map getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map capabilities) { + this.capabilities = capabilities; + } + + public Object getTosca_id() { + return tosca_id; + } + + public void setTosca_id(Object tosca_id) { + this.tosca_id = tosca_id; + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterPropertyInfo.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterPropertyInfo.java new file mode 100644 index 0000000000..ea94ca23e4 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/UploadNodeFilterPropertyInfo.java @@ -0,0 +1,48 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ +package org.openecomp.sdc.be.model; + +import java.util.List; + +public class UploadNodeFilterPropertyInfo { + + private String name; + private List values; + + public UploadNodeFilterPropertyInfo() { + } + + public UploadNodeFilterPropertyInfo(String name, List value) { + this.name = name; + this.values = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getValues() { + return values; + } + + public void setValue(List values) { + this.values = values; + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeFilterOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeFilterOperation.java new file mode 100644 index 0000000000..989708c8d6 --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsontitan/operations/NodeFilterOperation.java @@ -0,0 +1,179 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T 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.jsontitan.operations; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import fj.data.Either; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.dao.titan.TitanOperationStatus; +import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition; +import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter; +import org.openecomp.sdc.common.jsongraph.util.CommonUtility; +import org.openecomp.sdc.common.log.elements.LoggerFactory; +import org.openecomp.sdc.common.log.wrappers.Logger; + +@org.springframework.stereotype.Component("service-filter-operations") +public class NodeFilterOperation extends BaseOperation { + + private static Logger logger = LoggerFactory.getLogger(NodeFilterOperation.class, + org.slf4j.LoggerFactory.getLogger(NodeFilterOperation.class)); + + public Either, StorageOperationStatus> deleteNodeFilters(Service service, + Set componentInstanceIds) { + Either getComponentVertex; + Either getNodeFilterVertex; + StorageOperationStatus status; + + getComponentVertex = titanDao.getVertexById(service.getUniqueId(), JsonParseFlagEnum.NoParse); + if (getComponentVertex.isRight()) { + return Either.right( + DaoStatusConverter.convertTitanStatusToStorageStatus(getComponentVertex.right().value())); + } + + getNodeFilterVertex = + titanDao.getChildVertex(getComponentVertex.left().value(), EdgeLabelEnum.NODE_FILTER_TEMPLATE, + JsonParseFlagEnum.NoParse); + if (getNodeFilterVertex.isLeft()) { + status = deleteToscaDataElements(service.getUniqueId(), EdgeLabelEnum.NODE_FILTER_TEMPLATE, + new ArrayList<>(componentInstanceIds)); + if (status != StorageOperationStatus.OK) { + return Either.right(status); + } + } + + return Either.left(componentInstanceIds); + } + + + public Either deleteNodeFilter(Service service, String componentInstanceId) { + final Either, StorageOperationStatus> listStorageOperationStatusEither = + deleteNodeFilters(service, ImmutableSet.of(componentInstanceId)); + if (listStorageOperationStatusEither.isRight()) { + return Either.right(listStorageOperationStatusEither.right().value()); + } + return Either.left(componentInstanceId); + } + + + public Either createNodeFilter(String serviceId, + String componentInstanceId) { + CINodeFilterDataDefinition nodeFilterDataDefinition = new CINodeFilterDataDefinition(); + return addOrUpdateNodeFilter(false, serviceId, componentInstanceId, nodeFilterDataDefinition); + } + + public Either deleteConstraint(String serviceId, + String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition, int propertyIndex) { + ListDataDefinition properties = + nodeFilterDataDefinition.getProperties(); + properties.getListToscaDataDefinition().remove(propertyIndex); + nodeFilterDataDefinition.setProperties(properties); + return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition); + } + + public Either addNewProperty(String serviceId, + String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition, + RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition) { + ListDataDefinition properties = + nodeFilterDataDefinition.getProperties(); + if (properties == null) { + properties = new ListDataDefinition<>(); + nodeFilterDataDefinition.setProperties(properties); + } + properties.getListToscaDataDefinition().add(requirementNodeFilterPropertyDataDefinition); + nodeFilterDataDefinition.setProperties(properties); + return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition); + } + + public Either updateProperties(String serviceId, + String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition, + List requirementNodeFilterPropertyDataDefinition) { + ListDataDefinition properties = + nodeFilterDataDefinition.getProperties(); + properties.getListToscaDataDefinition().clear(); + properties.getListToscaDataDefinition().addAll(requirementNodeFilterPropertyDataDefinition); + nodeFilterDataDefinition.setProperties(properties); + return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition); + } + + public Either updateNodeFilter(String serviceId, + String componentInstanceId, CINodeFilterDataDefinition ciNodeFilterDataDefinition) { + return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, ciNodeFilterDataDefinition); + } + + private Either addOrUpdateNodeFilter(boolean isUpdateAction, + String serviceId, String componentInstanceId, CINodeFilterDataDefinition ciNodeFilterDataDefinition) { + + StorageOperationStatus statusRes; + Either getToscaElementRes; + + getToscaElementRes = titanDao.getVertexById(serviceId, JsonParseFlagEnum.NoParse); + if (getToscaElementRes.isRight()) { + TitanOperationStatus status = getToscaElementRes.right().value(); + CommonUtility.addRecordToLog(logger, CommonUtility.LogLevelEnum.DEBUG, + "Failed to get tosca element {} upon adding the properties. Status is {}. ", serviceId, status); + statusRes = DaoStatusConverter.convertTitanStatusToStorageStatus(status); + return Either.right(statusRes); + } + GraphVertex serviceVertex = getToscaElementRes.left().value(); + ciNodeFilterDataDefinition.setID(componentInstanceId); + statusRes = performUpdateToscaAction(isUpdateAction, serviceVertex, ImmutableList.of(ciNodeFilterDataDefinition)); + if (!statusRes.equals(StorageOperationStatus.OK)) { + titanDao.rollback(); + logger.error( + " Failed to perform tosca update for node filter in service {} , component instance {}. status is {}", + serviceId, componentInstanceId, statusRes); + return Either.right(statusRes); + } + titanDao.commit(); + return Either.left(ciNodeFilterDataDefinition); + + } + + + private StorageOperationStatus performUpdateToscaAction(boolean isUpdate, GraphVertex graphVertex, + List toscaDataList) { + if (isUpdate) { + return updateToscaDataOfToscaElement(graphVertex, EdgeLabelEnum.NODE_FILTER_TEMPLATE, + VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID); + } else { + return addToscaDataToToscaElement(graphVertex, EdgeLabelEnum.NODE_FILTER_TEMPLATE, + VertexTypeEnum.NODE_FILTER_TEMPLATE, toscaDataList, JsonPresentationFields.UNIQUE_ID); + } + } + +} + + + diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintType.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintType.java index c78afd8b4a..6fb699124a 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintType.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/tosca/constraints/ConstraintType.java @@ -25,6 +25,8 @@ import java.util.List; public enum ConstraintType { + EQUAL("equal", "equal"), + IN_RANGE("inRange"), GREATER_THAN("greaterThan", "greater_than"), diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java new file mode 100644 index 0000000000..63353c167d --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UIConstraint.java @@ -0,0 +1,117 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.ui.model; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Objects; +import java.io.Serializable; + +public class UIConstraint implements Serializable { + + private String servicePropertyName; + private String constraintOperator; + private String sourceType; + private String sourceName; + private Object value; + + public UIConstraint() { + } + + public UIConstraint(String servicePropertyName, String constraintOperator, String sourceType, Object value) { + this.servicePropertyName = servicePropertyName; + this.constraintOperator = constraintOperator; + this.sourceType = sourceType; + this.value = value; + } + + public UIConstraint(String servicePropertyName, String constraintOperator, String sourceType, String sourceName, + Object value) { + this.servicePropertyName = servicePropertyName; + this.constraintOperator = constraintOperator; + this.sourceType = sourceType; + this.sourceName = sourceName; + this.value = value; + } + + public String getServicePropertyName() { + return servicePropertyName; + } + + public void setServicePropertyName(String servicePropertyName) { + this.servicePropertyName = servicePropertyName; + } + + public String getConstraintOperator() { + return constraintOperator; + } + + public void setConstraintOperator(String constraintOperator) { + this.constraintOperator = constraintOperator; + } + + public String getSourceType() { + return sourceType; + } + + public void setSourceType(String sourceType) { + this.sourceType = sourceType; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public String getSourceName() { + return sourceName; + } + + public void setSourceName(String sourceName) { + this.sourceName = sourceName; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof UIConstraint)) { + return false; + } + UIConstraint that = (UIConstraint) o; + return Objects.equal(getServicePropertyName(), that.getServicePropertyName()) && Objects.equal( + getConstraintOperator(), that.getConstraintOperator()) && Objects.equal(getSourceType(), + that.getSourceType()) && Objects.equal(getSourceName(), that.getSourceName()) && Objects.equal( + getValue(), that.getValue()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getServicePropertyName(), getConstraintOperator(), getSourceType(), getSourceName(), + getValue()); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("servicePropertyName", servicePropertyName) + .add("constraintOperator", constraintOperator).add("sourceType", sourceType) + .add("sourceName", sourceName).add("value", value).toString(); + } +} diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UINodeFilter.java b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UINodeFilter.java new file mode 100644 index 0000000000..16ce3a837b --- /dev/null +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/ui/model/UINodeFilter.java @@ -0,0 +1,31 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ +package org.openecomp.sdc.be.ui.model; + +import java.util.List; + +public class UINodeFilter { + + private List properties; + + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } +} -- cgit 1.2.3-korg