package com.onaro.sanscreen.client.view.reservations.functions; import com.onaro.client.leekui.runtime.OnaroAdapterUtils; import com.onaro.client.swing.table.functional.IFunction; import com.onaro.sanscreen.client.view.common.functions.AbstractContextAwareBulkFunction; import com.onaro.sanscreen.client.view.refresh.RefreshUtils; import com.onaro.sanscreen.server.interfaces.ServerInterfacesUtils; import com.onaro.sanscreen.server.interfaces.data.Context; import com.onaro.sanscreen.server.interfaces.data.ServerInterfaceException; import com.onaro.sanscreen.server.interfaces.data.inventory.Volume; import com.onaro.sanscreen.server.interfaces.data.reservation.ReservationEligibility; import com.onaro.sanscreen.server.interfaces.remote.ReservationRemote; import org.eclipse.core.runtime.IAdaptable; import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.Map; import java.util.Set; /** * This is a bulk function to populate the preference column for volume micro view. */ public class GetVolumePreferenceBulkFunction extends AbstractContextAwareBulkFunction { private Long selectedTierId; private Set selectedHosts; /** * To determine the preference of a volume we need the selected hosts in the reservation and the * Tier that is selected as part of the Requirement. * @param selectedHosts * @param selectedTierId */ public GetVolumePreferenceBulkFunction(Set selectedHosts, Long selectedTierId) { this.selectedHosts = selectedHosts; this.selectedTierId = selectedTierId; } public interface IGetVolumePreferenceBulkFunction extends IFunction { } @Override protected void evaluate(Collection inputs, Context context, Map outputMap) throws InterruptedException, InvocationTargetException { Map volumeEligibility; try { //As all the ports belong to the same storage because of the single selection for storage, // just picking up the first port to get the storage id. I firstObject = inputs.iterator().next(); Long storageId = -1L; if (firstObject != null) { Volume volume = OnaroAdapterUtils.getAdapter(firstObject, Volume.class); storageId = volume.getStorageId(); } ReservationRemote remote = ServerInterfacesUtils.getReservationRemote(); volumeEligibility = remote.getVolumeEligibilityForPathReservation(selectedHosts, storageId, selectedTierId); } catch (ServerInterfaceException e) { throw new InvocationTargetException(e); } OnaroAdapterUtils.getAdaptableToValueMap(inputs, Long.class, volumeEligibility, outputMap); } @Override protected RefreshUtils.MethodDescriptor getMethodCalled() { return new RefreshUtils.MethodDescriptor(ReservationRemote.class, "getVolumeEligibilityForPathReservation", Set.class, Long.class, Long.class); //$NON-NLS-1$ } }