@Override public List<VirtualMachine> getVirtualMachines( Long applicationId, Long componentId, Long instanceId, Long cloudId) { List<VirtualMachine> vms; List<VirtualMachine> result = new ArrayList<VirtualMachine>(); vms = virtualMachineModelService.getAll(); for (VirtualMachine vm : vms) { boolean suitable = true; List<Instance> instances = null; List<ApplicationComponent> appComps = null; // Filter for application id if (applicationId != null) { instances = this.getInstances(vm.getId()); appComps = new ArrayList<>(); for (Instance instance : instances) { if (instance.getVirtualMachine().getId().equals(vm.getId())) { LOGGER.info("Instance " + instance.getId() + " belongs to VM " + vm.getId()); appComps.add( getApplicationComponentForInstance(instance.getApplicationComponent().getId())); } } boolean oneInstanceFit = false; for (ApplicationComponent ac : appComps) { if (ac.getApplication().getId() == applicationId) { oneInstanceFit = true; } } suitable = oneInstanceFit; } // Filter for component id if (suitable && componentId != null) { if (instances == null) { instances = this.getInstances(vm.getId()); appComps = new ArrayList<ApplicationComponent>(); for (Instance instance : instances) { appComps.add( getApplicationComponentForInstance(instance.getApplicationComponent().getId())); } } boolean oneInstanceFit = false; for (ApplicationComponent ac : appComps) { if (ac.getComponent().getId() == componentId) { oneInstanceFit = true; } } suitable = oneInstanceFit; } // Filter for instance id if (suitable && instanceId != null) { if (instances == null) { instances = this.getInstances(vm.getId()); } boolean oneInstanceFit = false; for (Instance instance : instances) { if (instance.getId() == instanceId) { oneInstanceFit = true; } } suitable = oneInstanceFit; } // Filter for cloud id if (suitable && cloudId != null) { if (vm.cloud().getId() != cloudId) { suitable = false; } } // Add to result if (suitable) { result.add(vm); } } return result; }
@Override public List<Component> getComponents( Long applicationId, Long componentId, Long instanceId, Long cloudId) { List<Component> result = new ArrayList<Component>(); List<Component> components = componentModelService.getAll(); List<Instance> instances = null; List<VirtualMachine> vms = null; List<ApplicationComponent> appComps = applicationComponentModelService.getAll(); for (Component component : components) { boolean suitable = false; if (applicationId != null) { for (ApplicationComponent ac : appComps) { if (ac.getComponent().getId().equals(componentId) && ac.getApplication().getId().equals(applicationId)) { suitable = true; } } } if (componentId != null) { if (componentId.equals(component.getId())) { suitable = suitable && true; } } if (instanceId != null) { if (instances == null) instances = instanceModelService.getAll(); boolean oneFits = false; for (Instance instance : instances) { if (isInstanceOf(instance, appComps, component)) { oneFits = true; } } if (oneFits) { suitable = suitable && true; } else { suitable = false; } } if (cloudId != null) { if (instances == null) instances = instanceModelService.getAll(); if (vms == null) vms = virtualMachineModelService.getAll(); boolean oneFits = false; for (Instance instance : instances) { if (isInstanceOf(instance, vms, cloudId)) { if (isInstanceOf(instance, appComps, component)) { oneFits = true; } } } if (oneFits) { suitable = suitable && true; } else { suitable = false; } } if (suitable) { result.add(component); } } return result; }