@Override void handle(InstantiateVolumeOnPrimaryStorageMsg msg, ReturnValueCompletion<InstantiateVolumeOnPrimaryStorageReply> completion) { if (msg instanceof InstantiateRootVolumeFromTemplateOnPrimaryStorageMsg) { createRootVolume((InstantiateRootVolumeFromTemplateOnPrimaryStorageMsg) msg, completion); } else { createEmptyVolume(msg.getVolume(), msg.getDestHost().getUuid(), completion); } }
@Override protected void handle(final InstantiateVolumeOnPrimaryStorageMsg msg, final ReturnValueCompletion<InstantiateVolumeOnPrimaryStorageReply> completion) { if (msg instanceof InstantiateRootVolumeFromTemplateOnPrimaryStorageMsg) { createRootVolume((InstantiateRootVolumeFromTemplateOnPrimaryStorageMsg) msg, completion); } else { createEmptyVolume(msg.getVolume(), msg.getDestHost().getUuid(), new ReturnValueCompletion<String>(completion) { @Override public void success(String returnValue) { InstantiateVolumeOnPrimaryStorageReply r = new InstantiateVolumeOnPrimaryStorageReply(); VolumeInventory vol = msg.getVolume(); vol.setInstallPath(returnValue); vol.setFormat(VolumeConstant.VOLUME_FORMAT_QCOW2); r.setVolume(vol); completion.success(r); } @Override public void fail(ErrorCode errorCode) { completion.fail(errorCode); } }); } }
@Override protected void handle(final InstantiateVolumeOnPrimaryStorageMsg msg) { if (msg.getDestHost() == null) { String hostUuid = getAvailableHostUuidForOperation(); if (hostUuid == null) { throw new OperationFailureException(operr("the shared mount point primary storage[uuid:%s, name:%s] cannot find any " + "available host in attached clusters for instantiating the volume", self.getUuid(), self.getName())); } msg.setDestHost(HostInventory.valueOf(dbf.findByUuid(hostUuid, HostVO.class))); } HypervisorFactory f = getHypervisorFactoryByHostUuid(msg.getDestHost().getUuid()); HypervisorBackend bkd = f.getHypervisorBackend(self); bkd.handle(msg, new ReturnValueCompletion<InstantiateVolumeOnPrimaryStorageReply>(msg) { @Override public void success(InstantiateVolumeOnPrimaryStorageReply reply) { bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { InstantiateVolumeOnPrimaryStorageReply reply = new InstantiateVolumeOnPrimaryStorageReply(); reply.setError(errorCode); bus.reply(msg, reply); } }); }
private void createEmptyVolume(final InstantiateVolumeOnPrimaryStorageMsg msg) { NfsPrimaryStorageBackend backend; if (msg.getDestHost() != null) { backend = getBackend(HypervisorType.valueOf(msg.getDestHost().getHypervisorType())); } else { backend = getUsableBackend(); if (backend == null) { throw new OperationFailureException(operr("the NFS primary storage[uuid:%s, name:%s] cannot find any usable host to" + " create the data volume[uuid:%s, name:%s]", self.getUuid(), self.getName(), msg.getVolume().getUuid(), msg.getVolume().getName())); } } VolumeInventory vol = msg.getVolume(); final InstantiateVolumeOnPrimaryStorageReply reply = new InstantiateVolumeOnPrimaryStorageReply(); backend.instantiateVolume(PrimaryStorageInventory.valueOf(self), vol, new ReturnValueCompletion<VolumeInventory>(msg) { @Override public void success(VolumeInventory returnValue) { reply.setVolume(returnValue); bus.reply(msg, reply); } @Override public void fail(ErrorCode errorCode) { reply.setError(errorCode); reply.setSuccess(false); bus.reply(msg, reply); } }); }
createSubTaskProgress("create a volume[%s] on the local storage", msg.getVolume().getType()); String hostUuid = msg.getDestHost().getUuid(); LocalStorageHypervisorFactory f = getHypervisorBackendFactoryByHostUuid(hostUuid); final LocalStorageHypervisorBackend bkd = f.getHypervisorBackend(self);