Search in sources :

Example 1 with EndpointRule

use of com.sequenceiq.cloudbreak.api.model.EndpointRule 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;
}
Also used : Port(com.sequenceiq.cloudbreak.api.model.Port) EndpointRule(com.sequenceiq.cloudbreak.api.model.EndpointRule) ArrayList(java.util.ArrayList) SecurityRule(com.sequenceiq.cloudbreak.domain.SecurityRule) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 2 with EndpointRule

use of com.sequenceiq.cloudbreak.api.model.EndpointRule in project cloudbreak by hortonworks.

the class NetworkUtils method createACLRules.

private static List<EndpointRule> createACLRules(Stack stack) {
    List<EndpointRule> rules = new LinkedList<>();
    for (InstanceGroup instanceGroup : stack.getInstanceGroups()) {
        for (SecurityRule rule : instanceGroup.getSecurityGroup().getSecurityRules()) {
            rules.add(new EndpointRule(Action.PERMIT.getText(), rule.getCidr()));
        }
    }
    EndpointRule internalRule = new EndpointRule(Action.PERMIT.toString(), stack.getNetwork().getSubnetCIDR());
    rules.add(internalRule);
    rules.add(EndpointRule.DENY_RULE);
    return rules;
}
Also used : EndpointRule(com.sequenceiq.cloudbreak.api.model.EndpointRule) SecurityRule(com.sequenceiq.cloudbreak.domain.SecurityRule) LinkedList(java.util.LinkedList) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Aggregations

EndpointRule (com.sequenceiq.cloudbreak.api.model.EndpointRule)2 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)2 SecurityRule (com.sequenceiq.cloudbreak.domain.SecurityRule)2 Port (com.sequenceiq.cloudbreak.api.model.Port)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1