if (from.isSetLinks()) { List<Link> links = from.getLinks().stream() .filter(link -> !RELS_TO_REMOVE.contains(link.getRel())) .collect(toList()); if (from.isSetActions()) { to.setActions(adaptOut(from.getActions())); if (from.isSetAddress()) { to.setAddress(from.getAddress()); if (from.isSetAutoNumaStatus()) { to.setAutoNumaStatus(from.getAutoNumaStatus().value()); if (from.isSetCertificate()) { to.setCertificate(adaptOut(from.getCertificate())); if (from.isSetCluster()) { to.setCluster(adaptOut(from.getCluster())); if (from.isSetComment()) { to.setComment(from.getComment()); if (from.isSetCpu()) { to.setCpu(adaptOut(from.getCpu())); if (from.isSetDescription()) { to.setDescription(from.getDescription());
static Host getModel(int index) { Host model = new Host(); model.setName(NAMES[index]); model.setAddress(ADDRESSES[index]); model.setRootPassword(ROOT_PASSWORD); return model; }
private void updateIdForSingleHost(Host host, Set<Guid> guidsSet) { if (host.isSetName() && !host.isSetId()){ // find the corresponding host id Guid hostGuid = getHostId(host); if (hostGuid != null) { guidsSet.add(hostGuid); // add hostId element to host host.setId(hostGuid.toString()); } } else if (host.isSetId()){ guidsSet.add(Guid.createGuidFromString(host.getId())); } } }
private Guid getHostId(Host host) { // presence of host ID or name already validated return host.isSetId() ? new Guid(host.getId()) : host.isSetName() ? getEntity(VdsStatic.class, QueryType.GetVdsStaticByName, new NameQueryParameters(host.getName()), "Hosts: name=" + host.getName()).getId() : null; } }
@Mapping(from = VDS.class, to = Host.class) public static Host map(VDS entity, Host template) { Host model = template != null ? template : new Host(); model.setId(entity.getId().toString()); model.setName(entity.getName()); model.setComment(entity.getComment()); if (entity.getClusterId() != null) { Cluster cluster = new Cluster(); cluster.setId(entity.getClusterId().toString()); model.setCluster(cluster); model.setAddress(entity.getHostName()); if (entity.getPort() > 0) { model.setPort(entity.getPort()); model.setProtocol(HostProtocol.STOMP); HostStatus status = map(entity.getStatus(), null); model.setStatus(status); if (entity.getExternalStatus() != null) { ExternalStatus externalStatus = ExternalStatusMapper.map(entity.getExternalStatus()); model.setExternalStatus(externalStatus); model.setStatusDetail(entity.getNonOperationalReason().name().toLowerCase()); } else if (status == HostStatus.MAINTENANCE || status == HostStatus.PREPARING_FOR_MAINTENANCE) { model.setStatusDetail(entity.getMaintenanceReason()); model.setSpm(spm); if (entity.getVersion() != null && entity.getVersion().getMajor() != -1 &&
@Override public Host adapt(V3Host from) { Host to = new Host(); if (from.isSetLinks()) { to.getLinks().addAll(adaptIn(from.getLinks())); to.setActions(adaptIn(from.getActions())); to.setAddress(from.getAddress()); to.setAutoNumaStatus(AutoNumaStatus.fromValue(from.getAutoNumaStatus())); to.setCertificate(adaptIn(from.getCertificate())); to.setCluster(adaptIn(from.getCluster())); to.setComment(from.getComment()); to.setCpu(adaptIn(from.getCpu())); to.setDescription(from.getDescription()); to.setDevicePassthrough(adaptIn(from.getDevicePassthrough())); to.setDisplay(adaptIn(from.getDisplay())); to.setExternalHostProvider(adaptIn(from.getExternalHostProvider())); to.setExternalStatus(ExternalStatus.fromValue(from.getExternalStatus().getState()));
@Mapping(from = Host.class, to = VdsStatic.class) public static VdsStatic map(Host model, VdsStatic template) { VdsStatic entity = template != null ? template : new VdsStatic(); if (model.isSetId()) { entity.setId(GuidUtils.asGuid(model.getId())); if (model.isSetName()) { entity.setName(model.getName()); if (model.isSetCluster() && model.getCluster().isSetId()) { entity.setClusterId(GuidUtils.asGuid(model.getCluster().getId())); if (model.isSetAddress()) { entity.setHostName(model.getAddress()); if (model.isSetPort() && model.getPort() > 0) { entity.setPort(model.getPort()); } else { entity.setPort(DEFAULT_VDSM_PORT); if (model.isSetSsh()) { map(model.getSsh(), entity); if (model.isSetPowerManagement()) { entity = map(model.getPowerManagement(), entity); if (model.isSetSpm()) { if (model.getSpm().getPriority() != null) { entity.setVdsSpmPriority(model.getSpm().getPriority());
@Override protected void verify(Host model, Host transform) { assertNotNull(transform); assertEquals(model.getName(), transform.getName()); assertEquals(model.getComment(), transform.getComment()); assertEquals(model.getId(), transform.getId()); assertNotNull(transform.getCluster()); assertEquals(model.getCluster().getId(), transform.getCluster().getId()); assertEquals(model.getAddress(), transform.getAddress()); assertEquals(model.getPort(), transform.getPort()); assertEquals(model.getSpm().getPriority(), transform.getSpm().getPriority()); assertEquals(model.getDisplay().getAddress(), transform.getDisplay().getAddress()); }
public static Method getAddSignature(Host host) throws NoSuchMethodException, SecurityException { if (host == null) { throw new ValidationException("Parameter 'host' is mandatory but was not provided."); } if (host.getAddress()==null) { throw new ValidationException("Parameter 'host.address' is mandatory but was not provided."); } if (host.getName()==null) { throw new ValidationException("Parameter 'host.name' is mandatory but was not provided."); } if ( (host.getCluster()==null || host.getCluster().getId()==null) && (host.getCluster()==null || host.getCluster().getName()==null) ) { throw new ValidationException("Parameters 'host.cluster.id' or 'host.cluster.name' are mandatory but both were not provided."); } /** * using_root_password */ if (host!=null && host.getRootPassword()!=null ) { return HostsResource.class.getMethod("addUsingRootPassword", Host.class); } throw new ValidationException("No matching signature found, make sure that mandatory attributes are provided."); }
static void verifyModelSpecific(Host model, int index) { assertEquals(GUIDS[index].toString(), model.getId()); assertEquals(NAMES[index], model.getName()); assertEquals(ADDRESSES[index], model.getAddress()); assertEquals(HOST_STATUS[index], model.getStatus()); } }
public static void validateRefreshLun(Action action) { if (action == null) { throw new ValidationException("Action is mandatory but was not provided."); } if ( (action.getHost()==null || action.getHost().getId()==null) && (action.getHost()==null || action.getHost().getName()==null) ) { throw new ValidationException("Parameters 'host.id' or 'host.name' are mandatory but both were not provided."); } }
private void assertHostsListMatch(List<Host> modelHostsList, List<Host> trnsfHostsList) { for (Host host : modelHostsList){ boolean foundInTransformation = false; for (Host otherHost : trnsfHostsList){ if (host.getId().equals(otherHost.getId())){ foundInTransformation = true; break; } } assertTrue(foundInTransformation, "Umatching dedicated host in Placement Policy"); } }
private Response performCreate(ImageTransfer imageTransfer, TransferDiskImageParameters params) { updateTransferType(imageTransfer, params); if (imageTransfer.isSetHost() && imageTransfer.getHost().isSetId()) { params.setVdsId(Guid.createGuidFromString(imageTransfer.getHost().getId())); } if (imageTransfer.isSetInactivityTimeout()) { params.setClientInactivityTimeout(imageTransfer.getInactivityTimeout()); } return performCreate(ActionType.TransferDiskImage, params, new QueryIdResolver<Guid>(QueryType.GetImageTransferById, IdQueryParameters.class)); }
@Test public void testBadGuidValidation() { setUpGetEntityExpectations(false); Host host = new Host(); host.setCluster(new Cluster()); host.getCluster().setId("!!!"); assertThrows(MalformedIdException.class, () -> resource.update(host)); }