private static final Logger LOG = LoggerFactory.getLogger(PcePathDescription.class);
private List<PceLink> pathAtoZ = null;
- private List<PceLink> pathZtoA = null;
private PceResult rc;
private Map<LinkId, PceLink> allPceLinks = null;
public PceResult buildDescriptions() {
LOG.info("In buildDescriptions: AtoZ = {}", pathAtoZ);
- Map<AToZKey,AToZ> atozList = new HashMap<>();
+ Map<AToZKey,AToZ> atozMap = new HashMap<>();
if (pathAtoZ == null) {
rc.setRC(ResponseCodes.RESPONSE_FAILED);
LOG.error("In buildDescriptions: there is empty AtoZ path");
return rc;
}
- buildAtoZ(atozList, pathAtoZ);
+ buildAtoZ(atozMap, pathAtoZ);
+ rc.setAtoZDirection(buildAtoZDirection(atozMap).build());
+ List<PceLink> pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
+ LOG.info("In buildDescriptions: ZtoA {}", pathZtoA);
+
+ Map<ZToAKey,ZToA> ztoaMap = new HashMap<>();
+ if (pathZtoA == null) {
+ rc.setRC(ResponseCodes.RESPONSE_FAILED);
+ LOG.error("In buildDescriptions: there is empty ZtoA path");
+ return rc;
+ }
+ buildZtoA(ztoaMap, pathZtoA);
+ rc.setZtoADirection(buildZtoADirection(ztoaMap).build());
+
+ return rc;
+ }
+
+ /**
+ * Create a builder for AtoZDirection object.
+ * @param atozMap Map of AToZ object
+ * @return a builder for AtoZDirection object
+ */
+ private AToZDirectionBuilder buildAtoZDirection(Map<AToZKey, AToZ> atozMap) {
AToZDirectionBuilder atoZDirectionBldr = new AToZDirectionBuilder()
.setRate(Uint32.valueOf(rc.getRate()))
- .setAToZ(atozList);
+ .setAToZ(atozMap);
if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
} else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
|| "ODU4".equals(rc.getServiceType())) {
if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
+ @SuppressWarnings("unchecked")
List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
atoZDirectionBldr.setAToZWavelengthNumber(Uint32.valueOf(0))
.setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
atoZDirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
}
}
- rc.setAtoZDirection(atoZDirectionBldr.build());
- pathZtoA = ImmutableList.copyOf(pathAtoZ).reverse();
- LOG.info("In buildDescriptions: ZtoA {}", pathZtoA);
+ return atoZDirectionBldr;
+ }
- Map<ZToAKey,ZToA> ztoaList = new HashMap<>();
- if (pathZtoA == null) {
- rc.setRC(ResponseCodes.RESPONSE_FAILED);
- LOG.error("In buildDescriptions: there is empty ZtoA path");
- return rc;
- }
- buildZtoA(ztoaList, pathZtoA);
+ /**
+ * Create a builder for ZtoADirection object.
+ * @param ztoaMap Map of ZToA object
+ * @return a builder for ZtoADirection object
+ */
+ private ZToADirectionBuilder buildZtoADirection(Map<ZToAKey, ZToA> ztoaMap) {
ZToADirectionBuilder ztoADirectionBldr = new ZToADirectionBuilder()
.setRate(Uint32.valueOf(rc.getRate()))
- .setZToA(ztoaList);
+ .setZToA(ztoaMap);
if ("100GE".equals(rc.getServiceType()) || "OTU4".equals(rc.getServiceType())) {
ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(rc.getResultWavelength()));
} else if ("10GE".equals(rc.getServiceType()) || "1GE".equals(rc.getServiceType())
|| "ODU4".equals(rc.getServiceType())) {
if (rc.getResultTribSlot() != null && rc.getResultTribPort() != null) {
+ @SuppressWarnings("unchecked")
List<Uint16> tribSlotList = (List<Uint16>) rc.getResultTribSlot().values().toArray()[0];
ztoADirectionBldr.setZToAWavelengthNumber(Uint32.valueOf(0))
.setTribPortNumber(Uint16.valueOf(rc.getResultTribPort().values().toArray()[0].toString()))
ztoADirectionBldr.setTribSlotNumber(Uint16.valueOf(0)).setTribPortNumber(Uint16.valueOf(0));
}
}
- rc.setZtoADirection(ztoADirectionBldr.build());
-
- return rc;
+ return ztoADirectionBldr;
}
- private void buildAtoZ(Map<AToZKey, AToZ> atozList, List<PceLink> path) {
+ @SuppressWarnings("java:S138")
+ //sonar issue This method has 77 lines, which is greater than the 75 lines authorized. Split it into smaller
+ //ignore as it's not relevant to split it from functional point
+ private void buildAtoZ(Map<AToZKey, AToZ> atozMap, List<PceLink> path) {
Integer index = 0;
PceLink lastLink = null;
AToZ lastResource = null;
AToZKey clientKey = new AToZKey(index.toString());
Resource clientResource = new ResourceBuilder().setResource(stp).build();
AToZ firstResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
- atozList.put(firstResource.key(),firstResource);
+ atozMap.put(firstResource.key(),firstResource);
index += 1;
for (PceLink pcelink : path) {
String srcName = pcelink.getSourceId().getValue();
Resource nodeResource1 = new ResourceBuilder().setResource(sourceNode).build();
AToZ srcResource = new AToZBuilder().setId(srcName).withKey(sourceKey).setResource(nodeResource1).build();
index += 1;
- atozList.put(srcResource.key(),srcResource);
+ atozMap.put(srcResource.key(),srcResource);
// source TP
tpName = pcelink.getSourceTP().toString();
Resource tpResource1 = new ResourceBuilder().setResource(stp).build();
AToZ stpResource = new AToZBuilder().setId(tpName).withKey(srcTPKey).setResource(tpResource1).build();
index += 1;
- atozList.put(stpResource.key(),stpResource);
+ atozMap.put(stpResource.key(),stpResource);
String linkName = pcelink.getLinkId().getValue();
// Link
Resource nodeResource2 = new ResourceBuilder().setResource(atozLink).build();
AToZ linkResource = new AToZBuilder().setId(linkName).withKey(linkKey).setResource(nodeResource2).build();
index += 1;
- atozList.put(linkResource.key(),linkResource);
+ atozMap.put(linkResource.key(),linkResource);
String destName = pcelink.getDestId().getValue();
// target TP
Resource tpResource2 = new ResourceBuilder().setResource(dtp).build();
AToZ ttpResource = new AToZBuilder().setId(tpName).withKey(destTPKey).setResource(tpResource2).build();
index += 1;
- atozList.put(ttpResource.key(),ttpResource);
+ atozMap.put(ttpResource.key(),ttpResource);
org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev200629.pce
.resource.resource.resource.Node targetNode = new NodeBuilder()
}
if (lastResource != null) {
- atozList.put(lastResource.key(),lastResource);
+ atozMap.put(lastResource.key(),lastResource);
}
// build Z side Client TP
clientKey = new AToZKey(index.toString());
clientResource = new ResourceBuilder().setResource(stp).build();
lastResource = new AToZBuilder().setId(tpName).withKey(clientKey).setResource(clientResource).build();
- atozList.put(lastResource.key(),lastResource);
+ atozMap.put(lastResource.key(),lastResource);
}