diff options
author | 2018-05-09 16:42:59 +0530 | |
---|---|---|
committer | 2018-05-14 17:13:24 +0530 | |
commit | abe0a3794cfdb28d2af70ce37a2b35c8a195aea4 (patch) | |
tree | afb381c229e6f9a4421432e219d7a9a5fd9a0f8d /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp | |
parent | 71bd1d935e56d8bac4677f840188ecb397da1b2a (diff) |
Nested Dependency issues
Remove nested depends On connectivity
Change-Id: I65bd9473f879fa72b453c2793f2b2406adde4513
Issue-ID: SDC-1315
Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp')
2 files changed, 88 insertions, 141 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationEntityType.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationEntityType.java index dd7825b9a5..d4b85605d2 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationEntityType.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationEntityType.java @@ -20,88 +20,75 @@ import static org.openecomp.sdc.translator.services.heattotosca.ConsolidationDat import static org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil.isPortResource; import static org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil.isVolumeResource; +import java.util.*; +import java.util.stream.Collectors; + import org.openecomp.sdc.heat.datatypes.model.Resource; import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; - /** * The enum Entity type. */ public enum ConsolidationEntityType { - COMPUTE, - PORT, - VOLUME, - NESTED, - //Simple nested VFC (nested file with one compute) or a complex VFC (nested ST with more than - //one compute) - VFC_NESTED, - SUB_INTERFACE, - OTHER; + COMPUTE, PORT, VOLUME, NESTED, + //Simple nested VFC (nested file with one compute) or a complex VFC (nested ST with more than + //one compute) + VFC_NESTED, SUB_INTERFACE, OTHER; + + private ConsolidationEntityType sourceEntityType; + private ConsolidationEntityType targetEntityType; + + public ConsolidationEntityType getSourceEntityType() { + return sourceEntityType; + } - private ConsolidationEntityType sourceEntityType; - private ConsolidationEntityType targetEntityType; + public ConsolidationEntityType getTargetEntityType() { + return targetEntityType; + } - public ConsolidationEntityType getSourceEntityType() { - return sourceEntityType; - } - public ConsolidationEntityType getTargetEntityType() { - return targetEntityType; - } + /** + * Sets entity type. + * + * @param sourceResource the source resource + * @param targetResource the target resource + */ + public void setEntityType(Resource sourceResource, Resource targetResource, TranslationContext context) { + targetEntityType = getEntityType(targetResource, context); + sourceEntityType = getEntityType(sourceResource, context); + } + private static final Set<ConsolidationEntityType> consolidationEntityTypes = initConsolidationEntities(); - /** - * Sets entity type. - * - * @param sourceResource the source resource - * @param targetResource the target resource - */ - public void setEntityType(Resource sourceResource, - Resource targetResource, - TranslationContext context) { - targetEntityType = - getEntityType(targetResource, context); - sourceEntityType = - getEntityType(sourceResource, context); - } + private static Set<ConsolidationEntityType> initConsolidationEntities() { + return Collections.unmodifiableSet(EnumSet.allOf(ConsolidationEntityType.class).stream().filter( + consolidationEntityType -> consolidationEntityType != ConsolidationEntityType.OTHER + && consolidationEntityType != ConsolidationEntityType.VOLUME).collect(Collectors.toSet())); + } - private static final Set<ConsolidationEntityType> consolidationEntityTypes = initConsolidationEntities(); - - private static Set<ConsolidationEntityType> initConsolidationEntities() { - Set<ConsolidationEntityType> consolidationEntityTypes = new HashSet<>(Arrays.asList(ConsolidationEntityType - .values())); - return Collections.unmodifiableSet(consolidationEntityTypes.stream() - .filter(entity -> entity != ConsolidationEntityType.OTHER - && entity != ConsolidationEntityType.VOLUME) - .collect(Collectors.toSet())); - } + public static Set<ConsolidationEntityType> getSupportedConsolidationEntities() { + return consolidationEntityTypes; + } - public static Set<ConsolidationEntityType> getSupportedConsolidationEntities() { - return consolidationEntityTypes; - } + private ConsolidationEntityType getEntityType(Resource resource, TranslationContext context) { + ConsolidationEntityType consolidationEntityType = ConsolidationEntityType.OTHER; + if (isComputeResource(resource)) { + consolidationEntityType = ConsolidationEntityType.COMPUTE; + } else if (isPortResource(resource)) { + consolidationEntityType = ConsolidationEntityType.PORT; + } else if (isVolumeResource(resource)) { + consolidationEntityType = ConsolidationEntityType.VOLUME; + } else if (HeatToToscaUtil.isNestedResource(resource)) { + if (HeatToToscaUtil.isNestedVfcResource(resource, context)) { + consolidationEntityType = ConsolidationEntityType.VFC_NESTED; + } else { + consolidationEntityType = ConsolidationEntityType.NESTED; + } + } + return consolidationEntityType; + } - private ConsolidationEntityType getEntityType(Resource resource, TranslationContext context) { - ConsolidationEntityType consolidationEntityType = ConsolidationEntityType.OTHER; - if (isComputeResource(resource)) { - consolidationEntityType = ConsolidationEntityType.COMPUTE; - } else if (isPortResource(resource)) { - consolidationEntityType = ConsolidationEntityType.PORT; - } else if (HeatToToscaUtil.isSubInterfaceResource(resource, context)) { - consolidationEntityType = ConsolidationEntityType.SUB_INTERFACE; - } else if (isVolumeResource(resource)) { - consolidationEntityType = ConsolidationEntityType.VOLUME; - } else if (HeatToToscaUtil.isNestedResource(resource)) { - if (HeatToToscaUtil.isNestedVfcResource(resource, context)) { - consolidationEntityType = ConsolidationEntityType.VFC_NESTED; - } else { - consolidationEntityType = ConsolidationEntityType.NESTED; - } + public static boolean isEntityTypeNested(ConsolidationEntityType entityType) { + return NESTED == entityType || VFC_NESTED == entityType; } - return consolidationEntityType; - } }
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationTypesConnectivity.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationTypesConnectivity.java index 2edb4fb8f2..7b258d651f 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationTypesConnectivity.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationTypesConnectivity.java @@ -1,79 +1,39 @@ package org.openecomp.sdc.translator.services.heattotosca; -import org.apache.commons.collections.CollectionUtils; - -import java.util.EnumMap; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSetMultimap; +import com.google.common.collect.Multimap; public class ConsolidationTypesConnectivity { - private static Map<ConsolidationEntityType, Set<ConsolidationEntityType>> - entityToEntitiesWithoutRelationship = new EnumMap<>(ConsolidationEntityType.class); - - static { - entityToEntitiesWithoutRelationship - .put(ConsolidationEntityType.COMPUTE, getIgnoredComputeRelationships()); - entityToEntitiesWithoutRelationship - .put(ConsolidationEntityType.PORT,getIgnoredPortRelationships()); - entityToEntitiesWithoutRelationship - .put(ConsolidationEntityType.VOLUME, getIgnoredVolumeRelationships()); - entityToEntitiesWithoutRelationship - .put(ConsolidationEntityType.VFC_NESTED, getIgnoredVfcNestedRelationships()); - entityToEntitiesWithoutRelationship - .put(ConsolidationEntityType.NESTED, getIgnoredNestedRelationships()); - } - - private ConsolidationTypesConnectivity() { - } - - private static Set<ConsolidationEntityType> getIgnoredComputeRelationships(){ - return Stream.of(ConsolidationEntityType.COMPUTE, - ConsolidationEntityType.VOLUME, - ConsolidationEntityType.PORT, - ConsolidationEntityType.NESTED, - ConsolidationEntityType.VFC_NESTED).collect(Collectors.toSet()); - } - - private static Set<ConsolidationEntityType> getIgnoredPortRelationships(){ - return Stream.of(ConsolidationEntityType.COMPUTE, - ConsolidationEntityType.VOLUME, - ConsolidationEntityType.PORT, - ConsolidationEntityType.NESTED, - ConsolidationEntityType.VFC_NESTED).collect(Collectors.toSet()); - } - - private static Set<ConsolidationEntityType> getIgnoredVolumeRelationships(){ - return Stream.of(ConsolidationEntityType.COMPUTE, - ConsolidationEntityType.VOLUME, - ConsolidationEntityType.PORT, - ConsolidationEntityType.NESTED, - ConsolidationEntityType.VFC_NESTED).collect(Collectors.toSet()); - } - - private static Set<ConsolidationEntityType> getIgnoredVfcNestedRelationships(){ - return Stream.of(ConsolidationEntityType.COMPUTE, - ConsolidationEntityType.VOLUME, - ConsolidationEntityType.PORT, - ConsolidationEntityType.NESTED, - ConsolidationEntityType.VFC_NESTED).collect(Collectors.toSet()); - } - - private static Set<ConsolidationEntityType> getIgnoredNestedRelationships(){ - return Stream.of(ConsolidationEntityType.COMPUTE, - ConsolidationEntityType.PORT, - ConsolidationEntityType.NESTED, - ConsolidationEntityType.VFC_NESTED).collect(Collectors.toSet()); - } - - public static boolean isDependsOnRelationshipValid(ConsolidationEntityType source, - ConsolidationEntityType target) { - Set<ConsolidationEntityType> consolidationEntityTypes = - entityToEntitiesWithoutRelationship.get(source); - return CollectionUtils.isEmpty(consolidationEntityTypes) || - !consolidationEntityTypes.contains(target); - - } + private static Multimap<ConsolidationEntityType, ConsolidationEntityType> entityToEntitiesWithoutRelationship; + private static ImmutableSet<ConsolidationEntityType> consolidationEntityRelationNodes = ImmutableSet.of( + ConsolidationEntityType.COMPUTE, ConsolidationEntityType.VOLUME, + ConsolidationEntityType.PORT, ConsolidationEntityType.NESTED, + ConsolidationEntityType.VFC_NESTED); + + static { + entityToEntitiesWithoutRelationship = + ImmutableSetMultimap.<ConsolidationEntityType, ConsolidationEntityType>builder() + .putAll(ConsolidationEntityType.COMPUTE, consolidationEntityRelationNodes) + .putAll(ConsolidationEntityType.PORT, consolidationEntityRelationNodes) + .putAll(ConsolidationEntityType.VOLUME, consolidationEntityRelationNodes) + .putAll(ConsolidationEntityType.VFC_NESTED, consolidationEntityRelationNodes) + .putAll(ConsolidationEntityType.NESTED, consolidationEntityRelationNodes) + .build(); + } + + private ConsolidationTypesConnectivity() { + } + + static boolean isDependsOnRelationshipValid(ConsolidationEntityType source, ConsolidationEntityType target) { + return !eitherSourceOrTargetIsNested(source, target) + && (!entityToEntitiesWithoutRelationship.containsKey(source) + || !entityToEntitiesWithoutRelationship.containsEntry(source, target)); + } + + private static boolean eitherSourceOrTargetIsNested(ConsolidationEntityType source, + ConsolidationEntityType target) { + return ConsolidationEntityType.isEntityTypeNested(source) || ConsolidationEntityType.isEntityTypeNested(target); + } } |