class PacmanEc2Utils {

    public static Map<String, Boolean> checkAccessibleToAll(
            Set<GroupIdentifier> secuityGroups, String portToCheck,
            String sgRulesUrl, String cidrIp) throws Exception {
        String responseJson = null;
        String fromPort = null;
        String toPort = null;
        String ipprotocol = null;
        JsonParser jsonParser;
        JsonObject resultJson;
        HashMap<String, Boolean> openPorts = new HashMap<>();
        StringBuilder urlToQueryBuffer = new StringBuilder(sgRulesUrl);
        for (GroupIdentifier securityGrp : secuityGroups) {
            StringBuilder requestBody = new StringBuilder(
                    "{\"query\":{\"bool\":{\"must\":[{\"term\":{\"groupid.keyword\":{\"value\":\""
                            + securityGrp.getGroupId()
                            + "\"}}},{\"term\":{\"cidrip.keyword\":{\"value\":\""
                            + cidrIp
                            + "\"}}},{\"term\":{\"type.keyword\":{\"value\":\"inbound\"}}}]}}}");
            try {
                responseJson = PacmanUtils.doHttpPost(
                        urlToQueryBuffer.toString(), requestBody.toString());
            } catch (RuleExecutionFailedExeption e) {
                throw new RuleExecutionFailedExeption(e.getMessage());
            }
            jsonParser = new JsonParser();
            resultJson = (JsonObject) jsonParser.parse(responseJson);

            JsonObject hitsJson = (JsonObject) jsonParser.parse(resultJson.get(
                    "hits").toString());
            JsonArray hitsArray = hitsJson.getAsJsonArray("hits");
            logger.info(sgRulesUrl);
            logger.info(securityGrp.getGroupId());
            logger.info(portToCheck);
            for (int i = 0; i < hitsArray.size(); i++) {
                JsonObject source = hitsArray.get(i).getAsJsonObject()
                        .get("_source").getAsJsonObject();
                fromPort = source.get("fromport").getAsString();
                toPort = source.get("toport").getAsString();
                ipprotocol = source.get("ipprotocol").getAsString();
                logger.info(fromPort);
                logger.info(toPort);
                logger.info(ipprotocol);
                if (!org.apache.commons.lang.StringUtils.isEmpty(fromPort)
                        && !org.apache.commons.lang.StringUtils.isEmpty(toPort)) {
                    String fPort = "FromPort_" + fromPort + "_" + ipprotocol;
                    String tPort = "ToPort_" + toPort + "_" + ipprotocol;
                    openPorts.put(fPort + "-" + tPort, true);
                }
            }
        }
        return openPorts;
    }

    private  PacmanEc2Utils();

}