}
@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) {
// get all the instances that pass the predicate check
Set<Resource> resources = getResources(PropertyHelper.getReadRequest(), predicate);
// update all the matching instances with the property values from the request
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);