public List<String> getGuestL3Networks() { return CollectionUtils.transformToList(getVmNics(), new Function<String, VmNicInventory>() { @Override public String call(VmNicInventory arg) { return VirtualRouterNicMetaData.isGuestNic(arg) ? arg.getL3NetworkUuid() : null; } }); }
public VmNicInventory findNic(final String l3Uuid) { return CollectionUtils.find(vmNics, new Function<VmNicInventory, VmNicInventory>() { @Override public VmNicInventory call(VmNicInventory arg) { if (VmNicHelper.isL3AttachedToVmNic(arg, l3Uuid)) { return arg; } return null; } }); }
public void beforeDelete(final HostInventory hinv) { CollectionUtils.safeForEach(deleteHostExts, new ForEachFunction<HostDeleteExtensionPoint>() { @Override public void run(HostDeleteExtensionPoint extp) { extp.beforeDeleteHost(hinv); } }); }
@Override public void sort() { DebugUtils.Assert(candidates != null && !candidates.isEmpty(), "HostInventory cannot be none"); if (spec.getImage() == null || dbf.findByUuid(spec.getImage().getUuid(), ImageVO.class) == null) { prepareForNext(candidates); return; } List<String> bsUuids = Q.New(ImageBackupStorageRefVO.class).eq(ImageBackupStorageRefVO_.imageUuid, spec.getImage().getUuid()). select(ImageBackupStorageRefVO_.backupStorageUuid).listValues(); DebugUtils.Assert(bsUuids.size() > 0, String.format("imageUuid [%s] not in any BackupStorage", spec.getImage().getUuid())); //TODO: we suppose imageUuid is only in 1 bs, if it could be in 2 or more bss, then we should improve the bellow code BackupStorageInventory bs = BackupStorageInventory.valueOf(dbf.findByUuid(bsUuids.get(0), BackupStorageVO.class)); List<PriorityMap> priMap = new ArrayList<>(); for (BackupStoragePrimaryStorageExtensionPoint ext : pluginRgty.getExtensionList(BackupStoragePrimaryStorageExtensionPoint.class)) { priMap.addAll(formatPriority(ext.getPrimaryStoragePriorityMap(bs, spec.getImage()))); } priMap = priMap.stream() .sorted(Comparator.comparingInt(it -> it.priority)) .filter(distinctByKey(it -> it.PS)) .collect(Collectors.toList()); adjustCandidates(priMap); }
public List<String> getHypervisorTypesSupportingThisVolumeFormatInString() { return CollectionUtils.transformToList(getHypervisorTypesSupportingThisVolumeFormat(), new Function<String, HypervisorType>() { @Override public String call(HypervisorType arg) { return arg.toString(); } }); }
public void hostPingTask(final HypervisorType type, final HostInventory inv) { CollectionUtils.safeForEach(pingTaskExts, new ForEachFunction<HostPingTaskExtensionPoint>() { @Override public void run(HostPingTaskExtensionPoint ext) { if (ext.getHypervisorType().equals(type)) { ext.executeTaskAlongWithPingTask(inv); } } }); }
private boolean needAction() { if (self.getProviderType() == null) { return false; } LoadBalancerListenerVmNicRefVO activeNic = CollectionUtils.find(self.getListeners(), new Function<LoadBalancerListenerVmNicRefVO, LoadBalancerListenerVO>() { @Override public LoadBalancerListenerVmNicRefVO call(LoadBalancerListenerVO arg) { for (LoadBalancerListenerVmNicRefVO ref : arg.getVmNicRefs()) { if (ref.getStatus() == LoadBalancerVmNicStatus.Active || ref.getStatus() == LoadBalancerVmNicStatus.Pending) { return ref; } } return null; } }); if (activeNic == null) { return false; } return true; }
public static List<String> getVolumeFormatSupportedByHypervisorTypeInString(HypervisorType hvType) { return CollectionUtils.transformToList(getVolumeFormatSupportedByHypervisorType(hvType), new Function<String, VolumeFormat>() { @Override public String call(VolumeFormat arg) { return arg.toString(); } }); }
void beforeDelete(final ClusterInventory cinv) { CollectionUtils.safeForEach(deleteExts, new ForEachFunction<ClusterDeleteExtensionPoint>() { @Override public void run(ClusterDeleteExtensionPoint arg) { arg.beforeDeleteCluster(cinv); } }); }
private String buildUrl(String path) { String mgmtNicIp = CollectionUtils.find(self.getVmNics(), new Function<String, VmNicVO>() { @Override public String call(VmNicVO arg) { if (arg.getL3NetworkUuid().equals(getSelf().getManagementNetworkUuid())) { return arg.getIp(); } return null; } }); return buildAgentUrl(mgmtNicIp, path, getSelf().getAgentPort()); }
public Boolean getDeleteAll() { if (backupStorageUuids == null) { return true; } if (deleteAll == null) { List<String> bsUuids = CollectionUtils.transformToList(image.getBackupStorageRefs(), new Function<String, ImageBackupStorageRefInventory>() { @Override public String call(ImageBackupStorageRefInventory arg) { return arg.getBackupStorageUuid(); } }); deleteAll = backupStorageUuids.containsAll(bsUuids); } return deleteAll; }
void beforeUpdateOS(final ClusterVO cls) { CollectionUtils.safeForEach(updateOSExts, new ForEachFunction<ClusterUpdateOSExtensionPoint>() { @Override public void run(ClusterUpdateOSExtensionPoint arg) { arg.beforeUpdateClusterOS(cls); } }); }
@Override public SnapshotTO call(final VolumeSnapshotInventory s) { SnapshotTO to = new SnapshotTO(); to.path = s.getPrimaryStorageInstallPath(); to.snapshotUuid = s.getUuid(); if (s.getParentUuid() != null) { to.parentPath = CollectionUtils.find(children, new Function<String, VolumeSnapshotInventory>() { @Override public String call(VolumeSnapshotInventory arg) { return arg.getUuid().equals(s.getParentUuid()) ? arg.getPrimaryStorageInstallPath() : null; } }); } return to; } });
@Transactional(readOnly = true) private List<Tuple> getLbTuple(VmInstanceSpec servedVm) { String sql = "select l.uuid, l.loadBalancerUuid, ref.vmNicUuid from LoadBalancerListenerVmNicRefVO ref, LoadBalancerListenerVO l where ref.listenerUuid = l.uuid" + " and ref.vmNicUuid in (:nicUuids)"; TypedQuery<Tuple> q = dbf.getEntityManager().createQuery(sql, Tuple.class); q.setParameter("nicUuids", CollectionUtils.transformToList(servedVm.getDestNics(), new Function<String, VmNicInventory>() { @Override public String call(VmNicInventory arg) { return arg.getUuid(); } })); return q.getResultList(); }
public void failedToStartVm(final VmInstanceInventory inv, final ErrorCode reason) { CollectionUtils.safeForEach(startVmExtensions, new ForEachFunction<VmInstanceStartExtensionPoint>() { @Override public void run(VmInstanceStartExtensionPoint arg) { arg.failedToStartVm(inv, reason); } }); }
@Override public void allocate() { throwExceptionIfIAmTheFirstFlow(); if (spec.isListAllHosts()) { next(candidates); return; } final VmInstanceInventory vm = spec.getVmInstance(); HostVO vo = CollectionUtils.find(candidates, new Function<HostVO, HostVO>() { @Override public HostVO call(HostVO arg) { if (arg.getUuid().equals(vm.getLastHostUuid())) { return arg; } return null; } }); if (vo != null) { List<HostVO> vos = new ArrayList<>(); vos.add(vo); next(vos); } else { next(candidates); } } }
private void prepareStatistics() { List<Class> needReplyMsgs = new ArrayList<>(BeanUtils.reflections.getSubTypesOf(NeedReplyMessage.class)); needReplyMsgs = CollectionUtils.transformToList(needReplyMsgs, (Function<Class, Class>) arg -> !APIMessage.class.isAssignableFrom(arg) || APISyncCallMessage.class.isAssignableFrom(arg) ? arg : null); for (Class clz : needReplyMsgs) { MessageStatistic stat = new MessageStatistic(); stat.setMessageClassName(clz.getName()); statistics.put(stat.getMessageClassName(), stat); } }
public void beforeAttachVolume(final VmInstanceInventory vm, final VolumeInventory volume, Map data) { CollectionUtils.safeForEach(attachVolumeExtensions, new ForEachFunction<VmAttachVolumeExtensionPoint>() { @Override public void run(VmAttachVolumeExtensionPoint arg) { arg.beforeAttachVolume(vm, volume, data); } }); }
private NetworkServiceProviderInventory findProvider(final VmInstanceSpec spec) { L3NetworkInventory defaultL3 = CollectionUtils.find(VmNicSpec.getL3NetworkInventoryOfSpec(spec.getL3Networks()), new Function<L3NetworkInventory, L3NetworkInventory>() { @Override public L3NetworkInventory call(L3NetworkInventory arg) { return arg.getUuid().equals(spec.getVmInventory().getDefaultL3NetworkUuid()) ? arg : null; } }); for (NetworkServiceL3NetworkRefInventory ref : defaultL3.getNetworkServices()) { if (UserdataConstant.USERDATA_TYPE_STRING.equals(ref.getNetworkServiceType())) { return NetworkServiceProviderInventory.valueOf(dbf.findByUuid(ref.getNetworkServiceProviderUuid(), NetworkServiceProviderVO.class)); } } return null; }
public static List<String> getAllTypeNames() { List<BackupStorageType> exposedTypes = new ArrayList<BackupStorageType>(); for (BackupStorageType type : types.values()) { if (type.isExposed()) { exposedTypes.add(type); } } Collections.sort(exposedTypes, new Comparator<BackupStorageType>() { @Override public int compare(BackupStorageType o1, BackupStorageType o2) { return o1.getOrder() - o2.getOrder(); } }); return CollectionUtils.transformToList(exposedTypes, new Function<String, BackupStorageType>() { @Override public String call(BackupStorageType arg) { return arg.toString(); } }); }