@Mapping(from = LUNs.class, to = HostStorage.class) public static HostStorage map(LUNs entity, HostStorage template) { HostStorage model = template != null ? template : new HostStorage(); model.setId(entity.getLUNId()); model.setType(StorageDomainMapper.map(entity.getLunType(), null)); model.setLogicalUnits(new LogicalUnits()); model.getLogicalUnits().getLogicalUnits().add(map(entity, (LogicalUnit) null)); return model; }
@Override public V3Storage adapt(HostStorage from) { V3Storage to = new V3Storage(); if (from.isSetLinks()) { to.getLinks().addAll(adaptOut(from.getLinks())); if (from.isSetActions()) { to.setActions(adaptOut(from.getActions())); if (from.isSetAddress()) { to.setAddress(from.getAddress()); if (from.isSetComment()) { to.setComment(from.getComment()); if (from.isSetDescription()) { to.setDescription(from.getDescription()); if (from.isSetHost()) { to.setHost(adaptOut(from.getHost())); if (from.isSetId()) { to.setId(from.getId()); if (from.isSetHref()) { to.setHref(from.getHref()); if (from.isSetLogicalUnits()) { to.getLogicalUnits().addAll(adaptOut(from.getLogicalUnits().getLogicalUnits()));
private List<LogicalUnit> getIncomingLuns(HostStorage storage) { // user may pass the LUNs under Storage, or Storage-->VolumeGroup; both are supported. if (!storage.isSetLogicalUnits() || !storage.getLogicalUnits().isSetLogicalUnits()) { if (storage.isSetVolumeGroup() && storage.getVolumeGroup().isSetLogicalUnits() && storage.getVolumeGroup().getLogicalUnits().isSetLogicalUnits()) { return storage.getVolumeGroup().getLogicalUnits().getLogicalUnits(); } else { return new ArrayList<>(); } } else { return storage.getLogicalUnits().getLogicalUnits(); } }
@Mapping(from = org.ovirt.engine.core.common.businessentities.StorageDomain.class, to = HostStorage.class) public static HostStorage map(org.ovirt.engine.core.common.businessentities.StorageDomain entity, HostStorage template) { HostStorage model = template != null ? template : new HostStorage(); model.setId(entity.getStorage()); model.setType(StorageDomainMapper.map(entity.getStorageType(), null)); model.setVolumeGroup(new VolumeGroup()); model.getVolumeGroup().setId(entity.getStorage()); return model; }
@Override public HostStorage adapt(V3Storage from) { HostStorage to = new HostStorage(); if (from.isSetLinks()) { to.getLinks().addAll(adaptIn(from.getLinks())); to.setActions(adaptIn(from.getActions())); to.setAddress(from.getAddress()); to.setComment(from.getComment()); to.setDescription(from.getDescription()); to.setHost(adaptIn(from.getHost())); to.setId(from.getId()); to.setHref(from.getHref()); to.setLogicalUnits(new LogicalUnits()); to.getLogicalUnits().getLogicalUnits().addAll(adaptIn(from.getLogicalUnits())); to.setMountOptions(from.getMountOptions()); to.setName(from.getName()); to.setNfsRetrans(from.getNfsRetrans()); to.setNfsTimeo(from.getNfsTimeo());
@Test public void checkNFSStorageConnectionsMappings() { StorageServerConnections connection = new StorageServerConnections(); Guid connId = Guid.newGuid(); connection.setId(connId.toString()); connection.setStorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType.NFS); connection.setConnection("1.2.135.255:/myshare/data"); connection.setNfsRetrans((short) 200); connection.setNfsTimeo((short) 400); connection.setNfsVersion(org.ovirt.engine.core.common.businessentities.NfsVersion.V3); connection.setMountOptions("tcp"); HostStorage RESTConnection = new HostStorage(); RESTConnection.setId(connId.toString()); RESTConnection.setType(StorageType.NFS); RESTConnection.setAddress("1.2.135.255"); RESTConnection.setPath("/myshare/data"); RESTConnection.setNfsRetrans(200); RESTConnection.setNfsTimeo(400); RESTConnection.setNfsVersion(NfsVersion.V3); RESTConnection.setMountOptions("tcp"); StorageConnection mappedResult = StorageDomainMapper.map(connection, null); assertEquals(RESTConnection.getId(), mappedResult.getId()); assertEquals(RESTConnection.getType(), mappedResult.getType()); assertEquals(RESTConnection.getAddress(), mappedResult.getAddress()); assertEquals(RESTConnection.getPath(), mappedResult.getPath()); assertEquals(RESTConnection.getNfsRetrans(), mappedResult.getNfsRetrans()); assertEquals(RESTConnection.getNfsTimeo(), mappedResult.getNfsTimeo()); assertEquals(RESTConnection.getNfsVersion(), mappedResult.getNfsVersion()); assertEquals(RESTConnection.getMountOptions(), mappedResult.getMountOptions()); }
@Test public void checkPosixStorageConnectionsMappings() { StorageServerConnections connection = new StorageServerConnections(); Guid connId = Guid.newGuid(); connection.setId(connId.toString()); connection.setStorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType.POSIXFS); connection.setConnection("1.2.135.255:/myshare/data"); connection.setVfsType("nfs"); connection.setMountOptions("timeo=30"); HostStorage RESTConnection = new HostStorage(); RESTConnection.setId(connId.toString()); RESTConnection.setType(StorageType.POSIXFS); RESTConnection.setAddress("1.2.135.255"); RESTConnection.setPath("/myshare/data"); RESTConnection.setVfsType("nfs"); RESTConnection.setMountOptions("timeo=30"); StorageConnection mappedResult = StorageDomainMapper.map(connection, null); assertEquals(RESTConnection.getId(), mappedResult.getId()); assertEquals(RESTConnection.getType(), mappedResult.getType()); assertEquals(RESTConnection.getAddress(), mappedResult.getAddress()); assertEquals(RESTConnection.getVfsType(), mappedResult.getVfsType()); assertEquals(RESTConnection.getPath(), mappedResult.getPath()); assertEquals(RESTConnection.getMountOptions(), mappedResult.getMountOptions()); }
@Mapping(from = StorageDomain.class, to = StorageServerConnections.class) public static StorageServerConnections map(StorageDomain model, StorageServerConnections template) { StorageServerConnections entity = template != null ? template : new StorageServerConnections(); if (model.isSetStorage() && model.getStorage().isSetType()) { HostStorage storage = model.getStorage(); StorageType storageType = storage.getType(); if (storageType != null) { entity.setStorageType(map(storageType, null)); break; case NFS: if(storage.isSetAddress() && storage.isSetPath()) { entity.setConnection(storage.getAddress() + ":" + storage.getPath()); if(storage.getNfsRetrans() != null) { entity.setNfsRetrans(storage.getNfsRetrans().shortValue()); if(storage.getNfsTimeo() != null) { entity.setNfsTimeo(storage.getNfsTimeo().shortValue()); if(storage.getNfsVersion() != null) { entity.setNfsVersion(map(storage.getNfsVersion(), null)); if (storage.isSetMountOptions()) { entity.setMountOptions(storage.getMountOptions()); if (storage.isSetPath()) { entity.setConnection(storage.getPath()); if (storage.isSetAddress() && storage.isSetPath()) {
@Test public void checkISCSIStorageConnectionsMappings() { StorageServerConnections connection = new StorageServerConnections(); Guid connId = Guid.newGuid(); connection.setId(connId.toString()); connection.setIqn("iqn.my.target1"); connection.setPort("3260"); connection.setStorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType.ISCSI); connection.setConnection("1.2.135.255"); connection.setUserName("myuser1"); connection.setPassword("123"); HostStorage RESTConnection = new HostStorage(); RESTConnection.setId(connId.toString()); RESTConnection.setType(StorageType.ISCSI); RESTConnection.setPort(3260); RESTConnection.setTarget("iqn.my.target1"); RESTConnection.setAddress("1.2.135.255"); RESTConnection.setUsername("myuser1"); StorageConnection mappedResult = StorageDomainMapper.map(connection, null); assertEquals(RESTConnection.getId(), mappedResult.getId()); // Although password was set on StorageServerConnections object, it should not be returned via REST // thus testing here that it remains empty. assertEquals(RESTConnection.getPassword(), mappedResult.getPassword()); assertEquals(RESTConnection.getType(), mappedResult.getType()); assertEquals(RESTConnection.getAddress(), mappedResult.getAddress()); assertEquals(RESTConnection.getUsername(), mappedResult.getUsername()); assertEquals(RESTConnection.getTarget(), mappedResult.getTarget()); }
throw new ValidationException("Parameter 'storage_domain' is mandatory but was not provided."); if (storageDomain.getStorage()==null || storageDomain.getStorage().getType()==null) { throw new ValidationException("Parameter 'storage_domain.storage.type' is mandatory but was not provided."); && storageDomain.getStorage()!=null && storageDomain.getStorage().getVfsType()!=null && storageDomain.getStorage()!=null && storageDomain.getStorage().getPath()!=null ) { return StorageDomainsResource.class.getMethod("addGlusterOrPostfs", StorageDomain.class); && storageDomain.getStorage()!=null && storageDomain.getStorage().getPath()!=null && storageDomain.getStorage()!=null && storageDomain.getStorage().getAddress()!=null ) { return StorageDomainsResource.class.getMethod("addByPath", StorageDomain.class); && storageDomain.getStorage()!=null && storageDomain.getStorage().getLogicalUnits()!=null && storageDomain.getStorage().getLogicalUnits().getLogicalUnits()!=null && storageDomain.getStorage().getLogicalUnits().getLogicalUnits().size() > 0 && storageDomain.getStorage().getLogicalUnits().getLogicalUnits().get(0).getTarget()!=null && storageDomain.getStorage()!=null && storageDomain.getStorage().getLogicalUnits()!=null && storageDomain.getStorage().getLogicalUnits().getLogicalUnits()!=null && storageDomain.getStorage().getLogicalUnits().getLogicalUnits().size() > 0 && storageDomain.getStorage().getLogicalUnits().getLogicalUnits().get(0).getPort()!=null && storageDomain.getStorage()!=null && storageDomain.getStorage().getLogicalUnits()!=null && storageDomain.getStorage().getLogicalUnits().getLogicalUnits()!=null && storageDomain.getStorage().getLogicalUnits().getLogicalUnits().size() > 0 && storageDomain.getStorage().getLogicalUnits().getLogicalUnits().get(0).getId()!=null && storageDomain.getStorage()!=null && storageDomain.getStorage().getLogicalUnits()!=null && storageDomain.getStorage().getLogicalUnits().getLogicalUnits()!=null && storageDomain.getStorage().getLogicalUnits().getLogicalUnits().size() > 0 && storageDomain.getStorage().getLogicalUnits().getLogicalUnits().get(0).getAddress()!=null ) { return StorageDomainsResource.class.getMethod("addDirectLun", StorageDomain.class); && storageDomain.getStorage()!=null && storageDomain.getStorage().getPath()!=null ) { return StorageDomainsResource.class.getMethod("addLocal", StorageDomain.class);
@Override public Response add(StorageDomain storageDomain) { validateParameters(storageDomain, "host.id|name", "type", "storage"); validateRange("nfs_timeio", storageDomain.getStorage().getNfsTimeo(), 0, 65535); validateRange("nfs_retrans", storageDomain.getStorage().getNfsRetrans(), 0, 65535); HostStorage storageConnectionFromUser = storageDomain.getStorage(); Guid hostId = getHostId(storageDomain); StorageServerConnections cnx = null; if (storageConnectionFromUser.getType() != org.ovirt.engine.api.model.StorageType.MANAGED_BLOCK_STORAGE) { if (!storageConnectionFromUser.isSetId()) { validateParameters(storageDomain, "storage.type"); cnx = mapToCnx(storageDomain); cnx = getStorageServerConnection(storageConnectionFromUser.getId()); storageDomain.getStorage().setType(mapType(cnx.getStorageType())); if (!storageConnectionFromUser.isSetId()) { validateParameters(storageDomain.getStorage(), "address"); break; case POSIXFS: if (!storageConnectionFromUser.isSetId()) { validateParameters(storageDomain.getStorage(), "vfsType"); break; case GLUSTERFS: if (!storageConnectionFromUser.isSetId()) { validateParameters(storageDomain.getStorage(), "vfsType"); resp = addManagedBlockStorageDomain(ActionType.AddManagedBlockStorageDomain,
static StorageDomain getModel(int index) { StorageDomain model = new StorageDomain(); model.setName(getSafeEntry(index, NAMES)); model.setDescription(getSafeEntry(index, DESCRIPTIONS)); model.setType(getSafeEntry(index, TYPES)); model.setStorage(new HostStorage()); model.getStorage().setType(getSafeEntry(index, STORAGE_TYPES)); model.getStorage().setAddress(getSafeEntry(index, ADDRESSES)); model.getStorage().setPath(getSafeEntry(index, PATHS)); model.getStorage().setMountOptions(getSafeEntry(index, MOUNT_OPTIONS)); model.getStorage().setVfsType(getSafeEntry(index, VFS_TYPES)); return model; }
protected StorageDomain getIscsi() { StorageDomain model = getModel(0); model.getStorage().setType(StorageType.ISCSI); model.getStorage().setAddress(null); model.getStorage().setPath(null); model.getStorage().setVolumeGroup(new VolumeGroup()); model.getStorage().getVolumeGroup().setLogicalUnits(new LogicalUnits()); model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().add(new LogicalUnit()); model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().get(0).setId(LUN); model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().get(0).setTarget(TARGET); model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().get(0).setAddress(ADDRESSES[0]); model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().get(0).setPort(PORT); model.getStorage().setOverrideLuns(false); return model; }
@Override protected HostStorage postPopulate(HostStorage from) { from.setType(StorageType.FCP); from.setVolumeGroup(new VolumeGroup()); from.getVolumeGroup().setId(from.getId()); return from; }
protected void validateDiskForCreation(Disk disk) { if (DiskResourceUtils.isLunDisk(disk)) { validateParameters(disk.getLunStorage(), 2, "type"); // when creating a LUN disk, user must specify type. StorageType storageType = disk.getLunStorage().getType(); if (storageType != null && storageType == StorageType.ISCSI) { validateParameters(disk.getLunStorage().getLogicalUnits().getLogicalUnits().get(0), 3, "address", "target", "port", "id"); } } else if (disk.isSetLunStorage() && (!disk.getLunStorage().isSetLogicalUnits() || !disk.getLunStorage().getLogicalUnits().isSetLogicalUnits())) { // TODO: Implement nested entity existence validation infra for validateParameters() throw new WebFaultException(null, localize(Messages.INCOMPLETE_PARAMS_REASON), localize(Messages.INCOMPLETE_PARAMS_DETAIL_TEMPLATE, "LogicalUnit", "", "add"), Response.Status.BAD_REQUEST); } else { validateParameters(disk, 2, "provisionedSize", "format"); // Non lun disks require size and format } }
@Override protected void verify(HostStorage model, HostStorage transform) { assertNotNull(transform); assertEquals(model.getId(), transform.getId()); assertEquals(model.getType(), transform.getType()); assertEquals(model.getLogicalUnits().getLogicalUnits().size(), model.getLogicalUnits().getLogicalUnits().size()); for (int i = 0; i < model.getLogicalUnits().getLogicalUnits().size(); i++) { assertEquals(model.getLogicalUnits().getLogicalUnits().get(i).getId(), transform.getLogicalUnits().getLogicalUnits().get(i).getId()); } }
@Test public void testStorageLinks() { HostStorage storage = new HostStorage(); storage.setId(STORAGE_ID); storage.setHost(new Host()); storage.getHost().setId(HOST_ID); LinkHelper.addLinks(storage); assertEquals(STORAGE_HREF, storage.getHref()); assertEquals(HOST_HREF, storage.getHost().getHref()); }
/** * This mapping exists for adding a lun-disk, and assumes that 'storage' entity contains exactly one lun. */ @Mapping(from = HostStorage.class, to = LUNs.class) public static LUNs map(HostStorage model, LUNs template) { LUNs entity = template != null ? template : new LUNs(); if (model.isSetLogicalUnits() && model.getLogicalUnits().isSetLogicalUnits()) { LogicalUnit logicalUnit = model.getLogicalUnits().getLogicalUnits().get(0); entity.setLUNId(logicalUnit.getId()); ArrayList<StorageServerConnections> connections = new ArrayList<>(); connections.add(map(logicalUnit, null)); entity.setLunConnections(connections); } if (model.isSetType()) { entity.setLunType(StorageDomainMapper.map(model.getType(), null)); } return entity; }
@Override protected void verify(HostStorage model, HostStorage transform) { assertNotNull(transform); assertEquals(model.getId(), transform.getId()); assertEquals(model.getType(), transform.getType()); assertNotNull(model.getVolumeGroup()); assertEquals(model.getVolumeGroup().getId(), model.getVolumeGroup().getId()); } }
@Override protected HostStorage postPopulate(HostStorage from) { from.setType(StorageType.CINDER); LogicalUnit unit = new LogicalUnit(); unit.setId(from.getId()); from.getLogicalUnits().unsetLogicalUnits(); from.getLogicalUnits().getLogicalUnits().add(unit); return from; }