List<String> huuids = getHostUuidsFromCandidates(); if (!VmOperation.NewCreate.toString().equals(spec.getVmOperation())) { String sqlappend = ""; if (spec.getRequiredPrimaryStorageUuid() != null) {
@Override public List<HostVO> filterHostCandidates(List<HostVO> candidates, HostAllocatorSpec spec) { if (VmOperation.NewCreate.toString().equals(spec.getVmOperation())) { List<String> huuids = getNeedCheckHostLocalStorageList(candidates, spec); if(huuids.isEmpty()){ } else if (VmOperation.Start.toString().equals(spec.getVmOperation())) {
amsg.setDiskSize(diskSize); amsg.setL3NetworkUuids(msg.getL3NetworkUuids()); amsg.setVmOperation(VmOperation.NewCreate.toString()); amsg.setDryRun(true); amsg.setListAllHosts(true);
@Override public void allocate() { if (!VmOperation.NewCreate.toString().equals(spec.getVmOperation())) { next(candidates); return;
msg.setCpuCapacity(spec.getVmInventory().getCpuNum()); msg.setMemoryCapacity(spec.getVmInventory().getMemorySize()); msg.setVmOperation(spec.getCurrentVmOperation().toString()); if (spec.getImageSpec() != null) { msg.setImage(spec.getImageSpec().getInventory());
throwExceptionIfIAmTheFirstFlow(); if (VmOperation.NewCreate.toString().equals(spec.getVmOperation())) { next(candidates); return;
throwExceptionIfIAmTheFirstFlow(); if (!VmOperation.Migrate.toString().equals(spec.getVmOperation())) { throw new CloudRuntimeException("AllocatePrimaryStorageForVmMigrationFlow is only used for migrating vm");
msg.setVmOperation(spec.getCurrentVmOperation().toString());
msg.setServiceId(bus.makeLocalServiceId(HostAllocatorConstant.SERVICE_ID)); msg.setAllocatorStrategy(HostAllocatorConstant.MIGRATE_VM_ALLOCATOR_TYPE); msg.setVmOperation(spec.getCurrentVmOperation().toString()); msg.setRequiredPrimaryStorageUuid(spec.getVmInventory().getRootVolume().getPrimaryStorageUuid()); msg.setL3NetworkUuids(CollectionUtils.transformToList(
amsg.setServiceId(bus.makeLocalServiceId(HostAllocatorConstant.SERVICE_ID)); amsg.setAllocatorStrategy(HostAllocatorConstant.MIGRATE_VM_ALLOCATOR_TYPE); amsg.setVmOperation(VmOperation.Migrate.toString()); amsg.setL3NetworkUuids(VmNicHelper.getL3Uuids(VmNicInventory.valueOf(self.getVmNics()))); amsg.setDryRun(true);
if (!VmInstanceConstant.VmOperation.Migrate.toString().equals(spec.getVmOperation())) { return candidates;
msg.setVmOperation(spec.getCurrentVmOperation().toString()); msg.setAllocatorStrategy(HostAllocatorConstant.DESIGNATED_HOST_ALLOCATOR_STRATEGY_TYPE); msg.setL3NetworkUuids(CollectionUtils.transformToList(VmNicSpec.getL3NetworkInventoryOfSpec(spec.getL3Networks()), new Function<String, L3NetworkInventory>() {
private void getStartingCandidateHosts(final NeedReplyMessage msg, final ReturnValueCompletion completion) { refreshVO(); ErrorCode err = validateOperationByState(msg, self.getState(), SysErrors.OPERATION_ERROR); if (err != null) { throw new OperationFailureException(err); } final DesignatedAllocateHostMsg amsg = new DesignatedAllocateHostMsg(); amsg.setCpuCapacity(self.getCpuNum()); amsg.setMemoryCapacity(self.getMemorySize()); amsg.setVmInstance(VmInstanceInventory.valueOf(self)); amsg.setServiceId(bus.makeLocalServiceId(HostAllocatorConstant.SERVICE_ID)); amsg.setAllocatorStrategy(self.getAllocatorStrategy()); amsg.setVmOperation(VmOperation.Start.toString()); if (self.getImageUuid() != null && dbf.findByUuid(self.getImageUuid(), ImageVO.class) != null) { amsg.setImage(ImageInventory.valueOf(dbf.findByUuid(self.getImageUuid(), ImageVO.class))); } amsg.setL3NetworkUuids(VmNicHelper.getL3Uuids(VmNicInventory.valueOf(self.getVmNics()))); amsg.setDryRun(true); amsg.setListAllHosts(true); bus.send(amsg, new CloudBusCallBack(completion) { @Override public void run(MessageReply re) { if (!re.isSuccess()) { completion.fail(re.getError()); } else { completion.success(re); } } }); }
@Override public void allocate() { if (amITheFirstFlow()) { throw new CloudRuntimeException("HostPrimaryStorageAllocatorFlow cannot be the first flow in the chain"); } if (spec.getImage() == null) { next(candidates); return; } candidates = allocateFromCandidates(); if (candidates.isEmpty()) { String err = spec.getVmOperation().equals(VmOperation.NewCreate.toString()) ? String.format("cannot find available primary storage[state: %s, status: %s, available capacity %s bytes]." + " Check the state/status of primary storage and make sure they have been attached to clusters", PrimaryStorageState.Enabled, PrimaryStorageStatus.Connected, spec.getDiskSize()) : String.format("cannot find available primary storage[state: %s or %s, status: %s]." + " Check the state/status of primary storage and make sure they have been attached to clusters", PrimaryStorageState.Enabled, PrimaryStorageState.Disabled, PrimaryStorageStatus.Connected); fail(err); } else { next(candidates); } } }
@Override public List<HostVO> allocateHost(List<TagInventory> tags, List<HostVO> candidates, HostAllocatorSpec spec) { if (!VmOperation.NewCreate.toString().equals(spec.getVmOperation())) { return candidates; } for (TagInventory tag : tags) { String uuid = PrimaryStorageSystemTags.PRIMARY_STORAGE_ALLOCATOR_UUID_TAG.getTokenByTag(tag.getTag(), "uuid"); if (uuid != null) { return uuidTagAllocateHost(candidates, uuid); } String requiredUserTag = PrimaryStorageSystemTags.PRIMARY_STORAGE_ALLOCATOR_USERTAG_TAG_MANDATORY.getTokenByTag(tag.getTag(), "tag"); if (requiredUserTag != null) { return userTagAllocateHost(candidates, requiredUserTag, true); } String userTag = PrimaryStorageSystemTags.PRIMARY_STORAGE_ALLOCATOR_USERTAG_TAG.getTokenByTag(tag.getTag(), "tag"); if (userTag != null) { return userTagAllocateHost(candidates, userTag, false); } } return candidates; }
@Override public String getHostAllocatorStrategyName(HostAllocatorSpec spec) { if (!VmOperation.Migrate.toString().equals(spec.getVmOperation())) { return null; } SimpleQuery<PrimaryStorageVO> q = dbf.createQuery(PrimaryStorageVO.class); q.select(PrimaryStorageVO_.type); q.add(PrimaryStorageVO_.uuid, Op.EQ, spec.getVmInstance().getRootVolume().getPrimaryStorageUuid()); String type = q.findValue(); if (!LocalStorageConstants.LOCAL_STORAGE_TYPE.equals(type)) { return null; } return LocalStorageConstants.LOCAL_STORAGE_MIGRATE_VM_ALLOCATOR_TYPE; } }