@Transactional(readOnly = true) protected List<FactoryCluster> getAllFactoriesForAttachedClusters() { String sql = "select cluster" + " from ClusterVO cluster, PrimaryStorageClusterRefVO ref" + " where ref.clusterUuid = cluster.uuid" + " and ref.primaryStorageUuid = :uuid"; TypedQuery<ClusterVO> q = dbf.getEntityManager().createQuery(sql, ClusterVO.class); q.setParameter("uuid", self.getUuid()); List<ClusterVO> clusters = q.getResultList(); if (clusters.isEmpty()) { return new ArrayList<>(); } Map<String, FactoryCluster> m = new HashMap<>(); for (ClusterVO c : clusters) { FactoryCluster fc = m.get(c.getHypervisorType()); if (fc == null) { fc = new FactoryCluster(); fc.factory = getHypervisorBackendFactory(c.getHypervisorType()); fc.clusters = new ArrayList<>(); m.put(c.getHypervisorType(), fc); } fc.clusters.add(ClusterInventory.valueOf(c)); } List<FactoryCluster> fcs = new ArrayList<>(); fcs.addAll(m.values()); return fcs; }
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()); }
public static ClusterInventory valueOf(ClusterVO vo) { ClusterInventory inv = new ClusterInventory(); inv.setName(vo.getName()); inv.setDescription(vo.getDescription()); inv.setUuid(vo.getUuid()); inv.setState(vo.getState().toString()); inv.setCreateDate(vo.getCreateDate()); inv.setHypervisorType(vo.getHypervisorType()); inv.setZoneUuid(vo.getZoneUuid()); inv.setType(vo.getType()); inv.setLastOpDate(vo.getLastOpDate()); return inv; }
hvo.setName(msg.getName()); hvo.setDescription(msg.getDescription()); hvo.setHypervisorType(cluster.getHypervisorType()); hvo.setManagementIp(msg.getManagementIp()); hvo.setStatus(HostStatus.Connecting); hvo.setState(HostState.Enabled); final HypervisorFactory factory = getHypervisorFactory(HypervisorType.valueOf(cluster.getHypervisorType())); final HostVO vo = factory.createHost(hvo, msg); final AddHostMsg amsg = getAddHostMsg(msg);