X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=servicehandler%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Fservicehandler%2FDowngradeConstraints.java;h=c42ed0f5261114cd597b8d7ece576845670e4a6f;hb=9ab0cabbeeddeac5ab2bcfa7cb4a3f79f81a5c88;hp=d56f116f06d15e65f9ced6db35e011466f38306e;hpb=4bf74b30f3aa25ea9d914ca05e1e66fdf2a3cbc2;p=transportpce.git diff --git a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraints.java b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraints.java index d56f116f0..c42ed0f52 100644 --- a/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraints.java +++ b/servicehandler/src/main/java/org/opendaylight/transportpce/servicehandler/DowngradeConstraints.java @@ -7,32 +7,43 @@ */ package org.opendaylight.transportpce.servicehandler; -import java.util.List; - -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.CoRoutingOrGeneral; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRouting; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.CoRoutingBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.General; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.GeneralBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Diversity; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.DiversityBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Exclude; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.ExcludeBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Include; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.IncludeBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.general.Latency; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraintsBuilder; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints; -import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraintsBuilder; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifier; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.common.constraints.LinkIdentifierKey; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRouting; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.CoRoutingBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Distance; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.DistanceBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Diversity; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.DiversityBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Exclude; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.ExcludeBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.HopCount; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.HopCountBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Include; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.IncludeBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.Latency; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.LatencyBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.TEMetric; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.TEMetricBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierList; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.constraints.co.routing.ServiceIdentifierListKey; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.HardConstraintsBuilder; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraints; +import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.routing.constraints.SoftConstraintsBuilder; +import org.opendaylight.yangtools.yang.common.Uint32; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Class to Map Hard Constraints to Soft Constraints. - * * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange - * + * @author gilles Thouenon (gilles.thouenon@orange.com) */ public final class DowngradeConstraints { @@ -43,146 +54,320 @@ public final class DowngradeConstraints { /** * Add Hard Constraints to Soft Constraints. - * - * - * @param hardConstraints to be added - * @param softConstraints to be modified - * @return SoftConstraints modified + * @param hardConstraints to be added + * @param softConstraints to be modified + * @return SoftConstraints modified */ public static SoftConstraints updateSoftConstraints(HardConstraints hardConstraints, - SoftConstraints softConstraints) { + SoftConstraints softConstraints) { SoftConstraintsBuilder softConstraintsBuilder = new SoftConstraintsBuilder(softConstraints); - List hardCustomerCode = hardConstraints.getCustomerCode(); - if (!hardCustomerCode.isEmpty()) { - softConstraintsBuilder.getCustomerCode().addAll(hardCustomerCode); - } else { - LOG.warn("hard constraints customer code list is empty !"); - } - CoRoutingOrGeneral coRoutingOrGeneral = hardConstraints.getCoRoutingOrGeneral(); - if (coRoutingOrGeneral != null) { - if (coRoutingOrGeneral instanceof General) { - General hardGeneral = (General) coRoutingOrGeneral; - if (softConstraintsBuilder.getCoRoutingOrGeneral() instanceof General) { - General softGeneral = (General) softConstraintsBuilder.getCoRoutingOrGeneral(); - updateGeneral(hardGeneral, softGeneral); - } else { - softConstraintsBuilder.setCoRoutingOrGeneral(hardGeneral); - } - } else if (coRoutingOrGeneral instanceof CoRouting) { - CoRouting hardCoRouting = (CoRouting) coRoutingOrGeneral; - if (softConstraintsBuilder.getCoRoutingOrGeneral() instanceof CoRouting) { - CoRouting softCoRouting = (CoRouting) softConstraintsBuilder.getCoRoutingOrGeneral(); - updateCoRouting(hardCoRouting, softCoRouting); - } else { - softConstraintsBuilder.setCoRoutingOrGeneral(hardCoRouting); - } + if (hardConstraints.getCustomerCode() != null && !hardConstraints.getCustomerCode().isEmpty()) { + if (softConstraintsBuilder.getCustomerCode() == null + || softConstraintsBuilder.getCustomerCode().isEmpty()) { + softConstraintsBuilder.setCustomerCode(hardConstraints.getCustomerCode()); + } else { + Set updatedCustomerCode = new HashSet<>(softConstraintsBuilder.getCustomerCode()); + updatedCustomerCode.addAll(hardConstraints.getCustomerCode()); + softConstraintsBuilder.setCustomerCode(updatedCustomerCode); } - } else { - LOG.warn("hard constraints CoRoutingOrGeneral is null !"); } - return softConstraintsBuilder.build(); - } + if (hardConstraints.getOperationalMode() != null && !hardConstraints.getOperationalMode().isEmpty()) { + if (softConstraintsBuilder.getOperationalMode() == null + || softConstraintsBuilder.getOperationalMode().isEmpty()) { + softConstraintsBuilder.setOperationalMode(hardConstraints.getOperationalMode()); + } else { + Set updatedOperationalMode = new HashSet<>(softConstraintsBuilder.getOperationalMode()); + updatedOperationalMode.addAll(hardConstraints.getOperationalMode()); + softConstraintsBuilder.setOperationalMode(updatedOperationalMode); + } + } + if (hardConstraints.getDiversity() != null) { + softConstraintsBuilder + .setDiversity(updateDiveristy(hardConstraints.getDiversity(), softConstraints.getDiversity())); + } + if (hardConstraints.getExclude() != null) { + softConstraintsBuilder + .setExclude(updateExclude(hardConstraints.getExclude(), softConstraints.getExclude())); + } + if (hardConstraints.getInclude() != null) { + softConstraintsBuilder + .setInclude(updateInclude(hardConstraints.getInclude(), softConstraints.getInclude())); + } + if (hardConstraints.getLatency() != null) { + softConstraintsBuilder + .setLatency(updateLatency(hardConstraints.getLatency(), softConstraints.getLatency())); + } + if (hardConstraints.getDistance() != null) { + softConstraintsBuilder + .setDistance(updateDistance(hardConstraints.getDistance(), softConstraints.getDistance())); + } + if (hardConstraints.getHopCount() != null) { + softConstraintsBuilder + .setHopCount(updateHopCount(hardConstraints.getHopCount(), softConstraints.getHopCount())); + } + if (hardConstraints.getTEMetric() != null) { + softConstraintsBuilder + .setTEMetric(updateTEMetric(hardConstraints.getTEMetric(), softConstraints.getTEMetric())); + } - private static General updateGeneral(General hard, General soft) { - GeneralBuilder result = new GeneralBuilder(soft); - try { - result.setDiversity(updateDiveristy(hard.getDiversity(), soft.getDiversity())); - result.setExclude(updateExclude(hard.getExclude(), soft.getExclude())); - result.setInclude(updateInclude(hard.getInclude(), soft.getInclude())); - } catch (NullPointerException e) { - LOG.warn("failed to update some 'General' parameters !", e); + if (hardConstraints.getCoRouting() != null) { + softConstraintsBuilder + .setCoRouting(updateCoRouting(hardConstraints.getCoRouting(), softConstraints.getCoRouting())); } - return result.build(); + return softConstraintsBuilder.build(); } private static Include updateInclude(Include hard, Include soft) { - IncludeBuilder result = new IncludeBuilder(soft); - if (hard != null) { - result.getFiberBundle().addAll(hard.getFiberBundle()); - result.getNodeId().addAll(hard.getNodeId()); - result.getSite().addAll(hard.getSite()); - result.getSupportingServiceName().addAll(hard.getSupportingServiceName()); - } - return result.build(); + IncludeBuilder includeBldr = soft == null ? new IncludeBuilder() : new IncludeBuilder(soft); + + if (hard.getFiberBundle() != null && !hard.getFiberBundle().isEmpty()) { + if (includeBldr.getFiberBundle() == null) { + includeBldr.setFiberBundle(hard.getFiberBundle()); + } else { + Set fiberList = new HashSet<>(includeBldr.getFiberBundle()); + fiberList.addAll(hard.getFiberBundle()); + includeBldr.setFiberBundle(new HashSet<>(fiberList)); + } + } + if (hard.getNodeId() != null && !hard.getNodeId().isEmpty()) { + if (includeBldr.getNodeId() == null) { + includeBldr.setNodeId(hard.getNodeId()); + } else { + Set nodeIdList = new HashSet<>(includeBldr.getNodeId()); + nodeIdList.addAll(hard.getNodeId()); + includeBldr.setNodeId(new HashSet<>(nodeIdList)); + } + } + if (hard.getSite() != null && !hard.getSite().isEmpty()) { + if (includeBldr.getSite() == null) { + includeBldr.setSite(hard.getSite()); + } else { + Set siteList = new HashSet<>(includeBldr.getSite()); + siteList.addAll(hard.getSite()); + includeBldr.setSite(new HashSet<>(siteList)); + } + } + if (hard.getSrlgId() != null && !hard.getSrlgId().isEmpty()) { + if (includeBldr.getSrlgId() == null) { + includeBldr.setSrlgId(hard.getSrlgId()); + } else { + Set srlgList = new HashSet<>(includeBldr.getSrlgId()); + srlgList.addAll(hard.getSrlgId()); + includeBldr.setSrlgId(new HashSet<>(srlgList)); + } + } + if (hard.getSupportingServiceName() != null && !hard.getSupportingServiceName().isEmpty()) { + if (includeBldr.getSupportingServiceName() == null) { + includeBldr.setSupportingServiceName(hard.getSupportingServiceName()); + } else { + Set serviceList = new HashSet<>(includeBldr.getSupportingServiceName()); + serviceList.addAll(hard.getSupportingServiceName()); + includeBldr.setSupportingServiceName(new HashSet<>(serviceList)); + } + } + if (hard.getLinkIdentifier() != null && !hard.getLinkIdentifier().isEmpty()) { + if (includeBldr.getLinkIdentifier() == null) { + includeBldr.setLinkIdentifier(hard.getLinkIdentifier()); + } else { + Map linkList = new HashMap<>(includeBldr.getLinkIdentifier()); + linkList.putAll(hard.getLinkIdentifier()); + includeBldr.setLinkIdentifier(linkList); + } + } + return includeBldr.build(); } private static Exclude updateExclude(Exclude hard, Exclude soft) { - ExcludeBuilder result = new ExcludeBuilder(soft); - if (hard != null) { - result.getFiberBundle().addAll(hard.getFiberBundle()); - result.getNodeId().addAll(hard.getNodeId()); - result.getSite().addAll(hard.getSite()); - result.getSupportingServiceName().addAll(hard.getSupportingServiceName()); - } - return result.build(); + ExcludeBuilder excludeBldr = soft == null ? new ExcludeBuilder() : new ExcludeBuilder(soft); + + if (hard.getFiberBundle() != null && !hard.getFiberBundle().isEmpty()) { + if (excludeBldr.getFiberBundle() == null) { + excludeBldr.setFiberBundle(hard.getFiberBundle()); + } else { + Set fiberList = new HashSet<>(excludeBldr.getFiberBundle()); + fiberList.addAll(hard.getFiberBundle()); + excludeBldr.setFiberBundle(new HashSet<>(fiberList)); + } + } + if (hard.getNodeId() != null && !hard.getNodeId().isEmpty()) { + if (excludeBldr.getNodeId() == null) { + excludeBldr.setNodeId(hard.getNodeId()); + } else { + Set nodeIdList = new HashSet<>(excludeBldr.getNodeId()); + nodeIdList.addAll(hard.getNodeId()); + excludeBldr.setNodeId(new HashSet<>(nodeIdList)); + } + } + if (hard.getSite() != null && !hard.getSite().isEmpty()) { + if (excludeBldr.getSite() == null) { + excludeBldr.setSite(hard.getSite()); + } else { + Set siteList = new HashSet<>(excludeBldr.getSite()); + siteList.addAll(hard.getSite()); + excludeBldr.setSite(new HashSet<>(siteList)); + } + } + if (hard.getSrlgId() != null && !hard.getSrlgId().isEmpty()) { + if (excludeBldr.getSrlgId() == null) { + excludeBldr.setSrlgId(hard.getSrlgId()); + } else { + Set srlgList = new HashSet<>(excludeBldr.getSrlgId()); + srlgList.addAll(hard.getSrlgId()); + excludeBldr.setSrlgId(new HashSet<>(srlgList)); + } + } + if (hard.getSupportingServiceName() != null && !hard.getSupportingServiceName().isEmpty()) { + if (excludeBldr.getSupportingServiceName() == null) { + excludeBldr.setSupportingServiceName(hard.getSupportingServiceName()); + } else { + Set serviceList = new HashSet<>(excludeBldr.getSupportingServiceName()); + serviceList.addAll(hard.getSupportingServiceName()); + excludeBldr.setSupportingServiceName(new HashSet<>(serviceList)); + } + } + if (hard.getLinkIdentifier() != null && !hard.getLinkIdentifier().isEmpty()) { + if (excludeBldr.getLinkIdentifier() == null) { + excludeBldr.setLinkIdentifier(hard.getLinkIdentifier()); + } else { + Map linkList = new HashMap<>(excludeBldr.getLinkIdentifier()); + linkList.putAll(hard.getLinkIdentifier()); + excludeBldr.setLinkIdentifier(linkList); + } + } + return excludeBldr.build(); } private static Diversity updateDiveristy(Diversity hard, Diversity soft) { - DiversityBuilder result = new DiversityBuilder(soft); - if (hard != null) { - result.getExistingService().addAll(hard.getExistingService()); - result.setExistingServiceApplicability(hard.getExistingServiceApplicability()); + DiversityBuilder diversityBldr = soft == null ? new DiversityBuilder() : new DiversityBuilder(soft); + + Map< + org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service + .constraints.ServiceIdentifierListKey, + org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev211210.diversity.existing.service + .constraints.ServiceIdentifierList> sil = + diversityBldr.getServiceIdentifierList() == null + ? new HashMap<>() + : new HashMap<>(diversityBldr.getServiceIdentifierList()); + if (!hard.getServiceIdentifierList().isEmpty()) { + sil.putAll(hard.getServiceIdentifierList()); + diversityBldr.setServiceIdentifierList(sil); } - return result.build(); + if (hard.getDiversityType() != null) { + diversityBldr.setDiversityType(hard.getDiversityType()); + } + return diversityBldr.build(); } - private static CoRouting updateCoRouting(CoRouting hard, CoRouting soft) { - CoRoutingBuilder result = new CoRoutingBuilder(soft); - try { - result.setCoRouting( - updateCoCoRouting(hard.getCoRouting(), soft.getCoRouting())); - } catch (NullPointerException e) { - LOG.warn("failed to update some 'CoRouting' parameters !", e); - } - return result.build(); + private static Latency updateLatency(Latency hard, Latency soft) { + return soft == null || hard.getMaxLatency().longValue() <= soft.getMaxLatency().longValue() + ? new LatencyBuilder(hard).build() + : new LatencyBuilder(soft).build(); } - private static org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing - .or.general.co.routing.CoRouting updateCoCoRouting(org.opendaylight.yang.gen.v1.http.org.openroadm.routing - .constrains.rev161014.constraints.co.routing.or.general.co.routing.CoRouting hard, org.opendaylight - .yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general.co - .routing.CoRouting soft) { - org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.constraints.co.routing.or.general - .co.routing.CoRoutingBuilder result = new org.opendaylight.yang.gen.v1.http.org.openroadm.routing - .constrains.rev161014.constraints.co.routing.or.general.co.routing.CoRoutingBuilder(soft); - if (hard != null) { - result.getExistingService().addAll(hard.getExistingService()); - } - return result.build(); + private static Distance updateDistance(Distance hard, Distance soft) { + return soft == null || hard.getMaxDistance().longValue() <= soft.getMaxDistance().longValue() + ? new DistanceBuilder(hard).build() + : new DistanceBuilder(soft).build(); + } + + private static HopCount updateHopCount(HopCount hard, HopCount soft) { + if (soft == null) { + return new HopCountBuilder(hard).build(); + } + HopCountBuilder hcBldr = new HopCountBuilder(); + if (soft.getMaxWdmHopCount() == null) { + if (hard.getMaxWdmHopCount() != null) { + hcBldr.setMaxWdmHopCount(hard.getMaxWdmHopCount()); + } + } else { + hcBldr.setMaxWdmHopCount( + hard.getMaxWdmHopCount() == null + || soft.getMaxWdmHopCount().intValue() <= hard.getMaxWdmHopCount().intValue() + ? soft.getMaxWdmHopCount() + : hard.getMaxWdmHopCount()); + } + if (soft.getMaxOtnHopCount() == null) { + if (hard.getMaxOtnHopCount() != null) { + hcBldr.setMaxOtnHopCount(hard.getMaxOtnHopCount()); + } + } else { + hcBldr.setMaxOtnHopCount( + hard.getMaxOtnHopCount() == null + || soft.getMaxOtnHopCount().intValue() <= hard.getMaxOtnHopCount().intValue() + ? soft.getMaxOtnHopCount() + : hard.getMaxOtnHopCount()); + } + return hcBldr.build(); + } + + private static TEMetric updateTEMetric(TEMetric hard, TEMetric soft) { + if (soft == null) { + return new TEMetricBuilder(hard).build(); + } + TEMetricBuilder temBldr = new TEMetricBuilder(); + if (soft.getMaxWdmTEMetric() == null) { + if (hard.getMaxWdmTEMetric() != null) { + temBldr.setMaxWdmTEMetric(hard.getMaxWdmTEMetric()); + } + } else { + temBldr.setMaxWdmTEMetric( + hard.getMaxWdmTEMetric() == null + || soft.getMaxWdmTEMetric().intValue() <= hard.getMaxWdmTEMetric().intValue() + ? soft.getMaxWdmTEMetric() + : hard.getMaxWdmTEMetric()); + } + if (soft.getMaxOtnTEMetric() == null) { + if (hard.getMaxOtnTEMetric() != null) { + temBldr.setMaxOtnTEMetric(hard.getMaxWdmTEMetric()); + } + } else { + temBldr.setMaxOtnTEMetric( + hard.getMaxOtnTEMetric() == null + || soft.getMaxOtnTEMetric().intValue() <= hard.getMaxOtnTEMetric().intValue() + ? soft.getMaxOtnTEMetric() + : hard.getMaxOtnTEMetric()); + } + return temBldr.build(); + } + + private static CoRouting updateCoRouting(CoRouting hard, CoRouting soft) { + CoRoutingBuilder coRoutingBldr = soft == null ? new CoRoutingBuilder() : new CoRoutingBuilder(soft); + + Map< + ServiceIdentifierListKey, + ServiceIdentifierList> serviceIdentifierList = coRoutingBldr.getServiceIdentifierList() == null + ? new HashMap<>() + : new HashMap<>(coRoutingBldr.getServiceIdentifierList()); + if (!hard.getServiceIdentifierList().isEmpty()) { + serviceIdentifierList.putAll(hard.getServiceIdentifierList()); + coRoutingBldr.setServiceIdentifierList(serviceIdentifierList); + } + return coRoutingBldr.build(); } /** * Remove all hard constraints except latency. - * - * @param hardConstraints HardConstarints to be downgraded - * @return HardConstraints downgraded + * @param hardConstraints HardConstarints to be downgraded + * @return HardConstraints downgraded */ public static HardConstraints downgradeHardConstraints(HardConstraints hardConstraints) { HardConstraintsBuilder hardConstraintsBuilder = new HardConstraintsBuilder(); - CoRoutingOrGeneral coRoutingOrGeneral = hardConstraints.getCoRoutingOrGeneral(); - Latency latency = null; - if (coRoutingOrGeneral instanceof General) { - General general = (General) coRoutingOrGeneral; - if (general != null) { - latency = general.getLatency(); - if (latency != null) { - hardConstraintsBuilder.setCoRoutingOrGeneral(new GeneralBuilder().setLatency(latency).build()); - } else { - LOG.warn("latency value not found in HardContraints !"); - } - } + if (hardConstraints != null && hardConstraints.getLatency() != null) { + hardConstraintsBuilder.setLatency(hardConstraints.getLatency()); + } else { + LOG.warn("latency value not found in HardContraints !"); } return hardConstraintsBuilder.build(); } /** * Convert HardConstraints to SoftConstraints. - * - * @param hardConstraints to be converted. - * @return SoftConstraints converted. + * @param hardConstraints to be converted. + * @return SoftConstraints converted. */ public static SoftConstraints convertToSoftConstraints(HardConstraints hardConstraints) { - SoftConstraintsBuilder softConstraintsBuilder = new SoftConstraintsBuilder(hardConstraints); - return softConstraintsBuilder.build(); + return hardConstraints == null + ? new SoftConstraintsBuilder().build() + : new SoftConstraintsBuilder(hardConstraints).build(); } }