Source:
public HandlerResult handle(ProcessState state, ProcessInstance process) { final Instance instance = (Instance)state.getResource(); Map<String, Object> labels = DataAccessor.fieldMap(instance, InstanceConstants.FIELD_LABELS); List<Volume> volumes = InstanceHelpers.extractVolumesFromMounts(instance, objectManager); for (final Volume v : volumes) { String driver = DataAccessor.fieldString(v, VolumeConstants.FIELD_VOLUME_DRIVER); if (StringUtils.isNotEmpty(driver) && !VolumeConstants.LOCAL_DRIVER.equals(driver)) { List<? extends StoragePool> pools = storagePoolDao.findStoragePoolByDriverName(v.getAccountId(), driver); if (pools.size() == 0) { continue; } StoragePool sp = pools.get(0); final String accessMode = sp.getVolumeAccessMode(); if (StringUtils.isNotEmpty(accessMode) && StringUtils.isEmpty(v.getAccessMode()) && !accessMode.equals(v.getAccessMode())) { lockManager.lock(new InstanceVolumeAccessModeLock(v.getId()), new LockCallbackNoReturn() { @Override public void doWithLockNoResult() { objectManager.setFields(v, VOLUME.ACCESS_MODE, accessMode); } }); } } Map<String, Object> driver_opts = DataAccessor.fieldMap(v, VolumeConstants.FIELD_VOLUME_DRIVER_OPTS); if (driver_opts.containsKey(VolumeConstants.EC2_AZ)) { String zone = driver_opts.get(VolumeConstants.EC2_AZ).toString(); String label = String.format("%s=%s", VolumeConstants.HOST_ZONE_LABEL_KEY, zone); if (labels.containsKey(HostAffinityConstraint.LABEL_HEADER_AFFINITY_HOST_LABEL)) { label = labels.get(HostAffinityConstraint.LABEL_HEADER_AFFINITY_HOST_LABEL).toString() + "," + label; } labels.put(HostAffinityConstraint.LABEL_HEADER_AFFINITY_HOST_LABEL, label); objectManager.setFields(instance, InstanceConstants.FIELD_LABELS, labels); } } return null; }

Target:
public HandlerResult handle(ProcessState state, ProcessInstance process) { final Instance instance = (Instance)state.getResource(); Map<String, Object> labels = DataAccessor.fieldMap(instance, InstanceConstants.FIELD_LABELS); List<Volume> volumes = InstanceHelpers.extractVolumesFromMounts(instance, objectManager); for (final Volume v : volumes) { String driver = DataAccessor.fieldString(v, VolumeConstants.FIELD_VOLUME_DRIVER); if (StringUtils.isNotEmpty(driver) && !VolumeConstants.LOCAL_DRIVER.equals(driver)) { List<? extends StoragePool> pools = storagePoolDao.findStoragePoolByDriverName(v.getAccountId(), driver); if (pools.size() == 0) { continue; } StoragePool sp = pools.get(0); final String accessMode = sp.getVolumeAccessMode(); if (StringUtils.isNotEmpty(accessMode) && StringUtils.isEmpty(v.getAccessMode()) && !accessMode.equals(v.getAccessMode())) { lockManager.lock(new InstanceVolumeAccessModeLock(v.getId()), new LockCallbackNoReturn() { @Override public void doWithLockNoResult() { objectManager.setFields(v, VOLUME.ACCESS_MODE, accessMode); } }); } } Map<String, Object> driver_opts = DataAccessor.fieldMap(v, VolumeConstants.FIELD_VOLUME_DRIVER_OPTS); if (driver_opts.containsKey(VolumeConstants.EC2_AZ)) { String zone = driver_opts.get(VolumeConstants.EC2_AZ).toString(); String label = String.format("%s=%s", VolumeConstants.HOST_ZONE_LABEL_KEY, zone); Object originalLabel = labels.get(HostAffinityConstraint.LABEL_HEADER_AFFINITY_HOST_LABEL); if (originalLabel != null && !StringUtils.isEmpty(originalLabel.toString())) { label = originalLabel.toString() + "," + label; } labels.put(HostAffinityConstraint.LABEL_HEADER_AFFINITY_HOST_LABEL, label); objectManager.setFields(instance, InstanceConstants.FIELD_LABELS, labels); } } return null; }