@Override public Response reduceLuns(Action action) { List<LogicalUnit> reducedLuns = action.getLogicalUnits().getLogicalUnits(); List<String> lunIds = reducedLuns.stream().map(LogicalUnit::getId).collect(toList()); ReduceSANStorageDomainDevicesCommandParameters parameters = new ReduceSANStorageDomainDevicesCommandParameters(guid, lunIds); return performAction(ActionType.ReduceSANStorageDomainDevices, parameters); }
@Override public Response refreshLuns(Action action) { List<LogicalUnit> incomingLuns; if (action.isSetLogicalUnits()) { incomingLuns = action.getLogicalUnits().getLogicalUnits(); } else { incomingLuns = Collections.emptyList(); } ExtendSANStorageDomainParameters params = createParameters(guid, incomingLuns, false); return performAction(ActionType.RefreshLunsSize, params); }
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; }
protected void mapVolumeGroupFcp(StorageDomain model, org.ovirt.engine.core.common.businessentities.StorageDomain entity) { VolumeGroup vg = model.getStorage().getVolumeGroup(); List<LUNs> luns = getLunsByVgId(vg.getId()); if (luns != null && !luns.isEmpty()) { vg.setLogicalUnits(new LogicalUnits()); for (LUNs lun : luns) { LogicalUnit unit = map(lun); vg.getLogicalUnits().getLogicalUnits().add(unit); } } }
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()); } }
@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; }
/** * 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 V3VolumeGroup adapt(VolumeGroup from) { V3VolumeGroup to = new V3VolumeGroup(); if (from.isSetId()) { to.setId(from.getId()); } if (from.isSetLogicalUnits()) { to.getLogicalUnits().addAll(adaptOut(from.getLogicalUnits().getLogicalUnits())); } if (from.isSetName()) { to.setName(from.getName()); } return to; } }
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; }
@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); }
@Override public VolumeGroup adapt(V3VolumeGroup from) { VolumeGroup to = new VolumeGroup(); if (from.isSetId()) { to.setId(from.getId()); } if (from.isSetLogicalUnits()) { to.setLogicalUnits(new LogicalUnits()); to.getLogicalUnits().getLogicalUnits().addAll(adaptIn(from.getLogicalUnits())); } if (from.isSetName()) { to.setName(from.getName()); } return to; } }
@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; }
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; }
@Test public void testRefreshLunsSize() { List<String> lunsArray = new ArrayList(); lunsArray.add(GUIDS[2].toString()); setUriInfo(setUpActionExpectations(ActionType.RefreshLunsSize, ExtendSANStorageDomainParameters.class, new String[]{"LunIds"}, new Object[]{lunsArray}, true, true)); Action action = new Action(); LogicalUnits luns= new LogicalUnits(); LogicalUnit lun = new LogicalUnit(); lun.setId(GUIDS[2].toString()); luns.getLogicalUnits().add(lun); action.setLogicalUnits(luns); verifyActionResponse(resource.refreshLuns(action)); }
@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"); }