diff options
author | shrek2000 <orenkle@amdocs.com> | 2019-01-29 13:04:42 +0200 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2019-01-30 12:18:32 +0000 |
commit | ade7fd243fe41b5056ba63d3584ea616ee8bf808 (patch) | |
tree | 4be93c8ddfd4577b29fe8553f92d2bd17dbe89b4 /catalog-model/src/main/java/org | |
parent | 614136b09c5d11bec99fe3c1e23e8c9e022eaa58 (diff) |
Add dependent child service to service
Add dependent child service to service
Issue-ID: SDC-1987
Change-Id: Ic542fe1bc13f2b77df9944f05421a42b4b21c437
Signed-off-by: shrek2000 <orenkle@amdocs.com>
Diffstat (limited to 'catalog-model/src/main/java/org')
9 files changed, 503 insertions, 0 deletions
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<AdditionalInformationDefinition> additionalInformation; + protected List<PropertyDefinition> properties; private Map<String, InterfaceDefinition> interfaces; public Map<String, InterfaceDefinition> getInterfaces() { @@ -533,6 +534,14 @@ public abstract class Component { this.policies = policies; } + public List<PropertyDefinition> getProperties() { + return properties; + } + + public void setProperties(List<PropertyDefinition> 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<String, ArtifactDefinition> deploymentArtifacts; private Map<String, ArtifactDefinition> artifacts; private List<GroupInstance> 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<UploadNodeFilterPropertyInfo> properties; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List<UploadNodeFilterPropertyInfo> getProperties() { + return properties; + } + + public void setProperties(List<UploadNodeFilterPropertyInfo> 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<UploadNodeFilterPropertyInfo> properties = new ArrayList<>(); + private Map<String, UploadNodeFilterCapabilitiesInfo> capabilities = new HashMap<>(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List<UploadNodeFilterPropertyInfo> getProperties() { + return properties; + } + + public void setProperties(List<UploadNodeFilterPropertyInfo> properties) { + this.properties = properties; + } + + public Map<String, UploadNodeFilterCapabilitiesInfo> getCapabilities() { + return capabilities; + } + + public void setCapabilities(Map<String, UploadNodeFilterCapabilitiesInfo> 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<String> values; + + public UploadNodeFilterPropertyInfo() { + } + + public UploadNodeFilterPropertyInfo(String name, List<String> value) { + this.name = name; + this.values = value; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List<String> getValues() { + return values; + } + + public void setValue(List<String> 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<Set<String>, StorageOperationStatus> deleteNodeFilters(Service service, + Set<String> componentInstanceIds) { + Either<GraphVertex, TitanOperationStatus> getComponentVertex; + Either<GraphVertex, TitanOperationStatus> 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<String, StorageOperationStatus> deleteNodeFilter(Service service, String componentInstanceId) { + final Either<Set<String>, StorageOperationStatus> listStorageOperationStatusEither = + deleteNodeFilters(service, ImmutableSet.of(componentInstanceId)); + if (listStorageOperationStatusEither.isRight()) { + return Either.right(listStorageOperationStatusEither.right().value()); + } + return Either.left(componentInstanceId); + } + + + public Either<CINodeFilterDataDefinition, StorageOperationStatus> createNodeFilter(String serviceId, + String componentInstanceId) { + CINodeFilterDataDefinition nodeFilterDataDefinition = new CINodeFilterDataDefinition(); + return addOrUpdateNodeFilter(false, serviceId, componentInstanceId, nodeFilterDataDefinition); + } + + public Either<CINodeFilterDataDefinition, StorageOperationStatus> deleteConstraint(String serviceId, + String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition, int propertyIndex) { + ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties = + nodeFilterDataDefinition.getProperties(); + properties.getListToscaDataDefinition().remove(propertyIndex); + nodeFilterDataDefinition.setProperties(properties); + return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition); + } + + public Either<CINodeFilterDataDefinition, StorageOperationStatus> addNewProperty(String serviceId, + String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition, + RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition) { + ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> 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<CINodeFilterDataDefinition, StorageOperationStatus> updateProperties(String serviceId, + String componentInstanceId, CINodeFilterDataDefinition nodeFilterDataDefinition, + List<RequirementNodeFilterPropertyDataDefinition> requirementNodeFilterPropertyDataDefinition) { + ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> properties = + nodeFilterDataDefinition.getProperties(); + properties.getListToscaDataDefinition().clear(); + properties.getListToscaDataDefinition().addAll(requirementNodeFilterPropertyDataDefinition); + nodeFilterDataDefinition.setProperties(properties); + return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, nodeFilterDataDefinition); + } + + public Either<CINodeFilterDataDefinition, StorageOperationStatus> updateNodeFilter(String serviceId, + String componentInstanceId, CINodeFilterDataDefinition ciNodeFilterDataDefinition) { + return addOrUpdateNodeFilter(true, serviceId, componentInstanceId, ciNodeFilterDataDefinition); + } + + private Either<CINodeFilterDataDefinition, StorageOperationStatus> addOrUpdateNodeFilter(boolean isUpdateAction, + String serviceId, String componentInstanceId, CINodeFilterDataDefinition ciNodeFilterDataDefinition) { + + StorageOperationStatus statusRes; + Either<GraphVertex, TitanOperationStatus> 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<CINodeFilterDataDefinition> 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<UIConstraint> properties; + + public List<UIConstraint> getProperties() { + return properties; + } + + public void setProperties(List<UIConstraint> properties) { + this.properties = properties; + } +} |