@Test public void createSecurityGroupTestWithTestingFlag() throws KaramelException { SecurityGroupRule rule = mock(SecurityGroupRule.class); String uniqueGroup = NovaSetting.NOVA_UNIQUE_GROUP_NAME(clusterName, groupName); String uniqueDescription = NovaSetting.NOVA_UNIQUE_GROUP_DESCRIPTION(clusterName, groupName); Ingress ingress = Ingress.builder() .fromPort(0) .toPort(65535) .ipProtocol(IpProtocol.TCP) .build(); when(novaContext.getSecurityGroupApi()).thenReturn(securityGroupApi); when(securityGroupApi.createWithDescription(uniqueGroup, uniqueDescription)).thenReturn(securityGroupCreated); when(securityGroupCreated.getId()).thenReturn("10"); when(securityGroupApi.createRuleAllowingCidrBlock("10", ingress, "0.0.0.0/0")).thenReturn(rule); NovaLauncher novaLauncher = new NovaLauncher(novaContext, sshKeyPair); String groupId = novaLauncher.createSecurityGroup(clusterName, groupName, nova, ports); assertEquals("10", groupId); }
public String createSecurityGroup(String clusterName, String groupName, Nova nova, Set<String> ports) { String securityGroupUniqueName = NovaSetting.NOVA_UNIQUE_GROUP_NAME(clusterName, groupName); logger.info(String.format("Creating security group '%s' ...", securityGroupUniqueName)); SecurityGroupApi client = novaContext.getSecurityGroupApi(); String groupId; SecurityGroup created = client.createWithDescription(securityGroupUniqueName, NovaSetting .NOVA_UNIQUE_GROUP_DESCRIPTION(clusterName, groupName)); groupId = created.getId(); if (!TESTING) { for (String port : ports) { Integer portNumber; IpProtocol ipProtocol; if (port.contains("/")) { String[] s = port.split("/"); portNumber = Integer.valueOf(s[0]); ipProtocol = IpProtocol.valueOf(s[1]); } else { portNumber = Integer.valueOf(port); ipProtocol = IpProtocol.TCP; } Ingress ingress = Ingress.builder() .fromPort(portNumber) .toPort(portNumber) .ipProtocol(ipProtocol) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } } else { Ingress ingress = Ingress.builder() .fromPort(1) .toPort(65535) .ipProtocol(IpProtocol.TCP) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } logger.info(String.format("Security group '%s' was created :)", securityGroupUniqueName)); return groupId; }
NovaLauncher extends Launcher { public String createSecurityGroup(String clusterName, String groupName, Nova nova, Set<String> ports) { String securityGroupUniqueName = NovaSetting.NOVA_UNIQUE_GROUP_NAME(clusterName, groupName); logger.info(String.format("Creating security group '%s' ...", securityGroupUniqueName)); SecurityGroupApi client = novaContext.getSecurityGroupApi(); String groupId; SecurityGroup created = client.createWithDescription(securityGroupUniqueName, NovaSetting .NOVA_UNIQUE_GROUP_DESCRIPTION(clusterName, groupName)); groupId = created.getId(); if (!TESTING) { for (String port : ports) { Integer portNumber; IpProtocol ipProtocol; if (port.contains("/")) { String[] s = port.split("/"); portNumber = Integer.valueOf(s[0]); ipProtocol = IpProtocol.valueOf(s[1]); } else { portNumber = Integer.valueOf(port); ipProtocol = IpProtocol.TCP; } Ingress ingress = Ingress.builder() .fromPort(portNumber) .toPort(portNumber) .ipProtocol(ipProtocol) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } } else { Ingress ingress = Ingress.builder() .fromPort(1) .toPort(65535) .ipProtocol(IpProtocol.TCP) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } logger.info(String.format("Security group '%s' was created :)", securityGroupUniqueName)); return groupId; } }
NovaLauncher extends Launcher { public String createSecurityGroup(String clusterName, String groupName, Nova nova, Set<String> ports) { String securityGroupUniqueName = NovaSetting.NOVA_UNIQUE_GROUP_NAME(clusterName, groupName); logger.info(String.format("Creating security group '%s' ...", securityGroupUniqueName)); SecurityGroupApi client = novaContext.getSecurityGroupApi(); String groupId; SecurityGroup created = client.createWithDescription(securityGroupUniqueName, NovaSetting .NOVA_UNIQUE_GROUP_DESCRIPTION(clusterName, groupName)); groupId = created.getId(); if (!TESTING) { for (String port : ports) { Integer portNumber; IpProtocol ipProtocol; if (port.contains("/")) { String[] s = port.split("/"); portNumber = Integer.valueOf(s[0]); ipProtocol = IpProtocol.valueOf(s[1]); } else { portNumber = Integer.valueOf(port); ipProtocol = IpProtocol.TCP; } Ingress ingress = Ingress.builder() .fromPort(portNumber) .toPort(portNumber) .ipProtocol(ipProtocol) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } } else { Ingress ingress = Ingress.builder() .fromPort(1) .toPort(65535) .ipProtocol(IpProtocol.TCP) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } logger.info(String.format("Security group '%s' was created :)", securityGroupUniqueName)); return groupId; } NovaLauncher(NovaContext novaContext, SshKeyPair sshKeyPair); }
NovaLauncher extends Launcher { public String createSecurityGroup(String clusterName, String groupName, Nova nova, Set<String> ports) { String securityGroupUniqueName = NovaSetting.NOVA_UNIQUE_GROUP_NAME(clusterName, groupName); logger.info(String.format("Creating security group '%s' ...", securityGroupUniqueName)); SecurityGroupApi client = novaContext.getSecurityGroupApi(); String groupId; SecurityGroup created = client.createWithDescription(securityGroupUniqueName, NovaSetting .NOVA_UNIQUE_GROUP_DESCRIPTION(clusterName, groupName)); groupId = created.getId(); if (!TESTING) { for (String port : ports) { Integer portNumber; IpProtocol ipProtocol; if (port.contains("/")) { String[] s = port.split("/"); portNumber = Integer.valueOf(s[0]); ipProtocol = IpProtocol.valueOf(s[1]); } else { portNumber = Integer.valueOf(port); ipProtocol = IpProtocol.TCP; } Ingress ingress = Ingress.builder() .fromPort(portNumber) .toPort(portNumber) .ipProtocol(ipProtocol) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } } else { Ingress ingress = Ingress.builder() .fromPort(1) .toPort(65535) .ipProtocol(IpProtocol.TCP) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } logger.info(String.format("Security group '%s' was created :)", securityGroupUniqueName)); return groupId; } NovaLauncher(NovaContext novaContext, SshKeyPair sshKeyPair); static NovaContext validateCredentials(NovaCredentials novaCredentials, ContextBuilder builder); static NovaCredentials readCredentials(Confs confs); String createSecurityGroup(String clusterName, String groupName, Nova nova, Set<String> ports); boolean uploadSshPublicKey(String keyPairName, Nova nova, boolean removeOld); boolean cleanupFailedNodes(Map<NodeMetadata, Throwable> failedNodes); @Override void cleanup(JsonCluster definition, ClusterRuntime runtime); void cleanup(String clusterName, Set<String> vmIds, Set<String> vmNames, Map<String, String> groupRegion); @Override String forkGroup(JsonCluster definition, ClusterRuntime runtime, String name); @Override List<MachineRuntime> forkMachines(JsonCluster definition, ClusterRuntime runtime, String name); static Predicate<NodeMetadata> withPredicate(final Set<String> ids, final Set<String> names,
                                                      final Set<String> groupNames); }
