@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; }
/** * Create an instance of {@link PmProxy } * */ public PmProxy createPmProxy() { return new PmProxy(); }
@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()); }
@Mapping(from = VDS.class, to = PowerManagement.class) public static PowerManagement map(VDS entity, PowerManagement template) { PowerManagement model = template != null ? template : new PowerManagement(); if (entity.getFenceProxySources() != null) { PmProxies pmProxies = new PmProxies(); for (FenceProxySourceType fenceProxySource : entity.getFenceProxySources()) { PmProxy pmProxy = new PmProxy(); pmProxy.setType(map(fenceProxySource, null)); pmProxies.getPmProxies().add(pmProxy); } model.setPmProxies(pmProxies); } model.setKdumpDetection(entity.isPmKdumpDetection()); model.setEnabled(entity.isPmEnabled()); model.setAutomaticPmEnabled(!entity.isDisablePowerManagementPolicy()); return model; }