Search in sources :

Example 6 with Security

use of com.sequenceiq.cloudbreak.cloud.model.Security 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());
}
Also used : PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) ArrayList(java.util.ArrayList) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security)

Example 7 with Security

use of com.sequenceiq.cloudbreak.cloud.model.Security 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);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Configuration(freemarker.template.Configuration) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Matchers.containsString(org.hamcrest.Matchers.containsString) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Before(org.junit.Before)

Aggregations

Security (com.sequenceiq.cloudbreak.cloud.model.Security)7 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)6 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)6 InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)5 Image (com.sequenceiq.cloudbreak.cloud.model.Image)5 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)5 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 Group (com.sequenceiq.cloudbreak.cloud.model.Group)4 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)4 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Before (org.junit.Before)4 Configuration (freemarker.template.Configuration)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 FreeMarkerConfigurationFactoryBean (org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean)3 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 Network (com.sequenceiq.cloudbreak.cloud.model.Network)2 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)2