@Test void addResourcesToContextTest() { List<CloudResource> resources = new ArrayList<>(); resources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker1").group("worker").build()); resources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker2").group("worker").build()); resources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker3").group("worker").build()); resources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("compute1").group("compute").build()); resources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("compute2").group("compute").build()); resources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("compute3").group("compute").build()); resources.add(CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.REQUESTED).name("volume1").group("worker").build()); resources.add(CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.REQUESTED).name("volume3").group("compute").build()); resources.add(CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.REQUESTED).name("volume4").group("compute").build()); List<Group> groups = new ArrayList<>(); List<CloudInstance> workerInstances = new ArrayList<>(); workerInstances.add(new CloudInstance("W1", getInstanceTemplate(1L, "worker"), mock(InstanceAuthentication.class))); workerInstances.add(new CloudInstance(null, getInstanceTemplate(2L, "worker"), mock(InstanceAuthentication.class))); workerInstances.add(new CloudInstance(null, getInstanceTemplate(3L, "worker"), mock(InstanceAuthentication.class))); groups.add(new Group("worker", InstanceGroupType.CORE, workerInstances, mock(Security.class), mock(CloudInstance.class), mock(InstanceAuthentication.class), "admin", "ssh", 100, Optional.empty())); List<CloudInstance> computeInstances = new ArrayList<>(); computeInstances.add(new CloudInstance("C1", getInstanceTemplate(4L, "compute"), mock(InstanceAuthentication.class))); computeInstances.add(new CloudInstance("C2", getInstanceTemplate(5L, "compute"), mock(InstanceAuthentication.class))); computeInstances.add(new CloudInstance(null, getInstanceTemplate(6L, "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())); ResourceBuilderContext context = new ResourceBuilderContext("context", Location.location(Region.region("us-west-1")), 0); awsContextService.addResourcesToContext(resources, context, groups); List<CloudResource> worker1 = context.getComputeResources(2L); assertEquals(2, worker1.size()); assertTrue(worker1.stream().anyMatch(cloudResource -> "worker1".equals(cloudResource.getName()))); assertTrue(worker1.stream().anyMatch(cloudResource -> "volume1".equals(cloudResource.getName()))); List<CloudResource> worker2 = context.getComputeResources(3L); assertEquals(1, worker2.size()); assertTrue(worker2.stream().anyMatch(cloudResource -> "worker2".equals(cloudResource.getName()))); List<CloudResource> compute1 = context.getComputeResources(6L); assertEquals(2, compute1.size()); assertTrue(compute1.stream().anyMatch(cloudResource -> "compute1".equals(cloudResource.getName()))); assertTrue(compute1.stream().anyMatch(cloudResource -> "volume3".equals(cloudResource.getName()))); }
public void addResourcesToContext(List<CloudResource> resources, 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 = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_INSTANCE); List<CloudResource> groupVolumeSets = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_VOLUMESET); for (int i = 0; i < ids.size(); i++) { if (i < groupInstances.size()) { if (i > groupVolumeSets.size() - 1) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } else { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i), groupVolumeSets.get(i))); } } } }); }
AwsContextService { public void addResourcesToContext(List<CloudResource> resources, 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 = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_INSTANCE); List<CloudResource> groupVolumeSets = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_VOLUMESET); for (int i = 0; i < ids.size(); i++) { if (i < groupInstances.size()) { if (i > groupVolumeSets.size() - 1) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } else { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i), groupVolumeSets.get(i))); } } } }); } }
AwsContextService { public void addResourcesToContext(List<CloudResource> resources, 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 = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_INSTANCE); List<CloudResource> groupVolumeSets = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_VOLUMESET); for (int i = 0; i < ids.size(); i++) { if (i < groupInstances.size()) { if (i > groupVolumeSets.size() - 1) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } else { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i), groupVolumeSets.get(i))); } } } }); }  }
AwsContextService { public void addResourcesToContext(List<CloudResource> resources, 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 = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_INSTANCE); List<CloudResource> groupVolumeSets = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_VOLUMESET); for (int i = 0; i < ids.size(); i++) { if (i < groupInstances.size()) { if (i > groupVolumeSets.size() - 1) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } else { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i), groupVolumeSets.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 addResourcesToContext(List<CloudResource> resources, 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 = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_INSTANCE); List<CloudResource> groupVolumeSets = getResourcesOfTypeInGroup(resources, group, ResourceType.AWS_VOLUMESET); for (int i = 0; i < ids.size(); i++) { if (i < groupInstances.size()) { if (i > groupVolumeSets.size() - 1) { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i))); } else { context.addComputeResources(ids.get(i), List.of(groupInstances.get(i), groupVolumeSets.get(i))); } } } }); }  void addInstancesToContext(List<CloudResource> instances, ResourceBuilderContext context, List<Group> groups); void addResourcesToContext(List<CloudResource> resources, ResourceBuilderContext context, List<Group> groups);  }