@Transactional(readOnly = true) private NfsPrimaryStorageBackend getUsableBackend() { List<String> cuuids = CollectionUtils.transformToList(self.getAttachedClusterRefs(), new Function<String, PrimaryStorageClusterRefVO>() { @Override public String call(PrimaryStorageClusterRefVO arg) { return arg.getClusterUuid(); } }); if (cuuids.isEmpty()) { return null; } String sql = "select cluster.uuid from ClusterVO cluster, HostVO host where cluster.uuid = host.clusterUuid and host.status = :hostStatus and cluster.uuid in (:cuuids)"; TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class); q.setParameter("hostStatus", HostStatus.Connected); q.setParameter("cuuids", cuuids); cuuids = q.getResultList(); if (cuuids.isEmpty()) { return null; } return getBackendByClusterUuid(cuuids.get(0)); }
private void handle(PrimaryStorageRemoveCachedImageMsg msg) { if (self.getAttachedClusterRefs().isEmpty()) { PrimaryStorageRemoveCachedImageReply reply = new PrimaryStorageRemoveCachedImageReply(); reply.setError(operr("primary storage[uuid:%s] doesn't attach to any cluster", self.getUuid())); bus.reply(msg, reply); return; } PrimaryStorageClusterRefVO ref = self.getAttachedClusterRefs().iterator().next(); ClusterVO cluster = dbf.findByUuid(ref.getClusterUuid(), ClusterVO.class); getBackend(HypervisorType.valueOf(cluster.getHypervisorType())).deleteImageCache(msg.getInventory()); }
@Override public void deleteHook() { List<String> cuuids = CollectionUtils.transformToList(self.getAttachedClusterRefs(), new Function<String, PrimaryStorageClusterRefVO>() { @Override public String call(PrimaryStorageClusterRefVO arg) { return arg.getClusterUuid(); } }); for (String cuuid : cuuids) { NfsPrimaryStorageBackend backend = getBackendByClusterUuid(cuuid); try { backend.detachFromCluster(getSelfInventory(), cuuid); } catch (NfsPrimaryStorageException e) { logger.warn(String.format("failed to detach the nfs primary storage[uuid: %s] from the cluster[uuid: %s]", self.getUuid(), cuuid)); } } }
@Override protected void connectHook(ConnectParam param, final Completion completion) { List<String> clusterUuids = self.getAttachedClusterRefs().stream() .map(PrimaryStorageClusterRefVO::getClusterUuid) .collect(Collectors.toList());
if (!self.getAttachedClusterRefs().stream() .anyMatch(ref -> ref.getClusterUuid().equals(d.getInventory().getClusterUuid()))) { return false;
protected PrimaryStorageInventory(PrimaryStorageVO vo) { setZoneUuid(vo.getZoneUuid()); setCreateDate(vo.getCreateDate()); setDescription(vo.getDescription()); setLastOpDate(vo.getLastOpDate()); setName(vo.getName()); setState(vo.getState().toString()); setType(vo.getType()); setUrl(vo.getUrl()); setUuid(vo.getUuid()); setMountPath(vo.getMountPath()); setStatus(vo.getStatus().toString()); attachedClusterUuids = new ArrayList<String>(vo.getAttachedClusterRefs().size()); for (PrimaryStorageClusterRefVO ref : vo.getAttachedClusterRefs()) { attachedClusterUuids.add(ref.getClusterUuid()); } if (vo.getCapacity() != null) { setTotalCapacity(vo.getCapacity().getTotalCapacity()); setAvailableCapacity(vo.getCapacity().getAvailableCapacity()); setTotalPhysicalCapacity(vo.getCapacity().getTotalPhysicalCapacity()); setAvailablePhysicalCapacity(vo.getCapacity().getAvailablePhysicalCapacity()); setSystemUsedCapacity(vo.getCapacity().getSystemUsedCapacity()); } }