@Override public V3PmProxy adapt(PmProxy from) { V3PmProxy to = new V3PmProxy(); if (from.isSetType()) { to.setType(from.getType().value()); } return to; } }
@Mapping(from = PowerManagement.class, to = VdsStatic.class) public static VdsStatic map(PowerManagement model, VdsStatic template) { VdsStatic entity = template != null ? template : new VdsStatic(); if (model.isSetEnabled()) { entity.setPmEnabled(model.isEnabled()); } if (model.isSetAutomaticPmEnabled()) { entity.setDisablePowerManagementPolicy(!model.isAutomaticPmEnabled()); } if (model.isSetPmProxies()) { List<FenceProxySourceType> fenceProxySources = model.getPmProxies() .getPmProxies() .stream() .map(pmProxy -> FenceProxySourceType.forValue(pmProxy.getType().toString())) .collect(toCollection(LinkedList::new)); entity.setFenceProxySources(fenceProxySources); } if (model.isSetKdumpDetection()) { entity.setPmKdumpDetection(model.isKdumpDetection()); } return entity; }
@Test public void testPmProxyPreferences() { VDS vds = new VDS(); vds.setId(Guid.Empty); vds.setFenceProxySources(Arrays.asList(FenceProxySourceType.CLUSTER, FenceProxySourceType.DC)); Host host = HostMapper.map(vds, (Host) null); assertEquals(2, host.getPowerManagement().getPmProxies().getPmProxies().size()); assertEquals(PmProxyType.CLUSTER, host.getPowerManagement().getPmProxies().getPmProxies().get(0).getType()); assertEquals(PmProxyType.DC, host.getPowerManagement().getPmProxies().getPmProxies().get(1).getType()); }