@Mapping(from = HostStorage.class, to = org.ovirt.engine.core.common.businessentities.StorageDomain.class) public static org.ovirt.engine.core.common.businessentities.StorageDomain map(HostStorage model, org.ovirt.engine.core.common.businessentities.StorageDomain template) { org.ovirt.engine.core.common.businessentities.StorageDomain entity = template != null ? template : new org.ovirt.engine.core.common.businessentities.StorageDomain(); entity.setStorage(model.getId()); if (model.isSetType()) { entity.setStorageType(StorageDomainMapper.map(model.getType(), null)); } return entity; } }
/** * 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 public Response remove() { StorageDomain storageDomain = get(); if (storageDomain.getStorage().getType().equals(StorageType.LOCALFS)) { RemoveStorageDomainParameters params = new RemoveStorageDomainParameters(guid); params.setDoFormat(true); return performAction(ActionType.RemoveStorageDomain, params); } else { DetachStorageDomainFromPoolParameters params = new DetachStorageDomainFromPoolParameters(guid, dataCenterId); return performAction(ActionType.DetachStorageDomainFromPool, params); } } }
@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()); } }
@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 void verifyModel(HostStorage model, int index) { assertEquals(StorageType.ISCSI, model.getType()); assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(1, model.getLogicalUnits().getLogicalUnits().size()); assertEquals(GUIDS[index].toString(), model.getLogicalUnits().getLogicalUnits().get(0).getId()); verifyLinks(model); }
private 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|size", "format"); // Non lun disks require size and format } }
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 } }
&& disk.getLunStorage()!=null && disk.getLunStorage().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits().size() > 0 && disk.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).getId()!=null && disk.getLunStorage()!=null && disk.getLunStorage().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits().size() > 0 && disk.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).getAddress()!=null && disk.getLunStorage()!=null && disk.getLunStorage().getType()!=null ) { return DisksResource.class.getMethod("addLun", Disk.class);
protected void validateDiskForCreation(Disk disk) { validateParameters(disk); if (DiskResourceUtils.isLunDisk(disk)) { validateParameters(disk.getLunStorage(), 4, "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), 4, "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, 4, "provisionedSize|size", "format"); // Non lun disks require size and format } }
private void verifyGetFcp(StorageDomain model) { assertEquals(GUIDS[0].toString(), model.getId()); assertEquals(NAMES[0], model.getName()); assertEquals(StorageDomainType.DATA, model.getType()); assertNotNull(model.getStorage()); assertEquals(StorageType.FCP, model.getStorage().getType()); assertNotNull(model.getLinks().get(0).getHref()); }
@Override protected void verify(StorageDomain model, StorageDomain transform) { assertNotNull(transform); assertEquals(model.getName(), transform.getName()); assertEquals(model.getId(), transform.getId()); // REVIST No descriptions for storage domains // assertEquals(model.getDescription(), transform.getDescription()); // REVIST No comment for storage domains //assertEquals(model.getComment(), transform.getComment()); assertEquals(model.getType(), transform.getType()); assertNotNull(transform.getStorage()); assertEquals(model.getStorage().getType(), transform.getStorage().getType()); assertEquals(model.getStorageFormat(), transform.getStorageFormat()); }
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.");
protected void verifyIscsi(StorageDomain model) { assertEquals(GUIDS[0].toString(), model.getId()); assertEquals(NAMES[0], model.getName()); assertEquals(TYPES[0], model.getType()); assertNotNull(model.getStorage()); assertEquals(StorageType.ISCSI, model.getStorage().getType()); assertNotNull(model.getStorage().getVolumeGroup()); assertEquals(GUIDS[GUIDS.length - 1].toString(), model.getStorage().getVolumeGroup().getId()); assertTrue(model.getStorage().getVolumeGroup().isSetLogicalUnits()); assertNotNull(model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().get(0)); assertEquals(LUN, model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().get(0).getId()); assertEquals(TARGET, model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().get(0).getTarget()); assertEquals(ADDRESSES[0], model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().get(0).getAddress()); assertEquals(PORT, model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits().get(0).getPort()); assertEquals(7, model.getLinks().size()); assertNotNull(getLinkByName(model, "permissions")); assertNotNull(model.getLinks().get(0).getHref()); verifyLinks(model); } }
static void verifyModelSpecific(StorageDomain model, int index) { assertEquals(getSafeEntry(index, GUIDS).toString(), model.getId()); assertEquals(getSafeEntry(index, NAMES), model.getName()); // REVIST No descriptions for storage domains // assertEquals(DESCRIPTIONS[index], model.getDescription()); assertEquals(getSafeEntry(index, TYPES), model.getType()); assertNotNull(model.getStorage()); assertEquals(getSafeEntry(index, STORAGE_TYPES), model.getStorage().getType()); if (index != LOCAL_IDX && index != POSIX_IDX) { assertEquals(getSafeEntry(index, ADDRESSES), model.getStorage().getAddress()); } assertEquals(PATHS[index], model.getStorage().getPath()); assertNotNull(getLinkByName(model, "permissions")); if (model.getType() == StorageDomainType.ISO) { assertEquals(5, model.getLinks().size()); assertNotNull(getLinkByName(model, "files")); } else if (model.getType().equals(TYPES[2])) { assertEquals(7, model.getLinks().size()); assertNotNull(getLinkByName(model, "templates")); assertNotNull(getLinkByName(model, "vms")); } assertNotNull(model.getLinks().get(0).getHref()); }
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");
entity.setStorageType(map(model.getStorage().getType(), null));
@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()); }
@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()); }
@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()); }