/** * This method looks up in the statestore for cluster information for a given key. * * @param vpc VPC of the region that the cluster belongs to. Eg: us-east-1-vpc-defa0000 * @param env Environment the cluster belongs to * @param hint Additional information that works in combination with vpc * @param actorType Type that defines if the operation is happening for a producer or consumer * @return ClusterValue * @throws ClusterNotFoundException thrown if no cluster is found in the region */ protected ClusterValue getClusterDetails(String vpc, String env, String hint, String actorType) throws ClusterNotFoundException { log.info("Cluster Details: vpc: {}, env: {}, hint: {}, actorType: {}", vpc, env, hint, actorType); ClusterKey clusterKey = new ClusterKey(vpc, env, hint, null); Optional<ClusterValue> clusterValue = infraManager.getClusterByKey(clusterKey); if (clusterValue.isPresent()) { log.info("Cluster Information found - {}", clusterValue); return clusterValue.get(); } // If no cluster information is found set the actorType and look again. clusterKey.setType(actorType); clusterValue = infraManager.getClusterByKey(clusterKey); if (clusterValue.isPresent()) { log.info("Cluster Information found - {}", clusterValue); return clusterValue.get(); } else { log.info("Cluster Information not found for key - {}", clusterKey); throw new ClusterNotFoundException(clusterKey.toString()); } }
private Map<String, Set<String>> getHintToVpcsMap() { Set<ClusterKey> clusters = infraManager.getAllClusters().keySet(); return clusters.stream() .filter((ClusterKey key) -> env.equalsIgnoreCase(key.getEnv())) .collect(Collectors.groupingBy(ClusterKey::getHint, Collectors.mapping(ClusterKey::getVpc, Collectors.toSet()))); }
@Override @SuppressWarnings("unchecked") public ClusterKey build() { try { ClusterKey record = new ClusterKey(); record.vpc = fieldSetFlags()[0] ? this.vpc : (java.lang.String) defaultValue(fields()[0]); record.env = fieldSetFlags()[1] ? this.env : (java.lang.String) defaultValue(fields()[1]); record.hint = fieldSetFlags()[2] ? this.hint : (java.lang.String) defaultValue(fields()[2]); record.type = fieldSetFlags()[3] ? this.type : (java.lang.String) defaultValue(fields()[3]); return record; } catch (java.lang.Exception e) { throw new org.apache.avro.AvroRuntimeException(e); } } }