@SuppressWarnings("unchecked") private static Map<String, String> getCustomProperties(ResultSet rs) throws SQLException { return SerializationFactory.getDeserializer() .deserializeOrCreateNew(rs.getString("custom_properties"), LinkedHashMap.class); } }
private String serializeReturnValue(ActionReturnValue retVal) { return SerializationFactory.getSerializer().serialize(retVal); }
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; } } }
private String serializeParameters(ActionParametersBase params) { return SerializationFactory.getSerializer().serialize(params); }
/** * 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); } }
value = SerializationFactory.getSerializer().serialize(value);
@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); }
@Override public void updateVmLeaseInfo(Guid vmId, Map<String, String> leaseInfo) { getCallsHandler().executeModification("UpdateVmLeaseInfo", getCustomMapSqlParameterSource() .addValue("vm_guid", vmId) .addValue("lease_info", SerializationFactory.getSerializer().serialize(leaseInfo))); }
@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 MapSqlParameterSource createFullParametersMapper(NetworkAttachment networkAttachment) { MapSqlParameterSource mapper = createIdParameterMapper(networkAttachment.getId()) .addValue("network_id", networkAttachment.getNetworkId()) .addValue("nic_id", networkAttachment.getNicId()) .addValue("custom_properties", SerializationFactory.getSerializer().serialize(networkAttachment.getProperties())); mapIpConfiguration(networkAttachment, mapper); mapper.addValue("dns_resolver_configuration_id", getDnsResolverConfigurationId(networkAttachment)); return mapper; }
@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; }; }
@Override protected MapSqlParameterSource createFullParametersMapper(ClusterPolicy entity) { return createIdParameterMapper(entity.getId()) .addValue("name", entity.getName()) .addValue("description", entity.getDescription()) .addValue("is_locked", entity.isLocked()) .addValue("is_default", entity.isDefaultPolicy()) .addValue("custom_properties", SerializationFactory.getSerializer().serialize(entity.getParameterMap())); }
@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; }; }
@Override protected MapSqlParameterSource createFullParametersMapper(CommandEntity entity) { return getCustomMapSqlParameterSource().addValue("engine_session_seq_id", entity.getEngineSessionSeqId()) .addValue("user_id", Guid.isNullOrEmpty(entity.getUserId()) ? Guid.Empty : entity.getUserId()) .addValue("command_id", Guid.isNullOrEmpty(entity.getId()) ? Guid.Empty : entity.getId()) .addValue("command_type", entity.getCommandType().getValue()) .addValue("parent_command_id", entity.getParentCommandId()) .addValue("root_command_id", Guid.isNullOrEmpty(entity.getRootCommandId()) ? Guid.Empty : entity.getRootCommandId()) .addValue("command_context", SerializationFactory.getSerializer().serialize(entity.getCommandContext())) .addValue("command_parameters", serializeParameters(entity.getCommandParameters())) .addValue("command_params_class", entity.getCommandParameters() == null ? null : entity.getCommandParameters().getClass().getName()) .addValue("created_at", entity.getCreatedAt()) .addValue("status", entity.getCommandStatus().toString()) .addValue("executed", entity.isExecuted()) .addValue("callback_enabled", entity.isCallbackEnabled()) .addValue("return_value", serializeReturnValue(entity.getReturnValue())) .addValue("return_value_class", entity.getReturnValue() == null ? null : entity.getReturnValue().getClass().getName()) .addValue("data", SerializationFactory.getSerializer().serialize(entity.getData())); }
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 MapSqlParameterSource createFullParametersMapper(VmDevice entity) { return createIdParameterMapper(entity.getId()) .addValue("device", entity.getDevice()) .addValue("type", entity.getType().getValue()) .addValue("address", entity.getAddress()) .addValue("spec_params", SerializationFactory.getSerializer().serialize(entity.getSpecParams())) .addValue("is_managed", entity.isManaged()) .addValue("is_plugged", entity.isPlugged()) .addValue("is_readonly", entity.getReadOnly()) .addValue("alias", entity.getAlias()) .addValue("custom_properties", SerializationFactory.getSerializer().serialize(entity.getCustomProperties())) .addValue("snapshot_id", entity.getSnapshotId()) .addValue("logical_name", entity.getLogicalName()) .addValue("host_device", entity.getHostDevice()); }
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 protected MapSqlParameterSource createFullParametersMapper(PolicyUnit entity) { return createIdParameterMapper(entity.getId()) .addValue("name", entity.getName()) .addValue("is_internal", entity.isInternal()) .addValue("type", entity.getPolicyUnitType() == null ? PolicyUnitType.FILTER.getValue() : entity.getPolicyUnitType() .getValue()) .addValue("description", entity.getDescription()) .addValue("custom_properties_regex", SerializationFactory.getSerializer().serialize(entity.getParameterRegExMap())) .addValue("enabled", entity.isEnabled()); }
@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; }
mapper.addValue("agent_configuration", SerializationFactory.getSerializer().serialize(agentConfiguration)); mapper.addValue("additional_properties", SerializationFactory.getSerializer().serialize(additionalProperties)); mapper.addValue("read_only", readOnly); mapper.addValue("auto_sync", autoSync);