Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. 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.

  2. is.environment.central.instance=true

    Declares whether the environment in which the service is deployed belong to a central-instance kind of setup.

  3. 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.

    Code Block
      {{- 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 }}

  4. The host of the state-specific services referred by this service should be changed to the internal gateway host for tenant-based(namespace) redirection.

    Code Block
      - name: EGOV_MDMSTL_CALCULATOR_HOST
        valueFrom:
          configMapKeyRef:
            name: egov-service-host
            key: internal-gateway

    Sample values YAML file to refer to the above-said changes

    https://github.com/egovernments/DIGIT-DevOps/blob/central-instance/deploy-as-code/helm/charts/municipal-services/property-services/values.yaml

  5. 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

    Code Block
    languagejava
    	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");

  6. Update the Kafka producer in the service with the following code to enable the service to post to a tenant(namespace) specific topic based on the tenant-id.

    Code Block
    languagejava
    @Service
    @Slf4j
    public class Producer {
    
    	@Autowired
    	private CustomKafkaTemplate<String, Object> kafkaTemplate;
    	
    	@Autowired
    	private PropertyConfiguration configs;
    
    	public void push(String tenantId, String topic, Object value) {
    
    		String updatedTopic = topic;
    		if (configs.getIsEnvironmentCentralInstance()) {
    
    			String[] tenants = tenantId.split("\\.");
    			if (tenants.length > 1)
    				updatedTopic = tenants[1].concat("-").concat(topic);
    		}
    		log.info("The Kafka topic for the tenantId : " + tenantId + " is : " + updatedTopic);
    		kafkaTemplate.send(updatedTopic, value);
    	}
    } 

  7. Replace all the table names in the queries present with the {schema} placeholder

    Code Block
    languagesql
    private static String PROEPRTY_AUDIT_QUERY = "select property from {schema}.eg_pt_property_audit where propertyid=?";

  8. Add the following Schema replacer utility method and use the same to replace all queries with the respective schema.

    Code Block
    languagejava
    	/**
    	 * 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);
    	}

  9. 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.



...