@SuppressWarnings("unchecked") private static Map<String, String> getCustomProperties(ResultSet rs) throws SQLException { return SerializationFactory.getDeserializer() .deserializeOrCreateNew(rs.getString("custom_properties"), LinkedHashMap.class); } }
private List<HugePage> deserializeHugePages(String hugepages) throws SQLException { if (hugepages == null) { return null; } try { return SerializationFactory.getDeserializer() .deserializeUnformattedList(hugepages, HugePage.class); } catch (SerializationException e) { log.warn("Can not deserialize huge pages {} ", hugepages); return null; } } }
/** * Converts JSON string to instance of specified class. If {@code value} is {@code null} or empty, tries to create * new instance of specified class. If it fails returns {@code null} * * @param value * JSON string * @param clazz * specified class * @return new instance or {@code null} if a new instance cannot be created */ public <T extends Serializable> T deserializeOrCreateNew(String value, Class<T> clazz) { if (StringUtils.isEmpty(value)) { T instance; try { instance = clazz.newInstance(); } catch (Exception ex) { instance = null; } return instance; } else { return SerializationFactory.getDeserializer().deserialize(value, clazz); } }
@SuppressWarnings("unchecked") private static ActionReturnValue deserializeReturnValue(String payload, String className) { if (className == null) { return null; } Class<Serializable> retValueClass = (Class<Serializable>) ReflectionUtils.getClassFor(className); return (ActionReturnValue) SerializationFactory.getDeserializer().deserialize(payload, retValueClass); }
@SuppressWarnings("unchecked") private static ActionParametersBase deserializeParameters(String payload, String className) { if (className == null) { return null; } Class<Serializable> actionParamsClass = (Class<Serializable>) ReflectionUtils.getClassFor(className); return (ActionParametersBase) SerializationFactory.getDeserializer().deserialize(payload, actionParamsClass); }
@Override protected RowMapper<ClusterPolicy> createEntityRowMapper() { return (rs, arg1) -> { ClusterPolicy clusterPolicy = new ClusterPolicy(); clusterPolicy.setId(getGuid(rs, "id")); clusterPolicy.setName(rs.getString("name")); clusterPolicy.setDescription(rs.getString("description")); clusterPolicy.setLocked(rs.getBoolean("is_locked")); clusterPolicy.setDefaultPolicy(rs.getBoolean("is_default")); clusterPolicy.setParameterMap(SerializationFactory.getDeserializer() .deserializeOrCreateNew(rs.getString("custom_properties"), LinkedHashMap.class)); return clusterPolicy; }; }
private AdditionalProperties mapAdditionalProperties(ResultSet rs, Provider<?> entity) throws SQLException { switch (entity.getType()) { case EXTERNAL_NETWORK: case OPENSTACK_NETWORK: OpenstackNetworkProviderProperties networkProperties = new OpenstackNetworkProviderProperties(); mapOpenStackProperties(rs, networkProperties); networkProperties.setReadOnly(rs.getBoolean("read_only")); networkProperties.setAutoSync(rs.getBoolean("auto_sync")); networkProperties.setPluginType(rs.getString("plugin_type")); networkProperties.setAgentConfiguration(SerializationFactory.getDeserializer() .deserialize(rs.getString("agent_configuration"), AgentConfiguration.class)); return networkProperties; case OPENSTACK_IMAGE: OpenStackImageProviderProperties imageProperties = new OpenStackImageProviderProperties(); mapOpenStackProperties(rs, imageProperties); return imageProperties; case OPENSTACK_VOLUME: OpenStackVolumeProviderProperties volumeProperties = new OpenStackVolumeProviderProperties(); mapOpenStackProperties(rs, volumeProperties); return volumeProperties; case VMWARE: return SerializationFactory.getDeserializer().deserialize(rs.getString("additional_properties"), VmwareVmProviderProperties.class); case KVM: return SerializationFactory.getDeserializer().deserialize(rs.getString("additional_properties"), KVMVmProviderProperties.class); case XEN: return SerializationFactory.getDeserializer().deserialize(rs.getString("additional_properties"), XENVmProviderProperties.class); default: return null; } }
@Override protected RowMapper<PolicyUnit> createEntityRowMapper() { return (rs, arg1) -> { PolicyUnit policyUnit = new PolicyUnit(); policyUnit.setId(getGuid(rs, "id")); policyUnit.setName(rs.getString("name")); policyUnit.setInternal(rs.getBoolean("is_internal")); policyUnit.setPolicyUnitType(PolicyUnitType.forValue(rs.getInt("type"))); policyUnit.setDescription(rs.getString("description")); policyUnit.setParameterRegExMap(SerializationFactory.getDeserializer() .deserializeOrCreateNew(rs.getString("custom_properties_regex"), LinkedHashMap.class)); policyUnit.setEnabled(rs.getBoolean("enabled")); return policyUnit; }; }
protected void map(ResultSet rs, HostDevice device) throws SQLException{ device.setHostId(getGuid(rs, "host_id")); device.setDeviceName(rs.getString("device_name")); device.setParentDeviceName(rs.getString("parent_device_name")); device.setCapability(rs.getString("capability")); device.setIommuGroup((Integer) rs.getObject("iommu_group")); String mdevTypes = rs.getString("mdev_types"); if (mdevTypes != null && !mdevTypes.isEmpty()) { device.setMdevTypes(new HashSet<>(Arrays.asList(mdevTypes.split(",")))); } device.setProductName(rs.getString("product_name")); device.setProductId(rs.getString("product_id")); device.setVendorName(rs.getString("vendor_name")); device.setVendorId(rs.getString("vendor_id")); device.setParentPhysicalFunction(rs.getString("physfn")); device.setTotalVirtualFunctions((Integer) rs.getObject("total_vfs")); device.setNetworkInterfaceName(rs.getString("net_iface_name")); device.setAssignable(rs.getBoolean("is_assignable")); device.setAddress(SerializationFactory.getDeserializer() .deserializeOrCreateNew(rs.getString("address"), HashMap.class)); device.setVmId(getGuid(rs, "vm_id")); device.setDriver(rs.getString("driver")); } }
@Override @SuppressWarnings("unchecked") public Provider<?> mapRow(ResultSet rs, int index) throws SQLException { Provider<AdditionalProperties> entity = new Provider<>(); entity.setId(getGuidDefaultEmpty(rs, "id")); entity.setName(rs.getString("name")); entity.setDescription(rs.getString("description")); entity.setUrl(rs.getString("url")); entity.setType(ProviderType.valueOf(rs.getString("provider_type"))); entity.setRequiringAuthentication(rs.getBoolean("auth_required")); entity.setUsername(rs.getString("auth_username")); entity.setPassword(DbFacadeUtils.decryptPassword(rs.getString("auth_password"))); entity.setCustomProperties(SerializationFactory.getDeserializer() .deserialize(rs.getString("custom_properties"), HashMap.class)); entity.setAdditionalProperties(mapAdditionalProperties(rs, entity)); entity.setAuthUrl(rs.getString("auth_url")); entity.setIsUnmanaged(rs.getBoolean("is_unmanaged")); return entity; }
@Override public HostDeviceView mapRow(ResultSet rs, int rowNum) throws SQLException { HostDeviceView device = new HostDeviceView(); map(rs, device); device.setConfiguredVmId(getGuid(rs, "configured_vm_id")); device.setAttachedVmNames(split(rs.getString("attached_vm_names"))); device.setRunningVmName(rs.getString("running_vm_name")); Map<String, Object> specParams = SerializationFactory.getDeserializer() .deserializeOrCreateNew(rs.getString("spec_params"), HashMap.class); device.setIommuPlaceholder(specParams != null && VmHostDevice.isIommuPlaceHolder(specParams)); return device; } }
@Override @SuppressWarnings("unchecked") public T mapRow(ResultSet rs, int rowNum) throws SQLException { T entity = createVnicProfileEntity(); entity.setId(getGuid(rs, "id")); entity.setName(rs.getString("name")); entity.setNetworkId(getGuid(rs, "network_id")); entity.setNetworkQosId(getGuid(rs, "network_qos_id")); entity.setCustomProperties(SerializationFactory.getDeserializer() .deserializeOrCreateNew(rs.getString("custom_properties"), LinkedHashMap.class)); entity.setPortMirroring(rs.getBoolean("port_mirroring")); entity.setPassthrough(rs.getBoolean("passthrough")); entity.setMigratable(rs.getBoolean("migratable")); entity.setDescription(rs.getString("description")); entity.setNetworkFilterId(getGuid(rs, "network_filter_id")); return entity; }
entity.setBridged(rs.getBoolean("bridged")); entity.setQos(hostNetworkQosDao.get(entity.getId())); entity.setLabels(SerializationFactory.getDeserializer().deserialize(rs.getString("labels"), HashSet.class)); entity.setAdPartnerMac(rs.getString("ad_partner_mac"));