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 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 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 LogicalUnits } * */ public LogicalUnits createLogicalUnits() { return new LogicalUnits(); }
public static boolean isLunDisk(Disk disk) { return disk.isSetLunStorage() && disk.getLunStorage().isSetLogicalUnits() && disk.getLunStorage().getLogicalUnits().isSetLogicalUnits(); } }
@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); }
@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; }
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(); }
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; }
protected void mapVolumeGroupIscsi(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) { List<StorageServerConnections> lunConnections = lun.getLunConnections(); if (lunConnections != null) { for (StorageServerConnections cnx : lunConnections) { LogicalUnit unit = map(lun); unit = map(cnx, unit); vg.getLogicalUnits().getLogicalUnits().add(unit); } } } } }
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; }
/** * 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 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; } }
&& 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 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; }
@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()); } }
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 } }
@Test public void reduceLuns() { List<String> paramsLuns = new LinkedList<>(); paramsLuns.add(GUIDS[2].toString()); paramsLuns.add(GUIDS[3].toString()); setUriInfo(setUpActionExpectations(ActionType.ReduceSANStorageDomainDevices, ReduceSANStorageDomainDevicesCommandParameters.class, new String[]{"DevicesToReduce", "StorageDomainId"}, new Object[]{paramsLuns, GUIDS[0]}, true, true)); Action action = new Action(); LogicalUnits luns= new LogicalUnits(); paramsLuns.forEach(s -> { LogicalUnit lun = new LogicalUnit(); lun.setId(s); luns.getLogicalUnits().add(lun); }); action.setLogicalUnits(luns); verifyActionResponse(resource.reduceLuns(action)); }