use of com.sequenceiq.cloudbreak.api.model.Port in project cloudbreak by hortonworks.
the class DefaultSecurityGroupCreator method concatenatePorts.
private String concatenatePorts(Iterable<Port> ports) {
StringBuilder builder = new StringBuilder("");
Iterator<Port> portsIterator = ports.iterator();
while (portsIterator.hasNext()) {
Port port = portsIterator.next();
builder.append(port.getPort());
if (portsIterator.hasNext()) {
builder.append(',');
}
}
return builder.toString();
}
use of com.sequenceiq.cloudbreak.api.model.Port in project cloudbreak by hortonworks.
the class NetworkUtils method getPorts.
public static List<Port> getPorts(Optional<Stack> stack) {
List<Port> result = new ArrayList<>();
if (stack.isPresent()) {
Stack stackInstance = stack.get();
List<EndpointRule> aclRules = createACLRules(stackInstance);
for (InstanceGroup instanceGroup : stackInstance.getInstanceGroups()) {
for (SecurityRule rule : instanceGroup.getSecurityGroup().getSecurityRules()) {
for (String portNumber : rule.getPorts()) {
Port port = getPortByPortNumberAndProtocol(portNumber, rule.getProtocol());
if (port != null) {
result.add(new Port(port.getExposedService(), portNumber, portNumber, rule.getProtocol(), aclRules));
}
}
}
}
} else {
result.addAll(PORTS);
}
return result;
}
use of com.sequenceiq.cloudbreak.api.model.Port in project cloudbreak by hortonworks.
the class DefaultSecurityGroupCreator method getPortsOpenDesc.
private String getPortsOpenDesc(Iterable<Port> portsWithoutAclRules) {
StringBuilder allPortsOpenDescBuilder = new StringBuilder();
allPortsOpenDescBuilder.append("Open ports:");
for (Port port : portsWithoutAclRules) {
allPortsOpenDescBuilder.append(' ').append(port.getPort()).append(" (").append(port.getName()).append(')');
}
return allPortsOpenDescBuilder.toString();
}
use of com.sequenceiq.cloudbreak.api.model.Port in project cloudbreak by hortonworks.
the class ClusterToClusterResponseConverter method prepareServiceEndpointsMap.
private Map<String, String> prepareServiceEndpointsMap(Cluster cluster, String ambariIp) {
Set<HostGroup> hostGroups = cluster.getHostGroups();
Blueprint blueprint = cluster.getBlueprint();
Map<String, String> result = new HashMap<>();
List<Port> ports = NetworkUtils.getPorts(Optional.empty());
try {
JsonNode hostGroupsNode = blueprintValidator.getHostGroupNode(blueprint);
Map<String, HostGroup> hostGroupMap = blueprintValidator.createHostGroupMap(hostGroups);
for (JsonNode hostGroupNode : hostGroupsNode) {
String hostGroupName = blueprintValidator.getHostGroupName(hostGroupNode);
JsonNode componentsNode = blueprintValidator.getComponentsNode(hostGroupNode);
HostGroup actualHostgroup = hostGroupMap.get(hostGroupName);
String serviceAddress;
if (actualHostgroup.getConstraint().getInstanceGroup() != null) {
InstanceMetaData next = actualHostgroup.getConstraint().getInstanceGroup().getInstanceMetaData().iterator().next();
serviceAddress = next.getPublicIpWrapper();
} else {
serviceAddress = actualHostgroup.getHostMetadata().iterator().next().getHostName();
}
for (JsonNode componentNode : componentsNode) {
String componentName = componentNode.get("name").asText();
StackServiceComponentDescriptor componentDescriptor = stackServiceComponentDescs.get(componentName);
collectServicePorts(result, ports, ambariIp, serviceAddress, componentDescriptor, cluster);
}
}
} catch (Exception ignored) {
return result;
}
return result;
}
use of com.sequenceiq.cloudbreak.api.model.Port in project cloudbreak by hortonworks.
the class ClusterToClusterResponseConverter method collectServicePorts.
private void collectServicePorts(Map<String, String> result, Iterable<Port> ports, String ambariIp, String serviceAddress, StackServiceComponentDescriptor componentDescriptor, Cluster cluster) throws IOException {
if (componentDescriptor != null && componentDescriptor.isMaster()) {
List<String> exposedServices = new ArrayList<>();
Gateway gateway = cluster.getGateway();
if (gateway.getExposedServices() != null && gateway.getExposedServices().getValue() != null) {
exposedServices = gateway.getExposedServices().get(ExposedServices.class).getServices();
}
for (Port port : ports) {
collectServicePort(result, port, serviceAddress, ambariIp, componentDescriptor, exposedServices, gateway);
}
}
}
Aggregations