Source:
private Map<String,String> getNamespaceMapping(Set<String> tenants) { Map<String,String> namespaceMap = new HashMap<>(); if (tenants == null || tenants.isEmpty()) { return namespaceMap; } try { String path = "api/v1/namespaces"; URL url = new URL(NamespaceHandler.KUBERNETES_MASTER_URL + "/" + path); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("Authorization", "Bearer " + token); connection.setConnectTimeout(0); connection.setReadTimeout(0); connection.connect(); int responseCode = connection.getResponseCode(); if (responseCode == 200) { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.setCodec(new ObjectMapper()); InputStream inputStream = connection.getInputStream(); JsonParser jsonParser = jsonFactory.createParser(inputStream); JsonNode jsonNode = jsonParser.readValueAsTree(); if (jsonNode != null) { JsonNode items = jsonNode.get("items"); if (items != null && items.isArray()) { for (JsonNode project : items) { JsonNode metaData = project.get("metadata"); String projectName = metaData.get("name").asText(); String projectID = metaData.get("uid").asText(); if (tenants.contains(projectName)) { namespaceMap.put(projectID, projectName); } } } } jsonParser.close(); inputStream.close(); } else { log.error("Error getting metadata from the OpenShift Master (" + responseCode + "). This may mean the 'hawkular' user does not have permission to watch projects. Waiting 2 seconds and will try again."); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } } } catch (IOException e) { System.err.println(e); } return namespaceMap; }

Target:
private Map<String,String> getNamespaceMapping(Set<String> tenants) { Map<String,String> namespaceMap = new HashMap<>(); if (tenants == null || tenants.isEmpty()) { return namespaceMap; } try { String path = "api/v1/namespaces"; URL url = new URL(NamespaceHandler.KUBERNETES_MASTER_URL + "/" + path); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", "application/json"); connection.setRequestProperty("Authorization", "Bearer " + token); connection.setConnectTimeout(0); connection.setReadTimeout(0); connection.connect(); int responseCode = connection.getResponseCode(); if (responseCode == 200) { JsonFactory jsonFactory = new JsonFactory(); jsonFactory.setCodec(new ObjectMapper()); InputStream inputStream = connection.getInputStream(); JsonParser jsonParser = jsonFactory.createParser(inputStream); JsonNode jsonNode = jsonParser.readValueAsTree(); if (jsonNode != null) { JsonNode items = jsonNode.get("items"); if (items != null && items.isArray()) { for (JsonNode project : items) { JsonNode metaData = project.get("metadata"); String projectName = metaData.get("name").asText(); String projectID = metaData.get("uid").asText(); if (tenants.contains(projectName)) { namespaceMap.put(projectID, projectName); } } } } jsonParser.close(); inputStream.close(); } else { log.error("Error getting metadata from the OpenShift Master (" + responseCode + "). This may mean the 'hawkular' user does not have permission to watch projects. Waiting 2 seconds and will try again."); try { Thread.sleep(2000); } catch (InterruptedException e1) { e1.printStackTrace(); } } } catch (IOException e) { log.error(e); } return namespaceMap; }