InstanceConfig convert(DataNodeConfig dataNodeConfig) {
      InstanceConfig instanceConfig = new InstanceConfig(dataNodeConfig.getInstanceName());
      instanceConfig.setHostName(dataNodeConfig.getHostName());
      instanceConfig.setPort(Integer.toString(dataNodeConfig.getPort()));
      if (dataNodeConfig.getSslPort() != null) {
        instanceConfig.getRecord().setIntField(SSL_PORT_STR, dataNodeConfig.getSslPort());
      }
      if (dataNodeConfig.getHttp2Port() != null) {
        instanceConfig.getRecord().setIntField(HTTP2_PORT_STR, dataNodeConfig.getHttp2Port());
      }
      instanceConfig.getRecord().setSimpleField(DATACENTER_STR, dataNodeConfig.getDatacenterName());
      instanceConfig.getRecord().setSimpleField(RACKID_STR, dataNodeConfig.getRackId());
      long xid = dataNodeConfig.getXid();
      if (xid != DEFAULT_XID) {
        // Set the XID only if it is not the default, in order to avoid unnecessary updates.
        instanceConfig.getRecord().setLongField(XID_STR, xid);
      }
      instanceConfig.getRecord().setIntField(SCHEMA_VERSION_STR, CURRENT_SCHEMA_VERSION);
      instanceConfig.getRecord().setListField(SEALED_STR, new ArrayList<>(dataNodeConfig.getSealedReplicas()));
      instanceConfig.getRecord().setListField(PARTIALLY_SEALED_STR,
          new ArrayList<>(dataNodeConfig.getPartiallySealedReplicas()));
      instanceConfig.getRecord()
          .setListField(STOPPED_REPLICAS_STR, new ArrayList<>(dataNodeConfig.getStoppedReplicas()));
      instanceConfig.getRecord()
          .setListField(DISABLED_REPLICAS_STR, new ArrayList<>(dataNodeConfig.getDisabledReplicas()));
      dataNodeConfig.getDiskConfigs().forEach((mountPath, diskConfig) -> {
        Map<String, String> diskProps = new HashMap<>();
        diskProps.put(DISK_STATE, diskConfig.getState() == HardwareState.AVAILABLE ? AVAILABLE_STR : UNAVAILABLE_STR);
        diskProps.put(DISK_CAPACITY_STR, Long.toString(diskConfig.getDiskCapacityInBytes()));
        StringBuilder replicasStrBuilder = new StringBuilder();
        diskConfig.getReplicaConfigs()
            .forEach((partitionName, replicaConfig) -> replicasStrBuilder.append(partitionName)
                .append(REPLICAS_STR_SEPARATOR)
                .append(replicaConfig.getReplicaCapacityInBytes())
                .append(REPLICAS_STR_SEPARATOR)
                .append(replicaConfig.getPartitionClass())
                .append(REPLICAS_DELIM_STR));
        diskProps.put(REPLICAS_STR, replicasStrBuilder.toString());
        instanceConfig.getRecord().setMapField(mountPath, diskProps);
      });
      dataNodeConfig.getExtraMapFields().forEach((k, v) -> instanceConfig.getRecord().setMapField(k, v));
      return instanceConfig;
    }
@param dataNodeConfig the {@link DataNodeConfig} to convert into an {@link InstanceConfig}.
@return the {@link InstanceConfig}.
ambry-clustermap/src/main/java/com/github/ambry/clustermap/InstanceConfigToDataNodeConfigAdapter.java