private static String getLogicalUnitId(Disk disk) { if (disk.getLunStorage() != null && disk.getLunStorage().getLogicalUnits() != null && disk.getLunStorage().getLogicalUnits().getLogicalUnits().size() > 0) { return disk.getLunStorage().getLogicalUnits().getLogicalUnits().get(0).getId(); } // In case no LUN id was found we return empty GUID to avoid null key initialization in the map. return Guid.Empty.toString(); }
public HostStorages list() { HostStorages ret = new HostStorages(); for (LUNs lun : getLogicalUnits()) { HostStorage storage = map(lun); List<StorageServerConnections> lunConnections = lun.getLunConnections(); if (lunConnections!=null && !lunConnections.isEmpty()) { getMapper(StorageServerConnections.class, LogicalUnit.class).map(lunConnections.get(0), storage.getLogicalUnits().getLogicalUnits().get(0)); } ret.getHostStorages().add(addLinks(storage)); } return ret; }
&& 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 ) {
/** * 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; }
public static boolean isLunDisk(Disk disk) { return disk.isSetLunStorage() && disk.getLunStorage().isSetLogicalUnits() && disk.getLunStorage().getLogicalUnits().isSetLogicalUnits(); } }
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(); } }
@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 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; }
&& 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);
private Set<String> getLunIds(HostStorage storage, StorageType storageType, Guid hostId) { List<LogicalUnit> logicalUnits = new ArrayList<>(); if (storage.isSetLogicalUnits() && storage.getLogicalUnits().isSetLogicalUnits()) { logicalUnits = storage.getLogicalUnits().getLogicalUnits(); } else if (storage.isSetVolumeGroup() && storage.getVolumeGroup().isSetLogicalUnits() && storage.getVolumeGroup().getLogicalUnits().isSetLogicalUnits()) { logicalUnits = storage.getVolumeGroup().getLogicalUnits().getLogicalUnits(); } Set<String> lunIds = new HashSet<>(); for (LogicalUnit unit : logicalUnits) { validateParameters(unit, 4, "id"); // if the address and target were not supplied, we understand from this that // the user assumes that the host is already logged-in to the target of this lun. // so in this case we do not need (and do not have the required information) to login // to the target. if ((storageType == StorageType.ISCSI) && !isConnectionAssumed(unit)) { connectStorageToHost(hostId, storageType, unit); } lunIds.add(unit.getId()); } refreshHostStorage(hostId); return !lunIds.isEmpty() ? lunIds : null; }
@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; }
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 } }
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 } }
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; }
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 } }
@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); }
@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 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 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"); }