@Transactional private List<PrimaryStorageVO> getPrimaryStorageHostShouldMount(HostInventory host) { String sql = "select p from PrimaryStorageVO p where p.type = :type and p.uuid in (select ref.primaryStorageUuid from PrimaryStorageClusterRefVO ref where ref.clusterUuid = :clusterUuid)"; TypedQuery<PrimaryStorageVO> query = dbf.getEntityManager().createQuery(sql, PrimaryStorageVO.class); query.setParameter("type", NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE); query.setParameter("clusterUuid", host.getClusterUuid()); return query.getResultList(); }
@Override public void afterHostConnected(HostInventory host) { recalculatePrimaryStorageCapacity(host.getClusterUuid()); }
@Override @Transactional(readOnly = true) public Map<String, HostMaintenancePolicy> getHostMaintenanceVmOperationPolicy(HostInventory host) { Map<String, HostMaintenancePolicy> result = new HashMap<>(); String sql = "select vm.uuid" + " from PrimaryStorageVO ps, PrimaryStorageClusterRefVO ref, VmInstanceVO vm, VolumeVO vol" + " where ps.uuid = ref.primaryStorageUuid" + " and ps.type = :type" + " and ref.clusterUuid = :cuuid" + " and vol.primaryStorageUuid = ps.uuid" + " and vm.rootVolumeUuid = vol.uuid"; TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class); q.setParameter("type", LocalStorageConstants.LOCAL_STORAGE_TYPE); q.setParameter("cuuid", host.getClusterUuid()); List<String> vmUuids = q.getResultList(); vmUuids.forEach(it -> result.put(it, HostMaintenancePolicy.StopVm)); return result; }
private ErrorCode checkIfSpecifyPrimaryStorage(VmInstanceSpec spec){ if(spec.getRequiredPrimaryStorageUuidForRootVolume() == null){ ErrorCode errorCode = operr("The cluster[uuid=%s] mounts multiple primary storage[LocalStorage, other non-LocalStorage primary storage], You must specify the primary storage where the root disk is located", spec.getDestHost().getClusterUuid()); return errorCode; } if(spec.getDataDiskOfferings() != null && !spec.getDataDiskOfferings().isEmpty() && spec.getRequiredPrimaryStorageUuidForDataVolume() == null){ ErrorCode errorCode = operr("The cluster[uuid=%s] mounts multiple primary storage[LocalStorage, other non-LocalStorage primary storage], You must specify the primary storage where the data disk is located", spec.getDestHost().getClusterUuid()); return errorCode; } return null; }
@Override public void connectionReestablished(HostInventory inv) throws HostException { //TODO: make connect async List<L2NetworkInventory> l2s = getL2Networks(inv.getClusterUuid()); if (l2s.isEmpty()) { return; } FutureCompletion completion = new FutureCompletion(null); prepareNetwork(l2s.iterator(), inv.getUuid(), completion); completion.await(TimeUnit.SECONDS.toMillis(600)); if (!completion.isSuccess()) { throw new OperationFailureException(completion.getErrorCode()); } }
@Override public void connectionReestablished(HostInventory inv) throws HostException { //TODO: make connect async List<L2NetworkInventory> l2s = getL2Networks(inv.getClusterUuid()); if (l2s.isEmpty()) { return; } FutureCompletion completion = new FutureCompletion(null); prepareNetwork(l2s.iterator(), inv.getUuid(), completion); completion.await(TimeUnit.SECONDS.toMillis(600)); if (!completion.isSuccess()) { throw new OperationFailureException(completion.getErrorCode()); } }
@Override public void failedToAddHost(HostInventory host, AddHostMessage amsg) { final List<String> priUuids = findLocalStorageUuidByHostUuid(host.getClusterUuid()); if (priUuids == null || priUuids.isEmpty()) { return; } for (String priUUid : priUuids) { RecalculatePrimaryStorageCapacityMsg msg = new RecalculatePrimaryStorageCapacityMsg(); msg.setPrimaryStorageUuid(priUUid); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, priUUid); bus.send(msg, new CloudBusCallBack(null) { @Override public void run(MessageReply reply) { if (!reply.isSuccess()) { logger.warn(String.format("failed to sync primary storage[uuid:%s] capacity, %s", priUuids, reply.getError())); } } }); } } }
@Override public void afterDeleteHost(HostInventory inventory) { String clusterUuid = inventory.getClusterUuid(); List<String> psUuids = getNfsPrimaryStorageInCluster(clusterUuid); if(psUuids == null || psUuids.isEmpty()) { return; } if (Q.New(HostVO.class).eq(HostVO_.clusterUuid, clusterUuid).notEq(HostVO_.uuid, inventory.getUuid()).isExists()) { return; } for(String psUuid : psUuids) { releasePrimaryStorageCapacity(psUuid); } }
@Override public void afterDeleteHost(HostInventory inventory) { String clusterUuid = inventory.getClusterUuid(); if (Q.New(HostVO.class).eq(HostVO_.clusterUuid, clusterUuid).notEq(HostVO_.uuid, inventory.getUuid()).isExists()) { return; } final List<String> psUuids = getSMPPrimaryStorageInCluster(clusterUuid); if(psUuids == null || psUuids.isEmpty()) { return; } for (String psUuid : psUuids) { releasePrimaryStorageCapacity(psUuid); } }
@Override public void connectionReestablished(HostInventory inv) throws HostException { if (!KVMConstant.KVM_HYPERVISOR_TYPE.equals(inv.getHypervisorType())) { return; } FutureCompletion completion = new FutureCompletion(null); createSecret(inv.getUuid(), inv.getClusterUuid(), new Completion(completion) { @Override public void success() { completion.success(); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); completion.await(); if (!completion.isSuccess()) { throw new OperationFailureException(completion.getErrorCode()); } }
if (VmAllocatePrimaryStorageFlow.class.getName().equals(nextFlowName)) { if (spec.getCurrentVmOperation() == VmOperation.NewCreate) { List<String> localStorageUuids = getLocalStorageInCluster(spec.getDestHost().getClusterUuid()); if (localStorageUuids != null && !localStorageUuids.isEmpty()) { boolean isOnlyLocalStorage = SQL.New("select pri.uuid" + " and ref.clusterUuid = :cuuid" + " and pri.type != :ptype", String.class) .param("cuuid", spec.getDestHost().getClusterUuid()) .param("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE) .list().isEmpty();
@Override public void handle(final Map data) { VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); HostInventory host = spec.getDestHost(); self = changeVmStateInDb(VmInstanceStateEvent.running, ()-> { self.setZoneUuid(host.getZoneUuid()); self.setClusterUuid(host.getClusterUuid()); self.setLastHostUuid(lastHostUuid); self.setHostUuid(host.getUuid()); }); VmInstanceInventory vm = VmInstanceInventory.valueOf(self); extEmitter.afterMigrateVm(vm, vm.getLastHostUuid()); completion.success(); } }).error(new FlowErrorHandler(completion) {
.anyMatch(ref -> ref.getClusterUuid().equals(d.getInventory().getClusterUuid()))) { return false;
@Override public void run(FlowTrigger trigger, Map data) { VmInstanceSpec spec = (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString()); changeVmStateInDb(struct.getStrategy() == VmCreationStrategy.InstantStart ? VmInstanceStateEvent.running : VmInstanceStateEvent.paused, ()-> { self.setLastHostUuid(spec.getDestHost().getUuid()); self.setHostUuid(spec.getDestHost().getUuid()); self.setClusterUuid(spec.getDestHost().getClusterUuid()); self.setZoneUuid(spec.getDestHost().getZoneUuid()); self.setHypervisorType(spec.getDestHost().getHypervisorType()); self.setRootVolumeUuid(spec.getDestRootVolume().getUuid()); }); logger.debug(String.format("vm[uuid:%s] is started ..", self.getUuid())); VmInstanceInventory inv = VmInstanceInventory.valueOf(self); extEmitter.afterStartNewCreatedVm(inv); trigger.next(); } });
.eq(PrimaryStorageClusterRefVO_.clusterUuid, host.getClusterUuid()) .eq(PrimaryStorageClusterRefVO_.primaryStorageUuid, dstPsInv.getUuid()) .isExists();
amsg.setAllocationStrategy(dinv.getAllocatorStrategy()); List<String> localStorageUuids = getLocalStorageInCluster(spec.getDestHost().getClusterUuid()); for (String lsuuid : localStorageUuids) { amsg.addExcludePrimaryStorageUuid(lsuuid);
oldHostUuid = dbf.isExist(oldHostUuid, HostVO.class) ? oldHostUuid : null; SQL.New(VmInstanceVO.class).eq(VmInstanceVO_.uuid, spec.getVmInventory().getUuid()) .set(VmInstanceVO_.clusterUuid, spec.getDestHost().getClusterUuid()) .set(VmInstanceVO_.lastHostUuid, oldHostUuid) .set(VmInstanceVO_.hostUuid, spec.getDestHost().getUuid())