@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(InstanceResourceProvider.INSTANCE_FEED_NAME_PROPERTY_ID, "Feed1"); properties.put(InstanceResourceProvider.INSTANCE_ID_PROPERTY_ID, "Instance1"); properties.put(InstanceResourceProvider.INSTANCE_STATUS_PROPERTY_ID, "SUSPEND"); properties.put(InstanceResourceProvider.INSTANCE_START_TIME_PROPERTY_ID, "ST"); properties.put(InstanceResourceProvider.INSTANCE_END_TIME_PROPERTY_ID, "ET"); properties.put(InstanceResourceProvider.INSTANCE_DETAILS_PROPERTY_ID, "DETAILS"); properties.put(InstanceResourceProvider.INSTANCE_LOG_PROPERTY_ID, "log"); List<Instance> instances = new LinkedList<Instance>(); expect(service.getFeedNames()).andReturn(Collections.singletonList("Feed1")); expect(service.getInstances("Feed1")).andReturn(instances); replay(service); propertySet.add(properties); Request request = PropertyHelper.getCreateRequest(propertySet, Collections.<String,String>emptyMap()); InstanceResourceProvider provider = new InstanceResourceProvider(service, PropertyHelper.getPropertyIds(Resource.Type.DRInstance), PropertyHelper.getKeyPropertyIds(Resource.Type.DRInstance)); provider.updateResources(request, null); verify(service); }
@Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(INSTANCE_STATUS_PROPERTY_ID); if (desiredStatus != null) { Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { String status = (String) resource.getPropertyValue(INSTANCE_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(INSTANCE_FEED_NAME_PROPERTY_ID); String id = (String) resource.getPropertyValue(INSTANCE_ID_PROPERTY_ID); if (desiredStatus.equals("SUSPENDED")) { service.suspendInstance(feedName, id); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeInstance(feedName, id); } } } } return new RequestStatusImpl(null); }
InstanceResourceProvider extends AbstractDRResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(INSTANCE_STATUS_PROPERTY_ID); if (desiredStatus != null) { Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { String status = (String) resource.getPropertyValue(INSTANCE_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(INSTANCE_FEED_NAME_PROPERTY_ID); String id = (String) resource.getPropertyValue(INSTANCE_ID_PROPERTY_ID); if (desiredStatus.equals("SUSPENDED")) { service.suspendInstance(feedName, id); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeInstance(feedName, id); } } } } return new RequestStatusImpl(null); } }
InstanceResourceProvider extends AbstractDRResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(INSTANCE_STATUS_PROPERTY_ID); if (desiredStatus != null) { Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { String status = (String) resource.getPropertyValue(INSTANCE_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(INSTANCE_FEED_NAME_PROPERTY_ID); String id = (String) resource.getPropertyValue(INSTANCE_ID_PROPERTY_ID); if (desiredStatus.equals("SUSPENDED")) { service.suspendInstance(feedName, id); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeInstance(feedName, id); } } } } return new RequestStatusImpl(null); } InstanceResourceProvider(IvoryService ivoryService,
                                  Set<String> propertyIds,
                                  Map<Resource.Type, String> keyPropertyIds); }
InstanceResourceProvider extends AbstractDRResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(INSTANCE_STATUS_PROPERTY_ID); if (desiredStatus != null) { Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { String status = (String) resource.getPropertyValue(INSTANCE_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(INSTANCE_FEED_NAME_PROPERTY_ID); String id = (String) resource.getPropertyValue(INSTANCE_ID_PROPERTY_ID); if (desiredStatus.equals("SUSPENDED")) { service.suspendInstance(feedName, id); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeInstance(feedName, id); } } } } return new RequestStatusImpl(null); } InstanceResourceProvider(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); }
InstanceResourceProvider extends AbstractDRResourceProvider { @Override public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { IvoryService service = getService(); Iterator<Map<String,Object>> iterator = request.getProperties().iterator(); if (iterator.hasNext()) { Map<String, Object> propertyMap = iterator.next(); String desiredStatus = (String) propertyMap.get(INSTANCE_STATUS_PROPERTY_ID); if (desiredStatus != null) { Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate); for (Resource resource : resources) { String status = (String) resource.getPropertyValue(INSTANCE_STATUS_PROPERTY_ID); String feedName = (String) resource.getPropertyValue(INSTANCE_FEED_NAME_PROPERTY_ID); String id = (String) resource.getPropertyValue(INSTANCE_ID_PROPERTY_ID); if (desiredStatus.equals("SUSPENDED")) { service.suspendInstance(feedName, id); } else if (status.equals("SUSPENDED") && desiredStatus.equals("RUNNING")) { service.resumeInstance(feedName, id); } } } } return new RequestStatusImpl(null); } InstanceResourceProvider(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);  }