@Test public void throwExceptionWhenNotEnoughInstancesInGroup() { List<CloudResource> instances = List.of(); ResourceBuilderContext context = new ResourceBuilderContext("context", Location.location(Region.region("us-west-1")), 0); List<Group> groups = new ArrayList<>(); List<CloudInstance> computeInstances = new ArrayList<>(); computeInstances.add(new CloudInstance(null, getInstanceTemplate(4L, "compute"), mock(InstanceAuthentication.class))); groups.add(new Group("compute", InstanceGroupType.CORE, computeInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty())); CloudConnectorException exception = assertThrows(CloudConnectorException.class, () -> awsContextService.addInstancesToContext(instances, context, groups)); assertEquals("Not found enough instances in compute group, expected 1, got 0. " + "Please check the instances on your cloud provider for further details.", exception.getMessage()); }
public void addInstancesToContext(List<CloudResource> instances, ResourceBuilderContext context, List<Group> groups) { groups.forEach(group -> { List<Long> ids = group.getInstances().stream() .filter(instance -> Objects.isNull(instance.getInstanceId())) .map(CloudInstance::getTemplate) .map(InstanceTemplate::getPrivateId) .collect(Collectors.toList()); List<CloudResource> groupInstances = instances.stream().filter(inst -> inst.getGroup().equals(group.getName())).collect(Collectors.toList()); if (ids.size() > groupInstances.size()) { String message = String.format("Not found enough instances in %s group, expected %s, got %s. " + "Please check the instances on your cloud provider for further details.", group.getName(), ids.size(), groupInstances.size()); throw new CloudConnectorException(message); } for (int i = 0; i < ids.size(); i++) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } }); }
AwsContextService { public void addInstancesToContext(List<CloudResource> instances, ResourceBuilderContext context, List<Group> groups) { groups.forEach(group -> { List<Long> ids = group.getInstances().stream() .filter(instance -> Objects.isNull(instance.getInstanceId())) .map(CloudInstance::getTemplate) .map(InstanceTemplate::getPrivateId) .collect(Collectors.toList()); List<CloudResource> groupInstances = instances.stream().filter(inst -> inst.getGroup().equals(group.getName())).collect(Collectors.toList()); if (ids.size() > groupInstances.size()) { String message = String.format("Not found enough instances in %s group, expected %s, got %s. " + "Please check the instances on your cloud provider for further details.", group.getName(), ids.size(), groupInstances.size()); throw new CloudConnectorException(message); } for (int i = 0; i < ids.size(); i++) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } }); } }
AwsContextService { public void addInstancesToContext(List<CloudResource> instances, ResourceBuilderContext context, List<Group> groups) { groups.forEach(group -> { List<Long> ids = group.getInstances().stream() .filter(instance -> Objects.isNull(instance.getInstanceId())) .map(CloudInstance::getTemplate) .map(InstanceTemplate::getPrivateId) .collect(Collectors.toList()); List<CloudResource> groupInstances = instances.stream().filter(inst -> inst.getGroup().equals(group.getName())).collect(Collectors.toList()); if (ids.size() > groupInstances.size()) { String message = String.format("Not found enough instances in %s group, expected %s, got %s. " + "Please check the instances on your cloud provider for further details.", group.getName(), ids.size(), groupInstances.size()); throw new CloudConnectorException(message); } for (int i = 0; i < ids.size(); i++) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } }); }  }
AwsContextService { public void addInstancesToContext(List<CloudResource> instances, ResourceBuilderContext context, List<Group> groups) { groups.forEach(group -> { List<Long> ids = group.getInstances().stream() .filter(instance -> Objects.isNull(instance.getInstanceId())) .map(CloudInstance::getTemplate) .map(InstanceTemplate::getPrivateId) .collect(Collectors.toList()); List<CloudResource> groupInstances = instances.stream().filter(inst -> inst.getGroup().equals(group.getName())).collect(Collectors.toList()); if (ids.size() > groupInstances.size()) { String message = String.format("Not found enough instances in %s group, expected %s, got %s. " + "Please check the instances on your cloud provider for further details.", group.getName(), ids.size(), groupInstances.size()); throw new CloudConnectorException(message); } for (int i = 0; i < ids.size(); i++) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } }); }  void addInstancesToContext(List<CloudResource> instances, ResourceBuilderContext context, List<Group> groups); void addResourcesToContext(List<CloudResource> resources, ResourceBuilderContext context, List<Group> groups); }
AwsContextService { public void addInstancesToContext(List<CloudResource> instances, ResourceBuilderContext context, List<Group> groups) { groups.forEach(group -> { List<Long> ids = group.getInstances().stream() .filter(instance -> Objects.isNull(instance.getInstanceId())) .map(CloudInstance::getTemplate) .map(InstanceTemplate::getPrivateId) .collect(Collectors.toList()); List<CloudResource> groupInstances = instances.stream().filter(inst -> inst.getGroup().equals(group.getName())).collect(Collectors.toList()); if (ids.size() > groupInstances.size()) { String message = String.format("Not found enough instances in %s group, expected %s, got %s. " + "Please check the instances on your cloud provider for further details.", group.getName(), ids.size(), groupInstances.size()); throw new CloudConnectorException(message); } for (int i = 0; i < ids.size(); i++) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } }); }  void addInstancesToContext(List<CloudResource> instances, ResourceBuilderContext context, List<Group> groups); void addResourcesToContext(List<CloudResource> resources, ResourceBuilderContext context, List<Group> groups);  }