NovaLauncher extends Launcher { public String createSecurityGroup(String clusterName, String groupName, Nova nova, Set<String> ports) { String securityGroupUniqueName = NovaSetting.NOVA_UNIQUE_GROUP_NAME(clusterName, groupName); logger.info(String.format("Creating security group '%s' ...", securityGroupUniqueName)); SecurityGroupApi client = novaContext.getSecurityGroupApi(); String groupId; SecurityGroup created = client.createWithDescription(securityGroupUniqueName, NovaSetting .NOVA_UNIQUE_GROUP_DESCRIPTION(clusterName, groupName)); groupId = created.getId(); if (!TESTING) { for (String port : ports) { Integer portNumber; IpProtocol ipProtocol; if (port.contains("/")) { String[] s = port.split("/"); portNumber = Integer.valueOf(s[0]); ipProtocol = IpProtocol.valueOf(s[1]); } else { portNumber = Integer.valueOf(port); ipProtocol = IpProtocol.TCP; } Ingress ingress = Ingress.builder() .fromPort(portNumber) .toPort(portNumber) .ipProtocol(ipProtocol) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } } else { Ingress ingress = Ingress.builder() .fromPort(1) .toPort(65535) .ipProtocol(IpProtocol.TCP) .build(); client.createRuleAllowingCidrBlock(groupId, ingress, "0.0.0.0/0"); logger.info(String.format("Ports became open for '%s'", securityGroupUniqueName)); } logger.info(String.format("Security group '%s' was created :)", securityGroupUniqueName)); return groupId; } NovaLauncher(NovaContext novaContext, SshKeyPair sshKeyPair); static NovaContext validateCredentials(NovaCredentials novaCredentials, ContextBuilder builder); static NovaCredentials readCredentials(Confs confs); String createSecurityGroup(String clusterName, String groupName, Nova nova, Set<String> ports); boolean uploadSshPublicKey(String keyPairName, Nova nova, boolean removeOld); boolean cleanupFailedNodes(Map<NodeMetadata, Throwable> failedNodes); @Override void cleanup(JsonCluster definition, ClusterRuntime runtime); void cleanup(String clusterName, Set<String> vmIds, Set<String> vmNames, Map<String, String> groupRegion); @Override String forkGroup(JsonCluster definition, ClusterRuntime runtime, String name); @Override List<MachineRuntime> forkMachines(JsonCluster definition, ClusterRuntime runtime, String name); static Predicate<NodeMetadata> withPredicate(final Set<String> ids, final Set<String> names,
                                                      final Set<String> groupNames);  }