NovaLauncher extends Launcher { @Override public void cleanup(JsonCluster definition, ClusterRuntime runtime) throws KaramelException { runtime.resolveFailures(); List<GroupRuntime> groups = runtime.getGroups(); Set<String> allNovaVms = new HashSet<>(); Set<String> allNovaVmsIds = new HashSet<>(); Map<String, String> groupRegion = new HashMap<>(); for (GroupRuntime group : groups) { group.getCluster().resolveFailures(); Provider provider = UserClusterDataExtractor.getGroupProvider(definition, group.getName()); if (provider instanceof Nova) { for (MachineRuntime machine : group.getMachines()) { if (machine.getVmId() != null) { allNovaVmsIds.add(machine.getVmId()); } } JsonGroup jg = UserClusterDataExtractor.findGroup(definition, group.getName()); List<String> vmNames = NovaSetting.NOVA_UNIQUE_VM_NAMES(group.getCluster().getName(), group.getName(), jg.getSize()); allNovaVms.addAll(vmNames); groupRegion.put(group.getName(), novaContext.getNovaCredentials().getRegion()); } } cleanup(definition.getName(), allNovaVmsIds, allNovaVms, groupRegion); } 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);  }
@Test public void cleanup() throws KaramelException{ String uniqueGroup = NovaSetting.NOVA_UNIQUE_GROUP_NAME(clusterName, groupName); JsonCluster cluster = mock(JsonCluster.class); ClusterRuntime clusterRuntime = mock(ClusterRuntime.class); when(clusterRuntime.getName()).thenReturn(clusterName); List<JsonGroup> groups = new ArrayList<>(); JsonGroup group = mock(JsonGroup.class); groups.add(group); when(cluster.getGroups()).thenReturn(groups); when(cluster.getProvider()).thenReturn(nova); when(cluster.getName()).thenReturn(clusterName); when(group.getName()).thenReturn(groupName); when(group.getProvider()).thenReturn(nova); when(group.getSize()).thenReturn(1); List<GroupRuntime> groupRuntimes = new ArrayList<>(); GroupRuntime groupRuntime = mock(GroupRuntime.class); when(groupRuntime.getName()).thenReturn(groupName); when(groupRuntime.getId()).thenReturn("10"); when(groupRuntime.getCluster()).thenReturn(clusterRuntime); groupRuntimes.add(groupRuntime); when(clusterRuntime.getGroups()).thenReturn(groupRuntimes); SecurityGroup securityGroup = mock(SecurityGroup.class); List<SecurityGroup> securityGroupList = new ArrayList<>(); securityGroupList.add(securityGroup); FluentIterable<SecurityGroup> securityGroupFluentIterable = FluentIterable.from(securityGroupList); when(novaContext.getSecurityGroupApi()).thenReturn(securityGroupApi); when(securityGroupApi.list()).thenReturn(securityGroupFluentIterable); when(securityGroup.getName()).thenReturn(uniqueGroup); NovaLauncher novaLauncher = new NovaLauncher(novaContext, sshKeyPair); novaLauncher.cleanup(cluster, clusterRuntime); }