public boolean checkDuplicatePorts(List<Port> servicePorts, List<Agent> agents) {
        if (CollectionUtils.isEmpty(servicePorts) || CollectionUtils.isEmpty(agents)) {
            return true;
        }
        List<String> exposedPorts = new ArrayList<>();
        servicePorts.stream().forEach(port -> exposedPorts.add(defaultPortsBuilder.updatePortProtocol(port).getPort()));
        StringBuilder duplicatePortsList = new StringBuilder();
        boolean portsValid = true;
        // Check for duplicate ports being exposed in service or agents
        for (Agent agent : agents) {
            if (CollectionUtils.isNotEmpty(agent.getPorts())) {
                for (Port port : agent.getPorts()) {
                    port = defaultPortsBuilder.updatePortProtocol(port);
                    if (exposedPorts.contains(port.getPort())) {
                        duplicatePortsList.append(port.getPort()).append(" ");
                        portsValid = false;
                    }
                    exposedPorts.add(port.getPort());
                }
            }
        }
        if (!portsValid) {
            logger.info("Duplicate Port Exposed in Spec {} ", duplicatePortsList);
            WorkflowLogger.persist(ValidatorActivity.DUPLICATE_PORTS, LoggerTags.ERROR, duplicatePortsList.toString());
        }
        return portsValid;
    }
Validates the both Service and
Agent Ports present in Hspec on
Duplication of Ports etc.
workflow-controller/controller-service/src/main/java/io/hyscale/controller/validator/impl/PortsValidator.java