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 static boolean isLunDisk(Disk disk) { return disk.isSetLunStorage() && disk.getLunStorage().isSetLogicalUnits() && disk.getLunStorage().getLogicalUnits().isSetLogicalUnits(); } }
&& 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 ) { return DisksResource.class.getMethod("addLun", Disk.class);
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 } }
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 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 ActionParametersBase getAddParameters(DiskAttachment attachment, org.ovirt.engine.core.common.businessentities.storage.Disk entity, Disk disk) { DiskVmElement dve = map(attachment); dve.getId().setVmId(vmId); AddDiskParameters parameters = new AddDiskParameters(dve, entity); Guid storageDomainId = getStorageDomainId(disk); if (storageDomainId != null) { parameters.setStorageDomainId(storageDomainId); } if (attachment.isSetActive()) { parameters.setPlugDiskToVm(attachment.isActive()); } if (disk.isSetLunStorage() && disk.getLunStorage().isSetHost()) { parameters.setVdsId(getHostId(disk.getLunStorage().getHost())); } return parameters; }
@Override public Response add(Disk disk) { validateDiskForCreation(disk); AddDiskParameters params = new AddDiskParameters(); Guid storageDomainId = getStorageDomainId(disk); params.setStorageDomainId(storageDomainId); if (storageDomainId != null) { updateStorageTypeForDisk(disk, storageDomainId); } params.setDiskInfo(getMapper(Disk.class, org.ovirt.engine.core.common.businessentities.storage.Disk.class).map(disk, null)); if (disk.isSetLunStorage() && disk.getLunStorage().isSetHost()) { params.setVdsId(getHostId(disk.getLunStorage().getHost())); } if (disk.isSetId()) { params.setUsePassedDiskId(true); } if (disk.isSetImageId()) { params.setUsePassedImageId(true); } return performCreate(ActionType.AddDisk, params, new QueryIdResolver<Guid>(QueryType.GetDiskByDiskId, IdQueryParameters.class)); }
@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"); }
@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 testAddLunDiskMissingType() { Disk model = createIscsiLunDisk(); model.getLunStorage().setType(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)), "HostStorage", "lambda$testAddLunDiskMissingType$3", "type"); }
((LunDisk) engineDisk).setLun(StorageLogicalUnitMapper.map(disk.getLunStorage(), null));
to.setLunStorage(adaptOut(from.getLunStorage()));