Follow the generic updates before starting with the following changes
General update for services to be Central-Instance compatible
Application.properties variables to be added
state.level.tenantid.length=2
State-level tenant value will be picked from the full tenant-id separated by the '.' dot. once the tenant-id is separated by dot the resulting array of size given above will be considered state level.
is.environment.central.instance=trueDeclares whether the environment in which the service is deployed belong to a central-instance kind of setup.
The both above said variable has to be overridden in the values YAML file of the respective service to pick up the values from the environment.
{{- if index .Values "global" "is-environment-central-instance" }} - name: IS_ENVIRONMENT_CENTRAL_INSTANCE valueFrom: configMapKeyRef: name: egov-config key: is-environment-central-instance {{- end }} {{- if index .Values "global" "is-environment-central-instance" }} - name: STATE_LEVEL_TENANTID_LENGTH valueFrom: configMapKeyRef: name: egov-config key: state-level-tenantid-length {{- end }}
The host of the state-specific services referred by this service should be changed to the internal gateway host for tenant-based(namespace) redirection.
- name: EGOV_MDMS_HOST valueFrom: configMapKeyRef: name: egov-service-host key: internal-gateway
Sample values YAML file to refer to the above-said changes
If this service allows the search of data without tenant-id then the following validation should be added to all the search APIs belonging to the service. searches without state-level tenant-id (as described by this variable - state.level.tenantid.length) will render the application useless, so the following is mandatory
if(configs.getIsEnvironmentCentralInstance() && criteria.getTenantId() == null) throw new CustomException("EG_PT_INVALID_SEARCH"," TenantId is mandatory for search "); else if(configs.getIsEnvironmentCentralInstance() && criteria.getTenantId().split("\\.").length < configs.getStateLevelTenantIdLength()) throw new CustomException("EG_PT_INVALID_SEARCH"," TenantId should be mandatorily " + configs.getStateLevelTenantIdLength() + " levels for search");
Replace all the table names in the queries present with the {schema} placeholder
private static String PROEPRTY_AUDIT_QUERY = "select property from {schema}.eg_pt_property_audit where propertyid=?";
Add the following Schema replacer utility method and use the same to replace all queries with the respective schema.
/** * Method to fetch the state name from the tenantId * * @param query * @param tenantId * @return */ public String replaceSchemaPlaceholder(String query, String tenantId) { String finalQuery = null; if (tenantId.contains(".")) { String schemaName = tenantId.split("\\.")[1]; finalQuery = query.replace(PTConstants.SCHEMA_REPLACE_STRING, schemaName); } else { finalQuery = query.replace(PTConstants.SCHEMA_REPLACE_STRING.concat("."), ""); } return finalQuery; } /* * Sample method example to replace query with schema */ public List<String> getPropertyIds(Set<String> ownerIds, String tenantId) { List<Object> preparedStmtList = new ArrayList<>(); String query = queryBuilder.getPropertyIdsQuery(ownerIds, tenantId, preparedStmtList); query = util.replaceSchemaPlaceholder(query, tenantId); return jdbcTemplate.queryForList(query, preparedStmtList.toArray(), String.class); }
Change the persister config to alter the Kafka topic names for the configs belonging to your respective multi-schema service. The kafka topic name should be appended with the schema name of the respective state schema.