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()); } }
@Override public PrimaryStorageInventory createPrimaryStorage(PrimaryStorageVO vo, APIAddPrimaryStorageMsg msg) { vo.setMountPath(vo.getUrl()); vo.setType(SMPConstants.SMP_TYPE); vo = dbf.persistAndRefresh(vo); return PrimaryStorageInventory.valueOf(vo); }
@Transactional(readOnly = true) private void checkIfBackupStorageAttachedToMyZone(String bsUuid) { String sql = "select bs.uuid" + " from BackupStorageVO bs, BackupStorageZoneRefVO ref" + " where bs.uuid = ref.backupStorageUuid" + " and ref.zoneUuid = :zoneUuid" + " and bs.uuid = :bsUuid"; TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class); q.setParameter("zoneUuid", self.getZoneUuid()); q.setParameter("bsUuid", bsUuid); if (q.getResultList().isEmpty()) { throw new OperationFailureException(operr("backup storage[uuid:%s] is not attached to zone[uuid:%s] the primary storage[uuid:%s] belongs to", bsUuid, self.getZoneUuid(), self.getUuid())); } }
@Override public String call(PrimaryStorageVO arg) { return arg.getUuid(); } });
@Override public KVMHostAsyncHttpCallMsg call(String arg) { GetPhysicalCapacityCmd cmd = new GetPhysicalCapacityCmd(); cmd.uuid = self.getUuid(); cmd.setHostUuid(arg); cmd.storagePath = self.getUrl(); KVMHostAsyncHttpCallMsg msg = new KVMHostAsyncHttpCallMsg(); msg.setHostUuid(arg); msg.setCommand(cmd); msg.setPath(GET_PHYSICAL_CAPACITY_PATH); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, arg); return msg; } });
protected boolean changeStatus(PrimaryStorageStatus status) { if (status == self.getStatus()) { return false; } PrimaryStorageStatus oldStatus = self.getStatus(); self.setStatus(status); self = dbf.updateAndRefresh(self); PrimaryStorageStatusChangedData d = new PrimaryStorageStatusChangedData(); d.setInventory(PrimaryStorageInventory.valueOf(self)); d.setPrimaryStorageUuid(self.getUuid()); d.setOldStatus(oldStatus.toString()); d.setNewStatus(status.toString()); evtf.fire(PrimaryStorageCanonicalEvent.PRIMARY_STORAGE_STATUS_CHANGED_PATH, d); logger.debug(String.format("the primary storage[uuid:%s, name:%s] changed status from %s to %s", self.getUuid(), self.getName(), oldStatus, status)); return true; }
@Override public void run(MessageReply reply) { if (!reply.isSuccess() && !reply.getError().isError(PrimaryStorageErrors.DISCONNECTED)) { evt.setError(reply.getError()); logger.warn(String.format("failed to connect primary storage[uuid:%s, name:%s, url:%s]", finalVo.getUuid(), finalVo.getName(), finalVo.getUrl())); dbf.remove(finalVo); } else { PrimaryStorageInventory pinv = factory.getInventory(finalVo.getUuid()); logger.debug(String.format("successfully add primary storage[uuid:%s, name:%s, url: %s]", finalVo.getUuid(), finalVo.getName(), finalVo.getUrl())); evt.setInventory(pinv); } bus.publish(evt); } });
if (self.getStatus() == PrimaryStorageStatus.Connected) { return true; if (!self.getAttachedClusterRefs().stream() .anyMatch(ref -> ref.getClusterUuid().equals(d.getInventory().getClusterUuid()))) { return false; N.New(PrimaryStorageVO.class, self.getUuid()).warn_("unable to reconnect the primary storage[uuid:%s, name:%s], %s", self.getUuid(), self.getName(), future.getErrorCode()); } else { changeStatus(PrimaryStorageStatus.Connected);
while (it.hasNext()) { PrimaryStorageVO psvo = it.next(); if (!spec.getPossiblePrimaryStorageTypes().contains(psvo.getType())) { logger.debug(String.format("the primary storage[name:%s, uuid:%s, type:%s] is not in possible primary storage types[%s]," + " remove it", psvo.getName(), psvo.getUuid(), psvo.getType(), spec.getPossiblePrimaryStorageTypes())); it.remove(); while (it.hasNext()) { PrimaryStorageVO psvo = it.next(); if (spec.getExcludePrimaryStorageTypes().contains(psvo.getType())) { logger.debug(String.format("the primary storage[name:%s, uuid:%s, type:%s] is in exclude primary storage types[%s]," + " remove it", psvo.getName(), psvo.getUuid(), psvo.getType(), spec.getExcludePrimaryStorageTypes())); it.remove(); } else { for (PrimaryStorageVO vo : vos) { if (ratioMgr.calculatePrimaryStorageAvailableCapacityByRatio(vo.getUuid(), vo.getCapacity().getAvailableCapacity()) > spec.getSize()) { res.add(vo);
PrimaryStorageType psType = PrimaryStorageType.valueOf(ps.getType()); List<String> bsUuids = psType.findBackupStorage(ps.getUuid()); bq.setParameter("types", hostAllocatorMgr.getBackupStorageTypesByPrimaryStorageTypeFromMetrics(ps.getType())); lst.addAll(bq.getResultList()); } else if (!bsUuids.isEmpty()) { } else { logger.warn(String.format("the primary storage[uuid:%s, type:%s] needs a bound backup storage," + " but seems it's not added", ps.getUuid(), ps.getType()));
while (it.hasNext()) { PrimaryStorageVO psvo = it.next(); if (!spec.getPossiblePrimaryStorageTypes().contains(psvo.getType())) { logger.debug(String.format("the primary storage[name:%s, uuid:%s, type:%s] is not in possible primary storage types[%s]," + " remove it", psvo.getName(), psvo.getUuid(), psvo.getType(), spec.getPossiblePrimaryStorageTypes())); it.remove(); while (it.hasNext()) { PrimaryStorageVO psvo = it.next(); if (spec.getExcludePrimaryStorageTypes().contains(psvo.getType())) { logger.debug(String.format("the primary storage[name:%s, uuid:%s, type:%s] is in exclude primary storage types[%s]," + " remove it", psvo.getName(), psvo.getUuid(), psvo.getType(), spec.getExcludePrimaryStorageTypes())); it.remove();
@Override protected void connectHook(ConnectParam param, final Completion completion) { List<String> clusterUuids = self.getAttachedClusterRefs().stream() .map(PrimaryStorageClusterRefVO::getClusterUuid) .collect(Collectors.toList()); "or no hosts in the attached clusters are connected", self.getUuid(), self.getName() )); return;
public String makeTemplateFromVolumeInWorkspacePath(String imageUuid) { return PathUtil.join(self.getUrl(), "templateWorkspace", String.format("image-%s", imageUuid), String.format("%s.qcow2", imageUuid)); }
@Override public PrimaryStorageInventory createPrimaryStorage(PrimaryStorageVO vo, APIAddPrimaryStorageMsg msg) { String mountPathBase = NfsPrimaryStorageGlobalConfig.MOUNT_BASE.value(String.class); if (mountPathBase == null) { mountPathBase = NfsPrimaryStorageConstant.DEFAULT_NFS_MOUNT_PATH_ON_HOST; } String mountPath = PathUtil.join(mountPathBase, "prim-" + vo.getUuid()); vo.setMountPath(mountPath); vo = dbf.persistAndRefresh(vo); SystemTagCreator creator = PrimaryStorageSystemTags.CAPABILITY_HYPERVISOR_SNAPSHOT.newSystemTagCreator(vo.getUuid()); creator.setTagByTokens(map( e(PrimaryStorageSystemTags.CAPABILITY_HYPERVISOR_SNAPSHOT_TOKEN, KVMConstant.KVM_HYPERVISOR_TYPE) )); creator.create(); return PrimaryStorageInventory.valueOf(vo); }
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()); }
protected void handle(APIChangePrimaryStorageStateMsg msg) { APIChangePrimaryStorageStateEvent evt = new APIChangePrimaryStorageStateEvent(msg.getId()); PrimaryStorageState currState = self.getState(); PrimaryStorageStateEvent event = PrimaryStorageStateEvent.valueOf(msg.getStateEvent()); PrimaryStorageState nextState = AbstractPrimaryStorage.getNextState(currState, event); List<String> vmUuids = SQL.New("select vm.uuid from VmInstanceVO vm, VolumeVO vol" + " where vol.primaryStorageUuid =:uuid and vol.vmInstanceUuid = vm.uuid group by vm.uuid", String.class) .param("uuid", self.getUuid()).list(); if ( vmUuids.size() != 0 ) { stopAllVms(vmUuids); self.setState(nextState); self = dbf.updateAndRefresh(self); extpEmitter.afterChange(self, event, currState); data.setPrimaryStorageUuid(self.getUuid()); data.setOldState(currState); data.setNewState(nextState);
String psUuid = getSelfInventory().getRootVolume().getPrimaryStorageUuid(); PrimaryStorageVO ps = dbf.getEntityManager().find(PrimaryStorageVO.class, psUuid); PrimaryStorageType psType = PrimaryStorageType.valueOf(ps.getType()); List<String> bsUuids = psType.findBackupStorage(psUuid); q.setParameter("bsTypes", hostAllocatorMgr.getBackupStorageTypesByPrimaryStorageTypeFromMetrics(ps.getType())); return ImageInventory.valueOf(q.getResultList()); } else if (!bsUuids.isEmpty()) {