@Override public String call(PrimaryStorageInventory arg) { return arg.getUuid(); } });
protected PrimaryStorageInventory getSelfInventory() { return PrimaryStorageInventory.valueOf(self); }
@Override public void afterAttachPrimaryStorage(PrimaryStorageInventory inventory, String clusterUuid) { if (inventory.getType().equals(SMPConstants.SMP_TYPE)) { RecalculatePrimaryStorageCapacityMsg msg = new RecalculatePrimaryStorageCapacityMsg(); msg.setPrimaryStorageUuid(inventory.getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, inventory.getUuid()); bus.send(msg); } } }
public static APIDetachPrimaryStorageFromClusterEvent __example__() { APIDetachPrimaryStorageFromClusterEvent event = new APIDetachPrimaryStorageFromClusterEvent(); PrimaryStorageInventory ps = new PrimaryStorageInventory(); ps.setName("PS1"); ps.setUrl("/zstack_ps"); ps.setType("LocalStorage"); ps.setState(PrimaryStorageState.Enabled.toString()); ps.setStatus(PrimaryStorageStatus.Connected.toString()); event.setInventory(ps); return event; }
public static APISyncPrimaryStorageCapacityEvent __example__() { APISyncPrimaryStorageCapacityEvent event = new APISyncPrimaryStorageCapacityEvent(); PrimaryStorageInventory ps = new PrimaryStorageInventory(); ps.setName("PS1"); ps.setUrl("/zstack_ps"); ps.setType("LocalStorage"); ps.setAttachedClusterUuids(Collections.singletonList(uuid())); ps.setState(PrimaryStorageState.Enabled.toString()); ps.setStatus(PrimaryStorageStatus.Connected.toString()); ps.setAvailableCapacity(1024L * 1024L * 928L); ps.setAvailablePhysicalCapacity(1024L * 1024L * 928L); event.setInventory(ps); return event; }
@Transactional(readOnly = true) private List<PrimaryStorageInventory> getPrimaryStorageForHost(String clusterUuid) { String sql = "select p.uuid, p.url, p.mountPath from PrimaryStorageVO p where p.type = :ptype and p.uuid in (select r.primaryStorageUuid from PrimaryStorageClusterRefVO r where r.clusterUuid = :clusterUuid)"; Query query = dbf.getEntityManager().createQuery(sql); query.setParameter("clusterUuid", clusterUuid); query.setParameter("ptype", NfsPrimaryStorageConstant.NFS_PRIMARY_STORAGE_TYPE); List<Object[]> lst = query.getResultList(); List<PrimaryStorageInventory> pss = new ArrayList<PrimaryStorageInventory>(); for (Object[] objs : lst) { PrimaryStorageInventory inv = new PrimaryStorageInventory(); inv.setUuid((String) objs[0]); inv.setUrl((String) objs[1]); inv.setMountPath((String) objs[2]); pss.add(inv); } return pss; }
private void mount(PrimaryStorageInventory inv, String hostUuid, Completion completion) { MountCmd cmd = new MountCmd(); cmd.setUrl(inv.getUrl()); cmd.setMountPath(inv.getMountPath()); cmd.setOptions(NfsSystemTags.MOUNT_OPTIONS.getTokenByResourceUuid(inv.getUuid(), NfsSystemTags.MOUNT_OPTIONS_TOKEN)); syncHttpCall(MOUNT_PRIMARY_STORAGE_PATH, hostUuid, cmd, true, MountAgentResponse.class, inv, new ReturnValueCompletion<MountAgentResponse>(completion) { @Override public void success(MountAgentResponse returnValue) { logger.debug(String.format( "Successfully mounted nfs primary storage[uuid:%s] on kvm host[uuid:%s]", inv.getUuid(), hostUuid)); completion.success(); } @Override public void fail(ErrorCode errorCode) { if (errorCode.getDetails().contains("java.net.SocketTimeoutException: Read timed out")) { // socket read timeout is caused by timeout of mounting a wrong URL errorCode = touterr(errorCode, "mount timeout. Please the check if the URL[%s] is" + " valid to mount", inv.getUrl()); } completion.fail(errorCode); } }); }
String preDetach(PrimaryStorageVO vo, String clusterUuid) throws PrimaryStorageException { PrimaryStorageInventory inv = PrimaryStorageInventory.valueOf(vo); for (PrimaryStorageDetachExtensionPoint extp : detachExts) { try { extp.preDetachPrimaryStorage(inv, clusterUuid); } catch (PrimaryStorageException pe) { logger.debug(String.format("%s refused to detach primary storage[uuid:%s, name: %s] because %s", extp.getClass().getName(), inv.getUuid(), inv.getName(), pe.getMessage())); throw pe; } catch (Exception e) { logger.warn("Exception happened when calling preDetach of PrimaryStorageDetachExtensionPoint", e); } } return null; }
@Override public void run(List<MessageReply> replies) { if (!action.isActionCode(CascadeConstant.DELETION_FORCE_DELETE_CODE)) { for (MessageReply r : replies) { if (!r.isSuccess()) { completion.fail(r.getError()); return; } } } List<String> uuids = new ArrayList<>(); for (MessageReply r : replies) { PrimaryStorageInventory inv = prinvs.get(replies.indexOf(r)); uuids.add(inv.getUuid()); logger.debug(String.format("delete primary storage[uuid:%s, name:%s]", inv.getUuid(), inv.getName())); } dbf.removeByPrimaryKeys(uuids, PrimaryStorageVO.class); completion.success(); } });
PrimaryStorageInventory lsInv = new PrimaryStorageInventory(); lsInv.setName("example"); lsInv.setDescription("example"); lsInv.setUuid(uuid()); lsInv.setAttachedClusterUuids(asList(uuid())); lsInv.setAvailableCapacity(SizeUnit.GIGABYTE.toByte(200L)); lsInv.setAvailablePhysicalCapacity(SizeUnit.GIGABYTE.toByte(200L)); lsInv.setTotalCapacity(SizeUnit.GIGABYTE.toByte(300L)); lsInv.setTotalPhysicalCapacity(SizeUnit.GIGABYTE.toByte(300L)); lsInv.setState(PrimaryStorageState.Enabled.toString()); lsInv.setStatus(PrimaryStorageStatus.Connected.toString()); lsInv.setType("LocalStorage"); lsInv.setCreateDate(new Timestamp(org.zstack.header.message.DocUtils.date)); lsInv.setLastOpDate(new Timestamp(org.zstack.header.message.DocUtils.date)); lsInv.setUrl("/zstack_ps"); PrimaryStorageInventory nfsInv = new PrimaryStorageInventory(); String uuid = uuid(); nfsInv.setName("example"); nfsInv.setDescription("example"); nfsInv.setUuid(uuid); nfsInv.setAttachedClusterUuids(asList(uuid())); nfsInv.setAvailableCapacity(SizeUnit.GIGABYTE.toByte(200L)); nfsInv.setAvailablePhysicalCapacity(SizeUnit.GIGABYTE.toByte(200L)); nfsInv.setTotalCapacity(SizeUnit.GIGABYTE.toByte(300L)); nfsInv.setTotalPhysicalCapacity(SizeUnit.GIGABYTE.toByte(300L)); nfsInv.setState(PrimaryStorageState.Enabled.toString()); nfsInv.setStatus(PrimaryStorageStatus.Connected.toString()); nfsInv.setType("NFS");
void preAttach(PrimaryStorageVO vo, String clusterUuid) throws PrimaryStorageException { PrimaryStorageInventory inv = PrimaryStorageInventory.valueOf(vo); for (PrimaryStorageAttachExtensionPoint extp : attachExts) { try { extp.preAttachPrimaryStorage(inv, clusterUuid); } catch (PrimaryStorageException pe) { logger.debug(String.format("%s refused to attach primary storage[uuid:%s] because %s", extp.getClass().getName(), inv.getUuid(), pe.getMessage())); throw pe; } catch (Exception e) { logger.warn("Exception happened when calling preAttach of PrimaryStorageAttachExtensionPoint", e); } } }
@Transactional public List<HostInventory> getConnectedHostForOperation(PrimaryStorageInventory pri, int startPage, int pageLimit) { if (pri.getAttachedClusterUuids().isEmpty()) { throw new OperationFailureException(operr("cannot find a Connected host to execute command for smp primary storage[uuid:%s]", pri.getUuid())); } String sql = "select h from HostVO h " + "where h.status = :connectionState and h.clusterUuid in (:clusterUuids) " + "and h.uuid not in (select ref.hostUuid from PrimaryStorageHostRefVO ref " + "where ref.primaryStorageUuid = :psUuid and ref.hostUuid = h.uuid and ref.status = :status)"; TypedQuery<HostVO> q = dbf.getEntityManager().createQuery(sql, HostVO.class); q.setParameter("connectionState", HostStatus.Connected); q.setParameter("clusterUuids", pri.getAttachedClusterUuids()); q.setParameter("psUuid", pri.getUuid()); q.setParameter("status", PrimaryStorageHostStatus.Disconnected); q.setFirstResult(startPage * pageLimit); if (pageLimit > 0){ q.setMaxResults(pageLimit); } List<HostVO> ret = q.getResultList(); if (ret.isEmpty() && startPage == 0) { //check is first page throw new OperationFailureException(operr( "cannot find a host which has Connected host-SMP connection to execute command for smp primary storage[uuid:%s]", pri.getUuid())); } else { Collections.shuffle(ret); return HostInventory.valueOf(ret); } }
@Override public IncreasePrimaryStorageCapacityMsg call(VolumeSpec arg) { if (arg.isVolumeCreated()) { // don't return capacity as it has been returned when the volume is deleted return null; } IncreasePrimaryStorageCapacityMsg msg = new IncreasePrimaryStorageCapacityMsg(); msg.setDiskSize(arg.getSize()); msg.setPrimaryStorageUuid(arg.getPrimaryStorageInventory().getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, arg.getPrimaryStorageInventory().getUrl()); return msg; } });
private boolean isLocal(PrimaryStorageInventory inv) { return inv.getType().equals(LocalStorageConstants.LOCAL_STORAGE_TYPE); }
@Override public void fail(ErrorCode errorCode) { if (errorCode.getDetails().contains("java.net.SocketTimeoutException: Read timed out")) { // socket read timeout is caused by timeout of mounting a wrong URL errorCode = touterr(errorCode, "mount timeout. Please the check if the URL[%s] is" + " valid to mount", inv.getUrl()); } completion.fail(errorCode); } });
public static PrimaryStorageInventory valueOf(PrimaryStorageVO vo) { return new PrimaryStorageInventory(vo); }
private String selectRandomHostFromPS(PrimaryStorageInventory ps) { List<String> cuuids = ps.getAttachedClusterUuids(); if (cuuids.isEmpty()) { return null; } List<String> hosts = SQL.New("select host.uuid from ClusterVO cluster, HostVO host " + "where cluster.uuid = host.clusterUuid and host.status = :hostStatus and cluster.uuid in (:cuuids) order by rand()"). param("hostStatus", HostStatus.Connected).param("cuuids", cuuids).list(); if (hosts == null || hosts.size() == 0) { return null; } return hosts.get(0); }
private void unmount(PrimaryStorageInventory inv, String hostUuid) { UnmountCmd cmd = new UnmountCmd(); cmd.setUuid(inv.getUuid()); cmd.setMountPath(inv.getMountPath()); cmd.setUrl(inv.getUrl()); KVMHostSyncHttpCallMsg msg = new KVMHostSyncHttpCallMsg(); msg.setCommand(cmd); msg.setPath(UNMOUNT_PRIMARY_STORAGE_PATH); msg.setHostUuid(hostUuid); bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, hostUuid); MessageReply reply = bus.call(msg); if (!reply.isSuccess()) { throw new OperationFailureException(reply.getError()); } AgentResponse rsp = ((KVMHostSyncHttpCallReply) reply).toResponse(AgentResponse.class); if (!rsp.isSuccess()) { String err = String.format("Unable to unmount nfs primary storage[uuid:%s] on kvm host[uuid:%s], because %s", inv.getUuid(), hostUuid, rsp.getError()); logger.warn(err); } else { String info = String.format("Successfully unmount nfs primary storage[uuid:%s] on kvm host[uuid:%s]", inv.getUuid(), hostUuid); logger.debug(info); nfsFactory.updateNfsHostStatus(inv.getUuid(), hostUuid, PrimaryStorageHostStatus.Disconnected); } }
public static APIChangePrimaryStorageStateEvent __example__() { APIChangePrimaryStorageStateEvent event = new APIChangePrimaryStorageStateEvent(); PrimaryStorageInventory ps = new PrimaryStorageInventory(); ps.setName("PS1"); ps.setUrl("/zstack_ps"); ps.setType("LocalStorage"); ps.setAttachedClusterUuids(Collections.singletonList(uuid())); ps.setState(PrimaryStorageState.Disabled.toString()); event.setInventory(ps); return event; }
@Override public void fail(ErrorCode errorCode) { String err = String.format("failed to downloaded iso[uuid:%s, name:%s] from backup storage[uuid:%s] to primary storage[uuid:%s, name:%s]", img.getUuid(), img.getName(), msg.getIsoSpec().getSelectedBackupStorage().getBackupStorageUuid(), pinv.getUuid(), pinv.getName()); logger.warn(err); reply.setError(errorCode); bus.reply(msg, reply); } }, ImageCacheInventory.class);