use of com.sequenceiq.cloudbreak.cloud.model.SecurityRule in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildSecurity.
private Security buildSecurity(InstanceGroup ig) {
List<SecurityRule> rules = new ArrayList<>();
if (ig.getSecurityGroup() == null) {
return new Security(rules, null);
}
Long id = ig.getSecurityGroup().getId();
List<com.sequenceiq.cloudbreak.domain.SecurityRule> securityRules = securityRuleRepository.findAllBySecurityGroupId(id);
for (com.sequenceiq.cloudbreak.domain.SecurityRule securityRule : securityRules) {
List<PortDefinition> portDefinitions = new ArrayList<>();
for (String actualPort : securityRule.getPorts()) {
String[] segments = actualPort.split("-");
if (segments.length > 1) {
portDefinitions.add(new PortDefinition(segments[0], segments[1]));
} else {
portDefinitions.add(new PortDefinition(segments[0], segments[0]));
}
}
rules.add(new SecurityRule(securityRule.getCidr(), portDefinitions.toArray(new PortDefinition[portDefinitions.size()]), securityRule.getProtocol()));
}
return new Security(rules, ig.getSecurityGroup().getSecurityGroupId());
}
use of com.sequenceiq.cloudbreak.cloud.model.SecurityRule in project cloudbreak by hortonworks.
the class GcpFirewallInResourceBuilder method getSourceRanges.
private List<String> getSourceRanges(Security security) {
List<SecurityRule> rules = security.getRules();
List<String> sourceRanges = new ArrayList<>(rules.size());
for (SecurityRule securityRule : rules) {
sourceRanges.add(securityRule.getCidr());
}
return sourceRanges;
}
use of com.sequenceiq.cloudbreak.cloud.model.SecurityRule in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method setup.
@Before
public void setup() throws IOException, TemplateException {
initMocks(this);
FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
factoryBean.setPreferFileSystemAccess(false);
factoryBean.setTemplateLoaderPath("classpath:/");
factoryBean.afterPropertiesSet();
Configuration configuration = factoryBean.getObject();
ReflectionTestUtils.setField(heatTemplateBuilder, "freemarkerConfiguration", configuration);
ReflectionTestUtils.setField(heatTemplateBuilder, "openStackHeatTemplatePath", templatePath);
stackName = "testStack";
groups = new ArrayList<>(1);
String name = "master";
List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication);
List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
Security security = new Security(rules, null);
groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
Map<String, String> tags = new HashMap<>();
tags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key());
tags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key());
tags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key());
tags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key());
tags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key());
tags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key());
tags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key());
when(defaultCostTaggingService.prepareInstanceTagging()).thenReturn(tags);
image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "url", "default", null);
}
use of com.sequenceiq.cloudbreak.cloud.model.SecurityRule in project cloudbreak by hortonworks.
the class OpenStackSecurityGroupResourceBuilder method build.
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource resource) {
try {
OSClient<?> osClient = createOSClient(auth);
ComputeSecurityGroupService securityGroupService = osClient.compute().securityGroups();
SecGroupExtension securityGroup = securityGroupService.create(resource.getName(), "");
String securityGroupId = securityGroup.getId();
for (SecurityRule rule : security.getRules()) {
IPProtocol osProtocol = getProtocol(rule.getProtocol());
String cidr = rule.getCidr();
for (PortDefinition portStr : rule.getPorts()) {
int from = Integer.parseInt(portStr.getFrom());
int to = Integer.parseInt(portStr.getTo());
securityGroupService.createRule(createRule(securityGroupId, osProtocol, cidr, from, to));
}
}
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String subnetCidr = neutronView.isExistingSubnet() ? utils.getExistingSubnetCidr(auth, neutronView) : network.getSubnet().getCidr();
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.TCP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.UDP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.ICMP, "0.0.0.0/0"));
return createPersistedResource(resource, group.getName(), securityGroup.getId());
} catch (OS4JException ex) {
throw new OpenStackResourceException("SecurityGroup creation failed", resourceType(), resource.getName(), ex);
}
}
Aggregations