@Mapping(from = StorageServerConnections.class, to = LogicalUnit.class) public static LogicalUnit map(StorageServerConnections entity, LogicalUnit template) { LogicalUnit model = template != null ? template : new LogicalUnit(); model.setAddress(entity.getConnection()); model.setTarget(entity.getIqn()); model.setPort(Integer.parseInt(entity.getPort())); model.setUsername(entity.getUserName()); if (entity.getConnection()!=null && entity.getPort()!=null && entity.getPortal()!=null) { model.setPortal(entity.getConnection() + ":" + entity.getPort() + "," + entity.getPortal()); } return model; }
@Override public V3LogicalUnit adapt(LogicalUnit from) { V3LogicalUnit to = new V3LogicalUnit(); if (from.isSetAddress()) { to.setAddress(from.getAddress()); if (from.isSetDiskId()) { to.setDiskId(from.getDiskId()); if (from.isSetId()) { to.setId(from.getId()); if (from.isSetLunMapping()) { to.setLunMapping(from.getLunMapping()); if (from.isSetPassword()) { to.setPassword(from.getPassword()); if (from.isSetPaths()) { to.setPaths(from.getPaths()); if (from.isSetPort()) { to.setPort(from.getPort()); if (from.isSetPortal()) { to.setPortal(from.getPortal()); if (from.isSetProductId()) { to.setProductId(from.getProductId());
private boolean isConnectionAssumed(LogicalUnit unit) { // either 'target' and 'address' should both be provided, or none. Validate this if (unit.getAddress() != null || unit.getTarget() != null) { validateParameters(unit, "address", "target"); } boolean connectionAssumed = unit.getAddress() == null || unit.getTarget() == null; return connectionAssumed; }
private void connectStorageToHost(Guid hostId, StorageType storageType, LogicalUnit unit) { StorageServerConnections cnx = StorageDomainHelper.getConnection(storageType, unit.getAddress(), unit.getTarget(), unit.getUsername(), unit.getPassword(), unit.getPort()); performAction(ActionType.ConnectStorageToVds, new StorageServerConnectionParametersBase(cnx, hostId, false)); }
@Mapping(from = LogicalUnit.class, to = StorageServerConnections.class) public static StorageServerConnections map(LogicalUnit logicalUnit, StorageServerConnections connection) { StorageServerConnections entity = connection != null ? connection : new StorageServerConnections(); if (logicalUnit.isSetAddress()) { entity.setConnection(logicalUnit.getAddress()); } if (logicalUnit.isSetTarget()) { entity.setIqn(logicalUnit.getTarget()); } if (logicalUnit.isSetPort()) { entity.setPort(logicalUnit.getPort().toString()); } if (logicalUnit.isSetUsername()) { entity.setUserName(logicalUnit.getUsername()); } if (logicalUnit.isSetPassword()) { entity.setPassword(logicalUnit.getPassword()); } return entity; }
@Override public LogicalUnit adapt(V3LogicalUnit from) { LogicalUnit to = new LogicalUnit(); if (from.isSetAddress()) { to.setAddress(from.getAddress()); to.setDiskId(from.getDiskId()); to.setId(from.getId()); to.setLunMapping(from.getLunMapping()); to.setPassword(from.getPassword()); to.setPaths(from.getPaths()); to.setPort(from.getPort()); to.setPortal(from.getPortal()); to.setProductId(from.getProductId()); to.setSerial(from.getSerial()); to.setSize(from.getSize()); to.setStatus(LunStatus.fromValue(from.getStatus())); to.setStorageDomainId(from.getStorageDomainId());
@Mapping(from = LUNs.class, to = LogicalUnit.class) public static LogicalUnit map(LUNs entity, LogicalUnit template) { LogicalUnit model = template != null ? template : new LogicalUnit(); model.setId(entity.getLUNId()); if (entity.getVendorId()!=null && !entity.getVendorId().isEmpty()) { model.setVendorId(entity.getVendorId()); model.setProductId(entity.getProductId()); model.setSerial(entity.getSerial()); model.setLunMapping(entity.getLunMapping()); model.setVolumeGroupId(entity.getVolumeGroupId()); model.setStorageDomainId(entity.getStorageDomainId().toString()); model.setDiskId(entity.getDiskId().toString()); model.setStatus(map(entity.getStatus(), null)); model.setDiscardMaxSize(entity.getDiscardMaxSize()); model.setDiscardZeroesData(false); model.setSize(SizeConverter.convert((long)entity.getDeviceSize(), SizeConverter.SizeUnit.GiB, SizeConverter.SizeUnit.BYTES).longValue()); model.setPaths(entity.getPathCount()); return model;
&& disk.getLunStorage()!=null && disk.getLunStorage().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits()!=null && disk.getLunStorage().getLogicalUnits().getLogicalUnits().size() > 0 && disk.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).getTarget()!=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).getPort()!=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).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 ) {
private Disk createIscsiLunDisk() { Disk model = getModel(); model.setLunStorage(new HostStorage()); model.getLunStorage().setType(StorageType.ISCSI); model.getLunStorage().setLogicalUnits(new LogicalUnits()); model.getLunStorage().getLogicalUnits().getLogicalUnits().add(new LogicalUnit()); model.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).setId(GUIDS[0].toString()); model.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).setAddress(ISCSI_SERVER_ADDRESS); model.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).setTarget(ISCSI_SERVER_TARGET); model.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).setPort(ISCSI_SERVER_CONNECTION_PORT); model.setProvisionedSize(null); return model; }
private IscsiDetails mapLogicalUnitToIscsiDetails(LogicalUnit logicalUnit) { IscsiDetails iscsiDetails = new IscsiDetails(); iscsiDetails.setAddress(logicalUnit.getAddress()); iscsiDetails.setPort(logicalUnit.getPort()); iscsiDetails.setTarget(logicalUnit.getTarget()); iscsiDetails.setPortal(logicalUnit.getPortal()); iscsiDetails.setPaths(logicalUnit.getPaths()); iscsiDetails.setVendorId(logicalUnit.getVendorId()); iscsiDetails.setProductId(logicalUnit.getProductId()); iscsiDetails.setSerial(logicalUnit.getSerial()); return iscsiDetails; }
@Test public void testOneWayMapping() { LUNs model = new LUNs(); model.setVendorId("vendor_id_1"); model.setProductId("product_id_1"); model.setLunMapping(5); model.setSerial("some_serial"); model.setVolumeGroupId("volume_group_id_1"); model.setStorageDomainId(Guid.Empty); model.setDiskId(Guid.Empty); model.setStatus(org.ovirt.engine.core.common.businessentities.storage.LunStatus.Free); LogicalUnit entity = StorageLogicalUnitMapper.map(model, (LogicalUnit) null); assertEquals("vendor_id_1", entity.getVendorId()); assertEquals("product_id_1", entity.getProductId()); assertEquals("some_serial", entity.getSerial()); assertEquals(Integer.valueOf(5), entity.getLunMapping()); assertEquals("volume_group_id_1", entity.getVolumeGroupId()); assertEquals(entity.getStorageDomainId(), Guid.Empty.toString()); assertEquals(entity.getDiskId(), Guid.Empty.toString()); assertEquals(LunStatus.FREE, entity.getStatus()); }
@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; }
/** * Create an instance of {@link LogicalUnit } * */ public LogicalUnit createLogicalUnit() { return new LogicalUnit(); }
model.setHost(host); for (LogicalUnit lun : model.getStorage().getVolumeGroup().getLogicalUnits().getLogicalUnits()) { lun.setAddress(null); lun.setTarget(null);
private Action mapTargets(Action action, List<StorageServerConnections> targets) { if (targets != null) { Action.IscsiTargetsList iscsiTargets = new Action.IscsiTargetsList(); IscsiDetailss iscsiDetailss = new IscsiDetailss(); for (StorageServerConnections cnx : targets) { LogicalUnit logicalUnit = map(cnx); // The iscsiTargets property is replaced by discoveredTargets. The property is preserved // for backward compatibility, and should be removed in version 5 of the API. iscsiTargets.getIscsiTargets().add(logicalUnit.getTarget()); iscsiDetailss.getIscsiDetailss().add(mapLogicalUnitToIscsiDetails(logicalUnit)); } action.setIscsiTargets(iscsiTargets); action.setDiscoveredTargets(iscsiDetailss); } return action; }
@Test public void testAddLunDiskMissingId() { Disk model = createIscsiLunDisk(); model.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).setId(null); setUriInfo(setUpBasicUriExpectations()); // Because of extra frame offset used current method name in test, while in real world used "add" method name verifyIncompleteException(assertThrows(WebApplicationException.class, () -> collection.add(model)), "LogicalUnit", "lambda$testAddLunDiskMissingId$4", "id"); }
@Test public void testAddIscsiLunDiskIncompleteParametersConnectionAddress() { Disk model = createIscsiLunDisk(); model.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).setAddress(null); setUriInfo(setUpBasicUriExpectations()); // Because of extra frame offset used current method name in test, while in real world used "add" method name verifyIncompleteException(assertThrows(WebApplicationException.class, () -> collection.add(model)), "LogicalUnit", "lambda$testAddIscsiLunDiskIncompleteParametersConnectionAddress$5", "address"); }
@Test public void testAddIscsiLunDiskIncompleteParametersConnectionPort() { Disk model = createIscsiLunDisk(); model.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).setPort(null); setUriInfo(setUpBasicUriExpectations()); // Because of extra frame offset used current method name in test, while in real world used "add" method name verifyIncompleteException(assertThrows(WebApplicationException.class, () -> collection.add(model)), "LogicalUnit", "lambda$testAddIscsiLunDiskIncompleteParametersConnectionPort$7", "port"); }
@Test public void testAddIscsiLunDiskIncompleteParametersConnectionTarget() { Disk model = createIscsiLunDisk(); model.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).setTarget(null); setUriInfo(setUpBasicUriExpectations()); // Because of extra frame offset used current method name in test, while in real world used "add" method name verifyIncompleteException(assertThrows(WebApplicationException.class, () -> collection.add(model)), "LogicalUnit", "lambda$testAddIscsiLunDiskIncompleteParametersConnectionTarget$6", "target"); }