@Test public void testUpdateResources() 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>(); properties.put(FeedResourceProvider.FEED_NAME_PROPERTY_ID, "Feed1"); properties.put(FeedResourceProvider.FEED_DESCRIPTION_PROPERTY_ID, "desc"); properties.put(FeedResourceProvider.FEED_SCHEDULE_PROPERTY_ID, "sched"); properties.put(FeedResourceProvider.FEED_STATUS_PROPERTY_ID, "WAITING"); properties.put(FeedResourceProvider.FEED_SOURCE_CLUSTER_NAME_PROPERTY_ID, "source"); properties.put(FeedResourceProvider.FEED_TARGET_CLUSTER_NAME_PROPERTY_ID, "target"); List<String> feedNames = new LinkedList<String>(); feedNames.add("Feed1"); Map<String,String> props = new HashMap<String, String>(); Feed feed1 = new Feed("Feed1", "desc", "WAITING", "sched", "source", "st", "end", "l", "a", "target", "st", "end", "l", "a", props); expect(service.getFeedNames()).andReturn(feedNames); expect(service.getFeed("Feed1")).andReturn(feed1); service.updateFeed(feed1); replay(service); propertySet.add(properties); Request request = PropertyHelper.getCreateRequest(propertySet, Collections.<String,String>emptyMap()); FeedResourceProvider provider = new FeedResourceProvider(service, PropertyHelper.getPropertyIds(Resource.Type.DRFeed), PropertyHelper.getKeyPropertyIds(Resource.Type.DRFeed)); provider.updateResources(request, null); verify(service); }
@Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(FEED_STATUS_PROPERTY_ID); Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { IvoryService service = getService(); if (desiredStatus != null) { String status = (String) resource.getPropertyValue(FEED_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID); if (desiredStatus.equals("SCHEDULED")) { service.scheduleFeed(feedName); } else if (desiredStatus.equals("SUSPENDED")) { service.suspendFeed(feedName); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeFeed(feedName); } } service.updateFeed(getFeed((String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID), getUpdateMap(resource, propertyMap))); } } return new RequestStatusImpl(null); }
FeedResourceProvider extends AbstractDRResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(FEED_STATUS_PROPERTY_ID); Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { IvoryService service = getService(); if (desiredStatus != null) { String status = (String) resource.getPropertyValue(FEED_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID); if (desiredStatus.equals("SCHEDULED")) { service.scheduleFeed(feedName); } else if (desiredStatus.equals("SUSPENDED")) { service.suspendFeed(feedName); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeFeed(feedName); } } service.updateFeed(getFeed((String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID), getUpdateMap(resource, propertyMap))); } } return new RequestStatusImpl(null); } }
FeedResourceProvider extends AbstractDRResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(FEED_STATUS_PROPERTY_ID); Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { IvoryService service = getService(); if (desiredStatus != null) { String status = (String) resource.getPropertyValue(FEED_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID); if (desiredStatus.equals("SCHEDULED")) { service.scheduleFeed(feedName); } else if (desiredStatus.equals("SUSPENDED")) { service.suspendFeed(feedName); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeFeed(feedName); } } service.updateFeed(getFeed((String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID), getUpdateMap(resource, propertyMap))); } } return new RequestStatusImpl(null); } FeedResourceProvider(IvoryService ivoryService,
                              Set<String> propertyIds,
                              Map<Resource.Type, String> keyPropertyIds); }
FeedResourceProvider extends AbstractDRResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(FEED_STATUS_PROPERTY_ID); Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { IvoryService service = getService(); if (desiredStatus != null) { String status = (String) resource.getPropertyValue(FEED_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID); if (desiredStatus.equals("SCHEDULED")) { service.scheduleFeed(feedName); } else if (desiredStatus.equals("SUSPENDED")) { service.suspendFeed(feedName); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeFeed(feedName); } } service.updateFeed(getFeed((String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID), getUpdateMap(resource, propertyMap))); } } return new RequestStatusImpl(null); } FeedResourceProvider(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); }
FeedResourceProvider extends AbstractDRResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(FEED_STATUS_PROPERTY_ID); Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { IvoryService service = getService(); if (desiredStatus != null) { String status = (String) resource.getPropertyValue(FEED_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID); if (desiredStatus.equals("SCHEDULED")) { service.scheduleFeed(feedName); } else if (desiredStatus.equals("SUSPENDED")) { service.suspendFeed(feedName); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeFeed(feedName); } } service.updateFeed(getFeed((String) resource.getPropertyValue(FEED_NAME_PROPERTY_ID), getUpdateMap(resource, propertyMap))); } } return new RequestStatusImpl(null); } FeedResourceProvider(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);  }