@Test public void testGetResources() throws Exception { IvoryService service = createMock(IvoryService.class); Set<Map<String, Object>> propertySet = new HashSet<Map<String, Object>>(); Map<String, Object> properties = new HashMap<String, Object>(); List<String> targetClusterNames = new LinkedList<String>(); targetClusterNames.add("Cluster1"); targetClusterNames.add("Cluster2"); targetClusterNames.add("Cluster3"); Cluster.Interface interface1 = new Cluster.Interface("type", "endpoint", "version"); Cluster.Location location1 = new Cluster.Location("name", "path"); Cluster targetCluster1 = new Cluster("Cluster1", "Colo", Collections.singleton(interface1), Collections.singleton(location1), Collections.singletonMap("P1", "V1")); Cluster targetCluster2 = new Cluster("Cluster2", "Colo", Collections.singleton(interface1), Collections.singleton(location1), Collections.singletonMap("P1", "V1")); Cluster targetCluster3 = new Cluster("Cluster3", "Colo", Collections.singleton(interface1), Collections.singleton(location1), Collections.singletonMap("P1", "V1")); expect(service.getClusterNames()).andReturn(targetClusterNames); expect(service.getCluster("Cluster1")).andReturn(targetCluster1); expect(service.getCluster("Cluster2")).andReturn(targetCluster2); expect(service.getCluster("Cluster3")).andReturn(targetCluster3); replay(service); propertySet.add(properties); Request request = PropertyHelper.getCreateRequest(propertySet, Collections.<String,String>emptyMap()); TargetClusterResourceProvider provider = new TargetClusterResourceProvider(service, PropertyHelper.getPropertyIds(Resource.Type.DRTargetCluster), PropertyHelper.getKeyPropertyIds(Resource.Type.DRTargetCluster)); Set<Resource> resources = provider.getResources(request, null); Assert.assertEquals(3, resources.size()); verify(service); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); List<String> clusterNames = service.getClusterNames(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (String clusterName : clusterNames ) { Cluster cluster = service.getCluster(clusterName); Resource resource = new ResourceImpl(Resource.Type.DRTargetCluster); setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, cluster.getName(), requestedIds); setResourceProperty(resource, CLUSTER_COLO_PROPERTY_ID, cluster.getColo(), requestedIds); setResourceProperty(resource, CLUSTER_INTERFACES_PROPERTY_ID, cluster.getInterfaces(), requestedIds); setResourceProperty(resource, CLUSTER_LOCATIONS_PROPERTY_ID, cluster.getLocations(), requestedIds); setResourceProperty(resource, CLUSTER_PROPERTIES_PROPERTY_ID, cluster.getProperties(), requestedIds); if (predicate == null || predicate.evaluate(resource)) { resources.add(resource); } } return resources; }
TargetClusterResourceProvider extends AbstractDRResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); List<String> clusterNames = service.getClusterNames(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (String clusterName : clusterNames ) { Cluster cluster = service.getCluster(clusterName); Resource resource = new ResourceImpl(Resource.Type.DRTargetCluster); setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, cluster.getName(), requestedIds); setResourceProperty(resource, CLUSTER_COLO_PROPERTY_ID, cluster.getColo(), requestedIds); setResourceProperty(resource, CLUSTER_INTERFACES_PROPERTY_ID, cluster.getInterfaces(), requestedIds); setResourceProperty(resource, CLUSTER_LOCATIONS_PROPERTY_ID, cluster.getLocations(), requestedIds); setResourceProperty(resource, CLUSTER_PROPERTIES_PROPERTY_ID, cluster.getProperties(), requestedIds); if (predicate == null || predicate.evaluate(resource)) { resources.add(resource); } } return resources; } }
TargetClusterResourceProvider extends AbstractDRResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); List<String> clusterNames = service.getClusterNames(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (String clusterName : clusterNames ) { Cluster cluster = service.getCluster(clusterName); Resource resource = new ResourceImpl(Resource.Type.DRTargetCluster); setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, cluster.getName(), requestedIds); setResourceProperty(resource, CLUSTER_COLO_PROPERTY_ID, cluster.getColo(), requestedIds); setResourceProperty(resource, CLUSTER_INTERFACES_PROPERTY_ID, cluster.getInterfaces(), requestedIds); setResourceProperty(resource, CLUSTER_LOCATIONS_PROPERTY_ID, cluster.getLocations(), requestedIds); setResourceProperty(resource, CLUSTER_PROPERTIES_PROPERTY_ID, cluster.getProperties(), requestedIds); if (predicate == null || predicate.evaluate(resource)) { resources.add(resource); } } return resources; } TargetClusterResourceProvider(IvoryService ivoryService,
                                       Set<String> propertyIds,
                                       Map<Resource.Type, String> keyPropertyIds); }
TargetClusterResourceProvider extends AbstractDRResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); List<String> clusterNames = service.getClusterNames(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (String clusterName : clusterNames ) { Cluster cluster = service.getCluster(clusterName); Resource resource = new ResourceImpl(Resource.Type.DRTargetCluster); setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, cluster.getName(), requestedIds); setResourceProperty(resource, CLUSTER_COLO_PROPERTY_ID, cluster.getColo(), requestedIds); setResourceProperty(resource, CLUSTER_INTERFACES_PROPERTY_ID, cluster.getInterfaces(), requestedIds); setResourceProperty(resource, CLUSTER_LOCATIONS_PROPERTY_ID, cluster.getLocations(), requestedIds); setResourceProperty(resource, CLUSTER_PROPERTIES_PROPERTY_ID, cluster.getProperties(), requestedIds); if (predicate == null || predicate.evaluate(resource)) { resources.add(resource); } } return resources; } TargetClusterResourceProvider(IvoryService ivoryService,
                                       Set<String> propertyIds,
                                       Map<Resource.Type, String> keyPropertyIds); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
TargetClusterResourceProvider extends AbstractDRResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); List<String> clusterNames = service.getClusterNames(); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (String clusterName : clusterNames ) { Cluster cluster = service.getCluster(clusterName); Resource resource = new ResourceImpl(Resource.Type.DRTargetCluster); setResourceProperty(resource, CLUSTER_NAME_PROPERTY_ID, cluster.getName(), requestedIds); setResourceProperty(resource, CLUSTER_COLO_PROPERTY_ID, cluster.getColo(), requestedIds); setResourceProperty(resource, CLUSTER_INTERFACES_PROPERTY_ID, cluster.getInterfaces(), requestedIds); setResourceProperty(resource, CLUSTER_LOCATIONS_PROPERTY_ID, cluster.getLocations(), requestedIds); setResourceProperty(resource, CLUSTER_PROPERTIES_PROPERTY_ID, cluster.getProperties(), requestedIds); if (predicate == null || predicate.evaluate(resource)) { resources.add(resource); } } return resources; } TargetClusterResourceProvider(IvoryService ivoryService,
                                       Set<String> propertyIds,
                                       Map<Resource.Type, String> keyPropertyIds); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate);  }